Subscriptions: add renewal CTA on expiry governance view

This commit is contained in:
萝卜
2026-03-15 01:03:50 +00:00
parent f3f89e9492
commit 09cb6e9c6d
2 changed files with 72 additions and 0 deletions

View File

@@ -98,6 +98,27 @@
<div class="actions">
<a class="btn btn-secondary btn-sm" href="{!! $expiredUrl !!}">已过期({{ $summaryStats['expired_subscriptions'] ?? 0 }}</a>
<a class="btn btn-secondary btn-sm" href="{!! $expiring7dUrl !!}">7天内到期({{ $summaryStats['expiring_7d_subscriptions'] ?? 0 }}</a>
@php
// 当已处于“到期集合”视图时,补一个就近的续费下单入口(带回退到当前列表的 back
$isExpiryView = in_array((string) ($filters['expiry'] ?? ''), ['expired', 'expiring_7d'], true);
$renewalCtaUrl = '';
if ($isExpiryView) {
$q = [
'order_type' => 'renewal',
];
if ((int) ($filters['merchant_id'] ?? 0) > 0) {
$q['merchant_id'] = (int) $filters['merchant_id'];
}
if ((int) ($filters['plan_id'] ?? 0) > 0) {
$q['plan_id'] = (int) $filters['plan_id'];
}
$renewalCtaUrl = \App\Support\BackUrl::withBack('/admin/platform-orders/create?' . \Illuminate\Support\Arr::query($q), $selfWithoutBack);
}
@endphp
@if($isExpiryView)
<a class="btn btn-sm" href="{!! $renewalCtaUrl !!}">创建续费订单(当前集合)</a>
@endif
</div>
<div class="muted muted-xs mt-6">建议先处理“7天内到期”续费触达再处理“已过期”补单或关闭。</div>

View File

@@ -0,0 +1,51 @@
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AdminSiteSubscriptionIndexExpiryGovernanceRenewalCtaTest 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_expiry_view_should_show_create_renewal_order_cta_with_back_to_self(): void
{
$this->loginAsPlatformAdmin();
$res = $this->get('/admin/site-subscriptions?expiry=expiring_7d&merchant_id=2&plan_id=3');
$res->assertOk();
$res->assertSee('创建续费订单(当前集合)');
// CTA 应带上当前筛选 merchant_id/plan_id并且 back 回到当前列表selfWithoutBack
$res->assertSee('href="/admin/platform-orders/create?order_type=renewal&merchant_id=2&plan_id=3&back=%2Fadmin%2Fsite-subscriptions%3Fexpiry%3Dexpiring_7d%26merchant_id%3D2%26plan_id%3D3"', false);
// 链接不应出现 &amp;(只检查该 CTA 的 href 文本中不含 &amp;
$html = (string) $res->getContent();
preg_match('/href="([^"]+)"[^>]*>创建续费订单(当前集合)<\/a>/', $html, $m);
$ctaHref = (string) ($m[1] ?? '');
$this->assertNotSame('', $ctaHref);
$this->assertStringNotContainsString('&amp;', $ctaHref);
}
public function test_non_expiry_view_should_not_show_renewal_cta(): void
{
$this->loginAsPlatformAdmin();
$res = $this->get('/admin/site-subscriptions?status=activated');
$res->assertOk();
$res->assertDontSee('创建续费订单(当前集合)');
}
}