package gm import ( "fmt" "server/call" "server/common" "server/db" "server/modules/customer/app" "server/modules/customer/values" "server/natsClient" "server/pb" "server/util" "strings" "github.com/gin-gonic/gin" "github.com/liangdas/mqant/log" ) // 获取客服机器人消息 func GetCustomerRobot(c *gin.Context) { a := app.NewApp(c) defer func() { a.Response() }() req := &values.GetCustomerRobotReq{} if !a.S(req) { return } resp := values.GetCustomerRobotResp{} if _, err := db.Mysql().QueryAll(fmt.Sprintf("parent_id = %v", req.ParentId), "", &common.ConfigCustomerRobot{}, &resp.List); err != nil { log.Error("err:%v", err) a.Code = values.CodeRetry return } a.Data = resp } // 编辑客服机器人消息 func EditCustomerRobot(c *gin.Context) { a := app.NewApp(c) defer func() { a.Response() }() req := &values.EditCustomerRobotReq{} if !a.S(req) { return } var resp values.EditCustomerRobotResp for i := 0; i < len(req.List); i++ { if req.List[i] != nil { // 新增 if req.List[i].ID == 0 { log.Debug("req:%+v", req.List[i]) err := db.Mysql().Create(req.List[i]) if err != nil { log.Error(err.Error()) a.Code = values.CodeRetry return } log.Debug("req:%+v", req.List[i]) resp.List = append(resp.List, req.List[i]) } else { // 修改 log.Debug("req:%+v", req.List[i]) u := &common.ConfigCustomerRobot{} u.ID = req.List[i].ID update := util.StructToMap(req.List[i], "json") if err := db.Mysql().Update(u, update); err != nil { log.Error("err:%v", err) a.Code = values.CodeRetry return } } } } err := call.Publish(natsClient.TopicReloadConfig, &pb.ReloadGameConfig{Type: common.ReloadConfigCustomerRobot}) if err != nil { log.Error(err.Error()) a.Code = values.CodeRetry return } // 写入日志 for i := 0; i < len(req.List); i++ { if req.List[i] != nil { a.RecordEdit(values.PowerGM, fmt.Sprintf("编辑客服机器人配置:%v", *req.List[i])) } } a.Data = resp } // 删除客服机器人消息 func DelCustomerRobot(c *gin.Context) { a := app.NewApp(c) defer func() { a.Response() }() req := &values.DelCustomerRobotReq{} if !a.S(req) { return } for i := 0; i < len(req.List); i++ { if req.List[i] != nil { log.Debug("req:%+v", *req.List[i]) err := db.Mysql().Del(&common.ConfigCustomerRobot{}, " id = ?", *req.List[i]) if err != nil { log.Error(err.Error()) } } } err := call.Publish(natsClient.TopicReloadConfig, &pb.ReloadGameConfig{Type: common.ReloadConfigCustomerRobot}) if err != nil { log.Error(err.Error()) a.Code = values.CodeRetry } // 写入日志 for i := 0; i < len(req.List); i++ { if req.List[i] != nil { a.RecordEdit(values.PowerGM, fmt.Sprintf("删除客服机器人配置:%v", *req.List[i])) } } } // 获取标签 func GetCustomerLabel(c *gin.Context) { a := app.NewApp(c) defer func() { a.Response() }() resp := values.GetCustomerLabelResp{} if _, err := db.Mysql().QueryAll("", "", &common.CustomerOrderLabel{}, &resp.List); err != nil { log.Error("err:%v", err) a.Code = values.CodeRetry return } a.Data = resp } // 编辑标签 func EditCustomerLabel(c *gin.Context) { a := app.NewApp(c) defer func() { a.Response() }() req := &values.EditCustomerLabelReq{} if !a.S(req) { return } for i := 0; i < len(req.List); i++ { if req.List[i] != nil { // 新增 if req.List[i].ID == 0 { log.Debug("req:%+v", req.List[i]) err := db.Mysql().Create(req.List[i]) if err != nil { log.Error(err.Error()) a.Code = values.CodeRetry return } } else { // 修改 log.Debug("req:%+v", req.List[i]) u := &common.CustomerOrderLabel{} u.ID = req.List[i].ID update := util.StructToMap(req.List[i], "json") if err := db.Mysql().Update(u, update); err != nil { log.Error("err:%v", err) a.Code = values.CodeRetry return } } } } err := call.Publish(natsClient.TopicReloadConfig, &pb.ReloadGameConfig{Type: common.ReloadConfigCustomerLabel}) if err != nil { log.Error(err.Error()) a.Code = values.CodeRetry } // 写入日志 for i := 0; i < len(req.List); i++ { if req.List[i] != nil { a.RecordEdit(values.PowerGM, fmt.Sprintf("编辑工单标签配置:%v", *req.List[i])) } } } // 删除标签 func DelCustomerLabel(c *gin.Context) { a := app.NewApp(c) defer func() { a.Response() }() req := &values.DelCustomerLabelReq{} if !a.S(req) { return } for i := 0; i < len(req.List); i++ { if req.List[i] != nil { log.Debug("req:%+v", req.List[i]) err := db.Mysql().Del(&common.ConfigCustomerRobot{}, " id = ?", *req.List[i]) if err != nil { log.Error(err.Error()) } } } err := call.Publish(natsClient.TopicReloadConfig, &pb.ReloadGameConfig{Type: common.ReloadConfigCustomerLabel}) if err != nil { log.Error(err.Error()) a.Code = values.CodeRetry } // 写入日志 for i := 0; i < len(req.List); i++ { if req.List[i] != nil { a.RecordEdit(values.PowerGM, fmt.Sprintf("删除工单标签配置:%v", *req.List[i])) } } } // 客服系统配置 func GetConfigCustomer(c *gin.Context) { a := app.NewApp(c) defer func() { a.Response() }() resp := values.GetConfigCustomerResp{} if _, err := db.Mysql().QueryAll("", "", &common.ConfigCustomer{}, &resp.List); err != nil { log.Error("err:%v", err) a.Code = values.CodeRetry return } a.Data = resp } // 客服系统配置 func EditConfigCustomer(c *gin.Context) { a := app.NewApp(c) defer func() { a.Response() }() req := &values.EditConfigCustomerReq{} if !a.S(req) { return } for i := 0; i < len(req.List); i++ { if req.List[i] != nil { // 新增 if req.List[i].ID == 0 { log.Debug("req:%+v", req.List[i]) err := db.Mysql().Create(req.List[i]) if err != nil { log.Error(err.Error()) a.Code = values.CodeRetry return } } else { // 修改 log.Debug("req:%+v", req.List[i]) u := &common.ConfigCustomer{} u.ID = req.List[i].ID update := util.StructToMap(req.List[i], "json") if err := db.Mysql().Update(u, update); err != nil { log.Error("err:%v", err) a.Code = values.CodeRetry return } } } } err := call.Publish(natsClient.TopicReloadConfig, &pb.ReloadGameConfig{Type: common.ReloadConfigCustomer}) if err != nil { log.Error(err.Error()) a.Code = values.CodeRetry } // 写入日志 for i := 0; i < len(req.List); i++ { if req.List[i] != nil { a.RecordEdit(values.PowerGM, fmt.Sprintf("编辑客服系统配置:%v", *req.List[i])) } } } // 客服系统配置 func DelConfigCustomer(c *gin.Context) { a := app.NewApp(c) defer func() { a.Response() }() req := &values.DelConfigCustomerReq{} if !a.S(req) { return } for i := 0; i < len(req.List); i++ { if req.List[i] != nil { log.Debug("req:%+v", req.List[i]) err := db.Mysql().Del(&common.ConfigCustomer{}, " id = ?", *req.List[i]) if err != nil { log.Error(err.Error()) } } } err := call.Publish(natsClient.TopicReloadConfig, &pb.ReloadGameConfig{Type: common.ReloadConfigCustomer}) if err != nil { log.Error(err.Error()) a.Code = values.CodeRetry } // 写入日志 for i := 0; i < len(req.List); i++ { if req.List[i] != nil { a.RecordEdit(values.PowerGM, fmt.Sprintf("删除客服系统配置:%v", *req.List[i])) } } } // 客服黑名单 func GetCustomerBlackUser(c *gin.Context) { a := app.NewApp(c) defer func() { a.Response() }() req := &values.CustomerBlackUserReq{} if !a.S(req) { return } var resp values.CustomerBlackUserResp count, err := db.Mysql().QueryList(req.Page-1, req.Num, "", "", &common.CustomerBlackUser{}, &resp.List) if err != nil { log.Error("err:%v", err) a.Code = values.CodeRetry return } resp.Count = count a.Data = resp } // 客服黑名单 func EditCustomerBlackUser(c *gin.Context) { a := app.NewApp(c) defer func() { a.Response() }() req := &values.EditCustomerBlackUserReq{} if !a.S(req) { return } for i := 0; i < len(req.List); i++ { if req.List[i] != nil { log.Debug("opt:%v, req:%+v", req.Opt, *req.List[i]) if req.Opt == 1 { err := db.Mysql().Create(&common.CustomerBlackUser{Uid: *req.List[i]}) if err != nil { log.Error(err.Error()) } } else { data := &common.CustomerBlackUser{Uid: *req.List[i]} err := db.Mysql().Get(data) if err == nil { db.Mysql().Del(data) } } } } var str string if req.Opt == 1 { str = "添加" } else { str = "删除" } // 写入日志 for i := 0; i < len(req.List); i++ { if req.List[i] != nil { a.RecordEdit(values.PowerGM, fmt.Sprintf("%v客服系统黑名单 uid:%v", str, *req.List[i])) } } } // 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] element, list := GetElementByPath(t) var resp interface{} if opt == "list" { req := &values.GMConfigCommonListReq{ Condition: map[string]interface{}{}, } a.S(req) if !a.MGetSqlAll(element, list, req.Condition) { return } 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 }