From 1bbe6aff6c27949065b8cc1a665ed405e419d19a Mon Sep 17 00:00:00 2001 From: limeng <1131177064@qq.com> Date: Fri, 16 Oct 2026 21:33:20 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=BF=AB=E9=80=92=E5=BA=94=E4=BB=98):=20?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=85=8D=E4=BB=B6=E8=A1=A5=E5=8F=91=E6=89=A3?= =?UTF-8?q?=E6=AC=BE=E5=8C=B9=E9=85=8D=E5=8F=8A=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Business/AccessoryReshipDeductions.php | 29 +++++++ app/Http/Controllers/Business/Pages.php | 1 + config/business_navigation.php | 2 + docs/配件补发扣款.md | 19 +++++ .../Repositories/ShippingOrderRepository.php | 24 ++++++ .../Services/AccessoryReshipMatcher.php | 60 +++++++++++++++ .../View/AccessoryReshipPageData.php | 55 ++++++++++++++ .../accessory-reship-deductions.blade.php | 75 +++++++++++++++++++ routes/admin.php | 4 + tests/Unit/AccessoryReshipMatcherTest.php | 62 +++++++++++++++ tests/Unit/AccessoryReshipPageDataTest.php | 46 ++++++++++++ 11 files changed, 377 insertions(+) create mode 100644 app/Http/Controllers/Business/AccessoryReshipDeductions.php create mode 100644 docs/配件补发扣款.md create mode 100644 modules/EcommerceFinance/Services/AccessoryReshipMatcher.php create mode 100644 modules/EcommerceFinance/View/AccessoryReshipPageData.php create mode 100644 resources/views/business/pages/courier-payables/accessory-reship-deductions.blade.php create mode 100644 tests/Unit/AccessoryReshipMatcherTest.php create mode 100644 tests/Unit/AccessoryReshipPageDataTest.php diff --git a/app/Http/Controllers/Business/AccessoryReshipDeductions.php b/app/Http/Controllers/Business/AccessoryReshipDeductions.php new file mode 100644 index 00000000..1efd7c30 --- /dev/null +++ b/app/Http/Controllers/Business/AccessoryReshipDeductions.php @@ -0,0 +1,29 @@ +filters(); + // 先完成读取,失败时返回正常错误,避免下载半份扣款清单。 + $file = tmpfile(); + if ($file === false) abort(500, '无法创建导出文件。'); + fwrite($file, "\xEF\xBB\xBF"); + fputcsv($file, ['交易单号','补发快递单号','补发快递','补发时间','原始条形码','处理后条形码','补发运费','匹配状态','首发快递公司(候选)','首发快递单号(候选)','首发所属月份(候选)','扣款金额','说明']); + foreach ($data->rows($filters) as $row) { + if ($filters['match_status'] !== 'all' && $row['status'] !== $filters['match_status']) continue; + $values = [$row['trade_no'], $row['express_no'], ($row['express_name1'] ?: ($row['express_name2'] ?? '')), $row['ship_time'], $row['barcode'], $row['normalized_barcode'], $row['freight'], $row['status'] === 'matched' ? '可扣款' : '未匹配不扣款', implode(' / ', array_column($row['matches'], 'courier')), implode(' / ', array_column($row['matches'], 'express_no')), implode(' / ', array_column($row['matches'], 'month')), $row['deduction_cents'] === null ? '' : number_format($row['deduction_cents'] / 100, 2, '.', ''), $row['freight_cents'] === null ? '运费缺失或异常,待核实' : (count($row['matches']) > 1 ? '多候选待确认归属;运费只计一次' : '')]; + fputcsv($file, array_map(static function ($value) { + $value = (string) $value; + return preg_match('/^[=+\-@\t\r\n]/u', $value) ? "'" . $value : $value; + }, $values)); + } + rewind($file); + return response()->streamDownload(function () use ($file) { fpassthru($file); fclose($file); }, '配件补发扣款-' . $filters['month'] . '.csv', ['Content-Type' => 'text/csv; charset=UTF-8']); + } +} diff --git a/app/Http/Controllers/Business/Pages.php b/app/Http/Controllers/Business/Pages.php index 40b4ebe4..80137f1a 100644 --- a/app/Http/Controllers/Business/Pages.php +++ b/app/Http/Controllers/Business/Pages.php @@ -3272,6 +3272,7 @@ class Pages extends Controller 'courier-surcharge' => $this->contentForCourierSurcharge($tab), 'courier-surcharge-settlement' => $this->contentForCourierSurchargeSettlementPage(), 'freight-difference', 'other-surcharge-summary', 'return-fee' => $this->contentForCourierPayableSummary($page), + 'accessory-reship-deductions' => app(\Modules\EcommerceFinance\View\AccessoryReshipPageData::class)->page(), 'shipping-data' => $this->contentForShippingData(), 'return-pickup-management' => $this->contentForReturnPickupManagement(), 'withdrawal-management' => $this->contentForWithdrawalManagement(), diff --git a/config/business_navigation.php b/config/business_navigation.php index 9d2e7c83..85c85e29 100644 --- a/config/business_navigation.php +++ b/config/business_navigation.php @@ -656,6 +656,7 @@ $navigation = [ ['slug' => 'agreement-signing', 'title' => '协议签署'], ['slug' => 'freight-reconciliation', 'title' => '运费对账'], ['slug' => 'shipping-data', 'title' => '发货数据'], + ['slug' => 'accessory-reship-deductions', 'title' => '配件补发扣款'], ['slug' => 'third-party-warehouse-storage', 'title' => '三方仓进销存'], ['slug' => 'bookkeeping-details', 'title' => '记账明细'], ['slug' => 'compensation-details', 'title' => '赔偿明细'], @@ -720,6 +721,7 @@ $navigation = [ ], ['slug' => 'freight-reconciliation', 'title' => '运费对账'], ['slug' => 'shipping-data', 'title' => '发货数据'], + ['slug' => 'accessory-reship-deductions', 'title' => '配件补发扣款'], ['slug' => 'return-pickup-management', 'title' => '退货取件管理'], ['slug' => 'third-party-warehouse-storage', 'title' => '三方仓进销存'], ['slug' => 'warehouse-freight', 'title' => '仓储费'], diff --git a/docs/配件补发扣款.md b/docs/配件补发扣款.md new file mode 100644 index 00000000..6e05f117 --- /dev/null +++ b/docs/配件补发扣款.md @@ -0,0 +1,19 @@ +# 配件补发扣款 + +入口:快递应付 → 配件补发扣款。 + +选择业务年月后,读取发货数据中仓库为“常州简尚家居有限公司”的本月包裹,按现有发货数据的 source_id 合并口径汇总补发运费。配件条形码按明细顺序取第一个英文逗号前的值,去掉最后一个短横线及其后内容;首发条码只拆分英文逗号,不删除后缀。 + +首发候选限定业务月及前两个月(支持跨年)、仓库不为配件仓库、快递单号非空。使用完整交易单号和条码精确匹配。一个补发包裹始终只展示一行,重复候选去重;多首发候选仍归为可扣款,保留快递名称、快递单号和年月供核对,运费只统计一次。 + +金额来自发货数据的 freight,使用分汇总;缺失、负数或非数字运费显示待核实,不以零代替。页面提供可扣款、未匹配、全部三类局部切换和分页,CSV导出覆盖当前分类全部记录,不受分页限制。导出继承后台登录、公司上下文和本页权限,防止表格公式注入。 + +本版为匹配和扣款核对清单,不生成应付账记账记录;多候选的扣款归属尚需业务核对。本次无数据库迁移,无上游写入,无财务数据修改。 + +验证: + +- AccessoryReshipMatcherTest:首个配件条码、最后一个后缀、完整首发条码、交易单号、多候选去重、空单号、运费异常、精确金额。 +- AccessoryReshipPageDataTest:跨年三个月窗口、分页、汇总及多候选不重复计费。 +- 实际Blade页面检查:分类局部切换、分页、多候选提示、异常金额及手机/桌面布局。 +- 导出检查:路由优先级、本页权限、后台鉴权、UTF-8 BOM及公式保护。 +- 使用现有数据连接进行了真实业务月份只读匹配及性能验证。 diff --git a/modules/EcommerceFinance/Repositories/ShippingOrderRepository.php b/modules/EcommerceFinance/Repositories/ShippingOrderRepository.php index 3082afce..5fb9cb12 100644 --- a/modules/EcommerceFinance/Repositories/ShippingOrderRepository.php +++ b/modules/EcommerceFinance/Repositories/ShippingOrderRepository.php @@ -67,6 +67,30 @@ class ShippingOrderRepository return ['data' => $rows, 'total' => $total]; } + /** 仅批量读取本月配件及其交易单号对应的三个月首发候选;复用发货数据合并口径。 */ + public function accessoryReshipBatches(string $monthStart, string $nextMonth, string $windowStart): \Generator + { + $last = null; + while (true) { + $query = $this->db->table('jst_oms_shipping') + ->where('warehouse_name', \Modules\EcommerceFinance\Services\AccessoryReshipMatcher::WAREHOUSE) + ->where('ship_time', '>=', $monthStart)->where('ship_time', '<', $nextMonth); + if ($last !== null) $query->where('source_id', '>', $last); + // 指定条码顺序,保证“第一个条码”在重复匹配时稳定。 + $select = 'source_id, MAX(express_no) as express_no, MAX(trade_no) as trade_no, MAX(express_name1) as express_name1, MAX(express_name2) as express_name2, MAX(ship_time) as ship_time, SUM(freight) as freight, GROUP_CONCAT(DISTINCT barcode ORDER BY id SEPARATOR \',\' ) as barcode'; + $accessories = $query->groupBy('source_id')->selectRaw($select)->orderBy('source_id')->limit(1000)->get()->map(fn ($row) => (array) $row)->all(); + if ($accessories === []) return; + $trades = array_values(array_unique(array_filter(array_column($accessories, 'trade_no'), static fn ($trade) => trim((string) $trade) !== ''))); + $originals = $trades === [] ? [] : $this->db->table('jst_oms_shipping') + ->where('warehouse_name', '<>', \Modules\EcommerceFinance\Services\AccessoryReshipMatcher::WAREHOUSE) + ->where('ship_time', '>=', $windowStart)->where('ship_time', '<', $nextMonth) + ->whereIn('trade_no', $trades)->whereNotNull('express_no')->where('express_no', '<>', '') + ->select(['trade_no', 'barcode', 'express_no', 'express_name1', 'express_name2', 'ship_time', 'warehouse_name']) + ->get()->map(fn ($row) => (array) $row)->all(); + yield compact('accessories', 'originals'); + $last = $accessories[array_key_last($accessories)]['source_id']; + } + } /** 明细口径:无尺寸(0)的长宽高/体积显示为空白,对齐工作平台导出明细(合并保持 0)。 */ private function detailRow(array $r): array { diff --git a/modules/EcommerceFinance/Services/AccessoryReshipMatcher.php b/modules/EcommerceFinance/Services/AccessoryReshipMatcher.php new file mode 100644 index 00000000..e1dcbe02 --- /dev/null +++ b/modules/EcommerceFinance/Services/AccessoryReshipMatcher.php @@ -0,0 +1,60 @@ + 2 && (int) $decimal[2] >= 5 ? 1 : 0); + } + + public function match(array $accessories, iterable $originals): array + { + $index = []; + foreach ($originals as $original) { + if (trim((string) ($original['warehouse_name'] ?? '')) === self::WAREHOUSE || trim((string) ($original['express_no'] ?? '')) === '') continue; + $trade = trim((string) ($original['trade_no'] ?? '')); + if ($trade === '') continue; + foreach (explode(',', (string) ($original['barcode'] ?? '')) as $barcode) { + $barcode = trim($barcode); + if ($barcode === '') continue; + $key = json_encode([$trade, $barcode]); + $identity = json_encode([$original['express_no'], $original['express_name1'] ?? '', substr((string) $original['ship_time'], 0, 7)]); + $index[$key][$identity] = [ + 'express_no' => $original['express_no'], + 'courier' => ($original['express_name1'] ?? '') ?: ($original['express_name2'] ?? ''), + 'month' => substr((string) $original['ship_time'], 0, 7), + ]; + } + } + $result = []; + foreach ($accessories as $row) { + $barcode = self::barcode((string) ($row['barcode'] ?? '')); + $trade = trim((string) ($row['trade_no'] ?? '')); + $matches = ($barcode !== '' && $trade !== '') ? array_values($index[json_encode([$trade, $barcode])] ?? []) : []; + $row['normalized_barcode'] = $barcode; + $row['matches'] = $matches; + $row['status'] = $matches === [] ? 'unmatched' : 'matched'; + $row['freight_cents'] = self::cents($row['freight'] ?? null); + // 多候选仍属于可扣款;保持一条补发记录,运费不随候选数量放大。 + $row['deduction_cents'] = $matches === [] ? 0 : $row['freight_cents']; + $result[] = $row; + } + return $result; + } +} diff --git a/modules/EcommerceFinance/View/AccessoryReshipPageData.php b/modules/EcommerceFinance/View/AccessoryReshipPageData.php new file mode 100644 index 00000000..242fa5a1 --- /dev/null +++ b/modules/EcommerceFinance/View/AccessoryReshipPageData.php @@ -0,0 +1,55 @@ +query('month', now()->format('Y-m')); + abort_unless(is_string($month) && preg_match('/^\d{4}-(0[1-9]|1[0-2])$/', $month) && (int) substr($month, 0, 4) >= 2000, 422, '请选择有效业务月份。'); + $status = request()->query('match_status', 'matched'); + return ['month' => $month, 'match_status' => in_array($status, ['matched', 'unmatched', 'all'], true) ? $status : 'matched']; + } + + public function rows(array $filters): \Generator + { + $start = \Carbon\Carbon::createFromFormat('!Y-m', $filters['month']); + foreach ($this->shipping->accessoryReshipBatches($start->format('Y-m-d'), $start->copy()->addMonth()->format('Y-m-d'), $start->copy()->subMonths(2)->format('Y-m-d')) as $batch) { + foreach ($this->matcher->match($batch['accessories'], $batch['originals']) as $row) yield $row; + } + } + + public function page(): array + { + $filters = $this->filters(); + $page = max(1, (int) request('page', 1)); + $summary = ['all' => 0, 'matched' => 0, 'unmatched' => 0, 'amount' => 0, 'invalid_amount' => 0, 'ambiguous' => 0]; + $items = []; $total = 0; $error = null; + try { + foreach ($this->rows($filters) as $row) { + $summary['all']++; $summary[$row['status']]++; + if ($row['status'] === 'matched') { + $summary['amount'] += $row['deduction_cents'] ?? 0; + if ($row['deduction_cents'] === null) $summary['invalid_amount']++; + if (count($row['matches']) > 1) $summary['ambiguous']++; + } + if ($filters['match_status'] !== 'all' && $filters['match_status'] !== $row['status']) continue; + if ($total >= ($page - 1) * 50 && count($items) < 50) $items[] = $row; + $total++; + } + } catch (\Throwable $exception) { + report($exception); $error = '发货数据暂时无法读取,请检查数据连接或同步状态后重试。'; + $items = []; $total = 0; + $summary = array_fill_keys(array_keys($summary), 0); + } + return ['view' => 'business.pages.courier-payables.accessory-reship-deductions', 'reshipFilters' => $filters, 'reshipSummary' => $summary, 'reshipError' => $error, + 'reshipRows' => new LengthAwarePaginator($items, $total, 50, $page, ['path' => request()->url(), 'query' => request()->except('page')])]; + } +} diff --git a/resources/views/business/pages/courier-payables/accessory-reship-deductions.blade.php b/resources/views/business/pages/courier-payables/accessory-reship-deductions.blade.php new file mode 100644 index 00000000..53d26dbd --- /dev/null +++ b/resources/views/business/pages/courier-payables/accessory-reship-deductions.blade.php @@ -0,0 +1,75 @@ +@php + $filters = $reshipFilters; + $summary = $reshipSummary; + $labels = ['matched' => '可扣款项', 'unmatched' => '未匹配项', 'all' => '全部配件单']; + $startMonth = \Carbon\Carbon::createFromFormat('!Y-m', $filters['month'])->subMonths(2)->format('Y年n月'); +@endphp +
+

配件补发扣款

按交易单号及条形码匹配首发快递,核算配件补发运费。

快递应付
+
+ + + + @if (!$reshipError)导出当前分类@endif + 匹配范围:{{ $startMonth }} 至 {{ \Carbon\Carbon::createFromFormat('!Y-m', $filters['month'])->format('Y年n月') }} +
+
+ @foreach (['all' => '配件单数', 'matched' => '可扣款单数', 'unmatched' => '未匹配单数'] as $key => $label) +
{{ $label }}{{ $reshipError ? '—' : number_format($summary[$key]) }}
+ @endforeach +
可扣款总额(运费仅计一次){{ $reshipError ? '—' : '¥ ' . number_format($summary['amount'] / 100, 2) }}
+
+
匹配规则与扣款口径

配件仓库:常州简尚家居有限公司。配件条码取第一个英文逗号前的内容,再去掉最后一个“-”及其后内容。首发仓库排除该仓库,首发多个条码拆分后按完整条码匹配。仅匹配到首发快递单号的记录列为可扣款,金额取补发发货数据中的运费。

本页生成扣款核对清单,尚未记入应付账。多首发候选需确认归属,运费缺失或异常需核实;重复匹配不会新增扣款记录。

+ @if ($reshipError)@endif + @if ($summary['ambiguous'] || $summary['invalid_amount'])
多首发候选 {{ $summary['ambiguous'] }} 单,需确认归属;运费异常 {{ $summary['invalid_amount'] }} 单,暂未计入总额。
@endif +
+ +
+ @foreach (['交易单号','补发快递单号','补发快递','补发日期','原始条形码','处理后条形码','补发运费','匹配状态','首发快递 / 单号 / 所属月份','可扣金额','说明'] as $heading)@endforeach + + @forelse ($reshipRows as $row) + + @empty@endforelse +
{{ $heading }}
{{ $row['trade_no'] }}{{ $row['express_no'] }}{{ $row['express_name1'] ?: $row['express_name2'] }}{{ substr((string) $row['ship_time'], 0, 10) }}{{ $row['barcode'] }}{{ $row['normalized_barcode'] }}{{ $row['freight_cents'] === null ? '待核实' : number_format($row['freight_cents'] / 100, 2) }}{{ $row['status'] === 'matched' ? '可扣款' : '未匹配不扣款' }} + @forelse ($row['matches'] as $match)
{{ $match['courier'] ?: '快递名称待核实' }}
{{ $match['express_no'] }} ({{ $match['month'] }})
@empty — @endforelse +
{{ $row['deduction_cents'] === null ? '待核实' : number_format($row['deduction_cents'] / 100, 2) }}{{ $row['freight_cents'] === null ? '运费缺失或异常' : (count($row['matches']) > 1 ? '多候选,确认归属后扣款;仅计一次' : ($row['status'] === 'unmatched' ? '三个月内未匹配首发快递单号' : '待核对')) }}
{{ $reshipError ?: '当前月份及分类暂无记录,请调整业务月份或分类。' }}
+ +
+
+ +@push('body_end') + +@endpush diff --git a/routes/admin.php b/routes/admin.php index b2238732..0b6898d1 100644 --- a/routes/admin.php +++ b/routes/admin.php @@ -405,6 +405,10 @@ Route::get('workspace/courier-payables/courier-information/export', 'Business\Pa ->middleware('business.page:courier-payables,courier-information') ->name('business.courier-payables.courier-information.export'); +Route::get('workspace/courier-payables/accessory-reship-deductions/export', [\App\Http\Controllers\Business\AccessoryReshipDeductions::class, 'export']) + ->middleware('business.page:courier-payables,accessory-reship-deductions') + ->name('business.accessory-reship-deductions.export'); + Route::get('workspace/courier-payables/shipping-data/export', 'Business\Pages@exportShippingData') ->middleware('business.page:courier-payables,shipping-data') ->name('business.courier-payables.shipping-data.export'); diff --git a/tests/Unit/AccessoryReshipMatcherTest.php b/tests/Unit/AccessoryReshipMatcherTest.php new file mode 100644 index 00000000..1abf2a25 --- /dev/null +++ b/tests/Unit/AccessoryReshipMatcherTest.php @@ -0,0 +1,62 @@ + 'T001', 'warehouse_name' => '成品仓', 'barcode' => 'GBGJ-SJ038024N1410V02,OTHER-SKU', 'express_no' => 'SF001', 'express_name1' => '首发快递', 'ship_time' => '2026-08-01 12:00:00'], $changes); + } + private function accessory(array $changes = []): array + { + return array_replace(['trade_no' => 'T001', 'barcode' => 'GBGJ-SJ038024N1410V02-10,OTHER-SKU-2', 'freight' => '12.30'], $changes); + } + public function test_first_accessory_barcode_and_last_suffix_only(): void + { + $this->assertSame('GBGJ-SJ038024N1410V02', AccessoryReshipMatcher::barcode('GBGJ-SJ038024N1410V02-10,GBGJ-SJ038024N1410V02-2,GBGJ-SJ038024N1410V02-7')); + $this->assertSame('ABC', AccessoryReshipMatcher::barcode('ABC')); + $this->assertSame('', AccessoryReshipMatcher::barcode('')); + } + public function test_exact_trade_and_split_original_barcodes_without_normalizing_original(): void + { + $matcher = new AccessoryReshipMatcher; + $result = $matcher->match([$this->accessory(), $this->accessory(['barcode' => 'OTHER-SKU-2']), $this->accessory(['trade_no' => 'T002'])], [$this->original()]); + $this->assertSame(['matched', 'matched', 'unmatched'], array_column($result, 'status')); + $this->assertSame(1230, $result[0]['deduction_cents']); + $this->assertSame('2026-08', $result[0]['matches'][0]['month']); + $this->assertSame('unmatched', $matcher->match([$this->accessory()], [$this->original(['barcode' => 'GBGJ-SJ038024N1410V02-10'])])[0]['status']); + } + public function test_blank_waybill_accessory_warehouse_and_empty_keys_do_not_qualify(): void + { + $matcher = new AccessoryReshipMatcher; + $result = $matcher->match([$this->accessory(), $this->accessory(['trade_no' => '']), $this->accessory(['barcode' => ''])], [$this->original(['express_no' => ' ']), $this->original(['warehouse_name' => AccessoryReshipMatcher::WAREHOUSE])]); + $this->assertSame(['unmatched', 'unmatched', 'unmatched'], array_column($result, 'status')); + $this->assertSame([0, 0, 0], array_column($result, 'deduction_cents')); + } + public function test_multiple_matches_keep_one_deduction_and_deduplicate_same_waybill(): void + { + $matcher = new AccessoryReshipMatcher; + $originals = [$this->original(), $this->original(), $this->original(['express_no' => 'YTO002', 'express_name1' => '另一快递', 'ship_time' => '2026-09-01'])]; + $result = $matcher->match([$this->accessory()], $originals); + $this->assertCount(1, $result); + $this->assertCount(2, $result[0]['matches']); + $this->assertSame(1230, $result[0]['deduction_cents']); + $this->assertSame($result, $matcher->match([$this->accessory()], $originals)); + } + public function test_invalid_amount_stays_matched_but_cannot_supply_amount(): void + { + foreach ([null, '', '-2.00', 'abc'] as $value) { + $row = (new AccessoryReshipMatcher)->match([$this->accessory(['freight' => $value])], [$this->original()])[0]; + $this->assertSame('matched', $row['status']); + $this->assertNull($row['deduction_cents']); + } + $this->assertSame(1230, AccessoryReshipMatcher::cents('12.3000')); + $this->assertSame(1240, AccessoryReshipMatcher::cents('12.395')); + $this->assertSame(0, AccessoryReshipMatcher::cents('0.00')); + } +} diff --git a/tests/Unit/AccessoryReshipPageDataTest.php b/tests/Unit/AccessoryReshipPageDataTest.php new file mode 100644 index 00000000..e1e55ce6 --- /dev/null +++ b/tests/Unit/AccessoryReshipPageDataTest.php @@ -0,0 +1,46 @@ +shouldReceive('accessoryReshipBatches')->once()->with('2026-01-01', '2026-02-01', '2025-11-01')->andReturn((function () { yield ['accessories' => [['trade_no' => '001', 'barcode' => 'SKU-1', 'freight' => '2.50']], 'originals' => []]; })()); + $data = new AccessoryReshipPageData($repo, new AccessoryReshipMatcher); + $rows = iterator_to_array($data->rows(['month' => '2026-01'])); + $this->assertSame('unmatched', $rows[0]['status']); + $this->assertSame(0, $rows[0]['deduction_cents']); + } + + public function test_summary_does_not_duplicate_candidate_freight_and_paginates(): void + { + $request = Request::create('/workspace/courier-payables/accessory-reship-deductions?month=2026-09&match_status=all&page=2'); + Container::getInstance()->instance('request', $request); + $accessories = []; + for ($i = 0; $i < 105; $i++) $accessories[] = ['trade_no' => '001', 'barcode' => 'SKU-1', 'freight' => '0.10']; + $original = ['trade_no' => '001', 'barcode' => 'SKU', 'express_no' => 'FIRST', 'express_name1' => '快递', 'ship_time' => '2026-08-01', 'warehouse_name' => '成品仓']; + $repo = Mockery::mock(ShippingOrderRepository::class); + $repo->shouldReceive('accessoryReshipBatches')->andReturn((function () use ($accessories, $original) { yield ['accessories' => $accessories, 'originals' => [$original, array_replace($original, ['express_no' => 'SECOND'])]]; })()); + $data = (new AccessoryReshipPageData($repo, new AccessoryReshipMatcher))->page(); + $this->assertCount(50, $data['reshipRows']); + $this->assertSame(105, $data['reshipRows']->total()); + $this->assertSame(105, $data['reshipSummary']['matched']); + $this->assertSame(1050, $data['reshipSummary']['amount']); + $this->assertSame(105, $data['reshipSummary']['ambiguous']); + } +} -- 2.47.2