feat(bmpa): write run_id and richer meta for batch mark paid and activate

This commit is contained in:
萝卜
2026-03-17 14:03:06 +08:00
parent 9e40e73481
commit 0718090f49
2 changed files with 138 additions and 4 deletions

View File

@@ -1586,7 +1586,6 @@ class PlatformOrderController extends Controller
$success = 0;
$failed = 0;
$failedReasonCounts = [];
// 筛选摘要:用于审计记录(避免每条订单都手写拼接,且便于追溯本次批量处理口径)
$filterSummaryParts = [];
@@ -1699,8 +1698,12 @@ class PlatformOrderController extends Controller
$orders = $query->orderByDesc('id')->limit($limit)->get(['id']);
$processed = $orders->count();
// 批次号:用于把一次批量执行关联起来,便于后续追溯/筛选/可观测。
$runId = 'BMPA' . now()->format('YmdHis') . str_pad((string) random_int(1, 9999), 4, '0', STR_PAD_LEFT);
$success = 0;
$failed = 0;
$failedReasonCounts = [];
// 筛选摘要:用于审计记录(便于追溯本次批量处理口径)
$filterSummaryParts = [];
@@ -1816,11 +1819,13 @@ class PlatformOrderController extends Controller
];
data_set($meta2, 'audit', $audit);
// 便于追踪:记录最近一次批量推进信息
// 便于追踪:记录最近一次批量推进信息(扁平字段)
data_set($meta2, 'batch_mark_paid_and_activate', [
'at' => $nowStr,
'admin_id' => $admin->id,
'scope' => $scope,
'mode' => 'sync',
'run_id' => $runId,
]);
$order->meta = $meta2;
@@ -1834,17 +1839,43 @@ class PlatformOrderController extends Controller
$reason = $reason !== '' ? $reason : '未知错误';
$meta = (array) ($order->meta ?? []);
$failedReasonCounts[$reason] = ($failedReasonCounts[$reason] ?? 0) + 1;
data_set($meta, 'batch_mark_paid_and_activate_error', [
'message' => $reason,
'at' => $nowStr,
'admin_id' => $admin->id,
'scope' => $scope,
'run_id' => $runId,
'filters' => $filterSummary,
]);
// 即使失败也写入 batch_mark_paid_and_activate包含 run_id确保本批次可追溯。
data_set($meta, 'batch_mark_paid_and_activate', [
'at' => $nowStr,
'admin_id' => $admin->id,
'scope' => $scope,
'mode' => 'sync',
'run_id' => $runId,
]);
$order->meta = $meta;
$order->save();
}
}
$msg = '批量标记支付并生效完成:成功 ' . $success . ' 条,失败 ' . $failed . ' 条(命中 ' . $matchedTotal . ' 条,本次处理 ' . $processed . ' 条limit=' . $limit . '';
$msg = '批量标记支付并生效完成:成功 ' . $success . ' 条,失败 ' . $failed . ' 条(命中 ' . $matchedTotal . ' 条,本次处理 ' . $processed . ' 条limit=' . $limit . 'run_id=' . $runId . '';
if ($failed > 0 && count($failedReasonCounts) > 0) {
arsort($failedReasonCounts);
$top = array_slice($failedReasonCounts, 0, 3, true);
$topText = collect($top)->map(function ($cnt, $reason) {
$reason = mb_substr((string) $reason, 0, 60);
return $reason . '' . (int) $cnt . '';
})->implode('');
$msg .= '失败原因Top' . $topText;
}
return redirect()->back()->with('success', $msg);
}
@@ -1953,7 +1984,6 @@ class PlatformOrderController extends Controller
$success = 0;
$failed = 0;
$failedReasonCounts = [];
$nowStr = now()->toDateTimeString();
// 筛选摘要:用于审计记录(便于追溯本次批量处理口径)