ThirdGameOrder.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace App\Http\Controllers\admin;
  3. use App\Constants\HttpStatus;
  4. use App\Http\Controllers\Controller;
  5. use App\Services\ThirdGameBalanceService;
  6. use Exception;
  7. use Illuminate\Http\JsonResponse;
  8. use Illuminate\Validation\ValidationException;
  9. class ThirdGameOrder extends Controller
  10. {
  11. public function index(ThirdGameBalanceService $service): JsonResponse
  12. {
  13. try {
  14. $params = request()->validate([
  15. 'start_time' => ['required', 'date_format:Y-m-d H:i:s'],
  16. 'end_time' => ['required', 'date_format:Y-m-d H:i:s', 'after_or_equal:start_time'],
  17. 'page' => ['nullable', 'integer', 'min:1'],
  18. 'limit' => ['nullable', 'integer', 'min:1', 'max:2000'],
  19. ]);
  20. $result = $service->historyOrders(
  21. (string) $params['start_time'],
  22. (string) $params['end_time'],
  23. (int) ($params['page'] ?? 1),
  24. (int) ($params['limit'] ?? 200)
  25. );
  26. if (!$result['ok']) {
  27. throw new Exception($result['msg'], HttpStatus::CUSTOM_ERROR);
  28. }
  29. unset($result['ok']);
  30. return $this->success($result);
  31. } catch (ValidationException $e) {
  32. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  33. } catch (Exception $e) {
  34. return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage());
  35. }
  36. }
  37. }