From 1e5dbafb16453821c306e89c1ae403deccba6c62 Mon Sep 17 00:00:00 2001 From: limeng <1131177064@qq.com> Date: Wed, 25 Nov 2026 17:42:03 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E6=8A=A5?= =?UTF-8?q?=E4=BB=B7=E5=8F=98=E6=9B=B4=E6=97=B6=E6=96=B0=E5=A2=9E=E7=9C=81?= =?UTF-8?q?=E4=BB=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Business/CourierQuoteChanges.php | 6 ++ app/Models/Business/CourierQuoteChange.php | 2 +- app/Support/CourierQuoteChangeExport.php | 5 +- app/Support/CourierQuoteChangeService.php | 22 ++++++- app/Support/CourierQuoteProvinceAdditions.php | 64 +++++++++++++++++++ .../quote-change-editor.blade.php | 30 +++++++++ .../quote-change-province-fields.blade.php | 17 +++++ .../quote-change-show.blade.php | 10 +++ .../CourierQuoteChangeWorkflowTest.php | 25 ++++++++ 9 files changed, 177 insertions(+), 4 deletions(-) create mode 100644 app/Support/CourierQuoteProvinceAdditions.php create mode 100644 resources/views/business/pages/courier-payables/quote-change-province-fields.blade.php diff --git a/app/Http/Controllers/Business/CourierQuoteChanges.php b/app/Http/Controllers/Business/CourierQuoteChanges.php index 63040157a..967ce31e7 100644 --- a/app/Http/Controllers/Business/CourierQuoteChanges.php +++ b/app/Http/Controllers/Business/CourierQuoteChanges.php @@ -381,6 +381,12 @@ class CourierQuoteChanges extends Controller 'summary' => ['required', 'string', 'min:2', 'max:2000'], 'quote_notes' => ['sometimes', 'array', 'max:500'], 'quote_notes.*' => ['nullable', 'string', 'max:10000'], + 'province_additions' => ['sometimes', 'array', 'max:34'], + 'province_additions.*' => ['array:region,prices,note'], + 'province_additions.*.region' => ['required', 'string', 'max:16', 'regex:/^[\p{Han}]+$/u'], + 'province_additions.*.prices' => ['required', 'array'], + 'province_additions.*.prices.*' => ['required', 'numeric', 'min:0', 'decimal:0,4'], + 'province_additions.*.note' => ['nullable', 'string', 'max:10000'], 'items' => ['required', 'array', 'min:1', 'max:500'], 'items.*.source_cell' => ['required', 'regex:/^[A-Z]+[1-9][0-9]*$/'], 'items.*.source_row' => ['required', 'integer', 'min:0'], diff --git a/app/Models/Business/CourierQuoteChange.php b/app/Models/Business/CourierQuoteChange.php index 6fb7d8a5f..49a8d3489 100644 --- a/app/Models/Business/CourierQuoteChange.php +++ b/app/Models/Business/CourierQuoteChange.php @@ -72,7 +72,7 @@ class CourierQuoteChange extends Model public function hasQuotePayload(): bool { - return is_array($this->quote_payload) && array_diff_key($this->quote_payload, ['execution_periods' => true, 'quote_notes' => true]) !== []; + return is_array($this->quote_payload) && array_diff_key($this->quote_payload, ['execution_periods' => true, 'quote_notes' => true, 'province_additions' => true]) !== []; } public function isStockQuote(): bool diff --git a/app/Support/CourierQuoteChangeExport.php b/app/Support/CourierQuoteChangeExport.php index e55ec91c3..805a683ea 100644 --- a/app/Support/CourierQuoteChangeExport.php +++ b/app/Support/CourierQuoteChangeExport.php @@ -95,7 +95,10 @@ final class CourierQuoteChangeExport $values[$item->source_row][$item->source_column] = $item->new_amount; } - return [$values, $source['billing_rules'] ?? null]; + $source['values'] = $values; + $source = CourierQuoteProvinceAdditions::apply($source, $change->quote_payload['province_additions'] ?? []); + + return [$source['values'], $source['billing_rules'] ?? null]; } private function text(Worksheet $sheet, string $address, mixed $value): void diff --git a/app/Support/CourierQuoteChangeService.php b/app/Support/CourierQuoteChangeService.php index c28f04ea3..1e17c4d2c 100644 --- a/app/Support/CourierQuoteChangeService.php +++ b/app/Support/CourierQuoteChangeService.php @@ -29,6 +29,11 @@ final class CourierQuoteChangeService $data = CourierQuotePeriods::normalize($data); $data['quote_payload'] = CourierQuotePeriods::payload($data['quote_payload'] ?? null, $data['execution_periods']); $data['quote_payload'] = CourierQuoteNotes::payload($data['quote_payload'], $data, $source); + unset($data['quote_payload']['province_additions']); + if (!empty($data['province_additions'])) { + CourierQuoteProvinceAdditions::apply($source, $data['province_additions']); + $data['quote_payload']['province_additions'] = $data['province_additions']; + } } return DB::transaction(function () use ($data, $userId, $source): CourierQuoteChange { @@ -72,6 +77,11 @@ final class CourierQuoteChangeService $data = CourierQuotePeriods::normalize($data + ['end_date' => $change->end_date?->toDateString()]); $data['quote_payload'] = CourierQuotePeriods::payload($change->quote_payload, $data['execution_periods']); $data['quote_payload'] = CourierQuoteNotes::payload($data['quote_payload'], $data, $source); + unset($data['quote_payload']['province_additions']); + if (!empty($data['province_additions'])) { + CourierQuoteProvinceAdditions::apply($source, $data['province_additions']); + $data['quote_payload']['province_additions'] = $data['province_additions']; + } } return DB::transaction(function () use ($change, $data, $userId, $source): CourierQuoteChange { @@ -103,7 +113,7 @@ final class CourierQuoteChangeService { $this->ensureEditableBy($change, $userId); - if (! ($change->isStockQuote() && filled($change->proposed_values_json)) && $change->items()->count() === 0 && empty($change->quote_payload['quote_notes'])) { + if (! ($change->isStockQuote() && filled($change->proposed_values_json)) && $change->items()->count() === 0 && empty($change->quote_payload['quote_notes']) && empty($change->quote_payload['province_additions'])) { throw ValidationException::withMessages(['items' => '至少需要一条发生变化的报价明细。']); } @@ -231,6 +241,13 @@ final class CourierQuoteChangeService $values[$item->source_row][$item->source_column] = $item->new_amount; } + $expanded = CourierQuoteProvinceAdditions::apply( + ['values' => $values, 'formulas' => $formulas], + $change->quote_payload['province_additions'] ?? [] + ); + $values = $expanded['values']; + $formulas = $expanded['formulas']; + $importedVersionCount = collect($this->snapshot->load()['quotes'] ?? []) ->whereNull('source_change_id') ->count(); @@ -351,7 +368,7 @@ final class CourierQuoteChangeService ]); } - if ($change->items()->count() === 0 && empty($change->quote_payload['quote_notes'])) { + if ($change->items()->count() === 0 && empty($change->quote_payload['quote_notes']) && empty($change->quote_payload['province_additions'])) { throw ValidationException::withMessages(['items' => '至少需要一条原价格与新价格不同的变价明细。']); } } @@ -399,6 +416,7 @@ final class CourierQuoteChangeService 'end_date' => $change->end_date?->toDateString(), 'execution_periods' => $change->executionPeriods(), 'quote_notes' => $change->quote_payload['quote_notes'] ?? [], + 'province_additions' => $change->quote_payload['province_additions'] ?? [], 'is_retrospective' => $change->isRetrospective(), 'recalculation_status' => $change->recalculation_status, 'recalculation_note' => $change->recalculation_note, diff --git a/app/Support/CourierQuoteProvinceAdditions.php b/app/Support/CourierQuoteProvinceAdditions.php new file mode 100644 index 000000000..8f981276b --- /dev/null +++ b/app/Support/CourierQuoteProvinceAdditions.php @@ -0,0 +1,64 @@ + $label) { + if ($column === 0 || blank($label)) continue; + if (preg_match('/^(报价备注|备注|说明)[::]?$/u', trim($label))) { + $remarks = $column; + } elseif (collect($rows)->contains(fn ($row) => is_numeric($row[$column] ?? null))) { + $columns[$column] = (string) $label; + } + } + + return [$columns, $remarks, array_map(fn ($row) => (string) ($row[0] ?? ''), $rows), $layout['row_keys']]; + } + + public static function apply(array $source, array $additions): array + { + if ($additions === []) return $source; + + [$columns, $remarks, $regions, $rowKeys] = self::fields($source); + $normalize = static fn ($name) => preg_replace('/(?:壮族自治区|回族自治区|维吾尔自治区|自治区|特别行政区|省|市)$/u', '', trim($name)); + $existing = array_map($normalize, preg_split('/[、,,\/\s;;++]+/u', implode('、', $regions), -1, PREG_SPLIT_NO_EMPTY)); + $rows = []; + foreach ($additions as $index => $addition) { + $region = $normalize($addition['region']); + if ($region === '' || in_array($region, $existing, true)) { + throw ValidationException::withMessages(["province_additions.$index.region" => '省份已存在,请直接编辑原报价行。']); + } + if ($columns === [] || array_keys($columns) !== array_keys(array_intersect_key($columns, $addition['prices'])) || array_diff_key($addition['prices'], $columns)) { + throw ValidationException::withMessages(["province_additions.$index.prices" => '请填写该省份的全部价格列。']); + } + $existing[] = $region; + $row = array_fill(0, max(array_keys($columns)) + 1, null); + $row[0] = $addition['region']; + foreach ($columns as $column => $label) { + $row[$column] = (float) $addition['prices'][$column]; + } + if ($remarks !== null) $row[$remarks] = $addition['note'] ?? null; + ksort($row); + $rows[] = array_replace(array_fill(0, max(array_keys($row)) + 1, null), $row); + } + + $offset = (int) end($rowKeys) + 1; + $formulas = array_replace(array_fill(0, count($source['values']), []), $source['formulas']); + array_splice($source['values'], $offset, 0, $rows); + array_splice($formulas, $offset, 0, array_fill(0, count($rows), [])); + $source['formulas'] = $formulas; + + return $source; + } +} diff --git a/resources/views/business/pages/courier-payables/quote-change-editor.blade.php b/resources/views/business/pages/courier-payables/quote-change-editor.blade.php index ce5816050..513f17f5b 100644 --- a/resources/views/business/pages/courier-payables/quote-change-editor.blade.php +++ b/resources/views/business/pages/courier-payables/quote-change-editor.blade.php @@ -202,6 +202,21 @@ + @php([$provinceColumns, $provinceRemarks] = \App\Support\CourierQuoteProvinceAdditions::fields($source)) + @if($provinceColumns) +
仅新增原报价没有的省份。新增报价随本次变价审核生效。
+