feat(batch): 批次页last_result缺失时提供同批次粗略统计
This commit is contained in:
@@ -32,6 +32,7 @@ class PlatformBatchController extends Controller
|
||||
'safeBackForLinks' => $safeBackForLinks,
|
||||
'error' => '参数不完整:请提供 type(bas/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_error,BMPA=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,
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user