Birthdaygift.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace addon\birthdaygift\shop\controller;
  11. use addon\coupon\model\CouponType;
  12. use app\model\member\MemberLevel;
  13. use app\shop\controller\BaseShop;
  14. use addon\birthdaygift\model\BirthdayGift as BirthdayGiftModel;
  15. /**
  16. * 生日有礼控制器
  17. */
  18. class Birthdaygift extends BaseShop
  19. {
  20. public function __construct()
  21. {
  22. //执行父类构造函数
  23. parent::__construct();
  24. $this->replace = [
  25. 'BIRTHDAYGIFT_CSS' => __ROOT__ . '/addon/birthdaygift/shop/view/public/css',
  26. 'BIRTHDAYGIFT_JS' => __ROOT__ . '/addon/birthdaygift/shop/view/public/js',
  27. 'BIRTHDAYGIFT_IMG' => __ROOT__ . '/addon/birthdaygift/shop/view/public/img',
  28. ];
  29. }
  30. /**
  31. * 生日有礼活动列表
  32. * @return array|mixed
  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. $search_text = input('search_text', '');
  40. $status = input('status', '');
  41. $condition[] = [ 'site_id', '=', $this->site_id ];
  42. $condition[] = [ 'is_delete', '=', 0 ];
  43. if (!empty($search_text)) {
  44. $condition[] = [ 'activity_name', 'like', '%' . $search_text . '%' ];
  45. }
  46. if (!empty($status)) {
  47. $condition[] = [ 'status', '=', $status ];
  48. }
  49. $gift_model = new BirthdayGiftModel();
  50. $order = 'create_time DESC';
  51. $field = '*';
  52. $lists = $gift_model->birthdayGiftPageList($condition, $page, $page_size, $order, $field);
  53. return $lists;
  54. } else {
  55. return $this->fetch("birthdaygift/lists");
  56. }
  57. }
  58. /**
  59. * 创建生日有礼活动
  60. * @return array|mixed
  61. */
  62. public function add()
  63. {
  64. if (request()->isAjax()) {
  65. if (strpos(input('type', ''), 'point') !== false) {
  66. $point = input('point', 0);
  67. } else {
  68. $point = 0;
  69. }
  70. if (strpos(input('type', ''), 'balance') !== false) {
  71. if (input('balance_type') == 0) {
  72. $balance = input('balance', '0.00');
  73. $balance_money = '0.00';
  74. } else {
  75. $balance_money = input('balance_money', '0.00');
  76. $balance = '0.00';
  77. }
  78. } else {
  79. $balance = '0.00';
  80. $balance_money = '0.00';
  81. }
  82. if (strpos(input('type', ''), 'coupon') !== false) {
  83. $coupon = input('coupon', '');
  84. } else {
  85. $coupon = 0;
  86. }
  87. $data = [
  88. 'activity_name' => input('activity_name', ''),
  89. 'activity_time_type' => input('activity_time_type', 1),// 活动时间(1生日当天2生日当周3生日当月)
  90. 'blessing_content' => input('blessing_content', ''),
  91. 'level_id' => input('level_id', 0),
  92. 'level_name' => input('level_name', ''),
  93. 'type' => input('type', ''),
  94. 'point' => $point,
  95. 'balance' => $balance,
  96. 'balance_type' => input('balance_type', '0'),
  97. 'balance_money' => $balance_money,
  98. 'coupon' => $coupon,
  99. 'site_id' => $this->site_id,
  100. 'start_time' => strtotime(input('start_time', '')),
  101. 'end_time' => strtotime(input('end_time', '')),
  102. ];
  103. $gift_model = new BirthdayGiftModel();
  104. $res = $gift_model->addBirthdayGiftActivity($data);
  105. return $res;
  106. } else {
  107. //会员等级
  108. $member_level_model = new MemberLevel();
  109. $member_level_list = $member_level_model->getMemberLevelList([ [ 'site_id', '=', $this->site_id ] ], 'level_id, level_name', 'growth asc');
  110. $this->assign('member_level_list', $member_level_list[ 'data' ]);
  111. //获取优惠券列表
  112. $coupon_model = new CouponType();
  113. $condition = [
  114. [ 'promotion_type', '=', 0 ],
  115. [ 'status', '=', 1 ],
  116. [ 'site_id', '=', $this->site_id ],
  117. ];
  118. //优惠券字段
  119. $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,goods_type,max_fetch';
  120. $coupon_list = $coupon_model->getCouponTypeList($condition, $coupon_field);
  121. if (!empty($coupon_list[ 'data' ])) {
  122. foreach ($coupon_list[ 'data' ] as $k => $v) {
  123. if ($v[ 'count' ] < 0 || $v[ 'count' ] - $v[ 'lead_count' ] > 0) {
  124. $coupon_list[ 'data' ][ $k ][ 'coupon_flag' ] = true;
  125. } else {
  126. $coupon_list[ 'data' ][ $k ][ 'coupon_flag' ] = false;
  127. }
  128. }
  129. }
  130. $this->assign('coupon_list', $coupon_list);
  131. return $this->fetch("birthdaygift/add", $this->replace);
  132. }
  133. }
  134. /**
  135. * 生日有礼详情
  136. * @return array|mixed
  137. */
  138. public function detail()
  139. {
  140. $activity_id = input('id', '0');
  141. //获取信息
  142. $activity_model = new BirthdayGiftModel();
  143. $info = $activity_model->getBirthdayGiftDetail([ [ 'site_id', '=', $this->site_id ], [ 'id', '=', $activity_id ] ], '*')[ 'data' ] ?? [];
  144. if (empty($info)) $this->error('未获取到活动数据', addon_url('birthdaygift://shop/birthdaygift/lists'));
  145. $info[ 'status_name' ] = $activity_model->status[ $info[ 'status' ] ] ?? '';
  146. $this->assign('info', $info);
  147. return $this->fetch("birthdaygift/detail");
  148. }
  149. /**
  150. * 生日有礼活动关闭
  151. * @return array|mixed
  152. */
  153. public function finish()
  154. {
  155. $activity_id = input('activity_id', '0');
  156. if (empty($activity_id)) $this->error('缺少必传参数', addon_url('birthdaygift://shop/birthdaygift/lists'));
  157. $activity_model = new BirthdayGiftModel();
  158. $data = [
  159. 'status' => -1
  160. ];
  161. $res = $activity_model->updateBirthdayGift($activity_id, $this->site_id, $data);
  162. return $res;
  163. }
  164. /**
  165. * 生日有礼编辑
  166. * @return array|mixed
  167. */
  168. public function edit()
  169. {
  170. $activity_id = input('id', '0');
  171. if (request()->isAjax()) {
  172. if (strpos(input('type', ''), 'point') !== false) {
  173. $point = input('point', 0);
  174. } else {
  175. $point = 0;
  176. }
  177. if (strpos(input('type', ''), 'balance') !== false) {
  178. if (input('balance_type') == 0) {
  179. $balance = input('balance', '0.00');
  180. $balance_money = '0.00';
  181. } else {
  182. $balance_money = input('balance_money', '0.00');
  183. $balance = '0.00';
  184. }
  185. } else {
  186. $balance = '0.00';
  187. $balance_money = '0.00';
  188. }
  189. if (strpos(input('type', ''), 'coupon') !== false) {
  190. $coupon = input('coupon', '');
  191. } else {
  192. $coupon = 0;
  193. }
  194. $data = [
  195. 'activity_name' => input('activity_name', ''),
  196. 'activity_time_type' => input('activity_time_type', 1),// 活动时间(1生日当天2生日当周3生日当月)
  197. 'blessing_content' => input('blessing_content', ''),
  198. 'level_id' => input('level_id', 0),
  199. 'level_name' => input('level_name', ''),
  200. 'type' => input('type', ''),
  201. 'point' => $point,
  202. 'balance' => $balance,
  203. 'balance_type' => input('balance_type', '0'),
  204. 'balance_money' => $balance_money,
  205. 'coupon' => $coupon,
  206. 'site_id' => $this->site_id,
  207. 'start_time' => strtotime(input('start_time', '')),
  208. 'end_time' => strtotime(input('end_time', '')),
  209. ];
  210. $gift_model = new BirthdayGiftModel();
  211. $res = $gift_model->editBirthdayGiftActivity($data, $activity_id);
  212. return $res;
  213. } else {
  214. //会员等级
  215. $member_level_model = new MemberLevel();
  216. $member_level_list = $member_level_model->getMemberLevelList([ [ 'site_id', '=', $this->site_id ] ], 'level_id, level_name', 'growth asc');
  217. $this->assign('member_level_list', $member_level_list[ 'data' ]);
  218. //获取优惠券列表
  219. $coupon_model = new CouponType();
  220. $condition = [
  221. [ 'promotion_type', '=', 0 ],
  222. [ 'status', '=', 1 ],
  223. [ 'site_id', '=', $this->site_id ],
  224. ];
  225. //优惠券字段
  226. $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,goods_type,max_fetch';
  227. $coupon_list = $coupon_model->getCouponTypeList($condition, $coupon_field);
  228. if (!empty($coupon_list[ 'data' ])) {
  229. foreach ($coupon_list[ 'data' ] as $k => $v) {
  230. if ($v[ 'count' ] < 0 || $v[ 'count' ] - $v[ 'lead_count' ] > 0) {
  231. $coupon_list[ 'data' ][ $k ][ 'coupon_flag' ] = true;
  232. } else {
  233. $coupon_list[ 'data' ][ $k ][ 'coupon_flag' ] = false;
  234. }
  235. }
  236. }
  237. $this->assign('coupon_list', $coupon_list);
  238. //获取信息
  239. $activity_model = new BirthdayGiftModel();
  240. $info = $activity_model->getBirthdayGiftDetail([ [ 'site_id', '=', $this->site_id ], [ 'id', '=', $activity_id ] ], '*');
  241. $this->assign('info', $info[ 'data' ]);
  242. if (empty($info[ 'data' ])) $this->error('未获取到活动数据', addon_url('birthdaygift://shop/birthdaygift/lists'));
  243. return $this->fetch('birthdaygift/edit', $this->replace);
  244. }
  245. }
  246. /**
  247. * 删除生日有礼活动
  248. * @return array|mixed
  249. */
  250. public function delete()
  251. {
  252. $activity_id = input('activity_id', 0);
  253. if (empty($activity_id)) $this->error('缺少必传参数', addon_url('birthdaygift://shop/birthdaygift/lists'));
  254. $activity_model = new BirthdayGiftModel();
  255. $data = [
  256. 'is_delete' => 1
  257. ];
  258. $res = $activity_model->updateBirthdayGift($activity_id, $this->site_id, $data);
  259. return $res;
  260. }
  261. }