From ebcec21bd10be7b06c0315dd565cd4e99faa1042 Mon Sep 17 00:00:00 2001 From: limeng <1131177064@qq.com> Date: Fri, 4 Dec 2026 11:14:38 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=BF=AB=E9=80=92=E8=B4=A6=E5=8D=95):=20?= =?UTF-8?q?=E8=A1=A5=E5=85=85=E6=B2=B3=E5=8C=97=E5=8F=8A=E5=BE=B7=E9=82=A6?= =?UTF-8?q?=E9=A1=BA=E4=B8=B0=E8=81=94=E5=90=88=E4=B8=8A=E4=BC=A0=20(#1727?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Support/CourierBills/CourierBillStore.php | 2 +- .../CourierBills/CourierJointUploads.php | 5 +- docs/快递联合上传验收.md | 5 ++ .../Business/CourierJointUploadTest.php | 58 +++++++++++++++++-- 4 files changed, 63 insertions(+), 7 deletions(-) diff --git a/app/Support/CourierBills/CourierBillStore.php b/app/Support/CourierBills/CourierBillStore.php index 34f3d3ab9..28a5f8d51 100644 --- a/app/Support/CourierBills/CourierBillStore.php +++ b/app/Support/CourierBills/CourierBillStore.php @@ -767,7 +767,7 @@ final class CourierBillStore $owners = []; $statements = []; foreach ($set['groups'] as $g) { - foreach (array_unique([$g->name, ...$g->express_names]) as $name) { + foreach (array_intersect(array_unique([$g->name, ...$g->express_names]), $set['names']) as $name) { if (isset($owners[$name]) && $owners[$name] !== (int) $g->id) throw new RuntimeException('联合上传快递名称重复,请联系财务。'); $owners[$name] = (int) $g->id; } diff --git a/app/Support/CourierBills/CourierJointUploads.php b/app/Support/CourierBills/CourierJointUploads.php index c789788a8..034c27112 100644 --- a/app/Support/CourierBills/CourierJointUploads.php +++ b/app/Support/CourierBills/CourierJointUploads.php @@ -10,6 +10,8 @@ final class CourierJointUploads public const SETS = [ 'qiaoshe' => ['label' => '樵舍联合上传', 'names' => ['江西新建中通', '江西中通快运', '樵舍中通', '樵舍中通-上楼', '山东中通快运', '西安圆通', '西安中通快运']], 'yuantong' => ['label' => '圆通联合上传', 'names' => ['常州圆通其他', '常州圆通-上楼', '小件宿迁圆通', '睢宁宿迁圆通', '苏北宿迁圆通']], + 'hebei' => ['label' => '河北中通与霸州百世联合上传', 'names' => ['河北中通-江三', '河北中通小件-江三', '霸州百世快运-雅柏']], + 'debang-shunfeng' => ['label' => '德邦与顺丰干配联合上传', 'names' => ['睢宁德邦', '崔桥顺丰干配', '山东顺丰干配', '山东顺丰大件', '苏北顺丰干配大件', '苏北顺丰干配小件']], ]; public function resolve(string $key): array @@ -21,8 +23,7 @@ final class CourierJointUploads $matches = array_values(array_filter($groups, static fn ($g) => $g->name === $name || in_array($name, $g->express_names, true))); if (count($matches) !== 1) throw new RuntimeException('联合上传分组「' . $name . '」未配置或存在重名,请联系财务。'); $g = $matches[0]; - // 一个分组可以有多个业务名称,但不得借此授权集合之外的快递。 - if (array_diff($g->express_names, $set['names']) !== []) throw new RuntimeException('联合上传分组范围已变化,请联系财务。'); + // 可通过别名定位既有分组;上传时仍只允许本集合列出的名称。 $selected[(int) $g->id] = $g; } ksort($selected); diff --git a/docs/快递联合上传验收.md b/docs/快递联合上传验收.md index b02708d01..afac1b26c 100644 --- a/docs/快递联合上传验收.md +++ b/docs/快递联合上传验收.md @@ -8,6 +8,9 @@ - 樵舍:江西新建中通、江西中通快运、樵舍中通、樵舍中通-上楼、山东中通快运、西安圆通、西安中通快运。 - 圆通:常州圆通其他、常州圆通-上楼、小件宿迁圆通、睢宁宿迁圆通、苏北宿迁圆通。 - 睢宁宿迁圆通是苏北宿迁圆通的既有快递名称,圆通共 5 个名称、4 个分组。 +- 河北中通与霸州百世:河北中通-江三、河北中通小件-江三、霸州百世快运-雅柏,3 个名称、2 个分组。 +- 德邦与顺丰干配:睢宁德邦、崔桥顺丰干配、山东顺丰干配、山东顺丰大件、苏北顺丰干配大件、苏北顺丰干配小件,6 个名称、4 个分组。 +- 睢宁德邦归入既有顺德德邦分组;链接只接受列出的 6 个名称,不额外授权顺德德邦名称。 - 不改分组、机器人或既有单家链接。联合权限不继承文件名、机器人共用关系或合并账单配置。 - 优先按系统单号归组;系统查不到快递名称时,使用模板内明确填写的范围内名称。 - 无法归组、范围外名称、同单号不同归属、附加费缺少运费明细时,整份回滚并提示修改。 @@ -25,6 +28,8 @@ - 容量专项:100,000 行 CSV,3,900,052 字节,交替两家,校验、流式读入、归组及原有完整对账均执行。 - 100,000 行与 123,000 元合计完整,102.78 秒,PHP 峰值 154.5 MiB,数据库查询事件 101,823 次(包含既有逐行匹配更新)。 - 不据此承诺生产 MySQL 耗时;未对生产执行压测或上传测试账单。生产查询时两组尚无已上传文件和当月对账单。 +- 河北及德邦/顺丰扩展:生产只读确认原分组、别名及账单为空;49 项回归、625 个断言通过,新增两组整单上传与别名范围校验已覆盖。增加入口显示断言后单独运行页面路径,16 个断言通过。 +- 本次扩展沿用同一流式导入及每批 500 行分配,不改变数据量上限、导入命令或频率;未重复执行已通过的 10 万行容量测试。 生产复用已登记的 `portal-freight:import-pending` 独立批处理,每次一份;现有锁、1 CPU、1 GiB 容器、PHP 512 MiB、1 小时超时继续生效。 中断任务标记失败,联系财务核对后重传,不自动重复导入。 diff --git a/tests/Feature/Business/CourierJointUploadTest.php b/tests/Feature/Business/CourierJointUploadTest.php index c4018efe2..c835852d0 100644 --- a/tests/Feature/Business/CourierJointUploadTest.php +++ b/tests/Feature/Business/CourierJointUploadTest.php @@ -27,9 +27,16 @@ final class CourierJointUploadTest extends FeatureTestCase $this->company->makeCurrent(true); foreach (CourierJointUploads::SETS as $set) { foreach ($set['names'] as $name) { - if ($name === '睢宁宿迁圆通') continue; - $aliases = $name === '苏北宿迁圆通' ? [$name, '睢宁宿迁圆通'] : [$name]; - $this->ids[$name] = app(CourierBillStore::class)->saveGroup(null, ['name' => $name, + if (in_array($name, ['睢宁宿迁圆通', '河北中通小件-江三', '山东顺丰大件', '苏北顺丰干配小件'], true)) continue; + $aliases = match ($name) { + '苏北宿迁圆通' => [$name, '睢宁宿迁圆通'], + '河北中通-江三' => [$name, '河北中通小件-江三'], + '山东顺丰干配' => [$name, '山东顺丰大件'], + '苏北顺丰干配大件' => [$name, '苏北顺丰干配小件'], + '睢宁德邦' => ['顺德德邦', $name], + default => [$name], + }; + $this->ids[$name] = app(CourierBillStore::class)->saveGroup(null, ['name' => $name === '睢宁德邦' ? '顺德德邦' : $name, 'express_names' => $aliases, 'bundle' => '故意相同的合并配置']); } } @@ -131,11 +138,54 @@ final class CourierJointUploadTest extends FeatureTestCase $this->get($url)->assertOk()->assertSeeText('财务已确认结算')->assertDontSee('name="import"', false); } + public function test_new_sets_upload_all_requested_names_into_existing_groups(): void + { + foreach (['hebei' => 2, 'debang-shunfeng' => 4] as $key => $groupCount) { + $set = app(CourierJointUploads::class)->resolve($key); + $this->assertCount($groupCount, $set['groups']); + $url = app(CourierUploadLink::class)->jointPageUrl((int) $this->company->id, $key, '2026-11'); + $response = $this->get($url)->assertOk()->assertSeeText($set['label']); + $rows = $expected = []; + foreach ($set['names'] as $i => $name) { + $no = strtoupper($key) . '000' . $i; + $rows[] = [$no, '', '', $i + 1, $name]; + $group = collect($set['groups'])->first(fn ($g) => $g->name === $name || in_array($name, $g->express_names, true)); + $expected[$no] = $group->name; + $response->assertSeeText($name); + } + preg_match('/action="([^"]*\/upload[^"]*)"/', $response->getContent(), $matches); + Http::fake(); + $this->post(html_entity_decode($matches[1]), ['import' => $this->csv($rows)])->assertRedirect(); + $this->assertTrue(app(PortalFreightBillImports::class)->processNext()); + $file = CourierBillMatcher::db()->table('courier_bill_files')->orderByDesc('id')->first(); + $this->assertSame('parsed', $file->status, $file->message ?? ''); + $this->assertEquals(array_sum(range(1, count($rows))), $file->amount); + $actual = CourierBillMatcher::db()->table('courier_bill_lines as l')->join('courier_bill_statements as s', 's.id', '=', 'l.statement_id') + ->join('courier_bill_groups as g', 'g.id', '=', 's.group_id')->where('l.file_id', $file->id)->pluck('g.name', 'l.waybill_no')->all(); + $this->assertEquals($expected, $actual); + } + } + + public function test_unlisted_group_name_does_not_gain_access_through_an_allowed_alias(): void + { + $scope = app(CourierJointUploads::class)->snapshot('debang-shunfeng'); + $store = app(CourierBillStore::class); + $id = $store->uploadJoint($this->csv([['DB001', '', '', 10, '顺德德邦']]), '2026-11', $scope, '测试'); + $this->assertSame('failed', $store->db()->table('courier_bill_files')->find($id)->status); + $this->assertSame(0, $store->db()->table('courier_bill_lines')->count()); + app(ShippingLookup::class)->connection()->table('jst_oms_shipping')->insert(['express_no' => 'DB002', + 'express_name1' => '顺德德邦', 'source_id' => 102]); + $id = $store->uploadJoint($this->csv([['DB002', '', '', 10, '睢宁德邦']]), '2026-11', $scope, '测试'); + $this->assertSame('failed', $store->db()->table('courier_bill_files')->find($id)->status); + $this->assertSame(0, $store->db()->table('courier_bill_lines')->count()); + } + public function test_finance_can_open_each_link_and_courier_can_upload_one_mixed_file(): void { $this->loginAs()->withExceptionHandling(); $page = route('business.pages.show', ['section' => 'courier-payables-final', 'page' => 'courier-bill-reconciliation', 'cb_view' => 'upload']); - $this->get($page)->assertOk()->assertSeeText('樵舍联合上传')->assertSeeText('圆通联合上传'); + $this->get($page)->assertOk()->assertSeeText('樵舍联合上传')->assertSeeText('圆通联合上传') + ->assertSeeText('河北中通与霸州百世联合上传')->assertSeeText('德邦与顺丰干配联合上传'); $entry = route('business.courier-payables-final.courier-bills.joint-upload-link', ['joint' => 'qiaoshe', 'month' => '2026-11']); $response = $this->get($entry)->assertRedirect(); $url = $response->headers->get('Location');