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,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -10,12 +10,17 @@
|
||||
$selfWithoutBack = \App\Support\BackUrl::selfWithoutBack();
|
||||
$backToListUrl = $safeBackForLinks !== '' ? $safeBackForLinks : '/admin/platform-orders';
|
||||
|
||||
$hasSummary = $summary !== null;
|
||||
|
||||
$success = (int) (data_get($summary, 'success') ?? 0);
|
||||
$failed = (int) (data_get($summary, 'failed') ?? 0);
|
||||
$matched = (int) (data_get($summary, 'matched') ?? 0);
|
||||
$processed = (int) (data_get($summary, 'processed') ?? 0);
|
||||
$at = (string) (data_get($summary, 'at') ?? '');
|
||||
$topReasons = (array) (data_get($summary, 'top_reasons', []) ?? []);
|
||||
|
||||
$fallbackMatched = (int) (data_get($fallbackCounts, 'matched') ?? 0);
|
||||
$fallbackFailed = (int) (data_get($fallbackCounts, 'failed') ?? 0);
|
||||
@endphp
|
||||
|
||||
<div class="card mb-20">
|
||||
@@ -37,18 +42,25 @@
|
||||
@if(($error ?? '') !== '')
|
||||
<div class="warning">{{ $error }}</div>
|
||||
@else
|
||||
@if(! $hasSummary)
|
||||
<div class="warning mb-20">
|
||||
本批次尚未生成 last_result 汇总(可能队列任务仍在执行,或历史数据未补齐)。
|
||||
当前页面展示的是基于同批次订单的<strong>粗略统计</strong>,供运营先行定位。
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<div class="grid-3 mb-20">
|
||||
<div class="card">
|
||||
<h3>命中</h3>
|
||||
<div class="metric-number">{{ $matched }}</div>
|
||||
<div class="metric-number">{{ $hasSummary ? $matched : $fallbackMatched }}</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<h3>本次处理</h3>
|
||||
<div class="metric-number">{{ $processed }}</div>
|
||||
<div class="metric-number">{{ $hasSummary ? $processed : '-' }}</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<h3>成功 / 失败</h3>
|
||||
<div class="metric-number">{{ $success }} / {{ $failed }}</div>
|
||||
<div class="metric-number">{{ $hasSummary ? ($success . ' / ' . $failed) : ('- / ' . $fallbackFailed) }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -80,8 +92,10 @@
|
||||
|
||||
<div class="card">
|
||||
<h3>Top 失败原因</h3>
|
||||
@if(count($topReasons) === 0)
|
||||
<div class="muted">暂无(或尚未写入 last_result)。</div>
|
||||
@if(! $hasSummary)
|
||||
<div class="muted">暂无(last_result 未写入时不做原因聚合,以免在页面侧引入重查询)。</div>
|
||||
@elseif(count($topReasons) === 0)
|
||||
<div class="muted">暂无。</div>
|
||||
@else
|
||||
<table class="table">
|
||||
<thead>
|
||||
|
||||
Reference in New Issue
Block a user