refactor(heicode-self): 返回 raw quota + quota_per_unit(与网页台同源换算)
按 HM owner 要求:客户端换算余额应与网页台完全一致。网页台用 raw_quota / quota_per_unit(web renderQuotaCompat,quotaPerUnit 默认 500000、 系统设置可配)。原 /api/heicode/self 预先除好(quotaToDisplayUnit)反而与网页台 不一致、并迫使客户端 ×500000 回推。 改为返回原始 quota/used_quota + quota_per_unit + quota_display_type, 客户端直接 quota / quota_per_unit 即可,和网页台同一公式,去掉所有缩放 hack。 移除不再使用的 quotaToDisplayUnit。go build/vet 通过。 影响面:仅 Manager(HM),服务桌面客户端余额展示(响应字段语义调整:quota 由 展示值改为原始值,新增 quota_per_unit)。需客户端同步按 quota/quota_per_unit 换算。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -11,25 +11,10 @@ import (
|
||||
"github.com/heicode/manager/setting/operation_setting"
|
||||
)
|
||||
|
||||
// quotaToDisplayUnit converts a raw quota integer (DB unit) to the
|
||||
// site-configured display unit (USD / CNY / tokens). Mirrors the
|
||||
// conversion in billing.go so the desktop "balance pill" shows the
|
||||
// same number the user sees in the web dashboard.
|
||||
func quotaToDisplayUnit(raw int) float64 {
|
||||
amount := float64(raw)
|
||||
switch operation_setting.GetQuotaDisplayType() {
|
||||
case operation_setting.QuotaDisplayTypeCNY:
|
||||
return amount / common.QuotaPerUnit * operation_setting.USDExchangeRate
|
||||
case operation_setting.QuotaDisplayTypeTokens:
|
||||
return amount
|
||||
default:
|
||||
return amount / common.QuotaPerUnit
|
||||
}
|
||||
}
|
||||
|
||||
// quotaDisplayUnitLabel names the unit quotaToDisplayUnit produced, so the
|
||||
// desktop client can label the balance directly and must NOT divide the
|
||||
// already-converted quota again.
|
||||
// quotaDisplayUnitLabel names the unit the raw quota is denominated in, so the
|
||||
// desktop client converts exactly like the web dashboard:
|
||||
// usd = quota / quota_per_unit (mirrors web renderQuotaCompat)
|
||||
// Returns USD / CNY / tokens.
|
||||
func quotaDisplayUnitLabel() string {
|
||||
switch operation_setting.GetQuotaDisplayType() {
|
||||
case operation_setting.QuotaDisplayTypeCNY:
|
||||
@@ -82,8 +67,9 @@ func GetHeicodeSelf(c *gin.Context) {
|
||||
"display_name": user.DisplayName,
|
||||
"group": user.Group,
|
||||
"role": user.Role,
|
||||
"quota": quotaToDisplayUnit(user.Quota),
|
||||
"used_quota": quotaToDisplayUnit(user.UsedQuota),
|
||||
"quota": user.Quota,
|
||||
"used_quota": user.UsedQuota,
|
||||
"quota_per_unit": common.QuotaPerUnit,
|
||||
"quota_display_type": quotaDisplayUnitLabel(),
|
||||
"request_count": user.RequestCount,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user