Sport.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Constants\HttpStatus;
  4. use App\Http\Controllers\Controller;
  5. use App\Models\Sport as SportModel;
  6. use App\Services\FixtureService;
  7. use Illuminate\Http\JsonResponse;
  8. use Exception;
  9. use Illuminate\Validation\ValidationException;
  10. class Sport extends Controller
  11. {
  12. public function index(): JsonResponse
  13. {
  14. $date = request()->input('date', date('Y-m-d'));
  15. $start = strtotime($date);
  16. $end = strtotime("+1 day", $start);
  17. $list = SportModel::where("game_time", ">=", $start)
  18. ->where("game_time", "<", $end)
  19. ->get()->makeHidden(['id']);
  20. return $this->success(['list' => $list]);
  21. }
  22. public function odds(): JsonResponse
  23. {
  24. try {
  25. request()->validate([
  26. 'data_id' => ['required', 'string', 'min:1'],
  27. ]);
  28. $dataId = request()->input('data_id');
  29. $res = FixtureService::odds($dataId);
  30. } catch (ValidationException $e) {
  31. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  32. } catch (Exception $e) {
  33. return $this->error($e->getCode());
  34. }
  35. return $this->success($res);
  36. }
  37. public function oddsLive(): JsonResponse
  38. {
  39. try {
  40. request()->validate([
  41. 'data_id' => ['required', 'string', 'min:1'],
  42. ]);
  43. $dataId = request()->input('data_id');
  44. $res = FixtureService::oddsLive($dataId);
  45. } catch (ValidationException $e) {
  46. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  47. } catch (Exception $e) {
  48. return $this->error($e->getCode());
  49. }
  50. return $this->success($res);
  51. }
  52. }