Commit 68ef754d authored by shajiaiming's avatar shajiaiming

Merge branch 'feature/airdrop' into develop

parents d0499746 225bbe96
......@@ -2,6 +2,7 @@
namespace api\controllers;
use common\models\psources\AirDropRulePool;
use Yii;
use api\base\BaseController;
use common\models\psources\AirDrop;
......@@ -23,8 +24,21 @@ class AirDropController extends BaseController
{
if (Yii::$app->request->isPost) {
$data = Yii::$app->request->post();
$time = Yii::$app->params['AirDrop']['time'] ?? 7;
$amount = Yii::$app->params['AirDrop']['amount'] ?? 3;
$identifier = $data['identifier'] ?? null;
if (false == $identifier) {
$this->code = -1;
$this->msg = 'Validation failed.';
goto doEnd;
}
$exist = AirDropRulePool::find()->where(['identifier' => $identifier])->one();
if (false == $exist || false == $exist->rule) {
$this->code = -1;
$this->msg = 'Validation failed.';
goto doEnd;
}
$time = $exist->rule->duration - 1;
$create_time = date('Y-m-d');
$finish_time = date('Y-m-d', strtotime("+$time day"));
......@@ -46,10 +60,10 @@ class AirDropController extends BaseController
$apply_record_model->setIsNewRecord(true);
$apply_record_model->apply_id = $apply_id;
$apply_record_model->reach = AirDropApplyRecord::REACH_NO;
$apply_record_model->bonus_token = $amount;
$apply_record_model->amount = $exist->rule->amount;
$apply_record_model->token = $exist->rule->token;
$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();
......@@ -90,7 +104,7 @@ class AirDropController extends BaseController
}
$query = AirDropApplyRecord::find()
->select('id, reach, bonus_token, draw_status, create_time')
->select('id, reach, amount, token, create_time')
->where(['apply_id' => $model['id']]);
if (!empty($apply_ids)) {
$apply_ids = rtrim($apply_ids, ',');
......
......@@ -37,7 +37,7 @@ class AirDrop extends CommonActiveRecord
public function scenarios()
{
$scenarios = [
self:: SCENARIOS_CREATE => ['identifier', 'miner_address', 'reach_times', 'create_time', 'finish_time'],
self:: SCENARIOS_CREATE => ['identifier', 'miner_address', 'reach_times', 'create_time'],
self:: SCENARIOS_UPDATE => ['wallet_address'],
];
return array_merge(parent:: scenarios(), $scenarios);
......
......@@ -52,7 +52,6 @@ class AirDropApplyRecord extends CommonActiveRecord
'bonus_token' => '奖励单位',
'draw_status' => '领取情况',
'create_time' => '创建时间',
'finish_time' => '更新时间'
];
}
......
<?php
namespace common\models\psources;
use Yii;
use yii\db\Expression;
class AirDropRule extends CommonActiveRecord
{
//定义场景
const SCENARIOS_CREATE = 'create';
public static function getDb()
{
return Yii::$app->get('p_sources');
}
public static function tableName()
{
return '{{%wallet_airdrop_rule}}';
}
public function rules()
{
return [
[['token', 'amount', 'duration'], 'required'],
[['amount', 'duration'], 'integer'],
[['token'], 'string', 'length' => [2, 10]],
];
}
public function scenarios()
{
$scenarios = [
self:: SCENARIOS_CREATE => ['token', 'amount', 'duration'],
];
return array_merge(parent:: scenarios(), $scenarios);
}
public function attributeLabels()
{
return [
'token' => '空投币种单位',
'amount' => '每次空投数量',
'duration' => '空投周期'
];
}
public function getRecord()
{
return $this->hasMany(AirDropRulePool::className(), ['rule_id' => 'id'])->all();
}
}
\ No newline at end of file
<?php
namespace common\models\psources;
use Yii;
use yii\db\Expression;
class AirDropRulePool extends CommonActiveRecord
{
//定义场景
const SCENARIOS_CREATE = 'create';
public static function getDb()
{
return Yii::$app->get('p_sources');
}
public static function tableName()
{
return '{{%wallet_airdrop_rule_pool}}';
}
public function rules()
{
return [
[['rule_id', 'identifier'], 'required'],
[['identifier'], 'string', 'length' => [5, 50]],
['identifier', 'unique', 'message' => '树莓派编号已存在'],
];
}
public function scenarios()
{
$scenarios = [
self:: SCENARIOS_CREATE => ['rule_id', 'identifier'],
];
return array_merge(parent:: scenarios(), $scenarios);
}
public function attributeLabels()
{
return [
'identifier' => '树莓派编号',
'rule_id' => '所属规则'
];
}
public function getRule()
{
return $this->hasOne(AirDropRule::className(), ['id' => 'rule_id'])->one();
}
}
\ No newline at end of file
......@@ -133,15 +133,16 @@ class AirDropController extends Controller
if (empty($record)) {
return 0;
}
var_dump($record);exit;
foreach ($record as $val) {
go(function () use ($val) {
\Co::sleep(0.5);
$amount = 1;
$amount = $val->amount;
$fee = 1;
$note = '';
$execer = 'token';
$isToken = true;
$tokenSymbol = 'CCNY';
$tokenSymbol = $val->token;
$val->draw_status = AirDropApplyRecord::STATUS_DRAW_SUEEESS;
......
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