NewPc.php 11 KB

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