Admin subscriptions: expiring 7d add mini bar visualization

This commit is contained in:
萝卜
2026-03-17 01:05:48 +08:00
parent aca99d1f30
commit 0474f23713
3 changed files with 108 additions and 2 deletions

View File

@@ -589,6 +589,21 @@
color:var(--adm-text-muted, #94a3b8);
}
/* 订阅到期治理mini bar纯 CSS占比可视化增强说服力 */
[data-page="admin.site_subscriptions.index"] .adm-mini-bar{
height:8px;
margin-top:6px;
border-radius:999px;
background:var(--adm-bg-elevated, rgba(148, 163, 184, .12));
overflow:hidden;
}
[data-page="admin.site_subscriptions.index"] .adm-mini-bar-fill{
display:block;
height:100%;
background:linear-gradient(90deg, var(--adm-color-primary, #1677ff), rgba(22, 119, 255, .35));
}
.collapsible > summary{
list-style:none;
cursor:pointer;

View File

@@ -137,7 +137,18 @@
<span class="muted">(建议:进入后按订阅维度续费)</span>
</div>
</td>
<td>{{ $cnt }}</td>
<td>
{{ $cnt }}
@php
$barPct = 0;
if ((int) ($summaryStats['expiring_7d_subscriptions'] ?? 0) > 0) {
$barPct = min(100, max(0, round(((int) $cnt / (int) ($summaryStats['expiring_7d_subscriptions'] ?? 1)) * 100, 1)));
}
@endphp
<div class="adm-mini-bar" data-role="expiry-merchant-bar" title="占比 {{ $barPct }}%">
<span class="adm-mini-bar-fill" style="width: {{ $barPct }}%"></span>
</div>
</td>
<td>{{ $minEndsAt !== '' ? $minEndsAt : '-' }}</td>
</tr>
@empty
@@ -182,7 +193,18 @@
<tr>
<td><a class="link" href="{!! $mpUrl !!}">{{ $mname !== '' ? $mname : ('站点#' . $mid) }}</a></td>
<td>{{ $pname !== '' ? $pname : ('套餐#' . $pid) }}</td>
<td>{{ $cnt }}</td>
<td>
{{ $cnt }}
@php
$barPct = 0;
if ((int) ($summaryStats['expiring_7d_subscriptions'] ?? 0) > 0) {
$barPct = min(100, max(0, round(((int) $cnt / (int) ($summaryStats['expiring_7d_subscriptions'] ?? 1)) * 100, 1)));
}
@endphp
<div class="adm-mini-bar" data-role="expiry-merchant-plan-bar" title="占比 {{ $barPct }}%">
<span class="adm-mini-bar-fill" style="width: {{ $barPct }}%"></span>
</div>
</td>
<td>
{{ $minEndsAt !== '' ? $minEndsAt : '-' }}
<div class="muted muted-xs mt-6">

View File

@@ -0,0 +1,69 @@
<?php
namespace Tests\Feature;
use App\Models\Merchant;
use App\Models\Plan;
use App\Models\SiteSubscription;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AdminSiteSubscriptionIndexExpiring7dMiniBarsShouldRenderTest 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_expiring_7d_view_should_render_mini_bars_for_visualization(): void
{
$this->loginAsPlatformAdmin();
$merchant = Merchant::query()->firstOrFail();
$plan = Plan::query()->create([
'code' => 'sub_expiry_mini_bar_plan',
'name' => '到期治理 MiniBar 测试套餐',
'billing_cycle' => 'monthly',
'price' => 1,
'list_price' => 1,
'status' => 'active',
'sort' => 10,
'published_at' => now(),
]);
SiteSubscription::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'status' => 'activated',
'source' => 'manual',
'subscription_no' => 'SUB_EXP_MINI_BAR_0001',
'plan_name' => $plan->name,
'billing_cycle' => $plan->billing_cycle,
'period_months' => 1,
'amount' => 1,
'starts_at' => now()->subDays(10),
'ends_at' => now()->addDays(3),
'activated_at' => now()->subDays(10),
]);
$res = $this->get('/admin/site-subscriptions?expiry=expiring_7d');
$res->assertOk();
$html = (string) $res->getContent();
$this->assertStringContainsString('data-role="expiring-7d-merchant-top10"', $html);
$this->assertStringContainsString('class="adm-mini-bar"', $html);
$this->assertStringContainsString('class="adm-mini-bar-fill"', $html);
$css = (string) file_get_contents(public_path('css/admin-components.css'));
$this->assertStringContainsString('[data-page="admin.site_subscriptions.index"] .adm-mini-bar', $css);
$this->assertStringContainsString('[data-page="admin.site_subscriptions.index"] .adm-mini-bar-fill', $css);
}
}