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