Commit f693ddea authored by shajiaiming's avatar shajiaiming

计价货币

parent 485ab183
<?php
namespace common\models\psources;
use Yii;
use common\core\BaseActiveRecord;
class CoinCurrency extends BaseActiveRecord
{
public static function getDb()
{
return Yii::$app->get('p_sources');
}
public static function tableName()
{
return '{{coin_currency}}';
}
//定义场景
const SCENARIOS_CREATE = 'create';
const SCENARIOS_UPDATE = 'update';
public function rules()
{
return [
[['pj_id', 'pj_name'], 'required'],
[['icon', 'lang'], 'safe'],
[['platform_id', 'currency_id'], 'integer'],
];
}
public function attributeLabels()
{
return [
'platform_id' => '钱包Id',
'currency_id' => '货币Id',
];
}
public function scenarios()
{
$scenarios = [
self:: SCENARIOS_CREATE => ['pj_id', 'pj_name', 'icon', 'lang'],
self:: SCENARIOS_UPDATE => ['id', 'pj_id', 'pj_name', 'icon', 'lang'],
];
return array_merge(parent:: scenarios(), $scenarios);
}
}
\ No newline at end of file
...@@ -89,4 +89,9 @@ class CoinPlatform extends BaseActiveRecord ...@@ -89,4 +89,9 @@ class CoinPlatform extends BaseActiveRecord
{ {
return $this->hasOne(CoinSupportedCoin::className(), ['id' => 'charge_unit_id']); return $this->hasOne(CoinSupportedCoin::className(), ['id' => 'charge_unit_id']);
} }
public function getCurrency()
{
return $this->hasMany(CoinSupportedCurrency::className(), ['platform_id' => 'id']);
}
} }
<?php
namespace common\models\psources;
use Yii;
use common\core\BaseActiveRecord;
class CoinSupportedCurrency extends BaseActiveRecord
{
public static function getDb()
{
return Yii::$app->get('p_sources');
}
public static function tableName()
{
return '{{coin_supported_currency}}';
}
//定义场景
const SCENARIOS_CREATE = 'create';
const SCENARIOS_UPDATE = 'update';
public function rules()
{
return [
[['platform_id', 'currency_id'], 'required'],
[['platform_id', 'currency_id'], 'integer'],
];
}
public function attributeLabels()
{
return [
'platform_id' => '钱包Id',
'currency_id' => '货币Id',
];
}
public function scenarios()
{
$scenarios = [
self:: SCENARIOS_CREATE => ['platform_id', 'currency_id'],
self:: SCENARIOS_UPDATE => ['id', 'platform_id', 'currency_id'],
];
return array_merge(parent:: scenarios(), $scenarios);
}
public function getCurrency()
{
return $this->hasOne(CoinCurrency::className(), ['id' => 'currency_id']);
}
public static function loadArray(array $data)
{
return self::getDb()->createCommand()->batchInsert(self::tableName(),
['platform_id', 'currency_id'],
$data)->execute();
}
}
\ No newline at end of file
...@@ -2,11 +2,14 @@ ...@@ -2,11 +2,14 @@
namespace wallet\controllers; namespace wallet\controllers;
use common\models\psources\CoinCurrency;
use common\models\psources\CoinSupportedCurrency;
use common\service\trusteeship\TrusteeShipService; use common\service\trusteeship\TrusteeShipService;
use Yii; use Yii;
use common\models\Admin; use common\models\Admin;
use wallet\base\BaseController; use wallet\base\BaseController;
use common\models\psources\CoinPlatform; use common\models\psources\CoinPlatform;
use yii\helpers\ArrayHelper;
class WalletController extends BaseController class WalletController extends BaseController
{ {
...@@ -32,16 +35,16 @@ class WalletController extends BaseController ...@@ -32,16 +35,16 @@ class WalletController extends BaseController
public function actionWalletBallance() public function actionWalletBallance()
{ {
$current_platform_id = Yii::$app->request->getPlatformId(); $current_platform_id = Yii::$app->request->getPlatformId();
if(1 === $current_platform_id) { if (1 === $current_platform_id) {
$platform_id = Yii::$app->request->get('platform_id', 1); $platform_id = Yii::$app->request->get('platform_id', 1);
$platform_id = empty($platform_id) ? 1 : $platform_id; $platform_id = empty($platform_id) ? 1 : $platform_id;
} else { } else {
$platform_id = Yii::$app->request->getPlatformId(); $platform_id = Yii::$app->request->getPlatformId();
} }
if(!isset(Yii::$app->params['trusteeship']['node_'. $platform_id])){ if (!isset(Yii::$app->params['trusteeship']['node_' . $platform_id])) {
return ['code' => -1, 'data' => [], 'msg' => '此钱包节点尚未开通']; return ['code' => -1, 'data' => [], 'msg' => '此钱包节点尚未开通'];
} }
$node_params = Yii::$app->params['trusteeship']['node_'. $platform_id]; $node_params = Yii::$app->params['trusteeship']['node_' . $platform_id];
$type = Yii::$app->request->get('type', 1); $type = Yii::$app->request->get('type', 1);
$page = Yii::$app->request->get('page', 1); $page = Yii::$app->request->get('page', 1);
...@@ -76,7 +79,7 @@ class WalletController extends BaseController ...@@ -76,7 +79,7 @@ class WalletController extends BaseController
public function actionUserAsset() public function actionUserAsset()
{ {
$platform_id = Yii::$app->request->getPlatformId(); $platform_id = Yii::$app->request->getPlatformId();
$node_params = Yii::$app->params['trusteeship']['node_'. $platform_id]; $node_params = Yii::$app->params['trusteeship']['node_' . $platform_id];
$uid = Yii::$app->request->get('uid', ''); $uid = Yii::$app->request->get('uid', '');
$params = [ $params = [
'uid' => $uid 'uid' => $uid
...@@ -101,4 +104,66 @@ class WalletController extends BaseController ...@@ -101,4 +104,66 @@ class WalletController extends BaseController
return ['code' => 1, 'data' => $result['msg'], 'msg' => 'success']; return ['code' => 1, 'data' => $result['msg'], 'msg' => 'success'];
} }
public function actionCurrency()
{
$code = 0;
$msg = 'success';
$data = null;
$current_platform_id = Yii::$app->request->getPlatformId();
if (Yii::$app->request->isGet) {
if (1 === $current_platform_id) {
$platform_id = Yii::$app->request->get('platform_id', 1);
$platform_id = empty($platform_id) ? 1 : $platform_id;
} else {
$platform_id = Yii::$app->request->getPlatformId();
}
$coin_currency = CoinCurrency::find()->select('id, pj_name')->asArray()->all();
$coin_supported_currency = CoinSupportedCurrency::find()->where(['platform_id' => $platform_id])->asArray()->all();
$coin_supported_currency_id = ArrayHelper::getColumn($coin_supported_currency, 'currency_id');
foreach ($coin_currency as &$val) {
$val['checked'] = false;
if (in_array($val["id"], $coin_supported_currency_id)) {
$val['checked'] = true;
}
}
$data = $coin_currency;
goto doEnd;
}
if (Yii::$app->request->isPut) {
$params = Yii::$app->request->post();
$currency_ids = isset($params['currency_id']) ? $params['currency_id'] : null;
if (false == $currency_ids) {
$msg = '参数错误';
$code = -1;
goto doEnd;
}
CoinSupportedCurrency::deleteAll(['in', 'platform_id', $current_platform_id]);
$currency_id_arr = explode(',', $currency_ids);
foreach ($currency_id_arr as $val) {
$datas[] = [
$current_platform_id, (int)$val
];
}
CoinSupportedCurrency::loadArray($datas);
goto doEnd;
}
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
public function actionCurrencyUpdate()
{
$currency_model = CoinSupportedCurrency::find()->groupBy('currency_id')->all();
$pj_id = [];
foreach ($currency_model as $val) {
$pj_id[] = $val->currency->pj_id;
}
}
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment