fix(逆向物流报价): 统一快递名称并保留退货计费匹配 (#1653)
This commit is contained in:
parent
e1a6d311d3
commit
dedb8b7f0e
@ -11,10 +11,14 @@ namespace App\Support;
|
||||
class ReturnPickupFreightCalculator
|
||||
{
|
||||
private const CARRIER_MAP = [
|
||||
'速寄递' => '申通',
|
||||
'申通' => '申通',
|
||||
'德邦' => '德邦',
|
||||
'中通快运' => '中通快运',
|
||||
'速寄递' => '申通退货',
|
||||
'申通' => '申通退货',
|
||||
'申通退货' => '申通退货',
|
||||
'德邦' => '常州德邦逆向',
|
||||
'常州德邦' => '常州德邦逆向',
|
||||
'常州德邦逆向' => '常州德邦逆向',
|
||||
'中通快运' => '中通快运逆向',
|
||||
'中通快运逆向' => '中通快运逆向',
|
||||
];
|
||||
|
||||
private const PROVINCES = [
|
||||
|
||||
@ -689,6 +689,12 @@ final class ReverseLogisticsQuoteSnapshot
|
||||
|
||||
private function inferCompanyName(string $name): string
|
||||
{
|
||||
foreach (['申通' => '申通退货', '常州德邦' => '常州德邦逆向', '中通快运' => '中通快运逆向',
|
||||
'中铁' => '中铁客退', '常州松宇货运' => '常州松宇货运'] as $match => $displayName) {
|
||||
if (str_contains($name, $match)) {
|
||||
return $displayName;
|
||||
}
|
||||
}
|
||||
$companyName = trim((string) preg_replace('/(?:逆向|退货|报价表|报价)$/u', '', $name));
|
||||
|
||||
return $companyName !== '' ? $companyName : $name;
|
||||
@ -696,6 +702,11 @@ final class ReverseLogisticsQuoteSnapshot
|
||||
|
||||
private function inferCarrier(string $name): string
|
||||
{
|
||||
foreach (['申通' => '申通退货', '常州德邦' => '常州德邦逆向', '中通快运' => '中通快运逆向'] as $match => $carrier) {
|
||||
if (str_contains($name, $match)) {
|
||||
return $carrier;
|
||||
}
|
||||
}
|
||||
if (str_contains($name, '中铁')) return '中铁客退';
|
||||
if (str_contains($name, '松宇')) return '常州松宇货运';
|
||||
|
||||
|
||||
@ -81,6 +81,7 @@ final class ReturnPickupFreightCalculatorTest extends TestCase
|
||||
$this->assertTrue($shentong['covered']);
|
||||
$this->assertSame(14.0, $shentong['billable']);
|
||||
$this->assertSame(31.75, $shentong['total']);
|
||||
$this->assertSame($shentong, $calculator->calculate('申通退货', '湖南省', '江苏省宿迁市沭阳县某处', 13.4, 93, 13, 13));
|
||||
$this->assertSame('面单 9 + 续重 1.75 ×(14 − 1)', $shentong['formula']);
|
||||
|
||||
// 德邦:面单 + 费率 × 重量,不取整,不加 15kg 下限。
|
||||
@ -88,6 +89,7 @@ final class ReturnPickupFreightCalculatorTest extends TestCase
|
||||
$this->assertTrue($deppon['covered']);
|
||||
$this->assertSame(8.7, $deppon['billable']);
|
||||
$this->assertSame(17.7, $deppon['total']);
|
||||
$this->assertSame($deppon, $calculator->calculate('常州德邦逆向', '浙江', '江苏省常州市某处', 8.7, 116, 35, 11));
|
||||
|
||||
// 德邦超长/超三边:加收单列 7 元,不并入运费;体积重 170×35×11÷6000 = 10.91kg 大于毛重。
|
||||
$depponOversize = $calculator->calculate('德邦', '浙江', '江苏省常州市某处', 8.7, 170, 35, 11);
|
||||
@ -102,6 +104,7 @@ final class ReturnPickupFreightCalculatorTest extends TestCase
|
||||
$this->assertTrue($zto['covered']);
|
||||
$this->assertSame(40.0, $zto['billable']);
|
||||
$this->assertSame(47.0, $zto['total']);
|
||||
$this->assertSame($zto, $calculator->calculate('中通快运逆向', '浙江省', '江苏省常州市某处', 39.1, 112, 45, 24));
|
||||
$this->assertSame(0.0, $zto['surcharge']);
|
||||
$this->assertSame('面单 9 + 费率 0.95 × 40(31-60kg)', $zto['formula']);
|
||||
$this->assertStringContainsString('重量取大:max(毛重 39.1kg,体积重 20.16kg) = 39.1kg', (string) $zto['process']);
|
||||
|
||||
@ -86,7 +86,7 @@ final class ReverseLogisticsQuoteSnapshotTest extends TestCase
|
||||
|
||||
$this->assertTrue($snapshot['available']);
|
||||
$this->assertSame(['未识别报价表'], $snapshot['unparsed_sheets']);
|
||||
$this->assertSame(['申通', '德邦', '中通快运'], array_column($snapshot['rate_groups'], 'carrier'));
|
||||
$this->assertSame(['申通退货', '常州德邦逆向', '中通快运逆向'], array_column($snapshot['rate_groups'], 'carrier'));
|
||||
$this->assertSame(10, $snapshot['rate_summary']['rate_count']);
|
||||
$this->assertSame(8, $snapshot['rate_summary']['available_count']);
|
||||
$this->assertSame(2, $snapshot['rate_summary']['missing_count']);
|
||||
@ -96,25 +96,25 @@ final class ReverseLogisticsQuoteSnapshotTest extends TestCase
|
||||
|
||||
$rules = collect($snapshot['rate_groups'])->keyBy('carrier');
|
||||
|
||||
$this->assertSame(4, $rules['申通']['rate_count']);
|
||||
$this->assertSame('2026-05-01', $rules['申通']['effective_date']);
|
||||
$this->assertSame('首重 + 续重 × (结算重量 - 1)', $rules['申通']['pricing_label']);
|
||||
$this->assertSame('行=出发省份,列=到达省份(2 个到达省)', $rules['申通']['route_label']);
|
||||
$this->assertContains('4、计泡标准:长*宽*高/6000', $rules['申通']['constraints']);
|
||||
$this->assertSame(4, $rules['申通退货']['rate_count']);
|
||||
$this->assertSame('2026-05-01', $rules['申通退货']['effective_date']);
|
||||
$this->assertSame('首重 + 续重 × (结算重量 - 1)', $rules['申通退货']['pricing_label']);
|
||||
$this->assertSame('行=出发省份,列=到达省份(2 个到达省)', $rules['申通退货']['route_label']);
|
||||
$this->assertContains('4、计泡标准:长*宽*高/6000', $rules['申通退货']['constraints']);
|
||||
|
||||
$this->assertSame(2, $rules['德邦']['rate_count']);
|
||||
$this->assertSame('2026-04-07', $rules['德邦']['effective_date']);
|
||||
$this->assertSame('面单 + 重量 × 费率', $rules['德邦']['pricing_label']);
|
||||
$this->assertSame(2, $rules['常州德邦逆向']['rate_count']);
|
||||
$this->assertSame('2026-04-07', $rules['常州德邦逆向']['effective_date']);
|
||||
$this->assertSame('面单 + 重量 × 费率', $rules['常州德邦逆向']['pricing_label']);
|
||||
|
||||
$this->assertSame(4, $rules['中通快运']['rate_count']);
|
||||
$this->assertSame(2, $rules['中通快运']['available_count']);
|
||||
$this->assertSame('2026-04-21', $rules['中通快运']['effective_date']);
|
||||
$this->assertSame(['0-30kg', '31-60kg'], $rules['中通快运']['weight_bands']);
|
||||
$this->assertSame(1, $rules['中通快运']['destination_count']);
|
||||
$this->assertSame(4, $rules['中通快运逆向']['rate_count']);
|
||||
$this->assertSame(2, $rules['中通快运逆向']['available_count']);
|
||||
$this->assertSame('2026-04-21', $rules['中通快运逆向']['effective_date']);
|
||||
$this->assertSame(['0-30kg', '31-60kg'], $rules['中通快运逆向']['weight_bands']);
|
||||
$this->assertSame(1, $rules['中通快运逆向']['destination_count']);
|
||||
|
||||
$rates = collect($snapshot['rates']);
|
||||
|
||||
$shentong = $rates->firstWhere(fn (array $rate) => $rate['carrier'] === '申通'
|
||||
$shentong = $rates->firstWhere(fn (array $rate) => $rate['carrier'] === '申通退货'
|
||||
&& $rate['origin'] === '广东'
|
||||
&& $rate['destination'] === '江苏');
|
||||
$this->assertNotNull($shentong);
|
||||
@ -125,13 +125,13 @@ final class ReverseLogisticsQuoteSnapshotTest extends TestCase
|
||||
$this->assertSame('江苏', $shentong['destination_key']);
|
||||
$this->assertTrue($shentong['available']);
|
||||
|
||||
$deppon = $rates->firstWhere(fn (array $rate) => $rate['carrier'] === '德邦' && $rate['origin'] === '新疆');
|
||||
$deppon = $rates->firstWhere(fn (array $rate) => $rate['carrier'] === '常州德邦逆向' && $rate['origin'] === '新疆');
|
||||
$this->assertNotNull($deppon);
|
||||
$this->assertSame('江苏', $deppon['destination']);
|
||||
$this->assertSame(18.0, $deppon['base_amount']);
|
||||
$this->assertSame(5.5, $deppon['increment_amount']);
|
||||
|
||||
$bandRates = $rates->filter(fn (array $rate) => $rate['carrier'] === '中通快运' && $rate['origin'] === '安徽省');
|
||||
$bandRates = $rates->filter(fn (array $rate) => $rate['carrier'] === '中通快运逆向' && $rate['origin'] === '安徽省');
|
||||
$this->assertCount(2, $bandRates);
|
||||
$this->assertSame(['0-30kg', '31-60kg'], array_column($bandRates->values()->all(), 'weight_band'));
|
||||
$this->assertSame('安徽', $bandRates->first()['origin_key']);
|
||||
@ -152,4 +152,21 @@ final class ReverseLogisticsQuoteSnapshotTest extends TestCase
|
||||
$this->assertSame([], $snapshot['rates']);
|
||||
$this->assertSame([], $snapshot['rate_groups']);
|
||||
}
|
||||
|
||||
public function test_requested_courier_names_preserve_original_sheet_cells(): void
|
||||
{
|
||||
$payload = json_decode(file_get_contents($this->fixturePath), true, 512, JSON_THROW_ON_ERROR);
|
||||
foreach (['中铁物流返货报价', '常州松宇货运返货报价'] as $name) {
|
||||
$payload['sheets'][] = ['name' => $name, 'values' => [['原文保留']], 'formulas' => []];
|
||||
}
|
||||
file_put_contents($this->fixturePath, json_encode($payload, JSON_THROW_ON_ERROR));
|
||||
$quotes = (new ReverseLogisticsQuoteSnapshot($this->fixturePath))->load()['quotes'];
|
||||
$expected = ['申通退货', '常州德邦逆向', '中通快运逆向', '其他快递', '中铁客退', '常州松宇货运'];
|
||||
foreach ([0, 1, 2, 4, 5] as $index) {
|
||||
$this->assertSame($expected[$index], $quotes[$index]['company_name']);
|
||||
$this->assertSame($expected[$index], $quotes[$index]['carrier']);
|
||||
$this->assertSame($payload['sheets'][$index]['name'], $quotes[$index]['sheet_name']);
|
||||
$this->assertSame($payload['sheets'][$index]['values'], $quotes[$index]['values']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user