feat(plans): 列表显示关联订阅/订单数量并提供跳转
This commit is contained in:
@@ -89,7 +89,7 @@ class PlanController extends Controller
|
|||||||
'published' => trim((string) $request->query('published', '')),
|
'published' => trim((string) $request->query('published', '')),
|
||||||
];
|
];
|
||||||
|
|
||||||
$plansQuery = $this->applyFilters(Plan::query(), $filters);
|
$plansQuery = $this->applyFilters(Plan::query()->withCount(['subscriptions', 'platformOrders']), $filters);
|
||||||
|
|
||||||
$plans = (clone $plansQuery)
|
$plans = (clone $plansQuery)
|
||||||
->orderBy('sort')
|
->orderBy('sort')
|
||||||
@@ -111,6 +111,9 @@ class PlanController extends Controller
|
|||||||
'yearly_plans' => (clone $plansQuery)->where('billing_cycle', 'yearly')->count(),
|
'yearly_plans' => (clone $plansQuery)->where('billing_cycle', 'yearly')->count(),
|
||||||
'published_plans' => (clone $plansQuery)->whereNotNull('published_at')->count(),
|
'published_plans' => (clone $plansQuery)->whereNotNull('published_at')->count(),
|
||||||
'unpublished_plans' => (clone $plansQuery)->whereNull('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(),
|
'statusLabels' => $this->statusLabels(),
|
||||||
'billingCycleLabels' => $this->billingCycleLabels(),
|
'billingCycleLabels' => $this->billingCycleLabels(),
|
||||||
|
|||||||
@@ -73,12 +73,12 @@
|
|||||||
<div class="num-md">{{ $summaryStats['yearly_plans'] ?? 0 }}</div>
|
<div class="num-md">{{ $summaryStats['yearly_plans'] ?? 0 }}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<h3>已发布</h3>
|
<h3>关联订阅总量</h3>
|
||||||
<div class="num-md">{{ $summaryStats['published_plans'] ?? 0 }}</div>
|
<div class="num-md">{{ $summaryStats['subscriptions_count'] ?? 0 }}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<h3>未发布</h3>
|
<h3>关联平台订单总量</h3>
|
||||||
<div class="num-md">{{ $summaryStats['unpublished_plans'] ?? 0 }}</div>
|
<div class="num-md">{{ $summaryStats['platform_orders_count'] ?? 0 }}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -102,6 +102,8 @@
|
|||||||
<th>状态</th>
|
<th>状态</th>
|
||||||
<th>排序</th>
|
<th>排序</th>
|
||||||
<th>发布时间</th>
|
<th>发布时间</th>
|
||||||
|
<th>关联订阅</th>
|
||||||
|
<th>关联平台订单</th>
|
||||||
<th>操作</th>
|
<th>操作</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -120,6 +122,22 @@
|
|||||||
<td>{{ $statusLabels[$plan->status] ?? $plan->status }}</td>
|
<td>{{ $statusLabels[$plan->status] ?? $plan->status }}</td>
|
||||||
<td>{{ $plan->sort }}</td>
|
<td>{{ $plan->sort }}</td>
|
||||||
<td>{{ optional($plan->published_at)->format('Y-m-d H:i:s') ?: '-' }}</td>
|
<td>{{ optional($plan->published_at)->format('Y-m-d H:i:s') ?: '-' }}</td>
|
||||||
|
<td>
|
||||||
|
@php $subCount = (int) ($plan->subscriptions_count ?? 0); @endphp
|
||||||
|
@if($subCount > 0)
|
||||||
|
<a class="link" href="/admin/site-subscriptions?plan_id={{ $plan->id }}">{{ $subCount }} 个</a>
|
||||||
|
@else
|
||||||
|
<span class="muted">0</span>
|
||||||
|
@endif
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@php $orderCount = (int) ($plan->platform_orders_count ?? 0); @endphp
|
||||||
|
@if($orderCount > 0)
|
||||||
|
<a class="link" href="/admin/platform-orders?plan_id={{ $plan->id }}">{{ $orderCount }} 单</a>
|
||||||
|
@else
|
||||||
|
<span class="muted">0</span>
|
||||||
|
@endif
|
||||||
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<a href="/admin/plans/{{ $plan->id }}/edit" class="link">编辑</a>
|
<a href="/admin/plans/{{ $plan->id }}/edit" class="link">编辑</a>
|
||||||
|
|
||||||
@@ -136,7 +154,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
@empty
|
@empty
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="10" class="muted">暂无套餐数据,当前阶段先把套餐主表与总台目录立起来,后续可继续接套餐创建、授权项与订阅关联。</td>
|
<td colspan="12" class="muted">暂无套餐数据,当前阶段先把套餐主表与总台目录立起来,后续可继续接套餐创建、授权项与订阅关联。</td>
|
||||||
</tr>
|
</tr>
|
||||||
@endforelse
|
@endforelse
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
86
tests/Feature/AdminPlanLinksToSubscriptionsAndOrdersTest.php
Normal file
86
tests/Feature/AdminPlanLinksToSubscriptionsAndOrdersTest.php
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use App\Models\Merchant;
|
||||||
|
use App\Models\Plan;
|
||||||
|
use App\Models\PlatformOrder;
|
||||||
|
use App\Models\SiteSubscription;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class AdminPlanLinksToSubscriptionsAndOrdersTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
protected function loginAsPlatformAdmin(): void
|
||||||
|
{
|
||||||
|
$this->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('关联平台订单');
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user