Issue.php 10.0 KB

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