Commit d3bd85bc authored by shajiaming's avatar shajiaming

逻辑调整

parent 4ebc2a70
......@@ -77,52 +77,83 @@ class WalletChainController extends BaseController
public function actionChain()
{
$request = Yii::$app->request;
if (!$request->isPost) {
$this->code = -1;
$this->msg = '请求方式错误!';
goto doEnd;
}
$post = $request->post();
$model = new CoinPlatformWithHold();
$model->setScenario(CoinPlatformWithHold::SCENARIOS_CREATE);
$params = [
'platform' => isset($post['platform']) ? $post['platform'] : '',
'address' => isset($post['address']) ? $post['address'] : '',
'private_key' => isset($post['private_key']) ? $post['private_key'] : '',
'token' => isset($post['token']) ? strtoupper($post['token']) : '',
'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,
'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;
$this->code = -1;
goto doEnd;
}
$id = Yii::$app->p_sources->getLastInsertID();
$node_params = Yii::$app->params['para'];
$service = new Chain33Service($node_params);
$result = $service->addPara($params['platform'], $params['host'] . ':' . $params['port']);
if (0 != $result['code']) {
$this->code = $result['code'];
$this->msg = $result['msg'];
if ($request->isPost) {
$model = new CoinPlatformWithHold();
$model->setScenario(CoinPlatformWithHold::SCENARIOS_CREATE);
$params = [
'platform' => isset($post['platform']) ? $post['platform'] : '',
'address' => isset($post['address']) ? $post['address'] : '',
'private_key' => isset($post['private_key']) ? $post['private_key'] : '',
'token' => isset($post['token']) ? strtoupper($post['token']) : '',
'host' => isset($post['host']) ? $post['host'] : '',
'port' => isset($post['port']) ? $post['port'] : '',
'wallet_address' => isset($post['wallet_address']) ? $post['wallet_address'] : '',
'status' => CoinPlatformWithHold::STATUS_UNPAID,
'origin' => CoinPlatformWithHold::ORIGIN_USER,
'fee' => isset($post['fee']) ? $post['fee'] : '',
'exer' => 'user.p.' . (isset($post['platform']) ? $post['platform'] : '')
];
if ($model->load($params, '') && !$model->validate()) {
$errors = '';
foreach ($model->errors as $error) {
$errors .= $error[0];
}
$this->msg = $errors;
$this->code = -1;
goto doEnd;
}
$node_params = Yii::$app->params['para'];
$service = new Chain33Service($node_params);
$result = $service->addPara($params['platform'], $params['host'] . ':' . $params['port']);
if (0 != $result['code']) {
$this->code = $result['code'];
$this->msg = $result['msg'];
goto doEnd;
}
$model->save();
$this->data = (int)Yii::$app->p_sources->getLastInsertID();
goto doEnd;
}
$this->syncCoin(['platform' => $params['platform'], 'token' => $params['token']]);
$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