Issue.php 6.6 KB

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