feat(admin): subscription show summary stats
This commit is contained in:
@@ -21,12 +21,34 @@ class SiteSubscriptionController extends Controller
|
|||||||
|
|
||||||
$subscription->loadMissing(['merchant', 'plan']);
|
$subscription->loadMissing(['merchant', 'plan']);
|
||||||
|
|
||||||
$platformOrders = PlatformOrder::query()
|
$platformOrdersQuery = PlatformOrder::query()
|
||||||
->where('site_subscription_id', $subscription->id)
|
->where('site_subscription_id', $subscription->id);
|
||||||
|
|
||||||
|
$platformOrders = (clone $platformOrdersQuery)
|
||||||
->latest('id')
|
->latest('id')
|
||||||
->paginate(10)
|
->paginate(10)
|
||||||
->withQueryString();
|
->withQueryString();
|
||||||
|
|
||||||
|
// 可治理摘要:订阅下的订单同步情况
|
||||||
|
$summaryStats = [
|
||||||
|
'total_orders' => (clone $platformOrdersQuery)->count(),
|
||||||
|
'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;
|
||||||
$expiryLabel = '无到期';
|
$expiryLabel = '无到期';
|
||||||
if ($endsAt) {
|
if ($endsAt) {
|
||||||
@@ -42,6 +64,7 @@ class SiteSubscriptionController extends Controller
|
|||||||
return view('admin.site_subscriptions.show', [
|
return view('admin.site_subscriptions.show', [
|
||||||
'subscription' => $subscription,
|
'subscription' => $subscription,
|
||||||
'platformOrders' => $platformOrders,
|
'platformOrders' => $platformOrders,
|
||||||
|
'summaryStats' => $summaryStats,
|
||||||
'statusLabels' => $this->statusLabels(),
|
'statusLabels' => $this->statusLabels(),
|
||||||
'expiryLabel' => $expiryLabel,
|
'expiryLabel' => $expiryLabel,
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -75,6 +75,25 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="grid-4 mb-20">
|
||||||
|
<div class="card">
|
||||||
|
<h3>关联订单总数</h3>
|
||||||
|
<div class="num-md">{{ $summaryStats['total_orders'] ?? 0 }}</div>
|
||||||
|
</div>
|
||||||
|
<div class="card">
|
||||||
|
<h3>已同步</h3>
|
||||||
|
<div class="num-md">{{ $summaryStats['synced_orders'] ?? 0 }}</div>
|
||||||
|
</div>
|
||||||
|
<div class="card">
|
||||||
|
<h3>同步失败</h3>
|
||||||
|
<div class="num-md">{{ $summaryStats['failed_orders'] ?? 0 }}</div>
|
||||||
|
</div>
|
||||||
|
<div class="card">
|
||||||
|
<h3>可同步(已支付+已生效+未同步)</h3>
|
||||||
|
<div class="num-md">{{ $summaryStats['syncable_orders'] ?? 0 }}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<h3>关联平台订单({{ $platformOrders->total() }})</h3>
|
<h3>关联平台订单({{ $platformOrders->total() }})</h3>
|
||||||
<table>
|
<table>
|
||||||
|
|||||||
@@ -87,6 +87,8 @@ class AdminSiteSubscriptionShowTest extends TestCase
|
|||||||
->assertOk()
|
->assertOk()
|
||||||
->assertSee('订阅详情')
|
->assertSee('订阅详情')
|
||||||
->assertSee('SUB_SHOW_0001')
|
->assertSee('SUB_SHOW_0001')
|
||||||
|
->assertSee('关联订单总数')
|
||||||
|
->assertSee('可同步(已支付+已生效+未同步)')
|
||||||
->assertSee('关联平台订单')
|
->assertSee('关联平台订单')
|
||||||
->assertSee('PO_SUB_SHOW_0001');
|
->assertSee('PO_SUB_SHOW_0001');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user