| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653 |
- <?php
- namespace addons\GroupBuy\backend\controllers;
- use addons\GroupBuy\common\enums\GroupBuyEnum;
- use addons\GroupBuy\common\logic\order\ActiveFinish;
- use addons\GroupBuy\common\models\GroupBuyActive;
- use addons\GroupBuy\common\models\GroupBuyActiveGoodsAttr;
- use addons\GroupBuy\common\models\GroupBuyCate;
- use addons\GroupBuy\common\models\GroupBuyOrder;
- use common\enums\PayTypeEnum;
- use common\enums\StatusEnum;
- use common\models\common\AddonsMarketingSetting;
- use common\models\common\PaymentTrade;
- use common\models\common\PaymentTradeOrder;
- use common\models\goods\Goods;
- use common\models\goods\GoodsAttr;
- use common\models\user\User;
- use common\models\user\UserLevel;
- use EasyWeChat\Factory;
- use Yii;
- /**
- * 默认控制器
- *
- * Class DefaultController
- * @package addons\GroupBuy\backend\controllers
- */
- class DefaultController extends BaseController
- {
- public $enableCsrfValidation = false;
- /**
- * @desc:拼团活动列表
- * @Author: hua
- * @Date: 2021/12/13
- * @Time: 18:49
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|string|void
- */
- public function actionIndex()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isGet) {
- $get = \Yii::$app->request->get();
- $where[] = ['mall_id' => $this->mall_id];
- $where[] = ['status' => StatusEnum::ENABLED];
- if (!empty($get['goods_name'])) {
- $goods_list = Goods::lists(['where' => [['mall_id' => $this->mall_id], ['like', 'goods_name', trim($get['goods_name']) . '%', false], ['status' => StatusEnum::ENABLED]], 'select' => 'id']);
- $goods_id_arr = array_column($goods_list, 'id');
- $where[] = ['goods_id' => $goods_id_arr];
- }
- if (isset($get['group_status']) && $get['group_status'] != -1) $where[] = ['group_status' => $get['group_status']];
- $params['limit'] = 10;
- $params['where'] = $where;
- $params['order'] = 'id DESC';
- $params['with'] = ['goods' => function ($query) {
- // $query->where(['status' => StatusEnum::ENABLED]);
- }];
- $pageData = GroupBuyActive::listPage($params, false);
- if ($pageData === false) return $this->error(GroupBuyActive::getStaticError());
- if(!empty($pageData['list'])){
- $mall_sign = $this->mall['mall_sign'];
- $h5_domain = Yii::$app->services->setting->platform->get('system.h5_url');
- foreach ($pageData['list'] as &$lv){
- $lv['page_link'] = $h5_domain . '/#/plugins/group_buy/goodsDetail?sign=' . $mall_sign . '&active_id=' . $lv['id'];
- $lv['poster_filename'] = substr(md5("{'poster'_{$lv['id']}_{$this->mall_id}"), 0, 16);
- $lv['qrcode_filename'] = substr(md5("{'qrcode'_{$lv['id']}_{$this->mall_id}"), 0, 16);
- }
- $mall_logo = \Yii::$app->services->setting->mall->get($this->mall_id, 'basic.logo');
- if (empty($mall_logo)) \Yii::$app->request->hostInfo . '/resources/img/mall/mall_logo_default.jpg';
- $mall_logo = $this->imgBase64Encode($mall_logo);
- $mall_name = \Yii::$app->services->setting->mall->get($this->mall_id, 'basic.name');
- if (empty($mall_name)) $mall_name = '七件事商城';
- $pageData['mall_info']['mall_logo'] = $mall_logo;
- $pageData['mall_info']['mall_name'] = $mall_name;
- }
- return $this->success('操作成功', $pageData);
- }
- }
- return $this->render('index', []);
- }
- /**
- * 图片base64编码
- * @param string $img
- * @param bool $imgHtmlCode
- * author 江南极客
- * @return string
- */
- function imgBase64Encode($img = '', $imgHtmlCode = true)
- {
- //如果是本地文件
- if(strpos($img,'http') === false && !file_exists($img)){
- return $img;
- }
- //获取文件内容
- $file_content = file_get_contents($img);
- if($file_content === false){
- return $img;
- }
- $imageInfo = getimagesize($img);
- $prefiex = '';
- if($imgHtmlCode){
- $prefiex = 'data:' . $imageInfo['mime'] . ';base64,';
- }
- $base64 = $prefiex.chunk_split(base64_encode($file_content));
- return $base64;
- }
- /**
- * @desc:详情
- * @Author: hua
- * @Date: 2021/12/13
- * @Time: 18:50
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|string|void
- */
- public function actionDetail()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isGet) {
- $get = \Yii::$app->request->get();
- GroupBuyActive::checkActive($get['id'], $this->mall_id);
- $list = GroupBuyActiveGoodsAttr::lists(['where' => [['mall_id' => $this->mall_id], ['group_buy_active_id' => $get['id']]], 'with' => [
- 'goodsAttr' => function ($query) {
- $query->where(['status' => StatusEnum::ENABLED]);
- },
- 'goods' => function ($query) {
- $query->where(['status' => StatusEnum::ENABLED]);
- },
- 'groupBuyActive' => function ($query) {
- $query->where(['status' => StatusEnum::ENABLED]);
- },
- ]]);
- if ($list === false) return $this->error(GroupBuyActive::getStaticError());
- $commander_level_limit = '';
- $user_level_limit = '';
- foreach ($list as $item) {
- $commander_level_limit = $item['groupBuyActive']['commander_level_limit'];
- $user_level_limit = $item['groupBuyActive']['user_level_limit'];
- break;
- }
- $function = function ($level_limit) {
- $level_arr = explode(',', $level_limit);
- $user_level_list = UserLevel::lists(['where' => [['level' => $level_arr], ['mall_id' => $this->mall_id], ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]], 'select' => 'name']);
- $temp = array_column($user_level_list, 'name');
- // 存在等级0
- if (in_array(0, $level_arr)) $temp[] = '普通用户';
- return join(',', $temp);
- };
- $commander_level_limit_text = '全部';
- $user_level_limit_text = '全部';
- if ($commander_level_limit != 'all') {
- $commander_level_limit_text = $function($commander_level_limit);
- }
- if ($user_level_limit != 'all') {
- $user_level_limit_text = $function($user_level_limit);
- }
- return $this->success('操作成功', ['list' => $list, 'commander_level_limit_text' => $commander_level_limit_text, 'user_level_limit_text' => $user_level_limit_text]);
- }
- }
- return $this->render('index', []);
- }
- /**
- * @desc:删除
- * @Author: hua
- * @Date: 2021/12/13
- * @Time: 18:50
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|string|void
- */
- public function actionDel()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isGet) {
- $get = \Yii::$app->request->get();
- $get['mall_id'] = $this->mall_id;
- $res = GroupBuyActive::delData($get);
- if ($res === false) return $this->error(GroupBuyActive::getStaticError());
- return $this->success('操作成功');
- }
- }
- return $this->render('index', []);
- }
- /**
- * @desc:添加活动
- * @Author: hua
- * @Date: 2021/12/13
- * @Time: 18:50
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|string|void
- */
- public function actionAdd()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isPost) {
- $params = \Yii::$app->request->post();
- $params['mall_id'] = $this->mall_id;
- $res = GroupBuyActive::setData($params);
- if ($res === false) return $this->error(GroupBuyActive::getStaticError());
- return $this->success('操作成功');
- }
- }
- $title = '添加页面';
- return $this->render('add', ['title' => $title]);
- }
- /**
- * @desc:开团列表
- * @Author: hua
- * @Date: 2021/12/13
- * @Time: 18:49
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|string|void
- */
- public function actionOpenList()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isGet) {
- $params = \Yii::$app->request->get();
- $where[] = ['group_buy_active_id' => $params['group_buy_active_id']];
- $where[] = ['mall_id' => $this->mall_id];
- $where[] = ['is_commander' => 1];
- if (!empty($params['nickname'])) {
- $user_list = User::lists(['where' => [['like', 'nickname', $params['nickname'] . '%', false]], 'select' => 'id']);
- $where[] = ['user_id' => array_column($user_list, 'id')];
- }
- if (!empty($params['begin_time'])) $where[] = ['>=', 'created_at', strtotime($params['begin_time'])];
- if (!empty($params['end_time'])) $where[] = ['<=', 'created_at', strtotime($params['end_time'])];
- if (isset($params['order_status']) && $params['order_status'] != -1) $where[] = ['order_status' => $params['order_status']];
- $params['limit'] = 10;
- $params['where'] = $where;
- $params['with'] = ['user', 'groupBuyActive'];
- $list = GroupBuyOrder::listPage($params);
- if (!empty($list['list'])) {
- $open_group_id_arr = array_column($list['list'], 'open_group_id');
- $order_arr = GroupBuyOrder::lists(['where' => [['open_group_id' => $open_group_id_arr], ['is_pay' => 1]], 'select' => 'open_group_id,count(*) as counts', 'group' => 'open_group_id', 'index' => 'open_group_id']);
- foreach ($list['list'] as &$item) {
- $item['counts'] = $order_arr[$item['open_group_id']]['counts'] ?? 0;
- }
- }
- return $this->success('操作成功', $list);
- }
- }
- return $this->render('open-list', []);
- }
- /**
- * @desc:拼团成员
- * @Author: hua
- * @Date: 2021/12/14
- * @Time: 14:49
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|void
- */
- public function actionGroupBuyTeam()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isGet) {
- $get = \Yii::$app->request->get();
- $where[] = ['group_buy_active_id' => $get['group_buy_active_id']];
- $where[] = ['open_group_id' => $get['open_group_id']];
- $where[] = ['commander_id' => $get['commander_id']];
- $where[] = ['mall_id' => $this->mall_id];
- $where[] = ['is_pay' => 1];
- $params['where'] = $where;
- $params['with'] = ['user', 'groupBuyActive'];
- $list = GroupBuyOrder::listPage($params);
- return $this->success('操作成功', $list);
- }
- }
- }
- /**
- * @desc:结束拼团
- * @Author: hua
- * @Date: 2021/12/14
- * @Time: 15:16
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|void
- */
- public function actionFinish()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isGet) {
- $get = \Yii::$app->request->get();
- $counts = GroupBuyOrder::find()->where(['mall_id'=>$this->mall_id,'open_group_id'=>$get['open_group_id'],'is_pay'=>1])->count();
- $group_order = GroupBuyOrder::findOne(['mall_id'=>$this->mall_id,'id'=>$get['open_group_id'],'is_pay'=>1]);
- $active = GroupBuyActive::findOne(['mall_id'=>$this->mall_id,'id'=>$group_order['group_buy_active_id']]);
- if($active->is_virtual){
- if($active->virtual_group_type==2&&$counts<$active->gt_group_size){
- $res = GroupBuyOrder::finishGroupBuyOrder($this->mall_id, $get['open_group_id']);
- if ($res == false) return $this->error(GroupBuyOrder::getStaticError());
- }elseif ($active->virtual_group_type == 3) {
- $res = ActiveFinish::handle($this->mall_id, $get['open_group_id'], $active);
- if ($res == false) return $this->error('结束失败');
- }else{
- //成功
- $list = GroupBuyOrder::findAll(['mall_id' => $this->mall_id, 'open_group_id' => $get['open_group_id'], 'order_status' => GroupBuyEnum::JOINING]);
- $res = GroupBuyOrder::addMainOrder($group_order,$list,$active,$counts);
- if ($res == false) return $this->error(GroupBuyOrder::getStaticError());
- }
- }else{
- $res = GroupBuyOrder::finishGroupBuyOrder($this->mall_id, $get['open_group_id']);
- if ($res == false) return $this->error(GroupBuyOrder::getStaticError());
- }
- return $this->success('操作成功', []);
- }
- }
- }
- /**
- * @desc:拼团订单
- * @Author: hua
- * @Date: 2021/12/17
- * @Time: 16:35
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|string|void
- */
- public function actionOrderList()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isGet) {
- $get = \Yii::$app->request->get();
- $where[] = ['mall_id' => $this->mall_id];
- $where[] = ['status' => StatusEnum::ENABLED];
- if (!empty($get['mobile'])) {
- $user_list = User::lists(['where' => [['mall_id' => $this->mall_id], ['like', 'mobile', trim($get['mobile']) . '%', false], ['status' => StatusEnum::ENABLED]], 'select' => 'id']);
- $user_id_arr = array_column($user_list, 'id');
- $where[] = ['user_id' => $user_id_arr];
- }
- if (!empty($get['nickname'])) {
- $user_list = User::lists(['where' => [['mall_id' => $this->mall_id], ['like', 'nickname', trim($get['nickname']) . '%', false], ['status' => StatusEnum::ENABLED]], 'select' => 'id']);
- $user_id_arr = array_column($user_list, 'id');
- $where[] = ['user_id' => $user_id_arr];
- }
- if (!empty($get['order_no'])) {
- $where[] = ['order_no' => $get['order_no']];
- }
- if (isset($get['order_status']) && $get['order_status'] != -1) $where[] = ['order_status' => $get['order_status']];
- $params['limit'] = 10;
- $params['where'] = $where;
- $params['order'] = 'id DESC';
- $params['with'] = ['user', 'groupBuyActive'];
- $pageData = GroupBuyOrder::listPage($params, false);
- if ($pageData === false) return $this->error(GroupBuyOrder::getStaticError());
- $pageData['order_status_map'] = GroupBuyEnum::getOrderStatusMap();
- return $this->success('操作成功', $pageData);
- }
- }
- return $this->render('order-list', []);
- }
- /**
- * @desc:查询退款状态
- * @Author: hua
- * @Date: 2021/12/20
- * @Time: 15:38
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|void
- * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
- */
- public function actionQueryRefund()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isGet) {
- $get = \Yii::$app->request->get();
- $group_buy_order = GroupBuyOrder::findOne(['id' => $get['id'], 'mall_id' => $this->mall_id]);
- if ($group_buy_order == false) return $this->error(GroupBuyOrder::getStaticError());
- switch ($group_buy_order->payment_type) {
- case PayTypeEnum::BALANCE:
- return $this->success('已退款');
- case PayTypeEnum::WECHAT:
- $payment_order = PaymentTradeOrder::findOne(['order_no' => $group_buy_order->order_no]);
- $payment_trade = PaymentTrade::findOne(['id' => $payment_order->trade_id]);
- $out_trade_no = $payment_trade['out_trade_no'];
- $config = Yii::$app->services->pay->getWechatConfig($this->mall_id);
- $wechatConfig = [
- 'app_id' => $config['app_id'],
- 'mch_id' => $config['wechat_mch_id'],
- 'key' => $config['wechat_pay_secret'], // API 密钥
- 'cert_path' => dirname(Yii::$app->basePath) . '/' . $config['wechat_cert_pem_file'],
- 'key_path' => dirname(Yii::$app->basePath) . '/' . $config['wechat_key_pem_file'],
- 'notify_url' => ''//回调地址
- ];
- $res = Factory::payment($wechatConfig)->refund->queryByOutTradeNumber($out_trade_no);
- if ($res['result_code'] != 'SUCCESS') return $this->error($res['err_code_des']);
- return $this->success('操作成功', $res['return_msg']);
- default:
- return $this->error('暂时不支持该支付方式查询');
- }
- }
- }
- }
- /**
- * @desc: 活动装修
- * @Author: hua
- * @Date: 2021/12/20
- * @Time: 15:56
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|void
- */
- public function actionDiyIndex()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isPost) {
- $params = \Yii::$app->request->post();
- $res = \Yii::$app->services->validate->validate($params, [
- [['content'], 'required'],
- ]);
- if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- $params['mall_id'] = $this->mall_id;
- $params['addons_name'] = GroupBuyEnum::ADDONS_NAME;
- $res = AddonsMarketingSetting::setData($params);
- if ($res == false) return $this->error(AddonsMarketingSetting::getStaticError());
- return $this->success('操作成功', []);
- }
- if (\Yii::$app->request->isGet) {
- $params['mall_id'] = $this->mall_id;
- $params['addons_name'] = GroupBuyEnum::ADDONS_NAME;
- $params['status'] = StatusEnum::ENABLED;
- $res = AddonsMarketingSetting::findOne($params);
- if ($res == false) return $this->success('操作成功', []);
- $data = $res->toArray();
- $content = json_decode($data['content'], true);
- if (!empty($content)) {
- $active_data = array_pop($content);
- $active_ids = [];
- if (!empty($active_data['data']['goods'])) {
- foreach ($active_data['data']['goods'] as $item) {
- $active_ids[] = $item['params']['id'];
- }
- $list = GroupBuyActive::lists(['where' => [
- ['id' => $active_ids],
- ['status' => StatusEnum::ENABLED],
- ['group_status' => [GroupBuyEnum::NOT_STARTED, GroupBuyEnum::OPEN_GROUP]],
- ['mall_id' => $this->mall_id]], 'select' => 'id']
- );
- $active_id_arr = array_column($list, 'id');//没有被删除的活动id
- $goods_data = [];
- foreach ($active_data['data']['goods'] as $item) {
- if (in_array($item['params']['id'], $active_id_arr)) $goods_data[] = $item;
- }
- $active_data['data']['goods'] = $goods_data;
- $content[] = $active_data;
- $data['content'] = json_encode($content);
- }
- }
- return $this->success('操作成功', $data);
- }
- }
- return $this->render('diy-index');
- }
- /**
- * @desc:拼团分类列表
- * @Author: hua
- * @Date: 2021/12/13
- * @Time: 18:49
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|string|void
- */
- public function actionCateIndex()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isGet) {
- $where[] = ['mall_id' => $this->mall_id];
- $where[] = ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]];
- $params['limit'] = 10;
- $params['where'] = $where;
- $params['order'] = 'id DESC';
- $pageData = GroupBuyCate::listPage($params, false);
- if ($pageData === false) return $this->error(GroupBuyCate::getStaticError());
- return $this->success('操作成功', $pageData);
- }
- }
- return $this->render('cate-index', []);
- }
- /**
- * @desc:编辑拼团分类
- * @Author: hua
- * @Date: 2021/12/13
- * @Time: 18:49
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|string|void
- */
- public function actionCateEdit()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isGet) {
- $params = Yii::$app->request->get();
- $params['mall_id'] = $this->mall_id;
- $data = GroupBuyCate::findOne(['id' => $params['id'], 'mall_id' => $params['mall_id'], 'status' => [StatusEnum::DISABLED, StatusEnum::ENABLED]]);
- return $this->success('操作成功', $data);
- }
- if (\Yii::$app->request->isPost) {
- $params = Yii::$app->request->post();
- $params['mall_id'] = $this->mall_id;
- if (isset($params['status']) && in_array($params['status'], [StatusEnum::DISABLED, StatusEnum::DELETE])) {
- $res = GroupBuyActive::findOne([
- 'mall_id' => $this->mall_id,
- 'cate_id' => $params['id'],
- 'group_status' => [GroupBuyEnum::NOT_STARTED, GroupBuyEnum::OPEN_GROUP],
- 'status'=>[StatusEnum::ENABLED,StatusEnum::DISABLED]
- ]);
- if ($res) return $this->error('该拼团分类已关联拼团活动');
- }
- $res = GroupBuyCate::setData($params);
- if ($res === false) return $this->error(GroupBuyCate::getStaticError());
- return $this->success('操作成功', []);
- }
- }
- }
- /**
- * @desc:获取会员等级列表,添加活动使用,不用验证权限
- * @Author: hua
- * @Date: 2021/12/13
- * @Time: 18:50
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|string|void
- */
- public function actionUserLevelList()
- {
- $request = Yii::$app->request;
- if ($request->isAjax) {
- // 查询参数
- $where[] = ['in', 'status', [StatusEnum::ENABLED]];
- $where[] = ['=', 'mall_id', $this->mall['id']];
- $params = array('where' => $where, 'select' => 'id,level,name', 'order' => 'level asc', 'limit' => $request->get('limit', 12));
- $page_data = UserLevel::listPage($params, false);
- $page_data['list'] = array_merge([['id' => 0, 'level' => 0, 'name' => '普通用户']], $page_data['list']);
- return $this->success('操作成功', $page_data);
- }
- return $this->render($this->action->id);
- }
- /**
- * @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]];
- isset($get['keyword']) && $where[] = ['or', ['like', 'goods_name', $get['keyword']], ['=', 'id', $get['keyword']]];
- if(!empty($get['price'])){
- $where[]=['price'=>trim($get['price'])];
- }
- if (!empty($get['goods_source'])) {
- if ($get['goods_source'] === 'Main') {
- $where[] = ['=', 'mch_id', 0];
- $where[] = ['=', 'goods_source', ''];
- } elseif ($get['goods_source'] === 'Mch') {
- $where[] = ['>', 'mch_id', 0];
- } else {
- $where[] = ['=', 'goods_source', $get['goods_source']];
- }
- }
- // 排序
- // $group_buy_active_list = GroupBuyActive::findAll(['mall_id' => $this->mall_id, 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
- $group_buy_active_list = GroupBuyActive::find()->where(['mall_id'=>$this->mall_id,'status'=>StatusEnum::ENABLED])->andWhere(['>','end_at',time()])->all();
- $goods_id_arr = array_column($group_buy_active_list, 'goods_id');
- if($goods_id_arr) $where[] = ['not in', 'id', $goods_id_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);
- }
- /**
- * @desc:获取商品详情,添加活动使用,不用验证权限
- * @Author: hua
- * @Date: 2021/12/13
- * @Time: 18:51
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|string|void
- */
- public function actionGoodsDetail()
- {
- $request = Yii::$app->request;
- if ($request->isAjax) {
- $get = Yii::$app->request->get();
- $res = Yii::$app->services->validate->validate($get, [[['id'], 'integer']]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $detail = isset($get['id']) ? Goods::getOne([['id' => $get['id'], 'mall_id' => $this->mall_id]], true, ['cats', 'attr', 'extra']) : [];
- $detail['attr_groups'] = json_decode($detail['attr_groups'], true) ?? [];
- $detail['attr_groups_format'] = json_decode($detail['attr_groups_format'], true) ?? [];
- $detail['attr'] = GoodsAttr::formatFormAttr($detail['attr'] ?? [], $detail['attr_groups_format']);
- return $this->success('操作成功', compact('detail'));
- }
- return $this->render($this->action->id);
- }
- /**
- * @desc:获取拼团分类列表,添加活动使用,不用验证权限
- * @Author: hua
- * @Date: 2021/12/13
- * @Time: 18:51
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|string|void
- */
- public function actionCateList()
- {
- $request = Yii::$app->request;
- if ($request->isAjax) {
- $list = GroupBuyCate::lists(['where' => [['mall_id' => $this->mall_id], ['status' => StatusEnum::ENABLED]], 'order' => 'id asc', 'select' => 'id,name']);
- return $this->success('操作成功', compact('list'));
- }
- }
- /**
- * @desc:拼团商品列表
- * @Author: hua
- * @Date: 2021/12/14
- * @Time: 15:52
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|void
- */
- public function actionCheckActiveList()
- {
- $get = \Yii::$app->request->get();
- $where[] = ['mall_id' => $this->mall_id];
- $where[] = ['status' => StatusEnum::ENABLED];
- if (isset($get['active_id'])) $where[] = ['id' => json_decode($get['active_id'], true)];
- $list = GroupBuyActive::getActiveList($where, false);
- return $this->success('操作成功', $list);
- }
- }
|