Issue.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. $issue_no2 .= '';
  89. $data1 = \App\Models\Issue::where('issue_no', $issue_no2)->first();
  90. $data1 = null;
  91. $end_time = $data1 ? strtotime($data1->end_time) : (bcadd(strtotime($data2->end_time), 210, 0));
  92. $winnings = explode(',', $data2->winning_numbers);
  93. $winnings = array_map('intval', $winnings);
  94. $award = IssueService::award($winnings);
  95. $arr['sum'] = array_sum($winnings);
  96. $arr['a'] = $winnings[0];
  97. $arr['b'] = $winnings[1];
  98. $arr['c'] = $winnings[2];
  99. $arr['size'] = in_array('大', $award) ? '大' : "小";
  100. $arr['odd_or_even'] = in_array('单', $award) ? '单' : "双";
  101. $arr['issue_no'] = $data2->issue_no;
  102. $data = [
  103. 'issue_no' => $issue_no2,
  104. 'current_time' => time(),
  105. 'end_time' => $end_time,
  106. // 'winnings' => $arr,
  107. ];
  108. if ($data['end_time'] < $data['current_time']) {
  109. $data['end_time'] += 210;
  110. }
  111. $data['aa'] = $data['end_time'] - $data['current_time'];
  112. $data['winnings'] = $arr;
  113. return $this->success($data);
  114. }
  115. /**
  116. * @api {get} /issue 结果,走势
  117. * @apiGroup Issue
  118. * @apiVersion 1.0.0
  119. *
  120. * @apiParam {int} [page=1]
  121. * @apiParam {int} [limit=10]
  122. *
  123. * @apiSuccess {int} code
  124. * @apiSuccess {int} timestamp
  125. * @apiSuccess {String} msg
  126. * @apiSuccess {Object[]} data
  127. * @apiSuccess {int} data.id
  128. * @apiSuccess {String} data.issue_no 期号
  129. * @apiSuccess {String} data.start_time 开始时间
  130. * @apiSuccess {String} data.end_time 结束时间
  131. * @apiSuccess {String[]} data.award 开奖结果
  132. * @apiSuccess {String[]} data.winning_array 开奖结果
  133. * @apiSuccess {int} data.end_timestamp 结束时间 时间戳
  134. *
  135. */
  136. public function index()
  137. {
  138. try {
  139. $page = request()->input('page', 1);
  140. $limit = request()->input('limit', 10);
  141. $params = [
  142. 'page' => $page,
  143. 'limit' => $limit
  144. // 'status'=>3
  145. ];
  146. $res = IssueService::paginate($params);
  147. } catch (ValidationException $e) {
  148. return $this->error($e->validator->errors()->first());
  149. } catch (Exception $e) {
  150. return $this->error($e->getMessage());
  151. }
  152. return $this->success($res);
  153. }
  154. /**
  155. * @api {get} /issue/cao 统计
  156. * @apiGroup Issue
  157. * @apiVersion 1.0.0
  158. *
  159. * @apiSuccess {int} code
  160. * @apiSuccess {int} timestamp
  161. * @apiSuccess {String} msg
  162. * @apiSuccess {Object} data
  163. * @apiSuccess {int} data.total 总期数
  164. * @apiSuccess {Object[]} data.list 列表
  165. *
  166. */
  167. public function cao()
  168. {
  169. $type = [1, 2, 3, 4];
  170. $list = [];
  171. $list[] = Cao::whereIn('id', $type)->get();
  172. $type = [5, 6, 7, 8];
  173. $list[] = Cao::whereIn('id', $type)->get();
  174. $type = [9, 10];
  175. $list[] = Cao::whereIn('id', $type)->get();
  176. $list[] = [
  177. ['field' => '2.8回本', 'val' => 0],
  178. ['field' => '3.2回本', 'val' => 0],
  179. ];
  180. $type = [11, 12, 13];
  181. $list[] = Cao::whereIn('id', $type)->get();
  182. $list[] = Cao::where('id', '>=', 14)
  183. ->where('id', '<=', 41)
  184. ->get();
  185. $list[] = [
  186. ['field' => '龙', 'val' => 0],
  187. ['field' => '虎', 'val' => 0],
  188. ['field' => '合', 'val' => 0],
  189. ['field' => '鸡', 'val' => 0],
  190. ['field' => '鸭', 'val' => 0],
  191. ['field' => '狗', 'val' => 0],
  192. ];
  193. $list[] = [
  194. ['field' => '中', 'val' => 0],
  195. ['field' => '边', 'val' => 0],
  196. ['field' => '大边', 'val' => 0],
  197. ['field' => '小边', 'val' => 0],
  198. ];
  199. $list[] = Cao::where('id', '>=', 42)
  200. ->where('id', '<=', 49)
  201. ->get();
  202. $list[] = [
  203. ['field' => '三军0点', 'val' => 0],
  204. ['field' => '三军1点', 'val' => 0],
  205. ['field' => '三军2点', 'val' => 0],
  206. ['field' => '三军3点', 'val' => 0],
  207. ['field' => '三军4点', 'val' => 0],
  208. ['field' => '三军5点', 'val' => 0],
  209. ['field' => '三军6点', 'val' => 0],
  210. ['field' => '三军7点', 'val' => 0],
  211. ['field' => '三军8点', 'val' => 0],
  212. ['field' => '三军9点', 'val' => 0],
  213. ];
  214. $list[] = Cao::where('id', '>=', 50)
  215. ->where('id', '<=', 63)
  216. ->get();
  217. $list[] = Cao::where('id', '>=', 64)
  218. ->where('id', '<=', 77)
  219. ->get();
  220. $list[] = Cao::where('id', '>=', 78)
  221. ->where('id', '<=', 91)
  222. ->get();
  223. $count = \App\Models\Issue::count();
  224. $data = [
  225. 'total' => $count,
  226. 'list' => $list
  227. ];
  228. return $this->success($data);
  229. }
  230. }