Issue.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. public function fakeLotteryDraw()
  13. {
  14. IssueService::fakeLotteryDraw();
  15. return $this->success();
  16. }
  17. /**
  18. * @description: 分页数据
  19. * @return {*}
  20. */
  21. function index()
  22. {
  23. try {
  24. request()->validate([
  25. 'issue_no' => ['nullable', 'string'],
  26. 'id' => ['nullable', 'string'],
  27. 'status' => ['nullable', 'string'],
  28. ]);
  29. $search = request()->all();
  30. $result = IssueService::paginate($search);
  31. } catch (ValidationException $e) {
  32. return $this->error(HttpStatus::VALIDATION_FAILED, $e->validator->errors()->first());
  33. } catch (Exception $e) {
  34. return $this->error(intval($e->getCode()));
  35. }
  36. return $this->success($result);
  37. }
  38. /**
  39. * @description: 异常分页数据
  40. * @return {*}
  41. */
  42. function abnormal()
  43. {
  44. try {
  45. request()->validate([
  46. 'issue_no' => ['nullable', 'string'],
  47. 'id' => ['nullable', 'string'],
  48. 'status' => ['nullable', 'string'],
  49. ]);
  50. $search = request()->all();
  51. $search['abnormal'] = 1;
  52. $result = IssueService::paginate($search);
  53. } catch (ValidationException $e) {
  54. return $this->error(HttpStatus::VALIDATION_FAILED, $e->validator->errors()->first());
  55. } catch (Exception $e) {
  56. return $this->error(intval($e->getCode()));
  57. }
  58. return $this->success($result);
  59. }
  60. /**
  61. * @description: 修改|新增
  62. * @return {*}
  63. */
  64. public function store()
  65. {
  66. return $this->error(HttpStatus::CUSTOM_ERROR, '禁止编辑');
  67. // try {
  68. $params = request()->all();
  69. $validator = [
  70. 'issue_no' => 'required|string|max:50|alpha_dash|unique:issues,issue_no',
  71. 'winning_numbers' => 'nullable|string|max:100',
  72. 'status' => 'nullable|string',
  73. ];
  74. request()->validate($validator);
  75. $ret = IssueService::submit($params);
  76. if ($ret['code'] == IssueService::NOT) {
  77. return $this->error($ret['code'], $ret['msg']);
  78. }
  79. // } catch (ValidationException $e) {
  80. // return $this->error(HttpStatus::VALIDATION_FAILED, '', $e->errors());
  81. // } catch (Exception $e) {
  82. // return $this->error(intval($e->getCode()));
  83. // }
  84. return $this->success([], $ret['msg']);
  85. }
  86. // 开奖失败
  87. public function failure()
  88. {
  89. $id = request()->input('id');
  90. if (!$id) {
  91. return $this->error(HttpStatus::VALIDATION_FAILED, '参数错误');
  92. }
  93. $ret = IssueService::lotteryDrawFail($id);
  94. if ($ret['code'] == IssueService::NOT) {
  95. return $this->error($ret['code'], $ret['msg']);
  96. }
  97. return $this->success([], $ret['msg']);
  98. }
  99. /**
  100. * @description: 开始
  101. * @return {*}
  102. */
  103. public function betting()
  104. {
  105. $id = request()->input('id');
  106. if (!$id) {
  107. return $this->error(HttpStatus::VALIDATION_FAILED, '参数错误');
  108. }
  109. $ret = IssueService::betting($id);
  110. if ($ret['code'] == IssueService::NOT) {
  111. return $this->error($ret['code'], $ret['msg']);
  112. }
  113. return $this->success([], $ret['msg']);
  114. }
  115. /**
  116. * @description: 关闭
  117. * @return {*}
  118. */
  119. public function close()
  120. {
  121. $id = request()->input('id');
  122. if (!$id) {
  123. return $this->error(HttpStatus::VALIDATION_FAILED, '参数错误');
  124. }
  125. $ret = IssueService::closeBetting($id);
  126. if ($ret['code'] == IssueService::NOT) {
  127. return $this->error($ret['code'], $ret['msg']);
  128. }
  129. return $this->success([], $ret['msg']);
  130. }
  131. /**
  132. * @description: 开奖
  133. * @return {*}
  134. */
  135. public function lotteryDraw()
  136. {
  137. $id = request()->input('id');
  138. $winning_numbers = request()->input('winning_numbers');
  139. if (!$id) {
  140. return $this->error(HttpStatus::CUSTOM_ERROR, '参数错误');
  141. }
  142. if (empty($winning_numbers)) {
  143. $url = "https://ydpc28.co/api/pc28/list";
  144. $result = file_get_contents($url);
  145. $result = json_decode($result, true);
  146. if ($result['errorCode'] != 0) {
  147. return $this->error(HttpStatus::CUSTOM_ERROR, '参数错误');
  148. }
  149. $issue = IssueService::findOne(['id' => $id]);
  150. foreach ($result['data']['list'] as $item) {
  151. if ($item['lotNumber'] == $issue->issue_no) {
  152. $array = array_map('intval', str_split($item['openCode']));
  153. $winning_numbers = implode(',', $array);
  154. break;
  155. }
  156. }
  157. if (empty($winning_numbers)) {
  158. return $this->error(HttpStatus::CUSTOM_ERROR, '未查询到开奖信息,请手动开奖');
  159. }
  160. }
  161. if (explode(',', $winning_numbers) < 3) {
  162. return $this->error(HttpStatus::CUSTOM_ERROR, '开奖号码格式错误');
  163. }
  164. $winArr = array_map('intval', explode(',', $winning_numbers));
  165. $combo = IssueService::getCombo($winArr);
  166. $ret = IssueService::lotteryDraw($id, $winning_numbers, $combo, "");
  167. if ($ret['code'] == BaseService::NOT) {
  168. return $this->error($ret['code'], isset($ret['error']) ?? $ret['msg']);
  169. }
  170. return $this->success([], $ret['msg']);
  171. }
  172. /**
  173. * @description: 删除
  174. */
  175. public function destroy()
  176. {
  177. return $this->error(HttpStatus::CUSTOM_ERROR, '禁止删除');
  178. $id = request()->post('id');
  179. // 示例:通过 ID 删除
  180. $info = IssueService::findOne(['id' => $id]);
  181. if (!$info) {
  182. return $this->error(0, '期数不存在');
  183. }
  184. $info->delete();
  185. return $this->success([], '删除成功');
  186. }
  187. }