NewPc.php 11 KB

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