Issue.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. public function store()
  42. {
  43. // try {
  44. $params = request()->all();
  45. $validator = [
  46. 'issue_no' => 'required|string|max:50|alpha_dash|unique:issues,issue_no',
  47. 'winning_numbers' => 'nullable|string|max:100',
  48. 'status' => 'nullable|string',
  49. ];
  50. request()->validate($validator);
  51. $ret = IssueService::submit($params);
  52. if ($ret['code'] == IssueService::NOT) {
  53. return $this->error($ret['code'], $ret['msg']);
  54. }
  55. // } catch (ValidationException $e) {
  56. // return $this->error(HttpStatus::VALIDATION_FAILED, '', $e->errors());
  57. // } catch (Exception $e) {
  58. // return $this->error(intval($e->getCode()));
  59. // }
  60. return $this->success([], $ret['msg']);
  61. }
  62. /**
  63. * @description: 开始
  64. * @return {*}
  65. */
  66. public function betting()
  67. {
  68. $id = request()->input('id');
  69. if (!$id) {
  70. return $this->error(HttpStatus::VALIDATION_FAILED, '参数错误');
  71. }
  72. $ret = IssueService::betting($id);
  73. if ($ret['code'] == IssueService::NOT) {
  74. return $this->error($ret['code'], $ret['msg']);
  75. }
  76. return $this->success([], $ret['msg']);
  77. }
  78. /**
  79. * @description: 关闭
  80. * @return {*}
  81. */
  82. public function close()
  83. {
  84. $id = request()->input('id');
  85. if (!$id) {
  86. return $this->error(HttpStatus::VALIDATION_FAILED, '参数错误');
  87. }
  88. $ret = IssueService::closeBetting($id);
  89. if ($ret['code'] == IssueService::NOT) {
  90. return $this->error($ret['code'], $ret['msg']);
  91. }
  92. return $this->success([], $ret['msg']);
  93. }
  94. /**
  95. * @description: 开奖
  96. * @return {*}
  97. */
  98. public function lotteryDraw()
  99. {
  100. $id = request()->input('id');
  101. $winning_numbers = request()->input('winning_numbers');
  102. $image = request()->input('image');
  103. $combo = request()->input('combo');
  104. if (!$id) {
  105. return $this->error(HttpStatus::VALIDATION_FAILED, '参数错误');
  106. }
  107. if (!$winning_numbers) {
  108. return $this->error(HttpStatus::VALIDATION_FAILED, '参数错误');
  109. }
  110. if(explode(',', $winning_numbers) < 3){
  111. return $this->error(HttpStatus::VALIDATION_FAILED, '开奖号码格式错误');
  112. }
  113. $ret = IssueService::lotteryDraw($id,$winning_numbers,$combo,$image);
  114. if ($ret['code'] == IssueService::NOT) {
  115. return $this->error($ret['code'], $ret['msg']);
  116. }
  117. return $this->success([], $ret['msg']);
  118. }
  119. /**
  120. * @description: 删除
  121. */
  122. public function destroy()
  123. {
  124. $id = request()->post('id');
  125. // 示例:通过 ID 删除
  126. $info = IssueService::findOne(['id' => $id]);
  127. if (!$info) {
  128. return $this->error(0, '期数不存在');
  129. }
  130. $info->delete();
  131. return $this->success([], '删除成功');
  132. }
  133. }