| 12345678910111213141516171819202122232425262728293031 |
- <?php
- namespace App\Http\Controllers\admin;
- use App\Constants\HttpStatus;
- use App\Http\Controllers\Controller;
- use App\Services\Reporting\ReportAdmin;
- use App\Services\Reporting\ReportReader;
- use Illuminate\Support\Facades\Log;
- use Illuminate\Validation\ValidationException;
- class Reporting extends Controller
- {
- public function options(ReportAdmin $service) { return $this->run(fn () => $service->options()); }
- public function leaderboard(ReportReader $service) { return $this->run(fn () => $service->details(request()->all(), true)); }
- public function funds(ReportReader $service) { return $this->run(fn () => $service->funds(request()->all())); }
- public function summary(ReportReader $service) { return $this->run(fn () => $service->summary(request()->all())); }
- public function details(ReportReader $service) { return $this->run(fn () => $service->details(request()->all())); }
- public function orders(ReportReader $service) { return $this->run(fn () => $service->orders(request()->all())); }
- public function events(ReportReader $service) { return $this->run(fn () => $service->events(request()->all())); }
- public function settings(ReportAdmin $service) { return $this->run(fn () => $service->settings(request()->isMethod('POST') ? request()->all() : null)); }
- public function payments(ReportAdmin $service) { return $this->run(fn () => request()->isMethod('POST') ? $service->reconcile(request()->all()) : $service->reconciliations(request()->all())); }
- public function orderTime(ReportAdmin $service) { return $this->run(fn () => $service->reconcileOrder(request()->all())); }
- public function quality(ReportAdmin $service) { return $this->run(fn () => $service->quality(request()->all())); }
- private function run(callable $callback)
- {
- try { return $this->success($callback()); }
- catch (ValidationException $e) { return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first()); }
- catch (\Throwable $e) { Log::error('reporting_request_failed', ['exception' => $e]); return $this->error(HttpStatus::CUSTOM_ERROR, '报表暂不可用,请稍后重试'); }
- }
- }
|