PcIssue.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace App\Http\Controllers\admin;
  3. use App\Constants\HttpStatus;
  4. use App\Http\Controllers\Controller;
  5. use App\Services\PcIssueService;
  6. use Illuminate\Validation\ValidationException;
  7. use Exception;
  8. use App\Models\PcIssue as PcIssueModel;
  9. class PcIssue extends Controller
  10. {
  11. /**
  12. * @api {get} /admin/pcIssue 极速28
  13. * @apiGroup 极速28
  14. *
  15. * @apiUse result
  16. * @apiUse header
  17. * @apiVersion 1.0.0
  18. *
  19. * @apiParam {int} [page=1]
  20. * @apiParam {int} [limit=10]
  21. * @apiParam {string} [issue_no] 期号
  22. */
  23. public function index()
  24. {
  25. try {
  26. $search = request()->validate([
  27. 'page' => ['nullable', 'integer', 'min:1'],
  28. 'limit' => ['nullable', 'integer', 'min:1'],
  29. 'issue_no' => ['nullable', 'string'],
  30. ]);
  31. $page = request()->input('page', 1);
  32. $limit = request()->input('limit', 15);
  33. $result['total'] = PcIssueModel::where(PcIssueModel::getWhere($search))->count();
  34. $result['data'] = PcIssueModel::where(PcIssueModel::getWhere($search))
  35. ->orderByDesc('id')->forPage($page, $limit)->get();
  36. } catch (ValidationException $e) {
  37. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  38. } catch (Exception $e) {
  39. return $this->error(intval($e->getCode()));
  40. }
  41. return $this->success($result);
  42. }
  43. /**
  44. * @api {get} /admin/pcIssue/preDraw 预开奖
  45. * @apiGroup 极速28
  46. *
  47. * @apiUse result
  48. * @apiUse header
  49. * @apiVersion 1.0.0
  50. *
  51. * @apiParam {string} issue_no 期号
  52. * @apiParam {int} he 预开奖号码
  53. * - 开奖号码取值范围:0-27
  54. *
  55. */
  56. public function preDraw()
  57. {
  58. try {
  59. request()->validate([
  60. 'issue_no' => ['required', 'string'],
  61. 'he' => ['required', 'integer', 'min:0', 'max:27'],
  62. ]);
  63. $issueNo = request()->input('issue_no');
  64. $he = request()->input('he');
  65. $he = intval($he);
  66. $pcIssue = PcIssueModel::where('issue_no', $issueNo)->first();
  67. if (!$pcIssue) throw new Exception('期号错误', HttpStatus::CUSTOM_ERROR);
  68. if (!in_array($pcIssue->status, [PcIssueModel::STATUS_BETTING, PcIssueModel::STATUS_CLOSE])) {
  69. throw new Exception('预开奖失败;状态不正确', HttpStatus::CUSTOM_ERROR);
  70. }
  71. $keno = PcIssueService::getMatchingNumbers($he);
  72. $pcIssue->advance_keno = json_encode($keno);
  73. $pcIssue->advance_code = $he;
  74. $pcIssue->save();
  75. } catch (ValidationException $e) {
  76. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  77. } catch (Exception $e) {
  78. if ($e->getCode() == HttpStatus::CUSTOM_ERROR) {
  79. return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage());
  80. }
  81. return $this->error(intval($e->getCode()));
  82. }
  83. return $this->success();
  84. }
  85. }