| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- namespace App\Http\Controllers\admin;
- use App\Constants\HttpStatus;
- use App\Http\Controllers\Controller;
- use App\Services\PcIssueService;
- use Illuminate\Validation\ValidationException;
- use Exception;
- use App\Models\PcIssue as PcIssueModel;
- class PcIssue extends Controller
- {
- /**
- * @api {get} /admin/pcIssue 列表
- * @apiGroup 极速28
- *
- * @apiUse result
- * @apiUse header
- * @apiVersion 1.0.0
- *
- * @apiParam {int} [page=1]
- * @apiParam {int} [limit=10]
- * @apiParam {string} [issue_no] 期号
- */
- public function index()
- {
- try {
- $search = request()->validate([
- 'page' => ['nullable', 'integer', 'min:1'],
- 'limit' => ['nullable', 'integer', 'min:1'],
- 'issue_no' => ['nullable', 'string'],
- ]);
- $page = request()->input('page', 1);
- $limit = request()->input('limit', 15);
- $result['total'] = PcIssueModel::where(PcIssueModel::getWhere($search))->count();
- $result['data'] = PcIssueModel::where(PcIssueModel::getWhere($search))
- ->orderByDesc('id')->forPage($page, $limit)->get();
- } catch (ValidationException $e) {
- return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
- } catch (Exception $e) {
- return $this->error(intval($e->getCode()));
- }
- return $this->success($result);
- }
- /**
- * @api {post} /admin/pcIssue/preDraw 预开奖
- * @apiGroup 极速28
- *
- * @apiUse result
- * @apiUse header
- * @apiVersion 1.0.0
- *
- * @apiParam {string} issue_no 期号
- * @apiParam {int} he 预开奖号码
- * - 开奖号码取值范围:0-27
- *
- */
- public function preDraw()
- {
- try {
- request()->validate([
- 'issue_no' => ['required', 'string'],
- 'he' => ['required', 'integer', 'min:0', 'max:27'],
- ]);
- $issueNo = request()->input('issue_no');
- $he = request()->input('he');
- $he = intval($he);
- $pcIssue = PcIssueModel::where('issue_no', $issueNo)->first();
- if (!$pcIssue) throw new Exception('期号错误', HttpStatus::CUSTOM_ERROR);
- if (!in_array($pcIssue->status, [PcIssueModel::STATUS_BETTING, PcIssueModel::STATUS_CLOSE])) {
- throw new Exception('预开奖失败;状态不正确', HttpStatus::CUSTOM_ERROR);
- }
- $keno = PcIssueService::getMatchingNumbers($he);
- $pcIssue->advance_keno = json_encode($keno);
- $pcIssue->advance_code = $he;
- $pcIssue->save();
- $winningNumbers = PcIssueService::getWinningNumbers($keno);
- } catch (ValidationException $e) {
- return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
- } catch (Exception $e) {
- if ($e->getCode() == HttpStatus::CUSTOM_ERROR) {
- return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage());
- }
- return $this->error(intval($e->getCode()));
- }
- return $this->success($winningNumbers);
- }
- }
|