Issue.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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. class Issue extends BaseController
  10. {
  11. /**
  12. * @api {get} /issue/history 天机
  13. * @apiGroup Issue
  14. * @apiVersion 1.0.0
  15. *
  16. * @apiParam {String} [date] 日期 默认当天
  17. * - 格式:yyyy-mm-dd
  18. */
  19. function history()
  20. {
  21. try {
  22. request()->validate([
  23. 'date' => ['nullable', 'date', 'date_format:Y-m-d']
  24. ]);
  25. $date = request()->input('date', null);
  26. if (!$date) $date = date("Y-m-d");
  27. $list = CaoHistory::where('date', $date)->get()->toArray();
  28. if (count($list) > 0) {
  29. $list = $list[0];
  30. } else {
  31. $list = null;
  32. }
  33. } catch (ValidationException $e) {
  34. return $this->error($e->validator->errors()->first());
  35. } catch (Exception $e) {
  36. return $this->error($e->getMessage());
  37. }
  38. return $this->success($list);
  39. }
  40. /**
  41. * @api {get} /issue/prediction 预测
  42. * @apiGroup Issue
  43. * @apiVersion 1.0.0
  44. *
  45. * @apiSuccess {int} code
  46. * @apiSuccess {int} timestamp
  47. * @apiSuccess {String} msg
  48. * @apiSuccess {Object} data
  49. *
  50. * @apiParam {int} [page=1]
  51. * @apiParam {int} [limit=10]
  52. *
  53. * @apiSuccess {int} code
  54. * @apiSuccess {int} timestamp
  55. * @apiSuccess {String} msg
  56. * @apiSuccess {Object[]} data
  57. * @apiSuccess {int} data.id
  58. * @apiSuccess {String} data.issue_no 期号
  59. * @apiSuccess {int} data.size 预测大小:0小,1大
  60. * @apiSuccess {int} data.odd_or_even 预测单双:0单,1双
  61. * @apiSuccess {int} data.is_valid 结果:0错误,1正确
  62. * @apiSuccess {int[]} data.winning_numbers 开奖结果
  63. */
  64. function prediction()
  65. {
  66. try {
  67. request()->validate([
  68. 'page' => ['nullable', 'integer', 'min:1'],
  69. 'limit' => ['nullable', 'integer', 'min:1']
  70. ]);
  71. $page = request()->input('page', 1);
  72. $limit = request()->input('limit', 10);
  73. $list = Prediction::forPage($page, $limit)
  74. ->orderByDesc('issue_no')
  75. ->get();
  76. foreach ($list as &$item) {
  77. $item['day'] = date("m-d H:i", strtotime($item['updated_at']));
  78. }
  79. } catch (ValidationException $e) {
  80. return $this->error($e->validator->errors()->first());
  81. } catch (Exception $e) {
  82. return $this->error($e->getMessage());
  83. }
  84. return $this->success($list);
  85. }
  86. /**
  87. * @api {get} /issue/countdown 倒计时
  88. * @apiGroup Issue
  89. * @apiVersion 1.0.0
  90. *
  91. * @apiSuccess {int} code
  92. * @apiSuccess {int} timestamp
  93. * @apiSuccess {String} msg
  94. * @apiSuccess {Object} data
  95. * @apiSuccess {String} data.issue_no 期号
  96. * @apiSuccess {int} data.current_time 当前时间
  97. * @apiSuccess {int} data.end_time 结束时间
  98. * @apiSuccess {Object} data.winnings 开奖结果
  99. *
  100. */
  101. public function countdown()
  102. {
  103. $data2 = \App\Models\Issue::where('status', 3)->orderByDesc('issue_no')->first();
  104. $issue_no2 = $data2->issue_no + 1;
  105. $issue_no2 .= '';
  106. $data1 = \App\Models\Issue::where('issue_no', $issue_no2)->first();
  107. $end_time = $data1 ? strtotime($data1->end_time) : (bcadd(strtotime($data2->end_time), 210, 0));
  108. $winnings = explode(',', $data2->winning_numbers);
  109. $winnings = array_map('intval', $winnings);
  110. $award = IssueService::award($winnings);
  111. $arr['sum'] = array_sum($winnings);
  112. $arr['a'] = $winnings[0];
  113. $arr['b'] = $winnings[1];
  114. $arr['c'] = $winnings[2];
  115. $arr['size'] = in_array('大', $award) ? '大' : "小";
  116. $arr['odd_or_even'] = in_array('单', $award) ? '单' : "双";
  117. $arr['issue_no'] = $data2->issue_no;
  118. $data = [
  119. 'issue_no' => $issue_no2,
  120. 'current_time' => time(),
  121. 'end_time' => $end_time,
  122. // 'winnings' => $arr,
  123. ];
  124. if ($data['end_time'] < $data['current_time']) {
  125. $data['end_time'] += 210;
  126. }
  127. $data['aa'] = $data['end_time'] - $data['current_time'];
  128. $data['winnings'] = $arr;
  129. return $this->success($data);
  130. }
  131. /**
  132. * @api {get} /issue 结果,走势
  133. * @apiGroup Issue
  134. * @apiVersion 1.0.0
  135. *
  136. * @apiParam {int} [page=1]
  137. * @apiParam {int} [limit=10]
  138. *
  139. * @apiSuccess {int} code
  140. * @apiSuccess {int} timestamp
  141. * @apiSuccess {String} msg
  142. * @apiSuccess {Object[]} data
  143. * @apiSuccess {int} data.id
  144. * @apiSuccess {String} data.issue_no 期号
  145. * @apiSuccess {String} data.start_time 开始时间
  146. * @apiSuccess {String} data.end_time 结束时间
  147. * @apiSuccess {String[]} data.award 开奖结果
  148. * @apiSuccess {String[]} data.winning_array 开奖结果
  149. * @apiSuccess {int} data.end_timestamp 结束时间 时间戳
  150. *
  151. */
  152. public function index()
  153. {
  154. try {
  155. $page = request()->input('page', 1);
  156. $limit = request()->input('limit', 10);
  157. $params = [
  158. 'page' => $page,
  159. 'limit' => $limit
  160. // 'status'=>3
  161. ];
  162. $res = IssueService::paginate($params);
  163. foreach ($res['data'] as &$item) {
  164. $item['day'] = date("m-d H:i", strtotime($item['end_time']));
  165. }
  166. } catch (ValidationException $e) {
  167. return $this->error($e->validator->errors()->first());
  168. } catch (Exception $e) {
  169. return $this->error($e->getMessage());
  170. }
  171. return $this->success($res);
  172. }
  173. /**
  174. * @api {get} /issue/cao 统计,历史
  175. * @apiGroup Issue
  176. * @apiVersion 1.0.0
  177. *
  178. * @apiSuccess {int} code
  179. * @apiSuccess {int} timestamp
  180. * @apiSuccess {String} msg
  181. * @apiSuccess {Object} data
  182. * @apiSuccess {int} data.total 总期数
  183. * @apiSuccess {Object[]} data.list 列表
  184. *
  185. */
  186. public function cao()
  187. {
  188. $type = [1, 2, 3, 4];
  189. $list = [];
  190. $list[] = Cao::whereIn('id', $type)->get();
  191. $type = [5, 6, 7, 8];
  192. $list[] = Cao::whereIn('id', $type)->get();
  193. $type = [9, 10];
  194. $list[] = Cao::whereIn('id', $type)->get();
  195. $list[] = [
  196. ['field' => '2.8回本', 'val' => 0],
  197. ['field' => '3.2回本', 'val' => 0],
  198. ];
  199. $type = [11, 12, 13];
  200. $list[] = Cao::whereIn('id', $type)->get();
  201. $list[] = Cao::where('id', '>=', 14)
  202. ->where('id', '<=', 41)
  203. ->get();
  204. $list[] = [
  205. ['field' => '龙', 'val' => 0],
  206. ['field' => '虎', 'val' => 0],
  207. ['field' => '合', 'val' => 0],
  208. ['field' => '鸡', 'val' => 0],
  209. ['field' => '鸭', 'val' => 0],
  210. ['field' => '狗', 'val' => 0],
  211. ];
  212. $list[] = [
  213. ['field' => '中', 'val' => 0],
  214. ['field' => '边', 'val' => 0],
  215. ['field' => '大边', 'val' => 0],
  216. ['field' => '小边', 'val' => 0],
  217. ];
  218. $list[] = Cao::where('id', '>=', 42)
  219. ->where('id', '<=', 49)
  220. ->get();
  221. $list[] = [
  222. ['field' => '三军0点', 'val' => 0],
  223. ['field' => '三军1点', 'val' => 0],
  224. ['field' => '三军2点', 'val' => 0],
  225. ['field' => '三军3点', 'val' => 0],
  226. ['field' => '三军4点', 'val' => 0],
  227. ['field' => '三军5点', 'val' => 0],
  228. ['field' => '三军6点', 'val' => 0],
  229. ['field' => '三军7点', 'val' => 0],
  230. ['field' => '三军8点', 'val' => 0],
  231. ['field' => '三军9点', 'val' => 0],
  232. ];
  233. $list[] = Cao::where('id', '>=', 50)
  234. ->where('id', '<=', 63)
  235. ->get();
  236. $list[] = Cao::where('id', '>=', 64)
  237. ->where('id', '<=', 77)
  238. ->get();
  239. $list[] = Cao::where('id', '>=', 78)
  240. ->where('id', '<=', 91)
  241. ->get();
  242. $count = \App\Models\Issue::count();
  243. $data = [
  244. 'total' => $count,
  245. 'list' => $list
  246. ];
  247. return $this->success($data);
  248. }
  249. }