Issue.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <?php
  2. namespace App\Http\Controllers\api;
  3. use App\Models\Cao;
  4. use App\Models\Prediction;
  5. use App\Services\IssueService;
  6. use Illuminate\Validation\ValidationException;
  7. use Exception;
  8. class Issue extends BaseController
  9. {
  10. /**
  11. * @api {get} /issue/prediction 预测
  12. * @apiGroup Issue
  13. * @apiVersion 1.0.0
  14. *
  15. * @apiSuccess {int} code
  16. * @apiSuccess {int} timestamp
  17. * @apiSuccess {String} msg
  18. * @apiSuccess {Object} data
  19. *
  20. * @apiParam {int} [page=1]
  21. * @apiParam {int} [limit=10]
  22. */
  23. function prediction()
  24. {
  25. try {
  26. request()->validate([
  27. 'page' => ['nullable', 'integer', 'min:1'],
  28. 'limit' => ['nullable', 'integer', 'min:1']
  29. ]);
  30. $page = request()->input('page', 1);
  31. $limit = request()->input('limit', 10);
  32. $list = Prediction::forPage($page, $limit)->get();
  33. } catch (ValidationException $e) {
  34. return $this->error($e->validator->errors()->first());
  35. } catch (Exception $e) {
  36. return $this->error($e->getMessage());
  37. }
  38. return $this->success($list);
  39. }
  40. /**
  41. * @api {get} /issue/countdown 倒计时
  42. * @apiGroup Issue
  43. * @apiVersion 1.0.0
  44. *
  45. * @apiSuccess {int} code
  46. * @apiSuccess {int} timestamp
  47. * @apiSuccess {String} msg
  48. * @apiSuccess {Object} data
  49. * @apiSuccess {String} data.issue_no 期号
  50. * @apiSuccess {int} data.current_time 当前时间
  51. * @apiSuccess {int} data.end_time 结束时间
  52. * @apiSuccess {Object} data.winnings 开奖结果
  53. *
  54. */
  55. public function countdown()
  56. {
  57. $data1 = \App\Models\Issue::where('status', 1)->orderByDesc('issue_no')->first();
  58. $data2 = \App\Models\Issue::where('status', 3)->orderByDesc('issue_no')->first();
  59. $winnings = explode(',', $data2->winning_numbers);
  60. $winnings = array_map('intval', $winnings);
  61. $award = IssueService::award($winnings);
  62. $arr['sum'] = array_sum($winnings);
  63. $arr['a'] = $winnings[0];
  64. $arr['b'] = $winnings[1];
  65. $arr['c'] = $winnings[2];
  66. $arr['size'] = in_array('大', $award) ? '大' : "小";
  67. $arr['odd_or_even'] = in_array('单', $award) ? '单' : "双";
  68. $arr['issue_no'] = $data2->issue_no;
  69. $data = [
  70. 'issue_no' => $data1->issue_no,
  71. 'current_time' => time(),
  72. 'end_time' => strtotime($data1->end_time),
  73. 'winnings' => $arr,
  74. ];
  75. return $this->success($data);
  76. }
  77. /**
  78. * @api {get} /issue 结果,走势
  79. * @apiGroup Issue
  80. * @apiVersion 1.0.0
  81. *
  82. * @apiParam {int} [page=1]
  83. * @apiParam {int} [limit=10]
  84. *
  85. * @apiSuccess {int} code
  86. * @apiSuccess {int} timestamp
  87. * @apiSuccess {String} msg
  88. * @apiSuccess {Object[]} data
  89. * @apiSuccess {int} data.id
  90. * @apiSuccess {String} data.issue_no 期号
  91. * @apiSuccess {String} data.start_time 开始时间
  92. * @apiSuccess {String} data.end_time 结束时间
  93. * @apiSuccess {String[]} data.award 开奖结果
  94. * @apiSuccess {String[]} data.winning_array 开奖结果
  95. * @apiSuccess {int} data.end_timestamp 结束时间 时间戳
  96. *
  97. */
  98. public function index()
  99. {
  100. try {
  101. $page = request()->input('page', 1);
  102. $limit = request()->input('limit', 10);
  103. $params = [
  104. 'page' => $page,
  105. 'limit' => $limit
  106. // 'status'=>3
  107. ];
  108. $res = IssueService::paginate($params);
  109. } catch (ValidationException $e) {
  110. return $this->error($e->validator->errors()->first());
  111. } catch (Exception $e) {
  112. return $this->error($e->getMessage());
  113. }
  114. return $this->success($res);
  115. }
  116. /**
  117. * @api {get} /issue/cao 统计
  118. * @apiGroup Issue
  119. * @apiVersion 1.0.0
  120. *
  121. * @apiSuccess {int} code
  122. * @apiSuccess {int} timestamp
  123. * @apiSuccess {String} msg
  124. * @apiSuccess {Object[]} data
  125. *
  126. */
  127. public function cao()
  128. {
  129. $type = [1, 2, 3, 4];
  130. $list = [];
  131. $list[] = Cao::whereIn('id', $type)->get();
  132. $type = [5, 6, 7, 8];
  133. $list[] = Cao::whereIn('id', $type)->get();
  134. $type = [9, 10];
  135. $list[] = Cao::whereIn('id', $type)->get();
  136. $list[] = [
  137. ['field' => '2.8回本', 'val' => 0],
  138. ['field' => '3.2回本', 'val' => 0],
  139. ];
  140. $type = [11, 12, 13];
  141. $list[] = Cao::whereIn('id', $type)->get();
  142. $list[] = Cao::where('id', '>=', 14)
  143. ->where('id', '<=', 41)
  144. ->get();
  145. $list[] = [
  146. ['field' => '龙', 'val' => 0],
  147. ['field' => '虎', 'val' => 0],
  148. ['field' => '合', 'val' => 0],
  149. ['field' => '鸡', 'val' => 0],
  150. ['field' => '鸭', 'val' => 0],
  151. ['field' => '狗', 'val' => 0],
  152. ];
  153. $list[] = [
  154. ['field' => '中', 'val' => 0],
  155. ['field' => '边', 'val' => 0],
  156. ['field' => '大边', 'val' => 0],
  157. ['field' => '小边', 'val' => 0],
  158. ];
  159. $list[] = Cao::where('id', '>=', 42)
  160. ->where('id', '<=', 49)
  161. ->get();
  162. $list[] = [
  163. ['field' => '三军0点', 'val' => 0],
  164. ['field' => '三军1点', 'val' => 0],
  165. ['field' => '三军2点', 'val' => 0],
  166. ['field' => '三军3点', 'val' => 0],
  167. ['field' => '三军4点', 'val' => 0],
  168. ['field' => '三军5点', 'val' => 0],
  169. ['field' => '三军6点', 'val' => 0],
  170. ['field' => '三军7点', 'val' => 0],
  171. ['field' => '三军8点', 'val' => 0],
  172. ['field' => '三军9点', 'val' => 0],
  173. ];
  174. $list[] = Cao::where('id', '>=', 50)
  175. ->where('id', '<=', 63)
  176. ->get();
  177. $list[] = Cao::where('id', '>=', 64)
  178. ->where('id', '<=', 77)
  179. ->get();
  180. $list[] = Cao::where('id', '>=', 78)
  181. ->where('id', '<=', 91)
  182. ->get();
  183. return $this->success($list);
  184. }
  185. }