统一对账差额阈值使用 amounts.tolerance 配置

This commit is contained in:
萝卜
2026-03-13 11:25:31 +00:00
parent 916796f58e
commit ffbf68679b
3 changed files with 15 additions and 2 deletions

View File

@@ -69,7 +69,12 @@ class PlatformOrder extends Model
$receiptCents = (int) round(((float) $this->receiptTotal()) * 100);
$paidCents = (int) round(((float) ($this->paid_amount ?? 0)) * 100);
return abs($receiptCents - $paidCents) >= 1;
$tol = (float) config('saasshop.amounts.tolerance', 0.01);
$tolCents = (int) round($tol * 100);
// 以“分”为最小粒度,至少 1 分(若配置 0则视为要求严格一致
$tolCents = max(1, $tolCents);
return abs($receiptCents - $paidCents) >= $tolCents;
}
protected $fillable = [

View File

@@ -12,4 +12,11 @@ return [
// 同步失败原因展示截断长度(用于列表/聚合展示,避免撑坏布局)。
'sync_failed_reason_display_truncate_len' => 60,
],
// 金额对账相关配置(统一按分取整后做比较,避免浮点误差)。
'amounts' => [
// 允许的金额差异容差(单位:元),默认 0.01。
// 用于对账不一致、退款不一致等口径判断。
'tolerance' => 0.01,
],
];

View File

@@ -227,7 +227,8 @@
<div class="muted muted-xs">对账不一致订单:
<a class="link" href="{{ request()->fullUrlWithQuery(['reconcile_mismatch' => '1', 'page' => null]) }}">{{ $summaryStats['reconcile_mismatch_orders'] ?? 0 }}</a>
</div>
@if(abs($delta) >= 0.01)
@php $tol = (float) config('saasshop.amounts.tolerance', 0.01); @endphp
@if(abs($delta) >= $tol)
<div class="muted text-danger mt-6">提示:差额非 0,可能存在回执金额与订单金额不一致的订单。</div>
@endif
</div>