Issue.php 7.0 KB

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