Commit f50245cb authored by shajiaiming's avatar shajiaiming

Merge branch 'master' into develop

parents 044b73a5 c0727eec
......@@ -66,8 +66,6 @@ class AirDropController extends BaseController
goto doEnd;
}
$model = AirDrop::find()->select('id')->where(['identifier' => $identifier, 'miner_address' => $miner_address])->one();
$total = 0;
$items = [];
if (empty($model) || empty($model->record)) {
goto doEnd;
}
......@@ -80,10 +78,10 @@ class AirDropController extends BaseController
$apply_id_arr = explode(',', $apply_ids);
$query->andWhere(['in', 'id', $apply_id_arr]);
}
$expiry_date = date("Y-m-d");
$expiry_date = date("Y-m-d", strtotime("+1 day"));
$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('create_time desc')->limit($size)->all();
$countQuery = clone $query;
$total = (int)$countQuery->count();
......@@ -125,8 +123,48 @@ class AirDropController extends BaseController
return ['code' => $this->code, 'msg' => $this->msg, 'data' => (int)$this->data];
}
/**
* 空投领取情况
* @param identifier 树莓派编号
* @param miner_address 矿工地址
* @return array
*/
public function actionInfo()
{
if (Yii::$app->request->isPost) {
$this->code = -1;
$this->msg = '请求方式错误!';
goto doEnd;
}
$data = Yii::$app->request->get();
$identifier = $data['identifier'] ?? null;
if (false == $identifier) {
$this->code = -1;
$this->msg = 'Validation failed.';
goto doEnd;
}
$redis = Yii::$app->redis_app;
list($reach, $reached_times, $draw_success, $income, $un_draw) = $redis->hmget('airdrop:' . $identifier, 'reach', 'reached_times', 'draw_success', 'income', 'un_draw');
$this->data = [
'reach' => empty($reach) ? 0 : (int)$reach,
'reached_times' => empty($reached_times) ? 0 : (int)$reached_times,
'draw_success' => empty($draw_success) ? 0 : (int)$draw_success,
'income' => empty($income) ? 0 : (int)$reach,
'un_draw' => empty($un_draw) ? 0 : (int)$un_draw,
];
doEnd :
return ['code' => $this->code, 'msg' => $this->msg, 'data' => $this->data];
}
public function actionBatchDraw()
{
$this->code = -1;
$this->msg = '请求方式错误!';
goto doEnd;
if (!Yii::$app->request->isPost) {
$this->code = -1;
$this->msg = '请求方式错误!';
......@@ -196,6 +234,15 @@ class AirDropController extends BaseController
goto doEnd;
}
$redis = Yii::$app->redis_app;
$value = date('Y-m-d H:i:s');
$is_locked = $redis->setnx($data['identifier'], $value);
if (!$is_locked) {
$this->msg = '已达今日领取上限,请明天再来!';
$this->code = -1;
goto doEnd;
}
$redis->setex($data['identifier'], strtotime('23:59:59') - time(), $value);
$record->draw_status = AirDropApplyRecord::STATUS_DRAWING;
if (false == $record->save()) {
$this->code = -1;
......
......@@ -86,7 +86,7 @@ class WalletCoinController extends BaseController
$ticker = ['low' => 0, 'high' => 0, 'last' => 0, 'open' => 0, 'vol' => 0, 'rmb' => 0, 'usd' => 0];
foreach ($this->data as $key => &$val) {
$val['chain_quotation'] = isset($coin_quotations[strtoupper($val['chain'])]) ? $coin_quotations[strtoupper($val['chain'])] : [];
//$val['chain_quotation'] = isset($coin_quotations[strtoupper($val['chain'])]) ? $coin_quotations[strtoupper($val['chain'])] : [];
$nickname = json_decode($val['nickname'], true);
$val['nickname'] = isset($nickname[$this->lang]) ? $nickname[$this->lang] : '';
$introduce = json_decode($val['introduce'], true);
......@@ -141,14 +141,14 @@ class WalletCoinController extends BaseController
$this->data = $query->offset(($page - 1) * $limit)->limit($limit)->asArray()->all();
if (false != $this->data) {
$chains = array_unique(array_column($this->data, 'chain'));
$chain_quotation = [];
foreach ($chains as $key => $value) {
$chain_quotation[$value] = ExchangeBusiness::getquatation($value);
}
foreach ($this->data as $key => $value) {
$this->data[$key]['chain_quotation'] = $chain_quotation[$value['chain']] ?: null;
}
// $chains = array_unique(array_column($this->data, 'chain'));
// $chain_quotation = [];
// foreach ($chains as $key => $value) {
// $chain_quotation[$value] = ExchangeBusiness::getquatation($value);
// }
// foreach ($this->data as $key => $value) {
// $this->data[$key]['chain_quotation'] = $chain_quotation[$value['chain']] ?: null;
// }
foreach ($this->data as $key => &$value) {
$nickname = json_decode($value['nickname'], true);
$value['nickname'] = isset($nickname[$this->lang]) ? $nickname[$this->lang] : '';
......
......@@ -32,6 +32,7 @@ class AirDropController extends Controller
go(function () use ($val, $redis, $expiry_date) {
\Co::sleep(0.5);
if (!empty($val->record)) {
//达标次数
$reach = AirDropApplyRecord::find()
->where(['apply_id' => $val['id'], 'reach' => AirDropApplyRecord::REACH_YES])
......@@ -39,7 +40,14 @@ class AirDropController extends Controller
->sum('reach');
$reach = empty($reach) ? 0 : (int)$reach;
//已领取
//已领取次数
$reached_times = AirDropApplyRecord::find()
->where(['apply_id' => $val['id'], 'draw_status' => AirDropApplyRecord::STATUS_DRAW_SUEEESS])
->andWhere(['<', 'create_time', $expiry_date])
->count();
$reached_times = empty($reached_times) ? 0 : (int)$reached_times;
//已领取空投总量
$draw_success = AirDropApplyRecord::find()
->where(['apply_id' => $val['id'], 'draw_status' => AirDropApplyRecord::STATUS_DRAW_SUEEESS])
->andWhere(['<', 'create_time', $expiry_date])
......@@ -56,7 +64,7 @@ class AirDropController extends Controller
//未领取
$un_draw = $income - $draw_success;
$redis->hmset('airdrop:' . $val->identifier, 'reach', $reach, 'draw_success', $draw_success, 'income', $income, 'un_draw', $un_draw);
$redis->hmset('airdrop:' . $val->identifier, 'reach', $reach, 'reached_times', $reached_times, 'draw_success', $draw_success, 'income', $income, 'un_draw', $un_draw);
}
});
}
......@@ -111,7 +119,8 @@ class AirDropController extends Controller
$result = $service->getBalance($apply->wallet_address, $execer);
if (0 != $result['code']) continue;
$balance = $result['result'][0]['balance'] ?? 0;
if ($balance == 0) continue;
$frozen = $result['result'][0]['frozen'] ?? 0;
if (($balance + $frozen) / 1e8 < 3000) continue;
$transaction = Yii::$app->db->beginTransaction();
try {
$apply->reach_init = AirDrop::REACH_INIT_YES;
......@@ -168,7 +177,8 @@ class AirDropController extends Controller
$result = $service->getBalance($val->apply->wallet_address, $execer);
if (0 == $result['code']) {
$balance = $result['result'][0]['balance'] ?? 0;
if ($balance > 0) {
$frozen = $result['result'][0]['frozen'] ?? 0;
if (($balance + $frozen) / 1e8 >= 3000) {
$val->reach = AirDropApplyRecord::REACH_YES;
$val->save();
}
......
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