Commit ec71026d authored by shajiaiming's avatar shajiaiming

fix

parent aff4d514
...@@ -8,6 +8,7 @@ use common\models\psources\AirDrop; ...@@ -8,6 +8,7 @@ use common\models\psources\AirDrop;
use common\service\chain33\Chain33Service; use common\service\chain33\Chain33Service;
use common\models\psources\CoinAirDropTrade; use common\models\psources\CoinAirDropTrade;
use common\models\psources\AirDropApplyRecord; use common\models\psources\AirDropApplyRecord;
use yii\db\Exception;
class AirDropController extends BaseController class AirDropController extends BaseController
{ {
...@@ -22,13 +23,43 @@ class AirDropController extends BaseController ...@@ -22,13 +23,43 @@ class AirDropController extends BaseController
{ {
if (Yii::$app->request->isPost) { if (Yii::$app->request->isPost) {
$data = Yii::$app->request->post(); $data = Yii::$app->request->post();
$model = new AirDrop(); $create_time = date('Y-m-d');
$model->setScenario(AirDrop::SCENARIOS_CREATE); $finish_time = date('Y-m-d', strtotime("+7 day"));
if ($model->load($data, '') && $model->save()) {
$transaction = Yii::$app->db->beginTransaction();
try {
$model = new AirDrop();
$model->setScenario(AirDrop::SCENARIOS_CREATE);
$model->load($data, '');
if (!$model->validate()) {
$this->code = -1;
$this->msg = $model->errors;
goto doEnd;
}
$model->save();
$apply_id = $model->id;
$expiry_date = $this->getDatesFromRange($create_time, $finish_time);
$apply_record_model = new AirDropApplyRecord();
foreach ($expiry_date as $val) {
$apply_record_model->setIsNewRecord(true);
$apply_record_model->apply_id = $apply_id;
$apply_record_model->reach = AirDropApplyRecord::REACH_NO;
$apply_record_model->bonus_token = 3;
$apply_record_model->draw_status = AirDropApplyRecord::STATUS_UNDRAW;
$apply_record_model->create_time = $val;
$apply_record_model->update_time = $val;
$apply_record_model->save() && $apply_record_model->id = 0;;
}
$transaction->commit();
} catch (Exception $e) {
$transaction->rollback();
$this->code = -1;
$this->msg = $e->getMessage();
goto doEnd; goto doEnd;
} }
$this->code = -1;
$this->msg = $model->errors;
if (empty($this->msg)) { if (empty($this->msg)) {
$this->msg = 'Validation failed.'; $this->msg = 'Validation failed.';
} }
...@@ -63,8 +94,8 @@ class AirDropController extends BaseController ...@@ -63,8 +94,8 @@ class AirDropController extends BaseController
$apply_id_arr = explode(',', $apply_ids); $apply_id_arr = explode(',', $apply_ids);
$query->andWhere(['in', 'id', $apply_id_arr]); $query->andWhere(['in', 'id', $apply_id_arr]);
} }
// $expiry_date = date("Y-m-d", time()) . " 00:00:00"; $expiry_date = date("Y-m-d", strtotime("+1 day"));
// $query->andWhere(['<', 'create_time', $expiry_date]); $query->andWhere(['<', 'create_time', $expiry_date]);
$items = $query->offset(($page - 1) * $size)->orderBy('id desc')->limit($size)->all(); $items = $query->offset(($page - 1) * $size)->orderBy('id desc')->limit($size)->all();
$countQuery = clone $query; $countQuery = clone $query;
...@@ -310,4 +341,27 @@ class AirDropController extends BaseController ...@@ -310,4 +341,27 @@ class AirDropController extends BaseController
} }
return ['code' => 1, 'msg' => 'ok']; return ['code' => 1, 'msg' => 'ok'];
} }
function getDatesFromRange($start, $end, $format = 'Y-m-d')
{
// Declare an empty array
$array = array();
// Variable that store the date interval
// of period 1 day
$interval = new \DateInterval('P1D');
$realEnd = new \DateTime($end);
$realEnd->add($interval);
$period = new \DatePeriod(new \DateTime($start), $interval, $realEnd);
// Use loop to store date into array
foreach ($period as $date) {
$array[] = $date->format($format);
}
// Return the array elements
return $array;
}
} }
\ No newline at end of file
...@@ -26,6 +26,7 @@ class AirDrop extends CommonActiveRecord ...@@ -26,6 +26,7 @@ class AirDrop extends CommonActiveRecord
return [ return [
[['identifier', 'wallet_address', 'miner_address'], 'required'], [['identifier', 'wallet_address', 'miner_address'], 'required'],
[['reach_times'], 'integer'], [['reach_times'], 'integer'],
[['create_time', 'finish_time'], 'safe'],
[['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' => '树莓派编号已存在'], ['identifier', 'unique', 'message' => '树莓派编号已存在'],
...@@ -36,7 +37,7 @@ class AirDrop extends CommonActiveRecord ...@@ -36,7 +37,7 @@ class AirDrop extends CommonActiveRecord
public function scenarios() public function scenarios()
{ {
$scenarios = [ $scenarios = [
self:: SCENARIOS_CREATE => ['identifier', 'miner_address'], self:: SCENARIOS_CREATE => ['identifier', 'miner_address', 'reach_times', 'create_time', 'finish_time'],
self:: SCENARIOS_UPDATE => ['wallet_address'], self:: SCENARIOS_UPDATE => ['wallet_address'],
]; ];
return array_merge(parent:: scenarios(), $scenarios); return array_merge(parent:: scenarios(), $scenarios);
......
...@@ -49,7 +49,6 @@ class AirDropController extends Controller ...@@ -49,7 +49,6 @@ class AirDropController extends Controller
*/ */
public function actionReach() public function actionReach()
{ {
$begin = date("Y-m-d", time()) . " 00:00:00"; $begin = date("Y-m-d", time()) . " 00:00:00";
$end = date("Y-m-d", time()) . " 23:59:59"; $end = date("Y-m-d", time()) . " 23:59:59";
...@@ -140,8 +139,7 @@ class AirDropController extends Controller ...@@ -140,8 +139,7 @@ class AirDropController extends Controller
/** /**
* 获取游戏状态 * 获取游戏状态
* * @return
* @return array
*/ */
public function actionAutoAirDrop() public function actionAutoAirDrop()
{ {
......
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