chore(admin-dashboard): enrich trend bar tooltip with avg paid

This commit is contained in:
萝卜
2026-03-16 13:42:51 +08:00
parent ca05122c2c
commit 0f07fe7c8b
2 changed files with 40 additions and 2 deletions

View File

@@ -144,8 +144,12 @@
bar.style.height = h + 'px'; bar.style.height = h + 'px';
var date = (p && p.date) ? String(p.date) : ''; var date = (p && p.date) ? String(p.date) : '';
var count = (p && p.count != null) ? String(p.count) : '0'; var countNum = Number(p && p.count != null ? p.count : 0);
bar.title = date + '' + count + ' 单,已付 ¥' + formatMoney(paid); 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); el.appendChild(bar);
}); });

View File

@@ -0,0 +1,34 @@
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AdminDashboardTrendMiniChartTooltipShouldIncludeAvgTest 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_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);
}
}