LuckLottery.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\adminapi\controller\v1\marketing\lottery;
  13. use app\adminapi\controller\AuthController;
  14. use app\services\activity\lottery\LuckLotteryServices;
  15. use think\facade\App;
  16. /**
  17. * 抽奖活动
  18. * Class LuckLottery
  19. * @package app\controller\admin\v1\marketing\lottery
  20. */
  21. class LuckLottery extends AuthController
  22. {
  23. /**
  24. * LuckLottery constructor.
  25. * @param App $app
  26. * @param LuckLotteryServices $services
  27. */
  28. public function __construct(App $app, LuckLotteryServices $services)
  29. {
  30. parent::__construct($app);
  31. $this->services = $services;
  32. }
  33. /**
  34. * 抽奖列表
  35. * @return mixed
  36. */
  37. public function index()
  38. {
  39. $where = $this->request->postMore([
  40. ['start_status', '', '', 'start'],
  41. ['status', ''],
  42. ['factor', ''],
  43. ['store_name', '', '', 'keyword'],
  44. ]);
  45. return app('json')->success($this->services->getList($where));
  46. }
  47. /**
  48. * 抽奖活动详情
  49. * @param $id
  50. * @return mixed
  51. * @throws \think\db\exception\DataNotFoundException
  52. * @throws \think\db\exception\DbException
  53. * @throws \think\db\exception\ModelNotFoundException
  54. */
  55. public function detail($id)
  56. {
  57. if (!$id) {
  58. return app('json')->fail(100100);
  59. }
  60. return app('json')->success($this->services->getlotteryInfo((int)$id));
  61. }
  62. /**
  63. * 根据类型获取详情
  64. * @param $factor
  65. * @return mixed
  66. * @throws \think\db\exception\DataNotFoundException
  67. * @throws \think\db\exception\DbException
  68. * @throws \think\db\exception\ModelNotFoundException
  69. */
  70. public function factorInfo($factor)
  71. {
  72. if (!$factor) {
  73. return app('json')->fail(100100);
  74. }
  75. return app('json')->success($this->services->getlotteryFactorInfo((int)$factor));
  76. }
  77. /**
  78. * 添加抽奖
  79. * @return mixed
  80. * @throws \think\db\exception\DataNotFoundException
  81. * @throws \think\db\exception\DbException
  82. * @throws \think\db\exception\ModelNotFoundException
  83. */
  84. public function add()
  85. {
  86. $data = $this->request->postMore([
  87. ['name', ''],
  88. ['desc', ''],
  89. ['image', ''],
  90. ['factor', 1],
  91. ['factor_num', 1],
  92. ['attends_user', 1],
  93. ['user_level', []],
  94. ['user_label', []],
  95. ['is_svip', 0],
  96. ['period', [0, 0]],
  97. ['lottery_num_term', 1],
  98. ['lottery_num', 1],
  99. ['spread_num', 1],
  100. ['is_all_record', 1],
  101. ['is_personal_record', 1],
  102. ['is_content', 1],
  103. ['content', ''],
  104. ['status', 1],
  105. ['prize', []]
  106. ]);
  107. if (!$data['name']) {
  108. return app('json')->fail(400501);
  109. }
  110. if ($data['is_content'] && !$data['content']) {
  111. return app('json')->fail(400502);
  112. }
  113. [$start, $end] = $data['period'];
  114. unset($data['period']);
  115. $data['start_time'] = $start ? strtotime($start) : 0;
  116. $data['end_time'] = $end ? strtotime($end) : 0;
  117. if ($data['start_time'] && $data['end_time'] && $data['end_time'] <= $data['start_time']) {
  118. return app('json')->fail(400503);
  119. }
  120. if (!$data['prize']) {
  121. return app('json')->fail(400504);
  122. }
  123. if (in_array($data['factor'], [1, 2]) && !$data['factor_num']) {
  124. return app('json')->fail(400505);
  125. }
  126. return app('json')->success($this->services->add($data) ? 100000 : 100006);
  127. }
  128. /**
  129. * 修改抽奖
  130. * @param $id
  131. * @return mixed
  132. * @throws \think\db\exception\DataNotFoundException
  133. * @throws \think\db\exception\DbException
  134. * @throws \think\db\exception\ModelNotFoundException
  135. */
  136. public function edit($id)
  137. {
  138. $data = $this->request->postMore([
  139. ['name', ''],
  140. ['desc', ''],
  141. ['image', ''],
  142. ['factor', 1],
  143. ['factor_num', 1],
  144. ['attends_user', 1],
  145. ['user_level', []],
  146. ['user_label', []],
  147. ['is_svip', 0],
  148. ['period', [0, 0]],
  149. ['lottery_num_term', 1],
  150. ['lottery_num', 1],
  151. ['spread_num', 1],
  152. ['is_all_record', 1],
  153. ['is_personal_record', 1],
  154. ['is_content', 1],
  155. ['content', ''],
  156. ['status', 1],
  157. ['prize', []]
  158. ]);
  159. if (!$id) {
  160. return app('json')->fail(100100);
  161. }
  162. if (!$data['name']) {
  163. return app('json')->fail(400501);
  164. }
  165. [$start, $end] = $data['period'];
  166. unset($data['period']);
  167. $data['start_time'] = $start ? strtotime($start) : 0;
  168. $data['end_time'] = $end ? strtotime($end) : 0;
  169. if ($data['start_time'] && $data['end_time'] && $data['end_time'] <= $data['start_time']) {
  170. return app('json')->fail(400503);
  171. }
  172. if ($data['is_content'] && !$data['content']) {
  173. return app('json')->fail(400502);
  174. }
  175. if (!$data['prize']) {
  176. return app('json')->fail(400504);
  177. }
  178. if (in_array($data['factor'], [1, 2]) && !$data['factor_num']) {
  179. return app('json')->fail(400505);
  180. }
  181. return app('json')->success($this->services->edit((int)$id, $data) ? 100001 : 100007);
  182. }
  183. /**
  184. * 删除抽奖
  185. * @return mixed
  186. * @throws \think\db\exception\DataNotFoundException
  187. * @throws \think\db\exception\DbException
  188. * @throws \think\db\exception\ModelNotFoundException
  189. */
  190. public function delete()
  191. {
  192. list($id) = $this->request->getMore([
  193. ['id', 0],
  194. ], true);
  195. if (!$id) return app('json')->fail(100026);
  196. $this->services->delLottery((int)$id);
  197. return app('json')->success(100002);
  198. }
  199. /**
  200. * 设置活动状态
  201. * @param string $id
  202. * @param string $status
  203. * @return mixed
  204. * @throws \think\db\exception\DataNotFoundException
  205. * @throws \think\db\exception\DbException
  206. * @throws \think\db\exception\ModelNotFoundException
  207. */
  208. public function setStatus($id = '', $status = '')
  209. {
  210. if ($status == '' || $id == '') return app('json')->fail(100100);
  211. $this->services->setStatus((int)$id, (int)$status);
  212. return app('json')->success(100014);
  213. }
  214. }