Issue.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?php
  2. namespace App\Http\Controllers\admin;
  3. use App\Constants\HttpStatus;
  4. use App\Http\Controllers\Controller;
  5. use App\Services\BaseService;
  6. use App\Services\IssueService;
  7. use Illuminate\Support\Facades\DB;
  8. use Illuminate\Validation\ValidationException;
  9. use Exception;
  10. class Issue extends Controller
  11. {
  12. /**
  13. * @description: 分页数据
  14. * @return {*}
  15. */
  16. function index()
  17. {
  18. try {
  19. request()->validate([
  20. 'issue_no' => ['nullable', 'string'],
  21. 'id' => ['nullable', 'string'],
  22. 'status' => ['nullable', 'string'],
  23. ]);
  24. $search = request()->all();
  25. $result = IssueService::paginate($search);
  26. } catch (ValidationException $e) {
  27. return $this->error(HttpStatus::VALIDATION_FAILED, $e->validator->errors()->first());
  28. } catch (Exception $e) {
  29. return $this->error(intval($e->getCode()));
  30. }
  31. return $this->success($result);
  32. }
  33. /**
  34. * @description: 异常分页数据
  35. * @return {*}
  36. */
  37. function abnormal()
  38. {
  39. try {
  40. request()->validate([
  41. 'issue_no' => ['nullable', 'string'],
  42. 'id' => ['nullable', 'string'],
  43. 'status' => ['nullable', 'string'],
  44. ]);
  45. $search = request()->all();
  46. $search['abnormal'] = 1;
  47. $result = IssueService::paginate($search);
  48. } catch (ValidationException $e) {
  49. return $this->error(HttpStatus::VALIDATION_FAILED, $e->validator->errors()->first());
  50. } catch (Exception $e) {
  51. return $this->error(intval($e->getCode()));
  52. }
  53. return $this->success($result);
  54. }
  55. /**
  56. * @description: 修改|新增
  57. * @return {*}
  58. */
  59. public function store()
  60. {
  61. return $this->error(HttpStatus::CUSTOM_ERROR, '禁止编辑');
  62. // try {
  63. $params = request()->all();
  64. $validator = [
  65. 'issue_no' => 'required|string|max:50|alpha_dash|unique:issues,issue_no',
  66. 'winning_numbers' => 'nullable|string|max:100',
  67. 'status' => 'nullable|string',
  68. ];
  69. request()->validate($validator);
  70. $ret = IssueService::submit($params);
  71. if ($ret['code'] == IssueService::NOT) {
  72. return $this->error($ret['code'], $ret['msg']);
  73. }
  74. // } catch (ValidationException $e) {
  75. // return $this->error(HttpStatus::VALIDATION_FAILED, '', $e->errors());
  76. // } catch (Exception $e) {
  77. // return $this->error(intval($e->getCode()));
  78. // }
  79. return $this->success([], $ret['msg']);
  80. }
  81. // 开奖失败
  82. public function failure()
  83. {
  84. $id = request()->input('id');
  85. if (!$id) {
  86. return $this->error(HttpStatus::VALIDATION_FAILED, '参数错误');
  87. }
  88. $ret = IssueService::lotteryDrawFail($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 betting()
  99. {
  100. $id = request()->input('id');
  101. if (!$id) {
  102. return $this->error(HttpStatus::VALIDATION_FAILED, '参数错误');
  103. }
  104. $ret = IssueService::betting($id);
  105. if ($ret['code'] == IssueService::NOT) {
  106. return $this->error($ret['code'], $ret['msg']);
  107. }
  108. return $this->success([], $ret['msg']);
  109. }
  110. /**
  111. * @description: 关闭
  112. * @return {*}
  113. */
  114. public function close()
  115. {
  116. $id = request()->input('id');
  117. if (!$id) {
  118. return $this->error(HttpStatus::VALIDATION_FAILED, '参数错误');
  119. }
  120. $ret = IssueService::closeBetting($id);
  121. if ($ret['code'] == IssueService::NOT) {
  122. return $this->error($ret['code'], $ret['msg']);
  123. }
  124. return $this->success([], $ret['msg']);
  125. }
  126. /**
  127. * @description: 开奖
  128. * @return {*}
  129. */
  130. public function lotteryDraw()
  131. {
  132. $id = request()->input('id');
  133. $winning_numbers = request()->input('winning_numbers');
  134. $keno = null;
  135. if (!$id) {
  136. return $this->error(HttpStatus::CUSTOM_ERROR, '参数错误');
  137. }
  138. if (empty($winning_numbers)) {
  139. $issue = IssueService::findOne(['id' => $id]);
  140. if (!$issue) {
  141. return $this->error(HttpStatus::CUSTOM_ERROR, '期号不存在');
  142. }
  143. $playNowInfo = IssueService::getPlayNowWinningInfo($issue->issue_no);
  144. if ($playNowInfo['code'] == IssueService::NOT) {
  145. return $this->error(HttpStatus::CUSTOM_ERROR, $playNowInfo['msg']);
  146. }
  147. $winning_numbers = $playNowInfo['winning_numbers'];
  148. $keno = $playNowInfo['source_numbers'] ?? null;
  149. }
  150. $winningNumberList = array_map('trim', explode(',', $winning_numbers));
  151. if (count($winningNumberList) !== 3) {
  152. return $this->error(HttpStatus::CUSTOM_ERROR, '开奖号码格式错误');
  153. }
  154. $winArr = [];
  155. foreach ($winningNumberList as $number) {
  156. $value = filter_var($number, FILTER_VALIDATE_INT, [
  157. 'options' => [
  158. 'min_range' => 0,
  159. 'max_range' => 9,
  160. ],
  161. ]);
  162. if ($value === false) {
  163. return $this->error(HttpStatus::CUSTOM_ERROR, '开奖号码格式错误');
  164. }
  165. $winArr[] = (int)$value;
  166. }
  167. $winning_numbers = implode(',', $winArr);
  168. $combo = IssueService::getCombo($winArr);
  169. $ret = IssueService::lotteryDraw($id, $winning_numbers, $combo, "", $keno);
  170. if ($ret['code'] == BaseService::NOT) {
  171. return $this->error($ret['code'], $ret['error'] ?? $ret['msg']);
  172. }
  173. return $this->success([], $ret['msg']);
  174. }
  175. /**
  176. * @description: 删除
  177. */
  178. public function destroy()
  179. {
  180. return $this->error(HttpStatus::CUSTOM_ERROR, '禁止删除');
  181. $id = request()->post('id');
  182. // 示例:通过 ID 删除
  183. $info = IssueService::findOne(['id' => $id]);
  184. if (!$info) {
  185. return $this->error(0, '期数不存在');
  186. }
  187. $info->delete();
  188. return $this->success([], '删除成功');
  189. }
  190. }