serveFile($agreementSignature, $kind, 'courier'); } public function downloadSupplier(CourierAgreementSignature $agreementSignature, string $kind): StreamedResponse { return $this->serveFile($agreementSignature, $kind, 'supplier'); } private function serveFile(CourierAgreementSignature $agreementSignature, string $kind, string $partnerType): StreamedResponse { abort_unless($agreementSignature->company_id === (int) company_id() && $agreementSignature->archivedContractPayload($partnerType) !== null, 404); $path = match ($kind) { 'signed' => $agreementSignature->signed_pdf_path, 'certificate' => $agreementSignature->certificate_path, default => abort(404), }; abort_if(blank($path) || ! Storage::disk('uploads')->exists($path), 404, '归档附件不存在,请核对协议签署记录。'); $suffix = $kind === 'signed' ? '已签署合作合同' : '签署完成证书'; return Storage::disk('uploads')->response($path, $agreementSignature->business_no . '-' . $suffix . '.pdf', ['Content-Type' => 'application/pdf'], request()->boolean('preview') ? 'inline' : 'attachment'); } }