From 7dfc71ec23f92535f681d1c7330c424b603e62a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Wed, 11 Mar 2026 08:29:30 +0000 Subject: [PATCH] =?UTF-8?q?=E5=8D=95=E7=AC=94=E5=90=8C=E6=AD=A5=E8=AE=A2?= =?UTF-8?q?=E9=98=85=EF=BC=9A=E6=B2=BB=E7=90=86=E4=BC=98=E5=85=88=E5=AE=89?= =?UTF-8?q?=E5=85=A8=E9=98=80=20+=20=E6=B5=8B=E8=AF=95=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin/PlatformOrderController.php | 5 ++ ...eSubscriptionGovernanceSafetyValveTest.php | 73 +++++++++++++++++++ ...nPlatformOrderActivateSubscriptionTest.php | 7 ++ 3 files changed, 85 insertions(+) create mode 100644 tests/Feature/AdminPlatformOrderActivateSubscriptionGovernanceSafetyValveTest.php diff --git a/app/Http/Controllers/Admin/PlatformOrderController.php b/app/Http/Controllers/Admin/PlatformOrderController.php index ecafb2d..1c71559 100644 --- a/app/Http/Controllers/Admin/PlatformOrderController.php +++ b/app/Http/Controllers/Admin/PlatformOrderController.php @@ -359,6 +359,11 @@ class PlatformOrderController extends Controller { $admin = $this->ensurePlatformAdmin($request); + // 治理优先:当订单命中金额/状态不一致时,不建议直接同步订阅(避免把“带病订单”同步到订阅) + if ($order->isReconcileMismatch() || $order->isRefundInconsistent()) { + return redirect()->back()->with('warning', '当前订单命中「对账不一致/退款不一致」,为避免带病同步,请先完成金额/状态治理(补回执/核对退款/修正状态)后再同步订阅。'); + } + try { $subscription = $service->activateOrder($order->id, $admin->id); diff --git a/tests/Feature/AdminPlatformOrderActivateSubscriptionGovernanceSafetyValveTest.php b/tests/Feature/AdminPlatformOrderActivateSubscriptionGovernanceSafetyValveTest.php new file mode 100644 index 0000000..2a2dac0 --- /dev/null +++ b/tests/Feature/AdminPlatformOrderActivateSubscriptionGovernanceSafetyValveTest.php @@ -0,0 +1,73 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_activate_subscription_blocked_when_order_is_reconcile_mismatch(): void + { + $this->loginAsPlatformAdmin(); + + $merchant = Merchant::query()->firstOrFail(); + $plan = Plan::query()->create([ + 'code' => 'activate_subscription_gov_safety_valve_test', + 'name' => '单笔同步治理安全阀测试套餐', + 'billing_cycle' => 'monthly', + 'price' => 66, + 'list_price' => 66, + 'status' => 'active', + 'sort' => 10, + 'published_at' => now(), + ]); + + $order = PlatformOrder::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'order_no' => 'PO_ACT_GOV_BLOCK_0001', + 'order_type' => 'new_purchase', + 'status' => 'activated', + 'payment_status' => 'paid', + 'plan_name' => $plan->name, + 'billing_cycle' => $plan->billing_cycle, + 'period_months' => 1, + 'quantity' => 1, + 'payable_amount' => 66, + 'paid_amount' => 66, + 'placed_at' => now()->subMinutes(10), + 'paid_at' => now()->subMinutes(5), + 'activated_at' => now()->subMinutes(1), + // 对账不一致:receipt_total 65.98 vs paid_amount 66 + 'meta' => [ + 'payment_summary' => [ + 'count' => 1, + 'total_amount' => 65.98, + ], + ], + ]); + + $res = $this->post('/admin/platform-orders/' . $order->id . '/activate-subscription'); + $res->assertRedirect(); + $res->assertSessionHas('warning'); + + $order->refresh(); + $this->assertNull($order->site_subscription_id); + } +} diff --git a/tests/Feature/AdminPlatformOrderActivateSubscriptionTest.php b/tests/Feature/AdminPlatformOrderActivateSubscriptionTest.php index b72e3e1..1f18b8a 100644 --- a/tests/Feature/AdminPlatformOrderActivateSubscriptionTest.php +++ b/tests/Feature/AdminPlatformOrderActivateSubscriptionTest.php @@ -56,6 +56,13 @@ class AdminPlatformOrderActivateSubscriptionTest extends TestCase 'placed_at' => now()->subMinutes(10), 'paid_at' => now()->subMinutes(5), 'activated_at' => now()->subMinutes(1), + // 避免命中“治理优先”安全阀:构造回执与已付金额一致 + 'meta' => [ + 'payment_summary' => [ + 'count' => 1, + 'total_amount' => 66.00, + ], + ], ]); $this->post('/admin/platform-orders/' . $order->id . '/activate-subscription')