ThirdGameOrder.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace App\Http\Controllers\admin;
  3. use App\Constants\HttpStatus;
  4. use App\Http\Controllers\Controller;
  5. use App\Services\ThirdGameOrderService;
  6. use Exception;
  7. use Illuminate\Http\JsonResponse;
  8. use Illuminate\Validation\ValidationException;
  9. class ThirdGameOrder extends Controller
  10. {
  11. public function index(ThirdGameOrderService $service): JsonResponse
  12. {
  13. try {
  14. $params = request()->validate([
  15. 'page' => ['nullable', 'integer', 'min:1'],
  16. 'limit' => ['nullable', 'integer', 'min:1', 'max:200'],
  17. 'user_id' => ['nullable', 'integer', 'min:1'],
  18. 'member_id' => ['nullable', 'string', 'max:64'],
  19. 'username' => ['nullable', 'string', 'max:128'],
  20. 'first_name' => ['nullable', 'string', 'max:128'],
  21. 'player_id' => ['nullable', 'string', 'max:32'],
  22. 'platform' => ['nullable', 'string', 'max:32'],
  23. 'game_order_id' => ['nullable', 'string', 'max:128'],
  24. 'game_type' => ['nullable', 'integer', 'in:1,2,3,4,5,6,7'],
  25. 'status' => ['nullable', 'integer', 'in:0,1,2,3'],
  26. 'start_time' => ['nullable', 'date_format:Y-m-d H:i:s', 'required_with:end_time'],
  27. 'end_time' => [
  28. 'nullable', 'date_format:Y-m-d H:i:s', 'required_with:start_time', 'after_or_equal:start_time',
  29. ],
  30. ]);
  31. return $this->success($service->paginate($params));
  32. } catch (ValidationException $e) {
  33. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  34. } catch (Exception $e) {
  35. return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage());
  36. }
  37. }
  38. public function sync(ThirdGameOrderService $service): JsonResponse
  39. {
  40. try {
  41. $params = request()->validate([
  42. 'start_time' => ['required', 'date_format:Y-m-d H:i:s'],
  43. 'end_time' => ['required', 'date_format:Y-m-d H:i:s', 'after_or_equal:start_time'],
  44. 'page' => ['nullable', 'integer', 'min:1'],
  45. 'limit' => ['nullable', 'integer', 'min:1', 'max:2000'],
  46. ]);
  47. $result = $service->sync(
  48. (string) $params['start_time'],
  49. (string) $params['end_time'],
  50. (int) ($params['page'] ?? 1),
  51. (int) ($params['limit'] ?? 2000)
  52. );
  53. if (!$result['ok']) {
  54. throw new Exception($result['msg'], HttpStatus::CUSTOM_ERROR);
  55. }
  56. unset($result['ok']);
  57. return $this->success($result);
  58. } catch (ValidationException $e) {
  59. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  60. } catch (Exception $e) {
  61. return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage());
  62. }
  63. }
  64. }