|
@@ -32,12 +32,12 @@ func DealUserAmount(session *xorm.Session, req md.DealUserAmount) (err error) { |
|
|
|
|
|
|
|
|
//2、计算&&组装数据 |
|
|
//2、计算&&组装数据 |
|
|
now := time.Now() |
|
|
now := time.Now() |
|
|
userAmount, err := GetUserAmount(session, req.Mid, req.Uid) |
|
|
|
|
|
|
|
|
userAmount, err := GetUserAmount(session, req.Mid, req.Uid, true) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return err |
|
|
return err |
|
|
} |
|
|
} |
|
|
userAmountValue := decimal.NewFromFloat(zhios_order_relate_utils.StrToFloat64(userAmount)) |
|
|
userAmountValue := decimal.NewFromFloat(zhios_order_relate_utils.StrToFloat64(userAmount)) |
|
|
amountValue := decimal.NewFromFloat(req.Amount).RoundFloor(8) |
|
|
|
|
|
|
|
|
amountValue := decimal.NewFromFloat(req.Amount).RoundFloor(4) |
|
|
|
|
|
|
|
|
var finUserFlow = model.FinUserFlow{ |
|
|
var finUserFlow = model.FinUserFlow{ |
|
|
Uid: req.Uid, |
|
|
Uid: req.Uid, |
|
@@ -55,10 +55,10 @@ func DealUserAmount(session *xorm.Session, req md.DealUserAmount) (err error) { |
|
|
} |
|
|
} |
|
|
if req.Kind == "add" { |
|
|
if req.Kind == "add" { |
|
|
finUserFlow.Type = 0 |
|
|
finUserFlow.Type = 0 |
|
|
finUserFlow.AfterAmount = userAmountValue.Add(amountValue).RoundFloor(8).String() |
|
|
|
|
|
|
|
|
finUserFlow.AfterAmount = userAmountValue.Add(amountValue).RoundFloor(4).String() |
|
|
} else if req.Kind == "sub" { |
|
|
} else if req.Kind == "sub" { |
|
|
finUserFlow.Type = 1 |
|
|
finUserFlow.Type = 1 |
|
|
finUserFlow.AfterAmount = userAmountValue.Sub(amountValue).RoundFloor(8).String() |
|
|
|
|
|
|
|
|
finUserFlow.AfterAmount = userAmountValue.Sub(amountValue).RoundFloor(4).String() |
|
|
} else { |
|
|
} else { |
|
|
err = errors.New("错误的kind类型") |
|
|
err = errors.New("错误的kind类型") |
|
|
return err |
|
|
return err |
|
@@ -89,6 +89,7 @@ func DealUserAmount(session *xorm.Session, req md.DealUserAmount) (err error) { |
|
|
|
|
|
|
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func DealUserAmountNew(session *xorm.Session, req md.DealUserAmount) (err error) { |
|
|
func DealUserAmountNew(session *xorm.Session, req md.DealUserAmount) (err error) { |
|
|
if req.Amount < 0 { |
|
|
if req.Amount < 0 { |
|
|
req.Amount = 0 |
|
|
req.Amount = 0 |
|
@@ -104,7 +105,7 @@ func DealUserAmountNew(session *xorm.Session, req md.DealUserAmount) (err error) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//2、计算&&组装数据 |
|
|
//2、计算&&组装数据 |
|
|
userAmount, err := GetUserAmount(session, req.Mid, req.Uid) |
|
|
|
|
|
|
|
|
userAmount, err := GetUserAmount(session, req.Mid, req.Uid, false) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return err |
|
|
return err |
|
|
} |
|
|
} |
|
@@ -127,13 +128,14 @@ func DealUserAmountNew(session *xorm.Session, req md.DealUserAmount) (err error) |
|
|
|
|
|
|
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func DealUserAmountFlow(session *xorm.Session, req md.DealUserAmount) (err error) { |
|
|
func DealUserAmountFlow(session *xorm.Session, req md.DealUserAmount) (err error) { |
|
|
if req.Amount < 0 { |
|
|
if req.Amount < 0 { |
|
|
req.Amount = 0 |
|
|
req.Amount = 0 |
|
|
} |
|
|
} |
|
|
//2、计算&&组装数据 |
|
|
//2、计算&&组装数据 |
|
|
now := time.Now() |
|
|
now := time.Now() |
|
|
userAmount, err := GetUserAmount(session, req.Mid, req.Uid) |
|
|
|
|
|
|
|
|
userAmount, err := GetUserAmount(session, req.Mid, req.Uid, false) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return err |
|
|
return err |
|
|
} |
|
|
} |
|
@@ -178,25 +180,36 @@ func DealUserAmountFlow(session *xorm.Session, req md.DealUserAmount) (err error |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// GetUserAmount 获取用户余额 |
|
|
// GetUserAmount 获取用户余额 |
|
|
func GetUserAmount(session *xorm.Session, masterId string, uid int) (amount string, err error) { |
|
|
|
|
|
redisKey := fmt.Sprintf(md.UserAmountRedisKey, masterId, uid) |
|
|
|
|
|
amount, err = cache.GetString(redisKey) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
if err.Error() == "redigo: nil returned" { |
|
|
|
|
|
userAmount, err := db.UserProfileFindByIDWithSession(session, uid) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return amount, err |
|
|
|
|
|
} |
|
|
|
|
|
if userAmount == nil { |
|
|
|
|
|
amount = "0" |
|
|
|
|
|
} else { |
|
|
|
|
|
amount = userAmount.FinValid |
|
|
|
|
|
} |
|
|
|
|
|
//将获取到的余额值缓存至redis |
|
|
|
|
|
_ = SetCacheUserAmount(session, masterId, amount, uid, false) |
|
|
|
|
|
return amount, nil |
|
|
|
|
|
|
|
|
func GetUserAmount(session *xorm.Session, masterId string, uid int, isForceUpdate bool) (amount string, err error) { |
|
|
|
|
|
if isForceUpdate { |
|
|
|
|
|
userAmount, err1 := db.UserProfileFindByIDWithSession(session, uid) |
|
|
|
|
|
if err1 != nil { |
|
|
|
|
|
return amount, err1 |
|
|
|
|
|
} |
|
|
|
|
|
if userAmount == nil { |
|
|
|
|
|
amount = "0" |
|
|
|
|
|
} else { |
|
|
|
|
|
amount = userAmount.FinValid |
|
|
|
|
|
} |
|
|
|
|
|
//将获取到的余额值缓存至redis |
|
|
|
|
|
_ = SetCacheUserAmount(session, masterId, amount, uid, false) |
|
|
|
|
|
} else { |
|
|
|
|
|
redisKey := fmt.Sprintf(md.UserAmountRedisKey, masterId, uid) |
|
|
|
|
|
amount, err = cache.GetString(redisKey) |
|
|
|
|
|
if err != nil && err.Error() != "redigo: nil returned" { |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
userAmount, err1 := db.UserProfileFindByIDWithSession(session, uid) |
|
|
|
|
|
if err1 != nil { |
|
|
|
|
|
return amount, err1 |
|
|
|
|
|
} |
|
|
|
|
|
if userAmount == nil { |
|
|
|
|
|
amount = "0" |
|
|
|
|
|
} else { |
|
|
|
|
|
amount = userAmount.FinValid |
|
|
} |
|
|
} |
|
|
return amount, err |
|
|
|
|
|
|
|
|
//将获取到的余额值缓存至redis |
|
|
|
|
|
_ = SetCacheUserAmount(session, masterId, amount, uid, false) |
|
|
} |
|
|
} |
|
|
return amount, nil |
|
|
return amount, nil |
|
|
} |
|
|
} |
|
@@ -215,7 +228,7 @@ func SetCacheUserAmount(session *xorm.Session, masterId, amount string, uid int, |
|
|
} |
|
|
} |
|
|
//_, err := cache.Set(redisKey, int64(utils.StrToFloat64(amount))) |
|
|
//_, err := cache.Set(redisKey, int64(utils.StrToFloat64(amount))) |
|
|
//TODO::默认缓存1小时 (先调整为 2 min) |
|
|
//TODO::默认缓存1小时 (先调整为 2 min) |
|
|
_, err := cache.SetEx(redisKey, zhios_order_relate_utils.StrToFloat64(amount), 60*1) |
|
|
|
|
|
|
|
|
_, err := cache.SetEx(redisKey, zhios_order_relate_utils.StrToFloat64(amount), 60*0.5) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return err |
|
|
return err |
|
|
} |
|
|
} |
|
|