| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- <?php
- namespace addons\Recommen\api\modules\v1\controllers;
- use addons\Recommen\common\enums\RecommenEnum;
- use addons\Recommen\common\models\Recommen;
- use addons\Recommen\common\models\RecommenLog;
- use addons\Recommen\common\models\RecommenReward;
- use common\components\export\CsvTool;
- use common\enums\DiyEnum;
- use common\enums\StatusEnum;
- use common\models\common\Attachment;
- use common\models\common\PosterCode;
- use common\models\user\User;
- use Yii;
- use api\controllers\OnAuthController;
- /**
- * 默认控制器
- *
- * Class DefaultController
- * @package addons\Recommen\api\modules\v1\controllers
- */
- class DefaultController extends OnAuthController
- {
- public $modelClass = '';
- /**
- * 不用进行登录验证的方法
- *
- * 例如: ['index', 'update', 'create', 'view', 'delete']
- * 默认全部需要验证
- *
- * @var array
- */
- protected $authOptional = ['index','detail','list','ranking'];
- /**
- * 活动列表
- * @Author: ltm
- * @DateTime: 2022/5/17 0021 11:29
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|string|void
- */
- public function actionList()
- {
- $retuest = Yii::$app->request;
- if ($retuest->isGet) {
- $params = Yii::$app->request->get();
- // 检查提交的参数
- $where = [];
- $time = time();
- $where[] = ['<', 'start_time', $time];
- $where[] = ['>', 'end_time', $time];
- $where[] = ['=', 'status', StatusEnum::ENABLED];
- $where[] = ['=', 'mall_id', $this->mall_id];
- $order = 'id desc';
- $params = array('where' => $where, 'order'=>$order, 'limit' => 5);
- $list = Recommen::listPage($params, false, true);
- if($list){
- foreach($list['list'] as $k=>$v){
- $list['list'][$k]['recommen_reward'] = json_decode($v['recommen_reward']);
- $list['list'][$k]['open_time'] = date("Y-m-d H:i",$v['start_time']).'-'.date("Y-m-d H:i",$v['end_time']);
- }
- }
- $this->success('获取成功', $list);
- }
- }
- /**
- * 活动列表
- * @Author: ltm
- * @DateTime: 2022/5/17 0021 11:29
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|string|void
- */
- public function actionRanking(){
- $retuest = Yii::$app->request;
- if ($retuest->isGet) {
- $get = Yii::$app->request->get();
- $where = [];
- $with = ['user'];
- //筛选出正在进行的活动
- $active = Recommen::find()->select("id")->where(['mall_id' => $this->mall_id])->andWhere(['>', 'start_time', time()])->andWhere(['<', 'end_time', time()])->asArray()->column();
- if($active) { $where[] = ['in', 'active_id', $active]; }
- $where[] = ['=', 'mall_id', $this->mall_id];
- $where[] = ['>=', 'status', StatusEnum::DISABLED];
- $order = 'new_num desc';
- $params = array('where' => $where,'with' => $with,'group'=>'user_id','order'=>$order, 'limit' => $get['limit']);
- $params['select'] = 'user_id,max(new_num) as new_num';
- $list = RecommenLog::listPage($params, false, true);
- //获取奖励
- if($list['list'] && $get['page'] ==1){
- if($list['list']){
- $user_ids = array_column($list['list'],'user_id');
- $user_ids = array_unique($user_ids);
- $reward_data = ['where' => [['in','user_id',$user_ids]],'order'=>'id desc', 'limit' => 5];
- $reward = RecommenReward::lists($reward_data,true);
- $reward_data = [];
- if($reward){
- foreach($reward as $v){
- if($v['reward'] && $v['reward'] != "null" && $v['reward'] != null){
- $reward_data[] = implode(',',json_decode($v['reward'],true));
- }
- }
- }
- $list['reward'] = $reward_data;
- }
- }
- $this->success('获取成功', $list);
- }
- }
- /**
- * 活动详情
- * @Author: ltm
- * @DateTime: 2022/5/17 0021 11:29
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|string|void
- */
- public function actionDetail()
- {
- $retuest = Yii::$app->request;
- if ($retuest->isGet) {
- $params = Yii::$app->request->get();
- // 检查提交的参数
- $res = Yii::$app->services->validate->validate($params,[
- [['scene','id'], 'safe'],
- ]);
- if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- // 检查提交的参数
- if($params['scene']){
- $where[] = ['=', 'mall_id', $this->mall_id];
- $where[] = ['>=', 'status', StatusEnum::DISABLED];
- $where[] = ['=', 'code', $params['scene']];
- $qrode = PosterCode::getOne($where,true);
- if($qrode){
- $params['id'] = $qrode['item_id'];
- }
- }
- $where = [];
- $where[] = ['=', 'id', $params['id']];
- $where[] = ['=', 'status', StatusEnum::ENABLED];
- $where[] = ['=', 'mall_id', $this->mall_id];
- $detail = Recommen::getOne($where, true);
- if($detail){
- $detail['recommen_reward'] = json_decode($detail['recommen_reward']);
- $detail['be_recommen_reward'] = json_decode($detail['be_recommen_reward']);
- $detail['type_name'] = RecommenEnum::getRewardType()[$detail['type']];
- $detail['open_time'] = date("Y-m-d H:i",$detail['start_time']).'-'.date("Y-m-d H:i",$detail['end_time']);
- }
- $data['detail'] = $detail;
- $sign = $this->mall['mall_sign'];
- $data['qrcode'] = '/plugins/recommen/detail?active_id='.$params['id']."?sign={$sign}&pid=".$this->user_id."&share_type=1";
- $data['qrcode_id'] = RecommenEnum::SHARE_TYPE;
- $this->success('获取成功', $data);
- }
- }
- }
|