Bet.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. namespace App\Http\Controllers\admin;
  3. use App\Constants\HttpStatus;
  4. use App\Http\Controllers\Controller;
  5. use App\Services\BetService;
  6. use Illuminate\Support\Facades\DB;
  7. use Illuminate\Validation\ValidationException;
  8. use Exception;
  9. class Bet extends Controller
  10. {
  11. /**
  12. * @description: 分页数据
  13. * @return {*}
  14. *
  15. * @apiParam {String} [start_time] 开始时间
  16. * - 格式:`yyyy-mm-dd`
  17. * @apiParam {String} [end_time] 截止时间
  18. * - 格式:`yyyy-mm-dd`
  19. */
  20. function index()
  21. {
  22. try {
  23. $params = request()->validate([
  24. 'page' => ['nullable', 'integer', 'min:1'],
  25. 'limit' => ['nullable', 'integer', 'min:1'],
  26. 'member_id' => ['nullable', 'string'],
  27. 'keywords' => ['nullable', 'string', 'min:1'],
  28. 'issue_no' => ['nullable', 'string'],
  29. 'id' => ['nullable', 'string'],
  30. 'status' => ['nullable', 'integer', 'in:1,2'],
  31. 'username' => ['nullable', 'string', 'min:1'],
  32. 'start_time' => ['nullable', 'date', 'date_format:Y-m-d', 'required_with:end_time'],
  33. 'end_time' => ['nullable', 'date', 'date_format:Y-m-d', 'required_with:start_time'],
  34. 'is_winner'=>['nullable','integer','in:0,1'],
  35. ]);
  36. $result = BetService::paginate($params);
  37. } catch (ValidationException $e) {
  38. return $this->error(HttpStatus::VALIDATION_FAILED, $e->validator->errors()->first());
  39. } catch (Exception $e) {
  40. return $this->error(intval($e->getCode()));
  41. }
  42. return $this->success($result);
  43. }
  44. // 模拟下注
  45. public function fake()
  46. {
  47. $num = rand(1,5);
  48. for($i = 0;$i< $num;$i++){
  49. BetService::fakeBet();
  50. }
  51. return $this->success();
  52. }
  53. // /**
  54. // * @description: 修改|新增
  55. // * @return {*}
  56. // */
  57. // public function store()
  58. // {
  59. // // try {
  60. // $params = request()->all();
  61. // $validator = [
  62. // 'issue_no' => 'required|string|max:50|alpha_dash|unique:issues,issue_no',
  63. // 'winning_numbers' => 'nullable|string|max:100',
  64. // 'status' => 'nullable|string',
  65. // ];
  66. // request()->validate($validator);
  67. // $ret = BetService::submit($params);
  68. // if ($ret['code'] == BetService::NOT) {
  69. // return $this->error($ret['code'], $ret['msg']);
  70. // }
  71. // // } catch (ValidationException $e) {
  72. // // return $this->error(HttpStatus::VALIDATION_FAILED, '', $e->errors());
  73. // // } catch (Exception $e) {
  74. // // return $this->error(intval($e->getCode()));
  75. // // }
  76. // return $this->success([], $ret['msg']);
  77. // }
  78. // /**
  79. // * @description: 开始
  80. // * @return {*}
  81. // */
  82. // public function betting()
  83. // {
  84. // $id = request()->input('id');
  85. // if (!$id) {
  86. // return $this->error(HttpStatus::VALIDATION_FAILED, '参数错误');
  87. // }
  88. // $ret = BetService::betting($id);
  89. // if ($ret['code'] == BetService::NOT) {
  90. // return $this->error($ret['code'], $ret['msg']);
  91. // }
  92. // return $this->success([], $ret['msg']);
  93. // }
  94. // /**
  95. // * @description: 关闭
  96. // * @return {*}
  97. // */
  98. // public function close()
  99. // {
  100. // $id = request()->input('id');
  101. // if (!$id) {
  102. // return $this->error(HttpStatus::VALIDATION_FAILED, '参数错误');
  103. // }
  104. // $ret = BetService::closeBetting($id);
  105. // if ($ret['code'] == BetService::NOT) {
  106. // return $this->error($ret['code'], $ret['msg']);
  107. // }
  108. // return $this->success([], $ret['msg']);
  109. // }
  110. // /**
  111. // * @description: 开奖
  112. // * @return {*}
  113. // */
  114. // public function lotteryDraw()
  115. // {
  116. // $id = request()->input('id');
  117. // $winning_numbers = request()->input('winning_numbers');
  118. // $image = request()->input('image');
  119. // $combo = request()->input('combo');
  120. // if (!$id) {
  121. // return $this->error(HttpStatus::VALIDATION_FAILED, '参数错误');
  122. // }
  123. // if (!$winning_numbers) {
  124. // return $this->error(HttpStatus::VALIDATION_FAILED, '参数错误');
  125. // }
  126. // if(explode(',', $winning_numbers) < 3){
  127. // return $this->error(HttpStatus::VALIDATION_FAILED, '开奖号码格式错误');
  128. // }
  129. // $ret = BetService::lotteryDraw($id,$winning_numbers,$combo,$image);
  130. // if ($ret['code'] == BetService::NOT) {
  131. // return $this->error($ret['code'], $ret['msg']);
  132. // }
  133. // return $this->success([], $ret['msg']);
  134. // }
  135. // /**
  136. // * @description: 删除
  137. // */
  138. // public function destroy()
  139. // {
  140. // $id = request()->post('id');
  141. // // 示例:通过 ID 删除
  142. // $Bet= IssueService::findOne(['id' => $id]);
  143. // if (!$info) {
  144. // return $this->error(0, '期数不存在');
  145. // }
  146. // $info->delete();
  147. // return $this->success([], '删除成功');
  148. // }
  149. }