feat(admin): subscription show filter related orders by sync status
This commit is contained in:
@@ -21,32 +21,60 @@ class SiteSubscriptionController extends Controller
|
|||||||
|
|
||||||
$subscription->loadMissing(['merchant', 'plan']);
|
$subscription->loadMissing(['merchant', 'plan']);
|
||||||
|
|
||||||
$platformOrdersQuery = PlatformOrder::query()
|
$baseOrdersQuery = PlatformOrder::query()
|
||||||
->where('site_subscription_id', $subscription->id);
|
->where('site_subscription_id', $subscription->id);
|
||||||
|
|
||||||
$platformOrders = (clone $platformOrdersQuery)
|
// 可治理摘要:订阅下的订单同步情况(基于全量关联订单,不受页面筛选影响)
|
||||||
|
$summaryStats = [
|
||||||
|
'total_orders' => (clone $baseOrdersQuery)->count(),
|
||||||
|
'synced_orders' => (clone $baseOrdersQuery)
|
||||||
|
->whereRaw("JSON_EXTRACT(meta, '$.subscription_activation.subscription_id') IS NOT NULL")
|
||||||
|
->whereRaw("JSON_EXTRACT(meta, '$.subscription_activation_error.message') IS NULL")
|
||||||
|
->count(),
|
||||||
|
'failed_orders' => (clone $baseOrdersQuery)
|
||||||
|
->whereRaw("JSON_EXTRACT(meta, '$.subscription_activation_error.message') IS NOT NULL")
|
||||||
|
->count(),
|
||||||
|
'unsynced_orders' => (clone $baseOrdersQuery)
|
||||||
|
->whereRaw("JSON_EXTRACT(meta, '$.subscription_activation.subscription_id') IS NULL")
|
||||||
|
->whereRaw("JSON_EXTRACT(meta, '$.subscription_activation_error.message') IS NULL")
|
||||||
|
->count(),
|
||||||
|
'syncable_orders' => (clone $baseOrdersQuery)
|
||||||
|
->where('payment_status', 'paid')
|
||||||
|
->where('status', 'activated')
|
||||||
|
->whereRaw("JSON_EXTRACT(meta, '$.subscription_activation.subscription_id') IS NULL")
|
||||||
|
->count(),
|
||||||
|
];
|
||||||
|
|
||||||
|
// 页面列表筛选:仅影响“关联平台订单”列表展示,不影响摘要统计
|
||||||
|
$orderSyncStatus = trim((string) $request->query('order_sync_status', ''));
|
||||||
|
|
||||||
|
$displayOrdersQuery = (clone $baseOrdersQuery);
|
||||||
|
if ($orderSyncStatus === 'synced') {
|
||||||
|
$displayOrdersQuery
|
||||||
|
->whereRaw("JSON_EXTRACT(meta, '$.subscription_activation.subscription_id') IS NOT NULL")
|
||||||
|
->whereRaw("JSON_EXTRACT(meta, '$.subscription_activation_error.message') IS NULL");
|
||||||
|
} elseif ($orderSyncStatus === 'failed') {
|
||||||
|
$displayOrdersQuery
|
||||||
|
->whereRaw("JSON_EXTRACT(meta, '$.subscription_activation_error.message') IS NOT NULL");
|
||||||
|
} elseif ($orderSyncStatus === 'unsynced') {
|
||||||
|
$displayOrdersQuery
|
||||||
|
->whereRaw("JSON_EXTRACT(meta, '$.subscription_activation.subscription_id') IS NULL")
|
||||||
|
->whereRaw("JSON_EXTRACT(meta, '$.subscription_activation_error.message') IS NULL");
|
||||||
|
} elseif ($orderSyncStatus === 'syncable') {
|
||||||
|
$displayOrdersQuery
|
||||||
|
->where('payment_status', 'paid')
|
||||||
|
->where('status', 'activated')
|
||||||
|
->whereRaw("JSON_EXTRACT(meta, '$.subscription_activation.subscription_id') IS NULL");
|
||||||
|
}
|
||||||
|
|
||||||
|
$platformOrders = $displayOrdersQuery
|
||||||
->latest('id')
|
->latest('id')
|
||||||
->paginate(10)
|
->paginate(10)
|
||||||
->withQueryString();
|
->withQueryString();
|
||||||
|
|
||||||
// 可治理摘要:订阅下的订单同步情况
|
// 可治理摘要:订阅下的订单同步情况
|
||||||
$summaryStats = [
|
$summaryStats = $summaryStats + [
|
||||||
'total_orders' => (clone $platformOrdersQuery)->count(),
|
'current_order_sync_status' => $orderSyncStatus,
|
||||||
'synced_orders' => (clone $platformOrdersQuery)
|
|
||||||
->whereRaw("JSON_EXTRACT(meta, '$.subscription_activation.subscription_id') IS NOT NULL")
|
|
||||||
->count(),
|
|
||||||
'failed_orders' => (clone $platformOrdersQuery)
|
|
||||||
->whereRaw("JSON_EXTRACT(meta, '$.subscription_activation_error.message') IS NOT NULL")
|
|
||||||
->count(),
|
|
||||||
'unsynced_orders' => (clone $platformOrdersQuery)
|
|
||||||
->whereRaw("JSON_EXTRACT(meta, '$.subscription_activation.subscription_id') IS NULL")
|
|
||||||
->whereRaw("JSON_EXTRACT(meta, '$.subscription_activation_error.message') IS NULL")
|
|
||||||
->count(),
|
|
||||||
'syncable_orders' => (clone $platformOrdersQuery)
|
|
||||||
->where('payment_status', 'paid')
|
|
||||||
->where('status', 'activated')
|
|
||||||
->whereRaw("JSON_EXTRACT(meta, '$.subscription_activation.subscription_id') IS NULL")
|
|
||||||
->count(),
|
|
||||||
];
|
];
|
||||||
|
|
||||||
$endsAt = $subscription->ends_at;
|
$endsAt = $subscription->ends_at;
|
||||||
|
|||||||
@@ -101,6 +101,24 @@
|
|||||||
|
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<h3>关联平台订单({{ $platformOrders->total() }})</h3>
|
<h3>关联平台订单({{ $platformOrders->total() }})</h3>
|
||||||
|
|
||||||
|
<div class="mb-10">
|
||||||
|
<span class="muted">同步状态筛选:</span>
|
||||||
|
@php $cur = $summaryStats['current_order_sync_status'] ?? ''; @endphp
|
||||||
|
<a href="?" class="muted">全部</a>
|
||||||
|
<span class="muted">|</span>
|
||||||
|
<a href="?order_sync_status=synced" class="muted">已同步</a>
|
||||||
|
<span class="muted">|</span>
|
||||||
|
<a href="?order_sync_status=failed" class="muted">同步失败</a>
|
||||||
|
<span class="muted">|</span>
|
||||||
|
<a href="?order_sync_status=unsynced" class="muted">未同步</a>
|
||||||
|
<span class="muted">|</span>
|
||||||
|
<a href="?order_sync_status=syncable" class="muted">可同步</a>
|
||||||
|
@if($cur)
|
||||||
|
<span class="muted">(当前:{{ $cur }})</span>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
Reference in New Issue
Block a user