From 7de0d3370f53665ffe7976c74e0674e894e18d29 Mon Sep 17 00:00:00 2001 From: limeng <1131177064@qq.com> Date: Thu, 26 Nov 2026 21:48:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=91=E8=B4=A7=E6=95=B0=E6=8D=AE=E7=BC=BA?= =?UTF-8?q?=E5=B0=91=E8=AE=A1=E8=B4=B9=E9=87=8D=E9=87=8F=E6=97=B6=E7=95=99?= =?UTF-8?q?=E7=A9=BA=E8=BF=90=E8=B4=B9=20(#1490)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Freight/ShippingFreightCalculator.php | 6 +++++ .../ShippingFreightCalculatorTest.php | 25 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/modules/EcommerceFinance/Services/Freight/ShippingFreightCalculator.php b/modules/EcommerceFinance/Services/Freight/ShippingFreightCalculator.php index ab62ea30..503c8f29 100644 --- a/modules/EcommerceFinance/Services/Freight/ShippingFreightCalculator.php +++ b/modules/EcommerceFinance/Services/Freight/ShippingFreightCalculator.php @@ -176,6 +176,12 @@ final class ShippingFreightCalculator } } + if ($settle <= 0 && ! in_array($m, ['F', 'PERQTY'], true)) { + $d['settle_w'] = null; + + return $bad('缺少有效计费重量'); + } + switch ($m) { case '_PERKG': break; diff --git a/tests/Unit/EcommerceFinance/ShippingFreightCalculatorTest.php b/tests/Unit/EcommerceFinance/ShippingFreightCalculatorTest.php index b3df0b4e..288299a1 100644 --- a/tests/Unit/EcommerceFinance/ShippingFreightCalculatorTest.php +++ b/tests/Unit/EcommerceFinance/ShippingFreightCalculatorTest.php @@ -53,6 +53,31 @@ class ShippingFreightCalculatorTest extends TestCase $this->assertSame(9.8, $r['fee']); } + public function test_missing_weight_blocks_weight_based_quotes_but_allows_flat_per_package_price(): void + { + $calc = new ShippingFreightCalculator(); + $pkg = $this->pkg([ + 'actual_weight' => null, 'online_weight' => 0, 'weight_kg' => null, + 'length_cm' => null, 'width_cm' => null, 'height_cm' => null, + ]); + + $weightQuote = $this->quote([['省份', '面单', '费率'], ['江苏', 3.5, 0.7]]); + $result = $calc->calculate($pkg, $weightQuote, $this->cfg('新北中通')); + $this->assertSame('缺少有效计费重量', $result['status']); + $this->assertNull($result['fee']); + $this->assertNull($result['settle_w']); + + $pkg['volume_cm3'] = 60000; + $result = $calc->calculate($pkg, $weightQuote, $this->cfg('新北中通')); + $this->assertSame('OK', $result['status']); + $this->assertSame(8.75, $result['fee']); + + $flatQuote = $this->quote([['省份', '一口价'], ['江苏', 5.2]]); + $result = $calc->calculate($pkg, $flatQuote, $this->cfg('苏北极兔-滚轮')); + $this->assertSame('OK', $result['status']); + $this->assertSame(5.2, $result['fee']); + } + public function test_first_weight_with_extra_pieces_and_over_length(): void { $calc = new ShippingFreightCalculator();