feat(bmpa): write last_result summary for batch tracing
This commit is contained in:
@@ -1868,12 +1868,53 @@ class PlatformOrderController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$msg = '批量标记支付并生效完成:成功 ' . $success . ' 条,失败 ' . $failed . ' 条(命中 ' . $matchedTotal . ' 条,本次处理 ' . $processed . ' 条,limit=' . $limit . ',run_id=' . $runId . ')';
|
||||
|
||||
// 写入最小结果汇总(冗余写入到每条订单的 meta.batch_mark_paid_and_activate.last_result),便于运营在列表页直接看到“本次批量 BMPA 的执行结果”。
|
||||
// 注意:当前阶段不引入新表;后续若 BMPA Job 化,可复用 BAS 的 last_result 模式。
|
||||
$topReasons = [];
|
||||
if ($failed > 0 && count($failedReasonCounts) > 0) {
|
||||
arsort($failedReasonCounts);
|
||||
$top = array_slice($failedReasonCounts, 0, 3, true);
|
||||
$topText = collect($top)->map(function ($cnt, $reason) {
|
||||
foreach ($top as $reason => $cnt) {
|
||||
$topReasons[] = [
|
||||
'reason' => mb_substr((string) $reason, 0, 80),
|
||||
'count' => (int) $cnt,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$summary = [
|
||||
'run_id' => $runId,
|
||||
'success' => $success,
|
||||
'failed' => $failed,
|
||||
'matched' => (int) $matchedTotal,
|
||||
'processed' => (int) $processed,
|
||||
'top_reasons' => $topReasons,
|
||||
'at' => now()->toDateTimeString(),
|
||||
];
|
||||
|
||||
foreach ($orders as $row) {
|
||||
$order = PlatformOrder::query()->find($row->id);
|
||||
if (! $order) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$meta = (array) ($order->meta ?? []);
|
||||
$bmpa = (array) (data_get($meta, 'batch_mark_paid_and_activate', []) ?? []);
|
||||
if ((string) (data_get($bmpa, 'run_id') ?? '') !== $runId) {
|
||||
continue;
|
||||
}
|
||||
|
||||
data_set($bmpa, 'last_result', $summary);
|
||||
data_set($meta, 'batch_mark_paid_and_activate', $bmpa);
|
||||
|
||||
$order->meta = $meta;
|
||||
$order->save();
|
||||
}
|
||||
|
||||
$msg = '批量标记支付并生效完成:成功 ' . $success . ' 条,失败 ' . $failed . ' 条(命中 ' . $matchedTotal . ' 条,本次处理 ' . $processed . ' 条,limit=' . $limit . ',run_id=' . $runId . ')';
|
||||
|
||||
if ($failed > 0 && count($failedReasonCounts) > 0) {
|
||||
$topText = collect($failedReasonCounts)->sortDesc()->take(3)->map(function ($cnt, $reason) {
|
||||
$reason = mb_substr((string) $reason, 0, 60);
|
||||
return $reason . '(' . (int) $cnt . ')';
|
||||
})->implode(';');
|
||||
|
||||
Reference in New Issue
Block a user