Subscriptions: add renewal CTA on expiry governance view
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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);
|
||||
|
||||
// 链接不应出现 &(只检查该 CTA 的 href 文本中不含 &)
|
||||
$html = (string) $res->getContent();
|
||||
preg_match('/href="([^"]+)"[^>]*>创建续费订单(当前集合)<\/a>/', $html, $m);
|
||||
$ctaHref = (string) ($m[1] ?? '');
|
||||
$this->assertNotSame('', $ctaHref);
|
||||
$this->assertStringNotContainsString('&', $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('创建续费订单(当前集合)');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user