feat(admin): 站点管理页补齐订阅/平台订单/续费缺订阅治理入口 + back

This commit is contained in:
萝卜
2026-03-15 08:25:44 +00:00
parent 765195e7f3
commit 3b5cb6ede7
2 changed files with 80 additions and 1 deletions

View File

@@ -4,9 +4,41 @@
@section('page_title', '站点管理')
@section('content')
@php
// back 安全护栏:用于可能从其它页面跳入站点管理时的回退
$incomingBack = (string) request()->query('back', '');
$safeBackForLinks = \App\Support\BackUrl::sanitizeForLinks($incomingBack);
// 当前页自身(去掉 back用于生成 back 回跳,避免 back 嵌套膨胀
$selfWithoutBack = \App\Support\BackUrl::selfWithoutBack();
$merchantIndexUrlWithBack = \App\Support\BackUrl::withBack('/admin/merchants', $safeBackForLinks);
$makePlatformOrdersUrl = function (int $merchantId, array $overrides = []) use ($selfWithoutBack) {
$q = array_merge(['merchant_id' => $merchantId], $overrides);
$url = '/admin/platform-orders?' . \Illuminate\Support\Arr::query($q);
return \App\Support\BackUrl::withBack($url, $selfWithoutBack);
};
$makeSubscriptionsUrl = function (int $merchantId, array $overrides = []) use ($selfWithoutBack) {
$q = array_merge(['merchant_id' => $merchantId], $overrides);
$url = '/admin/site-subscriptions?' . \Illuminate\Support\Arr::query($q);
return \App\Support\BackUrl::withBack($url, $selfWithoutBack);
};
@endphp
<div class="card mb-20">
<p class="muted muted-tight">这里是总台视角的站点管理入口,用于开通、查看和维护 SaaS 站点主体。</p>
<p class="muted">当前站点列表已接入缓存:{{ $cacheMeta['store'] }} / TTL {{ $cacheMeta['ttl'] }}</p>
@if($safeBackForLinks !== '')
<div class="mt-10">
<a href="{!! $safeBackForLinks !!}" class="muted"> 返回上一页(保留上下文)</a>
</div>
@endif
<h3>新增站点</h3>
<form method="post" action="/admin/merchants">
@csrf
@@ -37,7 +69,12 @@
<td>{{ $merchant->status }}</td>
<td>{{ $merchant->contact_name }} / {{ $merchant->contact_phone }}</td>
<td>
<div class="actions gap-10">
<a href="/site-admin/login" target="_blank" rel="noopener">进入站点后台</a>
<a class="muted" href="{!! $makeSubscriptionsUrl((int) $merchant->id) !!}">订阅</a>
<a class="muted" href="{!! $makePlatformOrdersUrl((int) $merchant->id) !!}">平台订单</a>
<a class="muted" href="{!! $makePlatformOrdersUrl((int) $merchant->id, ['renewal_missing_subscription' => '1']) !!}">续费缺订阅</a>
</div>
<div class="muted muted-xs">当前阶段请使用该站点管理员账号登录</div>
</td>
</tr>

View File

@@ -0,0 +1,42 @@
<?php
namespace Tests\Feature;
use App\Models\Merchant;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AdminMerchantIndexGovernanceLinksShouldIncludeRenewalMissingSubscriptionTest 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_merchants_index_should_include_governance_links_with_back(): void
{
$this->loginAsPlatformAdmin();
$merchant = Merchant::query()->firstOrFail();
$res = $this->get('/admin/merchants');
$res->assertOk();
$html = (string) $res->getContent();
// 站点治理入口:订阅/平台订单/续费缺订阅
$this->assertStringContainsString('/admin/site-subscriptions?merchant_id=' . $merchant->id, $html);
$this->assertStringContainsString('/admin/platform-orders?merchant_id=' . $merchant->id, $html);
$this->assertStringContainsString('renewal_missing_subscription=1', $html);
// back 应回到站点管理页
$this->assertStringContainsString('back=' . urlencode('/admin/merchants'), $html);
}
}