CaiWuXiTong/app/Support/CourierQuotePdf.php
limeng a46d4dc678 修复签署文件日期未生成 (#225)
统一使用 signature_date 变量,并在推送 E 签宝前写入协议与报价确认单。
2026-09-21 10:02:37 +08:00

45 lines
1.4 KiB
PHP

<?php
namespace App\Support;
use App\Models\Business\CourierQuoteVersion;
use Illuminate\Support\Carbon;
use RuntimeException;
final class CourierQuotePdf
{
public function __construct(private readonly CourierQuoteConfirmation $confirmation)
{
}
public function render(CourierQuoteVersion $version, ?string $signatureDate = null): string
{
$data = $this->confirmation->data($version);
$signatureDate = Carbon::parse($signatureDate ?: now())->format('Y年n月j日');
$html = view('business.pdf.courier-quote', [
'version' => $version,
'change' => $version->change,
'values' => $data['values'],
'formulas' => $data['formulas'],
'partyA' => $data['party_a'],
'expiryDate' => $data['expiry_date'],
'faceFee' => $data['face_fee'],
'bubbleCoefficient' => $data['bubble_coefficient'],
'signatureDate' => $signatureDate,
'generatedAt' => now(),
'fontPath' => str_replace('\\', '/', resource_path('fonts/DroidSansFallback.ttf')),
])->render();
$pdf = app('dompdf.wrapper');
$pdf->setPaper('a4', 'landscape');
$pdf->loadHTML($html, 'UTF-8');
$bytes = $pdf->output();
if (! is_string($bytes) || ! str_starts_with($bytes, '%PDF-')) {
throw new RuntimeException('报价 PDF 生成失败。');
}
return $bytes;
}
}