Skip to content

Commit

Permalink
fix: wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiama committed May 30, 2024
1 parent ab22138 commit 71c23d2
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ func GetGroupWalletOf(sortable bool, uids ...int64) (wallets []Wallet, err error
}

// InsertWalletOf 更新钱包(money > 0 增加,money < 0 减少)
func (sql *Storage) InsertWalletOf(uid int64, money int) error {
sql.Lock()
defer sql.Unlock()
func InsertWalletOf(uid int64, money int) error {
sdb.Lock()
defer sdb.Unlock()
lastMoney := sdb.getWalletOf(uid)
newMoney := lastMoney.Money + money
if newMoney < 0 {
Expand All @@ -84,7 +84,7 @@ func (sql *Storage) InsertWalletOf(uid int64, money int) error {
return sdb.updateWalletOf(uid, newMoney)
}

// 获取钱包数据
// 获取钱包数据 no lock
func (sql *Storage) getWalletOf(uid int64) (wallet Wallet) {
uidstr := strconv.FormatInt(uid, 10)
_ = sql.db.Find("storage", &wallet, "where uid is "+uidstr)
Expand Down Expand Up @@ -112,7 +112,7 @@ func (sql *Storage) getGroupWalletOf(sortable bool, uids ...int64) (wallets []Wa
return
}

// 更新钱包
// 更新钱包 no lock
func (sql *Storage) updateWalletOf(uid int64, money int) (err error) {
return sql.db.Insert("storage", &Wallet{
UID: uid,
Expand Down

0 comments on commit 71c23d2

Please sign in to comment.