Merge branch 'dev_aagame_rtp_new' into dev_aagame

dev_aagame
zhora 1 week ago
commit 68d824ce8b
  1. 6
      call/config.go
  2. 93
      modules/web/providers/sn/handler.go

@ -2678,6 +2678,9 @@ func LoadConfigRtpControl() (err error) {
} }
func GetConfigRtpControl() []*common.ConfigRtpControl { func GetConfigRtpControl() []*common.ConfigRtpControl {
if len(configRtpControl) == 0 {
LoadConfigRtpControl()
}
return configRtpControl return configRtpControl
} }
@ -2712,6 +2715,9 @@ func GetConfigRtpTemplate() []*common.ConfigRtpTemplate {
} }
func GetConfigRtpTemplateId() string { func GetConfigRtpTemplateId() string {
if len(configTemplates) == 0 {
LoadConfigRtpTemplate()
}
for _, v := range configTemplates { for _, v := range configTemplates {
if v.Open == 1 && v.TemplateId != "" { if v.Open == 1 && v.TemplateId != "" {
return v.TemplateId return v.TemplateId

@ -3,7 +3,9 @@ package sn
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"github.com/go-redis/redis/v8"
"io/ioutil" "io/ioutil"
"server/call" "server/call"
"server/common" "server/common"
@ -185,6 +187,10 @@ func GameBet(c *gin.Context) {
resp.Msg = "success" resp.Msg = "success"
log.Debug("sn gameBetResp, %s:%+v", account, resp) log.Debug("sn gameBetResp, %s:%+v", account, resp)
a.Data = resp a.Data = resp
go func() {
defer util.Recover()
checkControl(uid)
}()
} }
func Settle(c *gin.Context) { func Settle(c *gin.Context) {
@ -602,7 +608,7 @@ func GameControlCallback(c *gin.Context) {
return return
} }
defer func() { defer func() {
err = Control(uid, util.ToInt(req.ControlId)) err = Control(uid, util.ToInt(req.ControlId), "", 0)
if err != nil { if err != nil {
log.Error("sn control err, %s", err.Error()) log.Error("sn control err, %s", err.Error())
} }
@ -627,21 +633,78 @@ func checkSpecialControl(result string) bool {
const specialControlRtp = 85 const specialControlRtp = 85
func Control(uid int, controlId int) error { func checkControl(uid int) {
if controlId == 0 { result, err := db.Redis().GetRedis().Get(context.Background(), fmt.Sprintf("player:%v:sn:status", uid)).Result()
controlId = 1 if err != nil {
if errors.Is(err, redis.Nil) {
return
}
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, uid:%d status:%s", uid, result)
controlInfos := strings.Split(result, "|")
rtp := util.ToInt(controlInfos[0])
templateId := controlInfos[1]
rtpNow := getControlRtp(uid)
totalRecharge, defaultValue, 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, uid:%d old info:%d|%s new info:%d|%s(%d|%d)", uid, rtp, templateId, rtpNow, templateIdNow, totalRecharge, defaultValue)
Control(uid, 0, templateIdNow, rtpNow)
}
}
func getControlRtp(uid int) int {
rtp := call.GetRtpControlV1(uid) rtp := call.GetRtpControlV1(uid)
result, _ := db.Redis().GetRedis().Get(context.Background(), fmt.Sprintf("player:%v:games:at", uid)).Result() result, _ := db.Redis().GetRedis().Get(context.Background(), fmt.Sprintf("player:%v:games:at", uid)).Result()
if rtp > specialControlRtp && checkSpecialControl(result) { if rtp > specialControlRtp && checkSpecialControl(result) {
rtp = specialControlRtp rtp = specialControlRtp
log.Debug("rtpControl special, uid:%d result:%s, rtp:%d", uid, result, specialControlRtp) log.Debug("rtpControl special, uid:%d result:%s, rtp:%d", uid, result, specialControlRtp)
} }
return rtp
}
func getControlTemplate(uid int) (int64, int, string) {
templateId := call.GetConfigRtpTemplateId() templateId := call.GetConfigRtpTemplateId()
if templateId == "" && DefaultTemplateId != "" { if templateId == "" && DefaultTemplateId != "" {
log.Debug("sn cfg templateId is nil") log.Debug("sn cfg templateId is nil")
templateId = DefaultTemplateId 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, uid:%d %d|%d %s", uid, rechargeInfo.TotalRecharge, defaultTemplateRecharge, templateId)
return rechargeInfo.TotalRecharge, defaultTemplateRecharge, templateId
}
func Control(uid int, controlId int, templateId string, rtp int) error {
if controlId == 0 {
controlId = 1
}
var totalRecharge int64
var defaultValue int
if rtp == 0 && templateId == "" {
rtp = getControlRtp(uid)
totalRecharge, defaultValue, templateId = getControlTemplate(uid)
}
req := &ControlReq{ req := &ControlReq{
BaseReq: BaseReq{ BaseReq: BaseReq{
SnAccount: SnAccount, SnAccount: SnAccount,
@ -661,18 +724,7 @@ func Control(uid int, controlId int) error {
}, },
} }
defaultTemplateRecharge := 300 * common.DecimalDigits log.Debug("sn control req, %+v templateInfo(%d|%d)", *req, totalRecharge, defaultValue)
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) reqBody, _ := json.Marshal(req)
var tmpValue map[string]interface{} var tmpValue map[string]interface{}
json.Unmarshal(reqBody, &tmpValue) json.Unmarshal(reqBody, &tmpValue)
@ -685,10 +737,13 @@ func Control(uid int, controlId int) error {
return err return err
} }
if resp.Code != CodeRequestSuccess && resp.Code != CodeRequestExist { if resp.Code != CodeRequestSuccess && resp.Code != CodeRequestExist {
log.Error("control err, %+v", resp) log.Error("sn control err, %+v", resp)
return fmt.Errorf("control err, %+v ", resp) return fmt.Errorf("sn 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("sn control, set user sn status err, %s", err.Error())
} }
return nil return nil
} }

Loading…
Cancel
Save