Issue.php 10 KB

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