From 9a566da98258d5fdeefe9d27a2415353d48847e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Wed, 11 Mar 2026 08:38:11 +0000 Subject: [PATCH] =?UTF-8?q?=E6=A0=87=E8=AE=B0=E6=94=AF=E4=BB=98=E5=B9=B6?= =?UTF-8?q?=E7=94=9F=E6=95=88=EF=BC=9A=E5=AD=98=E5=9C=A8=E9=80=80=E6=AC=BE?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E6=97=B6=E9=98=BB=E6=96=AD=E5=B9=B6=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E5=85=88=E6=A0=B8=E5=AF=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin/PlatformOrderController.php | 5 ++ ...rkPaidAndActivateRefundSafetyValveTest.php | 72 +++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 tests/Feature/AdminPlatformOrderMarkPaidAndActivateRefundSafetyValveTest.php diff --git a/app/Http/Controllers/Admin/PlatformOrderController.php b/app/Http/Controllers/Admin/PlatformOrderController.php index 1c71559..a11ed36 100644 --- a/app/Http/Controllers/Admin/PlatformOrderController.php +++ b/app/Http/Controllers/Admin/PlatformOrderController.php @@ -405,6 +405,11 @@ class PlatformOrderController extends Controller { $admin = $this->ensurePlatformAdmin($request); + // 治理优先:若该订单已有退款轨迹(refund_summary/refund_receipts),不允许直接“标记支付并生效”,避免出现带退款的订单被强行推进并同步订阅 + if ((float) $order->refundTotal() > 0) { + return redirect()->back()->with('warning', '当前订单已存在退款记录/退款汇总,请先核对退款轨迹与订单状态后再处理(不建议直接标记支付并生效)。'); + } + // 最小状态推进:将订单标记为已支付 + 已生效,并补齐时间与金额字段 $now = now(); $order->payment_status = 'paid'; diff --git a/tests/Feature/AdminPlatformOrderMarkPaidAndActivateRefundSafetyValveTest.php b/tests/Feature/AdminPlatformOrderMarkPaidAndActivateRefundSafetyValveTest.php new file mode 100644 index 0000000..bb22a41 --- /dev/null +++ b/tests/Feature/AdminPlatformOrderMarkPaidAndActivateRefundSafetyValveTest.php @@ -0,0 +1,72 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_mark_paid_and_activate_blocked_when_order_has_refund_records(): void + { + $this->loginAsPlatformAdmin(); + + $merchant = Merchant::query()->firstOrFail(); + $plan = Plan::query()->create([ + 'code' => 'mark_paid_refund_safety_valve_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_MARK_PAID_REFUND_BLOCK_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, + ], + ], + ]); + + $res = $this->post('/admin/platform-orders/' . $order->id . '/mark-paid-and-activate'); + $res->assertRedirect(); + $res->assertSessionHas('warning'); + + $order->refresh(); + $this->assertSame('unpaid', $order->payment_status); + $this->assertSame('pending', $order->status); + $this->assertNull($order->site_subscription_id); + } +}