feat(快递报价): 价格表右侧增加备注列,计费条件随确认单盖章并进入导出电子表 (#1020)
快递入驻填写的计费条件(执行时间、计费方式、是否计泡及抛比、起算重量、报价备注里的限长限重等) 原来在确认单里排在价格表下方、导出的报价电子表格里则完全没有,容易事后扯皮。 - 报价确认单 PDF(推送快递 e签宝盖章)与导出的报价 xlsx:价格表右侧增加「备注」列,逐行列出价格表以外的全部条件 - 新生成的入驻/变价报价补充口径:重量不取整说明、重量区间含上限、未列省份及空白价格不在报价范围、开票类型与税率、结算周期、附加费(除报价表及备注列明外不另收取) - 入驻表单报价备注下提示:要收的附加费须写在这里,没写视为不收取,并随确认单盖章 涉及:报价确认单与导出展示;已签署的确认单不变;不涉及迁移、权限和上游写入。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VANWYsNUbu2piMtCKymoyd
This commit is contained in:
parent
f5694567f2
commit
2a3ea39e72
@ -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<int,mixed> $values
|
||||
* @return array{table:list<list<string|int|float|null>>,notes:list<string>,row_keys:list<int|string>}
|
||||
*/
|
||||
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<list<mixed>>,notes:list<string>,row_keys:list<int|string>} $layout
|
||||
* @return array{rows:list<list<mixed>>,row_keys:list<int|string|null>}
|
||||
*/
|
||||
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
|
||||
|
||||
@ -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<string>
|
||||
*/
|
||||
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<string> $allowed
|
||||
*/
|
||||
|
||||
@ -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 @@
|
||||
|
||||
<h2>完整报价规则</h2>
|
||||
@if(! empty($billingRules))<p class="summary">{!! $mixedText($billingRules) !!}</p>@endif
|
||||
@php
|
||||
// 价格表右侧加「备注」列:价格表以外的计费条件(执行时间、计泡、起算重量、报价备注等)逐行列出,随确认单一起盖章。
|
||||
$quoteLayout = \App\Http\Controllers\Business\CourierQuoteSignatures::quoteTableWithNotes(\App\Http\Controllers\Business\CourierQuoteSignatures::quoteLayout($values));
|
||||
@endphp
|
||||
<table class="matrix">
|
||||
<tbody>
|
||||
@forelse($values as $rowIndex => $row)
|
||||
<tr>
|
||||
@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) !== '')<div class="formula">公式:{!! $mixedText($formula) !!}</div>@endif
|
||||
</{{ $rowIndex === 0 ? 'th' : 'td' }}>
|
||||
@if($quoteLayout['rows'] !== [])
|
||||
@foreach($quoteLayout['rows'] as $rowIndex => $row)
|
||||
@php($rowKey = $quoteLayout['row_keys'][$rowIndex] ?? null)
|
||||
@php($lastColumn = count($row) - 1)
|
||||
<tr>
|
||||
@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) !== '')<div class="formula">公式:{!! $mixedText($formula) !!}</div>@endif
|
||||
</{{ $rowIndex === 0 ? 'th' : 'td' }}>
|
||||
@endforeach
|
||||
</tr>
|
||||
@endforeach
|
||||
</tr>
|
||||
@empty
|
||||
<tr><td>该版本未保存可展示的报价矩阵。</td></tr>
|
||||
@endforelse
|
||||
@else
|
||||
@forelse($values as $rowIndex => $row)
|
||||
<tr>
|
||||
@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) !== '')<div class="formula">公式:{!! $mixedText($formula) !!}</div>@endif
|
||||
</{{ $rowIndex === 0 ? 'th' : 'td' }}>
|
||||
@endforeach
|
||||
</tr>
|
||||
@empty
|
||||
<tr><td>该版本未保存可展示的报价矩阵。</td></tr>
|
||||
@endforelse
|
||||
@endif
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
@ -615,6 +615,7 @@
|
||||
<div class="field">
|
||||
<label for="quote_note">报价备注</label>
|
||||
<textarea id="quote_note" name="quote_note" maxlength="2000" placeholder="如:限长限重、超长费、上楼费、偏远地区加价、深圳等城市单独价格">{{ $value('quote_note') }}</textarea>
|
||||
<span class="help">需要收取的附加费(超长超重、偏远地区、上楼、保价等)请在这里写清楚;没写的视为不收取。报价备注会原样写进报价确认单,由你方盖章确认。</span>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@ -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), [])
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user