From d68d0523b12b2d455a251714afd3983b42672ffc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Mon, 16 Mar 2026 22:54:19 +0800 Subject: [PATCH] chore(governance): block batch BMPA when sync-governance filters present --- .../Admin/PlatformOrderController.php | 11 ++++++ app/Support/PlatformOrderToolsGuard.php | 15 +++++++ ...leWhenSyncGovernanceFiltersPresentTest.php | 39 +++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 tests/Feature/AdminPlatformOrderIndexBatchBmpaButtonShouldDisableWhenSyncGovernanceFiltersPresentTest.php diff --git a/app/Http/Controllers/Admin/PlatformOrderController.php b/app/Http/Controllers/Admin/PlatformOrderController.php index 9024bb1..93b89d1 100644 --- a/app/Http/Controllers/Admin/PlatformOrderController.php +++ b/app/Http/Controllers/Admin/PlatformOrderController.php @@ -1632,6 +1632,17 @@ class PlatformOrderController extends Controller return redirect()->back()->with('warning', '为避免误操作,请先筛选「订单状态=待处理」且「支付状态=未支付」,再执行批量标记支付并生效。'); } + // 互斥筛选阻断:BMPA 面向“待处理+未支付”推进链路;若叠加同步治理筛选,语义会混乱,且可能误伤治理集合。 + $hasSyncGovernanceFilters = ((string) ($filters['syncable_only'] ?? '') === '1') + || ((string) ($filters['synced_only'] ?? '') === '1') + || (trim((string) ($filters['sync_status'] ?? '')) !== '') + || ((string) ($filters['fail_only'] ?? '') === '1') + || (trim((string) ($filters['sync_error_keyword'] ?? '')) !== ''); + + if ($hasSyncGovernanceFilters) { + return redirect()->back()->with('warning', '当前筛选包含「订阅同步治理」相关条件(同步状态/同步失败/失败原因/只看可同步等)。本动作仅用于推进待处理未支付订单,请先清空同步治理筛选后再执行。'); + } + // 治理优先:若当前筛选已包含“对账不一致/退款不一致”等治理集合,则先治理再执行批量推进 if ((string) ($filters['reconcile_mismatch'] ?? '') === '1' || (string) ($filters['refund_inconsistent'] ?? '') === '1') { return redirect()->back()->with('warning', '当前筛选包含「对账不一致/退款不一致」治理集合,请先完成回执/退款治理后,再执行批量标记支付并生效。'); diff --git a/app/Support/PlatformOrderToolsGuard.php b/app/Support/PlatformOrderToolsGuard.php index 46a8292..0c6b932 100644 --- a/app/Support/PlatformOrderToolsGuard.php +++ b/app/Support/PlatformOrderToolsGuard.php @@ -80,6 +80,21 @@ class PlatformOrderToolsGuard if ((string) ($filters['status'] ?? '') !== 'pending' || (string) ($filters['payment_status'] ?? '') !== 'unpaid') { return '请先筛选「订单状态=待处理」且「支付状态=未支付」再执行批量 BMPA。'; } + + // 互斥筛选阻断:BMPA 面向“待处理+未支付”推进链路;若叠加同步治理筛选,语义会混乱,且可能误伤治理集合。 + if ((string) ($filters['syncable_only'] ?? '') === '1') { + return '当前已勾选「只看可同步」:该集合语义为“已生效+未同步”,与 BMPA(待处理+未支付)互斥。请先取消只看可同步后再执行。'; + } + + $hasSyncGovernanceFilters = ((string) ($filters['synced_only'] ?? '') === '1') + || (trim((string) ($filters['sync_status'] ?? '')) !== '') + || ((string) ($filters['fail_only'] ?? '') === '1') + || (trim((string) ($filters['sync_error_keyword'] ?? '')) !== ''); + + if ($hasSyncGovernanceFilters) { + return '当前筛选包含「订阅同步治理」相关条件(同步状态/同步失败/失败原因等)。BMPA 动作仅用于推进待处理未支付订单,请先清空同步治理筛选后再执行。'; + } + if (((string) ($filters['reconcile_mismatch'] ?? '') === '1') || ((string) ($filters['refund_inconsistent'] ?? '') === '1')) { return '当前集合包含「对账不一致/退款不一致」治理集合:建议先完成回执/退款治理后再批量推进。'; } diff --git a/tests/Feature/AdminPlatformOrderIndexBatchBmpaButtonShouldDisableWhenSyncGovernanceFiltersPresentTest.php b/tests/Feature/AdminPlatformOrderIndexBatchBmpaButtonShouldDisableWhenSyncGovernanceFiltersPresentTest.php new file mode 100644 index 0000000..ee12b59 --- /dev/null +++ b/tests/Feature/AdminPlatformOrderIndexBatchBmpaButtonShouldDisableWhenSyncGovernanceFiltersPresentTest.php @@ -0,0 +1,39 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_batch_bmpa_button_should_disable_when_sync_governance_filters_present_even_if_pending_unpaid(): void + { + $this->loginAsPlatformAdmin(); + + // status=pending&payment_status=unpaid 是 BMPA 的基本口径;但叠加“同步失败”治理筛选应禁用(与后端阻断一致)。 + $res = $this->get('/admin/platform-orders?status=pending&payment_status=unpaid&fail_only=1'); + $res->assertOk(); + + $html = (string) $res->getContent(); + + $this->assertStringContainsString('批量标记支付并生效(含订阅同步)(当前筛选范围)', $html); + $this->assertStringContainsString('data-role="batch-bmpa-blocked-hint"', $html); + $this->assertStringContainsString('同步', $html); + + // 按钮 disabled(宽松断言) + $this->assertTrue(str_contains($html, 'type="submit" disabled') || str_contains($html, 'disabled="disabled"')); + } +}