Commit da76d9eb authored by shajiaiming's avatar shajiaiming

fix

parent 64ae6e97
...@@ -62,12 +62,22 @@ class AirDropController extends BaseController ...@@ -62,12 +62,22 @@ class AirDropController extends BaseController
]; ];
} }
if (Yii::$app->request->isPut) { doEnd :
return ['code' => $this->code, 'msg' => $this->msg, 'data' => $this->data];
}
public function actionBatchDraw()
{
if (!Yii::$app->request->isPost) {
$this->code = -1;
$this->msg = '请求方式错误!';
goto doEnd;
}
$data = Yii::$app->request->post(); $data = Yii::$app->request->post();
$id = $data['id'] ?? '';
$identifier = $data['identifier'] ?? ''; $identifier = $data['identifier'] ?? '';
$miner_address = $data['miner_address'] ?? ''; $miner_address = $data['miner_address'] ?? '';
if (false == $id || false == $identifier || false == $miner_address) { if (false == $identifier || false == $miner_address) {
$this->code = -1; $this->code = -1;
$this->msg = 'Validation failed.'; $this->msg = 'Validation failed.';
goto doEnd; goto doEnd;
...@@ -80,19 +90,15 @@ class AirDropController extends BaseController ...@@ -80,19 +90,15 @@ class AirDropController extends BaseController
goto doEnd; goto doEnd;
} }
$record = AirDropApplyRecord::find()->where(['id' => $id, 'reach' => AirDropApplyRecord::REACH_YES, 'draw_status' => AirDropApplyRecord::STATUS_UNDRAW])->one(); $record = AirDropApplyRecord::find()->where(['apply_id' => $model['id'], 'reach' => AirDropApplyRecord::REACH_YES, 'draw_status' => AirDropApplyRecord::STATUS_UNDRAW])->all();
if (empty($record)) { if (empty($record)) {
$this->code = -1; $this->code = -1;
$this->msg = '暂无符合条件的领取记录'; $this->msg = '暂无符合条件的领取记录';
goto doEnd; goto doEnd;
} }
foreach ($record as $val) {
$record->draw_status = AirDropApplyRecord::STATUS_DRAWING; $val->draw_status = AirDropApplyRecord::STATUS_DRAWING;
if (false == $record->save()) { $val->save();
$this->code = -1;
$this->msg = $record->errors;
goto doEnd;
}
} }
doEnd : doEnd :
...@@ -101,11 +107,17 @@ class AirDropController extends BaseController ...@@ -101,11 +107,17 @@ class AirDropController extends BaseController
public function actionDraw() public function actionDraw()
{ {
if (Yii::$app->request->isPost) { if (!Yii::$app->request->isPost) {
$this->code = -1;
$this->msg = '请求方式错误!';
goto doEnd;
}
$data = Yii::$app->request->post(); $data = Yii::$app->request->post();
$id = $data['id'] ?? '';
$identifier = $data['identifier'] ?? ''; $identifier = $data['identifier'] ?? '';
$miner_address = $data['miner_address'] ?? ''; $miner_address = $data['miner_address'] ?? '';
if (false == $identifier || false == $miner_address) { if (false == $id || false == $identifier || false == $miner_address) {
$this->code = -1; $this->code = -1;
$this->msg = 'Validation failed.'; $this->msg = 'Validation failed.';
goto doEnd; goto doEnd;
...@@ -118,16 +130,18 @@ class AirDropController extends BaseController ...@@ -118,16 +130,18 @@ class AirDropController extends BaseController
goto doEnd; goto doEnd;
} }
$record = AirDropApplyRecord::find()->where(['apply_id' => $model['id'], 'reach' => AirDropApplyRecord::REACH_YES, 'draw_status' => AirDropApplyRecord::STATUS_UNDRAW])->all(); $record = AirDropApplyRecord::find()->where(['id' => $id, 'reach' => AirDropApplyRecord::REACH_YES, 'draw_status' => AirDropApplyRecord::STATUS_UNDRAW])->one();
if (empty($record)) { if (empty($record)) {
$this->code = -1; $this->code = -1;
$this->msg = '暂无符合条件的领取记录'; $this->msg = '暂无符合条件的领取记录';
goto doEnd; goto doEnd;
} }
foreach ($record as $val) {
$val->draw_status = AirDropApplyRecord::STATUS_DRAWING; $record->draw_status = AirDropApplyRecord::STATUS_DRAWING;
$val->save(); 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