mirror of
https://github.com/linux-do/new-api.git
synced 2025-11-08 07:03:42 +08:00
feat: now use token as the unit of quota (close #33)
This commit is contained in:
@@ -55,7 +55,7 @@ func Redeem(key string, tokenId int) (quota int, err error) {
|
||||
if redemption.Status != common.RedemptionCodeStatusEnabled {
|
||||
return 0, errors.New("该兑换码已被使用")
|
||||
}
|
||||
err = TopUpToken(tokenId, redemption.Quota)
|
||||
err = TopUpTokenQuota(tokenId, redemption.Quota)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
@@ -119,12 +119,12 @@ func DeleteTokenById(id int, userId int) (err error) {
|
||||
return token.Delete()
|
||||
}
|
||||
|
||||
func DecreaseTokenRemainQuotaById(id int) (err error) {
|
||||
err = DB.Model(&Token{}).Where("id = ?", id).Update("remain_quota", gorm.Expr("remain_quota - ?", 1)).Error
|
||||
func ConsumeTokenQuota(id int, quota int) (err error) {
|
||||
err = DB.Model(&Token{}).Where("id = ?", id).Update("remain_quota", gorm.Expr("remain_quota - ?", quota)).Error
|
||||
return err
|
||||
}
|
||||
|
||||
func TopUpToken(id int, times int) (err error) {
|
||||
err = DB.Model(&Token{}).Where("id = ?", id).Update("remain_quota", gorm.Expr("remain_quota + ?", times)).Error
|
||||
func TopUpTokenQuota(id int, quota int) (err error) {
|
||||
err = DB.Model(&Token{}).Where("id = ?", id).Update("remain_quota", gorm.Expr("remain_quota + ?", quota)).Error
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user