fix(附加费): 支持明确配置多个改地址原因 (#1771)

This commit is contained in:
limeng 2026-12-06 11:03:43 +08:00
parent 77b1044565
commit 1abeedb96a
2 changed files with 33 additions and 1 deletions

View File

@ -195,6 +195,7 @@ final class BillSurchargeQuoteCalculator
}
} elseif (preg_match('/^查件类型\/查件原因是([^\/]+)\/([^\/]+)$/u', $condition, $path)) {
$expected = trim($path[1]) . '/' . trim($path[2]);
$allowedReasons = array_map(static fn ($reason) => trim($path[1]) . '/' . trim($reason), explode('或', $path[2]));
$candidates = array_filter($orders, static function ($order) use ($rule): bool {
$fields = array_column(json_decode($order->businessFieldList, true, 512, JSON_THROW_ON_ERROR) ?: [], 'value', 'fieldId');
return ($fields['logisticsField'] ?? '') === $rule->courier
@ -208,7 +209,7 @@ final class BillSurchargeQuoteCalculator
$actual = trim((string) ($fields['SELECT_CASCADEField1413856620250813172526'] ?? ''));
if ($actual === '') return '查件工单未填写查件类型和原因,待核实';
$evidence = '聚工单 ' . $latest->woNo . ' 查件类型/原因为“' . $actual . '”';
if ($actual !== $expected) return [['settlement_amount' => 0, 'evidence' => $evidence . ',不符合报价条件“' . $expected . '”,不计费']];
if (! in_array($actual, $allowedReasons, true)) return [['settlement_amount' => 0, 'evidence' => $evidence . ',不符合报价条件“' . $expected . '”,不计费']];
$evidence .= ',符合报价条件';
} elseif (in_array($condition, ['聚工单客服回复通过', '改地址客服回复通过'], true)) {
$approved = false;

View File

@ -544,6 +544,37 @@ class BillSurchargeMatchingTest extends FeatureTestCase
$this->assertEquals(20,$rows['SMALL01']->self_amount);
}
public function test_fixed_readdress_accepts_each_explicit_reason_at_the_couriers_own_rate(): void
{
$condition='查件类型/查件原因是改地址、电话/本省改地址.电话或跨省改地址,电话';
$this->quote('测试快递甲','改地址','固定单价','30元/单',$condition,'自有快递');
$this->quote('测试快递乙','改地址','固定单价','20元/单',$condition,'自有快递');
$cases=[['LOCAL02','测试快递甲','改地址、电话/本省改地址.电话',30],
['CROSS02','测试快递甲','改地址、电话/跨省改地址,电话',30],
['SMALL02','测试快递乙','改地址、电话/跨省改地址,电话',20],
['OTHER02','测试快递甲','扣单/跨省改地址,电话',0],
['LATEST02','测试快递甲','改地址、电话/本省改地址.电话',0],
['CANCEL02','测试快递甲','改地址、电话/跨省改地址,电话',30]];
$input=[];
foreach($cases as[$no,$courier,$reason,$amount]){
$this->ship($no,$courier);
$this->workOrder($no,$courier,'','',null,'2026-11-03',$reason);
$input[]=['waybill_no'=>$no,'item'=>'改地址'];
}
$this->workOrder('CROSS02','测试快递甲','','',null,'2026-11-04','改地址、电话/跨省改地址,电话');
$this->workOrder('LATEST02','测试快递甲','','',null,'2026-11-04','催件/其他');
$this->workOrder('CANCEL02','测试快递甲','','',null,'2026-11-04','催件/其他','CANCELLED');
$this->ship('WRONG02','测试快递甲');$this->ship('MISSING02','测试快递甲');
$this->workOrder('WRONG02','测试快递乙','','',null,'2026-11-03','改地址、电话/跨省改地址,电话');
$input[]=['waybill_no'=>'WRONG02','item'=>'改地址'];$input[]=['waybill_no'=>'MISSING02','item'=>'改地址'];
$r=app(\App\Support\CourierBills\BillSurchargeQuoteCalculator::class)->calculate($input,'courier','2026-11',['测试快递甲','测试快递乙']);
foreach($cases as[$no,$courier,$reason,$amount]){
$this->assertCount(1,$r['rows'][$no]['改地址']);
$this->assertEquals($amount,$r['rows'][$no]['改地址'][0]->settlement_amount);
}
foreach(['WRONG02','MISSING02']as$no)$this->assertStringContainsString('未找到同快递的有效查件工单',$r['notes'][$no]['改地址']);
}
public function test_long_side_wording_is_supported_without_ignoring_additional_conditions(): void
{
$this->ship('LONG01','曹县德邦其他');$this->ship('EDGE01','曹县德邦其他');