refactor(dashboard): inject 7d range from controller to avoid drift

This commit is contained in:
萝卜
2026-03-17 04:24:10 +08:00
parent 842eeb3e39
commit 583854bd35
2 changed files with 9 additions and 3 deletions

View File

@@ -164,6 +164,10 @@ class DashboardController extends Controller
$trendStart = now()->startOfDay()->subDays($trendDays - 1);
$trendEnd = now()->endOfDay();
// 统一提供给视图做“趋势/排行/占比”跳转的日期范围口径,避免 Blade 内重复 now() 计算导致漂移。
$dashboardRangeFrom7d = (string) $trendStart->format('Y-m-d');
$dashboardRangeTo7d = (string) $trendEnd->format('Y-m-d');
$trendRawRows = PlatformOrder::query()
->selectRaw("DATE(created_at) as d")
->selectRaw('COUNT(*) as cnt')
@@ -265,6 +269,8 @@ class DashboardController extends Controller
'stats' => $stats,
'platformOrderTrend7d' => $platformOrderTrend7d,
'recentPlatformOrders' => $recentPlatformOrders,
'dashboardRangeFrom7d' => $dashboardRangeFrom7d,
'dashboardRangeTo7d' => $dashboardRangeTo7d,
'planOrderShare' => $planOrderShare,
'planOrderShareTotal' => (int) $planOrderShareTotal,
'planIdToName' => $planIdToName,