mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-09-12 23:30:35 +00:00
refactor: deprecate int32 (#7025)
* refactor: deprecate int32 * fix(db): reject legacy user quota schemas at startup * fix(quota): enforce wallet bounds and saturating billing conversions * fix(rate-limit): keep count*duration from wrapping int64 * fix: error message
This commit is contained in:
+13
-1
@@ -175,7 +175,7 @@ func Redeem(key string, userId int) (quota int, err error) {
|
||||
if result.RowsAffected == 0 {
|
||||
return errors.New("该兑换码已被使用")
|
||||
}
|
||||
return tx.Model(&User{}).Where("id = ?", userId).Update("quota", gorm.Expr("quota + ?", redemption.Quota)).Error
|
||||
return creditTopUpQuota(tx, userId, redemption.Quota, nil)
|
||||
})
|
||||
if err != nil {
|
||||
common.SysError("redemption failed: " + err.Error())
|
||||
@@ -187,6 +187,12 @@ func Redeem(key string, userId int) (quota int, err error) {
|
||||
}
|
||||
|
||||
func (redemption *Redemption) Insert() error {
|
||||
if redemption.Quota <= 0 {
|
||||
return errors.New("redemption quota must be positive")
|
||||
}
|
||||
if err := common.ValidateWalletQuota(redemption.Quota); err != nil {
|
||||
return err
|
||||
}
|
||||
var err error
|
||||
err = DB.Create(redemption).Error
|
||||
return err
|
||||
@@ -199,6 +205,12 @@ func (redemption *Redemption) SelectUpdate() error {
|
||||
|
||||
// Update Make sure your token's fields is completed, because this will update non-zero values
|
||||
func (redemption *Redemption) Update() error {
|
||||
if redemption.Quota <= 0 {
|
||||
return errors.New("redemption quota must be positive")
|
||||
}
|
||||
if err := common.ValidateWalletQuota(redemption.Quota); err != nil {
|
||||
return err
|
||||
}
|
||||
var err error
|
||||
err = DB.Model(redemption).Select("name", "status", "quota", "redeemed_time", "expired_time").Updates(redemption).Error
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user