Update wallet.go

pull/361/head
overBaker 2 years ago
parent 69d6bc72ee
commit 07c51fc9cf

@ -71,16 +71,21 @@ func (d *walletServant) HandleRechargeSuccess(recharge *core.WalletRecharge, tra
return d.db.Transaction(func(tx *gorm.DB) error {
//获取当前时间戳
currentTimestamp := time.Now().Unix()
balance := user.Balance
newBalance := balance + recharge.Amount*864
if balance < currentTimestamp {
balance = currentTimestamp
if err := tx.Model(user).Update("balance", newBalance).Error; err != nil {
// 返回任何错误都会回滚事务
return err
}
} else {
// 扣除金额
if err := tx.Model(user).Update("balance", gorm.Expr("balance + ?", recharge.Amount*864)).Error; err != nil {
// 返回任何错误都会回滚事务
return err
}
}
// 扣除金额
if err := tx.Model(user).Update("balance", gorm.Expr("balance + ?", recharge.Amount*864)).Error; err != nil {
// 返回任何错误都会回滚事务
return err
}
balance := user.Balance
// 新增账单
if err := tx.Create(&dbr.WalletStatement{
UserID: user.ID,

Loading…
Cancel
Save