| 1315 | } |
| 1316 | |
| 1317 | func DecreaseUserQuota(id int, quota int, db bool) (err error) { |
| 1318 | if quota < 0 { |
| 1319 | return errors.New("quota 不能为负数!") |
| 1320 | } |
| 1321 | gopool.Go(func() { |
| 1322 | err := cacheDecrUserQuota(id, int64(quota)) |
| 1323 | if err != nil { |
| 1324 | common.SysLog("failed to decrease user quota: " + err.Error()) |
| 1325 | } |
| 1326 | }) |
| 1327 | if !db && common.BatchUpdateEnabled { |
| 1328 | addNewRecord(BatchUpdateTypeUserQuota, id, -quota) |
| 1329 | return nil |
| 1330 | } |
| 1331 | return decreaseUserQuota(id, quota) |
| 1332 | } |
| 1333 | |
| 1334 | func decreaseUserQuota(id int, quota int) (err error) { |
| 1335 | err = DB.Model(&User{}).Where("id = ?", id).Update("quota", gorm.Expr("quota - ?", quota)).Error |