Manjian.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace addon\manjian\shop\controller;
  11. use addon\coupon\model\CouponType;
  12. use app\model\member\MemberLevel;
  13. use app\shop\controller\BaseShop;
  14. use addon\manjian\model\Manjian as ManjianModel;
  15. use think\facade\Cache;
  16. /**
  17. * 满减控制器
  18. */
  19. class Manjian extends BaseShop
  20. {
  21. protected $replace = []; //视图输出字符串内容替换 相当于配置文件中的'view_replace_str'
  22. public function __construct()
  23. {
  24. parent::__construct();
  25. $this->replace = [
  26. 'MANJIAN_IMG' => __ROOT__ . '/addon/manjian/shop/view/public/img',
  27. 'MANJIAN_JS' => __ROOT__ . '/addon/manjian/shop/view/public/js',
  28. 'MANJIAN_CSS' => __ROOT__ . '/addon/manjian/shop/view/public/css',
  29. ];
  30. }
  31. /**
  32. * 满减列表
  33. */
  34. public function lists()
  35. {
  36. if (request()->isAjax()) {
  37. $page = input('page', 1);
  38. $page_size = input('page_size', PAGE_LIST_ROWS);
  39. $manjian_name = input('manjian_name', '');
  40. $status = input('status', '');
  41. $condition = [];
  42. $condition[] = [ 'site_id', '=', $this->site_id ];
  43. $condition[] = [ 'manjian_name', 'like', '%' . $manjian_name . '%' ];
  44. if ($status != null) {
  45. $condition[] = [ 'status', '=', $status ];
  46. }
  47. $start_time = input('start_time', '');
  48. $end_time = input('end_time', '');
  49. if ($start_time && !$end_time) {
  50. $condition[] = [ 'end_time', '>=', date_to_time($start_time) ];
  51. } elseif (!$start_time && $end_time) {
  52. $condition[] = [ 'start_time', '<=', date_to_time($end_time) ];
  53. } elseif ($start_time && $end_time) {
  54. $start_timestamp = date_to_time($start_time);
  55. $end_timestamp = date_to_time($end_time);
  56. $sql = "start_time between {$start_timestamp} and {$end_timestamp}";
  57. $sql .= " or end_time between {$start_timestamp} and {$end_timestamp}";
  58. $sql .= " or (start_time <= {$start_timestamp} and end_time >= {$end_timestamp})";
  59. $condition[] = [ '', 'exp', \think\facade\Db::raw($sql) ];
  60. }
  61. $order = 'create_time desc';
  62. $field = 'manjian_id,manjian_name,start_time,end_time,create_time,status';
  63. $manjian_model = new ManjianModel();
  64. $res = $manjian_model->getManjianPageList($condition, $page, $page_size, $order, $field);
  65. //获取状态名称
  66. $manjian_status_arr = $manjian_model->getManjianStatus();
  67. foreach ($res[ 'data' ][ 'list' ] as $key => $val) {
  68. $res[ 'data' ][ 'list' ][ $key ][ 'status_name' ] = $manjian_status_arr[ $val[ 'status' ] ];
  69. }
  70. return $res;
  71. } else {
  72. //满减状态
  73. $manjian_model = new ManjianModel();
  74. $manjian_status_arr = $manjian_model->getManjianStatus();
  75. $this->assign('manjian_status_arr', $manjian_status_arr);
  76. return $this->fetch("manjian/lists");
  77. }
  78. }
  79. /**
  80. * 满减添加
  81. */
  82. public function add()
  83. {
  84. $member_level_model = new MemberLevel();
  85. if (request()->isAjax()) {
  86. $data = [
  87. 'site_id' => $this->site_id,
  88. 'manjian_name' => input('manjian_name', ''),
  89. 'manjian_type' => input('manjian_type', ''),
  90. 'type' => input('type', 0),
  91. 'number' => input('number', 0),
  92. 'goods_ids' => input('goods_ids', ''),
  93. 'start_time' => strtotime(input('start_time', '')),
  94. 'end_time' => strtotime(input('end_time', '')),
  95. 'rule_json' => input('rule_json', ''),
  96. 'remark' => input('remark', '')
  97. ];
  98. $manjian_model = new ManjianModel();
  99. return $manjian_model->addManjian($data);
  100. } else {
  101. //获取优惠券列表
  102. $coupon_model = new CouponType();
  103. $condition = [
  104. [ 'status', '=', 1 ],
  105. [ 'site_id', '=', $this->site_id ],
  106. ];
  107. //优惠券字段
  108. $coupon_field = 'coupon_type_id,type,coupon_name,image,money,discount,validity_type,fixed_term,status,is_limit,at_least,count,lead_count,end_time';
  109. $coupon_list = $coupon_model->getCouponTypeList($condition, $coupon_field);
  110. $this->assign('coupon_list', $coupon_list);
  111. $this->assign('level_time', $member_level_model->level_time);
  112. return $this->fetch("manjian/add", [], $this->replace);
  113. }
  114. }
  115. /**
  116. * 满减编辑
  117. */
  118. public function edit()
  119. {
  120. $member_level_model = new MemberLevel();
  121. $manjian_model = new ManjianModel();
  122. if (request()->isAjax()) {
  123. $data = [
  124. 'manjian_id' => input('manjian_id', 0),
  125. 'site_id' => $this->site_id,
  126. 'manjian_name' => input('manjian_name', ''),
  127. 'manjian_type' => input('manjian_type', ''),
  128. 'type' => input('type', 0),
  129. 'goods_ids' => input('goods_ids', ''),
  130. 'start_time' => strtotime(input('start_time', '')),
  131. 'end_time' => strtotime(input('end_time', '')),
  132. 'rule_json' => input('rule_json', ''),
  133. 'remark' => input('remark', '')
  134. ];
  135. return $manjian_model->editManjian($data);
  136. } else {
  137. $manjian_id = input('manjian_id', 0);
  138. $this->assign('manjian_id', $manjian_id);
  139. $manjian_info = $manjian_model->getManjianDetail($manjian_id, $this->site_id);
  140. if (empty($manjian_info[ 'data' ])) $this->error('未获取到活动数据', addon_url('manjian://shop/manjian/lists'));
  141. $this->assign('manjian_info', $manjian_info[ 'data' ]);
  142. //获取优惠券列表
  143. $coupon_model = new CouponType();
  144. $condition = [
  145. [ 'status', '=', 1 ],
  146. [ 'site_id', '=', $this->site_id ],
  147. ];
  148. //优惠券字段
  149. $coupon_field = 'coupon_type_id,type,coupon_name,image,money,discount,validity_type,fixed_term,status,is_limit,at_least,count,lead_count,end_time';
  150. $coupon_list = $coupon_model->getCouponTypeList($condition, $coupon_field);
  151. $this->assign('coupon_list', $coupon_list);
  152. $this->assign('level_time', $member_level_model->level_time);
  153. return $this->fetch("manjian/edit", [], $this->replace);
  154. }
  155. }
  156. /**
  157. * 满减详情
  158. */
  159. public function detail()
  160. {
  161. $manjian_id = input('manjian_id', 0);
  162. $manjian_model = new ManjianModel();
  163. $manjian_info = $manjian_model->getManjianDetail($manjian_id, $this->site_id);
  164. if (empty($manjian_info[ 'data' ])) $this->error('未获取到活动数据', addon_url('manjian://shop/manjian/lists'));
  165. $this->assign('manjian_info', $manjian_info[ 'data' ]);
  166. return $this->fetch('manjian/detail');
  167. }
  168. /**
  169. * 满减关闭
  170. */
  171. public function close()
  172. {
  173. if (request()->isAjax()) {
  174. $manjian_id = input('manjian_id', 0);
  175. $manjian_model = new ManjianModel();
  176. return $manjian_model->closeManjian($manjian_id, $this->site_id);
  177. }
  178. }
  179. /**
  180. * 满减删除
  181. */
  182. public function delete()
  183. {
  184. if (request()->isAjax()) {
  185. $manjian_id = input('manjian_id', 0);
  186. $manjian_model = new ManjianModel();
  187. return $manjian_model->deleteManjian($manjian_id, $this->site_id);
  188. }
  189. }
  190. /**
  191. * 活动冲突商品
  192. */
  193. public function conflict()
  194. {
  195. $key = input('key', '');
  196. $conflict_data = Cache::get($key);
  197. $this->assign('conflict_data', $conflict_data);
  198. return $this->fetch('manjian/conflict');
  199. }
  200. }