DefaultController.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. <?php
  2. namespace addons\Bargain\backend\controllers;
  3. use addons\Bargain\common\models\BargainActive;
  4. use addons\Bargain\common\models\BargainCate;
  5. use addons\Bargain\common\enums\BargainEnum;
  6. use addons\Bargain\common\models\BargainOrder;
  7. use addons\Bargain\common\models\BargainUserOrder;
  8. use addons\GroupBuy\common\enums\GroupBuyEnum;
  9. use addons\GroupBuy\common\models\GroupBuyActive;
  10. use addons\GroupBuy\common\models\GroupBuyOrder;
  11. use common\enums\AddonsEnum;
  12. use common\enums\StatusEnum;
  13. use common\models\common\AddonsMarketingSetting;
  14. use common\models\goods\Goods;
  15. use common\models\user\User;
  16. use common\models\user\UserLevel;
  17. use Yii;
  18. use common\controllers\AddonsController;
  19. /**
  20. * 默认控制器
  21. *
  22. * Class DefaultController
  23. * @package addons\Bargain\backend\controllers
  24. */
  25. class DefaultController extends BaseController
  26. {
  27. public $enableCsrfValidation = false;
  28. /**
  29. * @desc: 活动装修
  30. * @Author: hua
  31. * @Date: 2021/12/20
  32. * @Time: 15:56
  33. * @Copyright: copyright (c) 2021 广东七件事集团
  34. * @return mixed|void
  35. */
  36. public function actionDiyIndex()
  37. {
  38. if (\Yii::$app->request->isAjax) {
  39. if (\Yii::$app->request->isPost) {
  40. $params = \Yii::$app->request->post();
  41. $res = \Yii::$app->services->validate->validate($params, [
  42. [['content'], 'required'],
  43. ]);
  44. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  45. $params['mall_id'] = $this->mall_id;
  46. $params['addons_name'] = AddonsEnum::ADDONS_NAME_BARGAIN;
  47. $res = AddonsMarketingSetting::setData($params);
  48. if ($res == false) return $this->error(AddonsMarketingSetting::getStaticError());
  49. return $this->success('操作成功', []);
  50. }
  51. if (\Yii::$app->request->isGet) {
  52. $params['mall_id'] = $this->mall_id;
  53. $params['addons_name'] = AddonsEnum::ADDONS_NAME_BARGAIN;
  54. $params['status'] = StatusEnum::ENABLED;
  55. $res = AddonsMarketingSetting::findOne($params);
  56. if ($res == false) return $this->success('操作成功', $data ?? []);
  57. $data = $res->toArray();
  58. $content = json_decode($data['content'], true);
  59. if (!empty($content)) {
  60. $active_data = array_pop($content);
  61. $active_ids = [];
  62. if (!empty($active_data['data']['goods'])) {
  63. foreach ($active_data['data']['goods'] as $item) {
  64. $active_ids[] = $item['params']['id'];
  65. }
  66. $list = BargainActive::lists(['where' => [
  67. ['id' => $active_ids],
  68. ['status' => StatusEnum::ENABLED],
  69. ['active_status' => [BargainEnum::ACTIVE_HANDING]],
  70. ['mall_id' => $this->mall_id]], 'select' => 'id']
  71. );
  72. $active_id_arr = array_column($list, 'id');//没有被删除的活动id
  73. $goods_data = [];
  74. foreach ($active_data['data']['goods'] as $item) {
  75. if (in_array($item['params']['id'], $active_id_arr)) $goods_data[] = $item;
  76. }
  77. $active_data['data']['goods'] = $goods_data;
  78. $content[] = $active_data;
  79. $data['content'] = json_encode($content);
  80. }
  81. }
  82. return $this->success('操作成功', $data ?? []);
  83. }
  84. }
  85. return $this->render('diy-index');
  86. }
  87. /**
  88. * @desc:分类列表
  89. * @Author: hua
  90. * @Date: 2021/12/31
  91. * @Time: 17:32
  92. * @Copyright: copyright (c) 2021 广东七件事集团
  93. * @return mixed|string|void
  94. */
  95. public function actionCateIndex()
  96. {
  97. if (\Yii::$app->request->isAjax) {
  98. if (\Yii::$app->request->isGet) {
  99. $where[] = ['mall_id' => $this->mall_id];
  100. $where[] = ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]];
  101. $params['limit'] = 10;
  102. $params['where'] = $where;
  103. $params['order'] = 'id DESC';
  104. $pageData = BargainCate::listPage($params, false);
  105. if ($pageData === false) return $this->error(BargainCate::getStaticError());
  106. return $this->success('操作成功', $pageData);
  107. }
  108. }
  109. return $this->render('cate-index', []);
  110. }
  111. /**
  112. * @desc:编辑砍价分类
  113. * @Author: hua
  114. * @Date: 2021/12/31
  115. * @Time: 17:35
  116. * @Copyright: copyright (c) 2021 广东七件事集团
  117. * @return mixed|void
  118. */
  119. public function actionCateEdit()
  120. {
  121. if (\Yii::$app->request->isAjax) {
  122. if (\Yii::$app->request->isGet) {
  123. $params = Yii::$app->request->get();
  124. $params['mall_id'] = $this->mall_id;
  125. $data = BargainCate::findOne(['id' => $params['id'], 'mall_id' => $params['mall_id'], 'status' => [StatusEnum::DISABLED, StatusEnum::ENABLED]]);
  126. return $this->success('操作成功', $data);
  127. }
  128. if (\Yii::$app->request->isPost) {
  129. $params = Yii::$app->request->post();
  130. $params['mall_id'] = $this->mall_id;
  131. if (isset($params['status']) && in_array($params['status'], [StatusEnum::DISABLED, StatusEnum::DELETE])) {
  132. $res = BargainActive::findOne(['mall_id' => $this->mall_id, 'cate_id' => $params['id'], 'active_status' => [BargainEnum::NOT_STARTED, BargainEnum::ACTIVE_HANDING]]);
  133. if ($res) return $this->error('该砍价分类已关联砍价活动');
  134. }
  135. $res = BargainCate::setData($params);
  136. if ($res === false) return $this->error(BargainCate::getStaticError());
  137. return $this->success('操作成功', []);
  138. }
  139. }
  140. }
  141. /**
  142. * @desc:活动列表
  143. * @Author: hua
  144. * @Date: 2022/1/3
  145. * @Time: 14:25
  146. * @Copyright: copyright (c) 2021 广东七件事集团
  147. * @return mixed|string|void
  148. */
  149. public function actionIndex()
  150. {
  151. if (\Yii::$app->request->isAjax) {
  152. if (\Yii::$app->request->isGet) {
  153. $get = \Yii::$app->request->get();
  154. $where[] = ['mall_id' => $this->mall_id];
  155. $where[] = ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]];
  156. if (!empty($get['goods_name'])) {
  157. $goods_list = Goods::lists(['where' => [['mall_id' => $this->mall_id], ['like', 'goods_name', trim($get['goods_name']) . '%', false], ['status' => StatusEnum::ENABLED]], 'select' => 'id']);
  158. $goods_id_arr = array_column($goods_list, 'id');
  159. $where[] = ['goods_id' => $goods_id_arr];
  160. }
  161. if (isset($get['active_status']) && $get['active_status'] != -1) $where[] = ['active_status' => $get['active_status']];
  162. $params['limit'] = 10;
  163. $params['where'] = $where;
  164. $params['order'] = 'id DESC';
  165. $params['with'] = ['goods' => function ($query) {
  166. // $query->where(['status' => StatusEnum::ENABLED]);
  167. }];
  168. $pageData = BargainActive::listPage($params, false);
  169. if ($pageData === false) return $this->error(BargainActive::getStaticError());
  170. return $this->success('操作成功', $pageData);
  171. }
  172. }
  173. return $this->render('index', []);
  174. }
  175. /**
  176. * @desc:添加活动
  177. * @Author: hua
  178. * @Date: 2021/12/31
  179. * @Time: 17:48
  180. * @Copyright: copyright (c) 2021 广东七件事集团
  181. * @return mixed|string|void
  182. */
  183. public function actionEdit()
  184. {
  185. if (\Yii::$app->request->isAjax) {
  186. if (\Yii::$app->request->isPost) {
  187. $params = \Yii::$app->request->post();
  188. $params['mall_id'] = $this->mall_id;
  189. if(is_array($params['goods_id']))$params['goods_id'] = $params['goods_id']['id'];
  190. $params['status'] = StatusEnum::ENABLED;
  191. $params['description'] = $params['description'] ?? '';
  192. $res = BargainActive::setData($params);
  193. if ($res === false) return $this->error(BargainActive::getStaticError());
  194. return $this->success('操作成功');
  195. }
  196. if (\Yii::$app->request->isGet) {
  197. $params = \Yii::$app->request->get();
  198. if (empty($params['id'])) {
  199. $data = [
  200. 'title' => '',
  201. 'cate_id' => 0,
  202. 'goods_id' => 0,
  203. 'type' => 1,
  204. 'stock' => 0,
  205. 'min_price' => 0,
  206. 'time' => 0,
  207. 'active_date' => [],
  208. 'mode_data' => [
  209. 'bargain_people' => 0,
  210. 'bargain_human' => 0,
  211. 'bargain_first_min_price' => 0,
  212. 'bargain_first_max_price' => 0,
  213. 'bargain_second_min_price' => 0,
  214. 'bargain_second_max_price' => 0,
  215. 'commission_type' => 0,
  216. ],
  217. 'attr_setting_type' => 0,
  218. 'join_limit_user_level' => [],
  219. 'bargain_limit_user_level' => [],
  220. 'join_time' => 1,
  221. 'bargain_time' => 1,
  222. 'is_repeat_bargain' => 1,
  223. 'introduction' => '',
  224. 'description' => '',
  225. 'is_creator_exempt' => 1,
  226. ];
  227. $data['goods'] = [];
  228. $data['cate']['name'] = '';
  229. } else {
  230. $params['mall_id'] = $this->mall_id;
  231. $with = ['goods' => function ($query) {
  232. $query->with(['attr']);
  233. }, 'cate'];
  234. $data = BargainActive::getOne([['id' => $params['id']], ['mall_id' => $this->mall_id]], true, $with);
  235. $data['active_date'][] = date('Y-m-d H:i:s', $data['begin_time']);
  236. $data['active_date'][] = date('Y-m-d H:i:s', $data['end_time']);
  237. $data['mode_data'] = json_decode($data['mode_data'], true);
  238. $data['join_limit_user_level'] = empty($data['join_limit_user_level']) ? [] : json_decode($data['join_limit_user_level'], true);
  239. $data['bargain_limit_user_level'] = empty($data['bargain_limit_user_level']) ? [] : json_decode($data['bargain_limit_user_level'], true);
  240. }
  241. $cate_list = BargainCate::lists(['where' => [['mall_id' => $this->mall_id], ['status' => StatusEnum::ENABLED]], 'order' => 'id asc', 'select' => 'id,name']);
  242. $data['cate_list'] = $cate_list;
  243. //获取商城用户等级 包含默认登记
  244. $default['level'] = 0;
  245. $default['name'] = '系统默认会员等级';
  246. $default['id'] = 0;
  247. $user_level_list = UserLevel::getUserLevel([['mall_id' => $this->mall_id]], [], 1);
  248. array_unshift($user_level_list,$default);
  249. $data['user_level_list'] = $user_level_list;
  250. return $this->success('操作成功', $data);
  251. }
  252. }
  253. $params = \Yii::$app->request->get();
  254. $title = empty($params['id']) ? '添加页面' : '编辑页面';
  255. return $this->render('edit', ['title' => $title]);
  256. }
  257. /**
  258. * @desc:删除
  259. * @Author: hua
  260. * @Date: 2021/12/13
  261. * @Time: 18:50
  262. * @Copyright: copyright (c) 2021 广东七件事集团
  263. * @return mixed|string|void
  264. */
  265. public function actionDel()
  266. {
  267. if (\Yii::$app->request->isAjax) {
  268. if (\Yii::$app->request->isGet) {
  269. $params = \Yii::$app->request->get();
  270. $params['mall_id'] = $this->mall_id;
  271. $params['status'] = StatusEnum::DELETE;
  272. $res = BargainActive::setData($params);
  273. if ($res === false) return $this->error(BargainActive::getStaticError());
  274. return $this->success('操作成功');
  275. }
  276. }
  277. return $this->render('index', []);
  278. }
  279. /**
  280. * @desc:失效操作
  281. * @Author: hua
  282. * @Date: 2022/1/3
  283. * @Time: 14:25
  284. * @Copyright: copyright (c) 2021 广东七件事集团
  285. * @return mixed|string|void
  286. */
  287. public function actionInvalid()
  288. {
  289. if (\Yii::$app->request->isAjax) {
  290. if (\Yii::$app->request->isGet) {
  291. $get = \Yii::$app->request->get();
  292. $get['mall_id'] = $this->mall_id;
  293. $res = BargainActive::invalidData($get);
  294. if ($res === false) return $this->error(BargainActive::getStaticError());
  295. return $this->success('操作成功');
  296. }
  297. }
  298. return $this->render('index', []);
  299. }
  300. /**
  301. * @desc:砍价订单详情
  302. * @Author: ltm
  303. * @Date: 2022/1/6
  304. * @Time: 14:48
  305. * @Copyright: copyright (c) 2021 广东七件事集团
  306. * @return mixed|string|void
  307. */
  308. public function actionOrderList()
  309. {
  310. if (\Yii::$app->request->isAjax) {
  311. if (\Yii::$app->request->isGet) {
  312. $get = \Yii::$app->request->get();
  313. $where[] = ['mall_id' => $this->mall_id];
  314. $where[] = ['status' => StatusEnum::ENABLED];
  315. if (!empty($get['mobile'])) {
  316. $user_list = User::lists(['where' => [['mall_id' => $this->mall_id], ['like', 'mobile', trim($get['mobile']) . '%', false], ['status' => StatusEnum::ENABLED]], 'select' => 'id']);
  317. $user_id_arr = array_column($user_list, 'id');
  318. $where[] = ['user_id' => $user_id_arr];
  319. }
  320. if (!empty($get['nickname'])) {
  321. $user_list = User::lists(['where' => [['mall_id' => $this->mall_id], ['like', 'nickname', trim($get['nickname']) . '%', false], ['status' => StatusEnum::ENABLED]], 'select' => 'id']);
  322. $user_id_arr = array_column($user_list, 'id');
  323. $where[] = ['user_id' => $user_id_arr];
  324. }
  325. if (!empty($get['order_no'])) {
  326. $where[] = ['order_no' => $get['order_no']];
  327. }
  328. if (isset($get['order_status']) && $get['order_status'] != -1) $where[] = ['order_status' => $get['order_status']];
  329. $params['limit'] = 10;
  330. $params['where'] = $where;
  331. $params['order'] = 'id DESC';
  332. $params['with'] = ['user', 'active'];
  333. $pageData = BargainOrder::listPage($params, false);
  334. if ($pageData === false) return $this->error(BargainOrder::getStaticError());
  335. $pageData['order_status_map'] = BargainEnum::getOrderStatusMap();
  336. return $this->success('操作成功', $pageData);
  337. }
  338. }
  339. return $this->render('order-list', []);
  340. }
  341. /**
  342. * @desc:砍价订单
  343. * @Author: hua
  344. * @Date: 2022/1/6
  345. * @Time: 14:48
  346. * @Copyright: copyright (c) 2021 广东七件事集团
  347. * @return mixed|string|void
  348. */
  349. public function actionUserOrderList()
  350. {
  351. if (\Yii::$app->request->isAjax) {
  352. if (\Yii::$app->request->isGet) {
  353. $get = \Yii::$app->request->get();
  354. $where[] = ['mall_id' => $this->mall_id];
  355. $where[] = ['status' => StatusEnum::ENABLED];
  356. $where[] = ['bargain_order_id' => $get['bargain_order_id']];
  357. if (!empty($get['mobile'])) {
  358. $user_list = User::lists(['where' => [['mall_id' => $this->mall_id], ['like', 'mobile', trim($get['mobile']) . '%', false], ['status' => StatusEnum::ENABLED]], 'select' => 'id']);
  359. $user_id_arr = array_column($user_list, 'id');
  360. $where[] = ['user_id' => $user_id_arr];
  361. }
  362. if (!empty($get['nickname'])) {
  363. $user_list = User::lists(['where' => [['mall_id' => $this->mall_id], ['like', 'nickname', trim($get['nickname']) . '%', false], ['status' => StatusEnum::ENABLED]], 'select' => 'id']);
  364. $user_id_arr = array_column($user_list, 'id');
  365. $where[] = ['user_id' => $user_id_arr];
  366. }
  367. $params['limit'] = 10;
  368. $params['where'] = $where;
  369. $params['order'] = 'id DESC';
  370. $params['with'] = ['user']; //var_dump($params);
  371. $pageData = BargainUserOrder::listPage($params, false);
  372. if ($pageData === false) return $this->error(BargainUserOrder::getStaticError());
  373. $pageData['order_status_map'] = BargainEnum::getOrderStatusMap();
  374. return $this->success('操作成功', $pageData);
  375. }
  376. }
  377. return $this->render('user-order-list', []);
  378. }
  379. public function actionSetting()
  380. {
  381. if (\Yii::$app->request->isAjax) {
  382. if (\Yii::$app->request->isPost) {
  383. $params = \Yii::$app->request->post();
  384. $params['mall_id'] = $this->mall_id;
  385. $postData['mall_id'] = $this->mall_id;
  386. \Yii::$app->services->setting->addons->set($this->mall_id, BargainEnum::ADDONS_NAME, ['basic' => $params]);
  387. return $this->success('操作成功');
  388. }
  389. if (\Yii::$app->request->isGet) {
  390. $list = \Yii::$app->services->setting->addons->get($this->mall_id, BargainEnum::ADDONS_NAME, 'basic');
  391. if(empty($list['grant_type'])) $list['grant_type'] = 1;
  392. return $this->success('操作成功', ['list' => $list]);
  393. }
  394. }
  395. return $this->render('setting', []);
  396. }
  397. /**
  398. * @desc:获取商品列表,添加活动使用,不用验证权限
  399. * @Author: hua
  400. * @Date: 2021/12/31
  401. * @Time: 17:55
  402. * @Copyright: copyright (c) 2021 广东七件事集团
  403. * @return mixed|string|void
  404. */
  405. public function actionGoodsList()
  406. {
  407. $request = Yii::$app->request;
  408. if ($request->isAjax) {
  409. //商品列表筛选
  410. $params = Yii::$app->request->get();
  411. // 排序
  412. $bargain_active_list = BargainActive::findAll(['mall_id' => $this->mall_id, 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED], 'active_status'=>[BargainEnum::NOT_STARTED,BargainEnum::ACTIVE_HANDING]]);
  413. $goods_id_arr = array_column($bargain_active_list, 'goods_id');
  414. $where = [
  415. ['mall_id' => $this->mall['id']],
  416. ['status' => [StatusEnum::ENABLED]],
  417. ['is_on_sale' => 1],
  418. ['is_attr' => 0],
  419. ];
  420. if (isset($params['goods_source'])) {
  421. if ($params['goods_source'] == 1) {
  422. $where[] = ['=', 'mch_id', 0];
  423. }
  424. if ($params['goods_source'] == 2) {
  425. $where[] = ['>', 'mch_id', 0];
  426. }
  427. }
  428. if (isset($params['keyword'])) {
  429. $where[] = [
  430. 'or',
  431. ['like', 'goods_name', '%'. trim($params['keyword']) . '%', false],
  432. ['=', 'id', trim($params['keyword'])],
  433. ];
  434. }
  435. $filterGoodsSource = ['JuheShop', 'QiJuhe'];
  436. if (!empty($filterGoodsSource)) { // 过滤供应链商品
  437. $where[] = ['not in', 'goods_source', $filterGoodsSource];
  438. }
  439. // dd($where);
  440. $where[] = ['not in', 'id', $goods_id_arr];
  441. $params['where'] = $where;
  442. $params['limit'] = 10;
  443. $params['order'] = 'sort ASC,id DESC';
  444. $page_data = Goods::getGoodsList($params, true, false);
  445. if ($page_data === false) return $this->error(Goods::getStaticError());
  446. return $this->success('操作成功', $page_data);
  447. }
  448. return $this->render($this->action->id);
  449. }
  450. /**
  451. * @desc:拼团商品列表
  452. * @Author: hua
  453. * @Date: 2021/12/14
  454. * @Time: 15:52
  455. * @Copyright: copyright (c) 2021 广东七件事集团
  456. * @return mixed|void
  457. */
  458. public function actionCheckActiveList()
  459. {
  460. $get = \Yii::$app->request->get();
  461. $where[] = ['mall_id' => $this->mall_id];
  462. $where[] = ['status' => StatusEnum::ENABLED];
  463. $where[] = ['>', 'stock', 0];
  464. if (isset($get['active_id'])) $where[] = ['id' => json_decode($get['active_id'], true)];
  465. $list = BargainActive::getActiveList($where, false);
  466. return $this->success('操作成功', $list);
  467. }
  468. }