calculate($package + [ 'express_name1' => $name, 'receiver_state' => '江苏省', 'receiver_city' => '南京市', 'warehouse_name' => '测试仓', 'actual_weight' => $weight, ], ['id' => 'TEST-QUOTE', 'p' => QuoteSheet::parse($values), 'vals' => $values, 'rules' => ''], FreightCarrierRules::for($name) + ['_name' => $name]); } public function test_shangran_date_headers_keep_all_weight_bands_and_do_not_extrapolate(): void { $values = [['省份', '0-2kg', 44595, 44624, '4.01-5', '5.01-6', '6.01-7', '备注'], ['江苏', 3, 4, 6, 8, 10, 12, '测试报价']]; foreach (['尚然极兔', '尚然申通'] as $name) { foreach ([[2, 3], [2.001, 4], [3, 4], [3.001, 6], [4, 6], [4.001, 8], [5, 8], [6, 10], [7, 12]] as [$w, $fee]) { $r = $this->calculate($name, $values, $w); $this->assertSame('OK', $r['status']); $this->assertSame((float) $fee, $r['fee']); } $this->assertStringStartsWith('超出报价公斤段', $this->calculate($name, $values, 7.01)['status']); $r = $this->calculate($name, $values, 2, ['length_cm' => 40, 'width_cm' => 40, 'height_cm' => 20]); $this->assertSame(4.0, $r['settle_w']); $this->assertSame(6.0, $r['fee']); $this->assertNull($this->calculate($name, $values, 0)['fee']); } } public function test_senbaihe_charges_one_package_and_keeps_exclusions_unpriced(): void { $values = [['省份', '一口价(加收)', '备注'], ['内蒙古', 17, '测试报价'], ['青海', 19], ['云南', 21]]; foreach (['森百禾韵达快运', '森百禾中通快运', '森百禾顺丰干配', '森百禾德邦快运', '森百禾百世快运'] as $name) { $r = $this->calculate($name, $values, 0, ['receiver_state' => '内蒙古自治区', 'pkg_count' => '1/8']); $this->assertSame('OK', $r['status']); $this->assertSame(17.0, $r['fee']); foreach ([['青海', '玉树藏族自治州'], ['云南', '大理白族自治州'], ['新疆', '乌鲁木齐'], ['安徽', '黄山市']] as [$p, $c]) { $r = $this->calculate($name, $values, 3, ['receiver_state' => $p, 'receiver_city' => $c]); $this->assertSame('报价注明该地区不发货', $r['status']); $this->assertNull($r['fee']); } $r = $this->calculate($name, $values, 3); $this->assertSame(0.0, $r['fee']); $this->assertSame('OK', $r['status']); $this->assertStringContainsString('未列省份按确认价', $r['formula']); $this->assertNull($this->calculate($name, $values, 3, ['receiver_state' => ''])['fee']); $r = $this->calculate($name, $values, 0, ['receiver_state' => '青海', 'receiver_city' => '']); $this->assertStringStartsWith('缺少收货城市', $r['status']); } } public function test_wujin_applies_volume_and_one_fixed_surcharge(): void { $values = [['省份', '面单', '费率(元/kg)'], ['江苏', 4, 2]]; $r = $this->calculate('常州武进', $values, 2, ['volume_cm3' => 30000]); $this->assertSame(15.0, $r['fee']); $this->assertSame(5.0, $r['settle_w']); $this->assertSame(1.0, $r['extra']); $this->assertStringContainsString('+每票加收1', $r['formula']); $r = $this->calculate('常州武进', $values, 2, ['volume_cm3' => 30000, 'warehouse_name' => '常州简尚家居有限公司']); $this->assertSame(9.0, $r['fee']); } public function test_five_kg_first_weight_selects_rate_by_total_weight_without_rounding(): void { $values = [['省份', '首重5kg(元)', '续重0-20kg', '续重20kg以上'], ['江苏', 10, 2, 3]]; foreach (['9999', '常州方圆'] as $name) { foreach ([[1, 10], [5, 10], [5.25, 10.5], [20, 40], [20.5, 56.5], [50, 145]] as [$w, $fee]) { $r = $this->calculate($name, $values, $w); $this->assertSame('OK', $r['status']); $this->assertSame((float) $fee, $r['fee']); } $this->assertSame('超出报价限重(50kg)', $this->calculate($name, $values, 50.01)['status']); $this->assertSame('超出报价限长(160cm)', $this->calculate($name, $values, 8, ['length_cm' => 161])['status']); $r = $this->calculate($name, $values, 2, ['volume_cm3' => 180000]); $this->assertSame(40.0, $r['fee']); } } public function test_route_first_weight_uses_both_provinces_and_seventy_kg_boundary(): void { $values = [['始发省', '省份', '首重20KG', '费率21-70KG', '费率70KG以上', '备注'], ['安徽', '江苏', 30, 2, 1, ''], ['浙江', '江苏', 50, 3, 2, '']]; foreach ([[10, 30], [20, 30], [70, 130], [71, 81]] as [$w, $fee]) { $r = $this->calculate('好省邮顺心捷达', $values, $w, ['warehouse_name' => '工厂-安徽测试仓']); $this->assertSame((float) $fee, $r['fee']); $this->assertSame('安徽→江苏', $r['region']); } $this->assertSame(80.0, $this->calculate('好省邮顺心捷达', $values, 30, ['sender_state' => '浙江省'])['fee']); $this->assertNull($this->calculate('好省邮顺心捷达', $values, 30)['fee']); $this->assertNull($this->calculate('好省邮顺心捷达', $values, 30, ['sender_state' => '广东'])['fee']); $values[] = ['安徽', '江苏', 31, 2, 1, '']; $this->assertStringStartsWith('报价地区匹配不唯一', $this->calculate('好省邮顺心捷达', $values, 30, ['sender_state' => '安徽'])['status']); } public function test_baishi_tiers_switch_at_twenty_thirty_and_stop_at_one_hundred_thirty(): void { $values = [['出发省', '到达省', '组合', '0-20', '', '20-30', '', '30-130', '', '备注'], ['', '', '', '首重10', '费率', '首重20', '费率', '首重30', '费率', ''], ['浙江', '江苏', '浙江江苏', 20, 2, 50, 3, 90, 4, '']]; foreach ([[1, 20], [10, 20], [19, 38], [20, 50], [29, 77], [30, 90], [130, 490]] as [$w, $fee]) { $r = $this->calculate('好省邮百世', $values, $w, ['sender_state' => '浙江省', 'volume_cm3' => 9000000]); $this->assertSame((float) $fee, $r['fee']); $this->assertNull($r['coef']); } $this->assertSame('超出报价限重(130kg)', $this->calculate('好省邮百世', $values, 131, ['sender_state' => '浙江'])['status']); } public function test_sf_city_groups_same_city_and_weight_tiers_are_unambiguous(): void { $values = [['目的省份', '目的城市', '轻抛系数', '首重(kg)', '最大重量(kg)', '首重运费', '费率', '轻抛系数', '首重(kg)', '最大重量(kg)', '首重运费', '费率', '备注'], ['四川', '同城', 6000, 20, 60, 20, 1, 6000, 60, 9999, 60, 2, ''], ['四川', '成都市/资阳市,乐山市', 6000, 20, 60, 30, 2, 6000, 60, 9999, 110, 3, ''], ['四川', '甘孜州', 6000, 20, 60, 40, 3, 6000, 60, 9999, 160, 4, ''], ['江苏省', '南京市,苏州市', 6000, 20, 60, 50, 4, 6000, 60, 9999, 210, 5, '']]; foreach ([[10, 30], [20, 30], [60, 110], [61, 113]] as [$w, $fee]) { $r = $this->calculate('好省邮顺丰', $values, $w, ['receiver_state' => '四川省', 'receiver_city' => '成都市', 'sender_state' => '江苏']); $this->assertSame((float) $fee, $r['fee']); } $r = $this->calculate('好省邮顺丰', $values, 21, ['receiver_state' => '四川', 'receiver_city' => '成都', 'sender_state' => '四川', 'sender_city' => '成都市']); $this->assertSame(21.0, $r['fee']); $this->assertStringContainsString('同城', $r['region']); $r = $this->calculate('好省邮顺丰', $values, 20, ['receiver_state' => '四川', 'receiver_city' => '甘孜藏族自治州', 'sender_state' => '浙江']); $this->assertSame(40.0, $r['fee']); $r = $this->calculate('好省邮顺丰', $values, 20, ['receiver_state' => '四川', 'receiver_city' => '成都市']); $this->assertStringStartsWith('缺少明确的始发城市', $r['status']); $this->assertNull($this->calculate('好省邮顺丰', $values, 20, ['receiver_city' => '徐州市'])['fee']); $this->assertNull($this->calculate('好省邮顺丰', $values, 20, ['receiver_city' => ''])['fee']); } }