From b85c82b830667ca5c0f7bce072b6e2cf60c42308 Mon Sep 17 00:00:00 2001 From: limeng <1131177064@qq.com> Date: Thu, 3 Dec 2026 09:45:32 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=BF=AB=E9=80=92=E6=9C=BA=E5=99=A8?= =?UTF-8?q?=E4=BA=BA):=20=E6=8C=89=E6=8C=87=E5=AE=9A=E7=BE=A4=E5=85=B3?= =?UTF-8?q?=E7=B3=BB=E7=BB=91=E5=AE=9A=E5=B9=B6=E5=8C=BA=E5=88=86=E5=B8=B8?= =?UTF-8?q?=E5=B7=9E=E5=BE=B7=E9=82=A6=E9=80=86=E5=90=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WorkPlatformCourierRobots.php | 26 ++++++++++++++++--- docs/快递账单群机器人复用.md | 4 +++ .../WorkPlatformCourierRobotsTest.php | 22 ++++++++++++++++ 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/app/Support/CourierBills/WorkPlatformCourierRobots.php b/app/Support/CourierBills/WorkPlatformCourierRobots.php index 7690327e3..812e63479 100644 --- a/app/Support/CourierBills/WorkPlatformCourierRobots.php +++ b/app/Support/CourierBills/WorkPlatformCourierRobots.php @@ -7,6 +7,23 @@ use RuntimeException; /** 按财务分组名称匹配工作平台的快递名称或群名;组合分组任一名称命中即可。 */ final class WorkPlatformCourierRobots { + /** 负责人明确指定的对应关系,目标必须命中工作平台完整业务名称。 */ + private const DESIGNATED_NAMES = [ + '北京韵达-乐鑫达' => '北京大件韵达', + '樵舍中通' => '樵舍中通', + '樵舍中通-上楼' => '樵舍中通', + '樵舍中通上楼' => '樵舍中通', + '江西中通快运' => '樵舍中通', + '江西新建中通' => '樵舍中通', + '山东中通快运' => '樵舍中通', + '南昌樵舍仓仓储费' => '樵舍中通', + '中通快运专线' => '常州中通快运', + '宿迁中通快运' => '沭阳中通快运', + '山东顺丰干配' => '顺德德邦', + '河北中通-江三' => '顺德德邦', + '苏北顺丰干配大件' => '顺德德邦', + ]; + public function match(array $groups, array $rows): array { $platformRows = []; @@ -20,13 +37,16 @@ final class WorkPlatformCourierRobots $robots = $unmatched = $ambiguous = []; foreach ($groups as $group) { $name = (string) $group->name; - // 负责人指定北京乐鑫达使用北京大件韵达的现有群机器人。 - $matchName = $name === '北京韵达-乐鑫达' ? '北京大件韵达' : $name; + $designatedName = self::DESIGNATED_NAMES[$name] ?? null; $candidates = []; $bestScore = 0; - $names = preg_split('/[|++、,,;;]+/u', $matchName, -1, PREG_SPLIT_NO_EMPTY) ?: []; + $names = preg_split('/[|++、,,;;]+/u', $name, -1, PREG_SPLIT_NO_EMPTY) ?: []; foreach ($platformRows as $row) { $keys = array_filter(array_map('trim', explode('|', (string) ($row['businessKey'] ?? '')))); + if ($designatedName !== null) { + if (in_array($designatedName, $keys, true)) $candidates[(string) $row['Id']] = $row; + continue; + } $platformGroup = (string) ($row['groupname'] ?? ''); $score = 0; foreach ($names as $part) { diff --git a/docs/快递账单群机器人复用.md b/docs/快递账单群机器人复用.md index b905f086f..75f4cad65 100644 --- a/docs/快递账单群机器人复用.md +++ b/docs/快递账单群机器人复用.md @@ -12,6 +12,10 @@ 北京韵达-乐鑫达按负责人指定使用“北京大件韵达+北京大件韵达临时”的机器人,匹配业务名称“北京大件韵达”。 +樵舍中通、樵舍中通-上楼(也兼容樵舍中通上楼)、江西中通快运、江西新建中通、山东中通快运、南昌樵舍仓仓储费,统一使用包含完整业务名称“樵舍中通”的南昌对接群配置。中通快运专线使用“常州中通快运+武进韵达快运”的机器人;宿迁中通快运使用“沭阳中通快运”的机器人。指定目标不存在或存在多条时保持未匹配/有歧义,不回退到其他同名群。 + +山东顺丰干配、河北中通-江三、苏北顺丰干配大件按负责人指定使用“顺德德邦+廊坊德邦+廊坊德邦其他”的机器人,匹配业务名称“顺德德邦”。 + ```sh php artisan courier-bills:import-platform-robots /private/path/robots.json --company=1 php artisan courier-bills:import-platform-robots /private/path/robots.json --company=1 --apply diff --git a/tests/Feature/Business/WorkPlatformCourierRobotsTest.php b/tests/Feature/Business/WorkPlatformCourierRobotsTest.php index 16a366bb6..743a94445 100644 --- a/tests/Feature/Business/WorkPlatformCourierRobotsTest.php +++ b/tests/Feature/Business/WorkPlatformCourierRobotsTest.php @@ -60,6 +60,28 @@ final class WorkPlatformCourierRobotsTest extends FeatureTestCase $this->assertSame('北京大件韵达+北京大件韵达临时', $result['robots']['北京韵达-乐鑫达']['group_name']); } + public function test_designated_nanchang_changzhou_and_shuyang_groups_use_the_requested_robot(): void + { + $rows = [$this->robot(588, '樵舍中通|江西中通快运', '南昌对接群'), + $this->robot(601, '常州中通快运|武进韵达快运', '常州中通快运+武进韵达快运'), + $this->robot(624, '沭阳中通快运', '沭阳中通快运群'), + $this->robot(603, '顺德德邦|廊坊德邦|廊坊德邦其他', '顺德德邦+廊坊德邦+廊坊德邦其他'), + $this->robot(999, '山东中通快运|宿迁中通快运|中通快运专线', '同名但未指定的群')]; + $names = ['樵舍中通', '樵舍中通-上楼', '樵舍中通上楼', '江西中通快运', '江西新建中通', + '山东中通快运', '南昌樵舍仓仓储费', '中通快运专线', '宿迁中通快运', + '山东顺丰干配', '河北中通-江三', '苏北顺丰干配大件']; + $groups = array_map(fn ($name) => (object) ['name' => $name], $names); + $result = (new WorkPlatformCourierRobots())->match($groups, $rows); + foreach (array_slice($names, 0, 7) as $name) $this->assertSame('588', $result['robots'][$name]['source_id']); + $this->assertSame('601', $result['robots']['中通快运专线']['source_id']); + $this->assertSame('624', $result['robots']['宿迁中通快运']['source_id']); + foreach (array_slice($names, 9) as $name) $this->assertSame('603', $result['robots'][$name]['source_id']); + $this->assertSame([], $result['unmatched']); + $this->assertSame([], $result['ambiguous']); + $missing = (new WorkPlatformCourierRobots())->match($groups, [end($rows)]); + $this->assertSame([], $missing['robots']); + } + public function test_import_is_previewed_backed_up_encrypted_and_used_for_upload_notifications(): void { Storage::fake('local');