From a26be5de9e20094c7df4d4acb56acfac42b0df93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Mon, 16 Mar 2026 23:03:38 +0800 Subject: [PATCH] chore(governance): block batch activate when refund_status=has --- .../Admin/PlatformOrderController.php | 7 ++++ app/Support/PlatformOrderToolsGuard.php | 3 ++ ...ionsShouldBlockWhenRefundStatusHasTest.php | 36 ++++++++++++++++++ ...onShouldDisableWhenRefundStatusHasTest.php | 37 +++++++++++++++++++ 4 files changed, 83 insertions(+) create mode 100644 tests/Feature/AdminPlatformOrderBatchActivateSubscriptionsShouldBlockWhenRefundStatusHasTest.php create mode 100644 tests/Feature/AdminPlatformOrderIndexBatchActivateButtonShouldDisableWhenRefundStatusHasTest.php diff --git a/app/Http/Controllers/Admin/PlatformOrderController.php b/app/Http/Controllers/Admin/PlatformOrderController.php index 816e8f4..0505003 100644 --- a/app/Http/Controllers/Admin/PlatformOrderController.php +++ b/app/Http/Controllers/Admin/PlatformOrderController.php @@ -1447,6 +1447,13 @@ class PlatformOrderController extends Controller return redirect()->back()->with('warning', '当前筛选集合包含「对账不一致/退款不一致」订单,为避免带病同步,请先完成金额/状态治理(补回执/核对退款/修正状态)后再批量同步订阅。'); } + // 防误操作(退款治理优先):当用户显式筛选「有退款」时,禁止直接批量同步 + if ($scope === 'filtered' + && ($filters['syncable_only'] ?? '') === '1' + && ((string) ($filters['refund_status'] ?? '') === 'has')) { + return redirect()->back()->with('warning', '当前筛选为「有退款」订单集合。为避免带退款订单直接同步订阅,请先完成退款治理(核对退款回执/修正状态)后再批量同步订阅。'); + } + // 防误操作(回执治理优先):当用户显式筛选「无回执」时,禁止直接批量同步 // 原因:已支付/已生效但无回执证据的订单属于收费闭环缺口,应先补齐回执留痕(可治理、可对账)再同步订阅。 if ($scope === 'filtered' diff --git a/app/Support/PlatformOrderToolsGuard.php b/app/Support/PlatformOrderToolsGuard.php index 5bf05ff..a1641f9 100644 --- a/app/Support/PlatformOrderToolsGuard.php +++ b/app/Support/PlatformOrderToolsGuard.php @@ -68,6 +68,9 @@ class PlatformOrderToolsGuard if ((string) ($filters['receipt_status'] ?? '') === 'none') { return '当前集合为「无回执」:建议先补齐支付回执留痕后再批量同步。'; } + if ((string) ($filters['refund_status'] ?? '') === 'has') { + return '当前集合为「有退款」:为避免带退款订单直接同步订阅,请先完成退款治理(核对退款回执/修正状态)后再批量同步。'; + } if (((string) ($filters['reconcile_mismatch'] ?? '') === '1') || ((string) ($filters['refund_inconsistent'] ?? '') === '1')) { return '当前集合包含「对账不一致/退款不一致」:建议先完成金额/状态治理后再批量同步。'; } diff --git a/tests/Feature/AdminPlatformOrderBatchActivateSubscriptionsShouldBlockWhenRefundStatusHasTest.php b/tests/Feature/AdminPlatformOrderBatchActivateSubscriptionsShouldBlockWhenRefundStatusHasTest.php new file mode 100644 index 0000000..b3d39a9 --- /dev/null +++ b/tests/Feature/AdminPlatformOrderBatchActivateSubscriptionsShouldBlockWhenRefundStatusHasTest.php @@ -0,0 +1,36 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_batch_activate_should_block_when_refund_status_has_present(): void + { + $this->loginAsPlatformAdmin(); + + $res = $this->post('/admin/platform-orders/batch-activate-subscriptions', [ + 'scope' => 'filtered', + 'syncable_only' => '1', + 'refund_status' => 'has', + 'limit' => 50, + ]); + + $res->assertRedirect(); + $res->assertSessionHas('warning'); + } +} diff --git a/tests/Feature/AdminPlatformOrderIndexBatchActivateButtonShouldDisableWhenRefundStatusHasTest.php b/tests/Feature/AdminPlatformOrderIndexBatchActivateButtonShouldDisableWhenRefundStatusHasTest.php new file mode 100644 index 0000000..5d83f79 --- /dev/null +++ b/tests/Feature/AdminPlatformOrderIndexBatchActivateButtonShouldDisableWhenRefundStatusHasTest.php @@ -0,0 +1,37 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_batch_activate_button_should_disable_when_refund_status_has_even_if_syncable_only_checked(): void + { + $this->loginAsPlatformAdmin(); + + $res = $this->get('/admin/platform-orders?syncable_only=1&refund_status=has'); + $res->assertOk(); + + $html = (string) $res->getContent(); + + $this->assertStringContainsString('批量同步订阅(当前筛选范围)', $html); + $this->assertStringContainsString('data-role="batch-activate-subscriptions-blocked-hint"', $html); + $this->assertStringContainsString('有退款', $html); + + $this->assertTrue(str_contains($html, 'type="submit" disabled') || str_contains($html, 'disabled="disabled"')); + } +}