NewPc.php 10 KB

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