配置化:同步失败原因TOPN与展示截断长度

This commit is contained in:
萝卜
2026-03-11 10:09:03 +00:00
parent 0b36ae8baf
commit 916796f58e
3 changed files with 16 additions and 6 deletions

View File

@@ -178,12 +178,15 @@ class PlatformOrderController extends Controller
// 同步失败原因聚合Top 5用于运营快速判断“常见失败原因”
// 注意:这里用 JSON_EXTRACT 做 group byMySQL 会返回带引号的 JSON 字符串,展示时做一次 trim 处理。
$topN = (int) config('saasshop.platform_orders.sync_failed_reason_top_n', 5);
$topN = max(1, min(20, $topN));
$failedReasonRows = (clone $baseQuery)
->whereRaw("JSON_EXTRACT(meta, '$.subscription_activation_error.message') IS NOT NULL")
->selectRaw("JSON_EXTRACT(meta, '$.subscription_activation_error.message') as reason, count(*) as cnt")
->groupBy('reason')
->orderByDesc('cnt')
->limit(5)
->limit($topN)
->get();
$failedReasonStats = $failedReasonRows->map(function ($row) {