feat(batch): 批次页last_result缺失时提供同批次粗略统计

This commit is contained in:
萝卜
2026-03-17 16:12:07 +08:00
parent 52d1507847
commit ea9cbe430c
2 changed files with 55 additions and 5 deletions

View File

@@ -32,6 +32,7 @@ class PlatformBatchController extends Controller
'safeBackForLinks' => $safeBackForLinks,
'error' => '参数不完整:请提供 typebas/bmpa与 run_id。',
'summary' => null,
'fallbackCounts' => null,
'governanceLinks' => [],
]);
}
@@ -58,6 +59,40 @@ class PlatformBatchController extends Controller
: 'batch_mark_paid_and_activate.last_result');
}
// 兜底:若 last_result 未写入(例如批量 job 尚未跑完,或历史数据未补齐),
// 则基于同批次订单粗略统计matched/processed/failed失败口径BAS=subscription_activation_errorBMPA=batch_mark_paid_and_activate_error
// 注意:这里尽量不做重计算 success因为“成功”的定义可能随业务变动仅用于 UI 提示。
$fallbackCounts = null;
if ($summary === null) {
$baseQuery = PlatformOrder::query();
$driver2 = $baseQuery->getQuery()->getConnection()->getDriverName();
if ($driver2 === 'sqlite') {
$baseQuery->whereRaw("JSON_EXTRACT(meta, '{$keyPrefix}.run_id') = ?", [$runId]);
} else {
$baseQuery->whereRaw("JSON_UNQUOTE(JSON_EXTRACT(meta, '{$keyPrefix}.run_id')) = ?", [$runId]);
}
$matched = (int) (clone $baseQuery)->count();
$failed = 0;
if ($type === 'bas') {
$failed = (int) (clone $baseQuery)
->whereRaw("JSON_EXTRACT(meta, '$.subscription_activation_error.message') IS NOT NULL")
->count();
}
if ($type === 'bmpa') {
$failed = (int) (clone $baseQuery)
->whereRaw("JSON_EXTRACT(meta, '$.batch_mark_paid_and_activate_error.message') IS NOT NULL")
->count();
}
$fallbackCounts = [
'matched' => $matched,
'failed' => $failed,
];
}
// 治理入口:全部/失败/按Top原因/可重试
$governanceLinks = [];
@@ -119,6 +154,7 @@ class PlatformBatchController extends Controller
'safeBackForLinks' => $safeBackForLinks,
'error' => '',
'summary' => $summary,
'fallbackCounts' => $fallbackCounts,
'governanceLinks' => $governanceLinks,
]);
}