|
|
|
@ -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" |
|
|
|
@ -631,6 +633,9 @@ const specialControlRtp = 85 |
|
|
|
func checkControl(uid int) { |
|
|
|
func checkControl(uid int) { |
|
|
|
result, err := db.Redis().GetRedis().Get(context.Background(), fmt.Sprintf("player:%v:sn:status", uid)).Result() |
|
|
|
result, err := db.Redis().GetRedis().Get(context.Background(), fmt.Sprintf("player:%v:sn:status", uid)).Result() |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
if errors.Is(err, redis.Nil) { |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
log.Error("get user sn status err, %s", err.Error()) |
|
|
|
log.Error("get user sn status err, %s", err.Error()) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
@ -638,12 +643,12 @@ func checkControl(uid int) { |
|
|
|
log.Error("get user sn status is nil, %d", uid) |
|
|
|
log.Error("get user sn status is nil, %d", uid) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
log.Debug("sn control update, status:%s", result) |
|
|
|
//log.Debug("sn control update, uid:%d status:%s", uid, result)
|
|
|
|
controlInfos := strings.Split(result, "|") |
|
|
|
controlInfos := strings.Split(result, "|") |
|
|
|
rtp := util.ToInt(controlInfos[0]) |
|
|
|
rtp := util.ToInt(controlInfos[0]) |
|
|
|
templateId := controlInfos[1] |
|
|
|
templateId := controlInfos[1] |
|
|
|
rtpNow := getControlRtp(uid) |
|
|
|
rtpNow := getControlRtp(uid) |
|
|
|
templateIdNow := getControlTemplate(uid) |
|
|
|
totalRecharge, defaultValue, templateIdNow := getControlTemplate(uid) |
|
|
|
var update bool |
|
|
|
var update bool |
|
|
|
if templateId != "" && templateId != templateIdNow { // 直接更新
|
|
|
|
if templateId != "" && templateId != templateIdNow { // 直接更新
|
|
|
|
update = true |
|
|
|
update = true |
|
|
|
@ -652,8 +657,13 @@ func checkControl(uid int) { |
|
|
|
update = true |
|
|
|
update = true |
|
|
|
} |
|
|
|
} |
|
|
|
if update { |
|
|
|
if update { |
|
|
|
log.Debug("sn control update, old info:%d|%s new info:%d|%s", rtp, templateId, rtpNow, templateIdNow) |
|
|
|
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, templateId, rtp) |
|
|
|
// todo 主动推会一直报错,兼容处理
|
|
|
|
|
|
|
|
err = db.Redis().GetRedis().Set(context.Background(), fmt.Sprintf("player:%v:sn:status", uid), fmt.Sprintf("%d|%s", rtpNow, templateIdNow), 0).Err() |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
log.Error("sn control, set user sn status err, %s", err.Error()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Control(uid, 0, templateIdNow, rtpNow) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -667,7 +677,7 @@ func getControlRtp(uid int) int { |
|
|
|
return rtp |
|
|
|
return rtp |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func getControlTemplate(uid int) string { |
|
|
|
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") |
|
|
|
@ -683,17 +693,19 @@ func getControlTemplate(uid int) string { |
|
|
|
if rechargeInfo.TotalRecharge >= int64(defaultTemplateRecharge) { |
|
|
|
if rechargeInfo.TotalRecharge >= int64(defaultTemplateRecharge) { |
|
|
|
templateId = "" |
|
|
|
templateId = "" |
|
|
|
} |
|
|
|
} |
|
|
|
log.Debug("sn control template, %d|%d %s", rechargeInfo.TotalRecharge, defaultTemplateRecharge, templateId) |
|
|
|
//log.Debug("sn control template, uid:%d %d|%d %s", uid, rechargeInfo.TotalRecharge, defaultTemplateRecharge, templateId)
|
|
|
|
return templateId |
|
|
|
return rechargeInfo.TotalRecharge, defaultTemplateRecharge, templateId |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func Control(uid int, controlId int, templateId string, rtp int) error { |
|
|
|
func Control(uid int, controlId int, templateId string, rtp int) error { |
|
|
|
if controlId == 0 { |
|
|
|
if controlId == 0 { |
|
|
|
controlId = 1 |
|
|
|
controlId = 1 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var totalRecharge int64 |
|
|
|
|
|
|
|
var defaultValue int |
|
|
|
if rtp == 0 && templateId == "" { |
|
|
|
if rtp == 0 && templateId == "" { |
|
|
|
rtp = getControlRtp(uid) |
|
|
|
rtp = getControlRtp(uid) |
|
|
|
templateId = getControlTemplate(uid) |
|
|
|
totalRecharge, defaultValue, templateId = getControlTemplate(uid) |
|
|
|
} |
|
|
|
} |
|
|
|
req := &ControlReq{ |
|
|
|
req := &ControlReq{ |
|
|
|
BaseReq: BaseReq{ |
|
|
|
BaseReq: BaseReq{ |
|
|
|
@ -714,7 +726,7 @@ func Control(uid int, controlId int, templateId string, rtp int) error { |
|
|
|
}, |
|
|
|
}, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
log.Debug("sn control req, %+v", *req) |
|
|
|
log.Debug("sn control req, %+v templateInfo(%d|%d)", *req, totalRecharge, defaultValue) |
|
|
|
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) |
|
|
|
@ -727,12 +739,12 @@ func Control(uid int, controlId int, templateId string, rtp 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() |
|
|
|
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 { |
|
|
|
if err != nil { |
|
|
|
log.Error("set user sn status err, %s", err.Error()) |
|
|
|
log.Error("sn control, set user sn status err, %s", err.Error()) |
|
|
|
} |
|
|
|
} |
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|