NewPc.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <?php
  2. namespace App\Http\Controllers\api;
  3. use App\Models\PcCaoHistory;
  4. use App\Models\PcIssue;
  5. use App\Models\PcPrediction;
  6. use App\Services\IssueService;
  7. use Carbon\Carbon;
  8. use Illuminate\Validation\ValidationException;
  9. use Exception;
  10. use Illuminate\Http\JsonResponse;
  11. class NewPc extends BaseController
  12. {
  13. /**
  14. * @api {get} /newPc/yuanTou 源头
  15. * @apiGroup newPc
  16. * @apiVersion 1.0.0
  17. * @apiSuccess {int} code
  18. * @apiSuccess {int} timestamp
  19. * @apiSuccess {String} msg
  20. * @apiSuccess {Object[]} data
  21. *
  22. */
  23. function yuanTou(): JsonResponse
  24. {
  25. $page = request()->input('page', 1);
  26. $limit = request()->input('limit', 20);
  27. $data = PcIssue::where('status', PcIssue::STATUS_DRAW)
  28. ->forPage($page, $limit)
  29. ->orderByDesc('issue_no')
  30. ->get();
  31. foreach ($data as &$item) {
  32. $item['keno'] = json_decode($item['keno'], true);
  33. }
  34. return $this->success($data);
  35. }
  36. /**
  37. * @api {get} /newPc/history 天机
  38. * @apiGroup newPc
  39. * @apiVersion 1.0.0
  40. *
  41. * @apiParam {int} [date] 日期 默认0
  42. * - 前1天 则date=1 前2天则date=2
  43. *
  44. * @apiSuccess {int} code
  45. * @apiSuccess {int} timestamp
  46. * @apiSuccess {String} msg
  47. * @apiSuccess {Object[]} data
  48. * @apiSuccess {String} data.date
  49. * @apiSuccess {int} data.total 总数
  50. * @apiSuccess {int} data.big 大
  51. * @apiSuccess {int} data.small 小
  52. * @apiSuccess {int} data.odd 单
  53. * @apiSuccess {int} data.even 双
  54. * @apiSuccess {int} data.big_odd 大单
  55. * @apiSuccess {int} data.big_even 大双
  56. * @apiSuccess {int} data.small_odd 小单
  57. * @apiSuccess {int} data.small_even 小双
  58. * @apiSuccess {int} data.max 极大
  59. * @apiSuccess {int} data.min 极小
  60. * @apiSuccess {int} data.pair 对子
  61. * @apiSuccess {int} data.sequence 顺子
  62. * @apiSuccess {int} data.leopard 豹子
  63. * @apiSuccess {int} data.num_0 00号
  64. * @apiSuccess {int} data.num_1 01号
  65. *
  66. */
  67. function history(): JsonResponse
  68. {
  69. try {
  70. request()->validate([
  71. 'date' => ['required', 'integer', 'min:0', 'max:30']
  72. ]);
  73. $date = request()->input('date');
  74. $date = Carbon::now()->subDays($date)->toDateString();
  75. $list = PcCaoHistory::where('date', $date)->get()->toArray();
  76. if (count($list) > 0) {
  77. $list = $list[0];
  78. } else {
  79. $list = null;
  80. }
  81. } catch (ValidationException $e) {
  82. return $this->error($e->validator->errors()->first());
  83. } catch (Exception $e) {
  84. return $this->error($e->getMessage());
  85. }
  86. return $this->success($list);
  87. }
  88. /**
  89. * @api {get} /newPc/prediction 预测
  90. * @apiGroup newPc
  91. * @apiVersion 1.0.0
  92. *
  93. * @apiSuccess {int} code
  94. * @apiSuccess {int} timestamp
  95. * @apiSuccess {String} msg
  96. * @apiSuccess {Object} data
  97. *
  98. * @apiParam {int} [page=1]
  99. * @apiParam {int} [limit=10]
  100. *
  101. * @apiSuccess {int} code
  102. * @apiSuccess {int} timestamp
  103. * @apiSuccess {String} msg
  104. * @apiSuccess {Object[]} data
  105. * @apiSuccess {int} data.id
  106. * @apiSuccess {String} data.issue_no 期号
  107. * @apiSuccess {int} data.size 预测大小:0小,1大
  108. * @apiSuccess {int} data.odd_or_even 预测单双:0单,1双
  109. * @apiSuccess {int} data.is_valid 结果:0错误,1正确
  110. * @apiSuccess {int[]} data.winning_numbers 开奖结果
  111. */
  112. function prediction(): JsonResponse
  113. {
  114. try {
  115. request()->validate([
  116. 'page' => ['nullable', 'integer', 'min:1'],
  117. 'limit' => ['nullable', 'integer', 'min:1']
  118. ]);
  119. $page = request()->input('page', 1);
  120. $limit = request()->input('limit', 10);
  121. $list = PcPrediction::forPage($page, $limit)
  122. ->orderByDesc('issue_no')
  123. ->get();
  124. foreach ($list as &$item) {
  125. $item['day'] = date("m-d H:i", strtotime($item['updated_at']));
  126. }
  127. } catch (ValidationException $e) {
  128. return $this->error($e->validator->errors()->first());
  129. } catch (Exception $e) {
  130. return $this->error($e->getMessage());
  131. }
  132. return $this->success($list);
  133. }
  134. /**
  135. * @api {get} /newPc/countdown 倒计时
  136. * @apiGroup newPc
  137. * @apiVersion 1.0.0
  138. *
  139. * @apiSuccess {int} code
  140. * @apiSuccess {int} timestamp
  141. * @apiSuccess {String} msg
  142. * @apiSuccess {Object} data
  143. * @apiSuccess {String} data.issue_no 期号
  144. * @apiSuccess {int} data.current_time 当前时间
  145. * @apiSuccess {int} data.end_time 结束时间
  146. * @apiSuccess {Object} data.winnings 开奖结果
  147. *
  148. */
  149. public function countdown(): JsonResponse
  150. {
  151. //获取最新一期已开奖的数据
  152. $data2 = PcIssue::where('status', PcIssue::STATUS_DRAW)->orderByDesc('issue_no')->first();
  153. $issue_no2 = preg_replace('/\D/', '', $data2->issue_no);
  154. $number = (int)$issue_no2 + 1;
  155. $issue_no2 = "P" . $number;
  156. $data1 = PcIssue::where('issue_no', $issue_no2)->first();
  157. $end_time = $data1 ? strtotime($data1->end_time) : (bcadd(strtotime($data2->end_time), 210, 0));
  158. $winnings = explode(',', $data2->winning_numbers);
  159. $winnings = array_map('intval', $winnings);
  160. $award = IssueService::award($winnings);
  161. $arr['sum'] = array_sum($winnings);
  162. $arr['a'] = $winnings[0];
  163. $arr['b'] = $winnings[1];
  164. $arr['c'] = $winnings[2];
  165. $arr['size'] = in_array('大', $award) ? '大' : "小";
  166. $arr['odd_or_even'] = in_array('单', $award) ? '单' : "双";
  167. $arr['issue_no'] = $data2->issue_no;
  168. $data = [
  169. 'issue_no' => $issue_no2,
  170. 'current_time' => time(),
  171. 'end_time' => $end_time,
  172. // 'winnings' => $arr,
  173. ];
  174. if ($data['end_time'] < $data['current_time']) {
  175. $data['end_time'] += 210;
  176. }
  177. $data['aa'] = $data['end_time'] - $data['current_time'];
  178. $data['winnings'] = $arr;
  179. return $this->success($data);
  180. }
  181. }