Bet.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. use App\Models\Bet as BetModel;
  10. class Bet extends Controller
  11. {
  12. function index()
  13. {
  14. // try {
  15. $params = request()->validate([
  16. 'page' => ['nullable', 'integer', 'min:1'],
  17. 'limit' => ['nullable', 'integer', 'min:1'],
  18. 'member_id' => ['nullable', 'string'],
  19. 'keywords' => ['nullable', 'string', 'min:1'],
  20. 'issue_no' => ['nullable', 'string'],
  21. 'id' => ['nullable', 'string'],
  22. 'status' => ['nullable', 'integer', 'in:1,2'],
  23. 'username' => ['nullable', 'string', 'min:1'],
  24. 'start_time' => ['nullable', 'date', 'date_format:Y-m-d', 'required_with:end_time'],
  25. 'end_time' => ['nullable', 'date', 'date_format:Y-m-d', 'required_with:start_time'],
  26. 'is_winner' => ['nullable', 'integer', 'in:0,1'],
  27. ]);
  28. $page = request()->input('page', 1);
  29. $limit = request()->input('limit', 10);
  30. $query = BetModel::where(BetService::getWhere($params))
  31. ->with(['user', 'issue', 'pcIssue']);
  32. if (isset($params['username']) && !empty($params['username'])) {
  33. $username = $params['username'];
  34. $query = $query->whereHas('user', function ($query) use ($username) {
  35. $query->where('username', $username);
  36. });
  37. }
  38. $count = $query->count();
  39. $query->orderBy('id', 'desc');
  40. $list = $query->forPage($page, $limit)->get();
  41. $result = ['total' => $count, 'data' => $list];
  42. foreach ($result['data'] as &$item) {
  43. $item['is_winner'] = null;
  44. $issue = $item['pc_issue'] ;
  45. $item['aaa'] = $issue;
  46. // $item['winning_array'] = $issue['winning_array'];
  47. // unset($item['issue'],$item['pc_issue']);
  48. if ($item['status'] == 2) {
  49. $item['is_winner'] = $item['profit'] > 0;
  50. }
  51. }
  52. // } catch (ValidationException $e) {
  53. // return $this->error(HttpStatus::VALIDATION_FAILED, $e->validator->errors()->first());
  54. // } catch (Exception $e) {
  55. // return $this->error(intval($e->getCode()));
  56. // }
  57. return $this->success($result);
  58. }
  59. // 模拟下注
  60. public function fake()
  61. {
  62. BetService::randomVirtualBetting(3);
  63. return 'success';
  64. }
  65. }