fix: 发票额度预警使用精确支撑天数 (#1240)

使用未舍入的可支撑天数判断 5 天阈值,并以两位小数展示。
This commit is contained in:
linchong 2026-11-18 16:52:10 +08:00
parent 5cf63f793a
commit 29e2779c7e
3 changed files with 15 additions and 13 deletions

View File

@ -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 = '未匹配';

View File

@ -252,7 +252,7 @@
@endif
</td>
<td @class(['is-number', 'invoice-quota-coverage', 'is-warning' => $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) . ' 天' : '—' }}
</td>
<td>{{ $row->quota_updated_at ?: '—' }}</td>
<td>

View File

@ -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('历史公司')