From 29e2779c7e1754de29c42e341c7bc5b5de8a6c49 Mon Sep 17 00:00:00 2001 From: linchong <2858233719@qq.com> Date: Wed, 18 Nov 2026 16:52:10 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=8F=91=E7=A5=A8=E9=A2=9D=E5=BA=A6?= =?UTF-8?q?=E9=A2=84=E8=AD=A6=E4=BD=BF=E7=94=A8=E7=B2=BE=E7=A1=AE=E6=94=AF?= =?UTF-8?q?=E6=92=91=E5=A4=A9=E6=95=B0=20(#1240)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 使用未舍入的可支撑天数判断 5 天阈值,并以两位小数展示。 --- app/Business/InvoiceQuotaPageData.php | 18 ++++++++++-------- .../business/pages/invoice_quota.blade.php | 2 +- .../Feature/Business/InvoiceQuotaPageTest.php | 8 ++++---- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/app/Business/InvoiceQuotaPageData.php b/app/Business/InvoiceQuotaPageData.php index 371d7b7e..b4d1f7f9 100644 --- a/app/Business/InvoiceQuotaPageData.php +++ b/app/Business/InvoiceQuotaPageData.php @@ -172,21 +172,23 @@ class InvoiceQuotaPageData $authStatus = strtoupper(trim((string) ($snapshot->auth_status ?? ''))); $elapsedDays = (int) ($forecastContext['elapsed_days'] ?? 0); $daysInMonth = (int) ($forecastContext['days_in_month'] ?? 0); - $dailyAverage = $elapsedDays > 0 - ? round($outputAmount / $elapsedDays, 2) + $dailyAverageRaw = $elapsedDays > 0 + ? $outputAmount / $elapsedDays : null; - $forecastMonthly = $dailyAverage !== null && $daysInMonth > 0 - ? round($dailyAverage * $daysInMonth, 2) + $dailyAverage = $dailyAverageRaw !== null ? round($dailyAverageRaw, 2) : null; + $forecastMonthly = $dailyAverageRaw !== null && $daysInMonth > 0 + ? round($outputAmount * $daysInMonth / $elapsedDays, 2) : null; - $coverageDays = $dailyAverage !== null && $dailyAverage > 0 && $availableAmount !== null - ? round(max($availableAmount, 0) / $dailyAverage, 1) + $coverageDaysRaw = $dailyAverageRaw !== null && $dailyAverageRaw > 0 && $availableAmount !== null + ? max($availableAmount, 0) / $dailyAverageRaw : null; + $coverageDays = $coverageDaysRaw !== null ? round($coverageDaysRaw, 2) : null; $quotaWarning = (bool) ($forecastContext['is_current'] ?? false) && $authStatus === 'AUTHENTICATED' && $availableAmount !== null && $availableAmount > 0 - && $coverageDays !== null - && $coverageDays < self::QUOTA_WARNING_DAYS; + && $coverageDaysRaw !== null + && $coverageDaysRaw < self::QUOTA_WARNING_DAYS; if ($snapshot === null) { $status = '未匹配'; diff --git a/resources/views/business/pages/invoice_quota.blade.php b/resources/views/business/pages/invoice_quota.blade.php index f81746af..9d75d3a3 100644 --- a/resources/views/business/pages/invoice_quota.blade.php +++ b/resources/views/business/pages/invoice_quota.blade.php @@ -252,7 +252,7 @@ @endif $row->quota_warning])> - {{ $row->coverage_days !== null ? number_format((float) $row->coverage_days, 1) . ' 天' : '—' }} + {{ $row->coverage_days !== null ? number_format((float) $row->coverage_days, 2) . ' 天' : '—' }} {{ $row->quota_updated_at ?: '—' }} diff --git a/tests/Feature/Business/InvoiceQuotaPageTest.php b/tests/Feature/Business/InvoiceQuotaPageTest.php index 482ef2e5..7b996b9f 100644 --- a/tests/Feature/Business/InvoiceQuotaPageTest.php +++ b/tests/Feature/Business/InvoiceQuotaPageTest.php @@ -49,7 +49,7 @@ class InvoiceQuotaPageTest extends FeatureTestCase $this->createPiaojuSnapshot('pi-1', '甲公司', 15000, '2026-11-18 13:30:07'); $this->createPiaojuSnapshot('pi-2', '乙公司', -100, '2026-11-18 13:51:43'); $this->createPiaojuSnapshot('pi-3', '丙公司', 4000, '2026-11-18 13:29:10'); - $this->createPiaojuSnapshot('pi-4', '预警公司', 500, '2026-11-18 11:29:10'); + $this->createPiaojuSnapshot('pi-4', '预警公司', 595, '2026-11-18 11:29:10'); } protected function tearDown(): void @@ -81,12 +81,12 @@ class InvoiceQuotaPageTest extends FeatureTestCase ->assertSeeText('5天额度预警') ->assertSeeText('15,000.00') ->assertSeeText('18,000.00') - ->assertSeeText('19,400.00') + ->assertSeeText('19,495.00') ->assertSeeText('甲公司') ->assertSeeText('8,500.00') ->assertSeeText('10,200.00') ->assertSeeText('日均 340.00') - ->assertSeeText('44.1 天') + ->assertSeeText('44.12 天') ->assertDontSeeText('1,500.00') ->assertSeeText('乙公司') ->assertSeeText('-100.00') @@ -95,7 +95,7 @@ class InvoiceQuotaPageTest extends FeatureTestCase ->assertSeeText('不可查看 0 · 额度不足 1') ->assertSeeText('预警公司') ->assertSeeText('3,600.00') - ->assertSeeText('4.2 天') + ->assertSeeText('4.96 天') ->assertSeeText('5天内预警') ->assertSeeText('2026-11-18 13:30') ->assertDontSeeText('历史公司')