diff --git a/resources/views/admin/dashboard.blade.php b/resources/views/admin/dashboard.blade.php index 6fec59b..99f82d7 100644 --- a/resources/views/admin/dashboard.blade.php +++ b/resources/views/admin/dashboard.blade.php @@ -87,10 +87,10 @@
快捷筛选:
- 待支付 - 待生效 + 待支付({{ (int) ($stats['platform_orders_unpaid_pending'] ?? 0) }}) + 待生效({{ (int) ($stats['platform_orders_paid_pending'] ?? 0) }}) 可同步 - 同步失败 + 同步失败({{ (int) ($stats['platform_orders_sync_failed'] ?? 0) }})
diff --git a/tests/Feature/AdminDashboardBillingWorkbenchQuickLinksShouldShowCountsTest.php b/tests/Feature/AdminDashboardBillingWorkbenchQuickLinksShouldShowCountsTest.php new file mode 100644 index 0000000..b24b7b5 --- /dev/null +++ b/tests/Feature/AdminDashboardBillingWorkbenchQuickLinksShouldShowCountsTest.php @@ -0,0 +1,94 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_dashboard_billing_workbench_quick_links_should_show_counts(): void + { + Cache::flush(); + + $this->loginAsPlatformAdmin(); + + $merchantId = (int) Merchant::query()->value('id'); + $platformAdminId = (int) Admin::query()->where('email', 'platform.admin@demo.local')->value('id'); + + // 构造三类集合:待支付 / 待生效 / 同步失败 + PlatformOrder::query()->create([ + 'merchant_id' => $merchantId, + 'plan_id' => null, + 'site_subscription_id' => null, + 'created_by_admin_id' => $platformAdminId ?: null, + 'order_no' => 'PO_DASHBOARD_UNPAID_PENDING', + 'order_type' => 'new_purchase', + 'status' => 'pending', + 'payment_status' => 'unpaid', + 'payable_amount' => 9, + 'paid_amount' => 0, + ]); + + 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', + 'order_type' => 'new_purchase', + 'status' => 'pending', + 'payment_status' => 'paid', + 'payable_amount' => 9, + 'paid_amount' => 9, + ]); + + PlatformOrder::query()->create([ + 'merchant_id' => $merchantId, + 'plan_id' => null, + 'site_subscription_id' => null, + 'created_by_admin_id' => $platformAdminId ?: null, + 'order_no' => 'PO_DASHBOARD_SYNC_FAILED', + 'order_type' => 'new_purchase', + 'status' => 'pending', + 'payment_status' => 'paid', + 'payable_amount' => 9, + 'paid_amount' => 9, + 'meta' => [ + 'subscription_activation_error' => [ + 'message' => 'sync failed', + ], + ], + ]); + + Cache::flush(); + + // 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()); + + $res = $this->get('/admin'); + $res->assertOk(); + + // paid_pending 的定义是 paid + pending,其中包含 sync_failed 那一条,因此预期为 2 + $res->assertSee('待支付(1)'); + $res->assertSee('待生效(2)'); + $res->assertSee('同步失败(1)'); + } +}