admin: 订阅详情页补齐BMPA失败数摘要与直达治理链接

This commit is contained in:
萝卜
2026-03-13 14:56:49 +00:00
parent 7960416aed
commit 2254e00f23
3 changed files with 103 additions and 0 deletions

View File

@@ -92,6 +92,11 @@ class SiteSubscriptionController extends Controller
} }
} }
// 订阅维度BMPA批量标记支付并生效失败订单数与平台订单列表 bmpa_failed_only 口径一致)
$bmpaFailedOrders = (clone $baseOrdersQuery)
->whereRaw("JSON_EXTRACT(meta, '$.batch_mark_paid_and_activate_error.message') IS NOT NULL")
->count();
$summaryStats = $summaryStats + [ $summaryStats = $summaryStats + [
'receipt_orders' => $receiptOrders, 'receipt_orders' => $receiptOrders,
'no_receipt_orders' => $noReceiptOrders, 'no_receipt_orders' => $noReceiptOrders,
@@ -103,6 +108,8 @@ class SiteSubscriptionController extends Controller
'refund_inconsistent_orders' => (int) $refundInconsistentOrders, 'refund_inconsistent_orders' => (int) $refundInconsistentOrders,
// 对账不一致订单(订阅维度) // 对账不一致订单(订阅维度)
'reconcile_mismatch_orders' => (int) $reconcileMismatchOrders, 'reconcile_mismatch_orders' => (int) $reconcileMismatchOrders,
// BMPA 失败订单(订阅维度)
'bmpa_failed_orders' => (int) $bmpaFailedOrders,
// 对账差额:回执总额 - 已付总额(订阅维度) // 对账差额:回执总额 - 已付总额(订阅维度)
'reconciliation_delta' => (float) ($totalReceiptAmount - (float) $metaOrders->sum('paid_amount')), 'reconciliation_delta' => (float) ($totalReceiptAmount - (float) $metaOrders->sum('paid_amount')),
]; ];

View File

@@ -236,6 +236,14 @@
@endif @endif
</div> </div>
<div class="card">
<h3>BMPA 失败数</h3>
<div class="num-md">
<a class="link" href="{!! $makePlatformOrderUrl(['site_subscription_id' => $subscription->id, 'bmpa_failed_only' => '1']) !!}">{{ $summaryStats['bmpa_failed_orders'] ?? 0 }}</a>
</div>
<div class="muted muted-xs">点击跳转:该订阅下「批量标记支付并生效失败」订单</div>
</div>
<div class="card"> <div class="card">
<h3>失败原因Top3</h3> <h3>失败原因Top3</h3>
@php $failedReasonStats = $failedReasonStats ?? []; @endphp @php $failedReasonStats = $failedReasonStats ?? []; @endphp

View File

@@ -0,0 +1,88 @@
<?php
namespace Tests\Feature;
use App\Models\Merchant;
use App\Models\Plan;
use App\Models\PlatformOrder;
use App\Models\SiteSubscription;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AdminSiteSubscriptionBmpaFailedSummaryCardTest 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_subscription_show_page_has_bmpa_failed_summary_card_and_link(): void
{
$this->loginAsPlatformAdmin();
$merchant = Merchant::query()->firstOrFail();
$plan = Plan::query()->create([
'code' => 'sub_bmpa_failed_card_01',
'name' => '订阅BMPA失败卡片测试套餐',
'billing_cycle' => 'monthly',
'price' => 10,
'list_price' => 10,
'status' => 'active',
'sort' => 10,
'published_at' => now(),
]);
$sub = SiteSubscription::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'status' => 'activated',
'source' => 'manual',
'subscription_no' => 'SUB_BMPA_FAILED_CARD_0001',
'plan_name' => $plan->name,
'billing_cycle' => $plan->billing_cycle,
'period_months' => 1,
'amount' => 10,
'starts_at' => now()->subDay(),
'ends_at' => now()->addMonth(),
'activated_at' => now()->subDay(),
]);
PlatformOrder::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'site_subscription_id' => $sub->id,
'created_by_admin_id' => 1,
'order_no' => 'PO_SUB_BMPA_FAILED_0001',
'order_type' => 'renewal',
'status' => 'pending',
'payment_status' => 'unpaid',
'plan_name' => $plan->name,
'billing_cycle' => $plan->billing_cycle,
'period_months' => 1,
'quantity' => 1,
'payable_amount' => 10,
'paid_amount' => 0,
'placed_at' => now(),
'meta' => [
'batch_mark_paid_and_activate_error' => [
'message' => '存在退款轨迹,不允许批量标记支付并生效',
'at' => now()->toDateTimeString(),
'admin_id' => 1,
],
],
]);
$this->get('/admin/site-subscriptions/' . $sub->id)
->assertOk()
->assertSee('BMPA 失败数')
->assertSee('/admin/platform-orders?site_subscription_id=' . $sub->id . '&bmpa_failed_only=1', false)
->assertSee('1');
}
}