Promotion.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
  9. * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
  10. * =========================================================
  11. */
  12. namespace addon\store\shopapi\controller;
  13. use addon\sitecoupon\model\Coupon as CouponModel;
  14. use app\model\promotion\Promotion as PromotionModel;
  15. use app\model\system\Promotion as SysPromotionModel;
  16. use app\model\member\MemberCoupon as MemberCouponModel;
  17. /**
  18. * 互动营销控制器
  19. * Class Promotion
  20. * @package addon\shop\siteapi\controller
  21. */
  22. class Promotion extends BaseStoreApi
  23. {
  24. /**
  25. * 互动营销 活动列表
  26. */
  27. public function lists()
  28. {
  29. $sys_promotion_model = new SysPromotionModel();
  30. $promotion_type_list = $sys_promotion_model->getPromotionType('member');
  31. $promotion_model = new PromotionModel();
  32. $condition = [ [ 'is_delete', '=', 0 ], [ 'site_id', '=', $this->site_id ] ];
  33. $page = isset($this->params[ 'page' ]) ? $this->params[ 'page' ] : '1';
  34. $page_size = isset($this->params[ 'page_size' ]) ? $this->params[ 'page_size' ] : PAGE_LIST_ROWS;
  35. $search_text = isset($this->params[ 'search_text' ]) ? $this->params[ 'search_text' ] : '';
  36. $start_time = isset($this->params[ 'start_time' ]) ? $this->params[ 'start_time' ] : '';
  37. $end_time = isset($this->params[ 'end_time' ]) ? $this->params[ 'end_time' ] : '';
  38. $state = isset($this->params[ 'state' ]) ? $this->params[ 'state' ] : '';
  39. $promotion_type = isset($this->params[ 'promotion_type' ]) ? $this->params[ 'promotion_type' ] : '';
  40. $order = isset($this->params[ 'order' ]) ? $this->params[ 'order' ] : '';
  41. $sort = isset($this->params[ 'sort' ]) ? $this->params[ 'sort' ] : '';
  42. $promotion_id = isset($this->params[ 'promotion_id' ]) ? $this->params[ 'promotion_id' ] : '';
  43. // 上架状态
  44. if ($state !== '') {
  45. $condition[] = [ 'state', '=', $state ];
  46. if ($state == 1) {
  47. $condition[] = [ 'end_time', '>', time() ];
  48. }
  49. }
  50. if (!empty($search_text)) {
  51. $condition[] = [ 'name', 'like', '%' . $search_text . '%' ];
  52. }
  53. if ($promotion_type !== "") {
  54. $condition[] = [ 'promotion_type', '=', $promotion_type ];
  55. }
  56. if ($promotion_id) {
  57. $condition[] = [ 'promotion_id', '=', $promotion_id ];
  58. }
  59. //时间
  60. if (!empty($start_time) && empty($end_time)) {
  61. $condition[] = [ "start_time", ">=", date_to_time($start_time) ];
  62. } elseif (empty($start_time) && !empty($end_time)) {
  63. $condition[] = [ "start_time", "<=", date_to_time($end_time) ];
  64. } elseif (!empty($start_time) && !empty($end_time)) {
  65. $condition[] = [ 'start_time', 'between', [ date_to_time($start_time), date_to_time($end_time) ] ];
  66. }
  67. if ($order == '') {
  68. $order_by = 'create_time desc';
  69. } else {
  70. $order_by = $order . ' ' . $sort;
  71. }
  72. $res = $promotion_model->getPromotionPageList($condition, $page, $page_size, $order_by);
  73. foreach ($res[ 'data' ][ 'list' ] as $k => $v) {
  74. $res[ 'data' ][ 'list' ][ $k ][ 'promotion_type_name' ] = $promotion_type_list[ $v[ 'promotion_type' ] ][ 'title' ];
  75. }
  76. return $this->response($res);
  77. }
  78. /**
  79. * 互动营销 活动详情
  80. */
  81. public function detail()
  82. {
  83. $promotion_id = isset($this->params[ 'promotion_id' ]) ? $this->params[ 'promotion_id' ] : '';
  84. $site_id = $this->site_id;
  85. $condition = [
  86. [ 'promotion_id', '=', $promotion_id ],
  87. [ 'site_id', '=', $site_id ]
  88. ];
  89. $promotion_model = new PromotionModel();
  90. $promotion_info = $promotion_model->getPromotionInfo($condition);
  91. if (empty($promotion_info[ 'data' ])) return $this->response($this->error('未获取到活动数据'));
  92. return $this->response($promotion_info);
  93. }
  94. /**
  95. * 互动营销 优惠券详情
  96. */
  97. public function couponList()
  98. {
  99. $promotion_id = isset($this->params[ 'promotion_id' ]) ? $this->params[ 'promotion_id' ] : '';
  100. //获取优惠券详情
  101. $coupon_model = new MemberCouponModel();
  102. $coupon_list = $coupon_model->getCouponList([ [ 'from_type_id', '=', $promotion_id ], [ 'from_type', '=', 'promotion' ], [ 'site_id', '=', $this->site_id ] ]);
  103. return $this->response($coupon_list);
  104. }
  105. /**
  106. * 删除活动
  107. */
  108. public function deletePromotion()
  109. {
  110. $promotion_ids = isset($this->params[ 'promotion_ids' ]) ? $this->params[ 'promotion_ids' ] : 0;
  111. $model = new PromotionModel();
  112. $res = $model->modifyIsDelete($promotion_ids, 1, $this->site_id);
  113. return $this->response($res);
  114. }
  115. /**
  116. * 修改活动
  117. */
  118. public function modifyPromotionState()
  119. {
  120. $promotion_ids = isset($this->params[ 'promotion_ids' ]) ? $this->params[ 'promotion_ids' ] : 0;
  121. $state = isset($this->params[ 'state' ]) ? $this->params[ 'state' ] : 1;
  122. $model = new PromotionModel();
  123. $res = $model->modifyPromotionState($promotion_ids, $state, $this->site_id);
  124. return $this->response($res);
  125. }
  126. /**
  127. * 添加活动
  128. */
  129. public function addPromotion()
  130. {
  131. $name = isset($this->params[ 'name' ]) ? $this->params[ 'name' ] : '';#活动名称
  132. $image = isset($this->params[ 'image' ]) ? $this->params[ 'image' ] : '';#活动主图
  133. $content = isset($this->params[ 'content' ]) ? $this->params[ 'content' ] : '';#活动富文本
  134. $stock = isset($this->params[ 'stock' ]) ? $this->params[ 'stock' ] : 0;#数量
  135. $start_time = isset($this->params[ 'start_time' ]) ? date_to_time($this->params[ 'start_time' ]) : '';#活动开始时间
  136. $end_time = isset($this->params[ 'end_time' ]) ? date_to_time($this->params[ 'end_time' ]) : '';#活动结束时间
  137. $share_title = isset($this->params[ 'share_title' ]) ? $this->params[ 'share_title' ] : '';#分享标题
  138. $share_desc = isset($this->params[ 'share_desc' ]) ? $this->params[ 'share_desc' ] : '';#分享描述
  139. $is_show_wechat = isset($this->params[ 'is_show_wechat' ]) ? $this->params[ 'is_show_wechat' ] : '';#是否显示关注公众号悬浮框 0否 1是
  140. $group_chat = isset($this->params[ 'group_chat' ]) ? $this->params[ 'group_chat' ] : '';#群聊二维码
  141. $group_name = isset($this->params[ 'group_name' ]) ? $this->params[ 'group_name' ] : '';#群聊名称
  142. $group_desc = isset($this->params[ 'group_desc' ]) ? $this->params[ 'group_desc' ] : '';#群聊介绍
  143. $coupon_data = isset($this->params[ 'coupon_data' ]) ? $this->params[ 'coupon_data' ] : '';
  144. $data = [
  145. 'site_id' => $this->site_id,
  146. 'name' => $name,
  147. 'image' => $image,
  148. 'content' => $content,
  149. 'stock' => $stock,
  150. 'start_time' => $start_time,
  151. 'end_time' => $end_time,
  152. 'share_title' => $share_title,
  153. 'share_desc' => $share_desc,
  154. 'is_show_wechat' => $is_show_wechat,
  155. 'group_chat' => $group_chat,
  156. 'group_name' => $group_name,
  157. 'group_desc' => $group_desc,
  158. 'coupon_data' => $coupon_data,
  159. ];
  160. $coupon_model = new CouponModel();
  161. $res = $coupon_model->addCoupon($data);
  162. return $this->response($res);
  163. }
  164. /**
  165. * 编辑活动
  166. */
  167. public function editPromotion()
  168. {
  169. $coupon_model = new CouponModel();
  170. $promotion_id = isset($this->params[ 'promotion_id' ]) ? $this->params[ 'promotion_id' ] : '';#商品Id
  171. $name = isset($this->params[ 'name' ]) ? $this->params[ 'name' ] : '';#活动名称
  172. $image = isset($this->params[ 'image' ]) ? $this->params[ 'image' ] : '';#活动主图
  173. $content = isset($this->params[ 'content' ]) ? $this->params[ 'content' ] : '';#活动富文本
  174. $stock = isset($this->params[ 'stock' ]) ? $this->params[ 'stock' ] : 0;#数量
  175. $start_time = isset($this->params[ 'start_time' ]) ? date_to_time($this->params[ 'start_time' ]) : '';#活动开始时间
  176. $end_time = isset($this->params[ 'end_time' ]) ? date_to_time($this->params[ 'end_time' ]) : '';#活动结束时间
  177. $share_title = isset($this->params[ 'share_title' ]) ? $this->params[ 'share_title' ] : '';#分享标题
  178. $share_desc = isset($this->params[ 'share_desc' ]) ? $this->params[ 'share_desc' ] : '';#分享描述
  179. $is_show_wechat = isset($this->params[ 'is_show_wechat' ]) ? $this->params[ 'is_show_wechat' ] : '';#是否显示关注公众号悬浮框 0否 1是
  180. $group_chat = isset($this->params[ 'group_chat' ]) ? $this->params[ 'group_chat' ] : '';#群聊二维码
  181. $group_name = isset($this->params[ 'group_name' ]) ? $this->params[ 'group_name' ] : '';#群聊名称
  182. $group_desc = isset($this->params[ 'group_desc' ]) ? $this->params[ 'group_desc' ] : '';#群聊介绍
  183. $coupon_data = isset($this->params[ 'coupon_data' ]) ? $this->params[ 'coupon_data' ] : '';
  184. $data = [
  185. 'promotion_id' => $promotion_id,
  186. 'site_id' => $this->site_id,
  187. 'name' => $name,
  188. 'image' => $image,
  189. 'content' => $content,
  190. 'stock' => $stock,
  191. 'start_time' => $start_time,
  192. 'end_time' => $end_time,
  193. 'share_title' => $share_title,
  194. 'share_desc' => $share_desc,
  195. 'is_show_wechat' => $is_show_wechat,
  196. 'group_chat' => $group_chat,
  197. 'group_name' => $group_name,
  198. 'group_desc' => $group_desc,
  199. 'coupon_data' => $coupon_data,
  200. ];
  201. $res = $coupon_model->editCoupon($data);
  202. return $this->response($res);
  203. }
  204. }