LuckLottery.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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->getMore([
  40. ['factor', ''],
  41. ['start', ''],
  42. ['status', ''],
  43. ['time', ''],
  44. ['keyword', ''],
  45. ]);
  46. return app('json')->success($this->services->getList($where));
  47. }
  48. /**
  49. * 抽奖活动详情
  50. * @param $id
  51. * @return mixed
  52. * @throws \think\db\exception\DataNotFoundException
  53. * @throws \think\db\exception\DbException
  54. * @throws \think\db\exception\ModelNotFoundException
  55. */
  56. public function detail($id)
  57. {
  58. if (!$id) {
  59. return app('json')->fail(100100);
  60. }
  61. return app('json')->success($this->services->getLotteryInfo((int)$id));
  62. }
  63. /**
  64. * 添加抽奖
  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 add()
  71. {
  72. $data = $this->request->postMore([
  73. ['name', ''],
  74. ['desc', ''],
  75. ['image', ''],
  76. ['factor', 1],
  77. ['factor_num', 1],
  78. ['attends_user', 1],
  79. ['user_level', []],
  80. ['user_label', []],
  81. ['is_svip', 0],
  82. ['period', [0, 0]],
  83. ['lottery_num_term', 1],
  84. ['lottery_num', 1],
  85. ['spread_num', 1],
  86. ['is_all_record', 1],
  87. ['is_personal_record', 1],
  88. ['is_content', 1],
  89. ['content', ''],
  90. ['status', 1],
  91. ['prize', []]
  92. ]);
  93. if (!$data['name']) {
  94. return app('json')->fail(400501);
  95. }
  96. if ($data['is_content'] && !$data['content']) {
  97. return app('json')->fail(400502);
  98. }
  99. [$start, $end] = $data['period'];
  100. unset($data['period']);
  101. $data['start_time'] = $start ? strtotime($start) : 0;
  102. $data['end_time'] = $end ? strtotime($end) : 0;
  103. if ($data['start_time'] && $data['end_time'] && $data['end_time'] <= $data['start_time']) {
  104. return app('json')->fail(400503);
  105. }
  106. if (!$data['prize']) {
  107. return app('json')->fail(400504);
  108. }
  109. if (in_array($data['factor'], [1, 2]) && !$data['factor_num']) {
  110. return app('json')->fail(400505);
  111. }
  112. return app('json')->success($this->services->add($data) ? 100000 : 100006);
  113. }
  114. /**
  115. * 修改抽奖
  116. * @param $id
  117. * @return mixed
  118. * @throws \think\db\exception\DataNotFoundException
  119. * @throws \think\db\exception\DbException
  120. * @throws \think\db\exception\ModelNotFoundException
  121. */
  122. public function edit($id)
  123. {
  124. $data = $this->request->postMore([
  125. ['name', ''],
  126. ['desc', ''],
  127. ['image', ''],
  128. ['factor', 1],
  129. ['factor_num', 1],
  130. ['attends_user', 1],
  131. ['user_level', []],
  132. ['user_label', []],
  133. ['is_svip', 0],
  134. ['period', [0, 0]],
  135. ['lottery_num_term', 1],
  136. ['lottery_num', 1],
  137. ['spread_num', 1],
  138. ['is_all_record', 1],
  139. ['is_personal_record', 1],
  140. ['is_content', 1],
  141. ['content', ''],
  142. ['status', 1],
  143. ['prize', []]
  144. ]);
  145. if (!$id) {
  146. return app('json')->fail(100100);
  147. }
  148. if (!$data['name']) {
  149. return app('json')->fail(400501);
  150. }
  151. [$start, $end] = $data['period'];
  152. unset($data['period']);
  153. $data['start_time'] = $start ? strtotime($start) : 0;
  154. $data['end_time'] = $end ? strtotime($end) : 0;
  155. if ($data['start_time'] && $data['end_time'] && $data['end_time'] <= $data['start_time']) {
  156. return app('json')->fail(400503);
  157. }
  158. if ($data['is_content'] && !$data['content']) {
  159. return app('json')->fail(400502);
  160. }
  161. if (!$data['prize']) {
  162. return app('json')->fail(400504);
  163. }
  164. if (in_array($data['factor'], [1, 2]) && !$data['factor_num']) {
  165. return app('json')->fail(400505);
  166. }
  167. return app('json')->success($this->services->edit((int)$id, $data) ? 100001 : 100007);
  168. }
  169. /**
  170. * 删除抽奖
  171. * @return mixed
  172. * @throws \think\db\exception\DataNotFoundException
  173. * @throws \think\db\exception\DbException
  174. * @throws \think\db\exception\ModelNotFoundException
  175. */
  176. public function delete()
  177. {
  178. list($id) = $this->request->getMore([
  179. ['id', 0],
  180. ], true);
  181. if (!$id) return app('json')->fail(100026);
  182. $this->services->delLottery((int)$id);
  183. return app('json')->success(100002);
  184. }
  185. /**
  186. * 设置活动状态
  187. * @param string $id
  188. * @param string $status
  189. * @return mixed
  190. * @throws \think\db\exception\DataNotFoundException
  191. * @throws \think\db\exception\DbException
  192. * @throws \think\db\exception\ModelNotFoundException
  193. */
  194. public function setStatus($id = '', $status = '')
  195. {
  196. if ($status == '' || $id == '') return app('json')->fail(100100);
  197. $this->services->setStatus((int)$id, (int)$status);
  198. return app('json')->success(100014);
  199. }
  200. public function factorList()
  201. {
  202. return app('json')->success($this->services->factorList());
  203. }
  204. public function factorUse()
  205. {
  206. $data = $this->request->postMore([
  207. [['point', 'd'], 0],
  208. [['pay', 'd'], 0],
  209. [['evaluate', 'd'], 0],
  210. ]);
  211. $this->services->factorUse($data);
  212. return app('json')->success('保存成功');
  213. }
  214. }