29 lines
1.3 KiB
PHP
29 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Business;
|
|
|
|
use App\Models\Business\CourierAgreementSignature;
|
|
use Illuminate\Routing\Controller;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Symfony\Component\HttpFoundation\StreamedResponse;
|
|
|
|
class CourierContracts extends Controller
|
|
{
|
|
/** A read-only archive entry point with courier-information page access, not signing-management access. */
|
|
public function download(CourierAgreementSignature $agreementSignature, string $kind): StreamedResponse
|
|
{
|
|
abort_unless($agreementSignature->company_id === (int) company_id()
|
|
&& $agreementSignature->archivedCourierContractPayload() !== 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');
|
|
}
|
|
}
|