Issue.php 7.4 KB

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