| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- <?php
- namespace App\Http\Controllers\api;
- use App\Models\PcCaoHistory;
- use App\Models\PcIssue;
- use App\Models\PcPrediction;
- use App\Services\IssueService;
- use Carbon\Carbon;
- use Illuminate\Validation\ValidationException;
- use Exception;
- use Illuminate\Http\JsonResponse;
- class NewPc extends BaseController
- {
- /**
- * @api {get} /newPc/yuanTou 源头
- * @apiGroup newPc
- * @apiVersion 1.0.0
- * @apiSuccess {int} code
- * @apiSuccess {int} timestamp
- * @apiSuccess {String} msg
- * @apiSuccess {Object[]} data
- *
- */
- function yuanTou(): JsonResponse
- {
- $page = request()->input('page', 1);
- $limit = request()->input('limit', 20);
- $data = PcIssue::where('status', PcIssue::STATUS_DRAW)
- ->forPage($page, $limit)
- ->orderByDesc('issue_no')
- ->get();
- foreach ($data as &$item) {
- $item['keno'] = json_decode($item['keno'], true);
- }
- return $this->success($data);
- }
- /**
- * @api {get} /newPc/history 天机
- * @apiGroup newPc
- * @apiVersion 1.0.0
- *
- * @apiParam {int} [date] 日期 默认0
- * - 前1天 则date=1 前2天则date=2
- *
- * @apiSuccess {int} code
- * @apiSuccess {int} timestamp
- * @apiSuccess {String} msg
- * @apiSuccess {Object[]} data
- * @apiSuccess {String} data.date
- * @apiSuccess {int} data.total 总数
- * @apiSuccess {int} data.big 大
- * @apiSuccess {int} data.small 小
- * @apiSuccess {int} data.odd 单
- * @apiSuccess {int} data.even 双
- * @apiSuccess {int} data.big_odd 大单
- * @apiSuccess {int} data.big_even 大双
- * @apiSuccess {int} data.small_odd 小单
- * @apiSuccess {int} data.small_even 小双
- * @apiSuccess {int} data.max 极大
- * @apiSuccess {int} data.min 极小
- * @apiSuccess {int} data.pair 对子
- * @apiSuccess {int} data.sequence 顺子
- * @apiSuccess {int} data.leopard 豹子
- * @apiSuccess {int} data.num_0 00号
- * @apiSuccess {int} data.num_1 01号
- *
- */
- function history(): JsonResponse
- {
- try {
- request()->validate([
- 'date' => ['required', 'integer', 'min:0', 'max:30']
- ]);
- $date = request()->input('date');
- $date = Carbon::now()->subDays($date)->toDateString();
- $list = PcCaoHistory::where('date', $date)->get()->toArray();
- if (count($list) > 0) {
- $list = $list[0];
- } else {
- $list = null;
- }
- } catch (ValidationException $e) {
- return $this->error($e->validator->errors()->first());
- } catch (Exception $e) {
- return $this->error($e->getMessage());
- }
- return $this->success($list);
- }
- /**
- * @api {get} /newPc/prediction 预测
- * @apiGroup newPc
- * @apiVersion 1.0.0
- *
- * @apiSuccess {int} code
- * @apiSuccess {int} timestamp
- * @apiSuccess {String} msg
- * @apiSuccess {Object} data
- *
- * @apiParam {int} [page=1]
- * @apiParam {int} [limit=10]
- *
- * @apiSuccess {int} code
- * @apiSuccess {int} timestamp
- * @apiSuccess {String} msg
- * @apiSuccess {Object[]} data
- * @apiSuccess {int} data.id
- * @apiSuccess {String} data.issue_no 期号
- * @apiSuccess {int} data.size 预测大小:0小,1大
- * @apiSuccess {int} data.odd_or_even 预测单双:0单,1双
- * @apiSuccess {int} data.is_valid 结果:0错误,1正确
- * @apiSuccess {int[]} data.winning_numbers 开奖结果
- */
- function prediction(): JsonResponse
- {
- try {
- request()->validate([
- 'page' => ['nullable', 'integer', 'min:1'],
- 'limit' => ['nullable', 'integer', 'min:1']
- ]);
- $page = request()->input('page', 1);
- $limit = request()->input('limit', 10);
- $list = PcPrediction::forPage($page, $limit)
- ->orderByDesc('issue_no')
- ->get();
- foreach ($list as &$item) {
- $item['day'] = date("m-d H:i", strtotime($item['updated_at']));
- }
- } catch (ValidationException $e) {
- return $this->error($e->validator->errors()->first());
- } catch (Exception $e) {
- return $this->error($e->getMessage());
- }
- return $this->success($list);
- }
- /**
- * @api {get} /newPc/countdown 倒计时
- * @apiGroup newPc
- * @apiVersion 1.0.0
- *
- * @apiSuccess {int} code
- * @apiSuccess {int} timestamp
- * @apiSuccess {String} msg
- * @apiSuccess {Object} data
- * @apiSuccess {String} data.issue_no 期号
- * @apiSuccess {int} data.current_time 当前时间
- * @apiSuccess {int} data.end_time 结束时间
- * @apiSuccess {Object} data.winnings 开奖结果
- *
- */
- public function countdown(): JsonResponse
- {
- //获取最新一期已开奖的数据
- $data2 = PcIssue::where('status', PcIssue::STATUS_DRAW)->orderByDesc('issue_no')->first();
- $issue_no2 = $data2->issue_no + 1;
- $issue_no2 .= '';
- $data1 = PcIssue::where('issue_no', $issue_no2)->first();
- $end_time = $data1 ? strtotime($data1->end_time) : (bcadd(strtotime($data2->end_time), 210, 0));
- $winnings = explode(',', $data2->winning_numbers);
- $winnings = array_map('intval', $winnings);
- $award = IssueService::award($winnings);
- $arr['sum'] = array_sum($winnings);
- $arr['a'] = $winnings[0];
- $arr['b'] = $winnings[1];
- $arr['c'] = $winnings[2];
- $arr['size'] = in_array('大', $award) ? '大' : "小";
- $arr['odd_or_even'] = in_array('单', $award) ? '单' : "双";
- $arr['issue_no'] = $data2->issue_no;
- $data = [
- 'issue_no' => $issue_no2,
- 'current_time' => time(),
- 'end_time' => $end_time,
- // 'winnings' => $arr,
- ];
- if ($data['end_time'] < $data['current_time']) {
- $data['end_time'] += 210;
- }
- $data['aa'] = $data['end_time'] - $data['current_time'];
- $data['winnings'] = $arr;
- return $this->success($data);
- }
- }
|