mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-10-23 03:36:30 +00:00
fix: expose account_stats_cost in usage log API and fix frontend display
Backend: - Add AccountStatsCost field to AdminUsageLog DTO - Map AccountStatsCost in UsageLogFromServiceAdmin mapper - Replace println with slog.Warn in api_key_auth_cache_impl.go Frontend: - Add account_stats_cost to AdminUsageLog TypeScript interface - Usage tooltip and table: prefer account_stats_cost when available, fallback to total_cost * multiplier (mirrors SQL COALESCE logic) - Excel export: same COALESCE fallback
This commit is contained in:
@@ -1 +1 @@
|
||||
0.1.110.24
|
||||
0.1.110.25
|
||||
|
||||
@@ -628,6 +628,7 @@ func UsageLogFromServiceAdmin(l *service.UsageLog) *AdminUsageLog {
|
||||
ModelMappingChain: l.ModelMappingChain,
|
||||
BillingTier: l.BillingTier,
|
||||
AccountRateMultiplier: l.AccountRateMultiplier,
|
||||
AccountStatsCost: l.AccountStatsCost,
|
||||
IPAddress: l.IPAddress,
|
||||
Account: AccountSummaryFromService(l.Account),
|
||||
}
|
||||
|
||||
@@ -427,6 +427,8 @@ type AdminUsageLog struct {
|
||||
|
||||
// AccountRateMultiplier 账号计费倍率快照(nil 表示按 1.0 处理)
|
||||
AccountRateMultiplier *float64 `json:"account_rate_multiplier"`
|
||||
// AccountStatsCost 自定义定价规则计算的账号统计费用(nil 表示使用默认公式)
|
||||
AccountStatsCost *float64 `json:"account_stats_cost,omitempty"`
|
||||
|
||||
// IPAddress 用户请求 IP(仅管理员可见)
|
||||
IPAddress *string `json:"ip_address,omitempty"`
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"math/rand/v2"
|
||||
"time"
|
||||
|
||||
@@ -99,7 +100,7 @@ func (s *APIKeyService) StartAuthCacheInvalidationSubscriber(ctx context.Context
|
||||
s.authCacheL1.Del(cacheKey)
|
||||
}); err != nil {
|
||||
// Log but don't fail - L1 cache will still work, just without cross-instance invalidation
|
||||
println("[Service] Warning: failed to start auth cache invalidation subscriber:", err.Error())
|
||||
slog.Warn("failed to start auth cache invalidation subscriber", "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -155,7 +155,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="row.account_rate_multiplier != null" class="mt-0.5 text-[11px] text-gray-400">
|
||||
A ${{ (row.total_cost * row.account_rate_multiplier).toFixed(6) }}
|
||||
A ${{ (row.account_stats_cost != null ? row.account_stats_cost * (row.account_rate_multiplier ?? 1) : row.total_cost * row.account_rate_multiplier).toFixed(6) }}
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -328,7 +328,7 @@
|
||||
<div class="flex items-center justify-between gap-6 border-t border-gray-700 pt-1.5">
|
||||
<span class="text-gray-400">{{ t('usage.accountBilled') }}</span>
|
||||
<span class="font-semibold text-green-400">
|
||||
${{ (((tooltipData?.total_cost || 0) * (tooltipData?.account_rate_multiplier ?? 1)) || 0).toFixed(6) }}
|
||||
${{ (tooltipData?.account_stats_cost != null ? (tooltipData.account_stats_cost * (tooltipData?.account_rate_multiplier ?? 1)) : ((tooltipData?.total_cost || 0) * (tooltipData?.account_rate_multiplier ?? 1))).toFixed(6) }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1057,6 +1057,8 @@ export interface AdminUsageLog extends UsageLog {
|
||||
|
||||
// 账号计费倍率(仅管理员可见)
|
||||
account_rate_multiplier?: number | null
|
||||
// 自定义定价规则计算的账号统计费用(nil 时使用 total_cost * multiplier)
|
||||
account_stats_cost?: number | null
|
||||
|
||||
// 用户请求 IP(仅管理员可见)
|
||||
ip_address?: string | null
|
||||
|
||||
@@ -495,7 +495,7 @@ const exportToExcel = async () => {
|
||||
log.cache_read_cost?.toFixed(6) || '0.000000', log.cache_creation_cost?.toFixed(6) || '0.000000',
|
||||
log.rate_multiplier?.toPrecision(4) || '1.00', (log.account_rate_multiplier ?? 1).toPrecision(4),
|
||||
log.total_cost?.toFixed(6) || '0.000000', log.actual_cost?.toFixed(6) || '0.000000',
|
||||
(log.total_cost * (log.account_rate_multiplier ?? 1)).toFixed(6), log.first_token_ms ?? '', log.duration_ms,
|
||||
((log.account_stats_cost ?? log.total_cost) * (log.account_rate_multiplier ?? 1)).toFixed(6), log.first_token_ms ?? '', log.duration_ms,
|
||||
log.request_id || '', log.user_agent || '', log.ip_address || ''
|
||||
])
|
||||
if (rows.length) {
|
||||
|
||||
Reference in New Issue
Block a user