| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495 |
- <?php
- namespace addons\Bargain\backend\controllers;
- use addons\Bargain\common\models\BargainActive;
- use addons\Bargain\common\models\BargainCate;
- use addons\Bargain\common\enums\BargainEnum;
- use addons\Bargain\common\models\BargainOrder;
- use addons\Bargain\common\models\BargainUserOrder;
- use addons\GroupBuy\common\enums\GroupBuyEnum;
- use addons\GroupBuy\common\models\GroupBuyActive;
- use addons\GroupBuy\common\models\GroupBuyOrder;
- use common\enums\AddonsEnum;
- use common\enums\StatusEnum;
- use common\models\common\AddonsMarketingSetting;
- use common\models\goods\Goods;
- use common\models\user\User;
- use common\models\user\UserLevel;
- use Yii;
- use common\controllers\AddonsController;
- /**
- * 默认控制器
- *
- * Class DefaultController
- * @package addons\Bargain\backend\controllers
- */
- class DefaultController extends BaseController
- {
- public $enableCsrfValidation = false;
- /**
- * @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'] = AddonsEnum::ADDONS_NAME_BARGAIN;
- $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'] = AddonsEnum::ADDONS_NAME_BARGAIN;
- $params['status'] = StatusEnum::ENABLED;
- $res = AddonsMarketingSetting::findOne($params);
- if ($res == false) return $this->success('操作成功', $data ?? []);
- $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 = BargainActive::lists(['where' => [
- ['id' => $active_ids],
- ['status' => StatusEnum::ENABLED],
- ['active_status' => [BargainEnum::ACTIVE_HANDING]],
- ['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/31
- * @Time: 17:32
- * @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 = BargainCate::listPage($params, false);
- if ($pageData === false) return $this->error(BargainCate::getStaticError());
- return $this->success('操作成功', $pageData);
- }
- }
- return $this->render('cate-index', []);
- }
- /**
- * @desc:编辑砍价分类
- * @Author: hua
- * @Date: 2021/12/31
- * @Time: 17:35
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|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 = BargainCate::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 = BargainActive::findOne(['mall_id' => $this->mall_id, 'cate_id' => $params['id'], 'active_status' => [BargainEnum::NOT_STARTED, BargainEnum::ACTIVE_HANDING]]);
- if ($res) return $this->error('该砍价分类已关联砍价活动');
- }
- $res = BargainCate::setData($params);
- if ($res === false) return $this->error(BargainCate::getStaticError());
- return $this->success('操作成功', []);
- }
- }
- }
- /**
- * @desc:活动列表
- * @Author: hua
- * @Date: 2022/1/3
- * @Time: 14:25
- * @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, StatusEnum::DISABLED]];
- 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['active_status']) && $get['active_status'] != -1) $where[] = ['active_status' => $get['active_status']];
- $params['limit'] = 10;
- $params['where'] = $where;
- $params['order'] = 'id DESC';
- $params['with'] = ['goods' => function ($query) {
- // $query->where(['status' => StatusEnum::ENABLED]);
- }];
- $pageData = BargainActive::listPage($params, false);
- if ($pageData === false) return $this->error(BargainActive::getStaticError());
- return $this->success('操作成功', $pageData);
- }
- }
- return $this->render('index', []);
- }
- /**
- * @desc:添加活动
- * @Author: hua
- * @Date: 2021/12/31
- * @Time: 17:48
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|string|void
- */
- public function actionEdit()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isPost) {
- $params = \Yii::$app->request->post();
- $params['mall_id'] = $this->mall_id;
- if(is_array($params['goods_id']))$params['goods_id'] = $params['goods_id']['id'];
- $params['status'] = StatusEnum::ENABLED;
- $params['description'] = $params['description'] ?? '';
- $res = BargainActive::setData($params);
- if ($res === false) return $this->error(BargainActive::getStaticError());
- return $this->success('操作成功');
- }
- if (\Yii::$app->request->isGet) {
- $params = \Yii::$app->request->get();
- if (empty($params['id'])) {
- $data = [
- 'title' => '',
- 'cate_id' => 0,
- 'goods_id' => 0,
- 'type' => 1,
- 'stock' => 0,
- 'min_price' => 0,
- 'time' => 0,
- 'active_date' => [],
- 'mode_data' => [
- 'bargain_people' => 0,
- 'bargain_human' => 0,
- 'bargain_first_min_price' => 0,
- 'bargain_first_max_price' => 0,
- 'bargain_second_min_price' => 0,
- 'bargain_second_max_price' => 0,
- 'commission_type' => 0,
- ],
- 'attr_setting_type' => 0,
- 'join_limit_user_level' => [],
- 'bargain_limit_user_level' => [],
- 'join_time' => 1,
- 'bargain_time' => 1,
- 'is_repeat_bargain' => 1,
- 'introduction' => '',
- 'description' => '',
- 'is_creator_exempt' => 1,
- ];
- $data['goods'] = [];
- $data['cate']['name'] = '';
- } else {
- $params['mall_id'] = $this->mall_id;
- $with = ['goods' => function ($query) {
- $query->with(['attr']);
- }, 'cate'];
- $data = BargainActive::getOne([['id' => $params['id']], ['mall_id' => $this->mall_id]], true, $with);
- $data['active_date'][] = date('Y-m-d H:i:s', $data['begin_time']);
- $data['active_date'][] = date('Y-m-d H:i:s', $data['end_time']);
- $data['mode_data'] = json_decode($data['mode_data'], true);
- $data['join_limit_user_level'] = empty($data['join_limit_user_level']) ? [] : json_decode($data['join_limit_user_level'], true);
- $data['bargain_limit_user_level'] = empty($data['bargain_limit_user_level']) ? [] : json_decode($data['bargain_limit_user_level'], true);
- }
- $cate_list = BargainCate::lists(['where' => [['mall_id' => $this->mall_id], ['status' => StatusEnum::ENABLED]], 'order' => 'id asc', 'select' => 'id,name']);
- $data['cate_list'] = $cate_list;
- //获取商城用户等级 包含默认登记
- $default['level'] = 0;
- $default['name'] = '系统默认会员等级';
- $default['id'] = 0;
- $user_level_list = UserLevel::getUserLevel([['mall_id' => $this->mall_id]], [], 1);
- array_unshift($user_level_list,$default);
- $data['user_level_list'] = $user_level_list;
- return $this->success('操作成功', $data);
- }
- }
- $params = \Yii::$app->request->get();
- $title = empty($params['id']) ? '添加页面' : '编辑页面';
- return $this->render('edit', ['title' => $title]);
- }
- /**
- * @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) {
- $params = \Yii::$app->request->get();
- $params['mall_id'] = $this->mall_id;
- $params['status'] = StatusEnum::DELETE;
- $res = BargainActive::setData($params);
- if ($res === false) return $this->error(BargainActive::getStaticError());
- return $this->success('操作成功');
- }
- }
- return $this->render('index', []);
- }
- /**
- * @desc:失效操作
- * @Author: hua
- * @Date: 2022/1/3
- * @Time: 14:25
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|string|void
- */
- public function actionInvalid()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isGet) {
- $get = \Yii::$app->request->get();
- $get['mall_id'] = $this->mall_id;
- $res = BargainActive::invalidData($get);
- if ($res === false) return $this->error(BargainActive::getStaticError());
- return $this->success('操作成功');
- }
- }
- return $this->render('index', []);
- }
- /**
- * @desc:砍价订单详情
- * @Author: ltm
- * @Date: 2022/1/6
- * @Time: 14:48
- * @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', 'active'];
- $pageData = BargainOrder::listPage($params, false);
- if ($pageData === false) return $this->error(BargainOrder::getStaticError());
- $pageData['order_status_map'] = BargainEnum::getOrderStatusMap();
- return $this->success('操作成功', $pageData);
- }
- }
- return $this->render('order-list', []);
- }
- /**
- * @desc:砍价订单
- * @Author: hua
- * @Date: 2022/1/6
- * @Time: 14:48
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|string|void
- */
- public function actionUserOrderList()
- {
- 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];
- $where[] = ['bargain_order_id' => $get['bargain_order_id']];
- 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];
- }
- $params['limit'] = 10;
- $params['where'] = $where;
- $params['order'] = 'id DESC';
- $params['with'] = ['user']; //var_dump($params);
- $pageData = BargainUserOrder::listPage($params, false);
- if ($pageData === false) return $this->error(BargainUserOrder::getStaticError());
- $pageData['order_status_map'] = BargainEnum::getOrderStatusMap();
- return $this->success('操作成功', $pageData);
- }
- }
- return $this->render('user-order-list', []);
- }
- public function actionSetting()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isPost) {
- $params = \Yii::$app->request->post();
- $params['mall_id'] = $this->mall_id;
- $postData['mall_id'] = $this->mall_id;
- \Yii::$app->services->setting->addons->set($this->mall_id, BargainEnum::ADDONS_NAME, ['basic' => $params]);
- return $this->success('操作成功');
- }
- if (\Yii::$app->request->isGet) {
- $list = \Yii::$app->services->setting->addons->get($this->mall_id, BargainEnum::ADDONS_NAME, 'basic');
- if(empty($list['grant_type'])) $list['grant_type'] = 1;
- return $this->success('操作成功', ['list' => $list]);
- }
- }
- return $this->render('setting', []);
- }
- /**
- * @desc:获取商品列表,添加活动使用,不用验证权限
- * @Author: hua
- * @Date: 2021/12/31
- * @Time: 17:55
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|string|void
- */
- public function actionGoodsList()
- {
- $request = Yii::$app->request;
- if ($request->isAjax) {
- //商品列表筛选
- $params = Yii::$app->request->get();
- // 排序
- $bargain_active_list = BargainActive::findAll(['mall_id' => $this->mall_id, 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED], 'active_status'=>[BargainEnum::NOT_STARTED,BargainEnum::ACTIVE_HANDING]]);
- $goods_id_arr = array_column($bargain_active_list, 'goods_id');
- $where = [
- ['mall_id' => $this->mall['id']],
- ['status' => [StatusEnum::ENABLED]],
- ['is_on_sale' => 1],
- ['is_attr' => 0],
- ];
- if (isset($params['goods_source'])) {
- if ($params['goods_source'] == 1) {
- $where[] = ['=', 'mch_id', 0];
- }
- if ($params['goods_source'] == 2) {
- $where[] = ['>', 'mch_id', 0];
- }
- }
- if (isset($params['keyword'])) {
- $where[] = [
- 'or',
- ['like', 'goods_name', '%'. trim($params['keyword']) . '%', false],
- ['=', 'id', trim($params['keyword'])],
- ];
- }
- $filterGoodsSource = ['JuheShop', 'QiJuhe'];
- if (!empty($filterGoodsSource)) { // 过滤供应链商品
- $where[] = ['not in', 'goods_source', $filterGoodsSource];
- }
- // dd($where);
- $where[] = ['not in', 'id', $goods_id_arr];
- $params['where'] = $where;
- $params['limit'] = 10;
- $params['order'] = 'sort ASC,id DESC';
- $page_data = Goods::getGoodsList($params, true, false);
- 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/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];
- $where[] = ['>', 'stock', 0];
- if (isset($get['active_id'])) $where[] = ['id' => json_decode($get['active_id'], true)];
- $list = BargainActive::getActiveList($where, false);
- return $this->success('操作成功', $list);
- }
- }
|