Skip to content

Commit

Permalink
Fix negative wallet balance
Browse files Browse the repository at this point in the history
修复钱包余额小于扣款金额时,余额会变成负数的问题
  • Loading branch information
vatebur committed May 28, 2024
1 parent 9976d9e commit afdffc1
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ func GetGroupWalletOf(sortable bool, uids ...int64) (wallets []Wallet, err error
// InsertWalletOf 更新钱包(money > 0 增加,money < 0 减少)
func InsertWalletOf(uid int64, money int) error {
lastMoney := sdb.getWalletOf(uid)
return sdb.updateWalletOf(uid, lastMoney.Money+money)
newMoney := lastMoney.Money + money
if newMoney < 0 {
newMoney = 0
}
return sdb.updateWalletOf(uid, newMoney)
}

// 获取钱包数据
Expand Down

0 comments on commit afdffc1

Please sign in to comment.