发货数据缺少计费重量时留空运费 (#1490)

This commit is contained in:
limeng 2026-11-26 21:48:03 +08:00
parent 8df3c3ec36
commit 7de0d3370f
2 changed files with 31 additions and 0 deletions

View File

@ -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;

View File

@ -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();