diff --git a/resources/views/admin/plans/index.blade.php b/resources/views/admin/plans/index.blade.php
index b2976b9..37ec3a8 100644
--- a/resources/views/admin/plans/index.blade.php
+++ b/resources/views/admin/plans/index.blade.php
@@ -4,6 +4,28 @@
@section('page_title', '套餐管理')
@section('content')
+@php
+ // back 参数用于“返回上一页(保留上下文)”,但 back 本身不应再包含 back(避免无限嵌套导致 URL 膨胀)
+ $currentQuery = request()->query();
+ unset($currentQuery['back']);
+ $selfWithoutBack = '/' . ltrim(request()->path(), '/');
+ if (count($currentQuery) > 0) {
+ $selfWithoutBack .= '?' . \Illuminate\Support\Arr::query($currentQuery);
+ }
+
+ // 用于构建“从套餐页跳转到订阅/订单页后可返回套餐页”的链接
+ $makeSubscriptionUrl = function (array $query) use ($selfWithoutBack) {
+ $query = $query + ['back' => $selfWithoutBack];
+
+ return '/admin/site-subscriptions?' . \Illuminate\Support\Arr::query($query);
+ };
+
+ $makePlatformOrderUrl = function (array $query) use ($selfWithoutBack) {
+ $query = $query + ['back' => $selfWithoutBack];
+
+ return '/admin/platform-orders?' . \Illuminate\Support\Arr::query($query);
+ };
+@endphp
这里是总台视角的套餐目录页,用于沉淀平台可售卖的标准能力包。
当前阶段先完成套餐主数据可见、可筛与口径收拢,后续再接授权项、售价规则与上下架动作。
@@ -125,7 +147,7 @@
@php $subCount = (int) ($plan->subscriptions_count ?? 0); @endphp
@if($subCount > 0)
- {{ $subCount }} 个
+ {{ $subCount }} 个
@else
0
@endif
@@ -133,7 +155,7 @@
|
@php $orderCount = (int) ($plan->platform_orders_count ?? 0); @endphp
@if($orderCount > 0)
- {{ $orderCount }} 单
+ {{ $orderCount }} 单
@else
0
@endif
diff --git a/tests/Feature/AdminPlanLinksContainBackTest.php b/tests/Feature/AdminPlanLinksContainBackTest.php
new file mode 100644
index 0000000..0aa24e5
--- /dev/null
+++ b/tests/Feature/AdminPlanLinksContainBackTest.php
@@ -0,0 +1,98 @@
+seed();
+
+ $this->post('/admin/login', [
+ 'email' => 'platform.admin@demo.local',
+ 'password' => 'Platform@123456',
+ ])->assertRedirect('/admin');
+ }
+
+ public function test_plans_page_links_to_subscriptions_and_orders_should_contain_back(): void
+ {
+ $this->loginAsPlatformAdmin();
+
+ $merchant = Merchant::query()->firstOrFail();
+
+ $plan = Plan::query()->create([
+ 'code' => 'plan_link_back_test',
+ 'name' => '套餐联动 back 测试',
+ 'billing_cycle' => 'monthly',
+ 'price' => 9.9,
+ 'list_price' => 9.9,
+ 'status' => 'active',
+ 'sort' => 1,
+ 'published_at' => now(),
+ ]);
+
+ $sub = SiteSubscription::query()->create([
+ 'merchant_id' => $merchant->id,
+ 'plan_id' => $plan->id,
+ 'status' => 'activated',
+ 'source' => 'manual',
+ 'subscription_no' => 'SUB_PLAN_LINK_BACK_0001',
+ 'plan_name' => $plan->name,
+ 'billing_cycle' => $plan->billing_cycle,
+ 'period_months' => 1,
+ 'amount' => 9.9,
+ 'starts_at' => now()->subDay(),
+ 'ends_at' => now()->addMonth(),
+ 'activated_at' => now()->subDay(),
+ ]);
+
+ PlatformOrder::query()->create([
+ 'merchant_id' => $merchant->id,
+ 'plan_id' => $plan->id,
+ 'site_subscription_id' => $sub->id,
+ 'order_no' => 'PO_PLAN_LINK_BACK_0001',
+ 'order_type' => 'new_purchase',
+ 'status' => 'activated',
+ 'payment_status' => 'paid',
+ 'plan_name' => $plan->name,
+ 'billing_cycle' => $plan->billing_cycle,
+ 'period_months' => 1,
+ 'quantity' => 1,
+ 'list_amount' => 9.9,
+ 'discount_amount' => 0,
+ 'payable_amount' => 9.9,
+ 'paid_amount' => 9.9,
+ 'placed_at' => now()->subHour(),
+ 'paid_at' => now()->subMinutes(30),
+ 'activated_at' => now()->subMinutes(20),
+ ]);
+
+ $back = '/admin/plans?status=active';
+
+ $res = $this->get($back);
+ $res->assertOk();
+
+ $expectedSubscriptionUrl = '/admin/site-subscriptions?' . Arr::query([
+ 'plan_id' => $plan->id,
+ 'back' => $back,
+ ]);
+
+ $expectedOrderUrl = '/admin/platform-orders?' . Arr::query([
+ 'plan_id' => $plan->id,
+ 'back' => $back,
+ ]);
+
+ $res->assertSee($expectedSubscriptionUrl, false);
+ $res->assertSee($expectedOrderUrl, false);
+ }
+}
|