dashboard: add quick links for BMPA failed and paid-no-receipt orders

This commit is contained in:
萝卜
2026-03-15 23:43:39 +08:00
parent e92636dd5b
commit 27753acb71
3 changed files with 96 additions and 0 deletions

View File

@@ -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(),

View File

@@ -173,6 +173,8 @@
<a class="btn btn-secondary btn-sm" href="{!! $platformOrdersQuickLinks['syncable_only'] !!}">可同步({{ (int) ($stats['platform_orders_syncable'] ?? 0) }}</a>
<a class="btn btn-secondary btn-sm" href="{!! $platformOrdersQuickLinks['sync_failed'] !!}">同步失败({{ (int) ($stats['platform_orders_sync_failed'] ?? 0) }}</a>
<a class="btn btn-secondary btn-sm" href="{!! \App\Support\BackUrl::withBack('/admin/platform-orders?renewal_missing_subscription=1', $selfWithoutBack) !!}">续费缺订阅({{ (int) ($stats['platform_orders_renewal_missing_subscription'] ?? 0) }}</a>
<a class="btn btn-secondary btn-sm" href="{!! \App\Support\BackUrl::withBack('/admin/platform-orders?bmpa_failed_only=1', $selfWithoutBack) !!}">BMPA失败{{ (int) ($stats['platform_orders_bmpa_failed'] ?? 0) }}</a>
<a class="btn btn-secondary btn-sm" href="{!! \App\Support\BackUrl::withBack('/admin/platform-orders?payment_status=paid&receipt_status=none', $selfWithoutBack) !!}">无回执({{ (int) ($stats['platform_orders_paid_no_receipt'] ?? 0) }}</a>
</div>
</div>

View File

@@ -0,0 +1,84 @@
<?php
namespace Tests\Feature;
use App\Models\PlatformOrder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Cache;
use Tests\TestCase;
class AdminDashboardBillingWorkbenchShouldIncludeBmpaFailedAndNoReceiptQuickLinksTest extends TestCase
{
use RefreshDatabase;
protected function loginAsPlatformAdmin(): void
{
$this->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并且不应出现 &amp;back=(避免回跳断链)
$res->assertSee('bmpa_failed_only=1', false);
$res->assertSee('receipt_status=none', false);
$res->assertSee('back=%2Fadmin', false);
$res->assertDontSee('&amp;back=', false);
}
}