From c4c91ebf14153d6a565cc1bd050959e8c24f32b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Sun, 15 Mar 2026 04:42:37 +0000 Subject: [PATCH] =?UTF-8?q?=E6=A0=87=E8=AE=B0=E6=94=AF=E4=BB=98=E5=B9=B6?= =?UTF-8?q?=E7=94=9F=E6=95=88=EF=BC=9A=E7=BB=AD=E8=B4=B9=E5=8D=95=E5=BF=85?= =?UTF-8?q?=E9=A1=BB=E7=BB=91=E5=AE=9A=E8=AE=A2=E9=98=85=EF=BC=88=E5=AE=89?= =?UTF-8?q?=E5=85=A8=E9=98=80=EF=BC=89=E5=B9=B6=E6=96=B0=E5=A2=9E=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin/PlatformOrderController.php | 5 ++ ...ewalShouldRequireSubscriptionGuardTest.php | 68 +++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 tests/Feature/AdminPlatformOrderMarkPaidAndActivateRenewalShouldRequireSubscriptionGuardTest.php diff --git a/app/Http/Controllers/Admin/PlatformOrderController.php b/app/Http/Controllers/Admin/PlatformOrderController.php index 3d5d677..a1a2370 100644 --- a/app/Http/Controllers/Admin/PlatformOrderController.php +++ b/app/Http/Controllers/Admin/PlatformOrderController.php @@ -684,6 +684,11 @@ class PlatformOrderController extends Controller { $admin = $this->ensurePlatformAdmin($request); + // 治理优先:续费单必须绑定订阅(兼容历史脏数据/手工改库等场景) + if ((string) ($order->order_type ?? '') === 'renewal' && ! (int) ($order->site_subscription_id ?? 0)) { + return redirect()->back()->with('warning', '当前订单类型为「续费」,但未绑定订阅(site_subscription_id 为空)。为避免误同步/续期串单,请先补齐订阅关联后再处理。'); + } + // 治理优先:若该订单已有退款轨迹(refund_summary/refund_receipts),不允许直接“标记支付并生效”,避免出现带退款的订单被强行推进并同步订阅 if ((float) $order->refundTotal() > 0) { return redirect()->back()->with('warning', '当前订单已存在退款记录/退款汇总,请先核对退款轨迹与订单状态后再处理(不建议直接标记支付并生效)。'); diff --git a/tests/Feature/AdminPlatformOrderMarkPaidAndActivateRenewalShouldRequireSubscriptionGuardTest.php b/tests/Feature/AdminPlatformOrderMarkPaidAndActivateRenewalShouldRequireSubscriptionGuardTest.php new file mode 100644 index 0000000..ca5a471 --- /dev/null +++ b/tests/Feature/AdminPlatformOrderMarkPaidAndActivateRenewalShouldRequireSubscriptionGuardTest.php @@ -0,0 +1,68 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_mark_paid_and_activate_should_be_blocked_when_order_is_renewal_but_subscription_missing(): void + { + $this->loginAsPlatformAdmin(); + + $merchant = Merchant::query()->firstOrFail(); + $plan = Plan::query()->create([ + 'code' => 'mark_paid_renewal_requires_sub_guard_plan', + 'name' => '标记支付续费必须绑订阅安全阀测试套餐', + 'billing_cycle' => 'monthly', + 'price' => 30, + 'list_price' => 30, + 'status' => 'active', + 'sort' => 10, + 'published_at' => now(), + ]); + + // 人为构造“脏数据”:renewal 但 site_subscription_id 为空 + $order = PlatformOrder::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'order_no' => 'PO_MARK_PAID_RENEWAL_NO_SUB_0001', + 'order_type' => 'renewal', + 'status' => 'pending', + 'payment_status' => 'unpaid', + 'plan_name' => $plan->name, + 'billing_cycle' => $plan->billing_cycle, + 'period_months' => 1, + 'quantity' => 1, + 'payable_amount' => 30, + 'paid_amount' => 0, + 'placed_at' => now(), + 'meta' => [], + ]); + + $res = $this->post('/admin/platform-orders/' . $order->id . '/mark-paid-and-activate'); + $res->assertRedirect(); + $res->assertSessionHas('warning'); + + $order->refresh(); + $this->assertSame('unpaid', $order->payment_status); + $this->assertSame('pending', $order->status); + $this->assertNull($order->site_subscription_id); + } +}