Commit edd1d8d6 authored by shajiaiming's avatar shajiaiming

fix

parent 60312f92
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace api\controllers; namespace api\controllers;
use common\models\psources\Coin;
use Yii; use Yii;
use api\base\BaseController; use api\base\BaseController;
use common\models\psources\CoinPlatform; use common\models\psources\CoinPlatform;
...@@ -35,7 +36,10 @@ class IssueChainController extends BaseController ...@@ -35,7 +36,10 @@ class IssueChainController extends BaseController
foreach ($chain_model as &$val) { foreach ($chain_model as &$val) {
$val->chain_name = isset($val->chain->platform) ? $val->chain->platform : ''; $val->chain_name = isset($val->chain->platform) ? $val->chain->platform : '';
$val->issue_charge = (float)sprintf("%0.3f", $val->issue_charge); $val->issue_charge = (float)sprintf("%0.3f", $val->issue_charge);
$val->charge_unit = isset($val->gas->coin_name) ? $val->gas->coin_name : ''; $val->exer = isset($val->chain->exer) ? $val->chain->exer : '';
$coin_model = Coin::find()->select('name')->where(['name' => strtoupper($val->charge_unit), 'platform' => $val->chain_name, 'treaty' => 2])->one();
$val->tokens = empty($coin_model) ? false : true;
unset($val->download_url); unset($val->download_url);
unset($val->introduce); unset($val->introduce);
unset($val->create_time); unset($val->create_time);
......
...@@ -179,11 +179,6 @@ class CoinIssueCoin extends CommonActiveRecord ...@@ -179,11 +179,6 @@ class CoinIssueCoin extends CommonActiveRecord
return $this->hasOne(CoinPlatform::className(), ['id' => 'platform_id']); return $this->hasOne(CoinPlatform::className(), ['id' => 'platform_id']);
} }
public function getGas()
{
return $this->hasOne(CoinSupportedCoin::className(), ['id' => 'charge_unit_id']);
}
public function getTransfer() public function getTransfer()
{ {
return $this->hasOne(CoinIssueChainRecord::className(), ['issue_coin_id' => 'id']); return $this->hasOne(CoinIssueChainRecord::className(), ['issue_coin_id' => 'id']);
......
...@@ -77,7 +77,7 @@ class CoinPlatform extends BaseActiveRecord ...@@ -77,7 +77,7 @@ class CoinPlatform extends BaseActiveRecord
public function attributes() public function attributes()
{ {
return array_merge(parent::attributes(), ['chain_name', 'charge_unit']); return array_merge(parent::attributes(), ['chain_name', 'charge_unit', 'tokens', 'exer']);
} }
public function getChain() public function getChain()
...@@ -85,8 +85,4 @@ class CoinPlatform extends BaseActiveRecord ...@@ -85,8 +85,4 @@ class CoinPlatform extends BaseActiveRecord
return $this->hasOne(CoinPlatformWithHold::className(), ['id' => 'chain_id']); return $this->hasOne(CoinPlatformWithHold::className(), ['id' => 'chain_id']);
} }
public function getGas()
{
return $this->hasOne(CoinSupportedCoin::className(), ['id' => 'charge_unit_id']);
}
} }
...@@ -70,4 +70,9 @@ class CoinPlatformWithHold extends BaseActiveRecord ...@@ -70,4 +70,9 @@ class CoinPlatformWithHold extends BaseActiveRecord
return ['code' => $exception->getCode(), 'message' => $exception->getMessage()]; return ['code' => $exception->getCode(), 'message' => $exception->getMessage()];
} }
} }
public function attributes()
{
return array_merge(parent::attributes(), ['tokens']);
}
} }
\ No newline at end of file
...@@ -2,7 +2,9 @@ ...@@ -2,7 +2,9 @@
namespace wallet\controllers; namespace wallet\controllers;
use common\models\psources\Coin;
use common\models\psources\CoinPlatform; use common\models\psources\CoinPlatform;
use common\models\psources\CoinPlatformWithHold;
use common\models\psources\CoinSupportedCoin; use common\models\psources\CoinSupportedCoin;
use common\service\chain33\Chain33Service; use common\service\chain33\Chain33Service;
use Yii; use Yii;
...@@ -102,10 +104,10 @@ class IssueChainController extends BaseController ...@@ -102,10 +104,10 @@ class IssueChainController extends BaseController
$result = Yii::$app->request->post(); $result = Yii::$app->request->post();
$issue_charge = isset($result['issue_charge']) ? $result['issue_charge'] : ''; $issue_charge = isset($result['issue_charge']) ? $result['issue_charge'] : '';
$charge_unit_id = isset($result['charge_unit_id']) ? strtoupper($result['charge_unit_id']) : ''; $charge_unit = isset($result['charge_unit']) ? strtoupper($result['charge_unit']) : '';
$id = isset($result['platform_id']) ? (int)$result['platform_id'] : 0; $id = isset($result['platform_id']) ? (int)$result['platform_id'] : 0;
if (false == $issue_charge || false == $charge_unit_id) { if (false == $issue_charge || false == $charge_unit) {
$msg = '提交数据有误'; $msg = '提交数据有误';
$code = -1; $code = -1;
goto doEnd; goto doEnd;
...@@ -123,7 +125,7 @@ class IssueChainController extends BaseController ...@@ -123,7 +125,7 @@ class IssueChainController extends BaseController
} }
$chain_model->issue_charge = $issue_charge; $chain_model->issue_charge = $issue_charge;
$chain_model->charge_unit_id = $charge_unit_id; $chain_model->charge_unit = $charge_unit;
if (false == $chain_model->save()) { if (false == $chain_model->save()) {
$msg = '手续费设置失败'; $msg = '手续费设置失败';
$code = -1; $code = -1;
...@@ -173,18 +175,44 @@ class IssueChainController extends BaseController ...@@ -173,18 +175,44 @@ class IssueChainController extends BaseController
public function actionGetTokens() public function actionGetTokens()
{ {
$data = null; $data = null;
$group = Yii::$app->request->getGroup();
if ('administrator' == $group) {
$chains = array_keys(Yii::$app->params['chain_nodes']);
$platform = CoinPlatformWithHold::find()->select('id, platform, exer')->where(['in', 'platform', $chains])->all();
$execer = \Yii::$app->request->post('execer', 'token'); } else {
$node = Yii::$app->params['chain_nodes']['STO']; $platform_id = Yii::$app->request->getPlatformId();
$service = new Chain33Service($node); $chain_model = CoinPlatform::find()->select('chain_id')->where(['id' => $platform_id])->andWhere(['<>', 'chain_id', 0])->one();
$funcName = 'GetTokens'; $platform = CoinPlatformWithHold::find()->select('id, platform, exer')->where(['id' => $chain_model->chain_id])->all();
$result = $service->getTokens('user.p.daitao.token', $funcName);
echo json_encode($result);exit; }
foreach ($platform as $val) {
$val->tokens = [];
if (!empty($val->exer)) {
$node = Yii::$app->params['chain_nodes'][strtoupper($val->platform)];
$service = new Chain33Service($node);
$funcName = 'GetTokens';
$result = $service->getTokens($val->exer, $funcName);
if (isset($result['code']) && 0 == $result['code']) {
$symbol = [];
foreach ($result['result']['tokens'] as $temp) {
$symbol[] = $temp['symbol'];
}
}
$coin_model = Coin::find()->select('name')->where(['platform' => $val->platform, 'treaty' => 2])->one();
if (!empty($coin_model)) {
array_unshift($symbol, $coin_model->name);
}
array_unshift($symbol, 'BTY');
$val->tokens = $symbol;
}
}
$data = $platform;
$code = 0; $code = 0;
$msg = 'success'; $msg = 'success';
doEnd : doEnd :
return ['code' => $code, 'msg' => $msg]; return ['code' => $code, 'msg' => $msg, 'data' => $data];
} }
} }
\ 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