DefaultController.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. <?php
  2. namespace addons\GroupBuy\backend\controllers;
  3. use addons\GroupBuy\common\enums\GroupBuyEnum;
  4. use addons\GroupBuy\common\logic\order\ActiveFinish;
  5. use addons\GroupBuy\common\models\GroupBuyActive;
  6. use addons\GroupBuy\common\models\GroupBuyActiveGoodsAttr;
  7. use addons\GroupBuy\common\models\GroupBuyCate;
  8. use addons\GroupBuy\common\models\GroupBuyOrder;
  9. use common\enums\PayTypeEnum;
  10. use common\enums\StatusEnum;
  11. use common\models\common\AddonsMarketingSetting;
  12. use common\models\common\PaymentTrade;
  13. use common\models\common\PaymentTradeOrder;
  14. use common\models\goods\Goods;
  15. use common\models\goods\GoodsAttr;
  16. use common\models\user\User;
  17. use common\models\user\UserLevel;
  18. use EasyWeChat\Factory;
  19. use Yii;
  20. /**
  21. * 默认控制器
  22. *
  23. * Class DefaultController
  24. * @package addons\GroupBuy\backend\controllers
  25. */
  26. class DefaultController extends BaseController
  27. {
  28. public $enableCsrfValidation = false;
  29. /**
  30. * @desc:拼团活动列表
  31. * @Author: hua
  32. * @Date: 2021/12/13
  33. * @Time: 18:49
  34. * @Copyright: copyright (c) 2021 广东七件事集团
  35. * @return mixed|string|void
  36. */
  37. public function actionIndex()
  38. {
  39. if (\Yii::$app->request->isAjax) {
  40. if (\Yii::$app->request->isGet) {
  41. $get = \Yii::$app->request->get();
  42. $where[] = ['mall_id' => $this->mall_id];
  43. $where[] = ['status' => StatusEnum::ENABLED];
  44. if (!empty($get['goods_name'])) {
  45. $goods_list = Goods::lists(['where' => [['mall_id' => $this->mall_id], ['like', 'goods_name', trim($get['goods_name']) . '%', false], ['status' => StatusEnum::ENABLED]], 'select' => 'id']);
  46. $goods_id_arr = array_column($goods_list, 'id');
  47. $where[] = ['goods_id' => $goods_id_arr];
  48. }
  49. if (isset($get['group_status']) && $get['group_status'] != -1) $where[] = ['group_status' => $get['group_status']];
  50. $params['limit'] = 10;
  51. $params['where'] = $where;
  52. $params['order'] = 'id DESC';
  53. $params['with'] = ['goods' => function ($query) {
  54. // $query->where(['status' => StatusEnum::ENABLED]);
  55. }];
  56. $pageData = GroupBuyActive::listPage($params, false);
  57. if ($pageData === false) return $this->error(GroupBuyActive::getStaticError());
  58. if(!empty($pageData['list'])){
  59. $mall_sign = $this->mall['mall_sign'];
  60. $h5_domain = Yii::$app->services->setting->platform->get('system.h5_url');
  61. foreach ($pageData['list'] as &$lv){
  62. $lv['page_link'] = $h5_domain . '/#/plugins/group_buy/goodsDetail?sign=' . $mall_sign . '&active_id=' . $lv['id'];
  63. $lv['poster_filename'] = substr(md5("{'poster'_{$lv['id']}_{$this->mall_id}"), 0, 16);
  64. $lv['qrcode_filename'] = substr(md5("{'qrcode'_{$lv['id']}_{$this->mall_id}"), 0, 16);
  65. }
  66. $mall_logo = \Yii::$app->services->setting->mall->get($this->mall_id, 'basic.logo');
  67. if (empty($mall_logo)) \Yii::$app->request->hostInfo . '/resources/img/mall/mall_logo_default.jpg';
  68. $mall_logo = $this->imgBase64Encode($mall_logo);
  69. $mall_name = \Yii::$app->services->setting->mall->get($this->mall_id, 'basic.name');
  70. if (empty($mall_name)) $mall_name = '七件事商城';
  71. $pageData['mall_info']['mall_logo'] = $mall_logo;
  72. $pageData['mall_info']['mall_name'] = $mall_name;
  73. }
  74. return $this->success('操作成功', $pageData);
  75. }
  76. }
  77. return $this->render('index', []);
  78. }
  79. /**
  80. * 图片base64编码
  81. * @param string $img
  82. * @param bool $imgHtmlCode
  83. * author 江南极客
  84. * @return string
  85. */
  86. function imgBase64Encode($img = '', $imgHtmlCode = true)
  87. {
  88. //如果是本地文件
  89. if(strpos($img,'http') === false && !file_exists($img)){
  90. return $img;
  91. }
  92. //获取文件内容
  93. $file_content = file_get_contents($img);
  94. if($file_content === false){
  95. return $img;
  96. }
  97. $imageInfo = getimagesize($img);
  98. $prefiex = '';
  99. if($imgHtmlCode){
  100. $prefiex = 'data:' . $imageInfo['mime'] . ';base64,';
  101. }
  102. $base64 = $prefiex.chunk_split(base64_encode($file_content));
  103. return $base64;
  104. }
  105. /**
  106. * @desc:详情
  107. * @Author: hua
  108. * @Date: 2021/12/13
  109. * @Time: 18:50
  110. * @Copyright: copyright (c) 2021 广东七件事集团
  111. * @return mixed|string|void
  112. */
  113. public function actionDetail()
  114. {
  115. if (\Yii::$app->request->isAjax) {
  116. if (\Yii::$app->request->isGet) {
  117. $get = \Yii::$app->request->get();
  118. GroupBuyActive::checkActive($get['id'], $this->mall_id);
  119. $list = GroupBuyActiveGoodsAttr::lists(['where' => [['mall_id' => $this->mall_id], ['group_buy_active_id' => $get['id']]], 'with' => [
  120. 'goodsAttr' => function ($query) {
  121. $query->where(['status' => StatusEnum::ENABLED]);
  122. },
  123. 'goods' => function ($query) {
  124. $query->where(['status' => StatusEnum::ENABLED]);
  125. },
  126. 'groupBuyActive' => function ($query) {
  127. $query->where(['status' => StatusEnum::ENABLED]);
  128. },
  129. ]]);
  130. if ($list === false) return $this->error(GroupBuyActive::getStaticError());
  131. $commander_level_limit = '';
  132. $user_level_limit = '';
  133. foreach ($list as $item) {
  134. $commander_level_limit = $item['groupBuyActive']['commander_level_limit'];
  135. $user_level_limit = $item['groupBuyActive']['user_level_limit'];
  136. break;
  137. }
  138. $function = function ($level_limit) {
  139. $level_arr = explode(',', $level_limit);
  140. $user_level_list = UserLevel::lists(['where' => [['level' => $level_arr], ['mall_id' => $this->mall_id], ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]], 'select' => 'name']);
  141. $temp = array_column($user_level_list, 'name');
  142. // 存在等级0
  143. if (in_array(0, $level_arr)) $temp[] = '普通用户';
  144. return join(',', $temp);
  145. };
  146. $commander_level_limit_text = '全部';
  147. $user_level_limit_text = '全部';
  148. if ($commander_level_limit != 'all') {
  149. $commander_level_limit_text = $function($commander_level_limit);
  150. }
  151. if ($user_level_limit != 'all') {
  152. $user_level_limit_text = $function($user_level_limit);
  153. }
  154. return $this->success('操作成功', ['list' => $list, 'commander_level_limit_text' => $commander_level_limit_text, 'user_level_limit_text' => $user_level_limit_text]);
  155. }
  156. }
  157. return $this->render('index', []);
  158. }
  159. /**
  160. * @desc:删除
  161. * @Author: hua
  162. * @Date: 2021/12/13
  163. * @Time: 18:50
  164. * @Copyright: copyright (c) 2021 广东七件事集团
  165. * @return mixed|string|void
  166. */
  167. public function actionDel()
  168. {
  169. if (\Yii::$app->request->isAjax) {
  170. if (\Yii::$app->request->isGet) {
  171. $get = \Yii::$app->request->get();
  172. $get['mall_id'] = $this->mall_id;
  173. $res = GroupBuyActive::delData($get);
  174. if ($res === false) return $this->error(GroupBuyActive::getStaticError());
  175. return $this->success('操作成功');
  176. }
  177. }
  178. return $this->render('index', []);
  179. }
  180. /**
  181. * @desc:添加活动
  182. * @Author: hua
  183. * @Date: 2021/12/13
  184. * @Time: 18:50
  185. * @Copyright: copyright (c) 2021 广东七件事集团
  186. * @return mixed|string|void
  187. */
  188. public function actionAdd()
  189. {
  190. if (\Yii::$app->request->isAjax) {
  191. if (\Yii::$app->request->isPost) {
  192. $params = \Yii::$app->request->post();
  193. $params['mall_id'] = $this->mall_id;
  194. $res = GroupBuyActive::setData($params);
  195. if ($res === false) return $this->error(GroupBuyActive::getStaticError());
  196. return $this->success('操作成功');
  197. }
  198. }
  199. $title = '添加页面';
  200. return $this->render('add', ['title' => $title]);
  201. }
  202. /**
  203. * @desc:开团列表
  204. * @Author: hua
  205. * @Date: 2021/12/13
  206. * @Time: 18:49
  207. * @Copyright: copyright (c) 2021 广东七件事集团
  208. * @return mixed|string|void
  209. */
  210. public function actionOpenList()
  211. {
  212. if (\Yii::$app->request->isAjax) {
  213. if (\Yii::$app->request->isGet) {
  214. $params = \Yii::$app->request->get();
  215. $where[] = ['group_buy_active_id' => $params['group_buy_active_id']];
  216. $where[] = ['mall_id' => $this->mall_id];
  217. $where[] = ['is_commander' => 1];
  218. if (!empty($params['nickname'])) {
  219. $user_list = User::lists(['where' => [['like', 'nickname', $params['nickname'] . '%', false]], 'select' => 'id']);
  220. $where[] = ['user_id' => array_column($user_list, 'id')];
  221. }
  222. if (!empty($params['begin_time'])) $where[] = ['>=', 'created_at', strtotime($params['begin_time'])];
  223. if (!empty($params['end_time'])) $where[] = ['<=', 'created_at', strtotime($params['end_time'])];
  224. if (isset($params['order_status']) && $params['order_status'] != -1) $where[] = ['order_status' => $params['order_status']];
  225. $params['limit'] = 10;
  226. $params['where'] = $where;
  227. $params['with'] = ['user', 'groupBuyActive'];
  228. $list = GroupBuyOrder::listPage($params);
  229. if (!empty($list['list'])) {
  230. $open_group_id_arr = array_column($list['list'], 'open_group_id');
  231. $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']);
  232. foreach ($list['list'] as &$item) {
  233. $item['counts'] = $order_arr[$item['open_group_id']]['counts'] ?? 0;
  234. }
  235. }
  236. return $this->success('操作成功', $list);
  237. }
  238. }
  239. return $this->render('open-list', []);
  240. }
  241. /**
  242. * @desc:拼团成员
  243. * @Author: hua
  244. * @Date: 2021/12/14
  245. * @Time: 14:49
  246. * @Copyright: copyright (c) 2021 广东七件事集团
  247. * @return mixed|void
  248. */
  249. public function actionGroupBuyTeam()
  250. {
  251. if (\Yii::$app->request->isAjax) {
  252. if (\Yii::$app->request->isGet) {
  253. $get = \Yii::$app->request->get();
  254. $where[] = ['group_buy_active_id' => $get['group_buy_active_id']];
  255. $where[] = ['open_group_id' => $get['open_group_id']];
  256. $where[] = ['commander_id' => $get['commander_id']];
  257. $where[] = ['mall_id' => $this->mall_id];
  258. $where[] = ['is_pay' => 1];
  259. $params['where'] = $where;
  260. $params['with'] = ['user', 'groupBuyActive'];
  261. $list = GroupBuyOrder::listPage($params);
  262. return $this->success('操作成功', $list);
  263. }
  264. }
  265. }
  266. /**
  267. * @desc:结束拼团
  268. * @Author: hua
  269. * @Date: 2021/12/14
  270. * @Time: 15:16
  271. * @Copyright: copyright (c) 2021 广东七件事集团
  272. * @return mixed|void
  273. */
  274. public function actionFinish()
  275. {
  276. if (\Yii::$app->request->isAjax) {
  277. if (\Yii::$app->request->isGet) {
  278. $get = \Yii::$app->request->get();
  279. $counts = GroupBuyOrder::find()->where(['mall_id'=>$this->mall_id,'open_group_id'=>$get['open_group_id'],'is_pay'=>1])->count();
  280. $group_order = GroupBuyOrder::findOne(['mall_id'=>$this->mall_id,'id'=>$get['open_group_id'],'is_pay'=>1]);
  281. $active = GroupBuyActive::findOne(['mall_id'=>$this->mall_id,'id'=>$group_order['group_buy_active_id']]);
  282. if($active->is_virtual){
  283. if($active->virtual_group_type==2&&$counts<$active->gt_group_size){
  284. $res = GroupBuyOrder::finishGroupBuyOrder($this->mall_id, $get['open_group_id']);
  285. if ($res == false) return $this->error(GroupBuyOrder::getStaticError());
  286. }elseif ($active->virtual_group_type == 3) {
  287. $res = ActiveFinish::handle($this->mall_id, $get['open_group_id'], $active);
  288. if ($res == false) return $this->error('结束失败');
  289. }else{
  290. //成功
  291. $list = GroupBuyOrder::findAll(['mall_id' => $this->mall_id, 'open_group_id' => $get['open_group_id'], 'order_status' => GroupBuyEnum::JOINING]);
  292. $res = GroupBuyOrder::addMainOrder($group_order,$list,$active,$counts);
  293. if ($res == false) return $this->error(GroupBuyOrder::getStaticError());
  294. }
  295. }else{
  296. $res = GroupBuyOrder::finishGroupBuyOrder($this->mall_id, $get['open_group_id']);
  297. if ($res == false) return $this->error(GroupBuyOrder::getStaticError());
  298. }
  299. return $this->success('操作成功', []);
  300. }
  301. }
  302. }
  303. /**
  304. * @desc:拼团订单
  305. * @Author: hua
  306. * @Date: 2021/12/17
  307. * @Time: 16:35
  308. * @Copyright: copyright (c) 2021 广东七件事集团
  309. * @return mixed|string|void
  310. */
  311. public function actionOrderList()
  312. {
  313. if (\Yii::$app->request->isAjax) {
  314. if (\Yii::$app->request->isGet) {
  315. $get = \Yii::$app->request->get();
  316. $where[] = ['mall_id' => $this->mall_id];
  317. $where[] = ['status' => StatusEnum::ENABLED];
  318. if (!empty($get['mobile'])) {
  319. $user_list = User::lists(['where' => [['mall_id' => $this->mall_id], ['like', 'mobile', trim($get['mobile']) . '%', false], ['status' => StatusEnum::ENABLED]], 'select' => 'id']);
  320. $user_id_arr = array_column($user_list, 'id');
  321. $where[] = ['user_id' => $user_id_arr];
  322. }
  323. if (!empty($get['nickname'])) {
  324. $user_list = User::lists(['where' => [['mall_id' => $this->mall_id], ['like', 'nickname', trim($get['nickname']) . '%', false], ['status' => StatusEnum::ENABLED]], 'select' => 'id']);
  325. $user_id_arr = array_column($user_list, 'id');
  326. $where[] = ['user_id' => $user_id_arr];
  327. }
  328. if (!empty($get['order_no'])) {
  329. $where[] = ['order_no' => $get['order_no']];
  330. }
  331. if (isset($get['order_status']) && $get['order_status'] != -1) $where[] = ['order_status' => $get['order_status']];
  332. $params['limit'] = 10;
  333. $params['where'] = $where;
  334. $params['order'] = 'id DESC';
  335. $params['with'] = ['user', 'groupBuyActive'];
  336. $pageData = GroupBuyOrder::listPage($params, false);
  337. if ($pageData === false) return $this->error(GroupBuyOrder::getStaticError());
  338. $pageData['order_status_map'] = GroupBuyEnum::getOrderStatusMap();
  339. return $this->success('操作成功', $pageData);
  340. }
  341. }
  342. return $this->render('order-list', []);
  343. }
  344. /**
  345. * @desc:查询退款状态
  346. * @Author: hua
  347. * @Date: 2021/12/20
  348. * @Time: 15:38
  349. * @Copyright: copyright (c) 2021 广东七件事集团
  350. * @return mixed|void
  351. * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
  352. */
  353. public function actionQueryRefund()
  354. {
  355. if (\Yii::$app->request->isAjax) {
  356. if (\Yii::$app->request->isGet) {
  357. $get = \Yii::$app->request->get();
  358. $group_buy_order = GroupBuyOrder::findOne(['id' => $get['id'], 'mall_id' => $this->mall_id]);
  359. if ($group_buy_order == false) return $this->error(GroupBuyOrder::getStaticError());
  360. switch ($group_buy_order->payment_type) {
  361. case PayTypeEnum::BALANCE:
  362. return $this->success('已退款');
  363. case PayTypeEnum::WECHAT:
  364. $payment_order = PaymentTradeOrder::findOne(['order_no' => $group_buy_order->order_no]);
  365. $payment_trade = PaymentTrade::findOne(['id' => $payment_order->trade_id]);
  366. $out_trade_no = $payment_trade['out_trade_no'];
  367. $config = Yii::$app->services->pay->getWechatConfig($this->mall_id);
  368. $wechatConfig = [
  369. 'app_id' => $config['app_id'],
  370. 'mch_id' => $config['wechat_mch_id'],
  371. 'key' => $config['wechat_pay_secret'], // API 密钥
  372. 'cert_path' => dirname(Yii::$app->basePath) . '/' . $config['wechat_cert_pem_file'],
  373. 'key_path' => dirname(Yii::$app->basePath) . '/' . $config['wechat_key_pem_file'],
  374. 'notify_url' => ''//回调地址
  375. ];
  376. $res = Factory::payment($wechatConfig)->refund->queryByOutTradeNumber($out_trade_no);
  377. if ($res['result_code'] != 'SUCCESS') return $this->error($res['err_code_des']);
  378. return $this->success('操作成功', $res['return_msg']);
  379. default:
  380. return $this->error('暂时不支持该支付方式查询');
  381. }
  382. }
  383. }
  384. }
  385. /**
  386. * @desc: 活动装修
  387. * @Author: hua
  388. * @Date: 2021/12/20
  389. * @Time: 15:56
  390. * @Copyright: copyright (c) 2021 广东七件事集团
  391. * @return mixed|void
  392. */
  393. public function actionDiyIndex()
  394. {
  395. if (\Yii::$app->request->isAjax) {
  396. if (\Yii::$app->request->isPost) {
  397. $params = \Yii::$app->request->post();
  398. $res = \Yii::$app->services->validate->validate($params, [
  399. [['content'], 'required'],
  400. ]);
  401. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  402. $params['mall_id'] = $this->mall_id;
  403. $params['addons_name'] = GroupBuyEnum::ADDONS_NAME;
  404. $res = AddonsMarketingSetting::setData($params);
  405. if ($res == false) return $this->error(AddonsMarketingSetting::getStaticError());
  406. return $this->success('操作成功', []);
  407. }
  408. if (\Yii::$app->request->isGet) {
  409. $params['mall_id'] = $this->mall_id;
  410. $params['addons_name'] = GroupBuyEnum::ADDONS_NAME;
  411. $params['status'] = StatusEnum::ENABLED;
  412. $res = AddonsMarketingSetting::findOne($params);
  413. if ($res == false) return $this->success('操作成功', []);
  414. $data = $res->toArray();
  415. $content = json_decode($data['content'], true);
  416. if (!empty($content)) {
  417. $active_data = array_pop($content);
  418. $active_ids = [];
  419. if (!empty($active_data['data']['goods'])) {
  420. foreach ($active_data['data']['goods'] as $item) {
  421. $active_ids[] = $item['params']['id'];
  422. }
  423. $list = GroupBuyActive::lists(['where' => [
  424. ['id' => $active_ids],
  425. ['status' => StatusEnum::ENABLED],
  426. ['group_status' => [GroupBuyEnum::NOT_STARTED, GroupBuyEnum::OPEN_GROUP]],
  427. ['mall_id' => $this->mall_id]], 'select' => 'id']
  428. );
  429. $active_id_arr = array_column($list, 'id');//没有被删除的活动id
  430. $goods_data = [];
  431. foreach ($active_data['data']['goods'] as $item) {
  432. if (in_array($item['params']['id'], $active_id_arr)) $goods_data[] = $item;
  433. }
  434. $active_data['data']['goods'] = $goods_data;
  435. $content[] = $active_data;
  436. $data['content'] = json_encode($content);
  437. }
  438. }
  439. return $this->success('操作成功', $data);
  440. }
  441. }
  442. return $this->render('diy-index');
  443. }
  444. /**
  445. * @desc:拼团分类列表
  446. * @Author: hua
  447. * @Date: 2021/12/13
  448. * @Time: 18:49
  449. * @Copyright: copyright (c) 2021 广东七件事集团
  450. * @return mixed|string|void
  451. */
  452. public function actionCateIndex()
  453. {
  454. if (\Yii::$app->request->isAjax) {
  455. if (\Yii::$app->request->isGet) {
  456. $where[] = ['mall_id' => $this->mall_id];
  457. $where[] = ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]];
  458. $params['limit'] = 10;
  459. $params['where'] = $where;
  460. $params['order'] = 'id DESC';
  461. $pageData = GroupBuyCate::listPage($params, false);
  462. if ($pageData === false) return $this->error(GroupBuyCate::getStaticError());
  463. return $this->success('操作成功', $pageData);
  464. }
  465. }
  466. return $this->render('cate-index', []);
  467. }
  468. /**
  469. * @desc:编辑拼团分类
  470. * @Author: hua
  471. * @Date: 2021/12/13
  472. * @Time: 18:49
  473. * @Copyright: copyright (c) 2021 广东七件事集团
  474. * @return mixed|string|void
  475. */
  476. public function actionCateEdit()
  477. {
  478. if (\Yii::$app->request->isAjax) {
  479. if (\Yii::$app->request->isGet) {
  480. $params = Yii::$app->request->get();
  481. $params['mall_id'] = $this->mall_id;
  482. $data = GroupBuyCate::findOne(['id' => $params['id'], 'mall_id' => $params['mall_id'], 'status' => [StatusEnum::DISABLED, StatusEnum::ENABLED]]);
  483. return $this->success('操作成功', $data);
  484. }
  485. if (\Yii::$app->request->isPost) {
  486. $params = Yii::$app->request->post();
  487. $params['mall_id'] = $this->mall_id;
  488. if (isset($params['status']) && in_array($params['status'], [StatusEnum::DISABLED, StatusEnum::DELETE])) {
  489. $res = GroupBuyActive::findOne([
  490. 'mall_id' => $this->mall_id,
  491. 'cate_id' => $params['id'],
  492. 'group_status' => [GroupBuyEnum::NOT_STARTED, GroupBuyEnum::OPEN_GROUP],
  493. 'status'=>[StatusEnum::ENABLED,StatusEnum::DISABLED]
  494. ]);
  495. if ($res) return $this->error('该拼团分类已关联拼团活动');
  496. }
  497. $res = GroupBuyCate::setData($params);
  498. if ($res === false) return $this->error(GroupBuyCate::getStaticError());
  499. return $this->success('操作成功', []);
  500. }
  501. }
  502. }
  503. /**
  504. * @desc:获取会员等级列表,添加活动使用,不用验证权限
  505. * @Author: hua
  506. * @Date: 2021/12/13
  507. * @Time: 18:50
  508. * @Copyright: copyright (c) 2021 广东七件事集团
  509. * @return mixed|string|void
  510. */
  511. public function actionUserLevelList()
  512. {
  513. $request = Yii::$app->request;
  514. if ($request->isAjax) {
  515. // 查询参数
  516. $where[] = ['in', 'status', [StatusEnum::ENABLED]];
  517. $where[] = ['=', 'mall_id', $this->mall['id']];
  518. $params = array('where' => $where, 'select' => 'id,level,name', 'order' => 'level asc', 'limit' => $request->get('limit', 12));
  519. $page_data = UserLevel::listPage($params, false);
  520. $page_data['list'] = array_merge([['id' => 0, 'level' => 0, 'name' => '普通用户']], $page_data['list']);
  521. return $this->success('操作成功', $page_data);
  522. }
  523. return $this->render($this->action->id);
  524. }
  525. /**
  526. * @desc:获取商品列表,添加活动使用,不用验证权限
  527. * @Author: hua
  528. * @Date: 2021/12/13
  529. * @Time: 18:51
  530. * @Copyright: copyright (c) 2021 广东七件事集团
  531. * @return mixed|string|void
  532. */
  533. public function actionGoodsList()
  534. {
  535. $request = Yii::$app->request;
  536. if ($request->isAjax) {
  537. //商品列表筛选
  538. $get = Yii::$app->request->get();
  539. $where = [['mall_id' => $this->mall['id'], 'status' => [StatusEnum::ENABLED]], ['is_on_sale' => 1]];
  540. isset($get['keyword']) && $where[] = ['or', ['like', 'goods_name', $get['keyword']], ['=', 'id', $get['keyword']]];
  541. if(!empty($get['price'])){
  542. $where[]=['price'=>trim($get['price'])];
  543. }
  544. if (!empty($get['goods_source'])) {
  545. if ($get['goods_source'] === 'Main') {
  546. $where[] = ['=', 'mch_id', 0];
  547. $where[] = ['=', 'goods_source', ''];
  548. } elseif ($get['goods_source'] === 'Mch') {
  549. $where[] = ['>', 'mch_id', 0];
  550. } else {
  551. $where[] = ['=', 'goods_source', $get['goods_source']];
  552. }
  553. }
  554. // 排序
  555. // $group_buy_active_list = GroupBuyActive::findAll(['mall_id' => $this->mall_id, 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  556. $group_buy_active_list = GroupBuyActive::find()->where(['mall_id'=>$this->mall_id,'status'=>StatusEnum::ENABLED])->andWhere(['>','end_at',time()])->all();
  557. $goods_id_arr = array_column($group_buy_active_list, 'goods_id');
  558. if($goods_id_arr) $where[] = ['not in', 'id', $goods_id_arr];
  559. $sort = 'sort ASC,id DESC';
  560. $params = ['where' => $where, 'limit' => 20, 'order' => $sort];
  561. $page_data = Goods::listPage($params, false, true);
  562. if ($page_data === false) return $this->error(Goods::getStaticError());
  563. return $this->success('操作成功', $page_data);
  564. }
  565. return $this->render($this->action->id);
  566. }
  567. /**
  568. * @desc:获取商品详情,添加活动使用,不用验证权限
  569. * @Author: hua
  570. * @Date: 2021/12/13
  571. * @Time: 18:51
  572. * @Copyright: copyright (c) 2021 广东七件事集团
  573. * @return mixed|string|void
  574. */
  575. public function actionGoodsDetail()
  576. {
  577. $request = Yii::$app->request;
  578. if ($request->isAjax) {
  579. $get = Yii::$app->request->get();
  580. $res = Yii::$app->services->validate->validate($get, [[['id'], 'integer']]);
  581. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  582. $detail = isset($get['id']) ? Goods::getOne([['id' => $get['id'], 'mall_id' => $this->mall_id]], true, ['cats', 'attr', 'extra']) : [];
  583. $detail['attr_groups'] = json_decode($detail['attr_groups'], true) ?? [];
  584. $detail['attr_groups_format'] = json_decode($detail['attr_groups_format'], true) ?? [];
  585. $detail['attr'] = GoodsAttr::formatFormAttr($detail['attr'] ?? [], $detail['attr_groups_format']);
  586. return $this->success('操作成功', compact('detail'));
  587. }
  588. return $this->render($this->action->id);
  589. }
  590. /**
  591. * @desc:获取拼团分类列表,添加活动使用,不用验证权限
  592. * @Author: hua
  593. * @Date: 2021/12/13
  594. * @Time: 18:51
  595. * @Copyright: copyright (c) 2021 广东七件事集团
  596. * @return mixed|string|void
  597. */
  598. public function actionCateList()
  599. {
  600. $request = Yii::$app->request;
  601. if ($request->isAjax) {
  602. $list = GroupBuyCate::lists(['where' => [['mall_id' => $this->mall_id], ['status' => StatusEnum::ENABLED]], 'order' => 'id asc', 'select' => 'id,name']);
  603. return $this->success('操作成功', compact('list'));
  604. }
  605. }
  606. /**
  607. * @desc:拼团商品列表
  608. * @Author: hua
  609. * @Date: 2021/12/14
  610. * @Time: 15:52
  611. * @Copyright: copyright (c) 2021 广东七件事集团
  612. * @return mixed|void
  613. */
  614. public function actionCheckActiveList()
  615. {
  616. $get = \Yii::$app->request->get();
  617. $where[] = ['mall_id' => $this->mall_id];
  618. $where[] = ['status' => StatusEnum::ENABLED];
  619. if (isset($get['active_id'])) $where[] = ['id' => json_decode($get['active_id'], true)];
  620. $list = GroupBuyActive::getActiveList($where, false);
  621. return $this->success('操作成功', $list);
  622. }
  623. }