Issue.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. // try {
  66. $params = request()->all();
  67. $validator = [
  68. 'issue_no' => 'required|string|max:50|alpha_dash|unique:issues,issue_no',
  69. 'winning_numbers' => 'nullable|string|max:100',
  70. 'status' => 'nullable|string',
  71. ];
  72. request()->validate($validator);
  73. $ret = IssueService::submit($params);
  74. if ($ret['code'] == IssueService::NOT) {
  75. return $this->error($ret['code'], $ret['msg']);
  76. }
  77. // } catch (ValidationException $e) {
  78. // return $this->error(HttpStatus::VALIDATION_FAILED, '', $e->errors());
  79. // } catch (Exception $e) {
  80. // return $this->error(intval($e->getCode()));
  81. // }
  82. return $this->success([], $ret['msg']);
  83. }
  84. // 开奖失败
  85. public function failure()
  86. {
  87. $id = request()->input('id');
  88. if (!$id) {
  89. return $this->error(HttpStatus::VALIDATION_FAILED, '参数错误');
  90. }
  91. $ret = IssueService::lotteryDrawFail($id);
  92. if ($ret['code'] == IssueService::NOT) {
  93. return $this->error($ret['code'], $ret['msg']);
  94. }
  95. return $this->success([], $ret['msg']);
  96. }
  97. /**
  98. * @description: 开始
  99. * @return {*}
  100. */
  101. public function betting()
  102. {
  103. $id = request()->input('id');
  104. if (!$id) {
  105. return $this->error(HttpStatus::VALIDATION_FAILED, '参数错误');
  106. }
  107. $ret = IssueService::betting($id);
  108. if ($ret['code'] == IssueService::NOT) {
  109. return $this->error($ret['code'], $ret['msg']);
  110. }
  111. return $this->success([], $ret['msg']);
  112. }
  113. /**
  114. * @description: 关闭
  115. * @return {*}
  116. */
  117. public function close()
  118. {
  119. $id = request()->input('id');
  120. if (!$id) {
  121. return $this->error(HttpStatus::VALIDATION_FAILED, '参数错误');
  122. }
  123. $ret = IssueService::closeBetting($id);
  124. if ($ret['code'] == IssueService::NOT) {
  125. return $this->error($ret['code'], $ret['msg']);
  126. }
  127. return $this->success([], $ret['msg']);
  128. }
  129. /**
  130. * @description: 开奖
  131. * @return {*}
  132. */
  133. public function lotteryDraw()
  134. {
  135. $id = request()->input('id');
  136. $winning_numbers = request()->input('winning_numbers');
  137. $image = request()->input('image');
  138. $combo = request()->input('combo');
  139. if (!$id) {
  140. return $this->error(HttpStatus::VALIDATION_FAILED, '参数错误');
  141. }
  142. if (!$winning_numbers) {
  143. return $this->error(HttpStatus::VALIDATION_FAILED, '参数错误');
  144. }
  145. if(explode(',', $winning_numbers) < 3){
  146. return $this->error(HttpStatus::VALIDATION_FAILED, '开奖号码格式错误');
  147. }
  148. $ret = IssueService::lotteryDraw($id,$winning_numbers,$combo,$image);
  149. if ($ret['code'] == IssueService::NOT) {
  150. return $this->error($ret['code'], $ret['msg']);
  151. }
  152. return $this->success([], $ret['msg']);
  153. }
  154. /**
  155. * @description: 删除
  156. */
  157. public function destroy()
  158. {
  159. $id = request()->post('id');
  160. // 示例:通过 ID 删除
  161. $info = IssueService::findOne(['id' => $id]);
  162. if (!$info) {
  163. return $this->error(0, '期数不存在');
  164. }
  165. $info->delete();
  166. return $this->success([], '删除成功');
  167. }
  168. }