| 1386 | } |
| 1387 | |
| 1388 | func DecreaseUserQuota(id int, quota int, db bool) (err error) { |
| 1389 | if quota < 0 { |
| 1390 | return errors.New("quota 不能为负数!") |
| 1391 | } |
| 1392 | gopool.Go(func() { |
| 1393 | err := cacheDecrUserQuota(id, int64(quota)) |
| 1394 | if err != nil { |
| 1395 | common.SysLog("failed to decrease user quota: " + err.Error()) |
| 1396 | } |
| 1397 | }) |
| 1398 | if !db && common.BatchUpdateEnabled { |
| 1399 | addNewRecord(BatchUpdateTypeUserQuota, id, -quota) |
| 1400 | return nil |
| 1401 | } |
| 1402 | return decreaseUserQuota(id, quota) |
| 1403 | } |
| 1404 | |
| 1405 | func decreaseUserQuota(id int, quota int) (err error) { |
| 1406 | err = DB.Model(&User{}).Where("id = ?", id).Update("quota", gorm.Expr("quota - ?", quota)).Error |