Issue.php 8.1 KB

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