feat: dashboard merchant revenue rank top5 7d

This commit is contained in:
萝卜
2026-03-15 23:08:29 +08:00
parent 397789df92
commit e92636dd5b
3 changed files with 102 additions and 3 deletions

View File

@@ -141,6 +141,27 @@ class DashboardController extends Controller
$planIdToName = Plan::query()->pluck('name', 'id')->all(); $planIdToName = Plan::query()->pluck('name', 'id')->all();
// 排行卡(最小可用):近 7 天站点收入排行 Top5按已付金额
$merchantRevenueRank7d = PlatformOrder::query()
->selectRaw('merchant_id, COUNT(*) as cnt')
->selectRaw("SUM(CASE WHEN payment_status = 'paid' THEN paid_amount ELSE 0 END) as paid_sum")
->whereBetween('created_at', [$trendStart, $trendEnd])
->groupBy('merchant_id')
->orderByDesc('paid_sum')
->limit(5)
->get()
->map(function ($row) {
return [
'merchant_id' => (int) ($row->merchant_id ?? 0),
'count' => (int) ($row->cnt ?? 0),
'paid_sum' => (float) ($row->paid_sum ?? 0),
];
})
->values()
->all();
$merchantIdToName = Merchant::query()->pluck('name', 'id')->all();
return view('admin.dashboard', [ return view('admin.dashboard', [
'adminName' => $admin->name, 'adminName' => $admin->name,
'stats' => $stats, 'stats' => $stats,
@@ -148,6 +169,8 @@ class DashboardController extends Controller
'recentPlatformOrders' => $recentPlatformOrders, 'recentPlatformOrders' => $recentPlatformOrders,
'planOrderShare' => $planOrderShare, 'planOrderShare' => $planOrderShare,
'planIdToName' => $planIdToName, 'planIdToName' => $planIdToName,
'merchantRevenueRank7d' => $merchantRevenueRank7d,
'merchantIdToName' => $merchantIdToName,
'platformAdmin' => $admin, 'platformAdmin' => $admin,
'cacheMeta' => [ 'cacheMeta' => [
'store' => config('cache.default'), 'store' => config('cache.default'),

View File

@@ -114,9 +114,49 @@
<div class="muted muted-xs mt-10">说明:先接入最小可用趋势数据;后续再补时间范围切换、维度切换与可视化图表。</div> <div class="muted muted-xs mt-10">说明:先接入最小可用趋势数据;后续再补时间范围切换、维度切换与可视化图表。</div>
</div> </div>
<div class="card"> <div class="card">
<h3 class="mt-0">排行</h3> <h3 class="mt-0">排行近7天站点收入 Top5</h3>
<div class="muted">(占位)后续接入:站点续费金额排行、套餐销量排行、异常订单排行等。</div> @php
<div class="muted muted-xs mt-10">说明:后续会补“时间范围切换 + 维度切换”的渐进增强交互。</div> $rankRows = (array) ($merchantRevenueRank7d ?? []);
$rankTotal = 0.0;
foreach ($rankRows as $r) {
$rankTotal += (float) ($r['paid_sum'] ?? 0);
}
@endphp
<div class="muted">Top5 合计已付 ¥{{ number_format($rankTotal, 2) }}</div>
<table class="mt-10" data-role="merchant-revenue-rank-7d">
<thead>
<tr>
<th>站点</th>
<th>订单数</th>
<th>已付金额</th>
</tr>
</thead>
<tbody>
@forelse($rankRows as $row)
@php
$mid = (int) ($row['merchant_id'] ?? 0);
$mname = (string) (($merchantIdToName[$mid] ?? '') ?: ('#' . $mid));
$merchantOrdersUrl = \App\Support\BackUrl::withBack(
'/admin/platform-orders?' . \Illuminate\Support\Arr::query(['merchant_id' => $mid]),
$selfWithoutBack
);
@endphp
<tr>
<td><a class="link" href="{!! $merchantOrdersUrl !!}">{{ $mname }}</a></td>
<td>{{ (int) ($row['count'] ?? 0) }}</td>
<td>¥{{ number_format((float) ($row['paid_sum'] ?? 0), 2) }}</td>
</tr>
@empty
<tr>
<td colspan="3" class="muted">暂无数据</td>
</tr>
@endforelse
</tbody>
</table>
<div class="muted muted-xs mt-10">说明:先落最小可用 Top5 排行;后续补时间范围切换、维度切换与异常排行。</div>
</div> </div>
</div> </div>

View File

@@ -0,0 +1,36 @@
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AdminDashboardMerchantRevenueRank7dCardShouldRenderTest 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_dashboard_merchant_revenue_rank_7d_card_should_render(): void
{
$this->loginAsPlatformAdmin();
$res = $this->get('/admin');
$res->assertOk();
$res->assertSee('排行近7天站点收入 Top5', false);
$res->assertSee('data-role="merchant-revenue-rank-7d"', false);
// 链接应携带 back保持仪表盘治理链路一致性
$res->assertSee('back=%2Fadmin', false);
$res->assertDontSee('&amp;back=', false);
}
}