瀏覽代碼

update 一个圈圈

master
DengBiao 7 月之前
父節點
當前提交
683321c883
共有 2 個文件被更改,包括 39 次插入26 次删除
  1. +1
    -1
      md/fin_user_flow.go
  2. +38
    -25
      svc/svc_deal_user_amount.go

+ 1
- 1
md/fin_user_flow.go 查看文件

@@ -31,7 +31,7 @@ const (
)

const DealUserAmountRequestIdPrefix = "%s:deal_user_amount:%d"
const UserAmountRedisKey = "%s:rule_user_amount:%d"
const UserAmountRedisKey = "%s:rule_cache_user_amount:%d"

type DealIntegralReleaseInterpositionUserAmountReq struct {
Kind string `json:"kind"`


+ 38
- 25
svc/svc_deal_user_amount.go 查看文件

@@ -32,12 +32,12 @@ func DealUserAmount(session *xorm.Session, req md.DealUserAmount) (err error) {

//2、计算&&组装数据
now := time.Now()
userAmount, err := GetUserAmount(session, req.Mid, req.Uid)
userAmount, err := GetUserAmount(session, req.Mid, req.Uid, true)
if err != nil {
return err
}
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{
Uid: req.Uid,
@@ -55,10 +55,10 @@ func DealUserAmount(session *xorm.Session, req md.DealUserAmount) (err error) {
}
if req.Kind == "add" {
finUserFlow.Type = 0
finUserFlow.AfterAmount = userAmountValue.Add(amountValue).RoundFloor(8).String()
finUserFlow.AfterAmount = userAmountValue.Add(amountValue).RoundFloor(4).String()
} else if req.Kind == "sub" {
finUserFlow.Type = 1
finUserFlow.AfterAmount = userAmountValue.Sub(amountValue).RoundFloor(8).String()
finUserFlow.AfterAmount = userAmountValue.Sub(amountValue).RoundFloor(4).String()
} else {
err = errors.New("错误的kind类型")
return err
@@ -89,6 +89,7 @@ func DealUserAmount(session *xorm.Session, req md.DealUserAmount) (err error) {

return nil
}

func DealUserAmountNew(session *xorm.Session, req md.DealUserAmount) (err error) {
if req.Amount < 0 {
req.Amount = 0
@@ -104,7 +105,7 @@ func DealUserAmountNew(session *xorm.Session, req md.DealUserAmount) (err error)
}

//2、计算&&组装数据
userAmount, err := GetUserAmount(session, req.Mid, req.Uid)
userAmount, err := GetUserAmount(session, req.Mid, req.Uid, false)
if err != nil {
return err
}
@@ -127,13 +128,14 @@ func DealUserAmountNew(session *xorm.Session, req md.DealUserAmount) (err error)

return nil
}

func DealUserAmountFlow(session *xorm.Session, req md.DealUserAmount) (err error) {
if req.Amount < 0 {
req.Amount = 0
}
//2、计算&&组装数据
now := time.Now()
userAmount, err := GetUserAmount(session, req.Mid, req.Uid)
userAmount, err := GetUserAmount(session, req.Mid, req.Uid, false)
if err != nil {
return err
}
@@ -178,25 +180,36 @@ func DealUserAmountFlow(session *xorm.Session, req md.DealUserAmount) (err error
}

// 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
}
@@ -215,7 +228,7 @@ func SetCacheUserAmount(session *xorm.Session, masterId, amount string, uid int,
}
//_, err := cache.Set(redisKey, int64(utils.StrToFloat64(amount)))
//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 {
return err
}


Loading…
取消
儲存