Divideticket.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
  9. * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
  10. * =========================================================
  11. */
  12. namespace addon\divideticket\shop\controller;
  13. use app\shop\controller\BaseShop;
  14. use addon\divideticket\model\Divideticket as DivideticketModel;
  15. use addon\divideticket\model\DivideticketFriendsGroup;
  16. /**
  17. * 好友瓜分券
  18. * Class DivideTicket
  19. * @package addon\divideticket\shop\controller
  20. */
  21. class Divideticket extends BaseShop
  22. {
  23. /**
  24. * 活动列表
  25. * @return array|mixed
  26. */
  27. public function lists()
  28. {
  29. $divideticket_model = new DivideticketModel();
  30. if (request()->isAjax()) {
  31. $page = input('page', 1);
  32. $page_size = input('page_size', PAGE_LIST_ROWS);
  33. $name = input('name', '');
  34. $status = input('status', '');
  35. $condition = [];
  36. if ($status !== "") {
  37. $condition[] = [ 'status', '=', $status ];
  38. }
  39. //类型
  40. $validity_type = input('validity_type', '');
  41. if ($validity_type) {
  42. $validity_start_time = input('validity_start_time', '');
  43. $validity_end_time = input('validity_end_time', '');
  44. switch ( $validity_type ) {
  45. case 1: //固定
  46. $condition[] = [ 'validity_end_time', 'between', [ $validity_start_time, $validity_end_time ] ];
  47. break;
  48. case 2:
  49. $condition[] = [ 'fixed_term', 'between', [ $validity_start_time, $validity_end_time ] ];
  50. break;
  51. }
  52. }
  53. $condition[] = [ 'site_id', '=', $this->site_id ];
  54. $condition[] = [ 'name', 'like', '%' . $name . '%' ];
  55. $data = $divideticket_model->getDivideticketPageList($condition, $page, $page_size);
  56. return $data;
  57. } else {
  58. $divideticket_status = $divideticket_model->getDivideticketStatus();
  59. $this->assign('divideticket_status', $divideticket_status);
  60. return $this->fetch("divideticket/lists");
  61. }
  62. }
  63. /**
  64. * 添加活动
  65. * @return mixed
  66. */
  67. public function add()
  68. {
  69. if (request()->isAjax()) {
  70. $data = [
  71. 'site_id' => $this->site_id,
  72. 'name' => input('name', ''),//活动名称
  73. 'goods_type' => input('goods_type', 1),
  74. 'goods_ids' => input('goods_ids', ''),
  75. 'money' => input('money', 0),//瓜分金额
  76. 'start_time' => strtotime(input('start_time', '')), // 活动开始时间
  77. 'end_time' => strtotime(input('end_time', '')), // 活动结束时间
  78. 'divide_num' => input('divide_num', 0),//瓜分人数
  79. 'image' => input('image', 0),//优惠券图片
  80. 'inventory' => input('inventory', ''),//库存
  81. 'count' => input('inventory', ''),//发放数量
  82. 'is_limit' => input('at_least', 0) > 0 ? 1 : 0,//使用门槛
  83. 'at_least' => input('at_least', 0),//满多少元可以使用
  84. 'divide_time' => input('divide_time', 1),//瓜分有效期
  85. 'validity_end_time' => strtotime(input('validity_end_time', '')),//有效期结束时间
  86. 'validity_type' => input('validity_type', ''),//有效期类型 0固定时间 1领取之日起
  87. 'fixed_term' => input('fixed_term', ''),//领取之日起N天内有效
  88. 'is_simulation' => input('is_simulation', 0),//是否模拟好友
  89. 'is_new' => input('is_new', 0),//仅新人限制
  90. 'divide_type' => input('divide_type', ''),//瓜分方式
  91. 'create_time' => time(),//创建时间
  92. 'remark' => input('remark', ''),//活动规则
  93. ];
  94. $divideticket_model = new DivideticketModel();
  95. $res = $divideticket_model->addDivideticket($data);
  96. return $res;
  97. } else {
  98. return $this->fetch("divideticket/add");
  99. }
  100. }
  101. /**
  102. * 编辑活动
  103. * @return mixed
  104. */
  105. public function edit()
  106. {
  107. $divideticket_model = new DivideticketModel();
  108. if (request()->isAjax()) {
  109. $data = [
  110. 'coupon_id' => input('coupon_id', ''),
  111. 'site_id' => $this->site_id,
  112. 'name' => input('name', ''),//活动名称
  113. 'goods_type' => input('goods_type', 1),
  114. 'goods_ids' => input('goods_ids', ''),
  115. 'money' => input('money', 0),//瓜分金额
  116. 'divide_time' => input('divide_time', 1),//瓜分有效期
  117. 'start_time' => strtotime(input('start_time', '')), // 活动开始时间
  118. 'end_time' => strtotime(input('end_time', '')), // 活动结束时间
  119. 'divide_num' => input('divide_num', 0),//瓜分人数
  120. 'image' => input('image', 0),//优惠券图片
  121. 'inventory' => input('inventory', ''),//发放数量
  122. 'is_limit' => input('at_least', 0) > 0 ? 1 : 0,//使用门槛
  123. 'at_least' => input('at_least', 0),//满多少元可以使用
  124. 'validity_end_time' => strtotime(input('validity_end_time', '')),//有效期结束时间
  125. 'validity_type' => input('validity_type', ''),//有效期类型 0固定时间 1领取之日起
  126. 'fixed_term' => input('fixed_term', ''),//领取之日起N天内有效
  127. 'is_simulation' => input('is_simulation', 0),//是否模拟好友
  128. 'is_new' => input('is_new', 0),//仅新人限制
  129. 'divide_type' => input('divide_type', ''),//瓜分方式
  130. 'remark' => input('remark', ''),//活动规则
  131. ];
  132. $res = $divideticket_model->editDivideticket($data);
  133. return $res;
  134. } else {
  135. $coupon_id = input('coupon_id', 0);
  136. $this->assign('coupon_id', $coupon_id);
  137. $condition = [
  138. [ 'coupon_id', '=', $coupon_id ],
  139. [ 'site_id', '=', $this->site_id ],
  140. ];
  141. $coupon_info = $divideticket_model->getDivideticketInfo($condition);
  142. if (empty($coupon_info[ 'data' ])) $this->error('未获取到优惠券数据', addon_url('divideticket://shop/divideticket/lists'));
  143. $this->assign('coupon_info', $coupon_info[ 'data' ]);
  144. return $this->fetch("divideticket/edit");
  145. }
  146. }
  147. /**
  148. * 详情
  149. * @return mixed|void
  150. */
  151. public function detail()
  152. {
  153. $coupon_id = input('coupon_id', 0);
  154. $this->assign('coupon_id', $coupon_id);
  155. $condition = [
  156. [ 'coupon_id', '=', $coupon_id ],
  157. [ 'site_id', '=', $this->site_id ],
  158. ];
  159. $divideticket_model = new DivideticketModel();
  160. $info = $divideticket_model->getDivideticketInfo($condition)[ 'data' ] ?? [];
  161. if (empty($info)) $this->error('未获取到优惠券数据', addon_url('divideticket://shop/divideticket/lists'));
  162. $info[ 'status_name' ] = $divideticket_model->getDivideticketStatus()[ $info[ 'status' ] ] ?? '';
  163. $this->assign('info', $info);
  164. return $this->fetch("divideticket/detail");
  165. }
  166. /**
  167. * 活动推广
  168. */
  169. public function spreadDivideticket()
  170. {
  171. $coupon_id = input('coupon_id', '');
  172. $divideticket_model = new DivideticketModel();
  173. $res = $divideticket_model->urlQrcode('/pages_promotion/divideticket/index', [ 'cid' => $coupon_id ], 'divideticket', $this->site_id);
  174. return $res;
  175. }
  176. /**
  177. * 关闭活动
  178. */
  179. public function close()
  180. {
  181. if (request()->isAjax()) {
  182. $coupon_id = input('coupon_id', 0);
  183. $data = [
  184. 'coupon_id' => $coupon_id,
  185. 'site_id' => $this->site_id,
  186. ];
  187. $divideticket_model = new DivideticketModel();
  188. return $divideticket_model->closeDividetocket($data);
  189. }
  190. }
  191. /**
  192. * 删除活动
  193. */
  194. public function delete()
  195. {
  196. if (request()->isAjax()) {
  197. $coupon_id = input('coupon_id', 0);
  198. $data = [
  199. 'coupon_id' => $coupon_id,
  200. 'site_id' => $this->site_id,
  201. ];
  202. $divideticket_model = new DivideticketModel();
  203. return $divideticket_model->deleteDividetocket($data);
  204. }
  205. }
  206. /**
  207. * 运营
  208. */
  209. public function operate()
  210. {
  211. $coupon_id = input('coupon_id', '0');
  212. if (request()->isAjax()) {
  213. $page = input('page', 1);
  214. $page_size = input('page_size', PAGE_LIST_ROWS);
  215. $condition = [];
  216. $condition[] = [ 'a.site_id', '=', $this->site_id ];
  217. if ($coupon_id) {
  218. $condition[] = [ 'a.promotion_id', '=', $coupon_id ];
  219. }
  220. $alias = 'a';
  221. $join = [
  222. [ 'promotion_friends_coupon p', 'a.promotion_id = p.coupon_id', 'left' ],
  223. [ 'member m', 'a.header_id = m.member_id', 'left' ],
  224. ];
  225. $field = 'a.*,p.name,m.username,m.nickname,m.headimg';
  226. $divideticket_group_model = new DivideticketFriendsGroup();
  227. $data = $divideticket_group_model->getDivideticketFriendsGroupPageList($condition, $page, $page_size, '', $field, $alias, $join);
  228. return $data;
  229. } else {
  230. $this->assign('coupon_id', $coupon_id);
  231. return $this->fetch("divideticket/operate");
  232. }
  233. }
  234. /**
  235. * 邀请人
  236. */
  237. public function groupMember()
  238. {
  239. $group_id = input('group_id', '0');
  240. if (request()->isAjax()) {
  241. $divideticket_group_model = new DivideticketFriendsGroup();
  242. $condition = [];
  243. $condition[] = [ 'a.group_id', '=', $group_id ];
  244. $condition[] = [ 'a.site_id', '=', $this->site_id ];
  245. $field = 'a.*,p.divide_num,p.money';
  246. $join = [
  247. [ 'promotion_friends_coupon p', 'a.promotion_id = p.coupon_id', 'left' ],
  248. ];
  249. $data = $divideticket_group_model->getDivideticketFriendsGroupInfo($condition, $field, $alias = 'a', $join);
  250. $member_arr[ 'code' ] = 0;
  251. $member_arr[ 'data' ][ 'list' ] = $data[ 'data' ][ 'member_list' ] ?? [];
  252. if ($member_arr[ 'data' ][ 'list' ]) {
  253. foreach ($member_arr[ 'data' ][ 'list' ] as $k => $v) {
  254. $member_arr[ 'data' ][ 'list' ][ $k ][ 'divide_num' ] = $data[ 'data' ][ 'divide_num' ];
  255. $member_arr[ 'data' ][ 'list' ][ $k ][ 'money' ] = $data[ 'data' ][ 'money' ];
  256. }
  257. }
  258. return $member_arr;
  259. } else {
  260. $this->assign('group_id', $group_id);
  261. return $this->fetch("divideticket/group_member");
  262. }
  263. }
  264. }