Commit da1f11fb authored by shajiaiming's avatar shajiaiming

fix

parent 573eb440
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
namespace api\controllers; namespace api\controllers;
use Yii; use Yii;
use api\base\BaseController;
use common\models\psources\CoinIssueCoin;
class IssueCoinController extends BaseController class IssueCoinController extends BaseController
{ {
...@@ -12,32 +14,55 @@ class IssueCoinController extends BaseController ...@@ -12,32 +14,55 @@ class IssueCoinController extends BaseController
* @throws \yii\base\Exception * @throws \yii\base\Exception
* @throws \yii\base\InvalidConfigException * @throws \yii\base\InvalidConfigException
*/ */
public function actionList() public function actionIssueApply()
{ {
$platform_id = Yii::$app->request->getPlatformId(); $model = new CoinIssueCoin();
if (1 === $platform_id) {
$platforms = CoinPlatform::find()->select('id, name')->asArray()->all(); $model->setScenario(CoinIssueCoin::SCENARIOS_CREATE);
} else {
$platforms = CoinPlatform::find()->select('id, name')->where(['id' => $platform_id])->asArray()->all(); if (!Yii::$app->request->isPost) {
$msg = '错误的请求方式';
$code = -1;
goto doEnd;
} }
$data = Yii::$app->request->post();
$data = [
'name' => isset($data['name']) ? $data['name'] : '',
'symbol' => isset($data['symbol']) ? strtoupper($data['symbol']) : '',
'total' => isset($data['total']) ? $data['total'] : '',
'owner' => isset($data['owner']) ? $data['owner'] : '',
'introduction' => isset($data['introduction']) ? $data['introduction'] : '',
'category' => isset($data['category']) ? $data['category'] : 0,
'platform_id' => isset($data['platform_id']) ? $data['platform_id'] : '',
'chain_id' => isset($data['chain_id']) ? $data['chain_id'] : ''
];
$model->load($data, '');
if (!$model->save()) {
$msg = current($model->firstErrors);
$code = -1;
goto doEnd;
}
$msg = 'ok';
$code = 0;
return ['code' => 0, 'msg' => 'ok', 'data' => $platforms]; doEnd :
return ['code' => $code, 'msg' => $msg];
} }
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);
...@@ -72,7 +97,7 @@ class IssueCoinController extends BaseController ...@@ -72,7 +97,7 @@ class IssueCoinController 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
......
<?php <?php
namespace common\models; namespace common\models\psources;
use Yii; use Yii;
use yii\db\Expression; use yii\db\Expression;
...@@ -10,11 +10,41 @@ class CoinIssueCoin extends CommonActiveRecord ...@@ -10,11 +10,41 @@ class CoinIssueCoin extends CommonActiveRecord
const STATUS_SUCCESS = 1; //发行成功 const STATUS_SUCCESS = 1; //发行成功
const STATUS_FAIL = 0; //发行失败 const STATUS_FAIL = 0; //发行失败
//定义场景
const SCENARIOS_CREATE = 'create';
const SCENARIOS_UPDATE = 'update';
public static function getDb() public static function getDb()
{ {
return Yii::$app->get('p_sources'); return Yii::$app->get('p_sources');
} }
public static function tableName()
{
return '{{%coin_issue_coin}}';
}
public function rules()
{
return [
[['name', 'symbol', 'total', 'owner', 'introduction', 'category', 'platform_id', 'chain_id'], 'required'],
[['total', 'category', 'platform_id', 'chain_id'], 'integer'],
['introduction', 'string', 'length' => [1, 20]],
['symbol', 'string', 'length' => [1, 20]],
['name', 'string', 'length' => [1, 6]],
['symbol', 'unique'],
];
}
public function scenarios()
{
$scenarios = [
self:: SCENARIOS_CREATE => ['name', 'symbol', 'total', 'owner', 'introduction', 'category', 'platform_id', 'chain_id'],
self:: SCENARIOS_UPDATE => ['name', 'symbol', 'total', 'owner', 'introduction', 'category', 'platform_id', 'chain_id'],
];
return array_merge(parent:: scenarios(), $scenarios);
}
public function fields() public function fields()
{ {
return [ return [
...@@ -28,11 +58,6 @@ class CoinIssueCoin extends CommonActiveRecord ...@@ -28,11 +58,6 @@ class CoinIssueCoin extends CommonActiveRecord
]; ];
} }
public static function tableName()
{
return '{{%coin_issue_coin}}';
}
public function attributeLabels() public function attributeLabels()
{ {
return [ return [
...@@ -42,8 +67,7 @@ class CoinIssueCoin extends CommonActiveRecord ...@@ -42,8 +67,7 @@ class CoinIssueCoin extends CommonActiveRecord
'owner' => '接收地址', 'owner' => '接收地址',
'introduction' => 'Token简介', 'introduction' => 'Token简介',
'category' => '是否增加发', 'category' => '是否增加发',
'chain_id' => '平行链名称', 'chain_id' => '平行链名称'
'msg' =>'失败原因'
]; ];
} }
......
<?php <?php
namespace common\models; namespace common\models\psources;
use yii\base\Model; use yii\base\Model;
...@@ -30,14 +30,34 @@ class CoinIssueCoinForm extends Model ...@@ -30,14 +30,34 @@ class CoinIssueCoinForm extends Model
const SCENARIOS_CREATE = 'create'; const SCENARIOS_CREATE = 'create';
const SCENARIOS_UPDATE = 'update'; const SCENARIOS_UPDATE = 'update';
public static function getDb()
{
return \Yii::$app->get('p_sources');
}
public function rules() public function rules()
{ {
return [ return [
[['name', 'symbol', 'total', 'owner', 'introduction', 'category', 'platform_id', 'chain_id'], 'required'], [['name', 'symbol', 'total', 'owner', 'introduction', 'category', 'platform_id', 'chain_id'], 'required'],
[['total', 'category', 'platform_id', 'chain_id'], 'integer'], [['total', 'category', 'platform_id', 'chain_id'], 'integer'],
['introduction', 'string', 'length' => [1, 20]],
['symbol', 'string', 'length' => [1, 20]],
['name', 'string', 'length' => [1, 6]],
['symbol', 'unique'],
[['total'], 'issuableAmout']
]; ];
} }
public function isExist($attribute, $params)
{
var_dump($attribute, $params);exit;
}
public function issuableAmout($attribute, $params)
{
return true;
}
public function scenarios() public function scenarios()
{ {
$scenarios = [ $scenarios = [
...@@ -68,7 +88,7 @@ class CoinIssueCoinForm extends Model ...@@ -68,7 +88,7 @@ class CoinIssueCoinForm extends Model
public function getIssueList($id) public function getIssueList($id)
{ {
$this->_issue_coin_list = CoinIssueCoinForm::find() $this->_issue_coin_list = CoinIssueCoin::find()
->where('agent_id = :agent_id', [':agent_id' => $id]) ->where('agent_id = :agent_id', [':agent_id' => $id])
->one(); ->one();
...@@ -92,17 +112,16 @@ class CoinIssueCoinForm extends Model ...@@ -92,17 +112,16 @@ class CoinIssueCoinForm extends Model
{ {
if ($this->validate()) { if ($this->validate()) {
if ($this->getIsNewRecord()) { if ($this->getIsNewRecord()) {
$this->_issue_coin_list = new Agent(); $this->_issue_coin_list = new CoinIssueCoin();
$isNew = true;
} else {
$isNew = false;
} }
$this->_issue_coin_list->agent_id = $this->agent_id; $this->_issue_coin_list->name = $this->name;
$this->_issue_coin_list->title = $this->title; $this->_issue_coin_list->symbol = $this->symbol;
$this->_issue_coin_list->etitle = $this->etitle; $this->_issue_coin_list->total = $this->total;
$this->_issue_coin_list->description = $this->description; $this->_issue_coin_list->owner = $this->owner;
$this->_issue_coin_list->requirement = $this->requirement; $this->_issue_coin_list->introduction = $this->introduction;
$this->_issue_coin_list->status = $this->status; $this->_issue_coin_list->category = $this->category;
$this->_issue_coin_list->platform_id = $this->platform_id;
$this->_issue_coin_list->chain_id = $this->chain_id;
return $this->_issue_coin_list->save(); return $this->_issue_coin_list->save();
......
<?php <?php
namespace common\models; namespace common\models\psources;
use Yii; use Yii;
use yii\db\ActiveRecord; use yii\db\ActiveRecord;
......
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