Issue.php 13 KB

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