From 2a3ea39e72d5c3a4c04fd99a87c4f6704f16b0ac Mon Sep 17 00:00:00 2001 From: limeng <1131177064@qq.com> Date: Mon, 9 Nov 2026 18:58:05 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=BF=AB=E9=80=92=E6=8A=A5=E4=BB=B7):=20?= =?UTF-8?q?=E4=BB=B7=E6=A0=BC=E8=A1=A8=E5=8F=B3=E4=BE=A7=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=A4=87=E6=B3=A8=E5=88=97=EF=BC=8C=E8=AE=A1=E8=B4=B9=E6=9D=A1?= =?UTF-8?q?=E4=BB=B6=E9=9A=8F=E7=A1=AE=E8=AE=A4=E5=8D=95=E7=9B=96=E7=AB=A0?= =?UTF-8?q?=E5=B9=B6=E8=BF=9B=E5=85=A5=E5=AF=BC=E5=87=BA=E7=94=B5=E5=AD=90?= =?UTF-8?q?=E8=A1=A8=20(#1020)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 快递入驻填写的计费条件(执行时间、计费方式、是否计泡及抛比、起算重量、报价备注里的限长限重等) 原来在确认单里排在价格表下方、导出的报价电子表格里则完全没有,容易事后扯皮。 - 报价确认单 PDF(推送快递 e签宝盖章)与导出的报价 xlsx:价格表右侧增加「备注」列,逐行列出价格表以外的全部条件 - 新生成的入驻/变价报价补充口径:重量不取整说明、重量区间含上限、未列省份及空白价格不在报价范围、开票类型与税率、结算周期、附加费(除报价表及备注列明外不另收取) - 入驻表单报价备注下提示:要收的附加费须写在这里,没写视为不收取,并随确认单盖章 涉及:报价确认单与导出展示;已签署的确认单不变;不涉及迁移、权限和上游写入。 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01VANWYsNUbu2piMtCKymoyd --- .../Business/CourierQuoteSignatures.php | 82 +++++++++++++++++-- app/Support/CourierOnboardingService.php | 35 +++++++- .../business/pdf/courier-quote.blade.php | 46 ++++++++--- .../views/onboarding/courier-form.blade.php | 1 + .../CourierOnboardingWorkflowTest.php | 32 ++++++-- 5 files changed, 170 insertions(+), 26 deletions(-) diff --git a/app/Http/Controllers/Business/CourierQuoteSignatures.php b/app/Http/Controllers/Business/CourierQuoteSignatures.php index 5dbe776f..aa4dc34a 100644 --- a/app/Http/Controllers/Business/CourierQuoteSignatures.php +++ b/app/Http/Controllers/Business/CourierQuoteSignatures.php @@ -131,13 +131,14 @@ class CourierQuoteSignatures extends Controller } /** - * 导出报价电子表格(xlsx,WPS / Excel 都能打开):只保留「省份」表头和各省价格, - * 不带标题、执行时间、计费说明和备注等文字行。 + * 导出报价电子表格(xlsx,WPS / Excel 都能打开):「省份」表头和各省价格, + * 右侧加「备注」列,逐行列出价格表以外的全部计费条件(执行时间、计泡、起算重量、报价备注等), + * 与快递盖章的报价确认单一致。 */ public function sheet(CourierQuoteVersion $quoteVersion): StreamedResponse { $values = json_decode((string) $quoteVersion->values_json, true); - $table = self::quoteTable(is_array($values) ? $values : []); + $table = self::quoteTableWithNotes(self::quoteLayout(is_array($values) ? $values : []))['rows']; abort_if($table === [], 404, '这份报价没有可导出的价格表。'); $spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); @@ -166,6 +167,10 @@ class CourierQuoteSignatures extends Controller for ($i = 2; $i <= count($table[0]); $i++) { $sheet->getColumnDimension(\PhpOffice\PhpSpreadsheet\Cell\Coordinate::stringFromColumnIndex($i))->setWidth(16); } + // 备注列:加宽、左对齐,方便阅读整句计费条件。 + $sheet->getColumnDimension($lastColumn)->setWidth(48); + $sheet->getStyle($lastColumn . '2:' . $lastColumn . count($table))->getAlignment() + ->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_LEFT); $sheet->freezePane('B2'); $fileName = $this->safeName(($quoteVersion->company_name ?: $quoteVersion->carrier_name) . '-' . $quoteVersion->version_code) . '-报价.xlsx'; @@ -183,7 +188,23 @@ class CourierQuoteSignatures extends Controller */ public static function quoteTable(array $values): array { - $rows = array_values(array_filter($values, 'is_array')); + return self::quoteLayout($values)['table']; + } + + /** + * 报价矩阵拆成「价格表」和「价格表以外的文字」: + * - table:从「省份」表头行开始,到第一行只有一格文字为止; + * - notes:其余所有文字行(执行时间、计费方式、计泡、起算重量、报价备注等),第一行标题除外; + * - row_keys:价格表每一行在原矩阵里的下标(用于对应公式)。 + * + * @param array $values + * @return array{table:list>,notes:list,row_keys:list} + */ + public static function quoteLayout(array $values): array + { + $arrays = array_filter($values, 'is_array'); + $keys = array_keys($arrays); + $rows = array_values($arrays); $filled = static fn (array $row): int => count(array_filter($row, static fn ($cell): bool => $cell !== null && trim((string) $cell) !== '')); $start = null; foreach ($rows as $index => $row) { @@ -202,12 +223,16 @@ class CourierQuoteSignatures extends Controller } } if ($start === null) { - return []; + return ['table' => [], 'notes' => [], 'row_keys' => []]; } $table = []; + $rowKeys = []; + $end = $start; for ($i = $start; $i < count($rows) && $filled($rows[$i]) >= 2; $i++) { $table[] = array_values($rows[$i]); + $rowKeys[] = $keys[$i]; + $end = $i + 1; } $width = 0; @@ -219,7 +244,52 @@ class CourierQuoteSignatures extends Controller } } - return array_map(static fn (array $row): array => array_pad(array_slice($row, 0, $width), $width, null), $table); + $notes = []; + foreach ($rows as $index => $row) { + if (($index >= $start && $index < $end) || ($index === 0 && $start > 0)) { + continue; + } + $text = implode(' ', array_map( + static fn ($cell): string => trim((string) $cell), + array_filter($row, static fn ($cell): bool => $cell !== null && trim((string) $cell) !== ''), + )); + if ($text !== '') { + $notes[] = $text; + } + } + + return [ + 'table' => array_map(static fn (array $row): array => array_pad(array_slice($row, 0, $width), $width, null), $table), + 'notes' => $notes, + 'row_keys' => $rowKeys, + ]; + } + + /** + * 价格表右侧加一列「备注」,每条计费条件占一行;条件比省份多时在表尾补行。 + * + * @param array{table:list>,notes:list,row_keys:list} $layout + * @return array{rows:list>,row_keys:list} + */ + public static function quoteTableWithNotes(array $layout): array + { + $table = $layout['table']; + if ($table === []) { + return ['rows' => [], 'row_keys' => []]; + } + $notes = $layout['notes']; + $width = count($table[0]); + $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); + $rows[] = $row; + $keys[] = $layout['row_keys'][$i] ?? null; + } + + return ['rows' => $rows, 'row_keys' => $keys]; } private function safeName(string $name): string diff --git a/app/Support/CourierOnboardingService.php b/app/Support/CourierOnboardingService.php index 7c20d530..ff040226 100644 --- a/app/Support/CourierOnboardingService.php +++ b/app/Support/CourierOnboardingService.php @@ -763,7 +763,7 @@ class CourierOnboardingService } // 规则说明放在价格表下方,避免报价确认单抬头的「面单费」误读说明文字。 - foreach ($onboarding->quoteRuleLines() as $rule) { + foreach ([...$onboarding->quoteRuleLines(), ...$this->quoteClauses($onboarding)] as $rule) { $matrix[] = $line($rule); } @@ -775,6 +775,39 @@ class CourierOnboardingService return $matrix; } + /** + * 报价表里看不出来、但会影响运费的口径,写进确认单让快递一并盖章确认,避免事后扯皮。 + * + * @return list + */ + private function quoteClauses(CourierOnboarding $onboarding): array + { + $structure = $onboarding->quoteStructure(); + $mode = (string) ($structure['mode'] ?? ''); + $kg = static fn ($value): string => CourierQuoteStructure::kg((float) $value); + $clauses = []; + if ($mode !== 'other') { + if (blank($onboarding->weight_rounding) || $onboarding->weight_rounding === 'none') { + $clauses[] = '重量取整:不取整,按实际计费重量计算'; + } + if (($structure['flat_bands'] ?? []) !== [] || ($structure['rate_tiers'] ?? []) !== []) { + $clauses[] = '重量区间:按计费重量所在区间取价,区间含上限(如 1-2kg 含 2kg)'; + } + $clauses[] = '报价范围:表中未列出的省份、空白的价格,表示不在本报价范围内'; + } + if (filled($onboarding->invoice_type)) { + $clauses[] = '开票:' . $onboarding->invoice_type + . ($onboarding->invoice_type !== '不开票' && $onboarding->tax_rate !== null && $onboarding->tax_rate !== '' ? ',税率' . $kg($onboarding->tax_rate) . '%' : ''); + } + if (filled($onboarding->settlement_cycle)) { + $clauses[] = '结算周期:' . $onboarding->settlement_cycle; + } + // 快递要收的附加费(超长超重、偏远、上楼、保价等)须写在报价备注里,没写的视为不收。 + $clauses[] = '附加费:除本报价表及备注列明的费用外,不另收取其他任何附加费'; + + return $clauses; + } + /** * @param list $allowed */ diff --git a/resources/views/business/pdf/courier-quote.blade.php b/resources/views/business/pdf/courier-quote.blade.php index 58071637..3ed05e05 100644 --- a/resources/views/business/pdf/courier-quote.blade.php +++ b/resources/views/business/pdf/courier-quote.blade.php @@ -30,6 +30,8 @@ .number { text-align: right; } .matrix { font-size: 7.5px; table-layout: auto; } .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; } @@ -120,21 +122,41 @@

完整报价规则

@if(! empty($billingRules))

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

@endif +@php + // 价格表右侧加「备注」列:价格表以外的计费条件(执行时间、计泡、起算重量、报价备注等)逐行列出,随确认单一起盖章。 + $quoteLayout = \App\Http\Controllers\Business\CourierQuoteSignatures::quoteTableWithNotes(\App\Http\Controllers\Business\CourierQuoteSignatures::quoteLayout($values)); +@endphp - @forelse($values as $rowIndex => $row) - - @foreach($row as $columnIndex => $cell) - @php($formula = $formulas[$rowIndex][$columnIndex] ?? null) - <{{ $rowIndex === 0 ? 'th' : 'td' }}> - {!! $mixedText(is_bool($cell) ? ($cell ? '是' : '否') : ($cell ?? '')) !!} - @if(is_string($formula) && trim($formula) !== '')
公式:{!! $mixedText($formula) !!}
@endif - + @if($quoteLayout['rows'] !== []) + @foreach($quoteLayout['rows'] as $rowIndex => $row) + @php($rowKey = $quoteLayout['row_keys'][$rowIndex] ?? null) + @php($lastColumn = count($row) - 1) + + @foreach($row as $columnIndex => $cell) + @php($formula = $rowKey !== null && $columnIndex < $lastColumn ? ($formulas[$rowKey][$columnIndex] ?? null) : null) + <{{ $rowIndex === 0 ? 'th' : 'td' }} @if($columnIndex === $lastColumn)class="matrix__note"@endif> + {!! $mixedText(is_bool($cell) ? ($cell ? '是' : '否') : ($cell ?? '')) !!} + @if(is_string($formula) && trim($formula) !== '')
公式:{!! $mixedText($formula) !!}
@endif + + @endforeach + @endforeach - - @empty - - @endforelse + @else + @forelse($values as $rowIndex => $row) + + @foreach($row as $columnIndex => $cell) + @php($formula = $formulas[$rowIndex][$columnIndex] ?? null) + <{{ $rowIndex === 0 ? 'th' : 'td' }}> + {!! $mixedText(is_bool($cell) ? ($cell ? '是' : '否') : ($cell ?? '')) !!} + @if(is_string($formula) && trim($formula) !== '')
公式:{!! $mixedText($formula) !!}
@endif + + @endforeach + + @empty + + @endforelse + @endif
该版本未保存可展示的报价矩阵。
该版本未保存可展示的报价矩阵。
diff --git a/resources/views/onboarding/courier-form.blade.php b/resources/views/onboarding/courier-form.blade.php index 33857cab..3eb74900 100644 --- a/resources/views/onboarding/courier-form.blade.php +++ b/resources/views/onboarding/courier-form.blade.php @@ -615,6 +615,7 @@
+ 需要收取的附加费(超长超重、偏远地区、上楼、保价等)请在这里写清楚;没写的视为不收取。报价备注会原样写进报价确认单,由你方盖章确认。
diff --git a/tests/Feature/Business/CourierOnboardingWorkflowTest.php b/tests/Feature/Business/CourierOnboardingWorkflowTest.php index d604d40c..18a30b71 100644 --- a/tests/Feature/Business/CourierOnboardingWorkflowTest.php +++ b/tests/Feature/Business/CourierOnboardingWorkflowTest.php @@ -235,6 +235,22 @@ class CourierOnboardingWorkflowTest extends FeatureTestCase $this->assertSame(['江苏', 3.2, 0.8], $values[$headerIndex + 1]); $this->assertContains('计费方式:面单+重量*费率', array_column($values, 0)); $this->assertContains('计泡:长*宽*高/6000,取实重与体积重较大值', array_column($values, 0)); + $this->assertContains('重量取整:不取整,按实际计费重量计算', array_column($values, 0)); + $this->assertContains('报价范围:表中未列出的省份、空白的价格,表示不在本报价范围内', array_column($values, 0)); + $this->assertContains('开票:增值税专用发票,税率6%', array_column($values, 0)); + $this->assertContains('结算周期:月结', array_column($values, 0)); + $this->assertContains('附加费:除本报价表及备注列明的费用外,不另收取其他任何附加费', array_column($values, 0)); + + // 价格表以外的计费条件进「备注」列:确认单 PDF 与导出的报价电子表格一致。 + $layout = \App\Http\Controllers\Business\CourierQuoteSignatures::quoteTableWithNotes( + \App\Http\Controllers\Business\CourierQuoteSignatures::quoteLayout($values), + ); + $this->assertSame(['省份', '面单', '费率(元/kg)', '备注'], $layout['rows'][0]); + $this->assertStringStartsWith('执行时间:', (string) $layout['rows'][1][3]); + $noteColumn = array_column($layout['rows'], 3); + $this->assertContains('计泡:长*宽*高/6000,取实重与体积重较大值', $noteColumn); + $this->assertContains('适用快递:新北中通-入驻', $noteColumn); + $this->assertNotContains('新北中通-入驻 报价', $noteColumn); $change = CourierQuoteChange::query()->findOrFail($onboarding->quote_change_id); $this->assertSame(CourierQuoteChange::STATUS_APPROVED, $change->status); $this->assertSame('新快递入驻', $change->change_type); @@ -311,7 +327,7 @@ class CourierOnboardingWorkflowTest extends FeatureTestCase $this->assertTrue(collect($names)->contains(fn ($name) => str_ends_with($name, '-回签单.pdf'))); $this->assertTrue(collect($names)->contains(fn ($name) => str_ends_with($name, '-签署完成证书.pdf'))); - // 导出电子档:xlsx 只保留省份表头和价格行,不带标题、执行时间、计费说明。 + // 导出电子档:xlsx 价格表右侧带「备注」列,逐行列出执行时间、计费方式、计泡等条件(与盖章确认单一致),不带标题。 $this->assertSame(route('business.courier-quote-signatures.sheet', $version), $listed['signed_files']['export']); $sheetResponse = $this->loginAs($reviewer, $this->company)->get($listed['signed_files']['export']); $sheetResponse->assertOk(); @@ -320,12 +336,14 @@ class CourierOnboardingWorkflowTest extends FeatureTestCase file_put_contents($xlsxPath, $sheetResponse->streamedContent()); $rows = \PhpOffice\PhpSpreadsheet\IOFactory::load($xlsxPath)->getActiveSheet()->toArray(null, false, false, false); @unlink($xlsxPath); - $this->assertSame(['省份', '面单', '费率(元/kg)'], $rows[0]); - $this->assertSame(['江苏', 3.2, 0.8], $rows[1]); - $flat = collect($rows)->flatten()->filter()->implode(' '); - $this->assertStringNotContainsString('执行时间', $flat); - $this->assertStringNotContainsString('计费方式', $flat); - $this->assertStringNotContainsString('计泡', $flat); + $this->assertSame(['省份', '面单', '费率(元/kg)', '备注'], $rows[0]); + $this->assertSame(['江苏', 3.2, 0.8], array_slice($rows[1], 0, 3)); + $this->assertStringStartsWith('执行时间:', (string) $rows[1][3]); + $notes = collect($rows)->pluck(3)->filter()->implode(' '); + $this->assertStringContainsString('计费方式:', $notes); + $this->assertStringContainsString('计泡:', $notes); + $this->assertStringContainsString('附加费:', $notes); + $this->assertStringNotContainsString('新北中通-入驻 报价', collect($rows)->flatten()->filter()->implode(' ')); $this->loginAs($reviewer, $this->company) ->post(route('business.courier-onboardings.activate', $onboarding), [])