feat: dashboard add platform order trend 7d
This commit is contained in:
@@ -84,6 +84,39 @@ class DashboardController extends Controller
|
||||
]
|
||||
);
|
||||
|
||||
// 趋势卡(最小可用):近 7 天平台订单按天统计(订单数 + 已付金额)
|
||||
$trendDays = 7;
|
||||
$trendStart = now()->startOfDay()->subDays($trendDays - 1);
|
||||
$trendEnd = now()->endOfDay();
|
||||
|
||||
$trendRawRows = PlatformOrder::query()
|
||||
->selectRaw("DATE(created_at) as d")
|
||||
->selectRaw('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('d')
|
||||
->orderBy('d')
|
||||
->get();
|
||||
|
||||
$trendByDate = [];
|
||||
foreach ($trendRawRows as $r) {
|
||||
$trendByDate[(string) $r->d] = [
|
||||
'date' => (string) $r->d,
|
||||
'count' => (int) ($r->cnt ?? 0),
|
||||
'paid_sum' => (float) ($r->paid_sum ?? 0),
|
||||
];
|
||||
}
|
||||
|
||||
$platformOrderTrend7d = [];
|
||||
for ($i = 0; $i < $trendDays; $i++) {
|
||||
$day = $trendStart->copy()->addDays($i)->format('Y-m-d');
|
||||
$platformOrderTrend7d[] = $trendByDate[$day] ?? [
|
||||
'date' => $day,
|
||||
'count' => 0,
|
||||
'paid_sum' => 0.0,
|
||||
];
|
||||
}
|
||||
|
||||
$recentPlatformOrders = PlatformOrder::query()
|
||||
->orderByDesc('id')
|
||||
->limit(5)
|
||||
@@ -111,6 +144,7 @@ class DashboardController extends Controller
|
||||
return view('admin.dashboard', [
|
||||
'adminName' => $admin->name,
|
||||
'stats' => $stats,
|
||||
'platformOrderTrend7d' => $platformOrderTrend7d,
|
||||
'recentPlatformOrders' => $recentPlatformOrders,
|
||||
'planOrderShare' => $planOrderShare,
|
||||
'planIdToName' => $planIdToName,
|
||||
|
||||
Reference in New Issue
Block a user