Enhance: plans links to subscriptions/orders include back

This commit is contained in:
萝卜
2026-03-13 19:01:45 +00:00
parent fe15002ce4
commit c456585fb5
2 changed files with 122 additions and 2 deletions

View File

@@ -4,6 +4,28 @@
@section('page_title', '套餐管理') @section('page_title', '套餐管理')
@section('content') @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
<div class="card mb-20"> <div class="card mb-20">
<p class="muted muted-tight">这里是总台视角的套餐目录页,用于沉淀平台可售卖的标准能力包。</p> <p class="muted muted-tight">这里是总台视角的套餐目录页,用于沉淀平台可售卖的标准能力包。</p>
<p class="muted">当前阶段先完成套餐主数据可见、可筛与口径收拢,后续再接授权项、售价规则与上下架动作。</p> <p class="muted">当前阶段先完成套餐主数据可见、可筛与口径收拢,后续再接授权项、售价规则与上下架动作。</p>
@@ -125,7 +147,7 @@
<td> <td>
@php $subCount = (int) ($plan->subscriptions_count ?? 0); @endphp @php $subCount = (int) ($plan->subscriptions_count ?? 0); @endphp
@if($subCount > 0) @if($subCount > 0)
<a class="link" href="/admin/site-subscriptions?plan_id={{ $plan->id }}">{{ $subCount }} </a> <a class="link" href="{!! $makeSubscriptionUrl(['plan_id' => $plan->id]) !!}">{{ $subCount }} </a>
@else @else
<span class="muted">0</span> <span class="muted">0</span>
@endif @endif
@@ -133,7 +155,7 @@
<td> <td>
@php $orderCount = (int) ($plan->platform_orders_count ?? 0); @endphp @php $orderCount = (int) ($plan->platform_orders_count ?? 0); @endphp
@if($orderCount > 0) @if($orderCount > 0)
<a class="link" href="/admin/platform-orders?plan_id={{ $plan->id }}">{{ $orderCount }} </a> <a class="link" href="{!! $makePlatformOrderUrl(['plan_id' => $plan->id]) !!}">{{ $orderCount }} </a>
@else @else
<span class="muted">0</span> <span class="muted">0</span>
@endif @endif

View File

@@ -0,0 +1,98 @@
<?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 Illuminate\Support\Arr;
use Tests\TestCase;
class AdminPlanLinksContainBackTest 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_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);
}
}