Issue.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. /**
  12. * @description: 分页数据
  13. * @return {*}
  14. */
  15. function index()
  16. {
  17. try {
  18. request()->validate([
  19. 'issue_no' => ['nullable', 'string'],
  20. 'id' => ['nullable', 'string'],
  21. 'status' => ['nullable', 'string'],
  22. ]);
  23. $search = request()->all();
  24. $result = IssueService::paginate($search);
  25. } catch (ValidationException $e) {
  26. return $this->error(HttpStatus::VALIDATION_FAILED, $e->validator->errors()->first());
  27. } catch (Exception $e) {
  28. return $this->error(intval($e->getCode()));
  29. }
  30. return $this->success($result);
  31. }
  32. /**
  33. * @description: 修改|新增
  34. * @return {*}
  35. */
  36. public function store()
  37. {
  38. // try {
  39. $params = request()->all();
  40. $validator = [
  41. 'issue_no' => 'required|string|max:50|alpha_dash|unique:issues,issue_no',
  42. 'winning_numbers' => 'nullable|string|max:100',
  43. 'status' => 'nullable|string',
  44. ];
  45. request()->validate($validator);
  46. $ret = IssueService::submit($params);
  47. if ($ret['code'] == IssueService::NOT) {
  48. return $this->error($ret['code'], $ret['msg']);
  49. }
  50. // } catch (ValidationException $e) {
  51. // return $this->error(HttpStatus::VALIDATION_FAILED, '', $e->errors());
  52. // } catch (Exception $e) {
  53. // return $this->error(intval($e->getCode()));
  54. // }
  55. return $this->success([], $ret['msg']);
  56. }
  57. /**
  58. * @description: 开始
  59. * @return {*}
  60. */
  61. public function betting()
  62. {
  63. $id = request()->input('id');
  64. if (!$id) {
  65. return $this->error(HttpStatus::VALIDATION_FAILED, '参数错误');
  66. }
  67. $ret = IssueService::betting($id);
  68. if ($ret['code'] == IssueService::NOT) {
  69. return $this->error($ret['code'], $ret['msg']);
  70. }
  71. return $this->success([], $ret['msg']);
  72. }
  73. /**
  74. * @description: 关闭
  75. * @return {*}
  76. */
  77. public function close()
  78. {
  79. $id = request()->input('id');
  80. if (!$id) {
  81. return $this->error(HttpStatus::VALIDATION_FAILED, '参数错误');
  82. }
  83. $ret = IssueService::closeBetting($id);
  84. if ($ret['code'] == IssueService::NOT) {
  85. return $this->error($ret['code'], $ret['msg']);
  86. }
  87. return $this->success([], $ret['msg']);
  88. }
  89. /**
  90. * @description: 开奖
  91. * @return {*}
  92. */
  93. public function lotteryDraw()
  94. {
  95. $id = request()->input('id');
  96. $winning_numbers = request()->input('winning_numbers');
  97. if (!$id) {
  98. return $this->error(HttpStatus::VALIDATION_FAILED, '参数错误');
  99. }
  100. if (!$winning_numbers) {
  101. return $this->error(HttpStatus::VALIDATION_FAILED, '参数错误');
  102. }
  103. if(explode(',', $winning_numbers) < 3){
  104. return $this->error(HttpStatus::VALIDATION_FAILED, '开奖号码格式错误');
  105. }
  106. $ret = IssueService::lotteryDraw($id,$winning_numbers);
  107. if ($ret['code'] == IssueService::NOT) {
  108. return $this->error($ret['code'], $ret['msg']);
  109. }
  110. return $this->success([], $ret['msg']);
  111. }
  112. }