admin: 订阅详情对账差额提示按容差配置判断并补测试护栏

This commit is contained in:
萝卜
2026-03-13 15:21:53 +00:00
parent 0745d5657c
commit b0ee9b6290
2 changed files with 95 additions and 3 deletions

View File

@@ -223,16 +223,17 @@
对账不一致订单:
<a class="link" href="{!! $makePlatformOrderUrl(['site_subscription_id' => $subscription->id, 'reconcile_mismatch' => '1']) !!}">{{ $summaryStats['reconcile_mismatch_orders'] ?? 0 }}</a>
</div>
@php $tol = (float) config('saasshop.amounts.tolerance', 0.01); @endphp
@if(((int) ($summaryStats['reconcile_mismatch_orders'] ?? 0)) > 0)
<div class="muted muted-xs text-danger">
提示:存在「回执总额 vs 已付金额」不一致订单。
<a class="link" href="{!! $makePlatformOrderUrl(['site_subscription_id' => $subscription->id, 'reconcile_mismatch' => '1']) !!}">进入对账不一致订单列表</a>
(建议先逐单核对回执轨迹与订单金额,再决定是否补回执/修正订单金额口径)。
</div>
@elseif(abs($delta) >= 0.01)
<div class="muted muted-xs text-danger">提示:差额 0,可能存在回执金额与订单已付金额不一致。</div>
@elseif(abs($delta) >= $tol)
<div class="muted muted-xs text-danger">提示:差额超过容差tol={{ number_format($tol, 2) }},可能存在回执金额与订单已付金额不一致。</div>
@else
<div class="muted muted-xs">差额 0当前订阅维度)</div>
<div class="muted muted-xs">差额在容差范围内tol={{ number_format($tol, 2) }}当前订阅维度)</div>
@endif
</div>

View File

@@ -0,0 +1,91 @@
<?php
namespace Tests\Feature;
use App\Models\Merchant;
use App\Models\Plan;
use App\Models\PlatformOrder;
use App\Models\SiteSubscription;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AdminSiteSubscriptionReconciliationDeltaToleranceHintTest extends TestCase
{
use RefreshDatabase;
protected function loginAsPlatformAdmin(): void
{
$this->seed();
$this->post('/admin/login', [
'email' => 'platform.admin@demo.local',
'password' => 'Platform@123456',
])->assertRedirect('/admin');
}
public function test_subscription_show_delta_hint_respects_tolerance_config(): void
{
$this->loginAsPlatformAdmin();
config(['saasshop.amounts.tolerance' => 0.05]);
$merchant = Merchant::query()->firstOrFail();
$plan = Plan::query()->create([
'code' => 'sub_delta_tol_01',
'name' => '订阅对账差额容差提示测试套餐',
'billing_cycle' => 'monthly',
'price' => 10,
'list_price' => 10,
'status' => 'active',
'sort' => 10,
'published_at' => now(),
]);
$sub = SiteSubscription::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'status' => 'activated',
'source' => 'manual',
'subscription_no' => 'SUB_DELTA_TOL_0001',
'plan_name' => $plan->name,
'billing_cycle' => $plan->billing_cycle,
'period_months' => 1,
'amount' => 10,
'starts_at' => now()->subDay(),
'ends_at' => now()->addMonth(),
'activated_at' => now()->subDay(),
]);
// paid_amount=10.00,回执=10.02,差额=0.02,在容差 0.05 内,应展示“在容差范围内”而非危险提示
PlatformOrder::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'site_subscription_id' => $sub->id,
'created_by_admin_id' => 1,
'order_no' => 'PO_SUB_DELTA_TOL_0001',
'order_type' => 'renewal',
'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()->subMinutes(10),
'paid_at' => now()->subMinutes(9),
'activated_at' => now()->subMinutes(8),
'meta' => [
'payment_summary' => [
'count' => 1,
'total_amount' => 10.02,
],
],
]);
$this->get('/admin/site-subscriptions/' . $sub->id)
->assertOk()
->assertSee('差额在容差范围内', false)
->assertDontSee('差额超过容差', false);
}
}