NewPc.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. }
  33. return $this->success($data);
  34. }
  35. /**
  36. * @api {get} /newPc/history 天机
  37. * @apiGroup newPc
  38. * @apiVersion 1.0.0
  39. *
  40. * @apiParam {int} [date] 日期 默认0
  41. * - 前1天 则date=1 前2天则date=2
  42. *
  43. * @apiSuccess {int} code
  44. * @apiSuccess {int} timestamp
  45. * @apiSuccess {String} msg
  46. * @apiSuccess {Object[]} data
  47. * @apiSuccess {String} data.date
  48. * @apiSuccess {int} data.total 总数
  49. * @apiSuccess {int} data.big 大
  50. * @apiSuccess {int} data.small 小
  51. * @apiSuccess {int} data.odd 单
  52. * @apiSuccess {int} data.even 双
  53. * @apiSuccess {int} data.big_odd 大单
  54. * @apiSuccess {int} data.big_even 大双
  55. * @apiSuccess {int} data.small_odd 小单
  56. * @apiSuccess {int} data.small_even 小双
  57. * @apiSuccess {int} data.max 极大
  58. * @apiSuccess {int} data.min 极小
  59. * @apiSuccess {int} data.pair 对子
  60. * @apiSuccess {int} data.sequence 顺子
  61. * @apiSuccess {int} data.leopard 豹子
  62. * @apiSuccess {int} data.num_0 00号
  63. * @apiSuccess {int} data.num_1 01号
  64. *
  65. */
  66. function history(): JsonResponse
  67. {
  68. try {
  69. request()->validate([
  70. 'date' => ['required', 'integer', 'min:0', 'max:30']
  71. ]);
  72. $date = request()->input('date');
  73. $date = Carbon::now()->subDays($date)->toDateString();
  74. $list = PcCaoHistory::where('date', $date)->get()->toArray();
  75. if (count($list) > 0) {
  76. $list = $list[0];
  77. } else {
  78. $list = null;
  79. }
  80. } catch (ValidationException $e) {
  81. return $this->error($e->validator->errors()->first());
  82. } catch (Exception $e) {
  83. return $this->error($e->getMessage());
  84. }
  85. return $this->success($list);
  86. }
  87. /**
  88. * @api {get} /newPc/prediction 预测
  89. * @apiGroup newPc
  90. * @apiVersion 1.0.0
  91. *
  92. * @apiSuccess {int} code
  93. * @apiSuccess {int} timestamp
  94. * @apiSuccess {String} msg
  95. * @apiSuccess {Object} data
  96. *
  97. * @apiParam {int} [page=1]
  98. * @apiParam {int} [limit=10]
  99. *
  100. * @apiSuccess {int} code
  101. * @apiSuccess {int} timestamp
  102. * @apiSuccess {String} msg
  103. * @apiSuccess {Object[]} data
  104. * @apiSuccess {int} data.id
  105. * @apiSuccess {String} data.issue_no 期号
  106. * @apiSuccess {int} data.size 预测大小:0小,1大
  107. * @apiSuccess {int} data.odd_or_even 预测单双:0单,1双
  108. * @apiSuccess {int} data.is_valid 结果:0错误,1正确
  109. * @apiSuccess {int[]} data.winning_numbers 开奖结果
  110. */
  111. function prediction(): JsonResponse
  112. {
  113. try {
  114. request()->validate([
  115. 'page' => ['nullable', 'integer', 'min:1'],
  116. 'limit' => ['nullable', 'integer', 'min:1']
  117. ]);
  118. $page = request()->input('page', 1);
  119. $limit = request()->input('limit', 10);
  120. $list = PcPrediction::forPage($page, $limit)
  121. ->orderByDesc('issue_no')
  122. ->get();
  123. foreach ($list as &$item) {
  124. $item['day'] = date("m-d H:i", strtotime($item['updated_at']));
  125. }
  126. } catch (ValidationException $e) {
  127. return $this->error($e->validator->errors()->first());
  128. } catch (Exception $e) {
  129. return $this->error($e->getMessage());
  130. }
  131. return $this->success($list);
  132. }
  133. }