From 92bcd3e3157a800c11ec6169ad90bf9d95693587 Mon Sep 17 00:00:00 2001 From: zhora Date: Sat, 25 Oct 2025 10:05:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A8=E6=80=81=E8=B0=83=E6=95=B4sn=20rtp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- call/config.go | 6 +++ modules/web/providers/sn/handler.go | 77 +++++++++++++++++++++++------ 2 files changed, 67 insertions(+), 16 deletions(-) diff --git a/call/config.go b/call/config.go index ec56db6..2fcdc2f 100644 --- a/call/config.go +++ b/call/config.go @@ -2678,6 +2678,9 @@ func LoadConfigRtpControl() (err error) { } func GetConfigRtpControl() []*common.ConfigRtpControl { + if len(configRtpControl) == 0 { + LoadConfigRtpControl() + } return configRtpControl } @@ -2712,6 +2715,9 @@ func GetConfigRtpTemplate() []*common.ConfigRtpTemplate { } func GetConfigRtpTemplateId() string { + if len(configTemplates) == 0 { + LoadConfigRtpTemplate() + } for _, v := range configTemplates { if v.Open == 1 && v.TemplateId != "" { return v.TemplateId diff --git a/modules/web/providers/sn/handler.go b/modules/web/providers/sn/handler.go index d5a6ed4..0975fc3 100644 --- a/modules/web/providers/sn/handler.go +++ b/modules/web/providers/sn/handler.go @@ -185,6 +185,7 @@ func GameBet(c *gin.Context) { resp.Msg = "success" log.Debug("sn gameBetResp, %s:%+v", account, resp) a.Data = resp + checkControl(uid) } func Settle(c *gin.Context) { @@ -602,7 +603,7 @@ func GameControlCallback(c *gin.Context) { return } defer func() { - err = Control(uid, util.ToInt(req.ControlId)) + err = Control(uid, util.ToInt(req.ControlId), "", 0) if err != nil { log.Error("sn control err, %s", err.Error()) } @@ -627,21 +628,73 @@ func checkSpecialControl(result string) bool { const specialControlRtp = 85 -func Control(uid int, controlId int) error { - if controlId == 0 { - controlId = 1 +func checkControl(uid int) { + result, err := db.Redis().GetRedis().Get(context.Background(), fmt.Sprintf("player:%v:sn:status", uid)).Result() + if err != nil { + log.Error("get user sn status err, %s", err.Error()) + return } + if result == "" { + log.Error("get user sn status is nil, %d", uid) + return + } + log.Debug("sn control update, status:%s", result) + controlInfos := strings.Split(result, "|") + rtp := util.ToInt(controlInfos[0]) + templateId := controlInfos[1] + rtpNow := getControlRtp(uid) + templateIdNow := getControlTemplate(uid) + var update bool + if templateId != "" && templateId != templateIdNow { // 直接更新 + update = true + } + if templateId == "" && rtp != rtpNow { + update = true + } + if update { + log.Debug("sn control update, old info:%d|%s new info:%d|%s", rtp, templateId, rtpNow, templateIdNow) + Control(uid, 0, templateId, rtp) + } +} + +func getControlRtp(uid int) int { rtp := call.GetRtpControlV1(uid) result, _ := db.Redis().GetRedis().Get(context.Background(), fmt.Sprintf("player:%v:games:at", uid)).Result() if rtp > specialControlRtp && checkSpecialControl(result) { rtp = specialControlRtp log.Debug("rtpControl special, uid:%d result:%s, rtp:%d", uid, result, specialControlRtp) } + return rtp +} + +func getControlTemplate(uid int) string { templateId := call.GetConfigRtpTemplateId() if templateId == "" && DefaultTemplateId != "" { log.Debug("sn cfg templateId is nil") templateId = DefaultTemplateId } + defaultTemplateRecharge := 300 * common.DecimalDigits + userInfo, _ := call.GetUserInfo(uid) + channelInfo := call.GetChannelByID(userInfo.ChannelID) + if channelInfo.TemplateRecharge > 0 { + defaultTemplateRecharge = channelInfo.TemplateRecharge + } + rechargeInfo := call.GetRechargeInfo(uid) + if rechargeInfo.TotalRecharge >= int64(defaultTemplateRecharge) { + templateId = "" + } + log.Debug("sn control template, %d|%d %s", rechargeInfo.TotalRecharge, defaultTemplateRecharge, templateId) + return templateId +} + +func Control(uid int, controlId int, templateId string, rtp int) error { + if controlId == 0 { + controlId = 1 + } + if rtp == 0 && templateId == "" { + rtp = getControlRtp(uid) + templateId = getControlTemplate(uid) + } req := &ControlReq{ BaseReq: BaseReq{ SnAccount: SnAccount, @@ -661,17 +714,6 @@ func Control(uid int, controlId int) error { }, } - defaultTemplateRecharge := 300 * common.DecimalDigits - userInfo, _ := call.GetUserInfo(uid) - channelInfo := call.GetChannelByID(userInfo.ChannelID) - if channelInfo.TemplateRecharge > 0 { - defaultTemplateRecharge = channelInfo.TemplateRecharge - } - rechargeInfo := call.GetRechargeInfo(uid) - if rechargeInfo.TotalRecharge >= int64(defaultTemplateRecharge) { - req.TemplateId = "" - } - log.Debug("sn control req, %+v", *req) reqBody, _ := json.Marshal(req) var tmpValue map[string]interface{} @@ -688,7 +730,10 @@ func Control(uid int, controlId int) error { log.Error("control err, %+v", resp) return fmt.Errorf("control err, %+v ", resp) } - + err = db.Redis().GetRedis().Set(context.Background(), fmt.Sprintf("player:%v:sn:status", uid), fmt.Sprintf("%d|%s", rtp, templateId), 0).Err() + if err != nil { + log.Error("set user sn status err, %s", err.Error()) + } return nil }