feat(admin): subscription show failed reason top3

This commit is contained in:
萝卜
2026-03-10 13:12:35 +00:00
parent 10a23180d5
commit 981fdc973d
3 changed files with 35 additions and 0 deletions

View File

@@ -45,6 +45,25 @@ class SiteSubscriptionController extends Controller
->count(),
];
// 同步失败原因聚合Top3订阅维度快速判断“常见失败原因”
$failedReasonRows = (clone $baseOrdersQuery)
->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(3)
->get();
$failedReasonStats = $failedReasonRows->map(function ($row) {
$reason = (string) ($row->reason ?? '');
$reason = trim($reason, "\" ");
return [
'reason' => $reason !== '' ? $reason : '(空)',
'count' => (int) ($row->cnt ?? 0),
];
})->values()->all();
// 页面列表筛选:仅影响“关联平台订单”列表展示,不影响摘要统计
$orderSyncStatus = trim((string) $request->query('order_sync_status', ''));
@@ -93,6 +112,7 @@ class SiteSubscriptionController extends Controller
'subscription' => $subscription,
'platformOrders' => $platformOrders,
'summaryStats' => $summaryStats,
'failedReasonStats' => $failedReasonStats,
'statusLabels' => $this->statusLabels(),
'expiryLabel' => $expiryLabel,
]);

View File

@@ -115,6 +115,20 @@
<div class="num-md">{{ $summaryStats['unsynced_orders'] ?? 0 }}</div>
<div class="muted muted-xs"> activation 且无 error</div>
</div>
<div class="card">
<h3>失败原因Top3</h3>
@php $failedReasonStats = $failedReasonStats ?? []; @endphp
@if(count($failedReasonStats) > 0)
<div class="muted mt-6">
@foreach($failedReasonStats as $item)
<div>{{ $item['reason'] }} <span class="muted">{{ $item['count'] }}</span></div>
@endforeach
</div>
@else
<div class="muted">暂无失败原因聚合数据</div>
@endif
</div>
</div>
<div class="card">

View File

@@ -90,6 +90,7 @@ class AdminSiteSubscriptionShowTest extends TestCase
->assertSee('关联订单总数')
->assertSee('可同步(已支付+已生效+未同步)')
->assertSee('未同步(无记录)')
->assertSee('失败原因Top3')
->assertSee('关联平台订单')
->assertSee('PO_SUB_SHOW_0001')
->assertSee('同步时间')