From 452ac450c8f9bbe6194169c56a572e70eb4a9162 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Sun, 15 Mar 2026 19:53:24 +0800 Subject: [PATCH] =?UTF-8?q?feat(admin):=20=E4=BB=AA=E8=A1=A8=E7=9B=98?= =?UTF-8?q?=E5=8F=AF=E5=90=8C=E6=AD=A5=E5=85=A5=E5=8F=A3=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E8=AE=A1=E6=95=B0=EF=BC=88=E5=8F=A3=E5=BE=84=E5=AF=B9=E9=BD=90?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E8=AE=A2=E5=8D=95=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Admin/DashboardController.php | 11 ++++ resources/views/admin/dashboard.blade.php | 2 +- ...WorkbenchSyncableCountShouldRenderTest.php | 58 +++++++++++++++++++ 3 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 tests/Feature/AdminDashboardBillingWorkbenchSyncableCountShouldRenderTest.php diff --git a/app/Http/Controllers/Admin/DashboardController.php b/app/Http/Controllers/Admin/DashboardController.php index 1eb2b03..dd6dd84 100644 --- a/app/Http/Controllers/Admin/DashboardController.php +++ b/app/Http/Controllers/Admin/DashboardController.php @@ -58,6 +58,17 @@ class DashboardController extends Controller // 口径对齐“待生效”语义:排除明确的同步失败(失败单应该去同步失败治理) ->whereRaw("JSON_EXTRACT(meta, '$.subscription_activation_error.message') IS NULL") ->count(), + // 可同步:沿用平台订单列表口径(paid+activated+未同步+无失败),且排除续费缺订阅脏数据 + 'platform_orders_syncable' => PlatformOrder::query() + ->where('payment_status', 'paid') + ->where('status', 'activated') + ->whereRaw("JSON_EXTRACT(meta, '$.subscription_activation.subscription_id') IS NULL") + ->whereRaw("JSON_EXTRACT(meta, '$.subscription_activation_error.message') IS NULL") + ->where(function ($q) { + $q->where('order_type', '!=', 'renewal') + ->orWhereNotNull('site_subscription_id'); + }) + ->count(), // 同步失败:沿用平台订单列表口径(meta.subscription_activation_error.message 存在即失败) 'platform_orders_sync_failed' => PlatformOrder::query() ->whereRaw("JSON_EXTRACT(meta, '$.subscription_activation_error.message') IS NOT NULL") diff --git a/resources/views/admin/dashboard.blade.php b/resources/views/admin/dashboard.blade.php index 81be3cb..d1a2b1b 100644 --- a/resources/views/admin/dashboard.blade.php +++ b/resources/views/admin/dashboard.blade.php @@ -101,7 +101,7 @@
待支付({{ (int) ($stats['platform_orders_unpaid_pending'] ?? 0) }}) 待生效({{ (int) ($stats['platform_orders_paid_pending'] ?? 0) }}) - 可同步 + 可同步({{ (int) ($stats['platform_orders_syncable'] ?? 0) }}) 同步失败({{ (int) ($stats['platform_orders_sync_failed'] ?? 0) }}) 续费缺订阅({{ (int) ($stats['platform_orders_renewal_missing_subscription'] ?? 0) }})
diff --git a/tests/Feature/AdminDashboardBillingWorkbenchSyncableCountShouldRenderTest.php b/tests/Feature/AdminDashboardBillingWorkbenchSyncableCountShouldRenderTest.php new file mode 100644 index 0000000..52fbf61 --- /dev/null +++ b/tests/Feature/AdminDashboardBillingWorkbenchSyncableCountShouldRenderTest.php @@ -0,0 +1,58 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_dashboard_billing_workbench_syncable_count_should_render(): void + { + Cache::flush(); + + $this->loginAsPlatformAdmin(); + + $merchantId = (int) Merchant::query()->value('id'); + $platformAdminId = (int) Admin::query()->where('email', 'platform.admin@demo.local')->value('id'); + + // seed 已包含 1 条已支付+已生效且未写入 subscription_activation 的平台订单(可同步口径下应命中) + // 这里再额外构造 1 条,最终期望显示为 2。 + PlatformOrder::query()->create([ + 'merchant_id' => $merchantId, + 'plan_id' => null, + 'site_subscription_id' => 1, + 'created_by_admin_id' => $platformAdminId ?: null, + 'order_no' => 'PO_DASHBOARD_SYNCABLE_001', + 'order_type' => 'new_purchase', + 'status' => 'activated', + 'payment_status' => 'paid', + 'payable_amount' => 9, + 'paid_amount' => 9, + 'meta' => [], + ]); + + Cache::flush(); + + $res = $this->get('/admin'); + $res->assertOk(); + + $res->assertSee('可同步(2)'); + } +}