平台订单详情:对账/退款异常时禁用同步订阅并给治理提示块

This commit is contained in:
萝卜
2026-03-14 00:15:25 +00:00
parent 61d50090a6
commit bf39bccbee
2 changed files with 111 additions and 19 deletions

View File

@@ -209,29 +209,37 @@
</div>
@endif
@php
$syncBlockedByGovernance = $order->isReconcileMismatch() || $order->isRefundInconsistent();
@endphp
<form method="post" action="/admin/platform-orders/{{ $order->id }}/activate-subscription" onsubmit="return confirm('确认同步订阅?将根据该订单创建/续期订阅');">
@csrf
<button type="submit" @disabled(! $canActivate || $alreadySynced)>{{ $alreadySynced ? '已同步' : '同步订阅' }}</button>
<button type="submit" @disabled(! $canActivate || $alreadySynced || $syncBlockedByGovernance)>{{ $alreadySynced ? '已同步' : '同步订阅' }}</button>
</form>
@if($order->isReconcileMismatch() || $order->isRefundInconsistent())
<div class="muted text-danger" style="margin-top:6px; width:100%;">
提示:当前订单命中「对账不一致/退款不一致」,为避免带病同步,请先完成金额/状态治理(补回执/核对退款/修正状态)后再同步订阅。
@if($order->isReconcileMismatch())
@php
$fixReceiptUrl = '/admin/platform-orders/' . $order->id . '?' . \Illuminate\Support\Arr::query(['back' => $orderShowSelf]) . '#add-payment-receipt';
@endphp
<a class="link" href="{!! $fixReceiptUrl !!}">去补回执</a>
@endif
@if($order->isReconcileMismatch() && $order->isRefundInconsistent())
<span class="muted"></span>
@endif
@if($order->isRefundInconsistent())
@php
$fixRefundUrl = '/admin/platform-orders/' . $order->id . '?' . \Illuminate\Support\Arr::query(['back' => $orderShowSelf]) . '#refund-receipts';
@endphp
<a class="link" href="{!! $fixRefundUrl !!}">去核对退款</a>
@endif
@if($syncBlockedByGovernance)
<div class="card" style="margin-top:10px; width:100%; border:1px solid #f5c2c7; background:#fff5f5;">
<div class="muted text-danger"><strong>同步订阅治理提示</strong>(当前不建议/不可直接同步)</div>
<div class="muted muted-xs" style="margin-top:6px;">
<div>原因:订单命中「对账不一致/退款不一致」。为避免把“带病订单”同步到订阅,请先完成金额/状态治理。</div>
<div style="margin-top:6px;">
@if($order->isReconcileMismatch())
@php
$fixReceiptUrl = '/admin/platform-orders/' . $order->id . '?' . \Illuminate\Support\Arr::query(['back' => $orderShowSelf]) . '#add-payment-receipt';
@endphp
<a class="link" href="{!! $fixReceiptUrl !!}">去补回执</a>
@endif
@if($order->isReconcileMismatch() && $order->isRefundInconsistent())
<span class="muted"></span>
@endif
@if($order->isRefundInconsistent())
@php
$fixRefundUrl = '/admin/platform-orders/' . $order->id . '?' . \Illuminate\Support\Arr::query(['back' => $orderShowSelf]) . '#refund-receipts';
@endphp
<a class="link" href="{!! $fixRefundUrl !!}">去核对退款</a>
@endif
</div>
</div>
</div>
@endif

View File

@@ -0,0 +1,84 @@
<?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 AdminPlatformOrderShowActivateSubscriptionButtonDisabledWhenGovernanceMismatchTest 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_activate_subscription_button_should_be_disabled_and_show_governance_block_when_reconcile_mismatch(): void
{
$this->loginAsPlatformAdmin();
$merchant = Merchant::query()->firstOrFail();
$plan = Plan::query()->create([
'code' => 'po_show_disable_sync_reconcile_mismatch_plan',
'name' => '同步订阅禁用-对账不一致测试套餐',
'billing_cycle' => 'monthly',
'price' => 10,
'list_price' => 10,
'status' => 'active',
'sort' => 10,
'published_at' => now(),
]);
// 已支付+已生效,但回执总额=9paid_amount=10 => reconcile_mismatch=true
$order = PlatformOrder::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'order_no' => 'PO_SHOW_DISABLE_SYNC_RECON_0001',
'order_type' => 'new_purchase',
'status' => 'activated',
'payment_status' => 'paid',
'plan_name' => $plan->name,
'billing_cycle' => $plan->billing_cycle,
'period_months' => 1,
'quantity' => 1,
'payable_amount' => 10,
'paid_amount' => 10,
'placed_at' => now(),
'paid_at' => now(),
'activated_at' => now(),
'meta' => [
'payment_summary' => [
'count' => 1,
'total_amount' => 9,
],
'payment_receipts' => [
[
'type' => 'bank_transfer',
'channel' => 'offline',
'amount' => 9,
'paid_at' => now()->toDateTimeString(),
'created_at' => now()->toDateTimeString(),
'admin_id' => 1,
],
],
],
]);
$res = $this->get('/admin/platform-orders/' . $order->id);
$res->assertOk();
$res->assertSee('同步订阅治理提示', false);
$res->assertSee('去补回执', false);
$res->assertSee('href="/admin/platform-orders/' . $order->id, false); // should include a link back to this page + anchor
$res->assertSee('disabled', false);
}
}