Issue.php 10 KB

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