Commit f3e46067 authored by shajiaiming's avatar shajiaiming

backend airdrop api

parent ec71026d
<?php
namespace wallet\controllers;
use common\models\psources\AirDropApplyRecord;
use Yii;
use wallet\base\BaseController;
use common\models\psources\AirDrop;
class AirDropController extends BaseController
{
public function actionIndex()
{
$page = Yii::$app->request->get('page', 1);
$size = Yii::$app->request->get('size', 10);
if (!Yii::$app->request->isGet) {
$this->code = -1;
$this->msg = '错误的请求方式.';
goto doEnd;
}
$query = AirDrop::find()->select('identifier, wallet_address,miner_address,create_time, finish_time');
$model = $query->offset(($page - 1) * $size)->orderBy('id desc')->limit($size)->all();
if (empty($model)) {
goto doEnd;
}
$countQuery = clone $query;
$this->data = [
'items' => $model,
'total' => (int)$countQuery->count()
];
doEnd :
return ['code' => $this->code, 'msg' => $this->msg, 'data' => $this->data];
}
public function actionApply()
{
$page = \Yii::$app->request->get('page', 1);
$size = \Yii::$app->request->get('size', 10);
$data = Yii::$app->request->get();
$identifier = $data['identifier'] ?? '';
$miner_address = $data['miner_address'] ?? '';
$apply_ids = isset($data['apply_ids']) ? $data['apply_ids'] : '';
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();
$total = 0;
$items = [];
if (empty($model) || empty($model->record)) {
goto doEnd;
}
$query = AirDropApplyRecord::find()
->select('reach, draw_status, create_time, update_time')
->where(['apply_id' => $model['id']]);
if (!empty($apply_ids)) {
$apply_ids = rtrim($apply_ids, ',');
$apply_id_arr = explode(',', $apply_ids);
$query->andWhere(['in', 'id', $apply_id_arr]);
}
$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();
$countQuery = clone $query;
$total = (int)$countQuery->count();
$this->data = [
'items' => $items,
'total' => $total,
];
doEnd :
return ['code' => $this->code, 'msg' => $this->msg, 'data' => $this->data];
}
}
\ No newline at end of file
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