diff --git a/app/Http/Controllers/Admin/PlanController.php b/app/Http/Controllers/Admin/PlanController.php
index 0f59fde..a593e11 100644
--- a/app/Http/Controllers/Admin/PlanController.php
+++ b/app/Http/Controllers/Admin/PlanController.php
@@ -89,7 +89,7 @@ class PlanController extends Controller
'published' => trim((string) $request->query('published', '')),
];
- $plansQuery = $this->applyFilters(Plan::query(), $filters);
+ $plansQuery = $this->applyFilters(Plan::query()->withCount(['subscriptions', 'platformOrders']), $filters);
$plans = (clone $plansQuery)
->orderBy('sort')
@@ -111,6 +111,9 @@ class PlanController extends Controller
'yearly_plans' => (clone $plansQuery)->where('billing_cycle', 'yearly')->count(),
'published_plans' => (clone $plansQuery)->whereNotNull('published_at')->count(),
'unpublished_plans' => (clone $plansQuery)->whereNull('published_at')->count(),
+ // 治理联动:当前筛选范围内关联订阅/订单总量
+ 'subscriptions_count' => (clone $plansQuery)->sum('subscriptions_count'),
+ 'platform_orders_count' => (clone $plansQuery)->sum('platform_orders_count'),
],
'statusLabels' => $this->statusLabels(),
'billingCycleLabels' => $this->billingCycleLabels(),
diff --git a/resources/views/admin/plans/index.blade.php b/resources/views/admin/plans/index.blade.php
index 365c08b..b2976b9 100644
--- a/resources/views/admin/plans/index.blade.php
+++ b/resources/views/admin/plans/index.blade.php
@@ -73,12 +73,12 @@
{{ $summaryStats['yearly_plans'] ?? 0 }}
-
已发布
-
{{ $summaryStats['published_plans'] ?? 0 }}
+
关联订阅总量
+
{{ $summaryStats['subscriptions_count'] ?? 0 }}
-
未发布
-
{{ $summaryStats['unpublished_plans'] ?? 0 }}
+
关联平台订单总量
+
{{ $summaryStats['platform_orders_count'] ?? 0 }}
@@ -102,6 +102,8 @@
状态 |
排序 |
发布时间 |
+ 关联订阅 |
+ 关联平台订单 |
操作 |
@@ -120,6 +122,22 @@
{{ $statusLabels[$plan->status] ?? $plan->status }} |
{{ $plan->sort }} |
{{ optional($plan->published_at)->format('Y-m-d H:i:s') ?: '-' }} |
+
+ @php $subCount = (int) ($plan->subscriptions_count ?? 0); @endphp
+ @if($subCount > 0)
+ {{ $subCount }} 个
+ @else
+ 0
+ @endif
+ |
+
+ @php $orderCount = (int) ($plan->platform_orders_count ?? 0); @endphp
+ @if($orderCount > 0)
+ {{ $orderCount }} 单
+ @else
+ 0
+ @endif
+ |
编辑
@@ -136,7 +154,7 @@
@empty
|
- | 暂无套餐数据,当前阶段先把套餐主表与总台目录立起来,后续可继续接套餐创建、授权项与订阅关联。 |
+ 暂无套餐数据,当前阶段先把套餐主表与总台目录立起来,后续可继续接套餐创建、授权项与订阅关联。 |
@endforelse
diff --git a/tests/Feature/AdminPlanLinksToSubscriptionsAndOrdersTest.php b/tests/Feature/AdminPlanLinksToSubscriptionsAndOrdersTest.php
new file mode 100644
index 0000000..e983e1f
--- /dev/null
+++ b/tests/Feature/AdminPlanLinksToSubscriptionsAndOrdersTest.php
@@ -0,0 +1,86 @@
+seed();
+
+ $this->post('/admin/login', [
+ 'email' => 'platform.admin@demo.local',
+ 'password' => 'Platform@123456',
+ ])->assertRedirect('/admin');
+ }
+
+ public function test_plans_page_shows_links_to_related_subscriptions_and_orders(): void
+ {
+ $this->loginAsPlatformAdmin();
+
+ $merchant = Merchant::query()->firstOrFail();
+
+ $plan = Plan::query()->create([
+ 'code' => 'link_test_monthly',
+ 'name' => '联动测试(月付)',
+ '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_LINK_PLAN_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_LINK_PLAN_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),
+ ]);
+
+ $this->get('/admin/plans')
+ ->assertOk()
+ ->assertSee('/admin/site-subscriptions?plan_id=' . $plan->id, false)
+ ->assertSee('/admin/platform-orders?plan_id=' . $plan->id, false)
+ ->assertSee('关联订阅')
+ ->assertSee('关联平台订单');
+ }
+}