Reporting.php 2.1 KB

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace App\Http\Controllers\admin;
  3. use App\Constants\HttpStatus;
  4. use App\Http\Controllers\Controller;
  5. use App\Services\Reporting\ReportAdmin;
  6. use App\Services\Reporting\ReportReader;
  7. use Illuminate\Support\Facades\Log;
  8. use Illuminate\Validation\ValidationException;
  9. class Reporting extends Controller
  10. {
  11. public function options(ReportAdmin $service) { return $this->run(fn () => $service->options()); }
  12. public function leaderboard(ReportReader $service) { return $this->run(fn () => $service->details(request()->all(), true)); }
  13. public function funds(ReportReader $service) { return $this->run(fn () => $service->funds(request()->all())); }
  14. public function summary(ReportReader $service) { return $this->run(fn () => $service->summary(request()->all())); }
  15. public function details(ReportReader $service) { return $this->run(fn () => $service->details(request()->all())); }
  16. public function orders(ReportReader $service) { return $this->run(fn () => $service->orders(request()->all())); }
  17. public function events(ReportReader $service) { return $this->run(fn () => $service->events(request()->all())); }
  18. public function settings(ReportAdmin $service) { return $this->run(fn () => $service->settings(request()->isMethod('POST') ? request()->all() : null)); }
  19. public function payments(ReportAdmin $service) { return $this->run(fn () => request()->isMethod('POST') ? $service->reconcile(request()->all()) : $service->reconciliations(request()->all())); }
  20. public function orderTime(ReportAdmin $service) { return $this->run(fn () => $service->reconcileOrder(request()->all())); }
  21. public function quality(ReportAdmin $service) { return $this->run(fn () => $service->quality(request()->all())); }
  22. private function run(callable $callback)
  23. {
  24. try { return $this->success($callback()); }
  25. catch (ValidationException $e) { return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first()); }
  26. catch (\Throwable $e) { Log::error('reporting_request_failed', ['exception' => $e]); return $this->error(HttpStatus::CUSTOM_ERROR, '报表暂不可用,请稍后重试'); }
  27. }
  28. }