CouponController.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. <?php
  2. namespace addons\Coupon\backend\controllers;
  3. use addons\Coupon\common\models\AddonsCoupon;
  4. use addons\Coupon\common\models\AddonsCouponCatRelate;
  5. use addons\Coupon\common\models\AddonsCouponGoodsRelate;
  6. use addons\Coupon\common\models\AddonsCouponMemberRelate;
  7. use addons\Coupon\common\models\AddonsCouponStatistics;
  8. use addons\Coupon\common\models\AddonsCouponGoodStatistics;
  9. use addons\Coupon\common\models\AddonsCouponReward;
  10. use addons\Coupon\common\models\CouponGiveItemSetting;
  11. use addons\Coupon\common\models\AddonsCouponMiniCode;
  12. use addons\Mch\common\models\Mch;
  13. use addons\Store\common\models\Store;
  14. use addons\Store\common\models\StoreGoods;
  15. use common\enums\AddonsEnum;
  16. use common\enums\StatusEnum;
  17. use common\helpers\ArrayHelper;
  18. use common\models\common\PosterCode;
  19. use common\models\goods\Goods;
  20. use common\models\goods\GoodsCate;
  21. use common\models\mall\Mall;
  22. use common\models\mall\MallAddons;
  23. use common\models\user\User;
  24. use common\models\user\UserLevel;
  25. use PHPUnit\Util\Exception;
  26. use Yii;
  27. use function Clue\StreamFilter\fun;
  28. use function Swoole\Coroutine\Http\get;
  29. use common\helpers\MiniQrCode;
  30. /**
  31. * 默认控制器
  32. *
  33. * Class DefaultController
  34. * @package addons\Coupon\backend\controllers
  35. */
  36. class CouponController extends BaseController
  37. {
  38. public $enableCsrfValidation = false;
  39. /**
  40. * @name:
  41. * @msg: 优惠券详细信息
  42. * @param {*}
  43. * @return {*}
  44. */
  45. public function actionCouponInfo()
  46. {
  47. if (!\Yii::$app->request->isGet) {
  48. return $this->error('请求方式错误');
  49. }
  50. $coupon_id = \Yii::$app->request->get('coupon_id');
  51. $is_copy = \Yii::$app->request->get('is_copy') ?? false;
  52. $store = [];
  53. if (empty($coupon_id)) {
  54. $coupon_info = [];
  55. $checked_categorys = $giving_rewards = $consume_rewards = $goods_id_list = $good_lists = $store_goods_lists = $member_level_limits = [];
  56. } else {
  57. $coupon_info = AddonsCoupon::find()
  58. ->select('id,mall_id,mch_id,store_id,name,type,discount,discount_limit,min_price,sub_price,total_count,sort,expire_type,expire_day,begin_at,end_at,appoint_type,rule,is_remind,remind_days,effect_days,is_receive_limit,receive_count,is_member,is_original_use,is_public_receive,is_giving,giving_expire,coupon_status,is_giving_reward,is_consume_reward,created_at,qrcode_url,poster_url,is_open_screen,give_time,is_superposition_use,is_not_allow_balance_pay,is_giving_use,day_limit')
  59. ->where(['mall_id' => $this->mall_id, 'id' => $coupon_id, 'status' => 1, 'coupon_status' => [1, 2, 3, 4]])
  60. ->one();
  61. // dd($coupon_info);
  62. if (empty($coupon_info)) {
  63. return $this->error('优惠券不存在或已失效');
  64. }
  65. if (($coupon_info->coupon_status != 1 || $coupon_info->coupon_status != 2) && $is_copy) {
  66. return $this->error('该优惠券不能复制');
  67. }
  68. if ($is_copy) {
  69. $coupon_info->id = 0;
  70. }
  71. $member_level_limits = AddonsCouponMemberRelate::find()
  72. ->select('member_level')
  73. ->where(['mall_id' => $this->mall_id, 'coupon_id' => $coupon_id])
  74. ->asArray()
  75. ->all();
  76. $member_level_limits = array_values(array_flip(array_flip(array_column($member_level_limits, 'member_level'))));
  77. $good_lists = $coupon_info->goods;
  78. $store_goods_lists = [];
  79. if (MallAddons::isInstall($this->mall_id, 'Store')) {
  80. $store_goods_lists = $coupon_info->storeGoods;
  81. }
  82. $coupon_rewards = AddonsCouponReward::find()
  83. ->select('reward_type,balance,score,red_packet')
  84. ->where(['mall_id' => $this->mall_id, 'coupon_id' => $coupon_id])
  85. ->asArray()
  86. ->all();
  87. if (!empty($coupon_rewards)) {
  88. foreach ($coupon_rewards as $rk => $rv) {
  89. if (1 == $rv['reward_type']) {
  90. $giving_rewards = [
  91. 'balance' => $rv['balance'],
  92. 'score' => $rv['score'],
  93. 'red_packet' => $rv['red_packet'],
  94. ];
  95. } elseif (2 == $rv['reward_type']) {
  96. $consume_rewards = [
  97. 'balance' => $rv['balance'],
  98. 'score' => $rv['score'],
  99. 'red_packet' => $rv['red_packet'],
  100. ];
  101. }
  102. }
  103. if (empty($giving_rewards)) {
  104. $giving_rewards = [];
  105. }
  106. if (empty($consume_rewards)) {
  107. $consume_rewards = [];
  108. }
  109. } else {
  110. $giving_rewards = $consume_rewards = [];
  111. }
  112. // 优惠券已经绑定的商品分类
  113. $checked_categorys = $coupon_info->cateRelate;
  114. // dd($checked_categorys);
  115. if (!empty($checked_categorys)) {
  116. $cate_ids = array_column($checked_categorys, 'cate_id');
  117. // dd($cate_ids);
  118. foreach ($cate_ids as $cate_id) {
  119. $cateids[] = [$cate_id];
  120. }
  121. $checked_categorys = $cateids;
  122. } else {
  123. $checked_categorys = [];
  124. }
  125. // 门店
  126. if ($coupon_info['appoint_type'] == 4) {
  127. $store = ArrayHelper::toArray($coupon_info->store);
  128. }
  129. }
  130. $member_levels = $member_levels = UserLevel::find()
  131. ->select('id,level,name')
  132. ->where(['mall_id' => $this->mall_id, 'status' => 1])
  133. ->asArray()
  134. ->all();
  135. $conditions = [['is_show' => 1, 'status' => StatusEnum::ENABLED, 'mall_id' => $this->mall_id, 'mch_id' => $this->admin->mch_id]];
  136. $good_categorys = GoodsCate::getCates($conditions, [], true, 'id,name,pic,parent_id');
  137. $good_categorys = GoodsCate::getTreeCate($good_categorys);
  138. $coupon_info = ArrayHelper::toArray($coupon_info);
  139. if (!empty($good_lists)) {
  140. $good_lists = ArrayHelper::toArray($good_lists);
  141. foreach ($good_lists as &$gv) {
  142. $gv['goods_id'] = $gv['id'];
  143. }
  144. $goods_id_list = array_column($good_lists, 'id');
  145. }
  146. $store_goods_id_list = [];
  147. if (!empty($store_goods_lists)) {
  148. $store_goods_lists = ArrayHelper::toArray($store_goods_lists);
  149. foreach ($store_goods_lists as &$gv) {
  150. $gv['goods_id'] = $gv['id'];
  151. }
  152. $store_goods_id_list = array_column($store_goods_lists, 'id');
  153. }
  154. if (!isset($coupon_info['is_open_screen'])) $coupon_info['is_open_screen'] = 0;
  155. $store_list = [];
  156. $mch_list = [];
  157. $addons_store = false;
  158. $addons_mch = false;
  159. if (MallAddons::isInstall($this->mall_id, 'Store')) {
  160. if (!empty($coupon_info['store_id'])) {
  161. // $where = [
  162. // ['mall_id'=>$this->mall_id],
  163. // ['status'=>1],
  164. // ['shop_status'=>1],
  165. // ['check_status'=>1],
  166. // ];
  167. $store_ids = explode(',', $coupon_info['store_id']);
  168. $coupon_info['store_id'] = $store_ids;
  169. $where[] = ['id' => $store_ids];
  170. $store_list = Store::lists([
  171. 'where' => $where,
  172. 'select' => 'id,logo_img,store_name'
  173. ]);
  174. }
  175. $addons_store = true;
  176. }
  177. if (MallAddons::isInstall($this->mall_id, 'Mch')) {
  178. if (!empty($coupon_info['mch_id'])) {
  179. // $where = [
  180. // ['mall_id'=>$this->mall_id],
  181. // ['status'=>1],
  182. // ['shop_status'=>1],
  183. // ['check_status'=>1],
  184. // ];
  185. $mch_ids = explode(',', $coupon_info['mch_id']);
  186. $coupon_info['mch_id'] = $mch_ids;
  187. $where[] = ['id' => $mch_ids];
  188. $mch_list = Mch::lists([
  189. 'where' => $where,
  190. 'select' => 'id,logo_img,store_name'
  191. ]);
  192. }
  193. $addons_mch = true;
  194. }
  195. return $this->success('操作成功', compact('coupon_info', 'member_levels', 'store_list', 'mch_list', 'good_categorys', 'member_level_limits', 'good_lists', 'goods_id_list', 'giving_rewards', 'consume_rewards', 'checked_categorys', 'store', 'addons_store', 'addons_mch', 'store_goods_lists', 'store_goods_id_list'));
  196. }
  197. /**
  198. * @name:
  199. * @msg: 优惠券统计数据
  200. * @param {*}
  201. * @return {*}
  202. */
  203. public function actionCouponStatistics()
  204. {
  205. if (!\Yii::$app->request->isGet) {
  206. return $this->error('请求方式错误');
  207. }
  208. $coupon_id = \Yii::$app->request->get('coupon_id');
  209. $page = \Yii::$app->request->get('page') ?? 1;
  210. $limit = \Yii::$app->request->get('page_size') ?? $this->pageSize;
  211. if (empty($coupon_id)) {
  212. return $this->error('参数错误');
  213. }
  214. $user_coupons = AddonsCouponStatistics::find()
  215. ->select('total_payed_amount,total_discount_amount,use_probability,receive_user_number,use_order_number,total_use_coupon_payed_amount,use_user_number')
  216. ->where(['mall_id' => $this->mall_id, 'coupon_id' => $coupon_id])
  217. ->asArray()
  218. ->one();
  219. if (!empty($user_coupons)) {
  220. foreach ($user_coupons as $uk => $uv) {
  221. $user_coupons[$uk] = floatval($uv);
  222. }
  223. $user_coupons['use_probability'] = $user_coupons['use_probability'] * 100 . '%';
  224. } else {
  225. $user_coupons = null;
  226. }
  227. $coupon_info = AddonsCoupon::find()
  228. ->where(['mall_id' => $this->mall_id, 'id' => $coupon_id])
  229. ->asArray()
  230. ->one();
  231. $coupon_info = array_merge($coupon_info, AddonsCoupon::parseCouponInfo($coupon_info));
  232. $where[] = ['mall_id' => $this->mall_id, 'coupon_id' => $coupon_id];
  233. $params = [
  234. 'select' => 'coupon_id,good_id,payed_number,buyed_user_number',
  235. 'where' => $where,
  236. 'limit' => $limit,
  237. 'page' => $page,
  238. ];
  239. $good_stat = AddonsCouponGoodStatistics::listPage($params);
  240. $good_statistics = [];
  241. if (!empty($good_stat['list'])) {
  242. $good_ids = array_column($good_stat['list'], 'good_id');
  243. if (empty($coupon_info['store_id'])) {
  244. $goods = Goods::find()
  245. ->select('id,goods_name,cover_pic')
  246. ->where(['id' => $good_ids])
  247. ->asArray()
  248. ->indexBy('id')
  249. ->all();
  250. } else {
  251. if (MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_STORE)) {
  252. $goods = StoreGoods::find()
  253. ->select('id,goods_name,cover_pic')
  254. ->where(['id' => $good_ids])
  255. ->asArray()
  256. ->indexBy('id')
  257. ->all();
  258. }
  259. }
  260. foreach ($good_stat['list'] as $lk => $lv) {
  261. $good_statistics[$lk] = $lv;
  262. $good_statistics[$lk]['goods_name'] = $goods[$lv['good_id']]['goods_name'] ?? '';
  263. $good_statistics[$lk]['cover_pic'] = $goods[$lv['good_id']]['cover_pic'] ?? '';
  264. }
  265. }
  266. return $this->success('操作成功', compact('user_coupons', 'good_statistics', 'coupon_info'));
  267. }
  268. /**
  269. * @name:
  270. * @msg: 优惠券置失效
  271. * @param {*}
  272. * @return {*}
  273. * @throws \Exception
  274. */
  275. public function actionFailure()
  276. {
  277. if (!\Yii::$app->request->isGet) {
  278. return $this->error('请求方式错误');
  279. }
  280. $coupon_id = \Yii::$app->request->get('coupon_id');
  281. if (empty($coupon_id)) {
  282. return $this->error('参数错误');
  283. }
  284. $model = AddonsCoupon::findOne(['and', ['mall_id' => $this->mall_id, 'id' => $coupon_id, 'status' => 1], ['!=', 'coupon_status', 4]]);
  285. if (empty($model)) {
  286. return $this->error('优惠券不能置失效');
  287. }
  288. $transaction = \Yii::$app->db->beginTransaction();
  289. $model->coupon_status = 4;
  290. $model->updated_at = time();
  291. $c_res = $model->save();
  292. // $uc_res = UserCoupon::updateAll(['status' => 4, 'updated_at' => time()], ['mall_id' => $this->mall_id, 'id' => $coupon_id]);
  293. $uc_res = true;
  294. if ($c_res !== false && $uc_res !== false) {
  295. $transaction->commit();
  296. return $this->success('操作成功');
  297. } else {
  298. $transaction->rollBack();
  299. return $this->error('操作失败:' . $model->getErrorMessage());
  300. }
  301. }
  302. /**
  303. * 删除
  304. * @return \yii\web\Response
  305. */
  306. public function actionDelete()
  307. {
  308. if (!\Yii::$app->request->isPost) {
  309. return $this->error('请求方式错误');
  310. }
  311. $coupon_id = \Yii::$app->request->post('coupon_id');
  312. if (empty($coupon_id)) {
  313. return $this->error('参数错误');
  314. }
  315. $res = AddonsCoupon::deleteCoupon($coupon_id, $this->mall_id);
  316. if (!$res) {
  317. return $this->error(AddonsCoupon::getStaticError());
  318. }
  319. return $this->success('删除成功');
  320. }
  321. /**
  322. * 指定商品可用时搜索商品
  323. * @return mixed|void
  324. */
  325. public function actionSearchGoods()
  326. {
  327. if (!\Yii::$app->request->isGet) {
  328. return $this->error('请求方式错误');
  329. }
  330. $page = \Yii::$app->request->get('page', 1);
  331. $limit = \Yii::$app->request->get('limit', $this->pageSize);
  332. $keyword = \Yii::$app->request->get('keyword');
  333. $where[] = [
  334. 'mall_id' => $this->mall_id,
  335. 'mch_id' => $this->admin->mch_id,
  336. 'status' => StatusEnum::ENABLED,
  337. 'is_on_sale' => 1,
  338. ];
  339. if (!empty($keyword)) {
  340. $where[] = ['like', 'goods_name', $keyword];
  341. }
  342. $params = [
  343. 'select' => 'id as goods_id,goods_name,cover_pic,sort,cost_price,stock,price',
  344. 'where' => $where,
  345. 'order' => 'sort asc,id desc',
  346. 'page' => $page,
  347. 'limit' => $limit,
  348. ];
  349. $list = Goods::listPage($params);
  350. return $this->success('操作成功', $list);
  351. }
  352. /**
  353. * 指定门店商品可用时搜索门店商品
  354. * @return mixed|void
  355. */
  356. public function actionSearchStoreGoods()
  357. {
  358. if (!\Yii::$app->request->isGet) {
  359. return $this->error('请求方式错误');
  360. }
  361. $is_install = MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_STORE);
  362. if (empty($is_install)) {
  363. return $this->success('操作成功', []);
  364. }
  365. $page = \Yii::$app->request->get('page', 1);
  366. $limit = \Yii::$app->request->get('limit', $this->pageSize);
  367. $storeKeyword = \Yii::$app->request->get('store_keyword', '');
  368. $keyword = \Yii::$app->request->get('keyword', '');
  369. $where[] = [
  370. 'mall_id' => $this->mall_id,
  371. 'status' => StatusEnum::ENABLED,
  372. 'is_on_sale' => 1,
  373. ];
  374. if ($keyword !== '') {
  375. if (is_numeric($keyword)) {
  376. $where[] = [
  377. 'or',
  378. ['like', 'goods_name', $keyword],
  379. ['=', 'id', $keyword]
  380. ];
  381. } else {
  382. $where[] = ['like', 'goods_name', $keyword];
  383. }
  384. }
  385. if ($storeKeyword !== '') {
  386. $storeFind = Store::find();
  387. Store::paramPack([
  388. 'where' => [
  389. [
  390. 'mall_id' => $this->mall_id,
  391. 'status' => StatusEnum::ENABLED
  392. ],
  393. ['like', 'store_name', $storeKeyword]
  394. ],
  395. 'select' => 'id'
  396. ], $storeFind);
  397. $storeIds = $storeFind->column();
  398. if (is_numeric($storeKeyword)) {
  399. $storeIds[] = $storeKeyword;
  400. }
  401. $where[] = ['in', 'store_id', $storeIds];
  402. }
  403. $params = [
  404. 'select' => 'id as goods_id,goods_name,cover_pic,sort,cost_price,stock,store_id,price,store_id',
  405. 'where' => $where,
  406. 'order' => 'sort asc,id desc',
  407. 'page' => $page,
  408. 'limit' => $limit,
  409. 'with' => [
  410. 'store' => function ($query) {
  411. $query->select('id, store_name, shop_mobile, logo_img');
  412. }
  413. ]
  414. ];
  415. $list = StoreGoods::listPage($params);
  416. return $this->success('操作成功', $list);
  417. }
  418. /**
  419. * 选择优惠券
  420. * @Author: lun
  421. * @DateTime: 2021/12/17 0017 10:16
  422. * @Copyright: copyright (c) 2021 广东七件事集团
  423. * @return mixed|string|void
  424. */
  425. public function actionSelectCoupon()
  426. {
  427. if (Yii::$app->request->isAjax && Yii::$app->request->isPost) {
  428. $params = Yii::$app->request->post();
  429. $params['where'][] = ['mall_id' => $this->mall_id];
  430. $params['where'][] = ['status' => [StatusEnum::ENABLED]];
  431. $params['where'][] = [
  432. 'or',
  433. ['=', 'total_count', -1],
  434. ['>', 'total_count', 'receive'],
  435. ];
  436. if (!empty($params['keyword'])) $params['where'][] = ['like', 'name', $params['keyword']];
  437. $params['order'] = 'sort asc,id desc';
  438. $params['select'] = 'id,name,type,discount,min_price,sub_price,expire_type,expire_day,begin_at,end_at,status';
  439. $list = AddonsCoupon::listPage($params);
  440. //判断是否过期
  441. foreach ($list['list'] as $k => $v) {
  442. $v['end_at'] < time() && $v['expire_type'] == 2 ? $list['list'][$k]['is_failure'] = 1 : $list['list'][$k]['is_failure'] = 0;
  443. }
  444. return $this->success('操作成功', $list);
  445. }
  446. }
  447. /**
  448. * 获取商品独立设置的优惠券设置
  449. * @Author: lun
  450. * @DateTime: 2022/3/9 0009 15:53
  451. * @Copyright: copyright (c) 2021 广东七件事集团
  452. * @return mixed|void
  453. */
  454. public function actionGetSettingCoupon()
  455. {
  456. $params = Yii::$app->request->post();
  457. $data = [];
  458. // 获取配置
  459. $result = CouponGiveItemSetting::getOne([['=', 'mall_id', $this->mall_id], ['=', 'item_id', $params['goods_id']]], true, [
  460. 'detail' => function ($query) {
  461. $query->where(['status' => StatusEnum::ENABLED])->with(['coupon']);
  462. }]);
  463. if (empty($result['detail'])) return $this->success('操作成功', $data);
  464. // 重新组合数组
  465. $data['is_enable'] = $result['is_enable'];
  466. $data['send_type'] = $result['send_type'];
  467. foreach ($result['detail'] as $item) {
  468. $data['coupon'][] = [
  469. 'discount_method' => $item['coupon']['type'] == 1 ? $item['coupon']['discount'] . '折' : $item['coupon']['sub_price'] . '元',
  470. 'name' => $item['coupon']['name'],
  471. 'num' => $item['num'],
  472. 'relevant_id' => $item['coupon_id'],
  473. ];
  474. }
  475. return $this->success('操作成功', $data);
  476. }
  477. /**
  478. * 指定 o2o 门店可用时搜索 o2o 门店
  479. * @return mixed|void
  480. */
  481. public function actionSearchStores()
  482. {
  483. if (!\Yii::$app->request->isGet) {
  484. return $this->error('请求方式错误');
  485. }
  486. $is_install = MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_STORE);
  487. if (empty($is_install)) {
  488. return $this->success('操作成功', []);
  489. }
  490. $page = \Yii::$app->request->get('page', 1);
  491. $limit = \Yii::$app->request->get('limit', $this->pageSize);
  492. $keyword = \Yii::$app->request->get('keyword');
  493. $where[] = ['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED];
  494. if (!empty($keyword)) {
  495. $where[] = ['like', 'store_name', $keyword];
  496. }
  497. $params = [
  498. 'select' => 'id,store_name,logo_img,shop_owner,shop_mobile',
  499. 'where' => $where,
  500. 'order' => 'created_at asc,id desc',
  501. 'page' => $page,
  502. 'limit' => $limit,
  503. ];
  504. $list = Store::listPage($params);
  505. return $this->success('操作成功', $list);
  506. }
  507. public function actionShowMiniPromotionCode()
  508. {
  509. $request = \Yii::$app->request;
  510. if ($request->isAjax) {
  511. if ($request->isPost) {
  512. $params = \Yii::$app->request->post();
  513. // 检查提交的参数
  514. $res = \Yii::$app->services->validate->validate($params, [
  515. [['id','store_id'], 'required'],
  516. ]);
  517. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  518. $coupon_model = AddonsCoupon::findOne(['id' => $params['id'], 'mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED]);
  519. if (empty($coupon_model['applet_code'])) {
  520. $mall = $this->mall;
  521. $params['mall_id'] = $this->mall_id;
  522. $params['mall_sign'] = $mall['mall_sign'];
  523. $params['sign'] = $mall['mall_sign'];
  524. $params['coupon_id'] = $coupon_model['id'];
  525. $params['coupon_share_log_id'] = 0;
  526. $params['item_id'] = $coupon_model['id'];
  527. $params['store_id'] = $params['store_id'];
  528. // $params['user_id'] = 1;
  529. // $params['content'] = $content;
  530. $poster = PosterCode::setData($this->mall_id, 0, 0, $params);
  531. if ($poster == false) {
  532. return $this->error(AddonsCouponMiniCode::getStaticError());
  533. }
  534. $code = $poster['code'];
  535. $page = 'plugins/pages/coupon/type';
  536. $obj = new MiniQrCode();
  537. $applet_code = $obj->getAppletQrCode($this->mall_id, $page, $code);
  538. // $applet_code = 'https://shuzixiangdao.oss-cn-guangzhou.aliyuncs.com/download/qrcode/1c772ee1dc819fd3518fbdc29bab4cdc.jpg';
  539. $coupon_model->applet_code = $applet_code;
  540. $coupon_model->save();
  541. if ($coupon_model == false) {
  542. return $this->error(AddonsCoupon::getStaticError());
  543. }
  544. }
  545. $applet_url = $coupon_model['applet_code'];
  546. return $this->success('获取成功', ['applet_url' => $applet_url]);
  547. }
  548. }
  549. }
  550. }