Issue.php 9.3 KB

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