Issue.php 10 KB

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