Commit e3005072 authored by shajiaiming's avatar shajiaiming

a

parent 4a49d213
......@@ -4,6 +4,7 @@ namespace api\controllers;
use common\components\ErrorMessage;
use common\models\psources\CoinIssueRevokeRecord;
use common\models\psources\CoinIssueTemplate;
use common\service\chain33\Chain33Service;
use Yii;
use yii\data\Pagination;
......@@ -42,7 +43,7 @@ class IssueCoinController extends BaseController
goto doEnd;
}
$result = [
$params = [
'name' => isset($result['name']) ? $result['name'] : '',
'symbol' => isset($result['symbol']) ? $result['symbol'] : '',
'total' => isset($result['total']) ? $result['total'] : '',
......@@ -59,12 +60,13 @@ class IssueCoinController extends BaseController
];
$model = new CoinIssueCoin();
if (35 == $platform_id) {
$params['template'] = isset($result['template']) ? $result['template'] : [];
$model->setScenario(CoinIssueCoin::SCENARIOS_CREATE_MALL);
} else {
$model->setScenario(CoinIssueCoin::SCENARIOS_CREATE);
}
$model->load($result, '');
$model->load($params, '');
if (!$model->validate()) {
$msg = $model->errors;
$code = -1;
......@@ -122,7 +124,7 @@ class IssueCoinController extends BaseController
$code = -1;
goto doEnd;
}
$result = [
$params = [
'name' => isset($result['name']) ? $result['name'] : '',
'symbol' => isset($result['symbol']) ? strtoupper($result['symbol']) : '',
'total' => isset($result['total']) ? $result['total'] : '',
......@@ -139,6 +141,7 @@ class IssueCoinController extends BaseController
];
$model = new CoinIssueCoin();
if (35 == $platform_id) {
$params['template'] = isset($result['template']) ? $result['template'] : [];
$model->setScenario(CoinIssueCoin::SCENARIOS_CREATE_MALL);
} else {
$model->setScenario(CoinIssueCoin::SCENARIOS_CREATE);
......@@ -152,6 +155,12 @@ class IssueCoinController extends BaseController
$msg = 'ok';
$code = 0;
$data = $model->getPrimaryKey();
if (35 == $platform_id) {
$template = new CoinIssueTemplate();
$template->issue_coin_id = $data;
$template->template = isset($result['template']) ? $result['template'] : [];
$template->save();
}
$params = [
'pre_create_tx' => $pre_create_tx,
......@@ -245,6 +254,7 @@ class IssueCoinController extends BaseController
$data->total = (int)$data->total * 1e4;
$data->chain_name = $data->chain->platform;
$data->issue_charge = rtrim(sprintf('%.3f', floatval($data->charge)), '0');
$data->template = isset($data->templated->template) ? $data->templated->template : [];
$code = 0;
$msg = 'success';
if (CoinIssueCoin::STATUS_FAILED == $data->status) {
......@@ -262,7 +272,6 @@ class IssueCoinController extends BaseController
$msg = '发行失败。失败原因:' . $data->transfer->finish_query_transaction;
}
if (CoinIssueCoin::STATUS_CANCEL_FAILED == $data->status) {
$code = -1;
$msg = '撤消失败。失败原因:' . ErrorMessage::getMessage($data->revoke->revoke_query_transaction);
......@@ -472,4 +481,34 @@ class IssueCoinController extends BaseController
doEnd :
return ['code' => $code, 'msg' => $msg];
}
public function actionSymbolValidate()
{
$code = 0;
$msg = 'success';
$symbol = Yii::$app->request->post('symbol', '');
if (false == $symbol) {
$msg = '缺少必要的参数';
$code = -1;
$data = null;
goto doEnd;
}
$model = CoinIssueCoin::find()->where(['symbol' => $symbol, 'platform_id' => 35])->asArray()->one();
if (empty($model)) {
$data = $symbol;
goto doEnd;
}
$data = $model['symbol'];
$suffix = substr($data, -1);
if (is_numeric($suffix)) {
$prefix = substr($data, 0, -1);
$data = $prefix . ($suffix + 1);
} else {
$data = $data . 1;
}
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
}
\ No newline at end of file
......@@ -47,13 +47,14 @@ class CoinIssueCoin extends CommonActiveRecord
public function rules()
{
return [
[['name', 'symbol', 'total', 'owner', 'introduction', 'category', 'type', 'platform_id', 'chain_id', 'charge_unit', 'charge'], 'required'],
[['name', 'symbol', 'total', 'owner', 'introduction', 'category', 'type', 'platform_id', 'chain_id', 'charge_unit', 'charge', 'template'], 'required'],
[['total', 'category', 'type', 'platform_id', 'chain_id'], 'integer'],
[['introduction', 'charge_unit'], 'string', 'length' => [1, 20]],
['symbol', 'string', 'length' => [6, 128]],
['name', 'string', 'length' => [3, 50]],
['nickname', 'string', 'length' => [0, 10]],
[['token_type', 'nickname'], 'safe'],
['template', 'verfiyTemplate'],
#['status', 'in', 'range' => [1, 2, 0]],
['name', 'verfiyName'],
['symbol', 'verfiySymbol'],
......@@ -65,13 +66,29 @@ class CoinIssueCoin extends CommonActiveRecord
{
$scenarios = [
self:: SCENARIOS_CREATE => ['name', 'symbol', 'total', 'owner', 'introduction', 'category', 'type', 'platform_id', 'chain_id', 'charge_unit', 'charge', 'token_type', 'nickname'],
self:: SCENARIOS_CREATE_MALL => ['name', 'symbol', 'total', 'owner', 'introduction', 'category', 'type', 'platform_id', 'chain_id', 'token_type', 'nickname'],
self:: SCENARIOS_CREATE_MALL => ['name', 'symbol', 'total', 'owner', 'introduction', 'category', 'type', 'platform_id', 'chain_id', 'token_type', 'nickname', 'template'],
self:: SCENARIOS_UPDATE => ['status'],
self:: SCENARIOS_CANCEL => ['status'],
];
return array_merge(parent:: scenarios(), $scenarios);
}
public function verfiyTemplate($attribute, $params)
{
if (3 == $this->token_type) {
if (empty($this->template)) {
$this->addError($attribute, '缺少必要的模板参数');
return false;
}
foreach ($this->template as $key => $val) {
if (empty($val)) {
$this->addError($attribute, $key . '不能为空');
return false;
}
}
}
}
public function verfiyName($attribute, $params)
{
//增发
......@@ -159,12 +176,13 @@ class CoinIssueCoin extends CommonActiveRecord
'msg' => '失败原因',
'status' => '状态',
'charge_unit' => '手续费',
'template' => '模板',
];
}
public function attributes()
{
return array_merge(parent::attributes(), ['issue_charge', 'url', 'chain_name']);
return array_merge(parent::attributes(), ['issue_charge', 'url', 'chain_name', 'template']);
}
public function getChain()
......@@ -186,4 +204,9 @@ class CoinIssueCoin extends CommonActiveRecord
{
return $this->hasOne(CoinIssueRevokeRecord::className(), ['issue_coin_id' => 'id']);
}
public function getTemplated()
{
return $this->hasOne(CoinIssueTemplate::className(), ['issue_coin_id' => 'id'])->select('template');
}
}
\ No newline at end of file
<?php
namespace common\models\psources;
use Yii;
use yii\db\Expression;
class CoinIssueTemplate extends CommonActiveRecord
{
public static function getDb()
{
return Yii::$app->get('p_sources');
}
public static function tableName()
{
return '{{%coin_issue_template}}';
}
public function getTransfer()
{
return $this->hasOne(CoinIssueCoin::className(), ['issue_coin_id' => '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