diff --git a/app/Http/Controllers/Admin/PlatformBatchController.php b/app/Http/Controllers/Admin/PlatformBatchController.php index 58083a7..f117060 100644 --- a/app/Http/Controllers/Admin/PlatformBatchController.php +++ b/app/Http/Controllers/Admin/PlatformBatchController.php @@ -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, ]); } diff --git a/resources/views/admin/platform_batches/show.blade.php b/resources/views/admin/platform_batches/show.blade.php index e455ef3..f37cd8b 100644 --- a/resources/views/admin/platform_batches/show.blade.php +++ b/resources/views/admin/platform_batches/show.blade.php @@ -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
@@ -37,18 +42,25 @@ @if(($error ?? '') !== '')
{{ $error }}
@else + @if(! $hasSummary) +
+ 本批次尚未生成 last_result 汇总(可能队列任务仍在执行,或历史数据未补齐)。 + 当前页面展示的是基于同批次订单的粗略统计,供运营先行定位。 +
+ @endif +

命中

-
{{ $matched }}
+
{{ $hasSummary ? $matched : $fallbackMatched }}

本次处理

-
{{ $processed }}
+
{{ $hasSummary ? $processed : '-' }}

成功 / 失败

-
{{ $success }} / {{ $failed }}
+
{{ $hasSummary ? ($success . ' / ' . $failed) : ('- / ' . $fallbackFailed) }}
@@ -80,8 +92,10 @@

Top 失败原因

- @if(count($topReasons) === 0) -
暂无(或尚未写入 last_result)。
+ @if(! $hasSummary) +
暂无(last_result 未写入时不做原因聚合,以免在页面侧引入重查询)。
+ @elseif(count($topReasons) === 0) +
暂无。
@else