feat: dashboard merchant revenue rank top5 7d
This commit is contained in:
@@ -141,6 +141,27 @@ class DashboardController extends Controller
|
||||
|
||||
$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', [
|
||||
'adminName' => $admin->name,
|
||||
'stats' => $stats,
|
||||
@@ -148,6 +169,8 @@ class DashboardController extends Controller
|
||||
'recentPlatformOrders' => $recentPlatformOrders,
|
||||
'planOrderShare' => $planOrderShare,
|
||||
'planIdToName' => $planIdToName,
|
||||
'merchantRevenueRank7d' => $merchantRevenueRank7d,
|
||||
'merchantIdToName' => $merchantIdToName,
|
||||
'platformAdmin' => $admin,
|
||||
'cacheMeta' => [
|
||||
'store' => config('cache.default'),
|
||||
|
||||
@@ -114,9 +114,49 @@
|
||||
<div class="muted muted-xs mt-10">说明:先接入最小可用趋势数据;后续再补时间范围切换、维度切换与可视化图表。</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<h3 class="mt-0">排行</h3>
|
||||
<div class="muted">(占位)后续接入:站点续费金额排行、套餐销量排行、异常订单排行等。</div>
|
||||
<div class="muted muted-xs mt-10">说明:后续会补“时间范围切换 + 维度切换”的渐进增强交互。</div>
|
||||
<h3 class="mt-0">排行(近7天站点收入 Top5)</h3>
|
||||
@php
|
||||
$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>
|
||||
|
||||
|
||||
@@ -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('&back=', false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user