Issue.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. namespace App\Http\Controllers\admin;
  3. use App\Constants\HttpStatus;
  4. use App\Http\Controllers\Controller;
  5. use App\Services\IssueService;
  6. use Illuminate\Support\Facades\DB;
  7. use Illuminate\Validation\ValidationException;
  8. use Exception;
  9. class Issue extends Controller
  10. {
  11. public function fakeLotteryDraw()
  12. {
  13. IssueService::fakeLotteryDraw();
  14. return $this->success();
  15. }
  16. /**
  17. * @description: 分页数据
  18. * @return {*}
  19. */
  20. function index()
  21. {
  22. try {
  23. request()->validate([
  24. 'issue_no' => ['nullable', 'string'],
  25. 'id' => ['nullable', 'string'],
  26. 'status' => ['nullable', 'string'],
  27. ]);
  28. $search = request()->all();
  29. $result = IssueService::paginate($search);
  30. } catch (ValidationException $e) {
  31. return $this->error(HttpStatus::VALIDATION_FAILED, $e->validator->errors()->first());
  32. } catch (Exception $e) {
  33. return $this->error(intval($e->getCode()));
  34. }
  35. return $this->success($result);
  36. }
  37. /**
  38. * @description: 异常分页数据
  39. * @return {*}
  40. */
  41. function abnormal()
  42. {
  43. try {
  44. request()->validate([
  45. 'issue_no' => ['nullable', 'string'],
  46. 'id' => ['nullable', 'string'],
  47. 'status' => ['nullable', 'string'],
  48. ]);
  49. $search = request()->all();
  50. $search['abnormal'] = 1;
  51. $result = IssueService::paginate($search);
  52. } catch (ValidationException $e) {
  53. return $this->error(HttpStatus::VALIDATION_FAILED, $e->validator->errors()->first());
  54. } catch (Exception $e) {
  55. return $this->error(intval($e->getCode()));
  56. }
  57. return $this->success($result);
  58. }
  59. /**
  60. * @description: 修改|新增
  61. * @return {*}
  62. */
  63. public function store()
  64. {
  65. return $this->error(HttpStatus::CUSTOM_ERROR,'禁止编辑');
  66. // try {
  67. $params = request()->all();
  68. $validator = [
  69. 'issue_no' => 'required|string|max:50|alpha_dash|unique:issues,issue_no',
  70. 'winning_numbers' => 'nullable|string|max:100',
  71. 'status' => 'nullable|string',
  72. ];
  73. request()->validate($validator);
  74. $ret = IssueService::submit($params);
  75. if ($ret['code'] == IssueService::NOT) {
  76. return $this->error($ret['code'], $ret['msg']);
  77. }
  78. // } catch (ValidationException $e) {
  79. // return $this->error(HttpStatus::VALIDATION_FAILED, '', $e->errors());
  80. // } catch (Exception $e) {
  81. // return $this->error(intval($e->getCode()));
  82. // }
  83. return $this->success([], $ret['msg']);
  84. }
  85. // 开奖失败
  86. public function failure()
  87. {
  88. $id = request()->input('id');
  89. if (!$id) {
  90. return $this->error(HttpStatus::VALIDATION_FAILED, '参数错误');
  91. }
  92. $ret = IssueService::lotteryDrawFail($id);
  93. if ($ret['code'] == IssueService::NOT) {
  94. return $this->error($ret['code'], $ret['msg']);
  95. }
  96. return $this->success([], $ret['msg']);
  97. }
  98. /**
  99. * @description: 开始
  100. * @return {*}
  101. */
  102. public function betting()
  103. {
  104. $id = request()->input('id');
  105. if (!$id) {
  106. return $this->error(HttpStatus::VALIDATION_FAILED, '参数错误');
  107. }
  108. $ret = IssueService::betting($id);
  109. if ($ret['code'] == IssueService::NOT) {
  110. return $this->error($ret['code'], $ret['msg']);
  111. }
  112. return $this->success([], $ret['msg']);
  113. }
  114. /**
  115. * @description: 关闭
  116. * @return {*}
  117. */
  118. public function close()
  119. {
  120. $id = request()->input('id');
  121. if (!$id) {
  122. return $this->error(HttpStatus::VALIDATION_FAILED, '参数错误');
  123. }
  124. $ret = IssueService::closeBetting($id);
  125. if ($ret['code'] == IssueService::NOT) {
  126. return $this->error($ret['code'], $ret['msg']);
  127. }
  128. return $this->success([], $ret['msg']);
  129. }
  130. /**
  131. * @description: 开奖
  132. * @return {*}
  133. */
  134. public function lotteryDraw()
  135. {
  136. $id = request()->input('id');
  137. $winning_numbers = request()->input('winning_numbers');
  138. $image = request()->input('image');
  139. $combo = request()->input('combo');
  140. if (!$id) {
  141. return $this->error(HttpStatus::VALIDATION_FAILED, '参数错误');
  142. }
  143. if (!$winning_numbers) {
  144. return $this->error(HttpStatus::VALIDATION_FAILED, '参数错误');
  145. }
  146. if(explode(',', $winning_numbers) < 3){
  147. return $this->error(HttpStatus::VALIDATION_FAILED, '开奖号码格式错误');
  148. }
  149. $ret = IssueService::lotteryDraw($id,$winning_numbers,$combo,$image);
  150. if ($ret['code'] == IssueService::NOT) {
  151. return $this->error($ret['code'], $ret['msg']);
  152. }
  153. return $this->success([], $ret['msg']);
  154. }
  155. /**
  156. * @description: 删除
  157. */
  158. public function destroy()
  159. {
  160. return $this->error(HttpStatus::CUSTOM_ERROR,'禁止删除');
  161. $id = request()->post('id');
  162. // 示例:通过 ID 删除
  163. $info = IssueService::findOne(['id' => $id]);
  164. if (!$info) {
  165. return $this->error(0, '期数不存在');
  166. }
  167. $info->delete();
  168. return $this->success([], '删除成功');
  169. }
  170. }