From 314563a8d5f55fcaac5f54fd3f55c914ef91c9e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Mon, 16 Mar 2026 21:46:08 +0800 Subject: [PATCH] chore(governance): block batch mark activated when filters conflict --- .../Admin/PlatformOrderController.php | 11 ++ ...atedShouldBlockWhenConflictFiltersTest.php | 171 ++++++++++++++++++ 2 files changed, 182 insertions(+) create mode 100644 tests/Feature/AdminPlatformOrderBatchMarkActivatedShouldBlockWhenConflictFiltersTest.php diff --git a/app/Http/Controllers/Admin/PlatformOrderController.php b/app/Http/Controllers/Admin/PlatformOrderController.php index 3323a6f..9024bb1 100644 --- a/app/Http/Controllers/Admin/PlatformOrderController.php +++ b/app/Http/Controllers/Admin/PlatformOrderController.php @@ -1852,6 +1852,17 @@ class PlatformOrderController extends Controller if (($filters['sync_status'] ?? '') !== 'unsynced') { return redirect()->back()->with('warning', '为避免把同步失败等异常单混入,请先锁定「同步状态=未同步(sync_status=unsynced)」(建议用快捷筛选「待生效」)再执行批量仅标记为已生效。'); } + + // 互斥筛选阻断:避免“待生效”批量动作在其它治理集合上误触(或误以为会命中失败单/已同步单/可同步单)。 + if ((string) ($filters['fail_only'] ?? '') === '1' || trim((string) ($filters['sync_error_keyword'] ?? '')) !== '') { + return redirect()->back()->with('warning', '当前筛选包含「同步失败/失败原因」治理集合:与“待生效(unsynced)”互斥。请先切回待生效集合后再执行批量仅标记为已生效。'); + } + if ((string) ($filters['synced_only'] ?? '') === '1') { + return redirect()->back()->with('warning', '当前已勾选「只看已同步」:该集合与“待生效(unsynced)”互斥。请先取消该筛选后再执行批量仅标记为已生效。'); + } + if ((string) ($filters['syncable_only'] ?? '') === '1') { + return redirect()->back()->with('warning', '当前已勾选「只看可同步」:该集合语义为“已生效(activated)+未同步”,与本动作处理的“待处理(pending)”互斥。请先取消只看可同步后再执行。'); + } } // 防误操作:scope=all 需要二次确认 diff --git a/tests/Feature/AdminPlatformOrderBatchMarkActivatedShouldBlockWhenConflictFiltersTest.php b/tests/Feature/AdminPlatformOrderBatchMarkActivatedShouldBlockWhenConflictFiltersTest.php new file mode 100644 index 0000000..c03e74b --- /dev/null +++ b/tests/Feature/AdminPlatformOrderBatchMarkActivatedShouldBlockWhenConflictFiltersTest.php @@ -0,0 +1,171 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_batch_mark_activated_should_block_when_fail_only_is_set(): void + { + $this->loginAsPlatformAdmin(); + + $merchant = Merchant::query()->firstOrFail(); + $plan = Plan::query()->create([ + 'code' => 'batch_mark_activated_block_fail_only_plan', + 'name' => '批量仅标记生效阻断(fail_only)测试套餐', + 'billing_cycle' => 'monthly', + 'price' => 10, + 'list_price' => 10, + 'status' => 'active', + 'sort' => 10, + 'published_at' => now(), + ]); + + $o = PlatformOrder::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'order_no' => 'PO_BMA_BLOCK_FAIL_ONLY_0001', + 'order_type' => 'new_purchase', + 'status' => 'pending', + 'payment_status' => 'paid', + 'plan_name' => $plan->name, + 'billing_cycle' => $plan->billing_cycle, + 'period_months' => 1, + 'quantity' => 1, + 'payable_amount' => 10, + 'paid_amount' => 10, + 'placed_at' => now()->subMinutes(10), + 'paid_at' => now()->subMinutes(5), + 'meta' => [], + ]); + + $this->post('/admin/platform-orders/batch-mark-activated', [ + 'scope' => 'filtered', + 'payment_status' => 'paid', + 'status' => 'pending', + 'sync_status' => 'unsynced', + 'fail_only' => '1', + 'limit' => 50, + ]) + ->assertRedirect() + ->assertSessionHas('warning'); + + $o->refresh(); + $this->assertSame('pending', $o->status); + } + + public function test_batch_mark_activated_should_block_when_synced_only_is_set(): void + { + $this->loginAsPlatformAdmin(); + + $merchant = Merchant::query()->firstOrFail(); + $plan = Plan::query()->create([ + 'code' => 'batch_mark_activated_block_synced_only_plan', + 'name' => '批量仅标记生效阻断(synced_only)测试套餐', + 'billing_cycle' => 'monthly', + 'price' => 10, + 'list_price' => 10, + 'status' => 'active', + 'sort' => 10, + 'published_at' => now(), + ]); + + $o = PlatformOrder::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'order_no' => 'PO_BMA_BLOCK_SYNCED_ONLY_0001', + 'order_type' => 'new_purchase', + 'status' => 'pending', + 'payment_status' => 'paid', + 'plan_name' => $plan->name, + 'billing_cycle' => $plan->billing_cycle, + 'period_months' => 1, + 'quantity' => 1, + 'payable_amount' => 10, + 'paid_amount' => 10, + 'placed_at' => now()->subMinutes(10), + 'paid_at' => now()->subMinutes(5), + 'meta' => [], + ]); + + $this->post('/admin/platform-orders/batch-mark-activated', [ + 'scope' => 'filtered', + 'payment_status' => 'paid', + 'status' => 'pending', + 'sync_status' => 'unsynced', + 'synced_only' => '1', + 'limit' => 50, + ]) + ->assertRedirect() + ->assertSessionHas('warning'); + + $o->refresh(); + $this->assertSame('pending', $o->status); + } + + public function test_batch_mark_activated_should_block_when_syncable_only_is_set(): void + { + $this->loginAsPlatformAdmin(); + + $merchant = Merchant::query()->firstOrFail(); + $plan = Plan::query()->create([ + 'code' => 'batch_mark_activated_block_syncable_only_plan', + 'name' => '批量仅标记生效阻断(syncable_only)测试套餐', + 'billing_cycle' => 'monthly', + 'price' => 10, + 'list_price' => 10, + 'status' => 'active', + 'sort' => 10, + 'published_at' => now(), + ]); + + $o = PlatformOrder::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'order_no' => 'PO_BMA_BLOCK_SYNCABLE_ONLY_0001', + 'order_type' => 'new_purchase', + 'status' => 'pending', + 'payment_status' => 'paid', + 'plan_name' => $plan->name, + 'billing_cycle' => $plan->billing_cycle, + 'period_months' => 1, + 'quantity' => 1, + 'payable_amount' => 10, + 'paid_amount' => 10, + 'placed_at' => now()->subMinutes(10), + 'paid_at' => now()->subMinutes(5), + 'meta' => [], + ]); + + $this->post('/admin/platform-orders/batch-mark-activated', [ + 'scope' => 'filtered', + 'payment_status' => 'paid', + 'status' => 'pending', + 'sync_status' => 'unsynced', + 'syncable_only' => '1', + 'limit' => 50, + ]) + ->assertRedirect() + ->assertSessionHas('warning'); + + $o->refresh(); + $this->assertSame('pending', $o->status); + } +}