validate()) return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0] ]; $query = QAndAQuestionTemplate::find()->alias('g')->where( ['is_delete' => 0, 'state' => 1, 'store_id' => get_store_id()] ); $count = $query->count(); $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $this->limit, 'page' => $this->page - 1]); $query->orderBy('id desc'); $list = $query ->limit($pagination->limit) ->offset($pagination->offset) ->asArray()->all(); return [ 'code' => 0, 'data' => [ 'row_count' => $count, 'page_count' => $pagination->pageCount, 'list' => $list, ] ]; } public function hot_list() { if (!$this->validate()) return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0] ]; $query = QAndAQuestionTemplate::find()->alias('g')->where( ['is_delete' => 0, 'state' => 1, 'store_id' => get_store_id(), 'is_hot' => 1] ); $count = $query->count(); $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $this->limit, 'page' => $this->page - 1]); $query->orderBy('id desc'); $list = $query ->limit($pagination->limit) ->offset($pagination->offset) ->asArray()->all(); return [ 'code' => 0, 'data' => [ 'row_count' => $count, 'page_count' => $pagination->pageCount, 'list' => $list, ] ]; } public function template_list() { if (!$this->validate()) return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0] ]; $query = QAndACat::find()->where(['is_delete' => 0, 'store_id' => get_store_id()]); $count = $query->count(); $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $this->limit, 'page' => $this->page - 1]); $cat_list = $query ->limit($pagination->limit) ->offset($pagination->offset) ->asArray()->all(); $list = []; foreach ($cat_list as $v) { $query = QAndAQuestionTemplate::find()->where(['is_delete' => 0, 'state' => 1, 'store_id' => get_store_id(), 'cat_id' => $v['id']])->orderBy('id desc')->asArray()->all(); $list[$v['name']] = $query; } return [ 'code' => 0, 'data' => [ 'row_count' => $count, 'page_count' => $pagination->pageCount, 'list' => $list, ] ]; } public function question_list() { if (!$this->validate()) return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0] ]; $user = $this->user; $query = QAndAQa::find() ->where(['is_delete' => 0, 'store_id' => get_store_id(), 'user_id' => $user->id]); $count = $query->count(); $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $this->limit, 'page' => $this->page - 1]); $list = $query ->limit($pagination->limit) ->offset($pagination->offset) ->orderBy('id DESC') ->asArray()->all(); foreach ($list as &$item) { $item['answer_time'] = date('Y-m-d H:i:s', $item['answer_time']); } return [ 'code' => 0, 'data' => [ 'total' => $count, 'list' => $list, ] ]; } public function del_question($id) { if (!$id) { return [ 'code' => 1, 'msg' => '参数错误' ]; } $item = QAndAQa::findOne($id); if (!$item) { return [ 'code' => 1, 'msg' => '参数错误' ]; } $item->is_delete = 1; $item->save(); return [ 'code' => 0, 'msg' => '删除成功' ]; } public function index() { if (!$this->validate()) return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0] ]; $ad_s = QAndAAdSetting::find()->where(['store_id' => get_store_id()])->one(); $qs_s = QAndASetting::find()->where(['store_id' => get_store_id()])->one(); $today_day = date('Y-m-d'); $today = Register::find()->where(['register_time' => $today_day, 'store_id' => get_store_id(), 'user_id' => $this->user->id])->asArray()->one(); $setting = IntegralSetting::find()->where(['store_id' => get_store_id()])->one(); $today_time = strtotime(date('Y-m-d')); $ad_use_num = QAndAAdLog::find()->where(['store_id' => get_store_id(), 'user_id' => get_user_id()]) ->andWhere(['>', 'created_at', $today_time]) ->count(); $all_award_integral = $ad_s->award_integral * $ad_s->see_num + $setting->register_integral; $use_award_integral = $ad_s->award_integral * $ad_use_num + ($today ? $setting->register_integral : 0); $job = [ [ 'name' => '观看视频获得积分', 'award_integral' => $ad_s->award_integral, 'type' => 1, //前段跳转页面用 1视频 2积分 'see_num_' => $ad_s->see_num, 'use_num' => $ad_use_num, ], [ 'name' => '积分签到', 'award_integral' => $setting->register_integral, 'type' => 2, 'see_num_' => 1, 'use_num' => $today ? 1 : 0, ], ]; // $appidArr = explode(',', $ad_s->adpid); // foreach ($appidArr as $k => $v) { // $appidArr[$k] = intval($v); // } return [ 'code' => 0, 'data' => [ 'integral' => $this->user->integral, 'adpid' => $ad_s->adpid, 'rule' => $qs_s->rule, 'all_award_integral' => $all_award_integral, 'use_award_integral' => $use_award_integral, 'job' => $job, ] ]; } public function add_integral() { $user = get_user(); $store_id = get_store_id(); $ad_s = QAndAAdSetting::find()->where(['store_id' => get_store_id()])->one(); // 获取今日0点时间戳 $today = strtotime(date('Y-m-d')); $count = QAndAAdLog::find()->where(['store_id' => $store_id, 'user_id' => $user->id]) ->andWhere(['>', 'created_at', $today]) ->count(); if ($count >= $ad_s->see_num) { return [ 'code' => 1, 'msg' => '今日观看次数已达上限' ]; } $log = new QAndAAdLog(); $log->store_id = $store_id; $log->user_id = $user->id; $log->integral = $ad_s->award_integral; if ($log->save()) { AccountLog::saveLog($user->id, $ad_s->award_integral, 1, 1, 0, 0, '观看视频广告获得积分', 18, $log->id, $store_id); $count = QAndAAdLog::find()->where(['store_id' => $store_id, 'user_id' => $user->id]) ->andWhere(['>', 'created_at', $today]) ->count(); return [ 'code' => 0, 'msg' => '积分增加成功', 'count' => $count, ]; } else { return [ 'code' => 1, 'msg' => '积分增加失败' ]; } } }