From 763c706cf3bf115ac2d81e49d5d280a62acd15e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Mon, 16 Mar 2026 19:23:42 +0800 Subject: [PATCH] fix(admin-dashboard): paid_pending count aligns with unsynced scope --- .../Controllers/Admin/DashboardController.php | 3 ++- ...orkbenchQuickLinksShouldShowCountsTest.php | 21 ++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Admin/DashboardController.php b/app/Http/Controllers/Admin/DashboardController.php index 61a879a..abb6d13 100644 --- a/app/Http/Controllers/Admin/DashboardController.php +++ b/app/Http/Controllers/Admin/DashboardController.php @@ -55,7 +55,8 @@ class DashboardController extends Controller 'platform_orders_paid_pending' => PlatformOrder::query() ->where('payment_status', 'paid') ->where('status', 'pending') - // 口径对齐“待生效”语义:排除明确的同步失败(失败单应该去同步失败治理) + // 口径对齐“待生效”语义(sync_status=unsynced):未同步 + 非失败 + ->whereRaw("JSON_EXTRACT(meta, '$.subscription_activation.subscription_id') IS NULL") ->whereRaw("JSON_EXTRACT(meta, '$.subscription_activation_error.message') IS NULL") ->count(), // 可同步:沿用平台订单列表口径(paid+activated+未同步+无失败),且排除续费缺订阅脏数据 diff --git a/tests/Feature/AdminDashboardBillingWorkbenchQuickLinksShouldShowCountsTest.php b/tests/Feature/AdminDashboardBillingWorkbenchQuickLinksShouldShowCountsTest.php index 0aa4b7e..8e079fa 100644 --- a/tests/Feature/AdminDashboardBillingWorkbenchQuickLinksShouldShowCountsTest.php +++ b/tests/Feature/AdminDashboardBillingWorkbenchQuickLinksShouldShowCountsTest.php @@ -59,6 +59,25 @@ class AdminDashboardBillingWorkbenchQuickLinksShouldShowCountsTest extends TestC 'paid_amount' => 9, ]); + // 脏数据兜底:即使 status=pending + paid,但若 meta 已写入 subscription_activation(视为已同步),不应计入“待生效(unsynced)”集合。 + PlatformOrder::query()->create([ + 'merchant_id' => $merchantId, + 'plan_id' => null, + 'site_subscription_id' => null, + 'created_by_admin_id' => $platformAdminId ?: null, + 'order_no' => 'PO_DASHBOARD_PAID_PENDING_BUT_ALREADY_SYNCED', + 'order_type' => 'new_purchase', + 'status' => 'pending', + 'payment_status' => 'paid', + 'payable_amount' => 9, + 'paid_amount' => 9, + 'meta' => [ + 'subscription_activation' => [ + 'subscription_id' => 123, + ], + ], + ]); + PlatformOrder::query()->create([ 'merchant_id' => $merchantId, 'plan_id' => null, @@ -81,7 +100,7 @@ class AdminDashboardBillingWorkbenchQuickLinksShouldShowCountsTest extends TestC // Debug:确保我们构造的数据在 DB 里 $this->assertSame(1, PlatformOrder::query()->where('payment_status', 'unpaid')->where('status', 'pending')->count()); - $this->assertSame(2, PlatformOrder::query()->where('payment_status', 'paid')->where('status', 'pending')->count()); + $this->assertSame(3, PlatformOrder::query()->where('payment_status', 'paid')->where('status', 'pending')->count()); $res = $this->get('/admin'); $res->assertOk();