| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- <?php
- namespace addons\RandomRedPacket\backend\controllers;
- use addons\RandomRedPacket\common\models\RandomRedPacket;
- use addons\RandomRedPacket\common\models\RandomRedPacketRelation;
- use addons\Rebate\backend\controllers\BaseController;
- use common\enums\StatusEnum;
- use common\models\goods\Goods;
- use Yii;
- use common\controllers\AddonsController;
- use yii\helpers\Json;
- class IndexController extends BaseController
- {
- public $enableCsrfValidation = false;
- /**
- * 活动列表
- * @Author: wu
- * @DateTime: 2023/2/14 0015 18:06
- * @Copyright: copyright (c) 2023 广东七件事集团
- * @return string|\yii\web\Response
- */
- public function actionIndex()
- {
- if (Yii::$app->request->isAjax) {
- if (Yii::$app->request->isPost) {
- $params = Yii::$app->request->post();
- // 检查提交的参数
- $res = Yii::$app->services->validate->validate($get,[
- [['activities_number', 'reward_type'], 'integer'],
- [['activities_name'], 'string'],
- ]);
- if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $time = time();
- $where = [];
- $where[] = ['=', 'mall_id', $this->mall_id];
- $where[] = ['<>', 'status', StatusEnum::DELETE];
- !empty($params['activities_number']) && $where[] = ['=', 'activities_number', $params['activities_number']];
- !empty($params['activities_name']) && $where[] = ['like', 'activities_name', $params['activities_name']];
- !empty($params['reward_type']) && $where[] = ['=', 'reward_type', $params['reward_type']];
- if(!empty($params['status'])) {// 状态条件筛选
- switch($params['status']) {
- case 1:// 进行中
- $where[] = ['<', 'start_at', $time];
- $where[] = ['>', 'end_at', $time];
- $where[] = ['=', 'status', StatusEnum::ENABLED];
- break;
- case 2:// 已过期
- $where[] = ['<', 'end_at', $time];
- break;
- case 3:// 已失效
- $where[] = ['=', 'status', StatusEnum::DISABLED];
- break;
- case 4:// 未开始
- $where[] = ['>', 'start_at', $time];
- break;
- }
- }
- // $with = ['statistics' => function($query){
- // $query->select("r_id,join_num,pay_num,pay_money");
- // }];
- $order = 'created_at desc';
- $select = "id,activities_name,activities_number,reward_type,get_number,created_at,status,start_at,end_at";
- $params = compact('where','order','select');
- $list = RandomRedPacket::listPage($params, false, true);
- $this->success('获取成功', ['list' => $list, 'now_time' => $time]);
- }
- } else {
- return $this->render($this->action->id);
- }
- }
- public function actionEdit()
- {
- if(\Yii::$app->request->isAjax){
- if(\Yii::$app->request->isPost){
- $params = \Yii::$app->request->post();
- $res = RandomRedPacket::setData($this->mall_id, $params);
- if($res == false) return $this->error("保存失败");
- return $this->success("保存成功");
- }else{
- $params = Yii::$app->request->get();
- //检查提交的参数
- $res = Yii::$app->services->validate->validate($get,[[['id'], 'integer']]);
- if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- if(!empty($params['id'])){
- $detail = RandomRedPacket::getOne([['id' => $params['id']]],true);
- $detail['goods'] = [];
- if($detail){
- $sort = 'id DESC';
- $select = "id, goods_name, cost_price, stock, cover_pic";
- $relation_list = RandomRedPacketRelation::find()->where(['packet_id'=>$params['id']])->all();
- $goods_ids = array_column($relation_list,'goods_id');
- $where = [['id' => $goods_ids]];
- $params = array('alias' => 'g', 'where' => $where, 'select'=>$select,'limit' => 10, 'order' => $sort );
- $page_data = Goods::listPage($params, false, true);
- $goods = Goods::find()->where(['id'=>$goods_ids])->select($select)->asArray()->all();
- $detail['goods'] = $goods;
- if ($page_data === false) return $this->error(Goods::getStaticError());
- }
- $data['detail'] = $detail;
- // echo '<pre>';print_r($detail);die;
- return $this->success('操作成功', $data);
- }
- }
- }
- return $this->render($this->action->id,['has_coupon' => []]);
- }
- /**
- * 操作处理
- *
- * @return void
- */
- public function actionHandle()
- {
- $request = Yii::$app->request;
- if($request->isAjax && $request->isPost){
- $params = Yii::$app->request->post();
- // echo '<pre>';print_r($params);die;
- //检查提交的参数
- $res = Yii::$app->services->validate->validate($get,[
- [['id', 'status'], 'integer']
- ]);
- if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- // 修改数据
- $res = RandomRedPacket::setData($this->mall_id, $params);
- if($res == false) return $this->error("修改失败" . RandomRedPacket::getStaticError());
- return $this->success("修改成功");
- }
- }
- /**
- * @desc:获取商品列表,添加活动使用,不用验证权限
- * @Author: hua
- * @Date: 2021/12/13
- * @Time: 18:51
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|string|void
- */
- public function actionGoodsList()
- {
- $request = Yii::$app->request;
- if ($request->isAjax) {
- //商品列表筛选
- $get = Yii::$app->request->get();
- $where = [['mall_id' => $this->mall['id'], 'status' => [StatusEnum::ENABLED]], ['is_on_sale' => 1]];
- // 筛选
- if (isset($get['keyword'])) {
- isset($get['keyword']) && $where[] = ['or', ['like', 'goods_name', $get['keyword']], ['=', 'id', $get['keyword']]];
- // isset($get['keyword']) && $where[] = ['like', 'goods_name', trim($get['keyword']) . '%', false];
- }
- // 排序
- $packet_active_list = RandomRedPacket::find()->where(['mall_id'=>$this->mall_id,'status'=>StatusEnum::ENABLED])->andWhere(['>','end_at',time()])->all();
- $packet_id_arr = array_column($packet_active_list, 'id');
- $relation_list = RandomRedPacketRelation::find()->where(['packet_id'=>$packet_id_arr])->asArray()->all();
- $ids_arr = array_column($relation_list, 'goods_id');
- $ids_arr = array_unique($ids_arr);
- !empty($ids_arr) && $where[] = ['not in', 'id', $ids_arr];
- // $where[] = ['not in', 'id', $ids_arr];
- $sort = 'sort ASC,id DESC';
- $params = ['where' => $where, 'limit' => 20, 'order' => $sort];
- $page_data = Goods::listPage($params, false, true);
- if ($page_data === false) return $this->error(Goods::getStaticError());
- return $this->success('操作成功', $page_data);
- }
- return $this->render($this->action->id);
- }
- }
|