统一退款不一致(refund_inconsistent)口径:引入 amounts.tolerance 并对齐模型与筛选

This commit is contained in:
萝卜
2026-03-13 15:51:26 +00:00
parent b0ee9b6290
commit 6f1b894b45
10 changed files with 128 additions and 30 deletions

View File

@@ -0,0 +1,84 @@
<?php
namespace Tests\Unit;
use App\Models\Merchant;
use App\Models\Plan;
use App\Models\PlatformOrder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class PlatformOrderRefundInconsistentToleranceConfigTest extends TestCase
{
use RefreshDatabase;
public function test_is_refund_inconsistent_respects_configured_tolerance(): void
{
config(['saasshop.amounts.tolerance' => 0.05]);
$merchant = Merchant::query()->create([
'name' => '容差单测站点',
'slug' => 'unit-test-merchant-refund-tol',
'status' => 'active',
]);
$plan = Plan::query()->create([
'code' => 'unit_test_plan_refund_tol_1',
'name' => '容差单测套餐',
'billing_cycle' => 'monthly',
'price' => 10,
'list_price' => 10,
'status' => 'active',
'sort' => 10,
'published_at' => now(),
]);
// 场景1状态=refunded但退款总额只差 0.02(在容差 0.05 内)=> 不应判定不一致
$order1 = PlatformOrder::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'order_no' => 'PO_UNIT_REFUND_TOL_0001',
'order_type' => 'subscription',
'status' => 'activated',
'payment_status' => 'refunded',
'plan_name' => 'Unit Test Plan',
'billing_cycle' => 'monthly',
'period_months' => 1,
'quantity' => 1,
'payable_amount' => 10,
'paid_amount' => 10,
'placed_at' => now(),
'meta' => [
'refund_summary' => [
'total_amount' => 9.98,
],
],
]);
$this->assertFalse($order1->isRefundInconsistent());
// 场景2状态!=refunded但退款总额只比已付多 0.02(在容差 0.05 内)=> 不应判定不一致
$order2 = PlatformOrder::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'order_no' => 'PO_UNIT_REFUND_TOL_0002',
'order_type' => 'subscription',
'status' => 'activated',
'payment_status' => 'paid',
'plan_name' => 'Unit Test Plan',
'billing_cycle' => 'monthly',
'period_months' => 1,
'quantity' => 1,
'payable_amount' => 10,
'paid_amount' => 10,
'placed_at' => now(),
'meta' => [
'refund_summary' => [
'total_amount' => 10.02,
],
],
]);
$this->assertFalse($order2->isRefundInconsistent());
}
}