feat(admin): 续费缺订阅时禁用仅标记为已生效并给治理引导
This commit is contained in:
@@ -342,11 +342,31 @@
|
||||
|
||||
@php
|
||||
$canMarkActivatedOnly = ($order->payment_status === 'paid') && ($order->status !== 'activated');
|
||||
// 安全阀:续费单未绑定订阅时,不允许“仅标记为已生效”(后端 markActivated 也会阻断)
|
||||
$markActivatedBlockedByMissingSubscriptionOnRenewal = ((string) ($order->order_type ?? '') === 'renewal')
|
||||
&& ((int) ($order->site_subscription_id ?? 0) <= 0);
|
||||
@endphp
|
||||
<form method="post" action="/admin/platform-orders/{{ $order->id }}/mark-activated" onsubmit="return confirm('确认将该订单标记为已生效?(不修改支付状态,不自动同步订阅)');">
|
||||
@csrf
|
||||
<button class="btn btn-secondary btn-sm" type="submit" @disabled(! $canMarkActivatedOnly)>仅标记为已生效</button>
|
||||
<button class="btn btn-secondary btn-sm" type="submit" @disabled(! $canMarkActivatedOnly || $markActivatedBlockedByMissingSubscriptionOnRenewal)>仅标记为已生效</button>
|
||||
</form>
|
||||
|
||||
@if($markActivatedBlockedByMissingSubscriptionOnRenewal)
|
||||
<div class="card governance-block">
|
||||
<div class="muted text-danger governance-block-title"><strong>生效治理提示</strong>(当前不可直接标记为已生效)</div>
|
||||
<div class="muted governance-block-body">
|
||||
<div>
|
||||
原因:当前订单类型为「续费」,但未绑定订阅(site_subscription_id 为空)。
|
||||
<span class="muted">|</span>
|
||||
<span class="muted">请先补齐订阅关联后再处理。</span>
|
||||
@if($missingSubscriptionHelpUrl !== '')
|
||||
<span class="muted">|</span>
|
||||
<a class="btn btn-secondary btn-sm" href="{!! $missingSubscriptionHelpUrl !!}">去订阅管理查找订阅</a>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
@if(! $canActivate)
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
<?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 AdminPlatformOrderShowMarkActivatedButtonDisabledWhenRenewalMissingSubscriptionTest 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_show_should_disable_mark_activated_button_when_renewal_order_missing_subscription(): void
|
||||
{
|
||||
$this->loginAsPlatformAdmin();
|
||||
|
||||
$merchant = Merchant::query()->firstOrFail();
|
||||
$plan = Plan::query()->create([
|
||||
'code' => 'po_show_mark_activated_disable_renewal_no_sub_plan',
|
||||
'name' => '订单详情 生效按钮禁用(续费无订阅)测试套餐',
|
||||
'billing_cycle' => 'monthly',
|
||||
'price' => 30,
|
||||
'list_price' => 30,
|
||||
'status' => 'active',
|
||||
'sort' => 10,
|
||||
'published_at' => now(),
|
||||
]);
|
||||
|
||||
$order = PlatformOrder::query()->create([
|
||||
'merchant_id' => $merchant->id,
|
||||
'plan_id' => $plan->id,
|
||||
'order_no' => 'PO_SHOW_MARK_ACTIVATED_DISABLE_RENEW_NO_SUB_0001',
|
||||
'order_type' => 'renewal',
|
||||
'status' => 'pending',
|
||||
'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(),
|
||||
'meta' => [],
|
||||
]);
|
||||
|
||||
$res = $this->get('/admin/platform-orders/' . $order->id);
|
||||
$res->assertOk();
|
||||
|
||||
// 按钮应被禁用(disabled)
|
||||
$res->assertSee('仅标记为已生效', false);
|
||||
$res->assertSee('disabled', false);
|
||||
|
||||
// 治理提示应出现,并包含引导入口
|
||||
$res->assertSee('生效治理提示', false);
|
||||
$res->assertSee('续费', false);
|
||||
$res->assertSee('未绑定订阅', false);
|
||||
$res->assertSee('去订阅管理查找订阅', false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user