params['AirDrop']['address']; $service = new Chain33Service(); $execer = 'coins'; $result = $service->getBalance($address, $execer); if (0 != $result['code']) { $this->code = -1; $this->msg = '余额获取失败。失败原因:' . $result['error']; goto doEnd; } $this->data = $result['result'][0]['balance'] ?? 0; doEnd : return ['code' => $this->code, 'msg' => $this->msg, 'data' => $this->data]; } /** * 总空投金额 * @param * @return array */ public function actionExpenses() { $expiry_date = date("Y-m-d", strtotime("+1 day")); $this->data = AirDropApplyRecord::find() ->where(['draw_status' => AirDropApplyRecord::STATUS_DRAW_SUEEESS]) ->andWhere(['<', 'create_time', $expiry_date]) ->sum('bonus_token'); if (empty($this->data)) { $this->data = 0; } doEnd : return ['code' => $this->code, 'msg' => $this->msg, 'data' => (int)$this->data]; } /** * 空投申请列表 * @param page 页码 * @param size 每页显示条数 * @return array */ 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; $redis = Yii::$app->redis_app; foreach ($model as &$val) { list($reach, $draw_success, $income, $un_draw) = $redis->hmget('airdrop:' . $val->identifier, 'reach', 'draw_success', 'income', 'un_draw'); $val->reach = empty($reach) ? 0 : (int)$reach; $val->draw_success = empty($draw_success) ? 0 : (int)$draw_success; $val->income = empty($income) ? 0 : (int)$income; $val->un_draw = empty($un_draw) ? 0 : (int)$un_draw; } $this->data = [ 'items' => $model, 'total' => (int)$countQuery->count() ]; doEnd : return ['code' => $this->code, 'msg' => $this->msg, 'data' => $this->data]; } /** * 每个树莓派的空投记录 * @param identifier 树莓派编号 * @param miner_address 矿工地址 * @param apply_ids * @param page 页码 * @param size 每页显示条数 * @return array */ 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]; } }