From 03163ee60cf0b14b270141f73f135bd614e550d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Sun, 15 Mar 2026 17:02:44 +0800 Subject: [PATCH] =?UTF-8?q?feat(admin):=20=E7=BB=AD=E8=B4=B9=E7=BC=BA?= =?UTF-8?q?=E8=AE=A2=E9=98=85=E6=B2=BB=E7=90=86=E9=97=AD=E7=8E=AF=EF=BC=88?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E6=89=8B=E5=B7=A5=E7=BB=91=E5=AE=9A=E8=AE=A2?= =?UTF-8?q?=E9=98=85=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/platform_orders/show.blade.php | 10 +++ ...mOrderAttachSubscriptionShouldWorkTest.php | 87 +++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 tests/Feature/AdminPlatformOrderAttachSubscriptionShouldWorkTest.php diff --git a/resources/views/admin/platform_orders/show.blade.php b/resources/views/admin/platform_orders/show.blade.php index 41bb86d..16ce666 100644 --- a/resources/views/admin/platform_orders/show.blade.php +++ b/resources/views/admin/platform_orders/show.blade.php @@ -457,6 +457,16 @@ 去订阅管理查找订阅 @endif + +
+
+ @csrf + + + +
+
口径:仅用于“续费缺订阅”治理;系统将校验订阅的站点/套餐必须与当前订单一致,避免串单。
+
@endif diff --git a/tests/Feature/AdminPlatformOrderAttachSubscriptionShouldWorkTest.php b/tests/Feature/AdminPlatformOrderAttachSubscriptionShouldWorkTest.php new file mode 100644 index 0000000..8ad16bd --- /dev/null +++ b/tests/Feature/AdminPlatformOrderAttachSubscriptionShouldWorkTest.php @@ -0,0 +1,87 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_attach_subscription_should_bind_subscription_for_renewal_missing_subscription_order(): void + { + $this->loginAsPlatformAdmin(); + + $merchant = Merchant::query()->firstOrFail(); + + $plan = Plan::query()->create([ + 'code' => 'po_attach_sub_plan', + 'name' => '绑定订阅测试套餐', + 'billing_cycle' => 'monthly', + 'price' => 10, + 'list_price' => 10, + 'status' => 'active', + 'sort' => 10, + 'published_at' => now(), + ]); + + $sub = SiteSubscription::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'status' => 'active', + 'source' => 'manual', + 'subscription_no' => 'SS_ATTACH_SUB_0001', + 'plan_name' => $plan->name, + 'billing_cycle' => $plan->billing_cycle, + 'period_months' => 1, + 'amount' => 10, + 'starts_at' => now()->subDays(1), + 'ends_at' => now()->addDays(10), + 'snapshot' => [], + 'meta' => [], + ]); + + $order = PlatformOrder::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'order_no' => 'PO_ATTACH_SUB_0001', + 'order_type' => 'renewal', + 'site_subscription_id' => null, + 'status' => 'pending', + 'payment_status' => 'unpaid', + 'plan_name' => $plan->name, + 'billing_cycle' => $plan->billing_cycle, + 'period_months' => 1, + 'quantity' => 1, + 'payable_amount' => 10, + 'paid_amount' => 0, + 'placed_at' => now()->subMinutes(10), + 'meta' => [], + ]); + + $this->post('/admin/platform-orders/' . $order->id . '/attach-subscription', [ + 'site_subscription_id' => $sub->id, + ])->assertRedirect(); + + $order->refresh(); + + $this->assertSame($sub->id, (int) $order->site_subscription_id); + $this->assertSame('attach_subscription', (string) data_get($order->meta, 'audit.0.action')); + $this->assertSame($sub->id, (int) data_get($order->meta, 'audit.0.subscription_id')); + } +}