|
@@ -1,11 +1,9 @@
|
|
package service
|
|
package service
|
|
|
|
|
|
import (
|
|
import (
|
|
- "sfbase/global"
|
|
|
|
"sfis/db"
|
|
"sfis/db"
|
|
"sfis/lock"
|
|
"sfis/lock"
|
|
"sfis/model"
|
|
"sfis/model"
|
|
- "sfis/model/response"
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
|
@@ -13,11 +11,10 @@ import (
|
|
"sfis/utils"
|
|
"sfis/utils"
|
|
"time"
|
|
"time"
|
|
|
|
|
|
- "go.uber.org/zap"
|
|
|
|
"gorm.io/gorm"
|
|
"gorm.io/gorm"
|
|
)
|
|
)
|
|
|
|
|
|
-func MoneyRecharge(appid string, money int, context *gin.Context) {
|
|
|
|
|
|
+func MoneyRecharge(appid string, money int, context *gin.Context) error {
|
|
//取出用户锁
|
|
//取出用户锁
|
|
lock.MainLock.Lock()
|
|
lock.MainLock.Lock()
|
|
userLock := lock.UserLockMap[appid]
|
|
userLock := lock.UserLockMap[appid]
|
|
@@ -46,15 +43,10 @@ func MoneyRecharge(appid string, money int, context *gin.Context) {
|
|
}
|
|
}
|
|
return nil
|
|
return nil
|
|
})
|
|
})
|
|
- if errs == nil {
|
|
|
|
- response.Ok(context)
|
|
|
|
- } else {
|
|
|
|
- global.Logger.Error("数据库操作失败", zap.Any("error:", errs))
|
|
|
|
- response.FailWithMessage("充值失败", context)
|
|
|
|
- }
|
|
|
|
|
|
+ return errs
|
|
}
|
|
}
|
|
|
|
|
|
-func ProductRecharge(appid string, productId, rechargeNum int, endTime string, context *gin.Context) {
|
|
|
|
|
|
+func ProductRecharge(appid string, productId, rechargeNum int, endTime string, context *gin.Context) error {
|
|
//取出用户锁
|
|
//取出用户锁
|
|
lock.MainLock.Lock()
|
|
lock.MainLock.Lock()
|
|
userLock := lock.UserLockMap[appid]
|
|
userLock := lock.UserLockMap[appid]
|
|
@@ -96,7 +88,7 @@ func ProductRecharge(appid string, productId, rechargeNum int, endTime string, c
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- //生充值记录
|
|
|
|
|
|
+ //生购买记录
|
|
err = tx.Exec("insert into user_buy_record (app_id,product_id,user_product_id,`before`,`after`,trade_money,buy_type,history_unit_price) values (?,?,?,?,?,?,?,?)", appid, productId, userProduct.ID, before, after, product.UnitPrice*rechargeNum, 1, product.UnitPrice).Error
|
|
err = tx.Exec("insert into user_buy_record (app_id,product_id,user_product_id,`before`,`after`,trade_money,buy_type,history_unit_price) values (?,?,?,?,?,?,?,?)", appid, productId, userProduct.ID, before, after, product.UnitPrice*rechargeNum, 1, product.UnitPrice).Error
|
|
if err != nil {
|
|
if err != nil {
|
|
log.Printf("appID:[%s],product_id:[%d],user_product_id:[%d],after:[%d],trade_money:[%d] execute insert into user_buy_record error:[%v]", appid, productId, userProduct.ID, after, product.UnitPrice*rechargeNum, err)
|
|
log.Printf("appID:[%s],product_id:[%d],user_product_id:[%d],after:[%d],trade_money:[%d] execute insert into user_buy_record error:[%v]", appid, productId, userProduct.ID, after, product.UnitPrice*rechargeNum, err)
|
|
@@ -105,10 +97,5 @@ func ProductRecharge(appid string, productId, rechargeNum int, endTime string, c
|
|
}
|
|
}
|
|
return nil
|
|
return nil
|
|
})
|
|
})
|
|
- if errs == nil {
|
|
|
|
- response.Ok(context)
|
|
|
|
- } else {
|
|
|
|
- global.Logger.Error("数据库操作失败", zap.Any("error:", errs))
|
|
|
|
- response.FailWithMessage("充值失败", context)
|
|
|
|
- }
|
|
|
|
|
|
+ return errs
|
|
}
|
|
}
|