Issue.php 9.5 KB

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