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); + } +}