Issue.php 7.8 KB

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