Commit edae5b99 authored by shajiaiming's avatar shajiaiming

Merge branch 'feature/issue_coin' into 'master'

Feature/issue coin See merge request !225
parents fbe46201 2993cce3
...@@ -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,17 @@ class IssueChainController extends BaseController ...@@ -35,7 +36,17 @@ 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 : ''; $coin_model = Coin::find()->select('name, treaty')->where(['name' => strtoupper($val->charge_unit), 'platform' => $val->chain_name, 'treaty' => 2])->one();
$val->tokens = empty($coin_model) ? false : true;
if (empty($coin_model)) {
$val->exer = isset($val->chain->exer) ? $val->chain->exer : '';
} else {
if (1 == $coin_model->treaty) {
$val->exer = 'user.p.' . $val->chain->platform . '.token';
} else {
$val->exer = 'user.p.' . $val->chain->platform . '.coins';
}
}
unset($val->download_url); unset($val->download_url);
unset($val->introduce); unset($val->introduce);
unset($val->create_time); unset($val->create_time);
......
...@@ -52,7 +52,7 @@ class IssueCoinController extends BaseController ...@@ -52,7 +52,7 @@ class IssueCoinController extends BaseController
'type' => isset($result['type']) ? $result['type'] : 0, 'type' => isset($result['type']) ? $result['type'] : 0,
'platform_id' => $platform_id, 'platform_id' => $platform_id,
'chain_id' => $chain_id, 'chain_id' => $chain_id,
'charge_unit_id' => isset($result['charge_unit_id']) ? $result['charge_unit_id'] : '', 'charge_unit' => isset($result['charge_unit']) ? $result['charge_unit'] : '',
'charge' => $coin_platform->issue_charge, 'charge' => $coin_platform->issue_charge,
]; ];
$model = new CoinIssueCoin(); $model = new CoinIssueCoin();
...@@ -129,8 +129,8 @@ class IssueCoinController extends BaseController ...@@ -129,8 +129,8 @@ class IssueCoinController extends BaseController
'type' => isset($result['type']) ? $result['type'] : 0, 'type' => isset($result['type']) ? $result['type'] : 0,
'platform_id' => $platform_id, 'platform_id' => $platform_id,
'chain_id' => $chain_id, 'chain_id' => $chain_id,
'charge_unit_id' => isset($result['charge_unit_id']) ? $result['charge_unit_id'] : '', 'charge_unit' => isset($result['charge_unit']) ? $result['charge_unit'] : '',
'charge' => $coin_platform->issue_charge, 'charge' => (CoinIssueCoin::TYPE_NO == $result['type']) ? $coin_platform->issue_charge : 0,
]; ];
$model->load($result, ''); $model->load($result, '');
if (!$model->save()) { if (!$model->save()) {
...@@ -234,7 +234,6 @@ class IssueCoinController extends BaseController ...@@ -234,7 +234,6 @@ class IssueCoinController extends BaseController
$data->total = (int)$data->total * 1e8; $data->total = (int)$data->total * 1e8;
$data->chain_name = $data->chain->platform; $data->chain_name = $data->chain->platform;
$data->issue_charge = rtrim(sprintf('%.3f', floatval($data->charge)), '0'); $data->issue_charge = rtrim(sprintf('%.3f', floatval($data->charge)), '0');
$data->charge_unit = isset($data->gas->coin_name) ? $data->gas->coin_name : '';
$code = 0; $code = 0;
$msg = 'success'; $msg = 'success';
if (CoinIssueCoin::STATUS_FAILED == $data->status) { if (CoinIssueCoin::STATUS_FAILED == $data->status) {
......
...@@ -3,9 +3,11 @@ ...@@ -3,9 +3,11 @@
namespace api\controllers; namespace api\controllers;
use api\base\BaseController; use api\base\BaseController;
use common\models\psources\Coin;
use common\models\psources\CoinAirDropTrade; use common\models\psources\CoinAirDropTrade;
use common\models\psources\CoinIssueTransfer; use common\models\psources\CoinIssueTransfer;
use common\models\psources\CoinPlatform; use common\models\psources\CoinPlatform;
use common\models\psources\CoinPlatformWithHold;
use common\service\chain33\Chain33Service; use common\service\chain33\Chain33Service;
use Yii; use Yii;
...@@ -82,17 +84,57 @@ class WalletController extends BaseController ...@@ -82,17 +84,57 @@ class WalletController extends BaseController
$msg = 'success'; $msg = 'success';
$platform_id = Yii::$app->request->get('platform_id', ''); $platform_id = Yii::$app->request->get('platform_id', '');
$token = Yii::$app->request->get('address', ''); $token = Yii::$app->request->get('address', '');
if (empty($platform_id) || empty($token)) { $symbol = Yii::$app->request->get('symbol', '');
if (empty($platform_id) || empty($token) || empty($symbol)) {
$msg = '参数不能为空'; $msg = '参数不能为空';
$code = -1; $code = -1;
$data = null; $data = null;
goto doEnd; goto doEnd;
} }
$node = Yii::$app->params['chain_parallel']['primary'];
$chain_model = CoinPlatform::find()->select('chain_id')->where(['id' => $platform_id])->andWhere(['<>', 'chain_id', 0])->one();
if (empty($chain_model)) {
$msg = '此功能为付费功能,有兴趣请与销售联系';
$code = -1;
goto doEnd;
}
$platform = CoinPlatformWithHold::find()->select('exer, platform')->where(['id' => $chain_model->chain_id])->one();
if (empty($platform)) {
$msg = '此功能为付费功能,有兴趣请与销售联系';
$code = -1;
goto doEnd;
}
$node = Yii::$app->params['chain_nodes'][strtoupper($platform->platform)];
if (empty($node)) {
$msg = '此功能为付费功能,有兴趣请与销售联系';
$code = -1;
goto doEnd;
}
$coin_model = Coin::find()->select('name, treaty')->where(['name' => strtoupper($symbol), 'platform' => $platform->platform])->one();
$service = new Chain33Service($node); $service = new Chain33Service($node);
$address[] = $token; $address[] = $token;
$execer = 'coins';
$result = $service->getBalance($address, $execer);
$switch = false;
if (empty($coin_model)) {
$execer = $platform->exer;
} else {
if (1 == $coin_model->treaty) {
$execer = 'user.p.' . $chain_model->chain->platform . '.token';
} else {
$execer = 'user.p.' . $chain_model->chain->platform . '.coins';
$switch = true;
}
}
if (false == $switch) {
$result = $service->getTokenBalance($address, $execer, $symbol);
} else {
$result = $service->getBalance($address, $execer);
}
if (0 !== $result['code']) { if (0 !== $result['code']) {
$msg = '当前发币人数过多,请客官稍后再试'; $msg = '当前发币人数过多,请客官稍后再试';
$code = -1; $code = -1;
......
...@@ -46,9 +46,9 @@ class CoinIssueCoin extends CommonActiveRecord ...@@ -46,9 +46,9 @@ class CoinIssueCoin extends CommonActiveRecord
public function rules() public function rules()
{ {
return [ return [
[['name', 'symbol', 'total', 'owner', 'introduction', 'category', 'type', 'platform_id', 'chain_id', 'charge_unit_id', 'charge'], 'required'], [['name', 'symbol', 'total', 'owner', 'introduction', 'category', 'type', 'platform_id', 'chain_id', 'charge_unit', 'charge'], 'required'],
[['total', 'category', 'type', 'platform_id', 'chain_id', 'charge_unit_id'], 'integer'], [['total', 'category', 'type', 'platform_id', 'chain_id'], 'integer'],
['introduction', 'string', 'length' => [1, 20]], [['introduction','charge_unit'], 'string', 'length' => [1, 20]],
['symbol', 'string', 'length' => [1, 6]], ['symbol', 'string', 'length' => [1, 6]],
['name', 'string', 'length' => [1, 20]], ['name', 'string', 'length' => [1, 20]],
#['status', 'in', 'range' => [1, 2, 0]], #['status', 'in', 'range' => [1, 2, 0]],
...@@ -61,7 +61,7 @@ class CoinIssueCoin extends CommonActiveRecord ...@@ -61,7 +61,7 @@ class CoinIssueCoin extends CommonActiveRecord
public function scenarios() public function scenarios()
{ {
$scenarios = [ $scenarios = [
self:: SCENARIOS_CREATE => ['name', 'symbol', 'total', 'owner', 'introduction', 'category', 'type', 'platform_id', 'chain_id', 'charge_unit_id', 'charge'], self:: SCENARIOS_CREATE => ['name', 'symbol', 'total', 'owner', 'introduction', 'category', 'type', 'platform_id', 'chain_id', 'charge_unit', 'charge'],
self:: SCENARIOS_UPDATE => ['status'], self:: SCENARIOS_UPDATE => ['status'],
self:: SCENARIOS_CANCEL => ['status'], self:: SCENARIOS_CANCEL => ['status'],
]; ];
...@@ -148,13 +148,13 @@ class CoinIssueCoin extends CommonActiveRecord ...@@ -148,13 +148,13 @@ class CoinIssueCoin extends CommonActiveRecord
'chain_id' => '平行链名称', 'chain_id' => '平行链名称',
'msg' => '失败原因', 'msg' => '失败原因',
'status' => '状态', 'status' => '状态',
'charge_unit_id' => '手续费', 'charge_unit' => '手续费',
]; ];
} }
public function attributes() public function attributes()
{ {
return array_merge(parent::attributes(), ['issue_charge', 'charge_unit', 'url', 'chain_name']); return array_merge(parent::attributes(), ['issue_charge', 'url', 'chain_name']);
} }
/** /**
...@@ -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()
......
...@@ -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', 'platform_id', 'issue_charge', 'charge_unit']);
}
} }
\ No newline at end of file
...@@ -260,11 +260,21 @@ class Chain33Service ...@@ -260,11 +260,21 @@ class Chain33Service
{ {
$params = [ $params = [
'addresses' => $address, 'addresses' => $address,
'execer' => $execer 'execer' => $execer,
]; ];
return $this->send($params, 'Chain33.GetBalance'); return $this->send($params, 'Chain33.GetBalance');
} }
public function getTokenBalance($address, $execer, $tokenSymbol)
{
$params = [
'addresses' => $address,
'execer' => $execer,
'tokenSymbol' => $tokenSymbol
];
return $this->send($params, 'token.GetTokenBalance');
}
public function createNoBalanceTransaction($txHex, $payAddr, $privkey) public function createNoBalanceTransaction($txHex, $payAddr, $privkey)
{ {
$params = [ $params = [
...@@ -394,6 +404,26 @@ class Chain33Service ...@@ -394,6 +404,26 @@ class Chain33Service
} }
/** /**
* 查询所有预创建的token GetTokens
* @param string $execer
* @param string $funcName
* @return array
*/
public function getTokens($execer, $funcName)
{
$params = [
'execer' => $execer,
'funcName' => $funcName,
'payload' => [
'status' => 1,
'queryAll' => true,
'symbolOnly' => true
]
];
return $this->send($params, 'Chain33.Query');
}
/**
* @param array $hashes * @param array $hashes
* @return array * @return array
*/ */
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace console\controllers; namespace console\controllers;
use common\models\psources\CoinIssueRevokeRecord; use common\models\psources\CoinIssueRevokeRecord;
use common\models\psources\CoinPlatformWithHold;
use Yii; use Yii;
use yii\console\Controller; use yii\console\Controller;
use yii\helpers\ArrayHelper; use yii\helpers\ArrayHelper;
...@@ -63,9 +64,11 @@ class IssueChainTransferController extends Controller ...@@ -63,9 +64,11 @@ class IssueChainTransferController extends Controller
return 0; return 0;
} }
$node = Yii::$app->params['chain_nodes']['STO'];
$chain_service = new Chain33Service($node);
foreach ($model as $val) { foreach ($model as $val) {
$platform = CoinPlatformWithHold::find()->select('platform')->where(['id' => $val->coin->chain_id])->one();
$node = Yii::$app->params['chain_nodes'][strtoupper($platform->platform)];
$chain_service = new Chain33Service($node);
//执行1.2构造 //执行1.2构造
$result = $chain_service->createRawTokenFinishTx($val->coin->symbol, $val->coin->owner); $result = $chain_service->createRawTokenFinishTx($val->coin->symbol, $val->coin->owner);
if (null != $result['error']) { if (null != $result['error']) {
...@@ -78,8 +81,7 @@ class IssueChainTransferController extends Controller ...@@ -78,8 +81,7 @@ class IssueChainTransferController extends Controller
} }
$txHex = $result['result']; $txHex = $result['result'];
$privkey = '8ac19c0b8858ccd6ed34e2bce0f11be2fc696e658d0b98fb1d3ef85ec5a3992c'; $privkey = Yii::$app->params['chain_nodes'][strtoupper($platform->platform)]['privkey'];
#$privkey = $val->coin->chain->private_key;
$expire = '1m'; $expire = '1m';
//执行1.2签名 //执行1.2签名
$signRawTx = $chain_service->signRawTx($privkey, $txHex, $expire); $signRawTx = $chain_service->signRawTx($privkey, $txHex, $expire);
...@@ -141,16 +143,19 @@ class IssueChainTransferController extends Controller ...@@ -141,16 +143,19 @@ class IssueChainTransferController extends Controller
return 0; return 0;
} }
$node = Yii::$app->params['chain_nodes']['STO'];
$service = new Chain33Service($node);
$current_time = time(); $current_time = time();
foreach ($model as $val) { foreach ($model as $val) {
$platform = CoinPlatformWithHold::find()->select('platform')->where(['id' => $val->coin->chain_id])->one();
$node = Yii::$app->params['chain_nodes'][strtoupper($platform->platform)];
if (1 == $step) { if (1 == $step) {
$result = $service->QueryTransaction($val->pre_send_transaction); $result = $this->queryTransaction($node, $val->pre_send_transaction);
#$result = $service->QueryTransaction($val->pre_send_transaction);
$column = 'pre_query_transaction'; $column = 'pre_query_transaction';
} }
if (2 == $step) { if (2 == $step) {
$result = $service->QueryTransaction($val->finish_send_transaction); $result = $this->queryTransaction($node, $val->finish_send_transaction);
#$result = $service->QueryTransaction($val->finish_send_transaction);
$column = 'finish_query_transaction'; $column = 'finish_query_transaction';
} }
if (isset($result['result']['actionName']) && 'unknown' == $result['result']['actionName']) { if (isset($result['result']['actionName']) && 'unknown' == $result['result']['actionName']) {
...@@ -294,7 +299,8 @@ class IssueChainTransferController extends Controller ...@@ -294,7 +299,8 @@ class IssueChainTransferController extends Controller
$service = new Chain33Service($node); $service = new Chain33Service($node);
$current_time = time(); $current_time = time();
foreach ($issue_coin_model as $val) { foreach ($issue_coin_model as $val) {
$result = $service->QueryTransaction($val->revoke->revoke_send_transaction); $result = $this->QueryTransaction($node, $val->revoke->revoke_send_transaction);
#$result = $service->QueryTransaction($val->revoke->revoke_send_transaction);
if (isset($result['result']['actionName']) && 'unknown' == $result['result']['actionName']) { if (isset($result['result']['actionName']) && 'unknown' == $result['result']['actionName']) {
$data = [ $data = [
'revoke_query_transaction' => 'success' 'revoke_query_transaction' => 'success'
...@@ -381,4 +387,22 @@ class IssueChainTransferController extends Controller ...@@ -381,4 +387,22 @@ class IssueChainTransferController extends Controller
$coin_issue_record->save(); $coin_issue_record->save();
} }
protected function queryTransaction($node_params, $send_result)
{
static $result = [];
$service = new Chain33Service($node_params);
$result = $service->QueryTransaction($send_result);
if (isset($result['result']['receipt']) && is_array($result['result']['receipt']['logs'])) {
foreach ($result['result']['receipt']['logs'] as $log) {
if (isset($log['tyName']) && 'logerr' == strtolower($log['tyName'])) {
return $result;
}
}
}
if (isset($result['result']['tx']['next'])) {
$this->queryTransaction($node_params, $result['result']['tx']['next']);
}
return $result;
}
} }
\ No newline at end of file
This diff is collapsed.
...@@ -2,8 +2,11 @@ ...@@ -2,8 +2,11 @@
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 Yii; use Yii;
use wallet\base\BaseController; use wallet\base\BaseController;
...@@ -16,12 +19,12 @@ class IssueChainController extends BaseController ...@@ -16,12 +19,12 @@ class IssueChainController extends BaseController
public function actionIndex() public function actionIndex()
{ {
$data = null; $data = null;
$platform_id = Yii::$app->request->getPlatformId(); $group = Yii::$app->request->getGroup();
if ('administrator' == $group) {
if (1 == $platform_id) { $chain_model = CoinPlatform::find()->where(['<>', 'chain_id', 0])->all();
$chain_model = CoinPlatform::find()->all();
} else { } else {
$chain_model = CoinPlatform::find()->where(['id' => $platform_id])->all(); $platform_id = Yii::$app->request->getPlatformId();
$chain_model = CoinPlatform::find()->where(['id' => $platform_id])->andWhere(['<>', 'chain_id', 0])->all();
} }
if (false == $chain_model) { if (false == $chain_model) {
...@@ -30,18 +33,24 @@ class IssueChainController extends BaseController ...@@ -30,18 +33,24 @@ class IssueChainController extends BaseController
goto doEnd; goto doEnd;
} }
foreach ($chain_model as &$val) { foreach ($chain_model as $key => $val) {
if (!isset(Yii::$app->params['chain_nodes'][strtoupper($val->chain->platform)])) {
unset($chain_model[$key]);
}
$val->chain_name = isset($val->chain->platform) ? $val->chain->platform : ''; $val->chain_name = isset($val->chain->platform) ? $val->chain->platform : '';
unset($val->download_url); unset($val->download_url);
unset($val->introduce); unset($val->introduce);
unset($val->create_time); unset($val->create_time);
unset($val->update_time); unset($val->update_time);
unset($val->chain_id); }
$data = [];
foreach ($chain_model as $val) {
$data[] = $val;
} }
$msg = 'ok'; $msg = 'ok';
$code = 0; $code = 0;
$data = $chain_model; #$data = $chain_model;
doEnd : doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data]; return ['code' => $code, 'msg' => $msg, 'data' => $data];
...@@ -97,32 +106,39 @@ class IssueChainController extends BaseController ...@@ -97,32 +106,39 @@ class IssueChainController extends BaseController
public function actionSetCharge() public function actionSetCharge()
{ {
$data = null; $data = null;
$platform_id = Yii::$app->request->getPlatformId();
$result = Yii::$app->request->post(); $result = Yii::$app->request->post();
$group = Yii::$app->request->getGroup();
if ('administrator' == $group) {
$platform_id = isset($result['platform_id']) ? (int)$result['platform_id'] : 0;
} else {
$platform_id = Yii::$app->request->getPlatformId();
}
$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;
if (false == $issue_charge || false == $charge_unit_id) { if (false == $charge_unit || false == $platform_id) {
$msg = '提交数据有误'; $msg = '提交数据有误';
$code = -1; $code = -1;
goto doEnd; goto doEnd;
} }
if (1 == $platform_id) { if (floatval($issue_charge) == 0) {
$platform_id = $id; $msg = '数量错误';
$code = -1;
goto doEnd;
} }
$chain_model = CoinPlatform::find()->where(['id' => $platform_id])->one(); $chain_model = CoinPlatform::find()->where(['id' => $platform_id])->andWhere(['<>', 'chain_id', 0])->one();
if (false == $chain_model) { if (false == $chain_model) {
$msg = '不存在的链'; $msg = '钱包尚未开通一键发币功能,不能设置手续费';
$code = -1; $code = -1;
goto doEnd; goto doEnd;
} }
$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;
...@@ -143,8 +159,8 @@ class IssueChainController extends BaseController ...@@ -143,8 +159,8 @@ class IssueChainController extends BaseController
public function actionManageReview() public function actionManageReview()
{ {
$data = null; $data = null;
$platform_id = Yii::$app->request->getPlatformId(); $group = Yii::$app->request->getGroup();
if (1 != $platform_id) { if ('administrator' != $group) {
$msg = '当前账户无权限操作'; $msg = '当前账户无权限操作';
$code = -1; $code = -1;
goto doEnd; goto doEnd;
...@@ -164,4 +180,72 @@ class IssueChainController extends BaseController ...@@ -164,4 +180,72 @@ class IssueChainController extends BaseController
return ['code' => $code, 'msg' => $msg]; return ['code' => $code, 'msg' => $msg];
} }
/**
* 查询所有预创建的token
* @param string execer
* @return array
*/
public function actionGetTokens()
{
$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();
} else {
$platform_id = Yii::$app->request->getPlatformId();
$chain_model = CoinPlatform::find()->select('chain_id')->where(['id' => $platform_id])->andWhere(['<>', 'chain_id', 0])->one();
if (empty($chain_model)) {
$msg = '尚未开通此功能';
$code = -1;
goto doEnd;
}
$platform = CoinPlatformWithHold::find()->select('id, platform, exer')->where(['id' => $chain_model->chain_id])->one();
if (empty($platform)) {
$msg = '尚未开通此功能';
$code = -1;
goto doEnd;
}
if (!isset(Yii::$app->params['chain_nodes'][strtoupper($platform->platform)])) {
$msg = '尚未开通此功能';
$code = -1;
goto doEnd;
}
$platform = array($platform);
}
foreach ($platform as $val) {
$val->tokens = [];
$symbol = [];
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']) {
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;
$val->platform_id = Yii::$app->params['chain_nodes'][strtoupper($val->platform)]['platform_id'];
}
unset($val->exer);
$coin_platform = CoinPlatform::find()->select('issue_charge, charge_unit')->where(['id' => Yii::$app->params['chain_nodes'][strtoupper($val->platform)]['platform_id']])->one();
$val->issue_charge = empty($coin_platform->issue_charge) ? '' : $coin_platform->issue_charge;
$val->charge_unit = empty($coin_platform->charge_unit) ? '' : $coin_platform->charge_unit;
}
$data = $platform;
$code = 0;
$msg = 'success';
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
} }
\ No newline at end of file
...@@ -29,12 +29,12 @@ class IssueCoinController extends BaseController ...@@ -29,12 +29,12 @@ class IssueCoinController extends BaseController
$chain_id = \Yii::$app->request->get('chain_id', ''); $chain_id = \Yii::$app->request->get('chain_id', '');
if (1 == $platform_id) { if (1 == $platform_id) {
$query = CoinIssueCoin::find() $query = CoinIssueCoin::find()
->select('id, name, total, status, chain_id, charge_unit_id, charge, platform_id, owner, category, type, symbol, introduction, create_time') ->select('id, name, total, status, chain_id, charge_unit, charge, platform_id, owner, category, type, symbol, introduction, create_time')
->where(['in', 'status', [CoinIssueCoin::STATUS_CONFIRM, CoinIssueCoin::STATUS_ALLOW, CoinIssueCoin::STATUS_REFUSE, CoinIssueCoin::STATUS_SUCCESS, CoinIssueCoin::STATUS_FAILED]]) ->where(['in', 'status', [CoinIssueCoin::STATUS_CONFIRM, CoinIssueCoin::STATUS_ALLOW, CoinIssueCoin::STATUS_REFUSE, CoinIssueCoin::STATUS_SUCCESS, CoinIssueCoin::STATUS_FAILED]])
->orderBy('create_time desc'); ->orderBy('create_time desc');
} else { } else {
$query = CoinIssueCoin::find() $query = CoinIssueCoin::find()
->select('id, name, total, status, chain_id, charge_unit_id, charge, platform_id, owner, category, type, symbol, introduction, create_time') ->select('id, name, total, status, chain_id, charge_unit, charge, platform_id, owner, category, type, symbol, introduction, create_time')
->where(['platform_id' => $platform_id]) ->where(['platform_id' => $platform_id])
->andWhere(['in', 'status', [CoinIssueCoin::STATUS_CONFIRM, CoinIssueCoin::STATUS_ALLOW, CoinIssueCoin::STATUS_REFUSE, CoinIssueCoin::STATUS_SUCCESS, CoinIssueCoin::STATUS_FAILED]]) ->andWhere(['in', 'status', [CoinIssueCoin::STATUS_CONFIRM, CoinIssueCoin::STATUS_ALLOW, CoinIssueCoin::STATUS_REFUSE, CoinIssueCoin::STATUS_SUCCESS, CoinIssueCoin::STATUS_FAILED]])
->orderBy('create_time desc'); ->orderBy('create_time desc');
...@@ -60,7 +60,6 @@ class IssueCoinController extends BaseController ...@@ -60,7 +60,6 @@ class IssueCoinController extends BaseController
foreach ($models as &$val) { foreach ($models as &$val) {
$platform = isset($val->chain->platform) ? $val->chain->platform : ''; $platform = isset($val->chain->platform) ? $val->chain->platform : '';
$val->chain_name = $platform; $val->chain_name = $platform;
$val->charge_unit = isset($val->gas->coin_name) ? $val->gas->coin_name : '';
$val->url = Yii::$app->redis->hget('platform_brower_info', $platform); $val->url = Yii::$app->redis->hget('platform_brower_info', $platform);
$val->total = (int)$val->total * 1e8; $val->total = (int)$val->total * 1e8;
} }
...@@ -98,7 +97,6 @@ class IssueCoinController extends BaseController ...@@ -98,7 +97,6 @@ class IssueCoinController extends BaseController
$platform = isset($data->chain->platform) ? $data->chain->platform : ''; $platform = isset($data->chain->platform) ? $data->chain->platform : '';
$data->total = (int)$data->total * 1e8; $data->total = (int)$data->total * 1e8;
$data->issue_charge = rtrim(sprintf('%.3f', floatval($data->charge)), '0'); $data->issue_charge = rtrim(sprintf('%.3f', floatval($data->charge)), '0');
$data->charge_unit = isset($data->gas->coin_name) ? $data->gas->coin_name : '';
$data->url = Yii::$app->redis->hget('platform_brower_info', $platform); $data->url = Yii::$app->redis->hget('platform_brower_info', $platform);
$code = 0; $code = 0;
$msg = 'success'; $msg = 'success';
......
...@@ -46,7 +46,8 @@ class UserController extends BaseController ...@@ -46,7 +46,8 @@ class UserController extends BaseController
'username' => $user->username, 'username' => $user->username,
'uid' => isset($user->bind_uid) ? $user->bind_uid : $user->uid, 'uid' => isset($user->bind_uid) ? $user->bind_uid : $user->uid,
'type' => isset($user->bind_uid) ? 2 : 1, 'type' => isset($user->bind_uid) ? 2 : 1,
'platform_id' => $user->platform_id 'platform_id' => $user->platform_id,
'group' => $user->group
]; ];
return ['code' => $code, 'msg' => $msg, 'data' => $data]; return ['code' => $code, 'msg' => $msg, 'data' => $data];
......
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