Commit da1f11fb authored by shajiaiming's avatar shajiaiming

fix

parent 573eb440
......@@ -3,6 +3,8 @@
namespace api\controllers;
use Yii;
use api\base\BaseController;
use common\models\psources\CoinIssueCoin;
class IssueCoinController extends BaseController
{
......@@ -12,32 +14,55 @@ class IssueCoinController extends BaseController
* @throws \yii\base\Exception
* @throws \yii\base\InvalidConfigException
*/
public function actionList()
public function actionIssueApply()
{
$platform_id = Yii::$app->request->getPlatformId();
if (1 === $platform_id) {
$platforms = CoinPlatform::find()->select('id, name')->asArray()->all();
} else {
$platforms = CoinPlatform::find()->select('id, name')->where(['id' => $platform_id])->asArray()->all();
$model = new CoinIssueCoin();
$model->setScenario(CoinIssueCoin::SCENARIOS_CREATE);
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()
{
$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 = empty($platform_id) ? 1 : $platform_id;
} else {
$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' => '此钱包节点尚未开通'];
}
$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);
$page = Yii::$app->request->get('page', 1);
......@@ -72,7 +97,7 @@ class IssueCoinController extends BaseController
public function actionUserAsset()
{
$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', '');
$params = [
'uid' => $uid
......
<?php
namespace common\models;
namespace common\models\psources;
use Yii;
use yii\db\Expression;
......@@ -10,11 +10,41 @@ class CoinIssueCoin extends CommonActiveRecord
const STATUS_SUCCESS = 1; //发行成功
const STATUS_FAIL = 0; //发行失败
//定义场景
const SCENARIOS_CREATE = 'create';
const SCENARIOS_UPDATE = 'update';
public static function getDb()
{
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()
{
return [
......@@ -28,11 +58,6 @@ class CoinIssueCoin extends CommonActiveRecord
];
}
public static function tableName()
{
return '{{%coin_issue_coin}}';
}
public function attributeLabels()
{
return [
......@@ -42,8 +67,7 @@ class CoinIssueCoin extends CommonActiveRecord
'owner' => '接收地址',
'introduction' => 'Token简介',
'category' => '是否增加发',
'chain_id' => '平行链名称',
'msg' =>'失败原因'
'chain_id' => '平行链名称'
];
}
......
<?php
namespace common\models;
namespace common\models\psources;
use yii\base\Model;
......@@ -30,14 +30,34 @@ class CoinIssueCoinForm extends Model
const SCENARIOS_CREATE = 'create';
const SCENARIOS_UPDATE = 'update';
public static function getDb()
{
return \Yii::$app->get('p_sources');
}
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'],
[['total'], 'issuableAmout']
];
}
public function isExist($attribute, $params)
{
var_dump($attribute, $params);exit;
}
public function issuableAmout($attribute, $params)
{
return true;
}
public function scenarios()
{
$scenarios = [
......@@ -68,7 +88,7 @@ class CoinIssueCoinForm extends Model
public function getIssueList($id)
{
$this->_issue_coin_list = CoinIssueCoinForm::find()
$this->_issue_coin_list = CoinIssueCoin::find()
->where('agent_id = :agent_id', [':agent_id' => $id])
->one();
......@@ -92,17 +112,16 @@ class CoinIssueCoinForm extends Model
{
if ($this->validate()) {
if ($this->getIsNewRecord()) {
$this->_issue_coin_list = new Agent();
$isNew = true;
} else {
$isNew = false;
$this->_issue_coin_list = new CoinIssueCoin();
}
$this->_issue_coin_list->agent_id = $this->agent_id;
$this->_issue_coin_list->title = $this->title;
$this->_issue_coin_list->etitle = $this->etitle;
$this->_issue_coin_list->description = $this->description;
$this->_issue_coin_list->requirement = $this->requirement;
$this->_issue_coin_list->status = $this->status;
$this->_issue_coin_list->name = $this->name;
$this->_issue_coin_list->symbol = $this->symbol;
$this->_issue_coin_list->total = $this->total;
$this->_issue_coin_list->owner = $this->owner;
$this->_issue_coin_list->introduction = $this->introduction;
$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();
......
<?php
namespace common\models;
namespace common\models\psources;
use Yii;
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