统一退款不一致(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

@@ -58,7 +58,7 @@ class AdminPlatformOrderBatchActivateSubscriptionsRefundInconsistentFilterFields
'meta' => [
'refund_summary' => [
'count' => 1,
'total_amount' => 10.00,
'total_amount' => 10.01,
],
],
]);

View File

@@ -57,7 +57,7 @@ class AdminPlatformOrderBatchMarkActivatedRefundInconsistentFilterFieldsTest ext
'meta' => [
'refund_summary' => [
'count' => 1,
'total_amount' => 10.00,
'total_amount' => 10.01,
],
],
]);

View File

@@ -58,7 +58,7 @@ class AdminPlatformOrderClearSyncErrorsRefundInconsistentFilterFieldsTest extend
'meta' => [
'refund_summary' => [
'count' => 1,
'total_amount' => 10.00,
'total_amount' => 10.01,
],
'subscription_activation_error' => [
'message' => '测试错误A',

View File

@@ -84,7 +84,7 @@ class AdminPlatformOrderExportRefundInconsistentFilterTest extends TestCase
'meta' => [
'refund_summary' => [
'count' => 1,
'total_amount' => 10.00,
'total_amount' => 10.01,
],
],
]);
@@ -110,7 +110,7 @@ class AdminPlatformOrderExportRefundInconsistentFilterTest extends TestCase
'meta' => [
'refund_summary' => [
'count' => 1,
'total_amount' => 10.00,
'total_amount' => 10.01,
],
],
]);

View File

@@ -87,9 +87,9 @@ class AdminPlatformOrderRefundInconsistentFilterTest extends TestCase
'meta' => [
'refund_summary' => [
'count' => 1,
'total_amount' => 10.00,
'total_amount' => 10.01,
'last_at' => now()->toDateTimeString(),
'last_amount' => 10.00,
'last_amount' => 10.01,
'last_channel' => 'bank',
],
],
@@ -116,9 +116,9 @@ class AdminPlatformOrderRefundInconsistentFilterTest extends TestCase
'meta' => [
'refund_summary' => [
'count' => 1,
'total_amount' => 10.00,
'total_amount' => 10.01,
'last_at' => now()->toDateTimeString(),
'last_amount' => 10.00,
'last_amount' => 10.01,
'last_channel' => 'bank',
],
],

View File

@@ -57,7 +57,7 @@ class AdminPlatformOrderRefundInconsistentRowHintTest extends TestCase
'meta' => [
'refund_summary' => [
'count' => 1,
'total_amount' => 10.00,
'total_amount' => 10.01,
],
],
]);

View File

@@ -96,10 +96,12 @@ class PlatformOrderRefundInconsistentTest extends TestCase
],
]);
// refunded 状态下:只有当退款总额 + 容差 < 已付金额 才算不一致。
// 这里 refund_total=9.98、paid=10.00,差额 0.02 > 默认容差 0.01,因此应判定为不一致。
$this->assertTrue($order->isRefundInconsistent());
}
public function test_is_refund_inconsistent_when_status_not_refunded_but_refund_total_reaches_paid_amount(): void
public function test_is_refund_inconsistent_when_status_not_refunded_but_refund_total_reaches_paid_amount_plus_tolerance(): void
{
$merchant = Merchant::query()->create([
'name' => '单测站点3',
@@ -139,6 +141,8 @@ class PlatformOrderRefundInconsistentTest extends TestCase
],
]);
$this->assertTrue($order->isRefundInconsistent());
// paid非 refunded状态下只有当退款总额 >= 已付金额 + 容差 才算不一致。
// 这里 refund_total=10.00 与 paid=10.00 相等,未达到 paid + 0.01,因此不应判定不一致。
$this->assertFalse($order->isRefundInconsistent());
}
}

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