diff --git a/app/Http/Controllers/Admin/DashboardController.php b/app/Http/Controllers/Admin/DashboardController.php index 4952f02..0f9d680 100644 --- a/app/Http/Controllers/Admin/DashboardController.php +++ b/app/Http/Controllers/Admin/DashboardController.php @@ -77,6 +77,16 @@ class DashboardController extends Controller ->where('order_type', 'renewal') ->whereNull('site_subscription_id') ->count(), + // BMPA 失败:用于运营快速定位“批量标记支付并生效”失败的订单集合 + 'platform_orders_bmpa_failed' => PlatformOrder::query() + ->whereRaw("JSON_EXTRACT(meta, '$.batch_mark_paid_and_activate_error.message') IS NOT NULL") + ->count(), + // 无回执(已支付但缺少回执证据):用于治理“已付但无回执”的风险订单 + 'platform_orders_paid_no_receipt' => PlatformOrder::query() + ->where('payment_status', 'paid') + ->whereRaw("JSON_EXTRACT(meta, '$.payment_summary.total_amount') IS NULL") + ->whereRaw("JSON_EXTRACT(meta, '$.payment_receipts[0].amount') IS NULL") + ->count(), // 站点治理 'active_merchants' => Merchant::query()->where('status', 'active')->count(), diff --git a/resources/views/admin/dashboard.blade.php b/resources/views/admin/dashboard.blade.php index e66aeeb..3f0807b 100644 --- a/resources/views/admin/dashboard.blade.php +++ b/resources/views/admin/dashboard.blade.php @@ -173,6 +173,8 @@ 可同步({{ (int) ($stats['platform_orders_syncable'] ?? 0) }}) 同步失败({{ (int) ($stats['platform_orders_sync_failed'] ?? 0) }}) 续费缺订阅({{ (int) ($stats['platform_orders_renewal_missing_subscription'] ?? 0) }}) + BMPA失败({{ (int) ($stats['platform_orders_bmpa_failed'] ?? 0) }}) + 无回执({{ (int) ($stats['platform_orders_paid_no_receipt'] ?? 0) }}) diff --git a/tests/Feature/AdminDashboardBillingWorkbenchShouldIncludeBmpaFailedAndNoReceiptQuickLinksTest.php b/tests/Feature/AdminDashboardBillingWorkbenchShouldIncludeBmpaFailedAndNoReceiptQuickLinksTest.php new file mode 100644 index 0000000..2d8b19f --- /dev/null +++ b/tests/Feature/AdminDashboardBillingWorkbenchShouldIncludeBmpaFailedAndNoReceiptQuickLinksTest.php @@ -0,0 +1,84 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_dashboard_billing_workbench_should_include_bmpa_failed_and_no_receipt_quick_links(): void + { + Cache::flush(); + + $this->loginAsPlatformAdmin(); + + // 清理 seed 中的订单数据,避免 seed 口径变化影响该用例(本用例只验证“仪表盘是否提供治理入口与计数渲染”) + PlatformOrder::query()->delete(); + + $merchantId = (int) \App\Models\Merchant::query()->value('id'); + + // 构造:1) BMPA 失败订单(meta.batch_mark_paid_and_activate_error.message 存在) + // 2) 已支付但无回执证据订单(payment_status=paid 且 payment_summary/payment_receipts 都为空) + PlatformOrder::query()->create([ + 'merchant_id' => $merchantId, + 'plan_id' => null, + 'site_subscription_id' => null, + 'created_by_admin_id' => null, + 'order_no' => 'PO_DASH_BMPA_FAILED_001', + 'order_type' => 'new_purchase', + 'status' => 'pending', + 'payment_status' => 'unpaid', + 'payable_amount' => 9, + 'paid_amount' => 0, + 'meta' => [ + 'batch_mark_paid_and_activate_error' => [ + 'message' => 'bmpa failed', + ], + ], + ]); + + PlatformOrder::query()->create([ + 'merchant_id' => $merchantId, + 'plan_id' => null, + 'site_subscription_id' => null, + 'created_by_admin_id' => null, + 'order_no' => 'PO_DASH_PAID_NO_RECEIPT_001', + 'order_type' => 'new_purchase', + 'status' => 'pending', + 'payment_status' => 'paid', + 'payable_amount' => 9, + 'paid_amount' => 9, + 'meta' => [], + ]); + + Cache::flush(); + + $res = $this->get('/admin'); + $res->assertOk(); + + // 计数应渲染到按钮文案中 + $res->assertSee('BMPA失败(1)'); + $res->assertSee('无回执(1)'); + + // 链接应携带 back,并且不应出现 &back=(避免回跳断链) + $res->assertSee('bmpa_failed_only=1', false); + $res->assertSee('receipt_status=none', false); + $res->assertSee('back=%2Fadmin', false); + $res->assertDontSee('&back=', false); + } +}