perf(admin): platform orders list read batch_activation first

This commit is contained in:
萝卜
2026-03-10 11:32:01 +00:00
parent 50f15cdea8
commit c3a16fae9e
3 changed files with 33 additions and 1 deletions

View File

@@ -105,6 +105,26 @@ class PlatformOrderController extends Controller
->count(),
'total_payable_amount' => (float) ((clone $baseQuery)->sum('payable_amount') ?: 0),
'total_paid_amount' => (float) ((clone $baseQuery)->sum('paid_amount') ?: 0),
'syncable_orders' => (clone $baseQuery)
->where('payment_status', 'paid')
->where('status', 'activated')
->whereRaw("JSON_EXTRACT(meta, '$.subscription_activation.subscription_id') IS NULL")
->count(),
'batch_synced_24h_orders' => (function () use ($baseQuery) {
$since = now()->subHours(24)->format('Y-m-d H:i:s');
$q = (clone $baseQuery)
->whereRaw("JSON_EXTRACT(meta, '$.batch_activation.at') IS NOT NULL");
$driver = $q->getQuery()->getConnection()->getDriverName();
if ($driver === 'sqlite') {
$q->whereRaw("JSON_EXTRACT(meta, '$.batch_activation.at') >= ?", [$since]);
} else {
$q->whereRaw("JSON_UNQUOTE(JSON_EXTRACT(meta, '$.batch_activation.at')) >= ?", [$since]);
}
return $q->count();
})(),
],
'failedReasonStats' => $failedReasonStats,
]);