From 7dd508e84d459c0c689b668275eccd87be6ed6c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Sun, 15 Mar 2026 17:23:58 +0800 Subject: [PATCH] =?UTF-8?q?feat(admin):=20=E7=BB=91=E5=AE=9A=E8=AE=A2?= =?UTF-8?q?=E9=98=85=E5=90=8E=E5=9B=9E=E8=B7=B3=E6=8F=90=E7=A4=BA=E5=A2=9E?= =?UTF-8?q?=E5=BC=BA=EF=BC=88attached=5Fsubscription=20+=20=E6=BB=9A?= =?UTF-8?q?=E5=8A=A8=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin/PlatformOrderController.php | 15 +++- public/js/admin.js | 10 +++ ...houldCarryAttachedSubscriptionFlagTest.php | 84 +++++++++++++++++++ 3 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 tests/Feature/AdminPlatformOrderAttachSubscriptionRedirectShouldCarryAttachedSubscriptionFlagTest.php diff --git a/app/Http/Controllers/Admin/PlatformOrderController.php b/app/Http/Controllers/Admin/PlatformOrderController.php index 652abd6..38ee768 100644 --- a/app/Http/Controllers/Admin/PlatformOrderController.php +++ b/app/Http/Controllers/Admin/PlatformOrderController.php @@ -664,6 +664,11 @@ class PlatformOrderController extends Controller ]); $safeBack = \App\Support\BackUrl::sanitizeForLinks((string) ($data['back'] ?? '')); + // 进一步稳妥:强制回跳到订单详情自身(避免外部页面传错 back,导致运营迷路) + $fallbackBack = '/admin/platform-orders/' . $order->id; + if ($safeBack === '') { + $safeBack = $fallbackBack; + } if ((string) ($order->order_type ?? '') !== 'renewal') { return ($safeBack !== '' ? redirect($safeBack) : redirect()->back()) @@ -710,7 +715,15 @@ class PlatformOrderController extends Controller $order->save(); - return ($safeBack !== '' ? redirect($safeBack) : redirect()->back()) + // 绑定成功后追加一个轻量 query,用于前端 JS 做滚动/高亮提示(渐进增强) + $redirectUrl = $safeBack; + if (str_contains($redirectUrl, '?')) { + $redirectUrl .= '&attached_subscription=1'; + } else { + $redirectUrl .= '?attached_subscription=1'; + } + + return redirect($redirectUrl) ->with('success', '已绑定订阅:' . (string) ($sub->subscription_no ?? $sub->id)); } diff --git a/public/js/admin.js b/public/js/admin.js index fce76c3..44040f5 100644 --- a/public/js/admin.js +++ b/public/js/admin.js @@ -12,6 +12,16 @@ return (root || document).querySelector(sel); } + // 续费缺订阅治理:绑定成功后自动滚动到顶部提示区(让运营立刻看到 success/warning/error) + // 说明:由后端 redirect url 追加 attached_subscription=1 触发。 + if (window.location && window.location.search && window.location.search.indexOf('attached_subscription=1') >= 0) { + try { + window.scrollTo({ top: 0, behavior: 'smooth' }); + } catch (e) { + window.scrollTo(0, 0); + } + } + // 续费缺订阅治理:订单详情页“绑定订阅ID”输入框,小交互增强: // - 输入后按 Enter 直接提交 // - 自动聚焦,减少点击 diff --git a/tests/Feature/AdminPlatformOrderAttachSubscriptionRedirectShouldCarryAttachedSubscriptionFlagTest.php b/tests/Feature/AdminPlatformOrderAttachSubscriptionRedirectShouldCarryAttachedSubscriptionFlagTest.php new file mode 100644 index 0000000..9630e5d --- /dev/null +++ b/tests/Feature/AdminPlatformOrderAttachSubscriptionRedirectShouldCarryAttachedSubscriptionFlagTest.php @@ -0,0 +1,84 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_attach_subscription_should_redirect_to_order_show_with_attached_subscription_flag(): void + { + $this->loginAsPlatformAdmin(); + + $merchant = Merchant::query()->firstOrFail(); + + $plan = Plan::query()->create([ + 'code' => 'po_attach_sub_redirect_flag_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_REDIRECT_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_REDIRECT_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' => [], + ]); + + $res = $this->post('/admin/platform-orders/' . $order->id . '/attach-subscription', [ + 'site_subscription_id' => $sub->id, + // 故意不给 back:应回跳到订单详情自身,并携带 attached_subscription=1 + ]); + + $res->assertRedirect('/admin/platform-orders/' . $order->id . '?attached_subscription=1'); + } +}