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