|
@@ -7,16 +7,19 @@ import (
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
func GetSubscription(c *gin.Context) {
|
|
func GetSubscription(c *gin.Context) {
|
|
|
- var quota int
|
|
|
|
|
|
|
+ var remainQuota int
|
|
|
|
|
+ var usedQuota int
|
|
|
var err error
|
|
var err error
|
|
|
var token *model.Token
|
|
var token *model.Token
|
|
|
if common.DisplayTokenStatEnabled {
|
|
if common.DisplayTokenStatEnabled {
|
|
|
tokenId := c.GetInt("token_id")
|
|
tokenId := c.GetInt("token_id")
|
|
|
token, err = model.GetTokenById(tokenId)
|
|
token, err = model.GetTokenById(tokenId)
|
|
|
- quota = token.RemainQuota
|
|
|
|
|
|
|
+ remainQuota = token.RemainQuota
|
|
|
|
|
+ usedQuota = token.UsedQuota
|
|
|
} else {
|
|
} else {
|
|
|
userId := c.GetInt("id")
|
|
userId := c.GetInt("id")
|
|
|
- quota, err = model.GetUserQuota(userId)
|
|
|
|
|
|
|
+ remainQuota, err = model.GetUserQuota(userId)
|
|
|
|
|
+ usedQuota, err = model.GetUserUsedQuota(userId)
|
|
|
}
|
|
}
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
openAIError := OpenAIError{
|
|
openAIError := OpenAIError{
|
|
@@ -28,6 +31,7 @@ func GetSubscription(c *gin.Context) {
|
|
|
})
|
|
})
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
+ quota := remainQuota + usedQuota
|
|
|
amount := float64(quota)
|
|
amount := float64(quota)
|
|
|
if common.DisplayInCurrencyEnabled {
|
|
if common.DisplayInCurrencyEnabled {
|
|
|
amount /= common.QuotaPerUnit
|
|
amount /= common.QuotaPerUnit
|