diff --git a/public/js/admin.js b/public/js/admin.js index 10b9424..9fffdbf 100644 --- a/public/js/admin.js +++ b/public/js/admin.js @@ -144,8 +144,12 @@ bar.style.height = h + 'px'; var date = (p && p.date) ? String(p.date) : ''; - var count = (p && p.count != null) ? String(p.count) : '0'; - bar.title = date + ':' + count + ' 单,已付 ¥' + formatMoney(paid); + var countNum = Number(p && p.count != null ? p.count : 0); + if (!isFinite(countNum) || countNum < 0) { + countNum = 0; + } + var avg = countNum > 0 ? (paid / countNum) : 0; + bar.title = date + '|订单 ' + String(countNum) + ' 单|已付 ¥' + formatMoney(paid) + '|单均 ¥' + formatMoney(avg); el.appendChild(bar); }); diff --git a/tests/Feature/AdminDashboardTrendMiniChartTooltipShouldIncludeAvgTest.php b/tests/Feature/AdminDashboardTrendMiniChartTooltipShouldIncludeAvgTest.php new file mode 100644 index 0000000..bb564cf --- /dev/null +++ b/tests/Feature/AdminDashboardTrendMiniChartTooltipShouldIncludeAvgTest.php @@ -0,0 +1,34 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_trend_bar_tooltip_should_include_avg_paid_per_order(): void + { + $this->loginAsPlatformAdmin(); + + $this->get('/admin')->assertOk(); + + $js = (string) file_get_contents(public_path('js/admin.js')); + + // 护栏:趋势 bar 的 tooltip 应包含“单均”口径(更便于运营理解波动) + $this->assertStringContainsString("'|单均 ¥'", $js); + $this->assertStringContainsString('formatMoney(avg)', $js); + } +}