platform orders: add created_at range filter (created_from/to)

This commit is contained in:
萝卜
2026-03-16 00:30:09 +08:00
parent 223ea1d950
commit 0a58204799
3 changed files with 126 additions and 3 deletions

View File

@@ -273,6 +273,9 @@ class PlatformOrderController extends Controller
'refund_inconsistent' => (string) $request->query('refund_inconsistent', ''),
// 线索联动:用于从开通线索跳转查看关联订单
'lead_id' => trim((string) $request->query('lead_id', '')),
// 创建时间范围(用于“趋势→集合”跳转与运营筛选)
'created_from' => trim((string) $request->query('created_from', '')),
'created_to' => trim((string) $request->query('created_to', '')),
];
@@ -1235,6 +1238,9 @@ class PlatformOrderController extends Controller
'refund_inconsistent' => (string) $request->query('refund_inconsistent', ''),
// 线索联动:用于从开通线索跳转查看关联订单
'lead_id' => trim((string) $request->query('lead_id', '')),
// 创建时间范围(用于“趋势→集合”跳转与运营筛选)
'created_from' => trim((string) $request->query('created_from', '')),
'created_to' => trim((string) $request->query('created_to', '')),
];
@@ -2404,6 +2410,32 @@ class PlatformOrderController extends Controller
} else {
$builder->whereRaw("CAST(JSON_UNQUOTE(JSON_EXTRACT(meta, '$.platform_lead_id')) AS UNSIGNED) = ?", [$leadId]);
}
})
->when(($filters['created_from'] ?? '') !== '' || ($filters['created_to'] ?? '') !== '', function (Builder $builder) use ($filters) {
// 创建时间范围筛选:用于“趋势→集合”跳转与运营快速定位
// 口径:基于 created_at。
$from = trim((string) ($filters['created_from'] ?? ''));
$to = trim((string) ($filters['created_to'] ?? ''));
// 容错:仅接受 YYYY-MM-DD 格式;不合法则忽略,避免异常输入污染查询
if ($from !== '' && ! preg_match('/^\d{4}-\d{2}-\d{2}$/', $from)) {
$from = '';
}
if ($to !== '' && ! preg_match('/^\d{4}-\d{2}-\d{2}$/', $to)) {
$to = '';
}
if ($from !== '' && $to !== '') {
// [from 00:00:00, to 23:59:59]
$builder->whereBetween('created_at', [
$from . ' 00:00:00',
$to . ' 23:59:59',
]);
} elseif ($from !== '') {
$builder->where('created_at', '>=', $from . ' 00:00:00');
} elseif ($to !== '') {
$builder->where('created_at', '<=', $to . ' 23:59:59');
}
});
}