CompanyReportController.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace App\Http\Controllers\agent;
  3. use App\Http\Controllers\AgentApiController;
  4. use App\Services\CompanyMonthlyReportService;
  5. use Illuminate\Http\Request;
  6. /** 入股代理查看、下载公司营业报表(总后台按月上传)。合营代理不可见。 */
  7. class CompanyReportController extends AgentApiController
  8. {
  9. private function onlyEquity(): void
  10. {
  11. if (!$this->currentAgent()->isEquity()) throw new \RuntimeException('仅入股代理可查看公司营业报表');
  12. }
  13. public function index(Request $request, CompanyMonthlyReportService $service)
  14. {
  15. return $this->execute(function () use ($request, $service) {
  16. $this->onlyEquity();
  17. $data = $request->validate([
  18. 'page' => ['nullable', 'integer', 'min:1'], 'limit' => ['nullable', 'integer', 'min:1', 'max:100'],
  19. 'start_month' => ['nullable', 'date_format:Y-m'], 'end_month' => ['nullable', 'date_format:Y-m', 'after_or_equal:start_month'],
  20. ]);
  21. return $service->paginate($data, false);
  22. });
  23. }
  24. public function download(Request $request, CompanyMonthlyReportService $service)
  25. {
  26. return $this->executeFile(function () use ($request, $service) {
  27. $this->onlyEquity();
  28. $data = $request->validate(['id' => ['required', 'integer', 'min:1']]);
  29. return $service->download((int) $data['id']);
  30. });
  31. }
  32. }