From 4139a7036fd8258875103aa681676dbf96a4c73d Mon Sep 17 00:00:00 2001 From: JustSong Date: Sat, 15 Jul 2023 23:01:54 +0800 Subject: [PATCH] chore: make subscription api compatible with official api --- controller/billing.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/controller/billing.go b/controller/billing.go index a45253ab..2ef2d99c 100644 --- a/controller/billing.go +++ b/controller/billing.go @@ -7,16 +7,19 @@ import ( ) func GetSubscription(c *gin.Context) { - var quota int + var remainQuota int + var usedQuota int var err error var token *model.Token if common.DisplayTokenStatEnabled { tokenId := c.GetInt("token_id") token, err = model.GetTokenById(tokenId) - quota = token.RemainQuota + remainQuota = token.RemainQuota + usedQuota = token.UsedQuota } else { userId := c.GetInt("id") - quota, err = model.GetUserQuota(userId) + remainQuota, err = model.GetUserQuota(userId) + usedQuota, err = model.GetUserUsedQuota(userId) } if err != nil { openAIError := OpenAIError{ @@ -28,6 +31,7 @@ func GetSubscription(c *gin.Context) { }) return } + quota := remainQuota + usedQuota amount := float64(quota) if common.DisplayInCurrencyEnabled { amount /= common.QuotaPerUnit