Platform orders index: disable mark-activated when reconcile mismatch or refund trace; add tests
This commit is contained in:
@@ -1842,19 +1842,33 @@
|
||||
|
||||
@php
|
||||
$canMarkActivatedOnly = ($order->payment_status === 'paid') && ($order->status !== 'activated');
|
||||
// 安全阀对齐后端:续费单未绑定订阅时,不允许“仅标记为已生效”(后端 markActivated 也会阻断)
|
||||
// 安全阀对齐后端:以下情况不允许“仅标记为已生效”(后端 markActivated 也会阻断)
|
||||
// - 续费缺订阅:需先绑定订阅
|
||||
// - 对账不一致:需先补回执/核对金额
|
||||
// - 存在退款轨迹:需先核对退款轨迹与退款状态
|
||||
$markActivatedBlockedByMissingSubscriptionOnRenewalRow = ((string) ($order->order_type ?? '') === 'renewal')
|
||||
&& ((int) ($order->site_subscription_id ?? 0) <= 0);
|
||||
$markActivatedBlockedByGovernanceRow = (bool) ($order->isReconcileMismatch() || (((float) $order->refundTotal()) > 0));
|
||||
@endphp
|
||||
<form method="post" action="/admin/platform-orders/{{ $order->id }}/mark-activated" data-action="disable-on-submit" onsubmit="return confirm('确认将该订单标记为已生效?(不修改支付状态,不自动同步订阅)');" class="mb-6">
|
||||
@csrf
|
||||
<button class="btn btn-secondary btn-sm" type="submit" @disabled(! $canMarkActivatedOnly || $markActivatedBlockedByMissingSubscriptionOnRenewalRow)>仅标记为已生效</button>
|
||||
<button class="btn btn-secondary btn-sm" type="submit" @disabled(! $canMarkActivatedOnly || $markActivatedBlockedByMissingSubscriptionOnRenewalRow || $markActivatedBlockedByGovernanceRow)>仅标记为已生效</button>
|
||||
</form>
|
||||
@if($markActivatedBlockedByMissingSubscriptionOnRenewalRow)
|
||||
@if($markActivatedBlockedByMissingSubscriptionOnRenewalRow || $markActivatedBlockedByGovernanceRow)
|
||||
<div class="muted text-danger mt-6">
|
||||
续费缺订阅不可直接标记生效
|
||||
<span class="muted">|</span>
|
||||
<a class="link" href="{!! $relationFixUrlCompactForBmpa !!}">去关联订阅</a>
|
||||
@if($markActivatedBlockedByMissingSubscriptionOnRenewalRow)
|
||||
续费缺订阅不可直接标记生效
|
||||
<span class="muted">|</span>
|
||||
<a class="link" href="{!! $relationFixUrlCompactForBmpa !!}">去关联订阅</a>
|
||||
@elseif((bool) $order->isReconcileMismatch())
|
||||
对账不一致不可直接标记生效
|
||||
<span class="muted">|</span>
|
||||
<a class="link" href="{!! $reconcileFixUrlCompact !!}">去补回执</a>
|
||||
@else
|
||||
有退款轨迹不可直接标记生效
|
||||
<span class="muted">|</span>
|
||||
<a class="link" href="{!! $refundTraceFixUrlCompact !!}">去核对退款</a>
|
||||
@endif
|
||||
</div>
|
||||
@endif
|
||||
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
<?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 AdminPlatformOrderIndexRowMarkActivatedButtonShouldDisableWhenReconcileMismatchTest 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_platform_orders_index_row_mark_activated_button_should_disable_when_reconcile_mismatch(): void
|
||||
{
|
||||
$this->loginAsPlatformAdmin();
|
||||
|
||||
// 清理 seed,避免列表干扰断言。
|
||||
PlatformOrder::query()->delete();
|
||||
|
||||
$merchant = Merchant::query()->firstOrFail();
|
||||
|
||||
$plan = Plan::query()->create([
|
||||
'code' => 'po_index_mark_activated_reconcile_mismatch_test',
|
||||
'name' => '平台订单列表行级仅标记生效(对账不一致禁用)测试套餐',
|
||||
'billing_cycle' => 'monthly',
|
||||
'price' => 10,
|
||||
'list_price' => 10,
|
||||
'status' => 'active',
|
||||
'sort' => 10,
|
||||
'published_at' => now(),
|
||||
]);
|
||||
|
||||
// 已支付 + 待处理,但对账不一致(paid=10,回执=9)
|
||||
PlatformOrder::query()->create([
|
||||
'merchant_id' => $merchant->id,
|
||||
'plan_id' => $plan->id,
|
||||
'order_no' => 'PO_INDEX_MARK_ACTIVATED_RECON_MISMATCH_0001',
|
||||
'order_type' => 'new_purchase',
|
||||
'status' => 'pending',
|
||||
'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(),
|
||||
'meta' => [
|
||||
'payment_summary' => [
|
||||
'total_amount' => 9,
|
||||
'count' => 1,
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$res = $this->get('/admin/platform-orders');
|
||||
$res->assertOk();
|
||||
|
||||
$res->assertSee('PO_INDEX_MARK_ACTIVATED_RECON_MISMATCH_0001');
|
||||
|
||||
// 行级“仅标记为已生效”按钮必须 disabled
|
||||
$res->assertSee('action="/admin/platform-orders/', false);
|
||||
$res->assertSee('/mark-activated', false);
|
||||
$res->assertSee('disabled', false);
|
||||
|
||||
// 并给出最短治理入口:去补回执
|
||||
$res->assertSee('#add-payment-receipt', false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
<?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 AdminPlatformOrderIndexRowMarkActivatedButtonShouldDisableWhenRefundTraceExistsTest 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_platform_orders_index_row_mark_activated_button_should_disable_when_refund_trace_exists(): void
|
||||
{
|
||||
$this->loginAsPlatformAdmin();
|
||||
|
||||
// 清理 seed,避免列表干扰断言。
|
||||
PlatformOrder::query()->delete();
|
||||
|
||||
$merchant = Merchant::query()->firstOrFail();
|
||||
|
||||
$plan = Plan::query()->create([
|
||||
'code' => 'po_index_mark_activated_refund_trace_test',
|
||||
'name' => '平台订单列表行级仅标记生效(退款轨迹禁用)测试套餐',
|
||||
'billing_cycle' => 'monthly',
|
||||
'price' => 10,
|
||||
'list_price' => 10,
|
||||
'status' => 'active',
|
||||
'sort' => 10,
|
||||
'published_at' => now(),
|
||||
]);
|
||||
|
||||
// 已支付 + 待处理,但存在退款轨迹(refund_total>0)。
|
||||
// 注意:这里不强依赖 isRefundInconsistent(),只验证“有退款轨迹即需先治理”。
|
||||
PlatformOrder::query()->create([
|
||||
'merchant_id' => $merchant->id,
|
||||
'plan_id' => $plan->id,
|
||||
'order_no' => 'PO_INDEX_MARK_ACTIVATED_REFUND_TRACE_0001',
|
||||
'order_type' => 'new_purchase',
|
||||
'status' => 'pending',
|
||||
'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(),
|
||||
'meta' => [
|
||||
'refund_summary' => [
|
||||
'total_amount' => 1,
|
||||
'count' => 1,
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$res = $this->get('/admin/platform-orders');
|
||||
$res->assertOk();
|
||||
|
||||
$res->assertSee('PO_INDEX_MARK_ACTIVATED_REFUND_TRACE_0001');
|
||||
|
||||
// 行级“仅标记为已生效”按钮必须 disabled
|
||||
$res->assertSee('/mark-activated', false);
|
||||
$res->assertSee('disabled', false);
|
||||
|
||||
// 并给出最短治理入口:去核对退款(add-refund-receipt)
|
||||
$res->assertSee('#add-refund-receipt', false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user