admin: 列表行级BMPA对齐退款轨迹安全阀(存在退款即禁用并给入口)
This commit is contained in:
@@ -1782,12 +1782,15 @@
|
|||||||
@php
|
@php
|
||||||
$needReconcileFix = (bool) $order->isReconcileMismatch();
|
$needReconcileFix = (bool) $order->isReconcileMismatch();
|
||||||
$needRefundFix = (bool) $order->isRefundInconsistent();
|
$needRefundFix = (bool) $order->isRefundInconsistent();
|
||||||
|
// 退款轨迹:只要存在退款汇总/退款回执,就视为“需核对”的治理信号(用于禁用部分动作并给入口)
|
||||||
|
$hasRefundTrace = ((float) $order->refundTotal()) > 0;
|
||||||
|
|
||||||
// 行级 BMPA 安全阀(列表页也应禁用,避免运营误触):
|
// 行级 BMPA 安全阀(列表页也应禁用,避免运营误触):
|
||||||
// - 对账不一致/退款不一致:需先治理
|
// - 对账不一致/退款不一致:需先治理
|
||||||
|
// - 存在退款轨迹:需先核对退款轨迹与状态(避免带退款订单被推进)
|
||||||
// - 续费缺订阅:需先绑定订阅
|
// - 续费缺订阅:需先绑定订阅
|
||||||
$blockedByMissingSubscriptionOnRenewal = ((string) ($order->order_type ?? '') === 'renewal') && ((int) ($order->site_subscription_id ?? 0) <= 0);
|
$blockedByMissingSubscriptionOnRenewal = ((string) ($order->order_type ?? '') === 'renewal') && ((int) ($order->site_subscription_id ?? 0) <= 0);
|
||||||
$markPaidBlockedByGovernance = $needReconcileFix || $needRefundFix || $blockedByMissingSubscriptionOnRenewal;
|
$markPaidBlockedByGovernance = $needReconcileFix || $needRefundFix || $hasRefundTrace || $blockedByMissingSubscriptionOnRenewal;
|
||||||
|
|
||||||
// 仅当订单尚未处于 paid+activated 时,且未命中治理阻断时,才允许点击
|
// 仅当订单尚未处于 paid+activated 时,且未命中治理阻断时,才允许点击
|
||||||
$canMarkPaid = ((($order->payment_status !== 'paid') || ($order->status !== 'activated')) && (! $markPaidBlockedByGovernance));
|
$canMarkPaid = ((($order->payment_status !== 'paid') || ($order->status !== 'activated')) && (! $markPaidBlockedByGovernance));
|
||||||
@@ -1796,9 +1799,10 @@
|
|||||||
$reconcileFixUrlCompact = \App\Support\BackUrl::withBackAndFragment('/admin/platform-orders/' . $order->id, $selfWithoutBack, 'add-payment-receipt');
|
$reconcileFixUrlCompact = \App\Support\BackUrl::withBackAndFragment('/admin/platform-orders/' . $order->id, $selfWithoutBack, 'add-payment-receipt');
|
||||||
$refundFixUrlCompact = \App\Support\BackUrl::withBackAndFragment('/admin/platform-orders/' . $order->id, $selfWithoutBack, 'add-refund-receipt');
|
$refundFixUrlCompact = \App\Support\BackUrl::withBackAndFragment('/admin/platform-orders/' . $order->id, $selfWithoutBack, 'add-refund-receipt');
|
||||||
$relationFixUrlCompactForBmpa = \App\Support\BackUrl::withBackAndFragment('/admin/platform-orders/' . $order->id, $selfWithoutBack, 'relation-subscription');
|
$relationFixUrlCompactForBmpa = \App\Support\BackUrl::withBackAndFragment('/admin/platform-orders/' . $order->id, $selfWithoutBack, 'relation-subscription');
|
||||||
|
$refundTraceFixUrlCompact = \App\Support\BackUrl::withBackAndFragment('/admin/platform-orders/' . $order->id, $selfWithoutBack, 'add-refund-receipt');
|
||||||
@endphp
|
@endphp
|
||||||
|
|
||||||
@if($needReconcileFix || $needRefundFix || $blockedByMissingSubscriptionOnRenewal)
|
@if($needReconcileFix || $needRefundFix || $hasRefundTrace || $blockedByMissingSubscriptionOnRenewal)
|
||||||
<div class="governance-hints row-warn">
|
<div class="governance-hints row-warn">
|
||||||
@if($needReconcileFix)
|
@if($needReconcileFix)
|
||||||
<div class="muted text-danger muted-xs governance-hint">
|
<div class="muted text-danger muted-xs governance-hint">
|
||||||
@@ -1814,6 +1818,13 @@
|
|||||||
<a class="link" href="{!! $refundFixUrlCompact !!}">去核对退款</a>
|
<a class="link" href="{!! $refundFixUrlCompact !!}">去核对退款</a>
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
|
@if($hasRefundTrace && (! $needRefundFix))
|
||||||
|
<div class="muted text-danger muted-xs governance-hint">
|
||||||
|
<span class="row-warn-prefix">退款</span>
|
||||||
|
<span class="muted">|</span>
|
||||||
|
<a class="link" href="{!! $refundTraceFixUrlCompact !!}">有退款轨迹,请核对</a>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
@if($blockedByMissingSubscriptionOnRenewal)
|
@if($blockedByMissingSubscriptionOnRenewal)
|
||||||
<div class="muted text-danger muted-xs governance-hint">
|
<div class="muted text-danger muted-xs governance-hint">
|
||||||
<span class="row-warn-prefix">订阅</span>
|
<span class="row-warn-prefix">订阅</span>
|
||||||
|
|||||||
@@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use App\Models\Merchant;
|
||||||
|
use App\Models\Plan;
|
||||||
|
use App\Models\PlatformOrder;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class AdminPlatformOrderIndexRowMarkPaidAndActivateButtonShouldDisableWhenRefundTraceExistsTest 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_row_mark_paid_and_activate_button_should_be_disabled_when_refund_trace_exists_even_if_not_refund_inconsistent(): void
|
||||||
|
{
|
||||||
|
$this->loginAsPlatformAdmin();
|
||||||
|
|
||||||
|
$merchant = Merchant::query()->firstOrFail();
|
||||||
|
$plan = Plan::query()->create([
|
||||||
|
'code' => 'po_index_row_bmpa_disable_refund_trace_plan',
|
||||||
|
'name' => '平台订单列表行级BMPA禁用(存在退款轨迹)测试套餐',
|
||||||
|
'billing_cycle' => 'monthly',
|
||||||
|
'price' => 30,
|
||||||
|
'list_price' => 30,
|
||||||
|
'status' => 'active',
|
||||||
|
'sort' => 10,
|
||||||
|
'published_at' => now(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
// 构造:存在退款轨迹(refund_summary.total_amount > 0),但不一定触发 isRefundInconsistent()
|
||||||
|
// 目标:只要存在退款轨迹,BMPA 就应禁用(与后端 safety valve 对齐)。
|
||||||
|
$order = PlatformOrder::query()->create([
|
||||||
|
'merchant_id' => $merchant->id,
|
||||||
|
'plan_id' => $plan->id,
|
||||||
|
'order_no' => 'PO_INDEX_ROW_BMPA_DISABLE_REFUND_TRACE_0001',
|
||||||
|
'order_type' => 'new_purchase',
|
||||||
|
'status' => 'pending',
|
||||||
|
'payment_status' => 'unpaid',
|
||||||
|
'plan_name' => $plan->name,
|
||||||
|
'billing_cycle' => $plan->billing_cycle,
|
||||||
|
'period_months' => 1,
|
||||||
|
'quantity' => 1,
|
||||||
|
'payable_amount' => 30,
|
||||||
|
'paid_amount' => 0,
|
||||||
|
'placed_at' => now(),
|
||||||
|
'meta' => [
|
||||||
|
'refund_summary' => [
|
||||||
|
'count' => 1,
|
||||||
|
'total_amount' => 1.00,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertGreaterThan(0, (float) $order->refundTotal());
|
||||||
|
$this->assertFalse($order->isRefundInconsistent(), '此测试要求 refund trace 存在但不强依赖 refund_inconsistent');
|
||||||
|
|
||||||
|
$res = $this->get('/admin/platform-orders');
|
||||||
|
$res->assertOk();
|
||||||
|
|
||||||
|
$html = (string) $res->getContent();
|
||||||
|
$this->assertStringContainsString($order->order_no, $html);
|
||||||
|
|
||||||
|
// 断言:该订单所在行的“标记支付并生效”按钮应被禁用
|
||||||
|
$pattern = '#/admin/platform-orders/' . $order->id . '/mark-paid-and-activate.*?<button[^>]*disabled#s';
|
||||||
|
$this->assertMatchesRegularExpression($pattern, $html);
|
||||||
|
|
||||||
|
// 并且应给出最短治理入口(核对退款轨迹:直达追加退款记录面板)
|
||||||
|
$this->assertStringContainsString('#add-refund-receipt', $html);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user