diff --git a/resources/views/admin/platform_orders/show.blade.php b/resources/views/admin/platform_orders/show.blade.php index 6cfa865..d60c9a4 100644 --- a/resources/views/admin/platform_orders/show.blade.php +++ b/resources/views/admin/platform_orders/show.blade.php @@ -129,6 +129,15 @@ $canMarkPaid = ($order->payment_status !== 'paid') || ($order->status !== 'activated'); $syncError = data_get($order->meta, 'subscription_activation_error.message'); $syncErrorAt = data_get($order->meta, 'subscription_activation_error.at'); + + // 治理提示:标记支付并生效的安全阀(后端也会阻断) + $refundTotal = (float) $order->refundTotal(); + $receiptTotal = (float) $order->receiptTotal(); + $expectedPaid = (float) (((float) ($order->paid_amount ?? 0)) > 0 ? (float) $order->paid_amount : (float) ($order->payable_amount ?? 0)); + $receiptCents = (int) round($receiptTotal * 100); + $expectedCents = (int) round($expectedPaid * 100); + $markPaidBlockedByRefund = $refundTotal > 0; + $markPaidBlockedByReceiptMismatch = $receiptCents > 0 && abs($receiptCents - $expectedCents) >= 1; @endphp
@@ -137,6 +146,12 @@ + @if($markPaidBlockedByRefund) +
提示:当前订单已存在退款记录/退款汇总,建议先核对退款轨迹与状态后再进行「标记支付并生效」。
+ @elseif($markPaidBlockedByReceiptMismatch) +
提示:当前订单已存在支付回执,但回执总额与订单金额不一致,建议先补齐/修正回执后再进行「标记支付并生效」。
+ @endif +
@csrf diff --git a/tests/Feature/AdminPlatformOrderShowMarkPaidGovernanceHintTest.php b/tests/Feature/AdminPlatformOrderShowMarkPaidGovernanceHintTest.php new file mode 100644 index 0000000..d564329 --- /dev/null +++ b/tests/Feature/AdminPlatformOrderShowMarkPaidGovernanceHintTest.php @@ -0,0 +1,110 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_order_show_page_shows_hint_when_mark_paid_blocked_by_refund_total(): void + { + $this->loginAsPlatformAdmin(); + + $merchant = Merchant::query()->firstOrFail(); + $plan = Plan::query()->create([ + 'code' => 'show_mark_paid_hint_refund_test', + '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_PAID_HINT_REFUND_0001', + 'order_type' => 'new_purchase', + 'status' => 'pending', + 'payment_status' => 'unpaid', + 'plan_name' => $plan->name, + 'billing_cycle' => $plan->billing_cycle, + 'period_months' => 1, + 'quantity' => 1, + 'payable_amount' => 30, + 'paid_amount' => 0, + 'placed_at' => now(), + 'meta' => [ + 'refund_summary' => [ + 'count' => 1, + 'total_amount' => 1.00, + ], + ], + ]); + + $this->get('/admin/platform-orders/' . $order->id) + ->assertOk() + ->assertSee('已存在退款记录/退款汇总', false); + } + + public function test_order_show_page_shows_hint_when_mark_paid_blocked_by_receipt_mismatch(): void + { + $this->loginAsPlatformAdmin(); + + $merchant = Merchant::query()->firstOrFail(); + $plan = Plan::query()->create([ + 'code' => 'show_mark_paid_hint_receipt_test', + '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_PAID_HINT_RECEIPT_0002', + 'order_type' => 'new_purchase', + 'status' => 'pending', + 'payment_status' => 'unpaid', + 'plan_name' => $plan->name, + 'billing_cycle' => $plan->billing_cycle, + 'period_months' => 1, + 'quantity' => 1, + 'payable_amount' => 30, + 'paid_amount' => 0, + 'placed_at' => now(), + 'meta' => [ + 'payment_summary' => [ + 'count' => 1, + 'total_amount' => 29.98, + ], + ], + ]); + + $this->get('/admin/platform-orders/' . $order->id) + ->assertOk() + ->assertSee('已存在支付回执,但回执总额与订单金额不一致', false); + } +}