Issue.php 7.6 KB

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