platform orders: batch mark activated guard renewal missing subscription
This commit is contained in:
@@ -1758,6 +1758,8 @@ class PlatformOrderController extends Controller
|
||||
$processed = $orders->count();
|
||||
|
||||
$success = 0;
|
||||
$failed = 0;
|
||||
$failedReasonCounts = [];
|
||||
$nowStr = now()->toDateTimeString();
|
||||
|
||||
// 筛选摘要:用于审计记录(便于追溯本次批量处理口径)
|
||||
@@ -1780,6 +1782,27 @@ class PlatformOrderController extends Controller
|
||||
continue;
|
||||
}
|
||||
|
||||
// 治理优先:续费单必须绑定订阅(兼容历史脏数据/手工改库等场景)
|
||||
if ((string) ($order->order_type ?? '') === 'renewal' && ! (int) ($order->site_subscription_id ?? 0)) {
|
||||
$failed++;
|
||||
|
||||
$reason = '续费单未绑定订阅(site_subscription_id 为空),不允许批量仅标记为已生效。';
|
||||
$failedReasonCounts[$reason] = ($failedReasonCounts[$reason] ?? 0) + 1;
|
||||
|
||||
$meta = (array) ($order->meta ?? []);
|
||||
data_set($meta, 'batch_mark_activated_error', [
|
||||
'message' => $reason,
|
||||
'at' => $nowStr,
|
||||
'admin_id' => $admin->id,
|
||||
'scope' => $scope,
|
||||
'filters' => $filterSummary,
|
||||
]);
|
||||
$order->meta = $meta;
|
||||
$order->save();
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$order->status = 'activated';
|
||||
$order->activated_at = $order->activated_at ?: now();
|
||||
|
||||
@@ -1808,7 +1831,18 @@ class PlatformOrderController extends Controller
|
||||
$success++;
|
||||
}
|
||||
|
||||
$msg = '批量仅标记为已生效完成:成功 ' . $success . ' 条(命中 ' . $matchedTotal . ' 条,本次处理 ' . $processed . ' 条,limit=' . $limit . ')';
|
||||
$msg = '批量仅标记为已生效完成:成功 ' . $success . ' 条,失败 ' . $failed . ' 条(命中 ' . $matchedTotal . ' 条,本次处理 ' . $processed . ' 条,limit=' . $limit . ')';
|
||||
|
||||
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 . '(' . $cnt . ')';
|
||||
})->implode(';');
|
||||
|
||||
$msg .= ';失败原因Top:' . $topText;
|
||||
}
|
||||
|
||||
return redirect()->back()->with('success', $msg);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user