fix(发货核算): 补齐横林顺丰源沃圆通飞燕EMS规则
This commit is contained in:
parent
b461f95820
commit
7624be08d0
@ -32,6 +32,12 @@ final class FreightCarrierRules
|
||||
public static function all(): array
|
||||
{
|
||||
return [
|
||||
'横林顺丰干配' => ['mode' => 'C', 'first' => 3, 'minw' => 3, 'coef' => 6000],
|
||||
'源沃圆通' => [
|
||||
'mode' => 'FMD', 'flat_max' => 5, 'md_col' => 7, 'rate_col' => 6,
|
||||
'coef' => 10000, 'rate_max' => 30, 'perkg_min_weight' => 1,
|
||||
],
|
||||
'飞燕EMS' => ['mode' => 'E', 'coef' => null, 'max_weight' => 100],
|
||||
'尚然极兔' => [
|
||||
'mode' => 'E', 'coef' => 8000,
|
||||
// 原表将 2-3、3-4 保存为 Excel 日期序列,仅修正这两家表头。
|
||||
|
||||
@ -512,9 +512,13 @@ final class ShippingFreightCalculator
|
||||
$md = isset($cfg['md_col']) ? $g((int) $cfg['md_col']) : (float) $cfg['md'];
|
||||
if (preg_match('/^\s*([\d.]+)\s*元\/kg/iu', QuoteSheet::text($g(1)), $pk) && ! $need($g(2))) {
|
||||
$x = (float) $pk[1];
|
||||
$fee = $x * $w;
|
||||
$perKgWeight = max($w, (float) ($cfg['perkg_min_weight'] ?? 0));
|
||||
$fee = $x * $perKgWeight;
|
||||
$d['rate'] = $x;
|
||||
$F = "整省按{$f($x)}元/kg×{$f($w)}kg";
|
||||
$F = "整省按{$f($x)}元/kg×{$f($perKgWeight)}kg";
|
||||
if ($perKgWeight > $w) {
|
||||
$F .= "(最低收费{$f($fee)})";
|
||||
}
|
||||
}
|
||||
$bands = array_values(array_filter(QuoteSheet::bands($head, $rc > 1 ? range(1, $rc - 1) : []), static fn ($s) => $s[1] <= $fm + 0.0001));
|
||||
if ($fee !== null) {
|
||||
@ -529,6 +533,9 @@ final class ShippingFreightCalculator
|
||||
$d['flat'] = $v;
|
||||
$F = "{$f($w)}kg落在{$seg}段,一口价{$f($v)}";
|
||||
} else {
|
||||
if (isset($cfg['rate_max']) && $w > $cfg['rate_max']) {
|
||||
return $bad('超出报价公斤段(' . number_format($w, 2, '.', '') . 'kg)');
|
||||
}
|
||||
$b = $g($rc);
|
||||
if (! $need($b, $md)) {
|
||||
return $bad('报价单元格无数值(' . self::show($md) . ',' . self::show($b) . ')');
|
||||
|
||||
70
tests/Unit/EcommerceFinance/ThreeCarrierBillingRulesTest.php
Normal file
70
tests/Unit/EcommerceFinance/ThreeCarrierBillingRulesTest.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\EcommerceFinance;
|
||||
|
||||
use Modules\EcommerceFinance\Services\Freight\FreightCarrierRules;
|
||||
use Modules\EcommerceFinance\Services\Freight\QuoteSheet;
|
||||
use Modules\EcommerceFinance\Services\Freight\ShippingFreightCalculator;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ThreeCarrierBillingRulesTest extends TestCase
|
||||
{
|
||||
private function calculate(string $name, array $values, float $weight, array $package = []): array
|
||||
{
|
||||
return (new ShippingFreightCalculator())->calculate($package + [
|
||||
'receiver_state' => '江苏省', 'warehouse_name' => '测试仓', 'actual_weight' => $weight,
|
||||
], ['id' => 'TEST-QUOTE', 'p' => QuoteSheet::parse($values), 'vals' => $values, 'rules' => ''],
|
||||
FreightCarrierRules::for($name) + ['_name' => $name]);
|
||||
}
|
||||
|
||||
public function test_henglin_uses_three_kg_first_weight_and_unrounded_volume_weight(): void
|
||||
{
|
||||
$values = [['省份', '首重3kg', '费率1kg', '备注'], ['江苏', 9, 2, '测试数据']];
|
||||
foreach ([[0.5, 9], [3, 9], [3.25, 9.5], [12, 27]] as [$weight, $fee]) {
|
||||
$r = $this->calculate('横林顺丰干配', $values, $weight);
|
||||
$this->assertSame('OK', $r['status']);
|
||||
$this->assertSame((float) $fee, $r['fee']);
|
||||
}
|
||||
$r = $this->calculate('横林顺丰干配', $values, 1, ['volume_cm3' => 39000]);
|
||||
$this->assertSame(6.5, $r['settle_w']);
|
||||
$this->assertSame(16.0, $r['fee']);
|
||||
$r = $this->calculate('横林顺丰干配', $values, 8, ['measured_weight' => 4]);
|
||||
$this->assertSame('称重重量', $r['base_src']);
|
||||
$this->assertSame(11.0, $r['fee']);
|
||||
$this->assertNull($this->calculate('横林顺丰干配', $values, 0)['fee']);
|
||||
}
|
||||
|
||||
public function test_yuanwo_uses_flat_bands_then_waybill_plus_rate_and_remote_minimum(): void
|
||||
{
|
||||
$values = [['省份', '0-1kg', '1.01-2kg', '2.01-3kg', '3.01-4kg', '4.01-5kg', '5.01-30kg费率', '面单费', '备注'],
|
||||
[null, '元/票', '元/票', '元/票', '元/票', '元/票', null, null, null],
|
||||
['江苏', 3, 4, 5, 6, 7, 2, 3, '测试数据'], ['海南', '7元/kg最低收费7元']];
|
||||
foreach ([[1, 3], [1.001, 4], [2, 4], [3, 5], [4, 6], [5, 7], [5.1, 13.2], [30, 63]] as [$weight, $fee]) {
|
||||
$r = $this->calculate('源沃圆通', $values, $weight);
|
||||
$this->assertSame('OK', $r['status']);
|
||||
$this->assertSame((float) $fee, $r['fee']);
|
||||
}
|
||||
$this->assertNull($this->calculate('源沃圆通', $values, 30.1)['fee']);
|
||||
$r = $this->calculate('源沃圆通', $values, 0.2, ['receiver_state' => '海南省']);
|
||||
$this->assertSame(7.0, $r['fee']);
|
||||
$this->assertStringContainsString('最低收费7', $r['formula']);
|
||||
$this->assertSame(21.0, $this->calculate('源沃圆通', $values, 3, ['receiver_state' => '海南省'])['fee']);
|
||||
$r = $this->calculate('源沃圆通', $values, 1, ['volume_cm3' => 60000]);
|
||||
$this->assertSame(15.0, $r['fee']);
|
||||
}
|
||||
|
||||
public function test_ems_has_one_price_up_to_one_hundred_kg_and_does_not_price_no_service_regions(): void
|
||||
{
|
||||
$values = [['公斤段', '0-100kg', '备注'], ['省份', '一口价', null],
|
||||
['江苏', 12, '测试数据'], ['黑龙', 40], ['新疆', '不发'], ['西藏', '不发']];
|
||||
foreach ([0.5, 100] as $weight) {
|
||||
$r = $this->calculate('飞燕EMS', $values, $weight, ['volume_cm3' => 9000000]);
|
||||
$this->assertSame('OK', $r['status']);
|
||||
$this->assertSame(12.0, $r['fee']);
|
||||
}
|
||||
$this->assertSame(40.0, $this->calculate('飞燕EMS', $values, 10, ['receiver_state' => '黑龙江省'])['fee']);
|
||||
$this->assertNull($this->calculate('飞燕EMS', $values, 100.1)['fee']);
|
||||
$this->assertNull($this->calculate('飞燕EMS', $values, 10, ['receiver_state' => '新疆维吾尔自治区'])['fee']);
|
||||
$this->assertNull($this->calculate('飞燕EMS', $values, 0)['fee']);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user