NewPc.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 Carbon\Carbon;
  7. use Illuminate\Validation\ValidationException;
  8. use Exception;
  9. use Illuminate\Http\JsonResponse;
  10. class NewPc extends BaseController
  11. {
  12. /**
  13. * @api {get} /newPc/yuanTou 源头
  14. * @apiGroup newPc
  15. * @apiVersion 1.0.0
  16. * @apiSuccess {int} code
  17. * @apiSuccess {int} timestamp
  18. * @apiSuccess {String} msg
  19. * @apiSuccess {Object[]} data
  20. *
  21. */
  22. function yuanTou(): JsonResponse
  23. {
  24. $page = request()->input('page', 1);
  25. $limit = request()->input('limit', 20);
  26. $data = PcIssue::where('status', PcIssue::STATUS_DRAW)
  27. ->forPage($page, $limit)
  28. ->orderByDesc('issue_no')
  29. ->get();
  30. foreach ($data as &$item) {
  31. $item['keno'] = json_decode($item['keno'], true);
  32. sort($item['keno']);
  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. }