From 167211490b95c8ebea50cbaad8f2c2eabd99e8c0 Mon Sep 17 00:00:00 2001 From: limeng <1131177064@qq.com> Date: Mon, 16 Nov 2026 09:31:03 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=8A=A5=E4=BB=B7=E7=AD=BE=E7=BD=B2?= =?UTF-8?q?=E5=8E=9F=E4=BB=B6=E4=BB=85=E5=B1=95=E7=A4=BA=E6=A8=AA=E5=90=91?= =?UTF-8?q?=E6=96=B0=E4=BB=B7=E6=A0=BC=E5=B9=B6=E4=BF=AE=E5=A4=8D=E7=BC=BA?= =?UTF-8?q?=E5=A4=B1=E5=AD=97=E5=BD=A2=20(#1184)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Business/CourierQuoteSignatures.php | 11 +++- app/Support/CourierQuoteConfirmation.php | 2 +- .../business/pdf/courier-quote.blade.php | 51 +++++++------------ .../CourierQuoteSignatureWorkflowTest.php | 40 +++++++++++++++ tests/Unit/CourierQuotePdfWhitespaceTest.php | 4 +- 5 files changed, 71 insertions(+), 37 deletions(-) diff --git a/app/Http/Controllers/Business/CourierQuoteSignatures.php b/app/Http/Controllers/Business/CourierQuoteSignatures.php index 76d2b5cc..89154983 100644 --- a/app/Http/Controllers/Business/CourierQuoteSignatures.php +++ b/app/Http/Controllers/Business/CourierQuoteSignatures.php @@ -274,7 +274,7 @@ class CourierQuoteSignatures extends Controller } /** - * 价格表右侧加一列「备注」,每条计费条件占一行;条件比省份多时在表尾补行。 + * 复用价格表已有的「备注」列,缺少时再添加;条件比省份多时在表尾补行。 * * @param array{table:list>,notes:list,row_keys:list} $layout * @return array{rows:list>,row_keys:list} @@ -287,12 +287,19 @@ class CourierQuoteSignatures extends Controller } $notes = $layout['notes']; $width = count($table[0]); + $hasNoteColumn = preg_match('/^(备注|说明)[::]?$/u', trim((string) $table[0][$width - 1])) === 1; $rows = []; $keys = []; $total = max(count($table), count($notes) + 1); for ($i = 0; $i < $total; $i++) { $row = $table[$i] ?? array_fill(0, $width, null); - $row[] = $i === 0 ? '备注' : ($notes[$i - 1] ?? null); + if ($hasNoteColumn) { + if ($i > 0 && filled($notes[$i - 1] ?? null)) { + $row[$width - 1] = implode("\n", array_filter([$row[$width - 1], $notes[$i - 1]], static fn ($value) => $value !== null && $value !== '')); + } + } else { + $row[] = $i === 0 ? '备注' : ($notes[$i - 1] ?? null); + } $rows[] = $row; $keys[] = $layout['row_keys'][$i] ?? null; } diff --git a/app/Support/CourierQuoteConfirmation.php b/app/Support/CourierQuoteConfirmation.php index acb0b3e6..42ec1841 100644 --- a/app/Support/CourierQuoteConfirmation.php +++ b/app/Support/CourierQuoteConfirmation.php @@ -9,7 +9,7 @@ final class CourierQuoteConfirmation public function data(CourierQuoteVersion $version, ?string $signingSubject = null): array { $partyA = trim((string) $signingSubject) ?: trim((string) config('services.esign.default_initiator')); - $version->loadMissing(['change.items']); + $version->loadMissing(['change']); $values = $this->decodeMatrix($version->values_json); $nextVersion = CourierQuoteVersion::query() ->where('carrier_name', $version->carrier_name) diff --git a/resources/views/business/pdf/courier-quote.blade.php b/resources/views/business/pdf/courier-quote.blade.php index 0b2490e7..3c6c33f4 100644 --- a/resources/views/business/pdf/courier-quote.blade.php +++ b/resources/views/business/pdf/courier-quote.blade.php @@ -29,11 +29,12 @@ th { background: #eee8db; font-weight: 400; } .number { text-align: right; } .matrix { font-size: 7.5px; table-layout: auto; } + .matrix thead { display: table-header-group; } + .matrix tr { page-break-inside: avoid; } .matrix th, .matrix td { max-width: 90px; padding: 3px 4px; } .matrix .matrix__note { width: 30%; max-width: none; background: #faf6ea; } .matrix th.matrix__note { background: #eee8db; } .formula { color: #735c31; font-size: 7px; } - .summary { white-space: pre-wrap; } .signature { page-break-before: always; } .signature h2 { margin-top: 0; } .signature__meta { margin-bottom: 18px; color: #555; } @@ -47,15 +48,19 @@ $mixedText = static function ($value): string { // Spreadsheet-pasted whitespace has no glyph in the CJK font. $text = str_replace(["\r\n", "\r", "\t", "\u{00A0}"], ["\n", "\n", ' ', ' '], (string) $value); - $parts = preg_split('/([\x20-\x7E]+)/', $text, -1, PREG_SPLIT_DELIM_CAPTURE) ?: []; + // Keep real line breaks without reproducing spreadsheet alignment padding. + $text = preg_replace('/[ \x{3000}]+/u', ' ', $text) ?? $text; + // Droid Sans Fallback also lacks common dash and currency glyphs. + $latinCharacters = '\x20-\x7E\x{00A5}\x{00B0}\x{00B7}\x{00D7}\x{00F7}\x{2010}-\x{2015}\x{2212}'; + $parts = preg_split('/([' . $latinCharacters . ']+)/u', $text, -1, PREG_SPLIT_DELIM_CAPTURE) ?: []; - return implode('', array_map(static function (string $part): string { + return nl2br(implode('', array_map(static function (string $part) use ($latinCharacters): string { $escaped = e($part); - return preg_match('/^[\x20-\x7E]+$/', $part) === 1 + return preg_match('/^[' . $latinCharacters . ']+$/u', $part) === 1 ? '' . $escaped . '' : $escaped; - }, $parts)); + }, $parts)), false); }; @endphp
@@ -82,7 +87,7 @@ 执行期间{!! $mixedText($version->periodLabel()) !!} - 区间截止 / 有效期{!! $mixedText($version->isTemporary() ? '以左侧各区间为准,区间外恢复原报价' : $expiryDate) !!} + {!! $mixedText('区间截止 / 有效期') !!}{!! $mixedText($version->isTemporary() ? '以左侧各区间为准,区间外恢复原报价' : $expiryDate) !!} 报价编号{!! $mixedText($version->version_code) !!} @@ -98,40 +103,19 @@ @endif
本文件由财务系统根据已审核报价版本自动生成。乙方签章后文件与完成证书将按本版本单独归档;后续变价须生成新版本并重新签章,旧确认单不会被覆盖。
-@if($change) -

变价说明

-

{!! $mixedText($change->summary) !!}

-

新旧价格差异

- - - - @foreach($change->items as $item) - - - - - - - - - - @endforeach - -
单元格{!! $mixedText('地区/规则') !!}{!! $mixedText('重量段/计费项') !!}原价格新价格单位备注
{!! $mixedText($item->source_cell) !!}{!! $mixedText($item->region ?: '—') !!}{!! $mixedText($item->weight_band ?: ($item->charge_item ?: '—')) !!}{!! $mixedText(rtrim(rtrim($item->original_amount, '0'), '.')) !!}{!! $mixedText(rtrim(rtrim($item->new_amount, '0'), '.')) !!}{!! $mixedText($item->unit ?: '—') !!}{!! $mixedText($item->note ?: '—') !!}
-@endif - -

完整报价规则

+

报价明细(执行价格)

@if(! empty($billingRules))

{!! $mixedText($billingRules) !!}

@endif @php - // 价格表右侧加「备注」列:价格表以外的计费条件(执行时间、计泡、起算重量、报价备注等)逐行列出,随确认单一起盖章。 + // 价格表保留原有横向公斤段;其他计费条件合入备注,随确认单一起盖章。 $quoteLayout = \App\Http\Controllers\Business\CourierQuoteSignatures::quoteTableWithNotes(\App\Http\Controllers\Business\CourierQuoteSignatures::quoteLayout($values)); @endphp - @if($quoteLayout['rows'] !== []) @foreach($quoteLayout['rows'] as $rowIndex => $row) @php($rowKey = $quoteLayout['row_keys'][$rowIndex] ?? null) @php($lastColumn = count($row) - 1) + @if($rowIndex === 0)@endif + @if($rowIndex === 1)@endif @foreach($row as $columnIndex => $cell) @php($formula = $rowKey !== null && $columnIndex < $lastColumn ? ($formulas[$rowKey][$columnIndex] ?? null) : null) @@ -141,8 +125,11 @@ @endforeach + @if($rowIndex === 0)@endif @endforeach + @if(count($quoteLayout['rows']) > 1)@endif @else + @forelse($values as $rowIndex => $row) @foreach($row as $columnIndex => $cell) @@ -156,8 +143,8 @@ @empty @endforelse + @endif -
该版本未保存可展示的报价矩阵。
diff --git a/tests/Feature/Business/CourierQuoteSignatureWorkflowTest.php b/tests/Feature/Business/CourierQuoteSignatureWorkflowTest.php index b1af2707..f2040414 100644 --- a/tests/Feature/Business/CourierQuoteSignatureWorkflowTest.php +++ b/tests/Feature/Business/CourierQuoteSignatureWorkflowTest.php @@ -92,6 +92,46 @@ class CourierQuoteSignatureWorkflowTest extends FeatureTestCase $this->assertStringNotContainsString($this->company->name, $rendered); } + public function test_signature_pdf_contains_only_approved_prices_in_horizontal_weight_columns(): void + { + $version = $this->createVersion(); + $version->update([ + 'values_json' => json_encode([ + ['示例快递报价'], + ['省份', '0-3公斤', '3-35公斤', '单位', '备注'], + ['江苏', '0.5000', '0.5300', '元/公斤', '按实际重量计费'], + ['安徽', 0, '0.6300', '元/公斤', null], + ['计泡系数:1.2'], + ], JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR), + 'formulas_json' => '[]', + ]); + $version->change->update(['summary' => '内部审核备注,不发送给快递']); + $version->change->items()->update(['original_amount' => '987.6543', 'note' => '内部差额核对']); + + $text = []; + $pdf = app('dompdf.wrapper'); + $pdf->getDomPDF()->setCallbacks([['event' => 'end_frame', 'f' => static function ($frame) use (&$text): void { + if ($frame instanceof \Dompdf\FrameDecorator\Text) $text[] = $frame->get_text(); + }]]); + app()->instance('dompdf.wrapper', $pdf); + $signature = app(CourierQuoteSignatureService::class)->prepareVersion($version, $this->user->id); + $rendered = implode('', $text); + foreach (['0-3公斤', '3-35公斤', '江苏', '安徽', '0.5000', '0.5300', '0.6300', '元/公斤', '按实际重量计费', '计泡系数:1.2'] as $expected) { + $this->assertStringContainsString($expected, $rendered); + } + foreach (['新旧价格差异', '原价格', '差额', '单元格', '987.6543', '内部审核备注', '内部差额核对'] as $internal) { + $this->assertStringNotContainsString($internal, $rendered); + } + $this->assertStringStartsWith('%PDF-', Storage::disk('uploads')->get($signature->source_pdf_path)); + + $table = \App\Http\Controllers\Business\CourierQuoteSignatures::quoteTableWithNotes( + \App\Http\Controllers\Business\CourierQuoteSignatures::quoteLayout(json_decode($version->values_json, true)) + ); + $this->assertSame(['省份', '0-3公斤', '3-35公斤', '单位', '备注'], $table['rows'][0]); + $this->assertSame(['江苏', '0.5000', '0.5300', '元/公斤', "按实际重量计费\n计泡系数:1.2"], $table['rows'][1]); + $this->assertSame(0, $table['rows'][2][1]); + } + public function test_admin_can_push_the_exact_pdf_to_esign_sandbox(): void { $signature = $this->createPreparedSignature(); diff --git a/tests/Unit/CourierQuotePdfWhitespaceTest.php b/tests/Unit/CourierQuotePdfWhitespaceTest.php index 2eebe72d..14ebc8bf 100644 --- a/tests/Unit/CourierQuotePdfWhitespaceTest.php +++ b/tests/Unit/CourierQuotePdfWhitespaceTest.php @@ -21,11 +21,11 @@ class CourierQuotePdfWhitespaceTest extends TestCase 'quote_type' => '普通报价', 'effective_date' => '2026-11-01', ]), 'change' => (object) ['summary' => '按原报价执行。', 'approved_at' => now(), 'items' => []], - 'values' => [['地区', '费用'], ['江苏', '6.50']], + 'values' => [['地区', '费用', '单位', '备注'], ['江苏', '6.50', '元/单', '—'], ['安徽', '0.00', null, null]], 'formulas' => [], 'partyA' => '示例甲方', 'expiryDate' => '长期', 'faceFee' => '0.50', 'bubbleCoefficient' => '1.2', - 'billingRules' => "1、\u{00A0}计费重 > 0.5kg,费用6.50元。\t\t\t\r\n2、\u{00A0}轻抛比1:10000。\t\t\t\r3、保留末行。", + 'billingRules' => "1、\u{00A0}计费重 > 0.5kg,费用6.50元。\t\t\t\r\n2、\u{00A0}轻抛比1:10000。\t\t\t\r3、保留末行。0–3kg — 费用 ¥6.50。", 'signatureDate' => '2026年11月7日', 'generatedAt' => now(), 'fontPath' => str_replace('\\', '/', resource_path('fonts/DroidSansFallback.ttf')), ])->render();