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.
408 lines
11 KiB
408 lines
11 KiB
package handler |
|
|
|
import ( |
|
"fmt" |
|
"server/call" |
|
"server/common" |
|
"server/db" |
|
"server/modules/backend/app" |
|
"server/modules/backend/bdb" |
|
"server/modules/backend/values" |
|
"server/natsClient" |
|
"server/pb" |
|
"strconv" |
|
"time" |
|
|
|
"github.com/gin-gonic/gin" |
|
"github.com/gogo/protobuf/proto" |
|
"github.com/liangdas/mqant/log" |
|
"github.com/olivere/elastic/v7" |
|
) |
|
|
|
func WhiteListSwitch(c *gin.Context) { |
|
a := app.NewApp(c) |
|
defer func() { |
|
a.Response() |
|
}() |
|
req := new(values.WhiteListSwitchReq) |
|
if !a.S(req) { |
|
return |
|
} |
|
one := &common.WhiteList{ListType: call.SysListType, LimitType: req.Opt, Channel: req.Channel, Version: req.Version} |
|
_, err := db.ES().Upsert(common.ESIndexBackWhiteList, strconv.Itoa(req.Channel), one, one) |
|
if err != nil { |
|
log.Error("err:%v", err) |
|
a.Code = values.CodeRetry |
|
return |
|
} |
|
db.ES().Refresh(common.ESIndexBackWhiteList) |
|
send := &pb.InnerWhiteSwitch{Channel: uint32(req.Channel), Opt: uint32(req.Opt)} |
|
data, _ := proto.Marshal(send) |
|
if err := call.Publish(natsClient.TopicReloadConfig, &pb.ReloadGameConfig{Type: common.ReloadWhiteList, Data: data}); err != nil { |
|
log.Error("err:%v", err) |
|
a.Code = values.CodeRetry |
|
return |
|
} |
|
a.RecordEdit(values.PowerWhiteList, fmt.Sprintf("操作白名单开关:%v", req.Opt)) |
|
} |
|
|
|
func GetWhiteList(c *gin.Context) { |
|
a := app.NewApp(c) |
|
defer func() { |
|
a.Response() |
|
}() |
|
req := new(values.WhiteListReq) |
|
if !a.S(req) { |
|
return |
|
} |
|
var list []common.WhiteList |
|
q := elastic.NewBoolQuery() |
|
q.MustNot(elastic.NewMatchQuery("ListType", call.SysListType)) |
|
if req.ListType > 0 { |
|
q.Must(elastic.NewTermQuery("ListType", req.ListType)) |
|
} |
|
count, err := db.ES().QueryList(common.ESIndexBackWhiteList, int(req.Page-1), int(req.Num), q, &list, "CreateTime", false) |
|
if err != nil { |
|
log.Error("err:%v", err) |
|
a.Code = values.CodeRetry |
|
return |
|
} |
|
var sysConfig []common.WhiteList |
|
if _, err := db.ES().QueryList(common.ESIndexBackWhiteList, 0, 5000, elastic.NewTermQuery("ListType", call.SysListType), &sysConfig); err != nil { |
|
log.Error("err:%v", err) |
|
a.Code = values.CodeRetry |
|
return |
|
} |
|
resp := values.WhiteListResp{List: list, Count: count, SwitchList: sysConfig} |
|
a.Data = resp |
|
} |
|
|
|
func AddWhiteList(c *gin.Context) { |
|
a := app.NewApp(c) |
|
defer func() { |
|
a.Response() |
|
}() |
|
req := new(values.AddWhiteListReq) |
|
if !a.S(req) { |
|
return |
|
} |
|
if (req.ListType != 1 && req.ListType != 2) && (req.LimitType != 1 && req.LimitType != 2) && |
|
(req.Channel != common.AccountTypeFacebook && req.Channel != common.AccountTypeGoogleplay) { |
|
a.Code = values.CodeParam |
|
return |
|
} |
|
one := common.WhiteList{ |
|
ListType: req.ListType, |
|
LimitType: req.LimitType, |
|
Content: req.Content, |
|
Platform: req.Channel, |
|
Version: req.Version, |
|
Powers: req.Powers, |
|
CreateTime: time.Now().Unix(), |
|
Operator: a.User.Account, |
|
} |
|
if err := db.ES().InsertToES(common.ESIndexBackWhiteList, one); err != nil { |
|
log.Error("err:%v", err) |
|
a.Code = values.CodeRetry |
|
return |
|
} |
|
db.ES().Refresh(common.ESIndexBackWhiteList) |
|
if err := call.Publish(natsClient.TopicReloadConfig, &pb.ReloadGameConfig{Type: common.ReloadWhiteList}); err != nil { |
|
log.Error("err:%v", err) |
|
a.Code = values.CodeRetry |
|
return |
|
} |
|
a.RecordEdit(values.PowerWhiteList, fmt.Sprintf("新增白名单:%v", req.Content)) |
|
} |
|
|
|
func EditWhiteList(c *gin.Context) { |
|
a := app.NewApp(c) |
|
defer func() { |
|
a.Response() |
|
}() |
|
req := new(values.EditWhiteListReq) |
|
if !a.S(req) { |
|
return |
|
} |
|
update := map[string]interface{}{} |
|
if req.ListType != nil && (*req.ListType == 1 || *req.ListType == 2) { |
|
update["ListType"] = *req.ListType |
|
} |
|
if req.LimitType != nil && (*req.LimitType == 1 || *req.LimitType == 2) { |
|
update["LimitType"] = *req.LimitType |
|
} |
|
if req.Channel != nil && (*req.Channel == common.AccountTypeFacebook || *req.Channel == common.AccountTypeGoogleplay) { |
|
update["Platform"] = *req.Channel |
|
} |
|
if req.Content != nil { |
|
update["Content"] = *req.Content |
|
} |
|
if req.Powers != nil { |
|
update["Powers"] = *req.Powers |
|
} |
|
if req.Version != nil { |
|
update["Version"] = *req.Version |
|
} |
|
if len(update) == 0 { |
|
a.Code = values.CodeParam |
|
a.Msg = "没有内容修改" |
|
return |
|
} |
|
if _, err := db.ES().Update(common.ESIndexBackWhiteList, req.ID, update); err != nil { |
|
log.Error("err:%v", err) |
|
a.Code = values.CodeRetry |
|
return |
|
} |
|
db.ES().Refresh(common.ESIndexBackWhiteList) |
|
if err := call.Publish(natsClient.TopicReloadConfig, &pb.ReloadGameConfig{Type: common.ReloadWhiteList}); err != nil { |
|
log.Error("err:%v", err) |
|
a.Code = values.CodeRetry |
|
return |
|
} |
|
a.RecordEdit(values.PowerWhiteList, fmt.Sprintf("修改白名单:%v", req.ID)) |
|
} |
|
|
|
func DeleteWhiteList(c *gin.Context) { |
|
a := app.NewApp(c) |
|
defer func() { |
|
a.Response() |
|
}() |
|
req := new(values.DeleteWhiteListReq) |
|
if !a.S(req) { |
|
return |
|
} |
|
if err := db.ES().DeleteByQuery(common.ESIndexBackWhiteList, elastic.NewMatchQuery("_id", req.ID)); err != nil { |
|
log.Error("err:%v", err) |
|
a.Code = values.CodeRetry |
|
return |
|
} |
|
db.ES().Refresh(common.ESIndexBackWhiteList) |
|
if err := call.Publish(natsClient.TopicReloadConfig, &pb.ReloadGameConfig{Type: common.ReloadWhiteList}); err != nil { |
|
log.Error("err:%v", err) |
|
a.Code = values.CodeRetry |
|
return |
|
} |
|
a.RecordEdit(values.PowerWhiteList, fmt.Sprintf("删除白名单:%v", req.ID)) |
|
} |
|
|
|
func AddChannel(c *gin.Context) { |
|
a := app.NewApp(c) |
|
defer func() { |
|
a.Response() |
|
}() |
|
req := new(values.AddChannelReq) |
|
if !a.S(req) { |
|
return |
|
} |
|
|
|
one := new(common.Channel) |
|
one.ChannelID = req.ChannelID |
|
one.PlatformID = req.PlatformID |
|
one.Name = req.Name |
|
one.PackName = req.PackName |
|
one.Version = req.Version |
|
one.IsHot = req.IsHot |
|
one.AdjustAppToken = req.AdjustAppToken |
|
one.AdjustAuth = req.AdjustAuth |
|
one.AdjustEventID = req.AdjustEventID |
|
one.MainVersion = req.MainVersion |
|
one.Show = req.Show |
|
one.URL = req.URL |
|
one.IgnoreOrganic = req.IgnoreOrganic |
|
one.FBPixelID = req.FBPixelID |
|
one.FBAccessToken = req.FBAccessToken |
|
one.UP = req.UP |
|
one.ADUpload = req.ADUpload |
|
// m := map[int]int{} |
|
// for _, v := range req.Games { |
|
// id := common.GetGameIDByGames(v) |
|
// if id == 0 { |
|
// continue |
|
// } |
|
// m[id] = 1 |
|
// } |
|
// if len(m) > 0 { |
|
// s, _ := json.Marshal(m) |
|
// one.GameControl = string(s) |
|
// } |
|
if err := db.Mysql().Create(one); err != nil { |
|
log.Error("err:%v", err) |
|
return |
|
} |
|
err := call.Publish(natsClient.TopicReloadConfig, &pb.ReloadGameConfig{Type: common.ReloadChannel}) |
|
if err != nil { |
|
log.Error(err.Error()) |
|
} |
|
a.RecordEdit(values.PowerChannel, fmt.Sprintf("新增渠道:%v", req.ChannelID)) |
|
} |
|
|
|
func EditChannel(c *gin.Context) { |
|
a := app.NewApp(c) |
|
defer func() { |
|
a.Response() |
|
}() |
|
req := new(values.EditChannelReq) |
|
if !a.S(req) { |
|
return |
|
} |
|
one := new(common.Channel) |
|
one.ID = uint(req.ID) |
|
if err := db.Mysql().Get(one); err != nil { |
|
log.Error("err:%v", err) |
|
a.Code = values.CodeParam |
|
a.Msg = "渠道不存在" |
|
return |
|
} |
|
update := map[string]interface{}{} |
|
if req.ChannelID != nil && one.ChannelID != *req.ChannelID { |
|
// update = true |
|
// one.ChannelID = *req.ChannelID |
|
update["channel_id"] = *req.ChannelID |
|
} |
|
if req.PlatformID != nil && one.PlatformID != *req.PlatformID { |
|
// update = true |
|
// one.PlatformID = *req.PlatformID |
|
update["platform_id"] = *req.PlatformID |
|
} |
|
if req.Name != nil && one.Name != *req.Name { |
|
// update = true |
|
// one.Name = *req.Name |
|
update["name"] = *req.Name |
|
} |
|
if req.PackName != nil && one.PackName != *req.PackName { |
|
// update = true |
|
// one.PackName = *req.PackName |
|
update["pack_name"] = *req.PackName |
|
} |
|
if req.Version != nil && one.Version != *req.Version { |
|
// update = true |
|
// one.Version = *req.Version |
|
update["version"] = *req.Version |
|
} |
|
if req.MainVersion != nil && one.MainVersion != *req.MainVersion { |
|
// update = true |
|
// one.MainVersion = *req.MainVersion |
|
update["main_version"] = *req.MainVersion |
|
} |
|
if req.IsHot != nil && one.IsHot != *req.IsHot { |
|
// update = true |
|
// one.IsHot = *req.IsHot |
|
update["ishot"] = *req.IsHot |
|
} |
|
if req.AdjustAuth != nil && one.AdjustAuth != *req.AdjustAuth { |
|
// update = true |
|
// one.AdjustAuth = *req.AdjustAuth |
|
update["adjust_auth"] = *req.AdjustAuth |
|
} |
|
if req.AdjustAppToken != nil && one.AdjustAppToken != *req.AdjustAppToken { |
|
// update = true |
|
// one.AdjustAppToken = *req.AdjustAppToken |
|
update["adjust_app_token"] = *req.AdjustAppToken |
|
} |
|
if req.AdjustEventID != nil && one.AdjustEventID != *req.AdjustEventID { |
|
// update = true |
|
// one.AdjustEventID = *req.AdjustEventID |
|
update["adjust_eventid"] = *req.AdjustEventID |
|
} |
|
if req.URL != nil && one.URL != *req.URL { |
|
// update = true |
|
// one.URL = *req.URL |
|
update["url"] = *req.URL |
|
} |
|
if req.Show != nil && one.Show != *req.Show { |
|
// update = true |
|
// one.Show = *req.Show |
|
update["show"] = *req.Show |
|
} |
|
if req.IgnoreOrganic != nil && one.IgnoreOrganic != *req.IgnoreOrganic { |
|
// update = true |
|
// one.IgnoreOrganic = *req.IgnoreOrganic |
|
update["ignore_organic"] = *req.IgnoreOrganic |
|
} |
|
if req.FBPixelID != nil && one.FBPixelID != *req.FBPixelID { |
|
// update = true |
|
// one.FBPixelID = *req.FBPixelID |
|
update["fb_pixelid"] = *req.FBPixelID |
|
} |
|
if req.FBAccessToken != nil && one.FBAccessToken != *req.FBAccessToken { |
|
// update = true |
|
// one.FBAccessToken = *req.FBAccessToken |
|
update["fb_accesstoken"] = *req.FBAccessToken |
|
} |
|
if req.UP != nil && one.UP != *req.UP { |
|
// update = true |
|
// one.FBAccessToken = *req.FBAccessToken |
|
update["up"] = *req.UP |
|
} |
|
if req.ADUpload != nil && one.ADUpload != *req.ADUpload { |
|
// update = true |
|
// one.FBAccessToken = *req.FBAccessToken |
|
update["ad_upload"] = *req.ADUpload |
|
} |
|
if len(update) == 0 { |
|
a.Code = values.CodeParam |
|
a.Msg = "无内容修改" |
|
return |
|
} |
|
if err := db.Mysql().Update(&common.Channel{ID: uint(req.ID)}, update); err != nil { |
|
log.Error("err:%v", err) |
|
a.Code = values.CodeRetry |
|
return |
|
} |
|
err := call.Publish(natsClient.TopicReloadConfig, &pb.ReloadGameConfig{Type: common.ReloadChannel}) |
|
if err != nil { |
|
log.Error(err.Error()) |
|
} |
|
a.RecordEdit(values.PowerChannel, fmt.Sprintf("修改渠道:%v", *req.ChannelID)) |
|
} |
|
|
|
func DelChannel(c *gin.Context) { |
|
a := app.NewApp(c) |
|
defer func() { |
|
a.Response() |
|
}() |
|
req := new(values.DelChannelReq) |
|
if !a.S(req) { |
|
return |
|
} |
|
|
|
// 传入-1时清表 |
|
if req.ID == -1 { |
|
if err := db.Mysql().C().Delete(&common.Channel{}).Where("id > ?", req.ID); err != nil { |
|
log.Error("err:%v", err) |
|
a.Code = values.CodeRetry |
|
return |
|
} |
|
} else { |
|
one := &common.Channel{ID: uint(req.ID)} |
|
if err := db.Mysql().C().Delete(one).Where("id = ?", req.ID).Error; err != nil { |
|
log.Error("err:%v", err) |
|
a.Code = values.CodeRetry |
|
return |
|
} |
|
} |
|
|
|
err := call.Publish(natsClient.TopicReloadConfig, &pb.ReloadGameConfig{Type: common.ReloadChannel}) |
|
if err != nil { |
|
log.Error(err.Error()) |
|
} |
|
a.RecordEdit(values.PowerChannel, fmt.Sprintf("删除渠道:%v", req.ID)) |
|
} |
|
|
|
// OptList 操作日志 |
|
func OptList(c *gin.Context) { |
|
a := app.NewApp(c) |
|
defer func() { |
|
a.Response() |
|
}() |
|
req := new(values.EditHistoryListReq) |
|
if !a.S(req) { |
|
return |
|
} |
|
resp := values.EditHistoryListResp{} |
|
if err := bdb.BackDB.C().Order("time Desc").Limit(int(req.Num)).Offset(int((req.Page - 1) * req.Num)).Find(&resp.List).Error; err != nil { |
|
log.Error("err:%v", err) |
|
} |
|
resp.Count = bdb.BackDB.Count(&values.EditHistory{}, "") |
|
a.Data = resp |
|
}
|
|
|