feat(platform-orders): 增加批量生效24h筛选与统计

This commit is contained in:
萝卜
2026-03-10 15:24:10 +00:00
parent 09726d4f57
commit 852a6dbf3e
3 changed files with 143 additions and 0 deletions

View File

@@ -134,8 +134,11 @@ class PlatformOrderController extends Controller
'syncable_only' => (string) $request->query('syncable_only', ''),
// 只看最近 24 小时批量同步过的订单(可治理追踪)
'batch_synced_24h' => (string) $request->query('batch_synced_24h', ''),
// 只看最近 24 小时批量“仅标记为已生效”过的订单(可治理追踪)
'batch_mark_activated_24h' => (string) $request->query('batch_mark_activated_24h', ''),
];
$orders = $this->applyFilters(PlatformOrder::query()->with(['merchant', 'plan', 'siteSubscription']), $filters)
->latest('id')
->paginate(10)
@@ -224,6 +227,21 @@ class PlatformOrderController extends Controller
$q->whereRaw("JSON_UNQUOTE(JSON_EXTRACT(meta, '$.batch_activation.at')) >= ?", [$since]);
}
return $q->count();
})(),
'batch_mark_activated_24h_orders' => (function () use ($baseQuery) {
$since = now()->subHours(24)->format('Y-m-d H:i:s');
$q = (clone $baseQuery)
->whereRaw("JSON_EXTRACT(meta, '$.batch_mark_activated.at') IS NOT NULL");
$driver = $q->getQuery()->getConnection()->getDriverName();
if ($driver === 'sqlite') {
$q->whereRaw("JSON_EXTRACT(meta, '$.batch_mark_activated.at') >= ?", [$since]);
} else {
$q->whereRaw("JSON_UNQUOTE(JSON_EXTRACT(meta, '$.batch_mark_activated.at')) >= ?", [$since]);
}
return $q->count();
})(),
],
@@ -363,8 +381,11 @@ class PlatformOrderController extends Controller
'syncable_only' => (string) $request->query('syncable_only', ''),
// 只看最近 24 小时批量同步过的订单(可治理追踪)
'batch_synced_24h' => (string) $request->query('batch_synced_24h', ''),
// 只看最近 24 小时批量“仅标记为已生效”过的订单(可治理追踪)
'batch_mark_activated_24h' => (string) $request->query('batch_mark_activated_24h', ''),
];
$includeMeta = (string) $request->query('include_meta', '') === '1';
$query = $this->applyFilters(
@@ -817,6 +838,19 @@ class PlatformOrderController extends Controller
} else {
$builder->whereRaw("JSON_UNQUOTE(JSON_EXTRACT(meta, '$.batch_activation.at')) >= ?", [$since]);
}
})
->when(($filters['batch_mark_activated_24h'] ?? '') !== '', function (Builder $builder) {
// 只看最近 24 小时批量“仅标记为已生效”过的订单(基于 meta.batch_mark_activated.at
$since = now()->subHours(24)->format('Y-m-d H:i:s');
$builder->whereRaw("JSON_EXTRACT(meta, '$.batch_mark_activated.at') IS NOT NULL");
$driver = $builder->getQuery()->getConnection()->getDriverName();
if ($driver === 'sqlite') {
$builder->whereRaw("JSON_EXTRACT(meta, '$.batch_mark_activated.at') >= ?", [$since]);
} else {
$builder->whereRaw("JSON_UNQUOTE(JSON_EXTRACT(meta, '$.batch_mark_activated.at')) >= ?", [$since]);
}
});
}