Commit da76d9eb authored by shajiaiming's avatar shajiaiming

fix

parent 64ae6e97
...@@ -62,37 +62,43 @@ class AirDropController extends BaseController ...@@ -62,37 +62,43 @@ class AirDropController extends BaseController
]; ];
} }
if (Yii::$app->request->isPut) { doEnd :
$data = Yii::$app->request->post(); return ['code' => $this->code, 'msg' => $this->msg, 'data' => $this->data];
$id = $data['id'] ?? ''; }
$identifier = $data['identifier'] ?? '';
$miner_address = $data['miner_address'] ?? '';
if (false == $id || false == $identifier || false == $miner_address) {
$this->code = -1;
$this->msg = 'Validation failed.';
goto doEnd;
}
$model = AirDrop::find()->select('id')->where(['identifier' => $identifier, 'miner_address' => $miner_address])->one();
if (empty($model) || empty($model->record)) { public function actionBatchDraw()
$this->code = -1; {
$this->msg = '暂无符合条件的空投申请记录'; if (!Yii::$app->request->isPost) {
goto doEnd; $this->code = -1;
} $this->msg = '请求方式错误!';
goto doEnd;
}
$record = AirDropApplyRecord::find()->where(['id' => $id, 'reach' => AirDropApplyRecord::REACH_YES, 'draw_status' => AirDropApplyRecord::STATUS_UNDRAW])->one(); $data = Yii::$app->request->post();
if (empty($record)) { $identifier = $data['identifier'] ?? '';
$this->code = -1; $miner_address = $data['miner_address'] ?? '';
$this->msg = '暂无符合条件的领取记录'; if (false == $identifier || false == $miner_address) {
goto doEnd; $this->code = -1;
} $this->msg = 'Validation failed.';
goto doEnd;
}
$model = AirDrop::find()->select('id')->where(['identifier' => $identifier, 'miner_address' => $miner_address])->one();
$record->draw_status = AirDropApplyRecord::STATUS_DRAWING; if (empty($model) || empty($model->record)) {
if (false == $record->save()) { $this->code = -1;
$this->code = -1; $this->msg = '暂无符合条件的空投申请记录';
$this->msg = $record->errors; goto doEnd;
goto doEnd; }
}
$record = AirDropApplyRecord::find()->where(['apply_id' => $model['id'], 'reach' => AirDropApplyRecord::REACH_YES, 'draw_status' => AirDropApplyRecord::STATUS_UNDRAW])->all();
if (empty($record)) {
$this->code = -1;
$this->msg = '暂无符合条件的领取记录';
goto doEnd;
}
foreach ($record as $val) {
$val->draw_status = AirDropApplyRecord::STATUS_DRAWING;
$val->save();
} }
doEnd : doEnd :
...@@ -101,33 +107,41 @@ class AirDropController extends BaseController ...@@ -101,33 +107,41 @@ class AirDropController extends BaseController
public function actionDraw() public function actionDraw()
{ {
if (Yii::$app->request->isPost) { if (!Yii::$app->request->isPost) {
$data = Yii::$app->request->post(); $this->code = -1;
$identifier = $data['identifier'] ?? ''; $this->msg = '请求方式错误!';
$miner_address = $data['miner_address'] ?? ''; goto doEnd;
if (false == $identifier || false == $miner_address) { }
$this->code = -1;
$this->msg = 'Validation failed.';
goto doEnd;
}
$model = AirDrop::find()->select('id')->where(['identifier' => $identifier, 'miner_address' => $miner_address])->one();
if (empty($model) || empty($model->record)) { $data = Yii::$app->request->post();
$this->code = -1; $id = $data['id'] ?? '';
$this->msg = '暂无符合条件的空投申请记录'; $identifier = $data['identifier'] ?? '';
goto doEnd; $miner_address = $data['miner_address'] ?? '';
} if (false == $id || false == $identifier || false == $miner_address) {
$this->code = -1;
$this->msg = 'Validation failed.';
goto doEnd;
}
$model = AirDrop::find()->select('id')->where(['identifier' => $identifier, 'miner_address' => $miner_address])->one();
$record = AirDropApplyRecord::find()->where(['apply_id' => $model['id'], 'reach' => AirDropApplyRecord::REACH_YES, 'draw_status' => AirDropApplyRecord::STATUS_UNDRAW])->all(); if (empty($model) || empty($model->record)) {
if (empty($record)) { $this->code = -1;
$this->code = -1; $this->msg = '暂无符合条件的空投申请记录';
$this->msg = '暂无符合条件的领取记录'; goto doEnd;
goto doEnd; }
}
foreach ($record as $val) { $record = AirDropApplyRecord::find()->where(['id' => $id, 'reach' => AirDropApplyRecord::REACH_YES, 'draw_status' => AirDropApplyRecord::STATUS_UNDRAW])->one();
$val->draw_status = AirDropApplyRecord::STATUS_DRAWING; if (empty($record)) {
$val->save(); $this->code = -1;
} $this->msg = '暂无符合条件的领取记录';
goto doEnd;
}
$record->draw_status = AirDropApplyRecord::STATUS_DRAWING;
if (false == $record->save()) {
$this->code = -1;
$this->msg = $record->errors;
goto doEnd;
} }
doEnd : doEnd :
......
...@@ -28,6 +28,8 @@ class AirDrop extends CommonActiveRecord ...@@ -28,6 +28,8 @@ class AirDrop extends CommonActiveRecord
[['reach_times'], 'integer'], [['reach_times'], 'integer'],
[['identifier'], 'string', 'length' => [5, 50]], [['identifier'], 'string', 'length' => [5, 50]],
[['wallet_address', 'miner_address'], 'string', 'length' => [10, 50]], [['wallet_address', 'miner_address'], 'string', 'length' => [10, 50]],
['identifier', 'unique', 'message' => '树莓派编号已存在'],
['miner_address', 'unique', 'message' => '矿工地址已存在'],
]; ];
} }
......
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