From dcf67ef58a8376edbfe1e06055e92f3ef7940d85 Mon Sep 17 00:00:00 2001 From: limeng <1131177064@qq.com> Date: Thu, 3 Dec 2026 12:09:58 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E4=BB=A3=E5=8F=91=E5=AF=BC=E5=87=BA):=20?= =?UTF-8?q?=E6=9C=AA=E6=A0=B8=E7=AE=97=E7=BB=93=E7=AE=97=E9=87=91=E9=A2=9D?= =?UTF-8?q?=E4=BF=9D=E7=95=99=E7=A9=BA=E7=99=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DropshipFreight/DropshipExporter.php | 5 +++- .../Feature/Business/DropshipFreightTest.php | 30 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/app/Support/DropshipFreight/DropshipExporter.php b/app/Support/DropshipFreight/DropshipExporter.php index 496894398..87322690e 100644 --- a/app/Support/DropshipFreight/DropshipExporter.php +++ b/app/Support/DropshipFreight/DropshipExporter.php @@ -162,7 +162,10 @@ final class DropshipExporter } if (in_array($r['status'], DropshipReconciler::PAYABLE, true)) { $billTotal = (float) $billTotal + (float) $r['bill']; - $settleTotal = (float) $settleTotal + (float) ($r['final'] ?? $r['settle']); + $final = $r['final'] ?? $r['settle']; + if ($final !== null) { + $settleTotal = (float) $settleTotal + (float) $final; + } } elseif ($r['status'] === Category::LATER) { $label = Category::label(Category::LATER, (string) $r['status_month']); $extras[$label] = (float) ($extras[$label] ?? 0) + (float) $r['bill']; diff --git a/tests/Feature/Business/DropshipFreightTest.php b/tests/Feature/Business/DropshipFreightTest.php index bbc0a40f0..a97a546be 100644 --- a/tests/Feature/Business/DropshipFreightTest.php +++ b/tests/Feature/Business/DropshipFreightTest.php @@ -445,6 +445,36 @@ final class DropshipFreightTest extends FeatureTestCase @unlink($out); } + public function test_export_keeps_uncalculated_settlement_blank(): void + { + Storage::fake('local'); + $db = CourierBillMatcher::db(); + $factoryId = $db->table('dropship_factories')->insertGetId(['name' => '未核算测试厂家', 'warehouse' => self::WAREHOUSE, + 'keywords' => '测试快递', 'created_at' => now(), 'updated_at' => now()]); + $this->ship('UNCALCULATED0001', '测试快递', self::WAREHOUSE, '2026-11-03 09:00:00', 1, null); + $input = $this->xlsx(['账单' => [['快递单号', '运费'], ['UNCALCULATED0001', 6]]]); + $output = tempnam(sys_get_temp_dir(), 'uncalculated_export_'); + $book = null; + try { + $store = app(DropshipFreightStore::class); + $store->uploadFor('未核算.xlsx', $input, '2026-11', $factoryId, '测试'); + $handle = fopen($output, 'wb'); + try { + app(DropshipExporter::class)->export(collect($store->factories())->sole(), '2026-11', $handle); + } finally { + fclose($handle); + } + $book = \PhpOffice\PhpSpreadsheet\IOFactory::load($output); + $this->assertSame('运费', (string) $book->getSheetByName('汇总')->getCell('A2')->getValue()); + $this->assertEquals(6, $book->getSheetByName('汇总')->getCell('B2')->getValue()); + $this->assertNull($book->getSheetByName('汇总')->getCell('C2')->getValue()); + } finally { + $book?->disconnectWorksheets(); + @unlink($input); + @unlink($output); + } + } + public function test_keyword_helpers(): void { $this->assertSame('卿德客', DropshipFreightStore::warehouseCore('工厂-山东卿德客代发仓'));