admin: 平台订单列表行级同步订阅按钮命中治理阻断时禁用并提示
This commit is contained in:
@@ -1829,15 +1829,33 @@
|
||||
<button class="btn btn-secondary btn-sm" type="submit" @disabled(! $canMarkActivatedOnly)>仅标记为已生效</button>
|
||||
</form>
|
||||
|
||||
@php
|
||||
$syncBlockedByGovernanceRow = (bool) ($order->isReconcileMismatch() || $order->isRefundInconsistent());
|
||||
$syncBlockedByMissingSubscriptionOnRenewalRow = ((string) ($order->order_type ?? '') === 'renewal')
|
||||
&& ((int) ($order->site_subscription_id ?? 0) <= 0);
|
||||
|
||||
// 最短治理路径:续费缺订阅直接落到“关联订阅”面板。
|
||||
$relationFixUrlCompact = \App\Support\BackUrl::withBackAndFragment('/admin/platform-orders/' . $order->id, $selfWithoutBack, 'relation-subscription');
|
||||
|
||||
$syncBlockedRow = $syncBlockedByGovernanceRow || $syncBlockedByMissingSubscriptionOnRenewalRow;
|
||||
@endphp
|
||||
<form method="post" action="/admin/platform-orders/{{ $order->id }}/activate-subscription" data-action="disable-on-submit" onsubmit="return confirm('确认同步订阅?将根据该订单创建/续期订阅');">
|
||||
@csrf
|
||||
<button class="btn btn-secondary btn-sm" type="submit" @disabled(! $canActivate || $alreadySynced)>{{ $alreadySynced ? '已同步' : '同步订阅' }}</button>
|
||||
<button class="btn btn-secondary btn-sm" type="submit" @disabled(! $canActivate || $alreadySynced || $syncBlockedRow)>{{ $alreadySynced ? '已同步' : '同步订阅' }}</button>
|
||||
</form>
|
||||
|
||||
@if(! $canActivate)
|
||||
<div class="muted mt-6">需已支付且订单状态为已生效</div>
|
||||
@elseif($alreadySynced)
|
||||
<div class="muted mt-6">该订单已完成同步(幂等保护)</div>
|
||||
@elseif($syncBlockedRow)
|
||||
<div class="muted text-danger mt-6">
|
||||
需先完成治理后再同步
|
||||
@if($syncBlockedByMissingSubscriptionOnRenewalRow)
|
||||
<span class="muted">|</span>
|
||||
<a class="link" href="{!! $relationFixUrlCompact !!}">去关联订阅</a>
|
||||
@endif
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@if($syncError)
|
||||
|
||||
@@ -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 AdminPlatformOrderIndexRowActivateSubscriptionButtonShouldDisableWhenGovernanceMismatchTest 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_activate_subscription_button_should_be_disabled_when_reconcile_mismatch(): void
|
||||
{
|
||||
$this->loginAsPlatformAdmin();
|
||||
|
||||
$merchant = Merchant::query()->firstOrFail();
|
||||
$plan = Plan::query()->create([
|
||||
'code' => 'po_index_row_sync_disable_reconcile_mismatch_plan',
|
||||
'name' => '平台订单列表行级同步订阅禁用(对账不一致)测试套餐',
|
||||
'billing_cycle' => 'monthly',
|
||||
'price' => 30,
|
||||
'list_price' => 30,
|
||||
'status' => 'active',
|
||||
'sort' => 10,
|
||||
'published_at' => now(),
|
||||
]);
|
||||
|
||||
// 制造对账不一致:payment_status=paid + payment_summary.total_amount != paid_amount
|
||||
$order = PlatformOrder::query()->create([
|
||||
'merchant_id' => $merchant->id,
|
||||
'plan_id' => $plan->id,
|
||||
'order_no' => 'PO_INDEX_ROW_SYNC_DISABLE_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' => 30,
|
||||
'paid_amount' => 30,
|
||||
'placed_at' => now(),
|
||||
'paid_at' => now(),
|
||||
'activated_at' => now(),
|
||||
'meta' => [
|
||||
'payment_summary' => [
|
||||
'count' => 1,
|
||||
'total_amount' => 29,
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assertTrue($order->isReconcileMismatch());
|
||||
|
||||
$res = $this->get('/admin/platform-orders');
|
||||
$res->assertOk();
|
||||
|
||||
$html = (string) $res->getContent();
|
||||
$this->assertStringContainsString($order->order_no, $html);
|
||||
|
||||
// 断言:该订单所在行的“同步订阅”按钮应被禁用(避免运营在列表页误触)
|
||||
$pattern = '#/admin/platform-orders/' . $order->id . '/activate-subscription.*?<button[^>]*disabled#s';
|
||||
$this->assertMatchesRegularExpression($pattern, $html);
|
||||
|
||||
// 并且仍应存在最短治理入口(对账:去补回执)
|
||||
$this->assertStringContainsString('#add-payment-receipt', $html);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user