fix(运费核算): 四强圆通计费重量向上取整 #1708
@ -1233,6 +1233,7 @@ final class FreightCarrierRules
|
||||
'四强圆通' => [
|
||||
'mode' => 'A',
|
||||
'coef' => 10000,
|
||||
'ceil' => true,
|
||||
],
|
||||
'木际邮政' => [
|
||||
'mode' => 'E',
|
||||
|
||||
@ -13,6 +13,45 @@ use Tests\Feature\FeatureTestCase;
|
||||
|
||||
class ShippingFreightServiceTest extends FeatureTestCase
|
||||
{
|
||||
public function test_siqiang_yto_november_recalculation_rounds_up_and_preserves_other_scopes(): void
|
||||
{
|
||||
$this->version('QB-SQ', '四强圆通', '2026-09-01', null, [
|
||||
['省份', '面单费', '费率'], ['江苏', 3.5, 1.15],
|
||||
]);
|
||||
$db = DB::connection('business_mirror');
|
||||
$base = ['express_name1' => '四强圆通', 'warehouse_name' => '简尚-崔桥工厂仓',
|
||||
'ship_time' => '2026-11-03 12:00:00', 'receiver_state' => '江苏省',
|
||||
'qty' => 1, 'sku_source_id' => 1, 'barcode' => 'TEST-SQ'];
|
||||
foreach ([[901, 7.01], [902, 7.9], [903, 7.0]] as [$id, $weight]) {
|
||||
$db->table('jst_oms_shipping')->insert($base + [
|
||||
'source_id' => $id, 'express_no' => 'TEST-SQ-' . $id, 'online_weight' => $weight,
|
||||
]);
|
||||
}
|
||||
foreach ([904 => ['ship_time' => '2026-10-31 12:00:00'], 905 => ['express_name1' => '新北中通']] as $id => $overrides) {
|
||||
$db->table('jst_oms_shipping')->insert(array_replace($base, $overrides, [
|
||||
'source_id' => $id, 'express_no' => 'TEST-SQ-' . $id, 'online_weight' => 7.01,
|
||||
]));
|
||||
$db->table('jst_oms_shipping_freight')->insert([
|
||||
'source_id' => $id, 'status' => 'OK', 'freight' => 99, 'charge_weight' => 7.01,
|
||||
]);
|
||||
}
|
||||
$result = app(ShippingFreightService::class)->recalculate('2026-11-01', '2026-12-01', ['四强圆通']);
|
||||
|
||||
$this->assertSame(['packages' => 3, 'ok' => 3], $result);
|
||||
foreach ([901 => [7.01, 8, 12.70], 902 => [7.9, 8, 12.70], 903 => [7, 7, 11.55]] as $id => [$raw, $charge, $fee]) {
|
||||
$row = $db->table('jst_oms_shipping_freight')->where('source_id', $id)->sole();
|
||||
$this->assertEquals($raw, $row->base_weight);
|
||||
$this->assertEquals($charge, $row->charge_weight);
|
||||
$this->assertEquals($fee, $row->freight);
|
||||
$this->assertSame('QB-SQ', $row->quote_version);
|
||||
}
|
||||
foreach ([904, 905] as $id) {
|
||||
$row = $db->table('jst_oms_shipping_freight')->where('source_id', $id)->sole();
|
||||
$this->assertEquals(99, $row->freight);
|
||||
$this->assertEquals(7.01, $row->charge_weight);
|
||||
}
|
||||
}
|
||||
|
||||
public function test_return_carriers_use_reverse_quotes_and_persist_the_package_total(): void
|
||||
{
|
||||
$path = $this->bindReturnQuotes();
|
||||
|
||||
@ -28,6 +28,48 @@ class ShippingFreightCalculatorTest extends TestCase
|
||||
];
|
||||
}
|
||||
|
||||
public function test_siqiang_yto_rounds_charge_weight_up_without_changing_source_weight(): void
|
||||
{
|
||||
$calculator = new ShippingFreightCalculator();
|
||||
$quote = $this->quote([['省份', '面单费', '费率'], ['江苏', 3.5, 1.15]]);
|
||||
|
||||
foreach ([[7.01, 8.0], [7.9, 8.0], [7.0, 7.0]] as [$weight, $expected]) {
|
||||
$result = $calculator->calculate($this->pkg([
|
||||
'express_name1' => '四强圆通', 'online_weight' => $weight,
|
||||
'length_cm' => null, 'width_cm' => null, 'height_cm' => null,
|
||||
]), $quote, $this->cfg('四强圆通'));
|
||||
|
||||
$this->assertSame('OK', $result['status']);
|
||||
$this->assertSame($weight, $result['base_w']);
|
||||
$this->assertSame($weight, $result['settle_w']);
|
||||
$this->assertEquals($expected, $result['charge_w']);
|
||||
$this->assertSame(round(3.5 + 1.15 * $expected, 2), $result['fee']);
|
||||
$this->assertStringContainsString('重量向上取整', $result['formula']);
|
||||
}
|
||||
}
|
||||
|
||||
public function test_siqiang_yto_rounding_preserves_volume_and_free_warehouse_rules(): void
|
||||
{
|
||||
$calculator = new ShippingFreightCalculator();
|
||||
$quote = $this->quote([['省份', '面单费', '费率'], ['江苏', 3.5, 1.15]]);
|
||||
$package = $this->pkg([
|
||||
'express_name1' => '四强圆通', 'actual_weight' => 7.01,
|
||||
'length_cm' => 100, 'width_cm' => 100, 'height_cm' => 7.9,
|
||||
]);
|
||||
$result = $calculator->calculate($package, $quote, $this->cfg('四强圆通'));
|
||||
$this->assertSame(7.9, $result['settle_w']);
|
||||
$this->assertEquals(8, $result['charge_w']);
|
||||
$this->assertSame(12.7, $result['fee']);
|
||||
|
||||
$package['warehouse_name'] = '常州简尚家居有限公司';
|
||||
$package['actual_weight'] = 6.01;
|
||||
$result = $calculator->calculate($package, $quote, $this->cfg('四强圆通'));
|
||||
$this->assertTrue($result['free']);
|
||||
$this->assertSame(6.01, $result['settle_w']);
|
||||
$this->assertEquals(7, $result['charge_w']);
|
||||
$this->assertSame(11.55, $result['fee']);
|
||||
}
|
||||
|
||||
public function test_waybill_rate_uses_volume_weight_and_free_warehouses_do_not(): void
|
||||
{
|
||||
$calc = new ShippingFreightCalculator();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user