Issue.php 9.9 KB

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