From f9bea18ffda928f535c62ed26d20c319fb8c3732 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Wed, 18 Mar 2026 15:35:21 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E9=BD=90=E5=AF=B9=E8=B4=A6=E4=B8=8D?= =?UTF-8?q?=E4=B8=80=E8=87=B4=E7=AD=9B=E9=80=89=E5=AE=B9=E5=B7=AE=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=8A=A4=E6=A0=8F=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ncileMismatchToleranceConfigFilterTest.php | 106 ++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 tests/Feature/AdminPlatformOrderReconcileMismatchToleranceConfigFilterTest.php diff --git a/tests/Feature/AdminPlatformOrderReconcileMismatchToleranceConfigFilterTest.php b/tests/Feature/AdminPlatformOrderReconcileMismatchToleranceConfigFilterTest.php new file mode 100644 index 0000000..2dc3db9 --- /dev/null +++ b/tests/Feature/AdminPlatformOrderReconcileMismatchToleranceConfigFilterTest.php @@ -0,0 +1,106 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_reconcile_mismatch_filter_should_respect_amount_tolerance_config(): void + { + // 将容差调大,确保“差额小于容差”不被判定为对账不一致 + config()->set('saasshop.amounts.tolerance', 0.05); + + $this->loginAsPlatformAdmin(); + + $merchant = Merchant::query()->firstOrFail(); + $plan = Plan::query()->create([ + 'code' => 'po_reconcile_mismatch_tol_plan', + 'name' => '对账不一致容差配置测试套餐', + 'billing_cycle' => 'monthly', + 'price' => 10, + 'list_price' => 10, + 'status' => 'active', + 'sort' => 10, + 'published_at' => now(), + ]); + + // A:差额 0.04 < tol(0.05) => 不应命中 + PlatformOrder::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'order_no' => 'PO_RECON_TOL_NO_0001', + 'order_type' => 'new_purchase', + 'status' => 'activated', + '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(), + 'activated_at' => now(), + 'meta' => [ + 'payment_summary' => [ + 'count' => 1, + 'total_amount' => 9.96, + 'last_at' => now()->toDateTimeString(), + 'last_amount' => 9.96, + 'last_channel' => 'bank', + ], + ], + ]); + + // B:差额 0.06 >= tol(0.05) => 应命中 + PlatformOrder::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'order_no' => 'PO_RECON_TOL_YES_0002', + 'order_type' => 'new_purchase', + 'status' => 'activated', + '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(), + 'activated_at' => now(), + 'meta' => [ + 'payment_summary' => [ + 'count' => 1, + 'total_amount' => 9.94, + 'last_at' => now()->toDateTimeString(), + 'last_amount' => 9.94, + 'last_channel' => 'bank', + ], + ], + ]); + + $res = $this->get('/admin/platform-orders?reconcile_mismatch=1'); + $res->assertOk(); + + $res->assertDontSee('PO_RECON_TOL_NO_0001', false); + $res->assertSee('PO_RECON_TOL_YES_0002', false); + } +}