You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
176 lines
4.2 KiB
176 lines
4.2 KiB
package handler |
|
|
|
import ( |
|
"reflect" |
|
"server/call" |
|
"server/common" |
|
"server/modules/backend/app" |
|
"server/modules/backend/values" |
|
"server/natsClient" |
|
"server/pb" |
|
"sort" |
|
"strings" |
|
|
|
"github.com/gin-gonic/gin" |
|
) |
|
|
|
// ConfigControlCommon 所有调控配置通用逻辑 |
|
func ConfigControlCommon(c *gin.Context) { |
|
a := app.NewApp(c) |
|
defer func() { |
|
a.Response() |
|
}() |
|
path := c.Request.URL.Path |
|
path = strings.ReplaceAll(path, "/gm/control/", "") |
|
all := strings.Split(path, "/") |
|
if len(all) > 2 { |
|
a.Code = values.CodeRetry |
|
return |
|
} |
|
t := all[0] |
|
opt := all[1] |
|
reloadType := values.GetControlType(t) |
|
element, list := common.GetConfigStructByType(reloadType) |
|
var resp interface{} |
|
if opt == "list" { |
|
if !a.MGetAll(element, list) { |
|
return |
|
} |
|
resp = CheckSpecial(reloadType, list) |
|
if resp == nil { |
|
resp = values.GMConfigCommonListResp{Config: list} |
|
} |
|
} else if opt == "edit" { |
|
req := new(values.GMConfigCommonEditReq) |
|
if !a.S(req) { |
|
return |
|
} |
|
if !a.MUpdateAll(req.Config, element) { |
|
return |
|
} |
|
call.Publish(natsClient.TopicReloadConfig, &pb.ReloadGameConfig{Type: int32(reloadType)}) |
|
} else if opt == "del" { |
|
req := new(values.GMConfigCommonDelReq) |
|
if !a.S(req) { |
|
return |
|
} |
|
if !a.MDel(req.ID, element) { |
|
return |
|
} |
|
call.Publish(natsClient.TopicReloadConfig, &pb.ReloadGameConfig{Type: int32(reloadType)}) |
|
} |
|
a.Data = resp |
|
} |
|
|
|
func CheckSpecial(t int, list interface{}) interface{} { |
|
switch t { |
|
} |
|
return nil |
|
} |
|
|
|
// ConfigPayWeight 支付渠道权重配置 |
|
func ConfigPayWeight(c *gin.Context) { |
|
a := app.NewApp(c) |
|
defer func() { |
|
a.Response() |
|
}() |
|
path := c.Request.URL.Path |
|
index := strings.LastIndex(path, "/") |
|
if index < 0 { |
|
a.Code = values.CodeParam |
|
return |
|
} |
|
opt := path[index+1:] |
|
reloadType := common.ReloadConfigPayWeight |
|
element, list := common.GetConfigStructByType(reloadType) |
|
resp := values.GMConfigPayWeightResp{} |
|
if opt == "list" { |
|
if !a.MGetAll(element, list) { |
|
return |
|
} |
|
list = reflect.ValueOf(list).Elem().Interface() |
|
retList := []common.ConfigPayChannels{} |
|
for _, v := range list.([]common.ConfigPayChannels) { |
|
if v.CurrencyType == common.CurrencyBrazil { |
|
retList = append(retList, v) |
|
} |
|
} |
|
sort.Slice(retList, func(i, j int) bool { |
|
return retList[i].PayPer > retList[j].PayPer |
|
}) |
|
resp.Config = retList |
|
// resp.Status, _ = db.Redis().GetInt(common.RedisKeyPayStatus) |
|
} else if opt == "edit" { |
|
req := new(values.GMConfigCommonEditReq) |
|
if !a.S(req) { |
|
return |
|
} |
|
if !a.MUpdateAll(req.Config, element) { |
|
return |
|
} |
|
call.Publish(natsClient.TopicReloadConfig, &pb.ReloadGameConfig{Type: int32(reloadType)}) |
|
} else if opt == "del" { |
|
req := new(values.GMConfigCommonDelReq) |
|
if !a.S(req) { |
|
return |
|
} |
|
if !a.MDel(req.ID, element) { |
|
return |
|
} |
|
call.Publish(natsClient.TopicReloadConfig, &pb.ReloadGameConfig{Type: int32(reloadType)}) |
|
} |
|
a.Data = resp |
|
} |
|
|
|
// ConfigWithdrawWeight 退出渠道配置 |
|
func ConfigWithdrawWeight(c *gin.Context) { |
|
a := app.NewApp(c) |
|
defer func() { |
|
a.Response() |
|
}() |
|
path := c.Request.URL.Path |
|
index := strings.LastIndex(path, "/") |
|
if index < 0 { |
|
a.Code = values.CodeParam |
|
return |
|
} |
|
opt := path[index+1:] |
|
reloadType := common.ReloadConfigWithdrawWeight |
|
element, list := common.GetConfigStructByType(reloadType) |
|
var resp interface{} |
|
if opt == "list" { |
|
if !a.MGetAll(element, list) { |
|
return |
|
} |
|
list = reflect.ValueOf(list).Elem().Interface() |
|
retList := []common.ConfigWithdrawChannels{} |
|
for _, v := range list.([]common.ConfigWithdrawChannels) { |
|
if v.CurrencyType == common.CurrencyBrazil { |
|
retList = append(retList, v) |
|
} |
|
} |
|
sort.Slice(retList, func(i, j int) bool { |
|
return retList[i].WithdrawPer > retList[j].WithdrawPer |
|
}) |
|
resp = values.GMConfigCommonListResp{Config: retList} |
|
} else if opt == "edit" { |
|
req := new(values.GMConfigCommonEditReq) |
|
if !a.S(req) { |
|
return |
|
} |
|
if !a.MUpdateAll(req.Config, element) { |
|
return |
|
} |
|
call.Publish(natsClient.TopicReloadConfig, &pb.ReloadGameConfig{Type: int32(reloadType)}) |
|
} else if opt == "del" { |
|
req := new(values.GMConfigCommonDelReq) |
|
if !a.S(req) { |
|
return |
|
} |
|
if !a.MDel(req.ID, element) { |
|
return |
|
} |
|
call.Publish(natsClient.TopicReloadConfig, &pb.ReloadGameConfig{Type: int32(reloadType)}) |
|
} |
|
a.Data = resp |
|
}
|
|
|