refactor(platform-orders): created_at 快捷日期范围由 controller 注入

This commit is contained in:
萝卜
2026-03-17 06:43:58 +08:00
parent 96f19ecdf2
commit df99fb00ed
2 changed files with 17 additions and 3 deletions

View File

@@ -367,6 +367,14 @@ class PlatformOrderController extends Controller
$totalPayableAmount = (float) ((clone $baseQuery)->sum('payable_amount') ?: 0); $totalPayableAmount = (float) ((clone $baseQuery)->sum('payable_amount') ?: 0);
$totalPaidAmount = (float) ((clone $baseQuery)->sum('paid_amount') ?: 0); $totalPaidAmount = (float) ((clone $baseQuery)->sum('paid_amount') ?: 0);
// created_at 快捷入口日期范围:由 Controller 统一注入,避免 Blade 内多次 now() 调用跨天漂移。
$baseToday = now();
$createdRangeToday = $baseToday->format('Y-m-d');
// 近7天包含今天共 7 天,因此 from = today - 6 days
$createdRangeFrom7d = $baseToday->copy()->subDays(6)->format('Y-m-d');
// 近30天包含今天共 30 天,因此 from = today - 29 days
$createdRangeFrom30d = $baseToday->copy()->subDays(29)->format('Y-m-d');
return view('admin.platform_orders.index', [ return view('admin.platform_orders.index', [
'currentSubscription' => $currentSubscription, 'currentSubscription' => $currentSubscription,
'orders' => $orders, 'orders' => $orders,
@@ -397,6 +405,11 @@ class PlatformOrderController extends Controller
'paymentStatusLabels' => $this->paymentStatusLabels(), 'paymentStatusLabels' => $this->paymentStatusLabels(),
// order_type label 映射已下沉到 PlatformOrder::orderTypeLabel();这里不再透传 orderTypeLabels // order_type label 映射已下沉到 PlatformOrder::orderTypeLabel();这里不再透传 orderTypeLabels
// 'orderTypeLabels' => $this->orderTypeLabels(), // 'orderTypeLabels' => $this->orderTypeLabels(),
// created_at 快捷入口日期范围
'createdRangeToday' => $createdRangeToday,
'createdRangeFrom7d' => $createdRangeFrom7d,
'createdRangeFrom30d' => $createdRangeFrom30d,
'summaryStats' => [ 'summaryStats' => [
'total_orders' => (clone $baseQuery)->count(), 'total_orders' => (clone $baseQuery)->count(),
'paid_orders' => (clone $baseQuery)->where('payment_status', 'paid')->count(), 'paid_orders' => (clone $baseQuery)->where('payment_status', 'paid')->count(),

View File

@@ -411,9 +411,10 @@
<input type="date" name="created_to" data-role="po-created-to" placeholder="创建时间到YYYY-MM-DD" value="{{ $filters['created_to'] ?? '' }}" class="w-180"> <input type="date" name="created_to" data-role="po-created-to" placeholder="创建时间到YYYY-MM-DD" value="{{ $filters['created_to'] ?? '' }}" class="w-180">
@php @php
// 运营提效:常用时间范围快捷入口(保持 query/back 安全口径;不依赖 JS // 运营提效:常用时间范围快捷入口(保持 query/back 安全口径;不依赖 JS
$today = now()->format('Y-m-d'); // 日期范围由 Controller 注入,避免 Blade 内多次 now() 调用跨天漂移。
$from7d = now()->subDays(6)->format('Y-m-d'); $today = (string) ($createdRangeToday ?? now()->format('Y-m-d'));
$from30d = now()->subDays(29)->format('Y-m-d'); $from7d = (string) ($createdRangeFrom7d ?? now()->subDays(6)->format('Y-m-d'));
$from30d = (string) ($createdRangeFrom30d ?? now()->subDays(29)->format('Y-m-d'));
$createdRangeTodayUrl = $safeFullUrlWithQuery([ $createdRangeTodayUrl = $safeFullUrlWithQuery([
'created_from' => $today, 'created_from' => $today,