From 0745d5657ccdfe388cf7bc13ddd18de4f5f27bd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Fri, 13 Mar 2026 15:14:25 +0000 Subject: [PATCH] =?UTF-8?q?admin:=20=E5=8D=95=E7=AC=94=E6=A0=87=E8=AE=B0?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E5=B9=B6=E7=94=9F=E6=95=88=E5=9B=9E=E6=89=A7?= =?UTF-8?q?=E5=B7=AE=E9=A2=9D=E5=AE=89=E5=85=A8=E9=98=80=E6=8C=89=E5=AE=B9?= =?UTF-8?q?=E5=B7=AE=E9=85=8D=E7=BD=AE=E5=8C=96=E5=AF=B9=E9=BD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin/PlatformOrderController.php | 7 +- ...tivateReconcileMismatchSafetyValveTest.php | 2 +- ...MarkPaidAndActivateToleranceConfigTest.php | 75 +++++++++++++++++++ 3 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 tests/Feature/AdminPlatformOrderMarkPaidAndActivateToleranceConfigTest.php diff --git a/app/Http/Controllers/Admin/PlatformOrderController.php b/app/Http/Controllers/Admin/PlatformOrderController.php index 7113580..9340742 100644 --- a/app/Http/Controllers/Admin/PlatformOrderController.php +++ b/app/Http/Controllers/Admin/PlatformOrderController.php @@ -463,7 +463,12 @@ class PlatformOrderController extends Controller $expectedPaid = (float) (($order->paid_amount ?? 0) > 0 ? $order->paid_amount : $order->payable_amount); $receiptCents = (int) round($receiptTotal * 100); $expectedCents = (int) round($expectedPaid * 100); - if ($receiptCents > 0 && abs($receiptCents - $expectedCents) >= 1) { + + $tol = (float) config('saasshop.amounts.tolerance', 0.01); + $tolCents = (int) round($tol * 100); + $tolCents = max(1, $tolCents); + + if ($receiptCents > 0 && abs($receiptCents - $expectedCents) >= $tolCents) { return redirect()->back()->with('warning', '当前订单已存在支付回执,但回执总额与订单金额不一致。为避免带病推进,请先补齐/修正支付回执后再执行「标记支付并生效」。'); } diff --git a/tests/Feature/AdminPlatformOrderMarkPaidAndActivateReconcileMismatchSafetyValveTest.php b/tests/Feature/AdminPlatformOrderMarkPaidAndActivateReconcileMismatchSafetyValveTest.php index c15b4ad..df0b52b 100644 --- a/tests/Feature/AdminPlatformOrderMarkPaidAndActivateReconcileMismatchSafetyValveTest.php +++ b/tests/Feature/AdminPlatformOrderMarkPaidAndActivateReconcileMismatchSafetyValveTest.php @@ -38,7 +38,7 @@ class AdminPlatformOrderMarkPaidAndActivateReconcileMismatchSafetyValveTest exte 'published_at' => now(), ]); - // 已存在回执汇总,但与订单应付金额不一致 + // 已存在回执汇总,但与订单应付金额不一致(差 0.02,超过默认容差 0.01) $order = PlatformOrder::query()->create([ 'merchant_id' => $merchant->id, 'plan_id' => $plan->id, diff --git a/tests/Feature/AdminPlatformOrderMarkPaidAndActivateToleranceConfigTest.php b/tests/Feature/AdminPlatformOrderMarkPaidAndActivateToleranceConfigTest.php new file mode 100644 index 0000000..4671a5d --- /dev/null +++ b/tests/Feature/AdminPlatformOrderMarkPaidAndActivateToleranceConfigTest.php @@ -0,0 +1,75 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_mark_paid_and_activate_uses_configured_tolerance_for_receipt_mismatch_safety_valve(): void + { + $this->loginAsPlatformAdmin(); + + config(['saasshop.amounts.tolerance' => 0.05]); + + $merchant = Merchant::query()->firstOrFail(); + $plan = Plan::query()->create([ + 'code' => 'mark_paid_tol_cfg_plan', + 'name' => '标记支付容差配置测试(月付)', + 'billing_cycle' => 'monthly', + 'price' => 30, + 'list_price' => 30, + 'status' => 'active', + 'sort' => 10, + 'published_at' => now(), + ]); + + // 订单应付 30.00,已有回执 30.02(差 0.02),在容差 0.05 内,不应阻断 + $order = PlatformOrder::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'order_no' => 'PO_MARK_PAID_TOL_CFG_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' => [ + 'payment_summary' => [ + 'count' => 1, + 'total_amount' => 30.02, + ], + ], + ]); + + $res = $this->post('/admin/platform-orders/' . $order->id . '/mark-paid-and-activate'); + $res->assertRedirect(); + $res->assertSessionHas('success'); + + $order->refresh(); + $this->assertSame('paid', $order->payment_status); + $this->assertSame('activated', $order->status); + $this->assertNotNull($order->site_subscription_id); + } +}