From 6abfbd7d9d43cd02f901d46dcb9df8bb5bc7cb19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Wed, 18 Mar 2026 01:10:51 +0800 Subject: [PATCH] Platform orders index: disable mark-activated when reconcile mismatch or refund trace; add tests --- .../admin/platform_orders/index.blade.php | 26 ++++-- ...ShouldDisableWhenReconcileMismatchTest.php | 82 +++++++++++++++++++ ...ShouldDisableWhenRefundTraceExistsTest.php | 82 +++++++++++++++++++ 3 files changed, 184 insertions(+), 6 deletions(-) create mode 100644 tests/Feature/AdminPlatformOrderIndexRowMarkActivatedButtonShouldDisableWhenReconcileMismatchTest.php create mode 100644 tests/Feature/AdminPlatformOrderIndexRowMarkActivatedButtonShouldDisableWhenRefundTraceExistsTest.php diff --git a/resources/views/admin/platform_orders/index.blade.php b/resources/views/admin/platform_orders/index.blade.php index ce27fb9..1d07796 100644 --- a/resources/views/admin/platform_orders/index.blade.php +++ b/resources/views/admin/platform_orders/index.blade.php @@ -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
@csrf - +
- @if($markActivatedBlockedByMissingSubscriptionOnRenewalRow) + @if($markActivatedBlockedByMissingSubscriptionOnRenewalRow || $markActivatedBlockedByGovernanceRow)
- 续费缺订阅不可直接标记生效 - - 去关联订阅 + @if($markActivatedBlockedByMissingSubscriptionOnRenewalRow) + 续费缺订阅不可直接标记生效 + + 去关联订阅 + @elseif((bool) $order->isReconcileMismatch()) + 对账不一致不可直接标记生效 + + 去补回执 + @else + 有退款轨迹不可直接标记生效 + + 去核对退款 + @endif
@endif diff --git a/tests/Feature/AdminPlatformOrderIndexRowMarkActivatedButtonShouldDisableWhenReconcileMismatchTest.php b/tests/Feature/AdminPlatformOrderIndexRowMarkActivatedButtonShouldDisableWhenReconcileMismatchTest.php new file mode 100644 index 0000000..2272e21 --- /dev/null +++ b/tests/Feature/AdminPlatformOrderIndexRowMarkActivatedButtonShouldDisableWhenReconcileMismatchTest.php @@ -0,0 +1,82 @@ +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); + } +} diff --git a/tests/Feature/AdminPlatformOrderIndexRowMarkActivatedButtonShouldDisableWhenRefundTraceExistsTest.php b/tests/Feature/AdminPlatformOrderIndexRowMarkActivatedButtonShouldDisableWhenRefundTraceExistsTest.php new file mode 100644 index 0000000..ed62289 --- /dev/null +++ b/tests/Feature/AdminPlatformOrderIndexRowMarkActivatedButtonShouldDisableWhenRefundTraceExistsTest.php @@ -0,0 +1,82 @@ +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); + } +}