Bet.php 4.9 KB

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