From bd25442109b3511c54ba25463a1c4e3092ded737 Mon Sep 17 00:00:00 2001 From: zhora Date: Tue, 23 Sep 2025 11:37:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E4=BB=98=E6=9D=83=E9=87=8D=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=EF=BC=8C=E4=B8=B4=E6=97=B6=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- call/config.go | 73 ++++++++++++++++++++++++++++++++++++ call/pay.go | 2 +- common/player.go | 1 + common/redis_keys.go | 5 +++ modules/gate/agent.go | 4 +- modules/pay/handler.go | 21 ++++++++++- modules/pay/values/values.go | 4 +- 7 files changed, 105 insertions(+), 5 deletions(-) diff --git a/call/config.go b/call/config.go index 30e61c8..0deb95e 100644 --- a/call/config.go +++ b/call/config.go @@ -2585,6 +2585,79 @@ func LoadConfigRtpControl() (err error) { log.Error("err:%v", err) return err } + //sort.Slice(result, func(i, j int) bool { + // a, b := result[i], result[j] + // + // // 处理RechargeDay:-1排到最后 + // if a.RechargeDay == -1 && b.RechargeDay != -1 { + // return false // a排在b后面 + // } + // if a.RechargeDay != -1 && b.RechargeDay == -1 { + // return true // a排在b前面 + // } + // if a.RechargeDay == -1 && b.RechargeDay == -1 { + // // 都是-1,继续比较下一个字段 + // if a.WithdrawPer == -1 && b.WithdrawPer != -1 { + // return false + // } + // if a.WithdrawPer != -1 && b.WithdrawPer == -1 { + // return true + // } + // if a.WithdrawPer == -1 && b.WithdrawPer == -1 { + // if a.PersonalRtp == -1 && b.PersonalRtp != -1 { + // return false + // } + // if a.PersonalRtp != -1 && b.PersonalRtp == -1 { + // return true + // } + // return a.PersonalRtp < b.PersonalRtp + // } else { + // if a.WithdrawPer != b.WithdrawPer { + // return a.WithdrawPer < b.WithdrawPer + // } + // } + // } else { + // if a.RechargeDay != b.RechargeDay { + // return a.RechargeDay < b.RechargeDay + // } + // } + // + // // 处理WithdrawPer:-1排到最后 + // if a.WithdrawPer == -1 && b.WithdrawPer != -1 { + // return false + // } + // if a.WithdrawPer != -1 && b.WithdrawPer == -1 { + // return true + // } + // if a.WithdrawPer == -1 && b.WithdrawPer == -1 { + // // 都是-1,继续比较下一个字段 + // if a.PersonalRtp == -1 && b.PersonalRtp != -1 { + // return false + // } + // if a.PersonalRtp != -1 && b.PersonalRtp == -1 { + // return true + // } + // return a.PersonalRtp < b.PersonalRtp + // } else { + // if a.WithdrawPer != b.WithdrawPer { + // return a.WithdrawPer < b.WithdrawPer + // } + // } + // + // // 处理PersonalRtp:-1排到最后 + // if a.PersonalRtp == -1 && b.PersonalRtp != -1 { + // return false + // } + // if a.PersonalRtp != -1 && b.PersonalRtp == -1 { + // return true + // } + // if a.PersonalRtp == -1 && b.PersonalRtp == -1 { + // // 都是-1,相等 + // return false + // } else { + // return a.PersonalRtp < b.PersonalRtp + // } + //}) configRtpControl = result return nil } diff --git a/call/pay.go b/call/pay.go index c574a78..e625814 100644 --- a/call/pay.go +++ b/call/pay.go @@ -112,7 +112,7 @@ func RechargeCallback(r *common.RechargeOrder, success bool, payAccount, extra s ro := &common.RechargeOrder{OrderID: r.OrderID, Status: common.StatusROrderCreate} return db.Mysql().Update(ro, &common.RechargeOrder{Status: common.StatusROrderFail}) } - + db.Redis().Delkey(common.GetRedisKeyUserPay(r.PayChannel, r.UID, int(r.Amount/common.DecimalDigits))) uid := r.UID re := GetRechargeInfo(uid) CheckUserBet(uid, r.CurrencyType) diff --git a/common/player.go b/common/player.go index f6723ba..ce95fd7 100644 --- a/common/player.go +++ b/common/player.go @@ -331,6 +331,7 @@ type ConfigRtpControl struct { ID int `gorm:"column:id;type:int(11) AUTO_INCREMENT;primary_key"` RechargeDay int `gorm:"column:recharge_day;type:bigint(20);comment:充值天数" web:"recharge_day"` WithdrawPer int `gorm:"column:withdraw_per;type:bigint(20);comment:提存比" web:"withdraw_per"` + PersonalRtp int `gorm:"column:personal_rtp;type:bigint(20);comment:个人rtp" web:"personal_rtp"` Rtp int `gorm:"column:rtp;type:int(11);comment:rtp" web:"rtp"` UpdatedBase } diff --git a/common/redis_keys.go b/common/redis_keys.go index 2c8041f..6895f99 100644 --- a/common/redis_keys.go +++ b/common/redis_keys.go @@ -52,6 +52,7 @@ const ( RedisKeyPdd = "pdd" RedisKeyShare = "share" RedisKeyWeekCard = "week_card" + RedisKeyUserPay = "user_pay" ) const ( @@ -219,3 +220,7 @@ func GetRedisKeyShare(uid int) string { func GetRedisKeyWeekCard(uid int) string { return fmt.Sprintf("%v:%v", RedisKeyWeekCard, uid) } + +func GetRedisKeyUserPay(payChannelId, uid, amount int) string { + return fmt.Sprintf("%v:%d:%d:%v", RedisKeyUserPay, payChannelId, amount, uid) +} diff --git a/modules/gate/agent.go b/modules/gate/agent.go index 36350eb..8d35d8c 100644 --- a/modules/gate/agent.go +++ b/modules/gate/agent.go @@ -295,7 +295,7 @@ func (a *agent) ReadLoop() { // 第一步拿到数据包长度 length, err := a.readInt(2) if err != nil { - // log.Error("err:%v", err) + // log.Error("read int err:%v", err) return } if length > a.gate.Options().BufSize { @@ -331,7 +331,7 @@ func (a *agent) ReadLoop() { // 第四步拿到uid _, err = a.readInt(4) if err != nil { - // log.Error("err:%v", err) + // log.Error("get uid err:%v", err) return } // log.Debug("uid:%v", uid) diff --git a/modules/pay/handler.go b/modules/pay/handler.go index 252821e..cc6f3cf 100644 --- a/modules/pay/handler.go +++ b/modules/pay/handler.go @@ -28,17 +28,34 @@ func Recharge(req *pb.InnerRechargeReq) (ret []byte, err error) { // } else { // payWay = values.ChoosePayWay(int(req.UID), int(req.Channel), req.Amount) // } + var isReplace bool if req.Channel == 0 { + var weightChannel uint32 for _, v := range call.GetConfigPayChannels() { if req.Amount*common.DecimalDigits <= v.PayUp && req.Amount*common.DecimalDigits >= v.PayDown && v.CurrencyType == common.CurrencyINR { - req.Channel = uint32(v.ChannelID) + weightChannel = uint32(v.ChannelID) break } } + for _, v := range call.GetConfigPayChannels() { + if req.Amount*common.DecimalDigits <= v.PayUp && req.Amount*common.DecimalDigits >= v.PayDown && v.CurrencyType == common.CurrencyINR { + if !db.Redis().Lock(common.GetRedisKeyUserPay(v.ChannelID, int(req.UID), int(req.Amount)), 2*time.Minute) { + continue + } + if weightChannel != uint32(v.ChannelID) { + log.Debug("recharge, replace pay channel, %v:%v", req.UID, v.ChannelID) + isReplace = true + } + weightChannel = uint32(v.ChannelID) + break + } + } + req.Channel = weightChannel } if req.Channel == 0 { log.Error("get channel err, is 0") } + payWay = values.PayWay(req.Channel) base := base.NewRechargeBase(req) allpay.NewSub(base, int(req.Channel)) start := time.Now() @@ -57,6 +74,8 @@ func Recharge(req *pb.InnerRechargeReq) (ret []byte, err error) { } if err != nil { values.PayFail(payWay) + } else if isReplace { + values.PaySuccess(payWay) } return } diff --git a/modules/pay/values/values.go b/modules/pay/values/values.go index 0db201d..a89a543 100644 --- a/modules/pay/values/values.go +++ b/modules/pay/values/values.go @@ -545,7 +545,9 @@ func AddWithdrawChannel(p int, amount int) { func AddPayChannel(p int, amount int) { log.Debug("update pay per, %d:%d", p, amount) if err := db.Mysql().C().Model(&common.ConfigPayChannels{}).Where("channel_id = ? and pay_per > 0 ", p). - Updates(map[string]interface{}{"pay_per": gorm.Expr("pay_per + ?", amount)}).Error; err != nil { + Updates(map[string]interface{}{ + "pay_per": gorm.Expr("CASE WHEN pay_per + ? < 1 THEN 1 ELSE pay_per + ? END", amount, amount), + }).Error; err != nil { log.Error("err:%v", err) } }