diff --git a/modules/EcommerceFinance/Repositories/SupplierAccessoryFreightRepository.php b/modules/EcommerceFinance/Repositories/SupplierAccessoryFreightRepository.php index eab752c02..cc6c18e9e 100644 --- a/modules/EcommerceFinance/Repositories/SupplierAccessoryFreightRepository.php +++ b/modules/EcommerceFinance/Repositories/SupplierAccessoryFreightRepository.php @@ -36,6 +36,14 @@ class SupplierAccessoryFreightRepository ->map(static fn ($group) => $group->map(static fn ($row) => (array) $row)->all()); // 复用代发厂家设置;整月只读一次,且每个快递名只匹配一次(含未命中)。 $factories = $db->table('dropship_factories')->orderBy('id')->get(['warehouse', 'keywords']); + // 和代发对账一致:自有快递以对账分组里的完整快递名称为准,优先于厂家关键字。 + $ownCouriers = []; + foreach ($db->table('courier_bill_groups')->get(['express_names']) as $group) { + foreach ((array) json_decode((string) $group->express_names, true, 512, JSON_THROW_ON_ERROR) as $name) { + $name = trim((string) $name); + if ($name !== '') $ownCouriers[$name] = true; + } + } $dropshipWarehouses = []; $start = \Carbon\Carbon::createFromFormat('!Y-m', $month); foreach ($this->shipping->accessoryFreightBatches($start->format('Y-m-d'), $start->copy()->addMonth()->format('Y-m-d')) as $batch) { @@ -48,10 +56,11 @@ class SupplierAccessoryFreightRepository $candidates = $products->get($barcode, []); $supplierName = trim((string) ($candidates[0]['supplier_name'] ?? '')); $courierName = trim((string) ($row['express_name1'] ?? '')) ?: trim((string) ($row['express_name2'] ?? '')); + $isOwnCourier = isset($ownCouriers[$courierName]); if (!array_key_exists($courierName, $dropshipWarehouses)) { - $dropshipWarehouses[$courierName] = $this->matcher->dropshipWarehouse($courierName, $factories); + $dropshipWarehouses[$courierName] = $isOwnCourier ? null : $this->matcher->dropshipWarehouse($courierName, $factories); } - yield $this->matcher->match($row, $candidates, $suppliers->get($supplierName, []), $couriers->get($courierName, []), $dropshipWarehouses[$courierName]); + yield $this->matcher->match($row, $candidates, $suppliers->get($supplierName, []), $couriers->get($courierName, []), $dropshipWarehouses[$courierName], $isOwnCourier); } } } diff --git a/modules/EcommerceFinance/Services/SupplierAccessoryFreightMatcher.php b/modules/EcommerceFinance/Services/SupplierAccessoryFreightMatcher.php index 882db3487..c735273c9 100644 --- a/modules/EcommerceFinance/Services/SupplierAccessoryFreightMatcher.php +++ b/modules/EcommerceFinance/Services/SupplierAccessoryFreightMatcher.php @@ -8,7 +8,7 @@ class SupplierAccessoryFreightMatcher { public const STATES = ['ready' => '可扣款', 'excluded' => '不扣款', 'pending' => '待核实']; - public function match(array $row, array $products, array $suppliers, array $couriers = [], ?string $dropshipWarehouse = null): array + public function match(array $row, array $products, array $suppliers, array $couriers = [], ?string $dropshipWarehouse = null, bool $isOwnCourier = false): array { $result = $this->matchSupplier($row, $products, $suppliers); $attributes = array_values(array_unique(array_map(static fn ($courier) => trim((string) ($courier['exp_properties'] ?? '')), $couriers))); @@ -20,6 +20,10 @@ class SupplierAccessoryFreightMatcher $result['reason'] = '外采快递不扣配件运费'; return $result; } + if ($isOwnCourier) { + if ($result['state'] === 'ready') $result['reason'] = '自有快递,按山东、河北供应商扣除全部配件运费'; + return $result; + } if ($dropshipWarehouse !== null) { $result['state'] = 'excluded'; $result['deduction_cents'] = 0; @@ -36,16 +40,16 @@ class SupplierAccessoryFreightMatcher return $result; } - /** 同一条厂家配置的关键字须同时出现在快递名和代发仓名中。 */ + /** 以代发厂家配置的快递关键字识别,不再用仓库名的字样判断归属。自有快递由调用方优先排除。 */ public function dropshipWarehouse(string $courier, iterable $factories): ?string { $courier = trim($courier); if ($courier === '') return null; foreach ($factories as $factory) { $warehouse = trim((string) $factory->warehouse); - if (!str_contains($warehouse, '代发仓')) continue; + if ($warehouse === '') continue; foreach (DropshipFreightStore::splitKeywords((string) $factory->keywords) as $keyword) { - if (str_contains($warehouse, $keyword) && str_contains($courier, $keyword)) return $warehouse; + if (str_contains($courier, $keyword)) return $warehouse; } } return null; diff --git a/resources/views/business/pages/supplier-payables/accessory-freight-deductions.blade.php b/resources/views/business/pages/supplier-payables/accessory-freight-deductions.blade.php index af366e1d8..dab0eb83a 100644 --- a/resources/views/business/pages/supplier-payables/accessory-freight-deductions.blade.php +++ b/resources/views/business/pages/supplier-payables/accessory-freight-deductions.blade.php @@ -21,7 +21,7 @@
仅取所选月份仓库为“常州简尚家居有限公司”的发货包裹。取第一个逗号前的条形码,再去掉最后一个“-”及其后缀,用处理后的条形码匹配商品资料条形码,再按商品供应商名称匹配供应商管理。联系人省为山东、山东省、河北、河北省的供应商,扣除对应包裹全部运费。每个发货包裹只计一次;不需要匹配首发单。外采快递不扣运费;按快递名称匹配工作平台快递资料,快递属性为“工厂”的包裹不扣运费。按代发厂家设置,同一配置的快递关键字同时出现在快递名称和代发仓名称中的,也不扣运费(如“浩浦极兔”与“工厂-河北浩浦代发仓”均包含“浩浦”)。使用快递名称1,为空时使用快递名称2。同名快递属性冲突时待核实;属性为空或未匹配时沿用其余规则。其他省份不扣,未匹配、资料缺失、供应商或省份冲突、运费异常的记录待核实。此处展示扣除明细,不自动入账。
仅取所选月份仓库为“常州简尚家居有限公司”的发货包裹。取第一个逗号前的条形码,再去掉最后一个“-”及其后缀,用处理后的条形码匹配商品资料条形码,再按商品供应商名称匹配供应商管理。联系人省为山东、山东省、河北、河北省的供应商,扣除对应包裹全部运费。每个发货包裹只计一次;不需要匹配首发单。外采快递不扣运费;按快递名称匹配工作平台快递资料,快递属性为“工厂”的包裹不扣运费。代发快递按代发厂家设置的快递关键字识别,命中则不扣运费;不再按仓库名称的字样判断。自有快递以“快递账单对账 → 对账分组”中的完整快递名称为准,优先于代发关键字和“工厂”属性,按原供应商及运费规则正常扣款。使用快递名称1,为空时使用快递名称2。同名快递属性冲突时待核实;属性为空或未匹配时沿用其余规则。其他省份不扣,未匹配、资料缺失、供应商或省份冲突、运费异常的记录待核实。此处展示扣除明细,不自动入账。