Issue.php 7.4 KB

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