Issue.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. * @description: 开始
  86. * @return {*}
  87. */
  88. public function betting()
  89. {
  90. $id = request()->input('id');
  91. if (!$id) {
  92. return $this->error(HttpStatus::VALIDATION_FAILED, '参数错误');
  93. }
  94. $ret = IssueService::betting($id);
  95. if ($ret['code'] == IssueService::NOT) {
  96. return $this->error($ret['code'], $ret['msg']);
  97. }
  98. return $this->success([], $ret['msg']);
  99. }
  100. /**
  101. * @description: 关闭
  102. * @return {*}
  103. */
  104. public function close()
  105. {
  106. $id = request()->input('id');
  107. if (!$id) {
  108. return $this->error(HttpStatus::VALIDATION_FAILED, '参数错误');
  109. }
  110. $ret = IssueService::closeBetting($id);
  111. if ($ret['code'] == IssueService::NOT) {
  112. return $this->error($ret['code'], $ret['msg']);
  113. }
  114. return $this->success([], $ret['msg']);
  115. }
  116. /**
  117. * @description: 开奖
  118. * @return {*}
  119. */
  120. public function lotteryDraw()
  121. {
  122. $id = request()->input('id');
  123. $winning_numbers = request()->input('winning_numbers');
  124. $image = request()->input('image');
  125. $combo = request()->input('combo');
  126. if (!$id) {
  127. return $this->error(HttpStatus::VALIDATION_FAILED, '参数错误');
  128. }
  129. if (!$winning_numbers) {
  130. return $this->error(HttpStatus::VALIDATION_FAILED, '参数错误');
  131. }
  132. if(explode(',', $winning_numbers) < 3){
  133. return $this->error(HttpStatus::VALIDATION_FAILED, '开奖号码格式错误');
  134. }
  135. $ret = IssueService::lotteryDraw($id,$winning_numbers,$combo,$image);
  136. if ($ret['code'] == IssueService::NOT) {
  137. return $this->error($ret['code'], $ret['msg']);
  138. }
  139. return $this->success([], $ret['msg']);
  140. }
  141. /**
  142. * @description: 删除
  143. */
  144. public function destroy()
  145. {
  146. $id = request()->post('id');
  147. // 示例:通过 ID 删除
  148. $info = IssueService::findOne(['id' => $id]);
  149. if (!$info) {
  150. return $this->error(0, '期数不存在');
  151. }
  152. $info->delete();
  153. return $this->success([], '删除成功');
  154. }
  155. }