|
@@ -11,7 +11,7 @@ import (
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
-func MoneyRecharge(appid string, money int, remark string) error {
|
|
|
+func MoneyRecharge(appid string, money int, remark string, discount int) error {
|
|
|
//取出用户锁
|
|
|
lock.MainLock.Lock()
|
|
|
userLock := lock.UserLockMap[appid]
|
|
@@ -26,15 +26,25 @@ func MoneyRecharge(appid string, money int, remark string) error {
|
|
|
errs := db.GetSFISDB().Transaction(func(tx *gorm.DB) error {
|
|
|
moneyBefore := userAccount.Money
|
|
|
moneyAfter := userAccount.Money + money
|
|
|
+ var err error
|
|
|
+ //修改折扣discount
|
|
|
+ if discount != 0 {
|
|
|
+ err = tx.Exec("update user_product set discount = ? WHERE `app_id` = ?", discount, appid).Error
|
|
|
+ if err != nil {
|
|
|
+ log.Printf("appID:[%s],money:[%d] execute cost user_account error:[%v]", appid, moneyAfter, err)
|
|
|
+ tx.Rollback()
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ }
|
|
|
//充值
|
|
|
- err := tx.Exec("update user_account set money = ?,update_at = ? WHERE `app_id` = ?", moneyAfter, nowStr,appid).Error
|
|
|
+ err = tx.Exec("update user_account set money = ?,update_at = ? WHERE `app_id` = ?", moneyAfter, nowStr, appid).Error
|
|
|
if err != nil {
|
|
|
log.Printf("appID:[%s],money:[%d] execute cost user_account error:[%v]", appid, moneyAfter, err)
|
|
|
tx.Rollback()
|
|
|
return err
|
|
|
}
|
|
|
//生充值记录
|
|
|
- err = tx.Exec("insert into user_money_record (app_id,`before`,`after`,trade_money,remark,create_at) values (?,?,?,?,?,?)", appid, moneyBefore, moneyAfter, money, remark,nowStr).Error
|
|
|
+ err = tx.Exec("insert into user_money_record (app_id,`before`,`after`,trade_money,remark,create_at) values (?,?,?,?,?,?)", appid, moneyBefore, moneyAfter, money, remark, nowStr).Error
|
|
|
if err != nil {
|
|
|
log.Printf("appID:[%s],trade_money:[%d] execute insert into user_money_record error:[%v]", appid, money, err)
|
|
|
tx.Rollback()
|