Commit 2c7661c8 authored by shajiaming's avatar shajiaming

Merge branch 'feature/issue_coin' into develop

parents eac8344b d3bd85bc
...@@ -77,12 +77,9 @@ class WalletChainController extends BaseController ...@@ -77,12 +77,9 @@ class WalletChainController extends BaseController
public function actionChain() public function actionChain()
{ {
$request = Yii::$app->request; $request = Yii::$app->request;
if (!$request->isPost) {
$this->code = -1;
$this->msg = '请求方式错误!';
goto doEnd;
}
$post = $request->post(); $post = $request->post();
if ($request->isPost) {
$model = new CoinPlatformWithHold(); $model = new CoinPlatformWithHold();
$model->setScenario(CoinPlatformWithHold::SCENARIOS_CREATE); $model->setScenario(CoinPlatformWithHold::SCENARIOS_CREATE);
$params = [ $params = [
...@@ -93,19 +90,21 @@ class WalletChainController extends BaseController ...@@ -93,19 +90,21 @@ class WalletChainController extends BaseController
'host' => isset($post['host']) ? $post['host'] : '', 'host' => isset($post['host']) ? $post['host'] : '',
'port' => isset($post['port']) ? $post['port'] : '', 'port' => isset($post['port']) ? $post['port'] : '',
'wallet_address' => isset($post['wallet_address']) ? $post['wallet_address'] : '', 'wallet_address' => isset($post['wallet_address']) ? $post['wallet_address'] : '',
'status' => CoinPlatformWithHold::STATUS_NO, 'status' => CoinPlatformWithHold::STATUS_UNPAID,
'origin' => CoinPlatformWithHold::ORIGIN_USER, 'origin' => CoinPlatformWithHold::ORIGIN_USER,
'fee' => isset($post['fee']) ? $post['fee'] : '', 'fee' => isset($post['fee']) ? $post['fee'] : '',
'hash' => isset($post['hash']) ? $post['hash'] : '',
'exer' => 'user.p.' . (isset($post['platform']) ? $post['platform'] : '') 'exer' => 'user.p.' . (isset($post['platform']) ? $post['platform'] : '')
]; ];
if ($model->load($params, '') && !$model->save()) { if ($model->load($params, '') && !$model->validate()) {
$this->msg = $model->errors; $errors = '';
foreach ($model->errors as $error) {
$errors .= $error[0];
}
$this->msg = $errors;
$this->code = -1; $this->code = -1;
goto doEnd; goto doEnd;
} }
$id = Yii::$app->p_sources->getLastInsertID();
$node_params = Yii::$app->params['para']; $node_params = Yii::$app->params['para'];
$service = new Chain33Service($node_params); $service = new Chain33Service($node_params);
...@@ -116,13 +115,45 @@ class WalletChainController extends BaseController ...@@ -116,13 +115,45 @@ class WalletChainController extends BaseController
goto doEnd; goto doEnd;
} }
$this->syncCoin(['platform' => $params['platform'], 'token' => $params['token']]); $model->save();
$this->data = (int)Yii::$app->p_sources->getLastInsertID();
goto doEnd;
}
$chain_update = CoinPlatformWithHold::find()->where(['id' => $id])->one(); if ($request->isPut) {
$chain_update->setScenario(CoinPlatformWithHold::SCENARIOS_UPDATE); $id = isset($post['id']) ? $post['id'] : 0;
$chain_update->status = CoinPlatformWithHold::STATUS_YES; $hash = isset($post['hash']) ? $post['hash'] : 0;
$chain_update->save(); if (false == $id || false == $hash) {
$this->msg = '缺少必要的参数';
$this->code = -1;
goto doEnd;
}
$model = CoinPlatformWithHold::findOne($id);
if (empty($model)) {
$this->msg = '数据不存在';
$this->code = -1;
goto doEnd;
}
$model->setScenario(CoinPlatformWithHold::SCENARIOS_UPDATE);
$params = [
'id' => $id,
'hash' => $hash,
'status' => CoinPlatformWithHold::STATUS_YES
];
if ($model->load($params, '') && !$model->save()) {
$errors = '';
foreach ($model->errors as $error) {
$errors .= $error[0];
}
$this->msg = $errors;
$this->code = -1;
goto doEnd;
}
$this->syncCoin(['platform' => $model['platform'], 'token' => $model['token']]);
}
doEnd : doEnd :
return ['code' => $this->code, 'data' => $this->data, 'msg' => $this->msg]; return ['code' => $this->code, 'data' => $this->data, 'msg' => $this->msg];
......
...@@ -16,6 +16,8 @@ class CoinPlatformWithHold extends BaseActiveRecord ...@@ -16,6 +16,8 @@ class CoinPlatformWithHold extends BaseActiveRecord
const STATUS_NO = 0; //创建失败 const STATUS_NO = 0; //创建失败
const STATUS_YES = 1; //创建成功 const STATUS_YES = 1; //创建成功
const STATUS_CREATEING = 2; //生效中
const STATUS_UNPAID = 3; //尚未支付
const ORIGIN_MANAGE = 1; //管理员创建 const ORIGIN_MANAGE = 1; //管理员创建
const ORIGIN_USER = 2; //h5用户创建 const ORIGIN_USER = 2; //h5用户创建
...@@ -43,7 +45,7 @@ class CoinPlatformWithHold extends BaseActiveRecord ...@@ -43,7 +45,7 @@ class CoinPlatformWithHold extends BaseActiveRecord
public function rules() public function rules()
{ {
return [ return [
[['platform', 'address', 'private_key', 'execer', 'exer', 'brower_url', 'token', 'host', 'wallet_address', 'status', 'port', 'fee', 'origin', 'hash'], 'required'], [['platform', 'address', 'private_key', 'execer', 'exer', 'brower_url', 'token', 'host', 'wallet_address', 'status', 'port', 'fee', 'origin'], 'required'],
[['platform', 'address', 'private_key', 'execer', 'exer', 'brower_url', 'token', 'host', 'wallet_address', 'hash'], 'string'], [['platform', 'address', 'private_key', 'execer', 'exer', 'brower_url', 'token', 'host', 'wallet_address', 'hash'], 'string'],
['address','unique','message'=>'地址已存在'], ['address','unique','message'=>'地址已存在'],
[['platform'], 'string', 'length' => [1, 30]], [['platform'], 'string', 'length' => [1, 30]],
...@@ -57,7 +59,7 @@ class CoinPlatformWithHold extends BaseActiveRecord ...@@ -57,7 +59,7 @@ class CoinPlatformWithHold extends BaseActiveRecord
{ {
$scenarios = [ $scenarios = [
self:: SCENARIOS_CREATE => ['platform', 'token', 'address', 'private_key', 'fee', 'host', 'port', 'wallet_address', 'status', 'origin', 'hash', 'exer'], self:: SCENARIOS_CREATE => ['platform', 'token', 'address', 'private_key', 'fee', 'host', 'port', 'wallet_address', 'status', 'origin', 'hash', 'exer'],
self:: SCENARIOS_UPDATE => ['status'], self:: SCENARIOS_UPDATE => ['id', 'hash', 'status'],
]; ];
return array_merge(parent:: scenarios(), $scenarios); return array_merge(parent:: scenarios(), $scenarios);
} }
......
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