| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- <?php
- namespace app\modules\client\models\v1;
- use app\models\IntegralSetting;
- use app\models\QAndAAdSetting;
- use app\models\QAndACat;
- use app\models\QAndAQa;
- use app\models\QAndAQuestionTemplate;
- use app\models\QAndASetting;
- use app\models\Register;
- use yii\base\Model;
- use yii\data\Pagination;
- use app\models\QAndAAdLog;
- use app\models\AccountLog;
- /**
- * @property \app\models\User $user;
- */
- class QuestionTemplateListForm extends Model
- {
- public $page;
- public $limit;
- public $user;
- /**
- * @return array
- */
- public function rules()
- {
- return [
- [['page', 'limit'], 'integer'],
- ];
- }
- public function 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()]
- );
- $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' => '积分增加失败'
- ];
- }
- }
- }
|