package hdl import ( "applet/app/cfg" implement2 "applet/app/db/implement" "applet/app/e" "applet/app/enum" "applet/app/lib/validate" "applet/app/lib/wechat" md2 "applet/app/lib/wechat/md" "applet/app/md" "applet/app/svc" "applet/app/utils" db "code.fnuoos.com/zhimeng/model.git/src" "code.fnuoos.com/zhimeng/model.git/src/super/implement" "code.fnuoos.com/zhimeng/model.git/src/super/model" "encoding/json" "github.com/gin-gonic/gin" "strings" "time" ) // SetOss // @Summary oss设置 // @Tags 设置中心-基础设置 // @Description 基础设置-oss设置 // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Accept json // @Produce json // @Param args body md.SetOssReq true "请求参数" // @Success 200 {string} "success" // @Failure 400 {object} md.Response "具体错误" // @Router /api/setCenter/basic/setOss [POST] func SetOss(c *gin.Context) { var req md.SetOssReq err := c.ShouldBindJSON(&req) if err != nil { err = validate.HandleValidateErr(err) err1 := err.(e.E) e.OutErr(c, err1.Code, err1.Error()) return } masterId := svc.GetMasterId(c) engine := db.DBs[masterId] sysCfgDb := implement2.NewSysCfgDb(engine, masterId) sysCfgDb.SysCfgUpdate(enum.FileAccessKey, req.FileAccessKey) sysCfgDb.SysCfgUpdate(enum.FileSecretKey, req.FileSecretKey) sysCfgDb.SysCfgUpdate(enum.FileBucketHost, req.FileBucketHost) sysCfgDb.SysCfgUpdate(enum.FileBucketRegion, req.FileBucketRegion) sysCfgDb.SysCfgUpdate(enum.FileBucket, req.FileBucket) svc.ClearRedis(c, masterId, enum.FileAccessKey) svc.ClearRedis(c, masterId, enum.FileSecretKey) svc.ClearRedis(c, masterId, enum.FileBucketHost) svc.ClearRedis(c, masterId, enum.FileBucketRegion) svc.ClearRedis(c, masterId, enum.FileBucket) svc.ClearAllRedis(c, masterId) e.OutSuc(c, "success", nil) return } // GetOss // @Summary oss获取 // @Tags 设置中心-基础设置 // @Description 基础设置-oss获取 // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Accept json // @Produce json // @Success 200 {object} md.SetOssResp // @Failure 400 {object} md.Response "具体错误" // @Router /api/setCenter/basic/getOss [GET] func GetOss(c *gin.Context) { masterId := svc.GetMasterId(c) engine := db.DBs[masterId] sysCfgDb := implement2.NewSysCfgDb(engine, masterId) res := sysCfgDb.SysCfgFindWithDb(enum.FileAccessKey, enum.FileSecretKey, enum.FileBucketHost, enum.FileBucketRegion, enum.FileBucket) e.OutSuc(c, md.SetOssResp{ Data: md.SetOssReq{ FileAccessKey: res[enum.FileAccessKey], FileSecretKey: res[enum.FileSecretKey], FileBucketHost: res[enum.FileBucketHost], FileBucketRegion: res[enum.FileBucketRegion], FileBucket: res[enum.FileBucket], }, QiNiuBucketRegionList: md.QiNiuBucketRegionList, }, nil) return } // WxOpenSet // @Summary 微信三方应用设置 // @Tags 设置中心-基础设置 // @Description 基础设置-微信三方应用设置 // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Accept json // @Produce json // @Param args body md.WxOpenSetReq true "请求参数" // @Success 200 {string} "success" // @Failure 400 {object} md.Response "具体错误" // @Router /api/setCenter/basic/wxOpenSet [POST] func WxOpenSet(c *gin.Context) { var req md.WxOpenSetReq err := c.ShouldBindJSON(&req) if err != nil { err = validate.HandleValidateErr(err) err1 := err.(e.E) e.OutErr(c, err1.Code, err1.Error()) return } masterId := svc.GetMasterId(c) // 1、查找对应 wx_open_third_party_app_list 记录 wxOpenThirdPartyAppListDb := implement.NewWxOpenThirdPartyAppListDb(db.Db) UserWxAppletList, err := wxOpenThirdPartyAppListDb.GetWxOpenThirdPartyAppList(utils.StrToInt(masterId)) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } if UserWxAppletList == nil { UserWxAppletList = &model.WxOpenThirdPartyAppList{ Uuid: utils.StrToInt(masterId), Token: req.Token, AesKey: req.AesKey, Appid: req.Appid, AppSecret: req.AppSecret, ComponentVerifyTicket: "", ComponentAccessToken: "", CreateAt: time.Now().Format("2006-01-02 15:04:05"), UpdateAt: time.Now().Format("2006-01-02 15:04:05"), } _, err = wxOpenThirdPartyAppListDb.WxOpenThirdPartyAppListInsert(UserWxAppletList) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } } else { UserWxAppletList.Token = req.Token UserWxAppletList.AesKey = req.AesKey UserWxAppletList.Appid = req.Appid UserWxAppletList.AppSecret = req.AppSecret _, err = wxOpenThirdPartyAppListDb.UpdateWxOpenThirdPartyAppList(UserWxAppletList, "token", "aes_key", "appid", "app_secret") if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } } e.OutSuc(c, "success", nil) return } // WxOpenGet // @Summary 微信三方应用获取 // @Tags 设置中心-基础设置 // @Description 基础设置-微信三方应用获取 // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Accept json // @Produce json // @Success 200 {object} md.WxOpenGetResp // @Failure 400 {object} md.Response "具体错误" // @Router /api/setCenter/basic/wxOpenGet [GET] func WxOpenGet(c *gin.Context) { masterId := svc.GetMasterId(c) // 1、查找对应 wx_open_third_party_app_list 记录 wxOpenThirdPartyAppListDb := implement.NewWxOpenThirdPartyAppListDb(db.Db) UserWxAppletList, err := wxOpenThirdPartyAppListDb.GetWxOpenThirdPartyAppList(utils.StrToInt(masterId)) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } if UserWxAppletList == nil { UserWxAppletList = &model.WxOpenThirdPartyAppList{ Uuid: utils.StrToInt(masterId), Token: "", AesKey: "", Appid: "", AppSecret: "", ComponentVerifyTicket: "", ComponentAccessToken: "", CreateAt: time.Now().Format("2006-01-02 15:04:05"), UpdateAt: time.Now().Format("2006-01-02 15:04:05"), } _, err = wxOpenThirdPartyAppListDb.WxOpenThirdPartyAppListInsert(UserWxAppletList) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } } sysCfgDb := implement2.NewSysCfgDb(db.Db, "") res := sysCfgDb.SysCfgFindWithDb(enum.WxOpenAppletServerDomain, enum.WxOpenAuthorizationEventReceivingConfiguration, enum.WxOpenDomainOfTheInitiatingPageForLoginAuthorization, enum.WxOpenMessageAndEventReceptionConfiguration, enum.WxOpenWhiteListIp) e.OutSuc(c, md.WxOpenGetResp{ Token: UserWxAppletList.Token, AesKey: UserWxAppletList.AesKey, Appid: UserWxAppletList.Appid, AppSecret: UserWxAppletList.AppSecret, WxOpenAppletServerDomain: res[enum.WxOpenAppletServerDomain], WxOpenAuthorizationEventReceivingConfiguration: res[enum.WxOpenAuthorizationEventReceivingConfiguration], WxOpenDomainOfTheInitiatingPageForLoginAuthorization: res[enum.WxOpenDomainOfTheInitiatingPageForLoginAuthorization], WxOpenMessageAndEventReceptionConfiguration: res[enum.WxOpenMessageAndEventReceptionConfiguration], WxOpenWhiteListIp: res[enum.WxOpenWhiteListIp], }, nil) return } type WxOpenThirdPartyAppList struct { Id int `json:"id" xorm:"not null pk autoincr unique(IDX_UUID_TYPE) INT(11)"` Uuid int `json:"uuid" xorm:"not null comment('站长id') index unique(IDX_UUID_TYPE) INT(10)"` Token string `json:"token" xorm:"not null default '' comment('消息校验Token') VARCHAR(255)"` AesKey string `json:"aes_key" xorm:"not null default '' comment('消息加解密Key') VARCHAR(255)"` Appid string `json:"appid" xorm:"not null default '' comment('appid') CHAR(50)"` AppSecret string `json:"app_secret" xorm:"not null default '' comment('appSecret') VARCHAR(255)"` ComponentVerifyTicket string `json:"component_verify_ticket" xorm:"not null default '' comment('验证票据') VARCHAR(255)"` ComponentAccessToken string `json:"component_access_token" xorm:"not null default '' comment('接口令牌') VARCHAR(255)"` CreateAt string `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` UpdateAt string `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` } // AppletList // @Summary 列表 // @Tags 设置中心-小程序设置 // @Description 小程序设置-列表 // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Accept json // @Produce json // @Success 200 {object} WxOpenThirdPartyAppList // @Failure 400 {object} md.Response "具体错误" // @Router /api/setCenter/applet/list [GET] func AppletList(c *gin.Context) { masterId := svc.GetMasterId(c) // 1、查找对应 user_wx_applet_list 记录 userWxAppletListDb := implement.NewUserWxAppletListDb(db.Db) UserWxAppletList, err := userWxAppletListDb.GetUserWxAppletList(masterId) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } e.OutSuc(c, UserWxAppletList, nil) return } // AppletAdd // @Summary 新增 // @Tags 设置中心-小程序设置 // @Description 小程序设置-新增 // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Accept json // @Produce json // @Param args body md.AppletAddReq true "请求参数" // @Success 200 {string} "success" // @Failure 400 {object} md.Response "具体错误" // @Router /api/setCenter/applet/add [POST] func AppletAdd(c *gin.Context) { var req md.AppletAddReq err := c.ShouldBindJSON(&req) if err != nil { err = validate.HandleValidateErr(err) err1 := err.(e.E) e.OutErr(c, err1.Code, err1.Error()) return } masterId := svc.GetMasterId(c) // 1、查找对应 user_wx_applet_list 记录 userWxAppletListDb := implement.NewUserWxAppletListDb(db.Db) UserWxAppletList, err := userWxAppletListDb.GetUserWxAppletList(masterId) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } if UserWxAppletList != nil { e.OutErr(c, e.ERR, "当前仅支持单个小程序") return } _, err = userWxAppletListDb.UserWxAppletListInsert(&model.UserWxAppletList{ Name: req.Name, Logo: req.Logo, Appid: req.Appid, OriginalId: req.OriginalId, AuthorizerRefreshToken: "", IsAuth: 0, Uuid: masterId, CreateAt: time.Now().Format("2006-01-02 15:04:05"), UpdateAt: time.Now().Format("2006-01-02 15:04:05"), }) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } e.OutSuc(c, "success", nil) return } // AppletUpdate // @Summary 更新 // @Tags 设置中心-小程序设置 // @Description 小程序设置-更新 // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Accept json // @Produce json // @Param args body md.AppletUpdateReq true "请求参数" // @Success 200 {string} "success" // @Failure 400 {object} md.Response "具体错误" // @Router /api/setCenter/applet/update [POST] func AppletUpdate(c *gin.Context) { var req md.AppletUpdateReq err := c.ShouldBindJSON(&req) if err != nil { err = validate.HandleValidateErr(err) err1 := err.(e.E) e.OutErr(c, err1.Code, err1.Error()) return } masterId := svc.GetMasterId(c) // 1、查找对应 user_wx_applet_list 记录 userWxAppletListDb := implement.NewUserWxAppletListDb(db.Db) UserWxAppletList, err := userWxAppletListDb.GetUserWxAppletList(masterId) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } if UserWxAppletList == nil { e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录") return } UserWxAppletList.Logo = req.Logo UserWxAppletList.Name = req.Name _, err = userWxAppletListDb.UpdateUserWxAppletList(UserWxAppletList, "logo", "name") if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } e.OutSuc(c, "success", nil) return } // AppletDelete // @Summary 删除 // @Tags 设置中心-小程序设置 // @Description 小程序设置-删除 // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Accept json // @Produce json // @Success 200 {string} "success" // @Failure 400 {object} md.Response "具体错误" // @Router /v1/banner/delete/{$id} [DELETE] func AppletDelete(c *gin.Context) { id := c.Param("id") masterId := svc.GetMasterId(c) // 1、查找对应 user_wx_applet_list 记录 userWxAppletListDb := implement.NewUserWxAppletListDb(db.Db) UserWxAppletList, err := userWxAppletListDb.GetUserWxAppletList(masterId) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } if UserWxAppletList == nil { e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录") return } _, err = userWxAppletListDb.UserWxAppletListDelete(id) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } e.OutSuc(c, "success", nil) return } // AppletAuthorize // @Summary 设置中心-基础设置-微信三方应用获取 // @Tags 设置中心 // @Description 设置中心-基础设置 // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Accept json // @Produce json // @Success 200 {string} "微信授权界面url" // @Failure 400 {object} md.Response "具体错误" // @Router /api/setCenter/applet/authorize [GET] func AppletAuthorize(c *gin.Context) { masterId := svc.GetMasterId(c) url := "http://super.advertisement.dengbiao.top/api/wxOpen/getPreAuthCode?master_id=" + masterId if cfg.Prd { url = "http://ad.zhios.cn/api/wxOpen/getPreAuthCode?master_id=" + masterId } e.OutSuc(c, map[string]string{ "url": url, }, nil) return } // AppletUnauthorized // @Summary 设置中心-基础设置-微信三方应用获取 // @Tags 设置中心 // @Description 设置中心-基础设置 // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Accept json // @Produce json // @Success 200 {string} "success" // @Failure 400 {object} md.Response "具体错误" // @Router /api/setCenter/applet/unauthorized [GET] func AppletUnauthorized(c *gin.Context) { appId := c.DefaultQuery("app_id", "") masterId := svc.GetMasterId(c) // 1、查找对应 user_wx_applet_list 记录 userWxAppletListDb := implement.NewUserWxAppletListDb(db.Db) UserWxAppletList, err := userWxAppletListDb.GetUserWxAppletList(masterId) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } if UserWxAppletList == nil { e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录") return } wxOpenThirdPartyAppListDb := implement.NewWxOpenThirdPartyAppListDb(db.Db) wxOpenThirdPartyAppList, err := wxOpenThirdPartyAppListDb.GetWxOpenThirdPartyAppList(utils.StrToInt(masterId)) if err != nil { e.OutErr(c, e.ERR, err.Error()) return } if wxOpenThirdPartyAppList == nil { e.OutErr(c, e.ERR_NOT_FAN, "未查询到对应三方应用记录") return } wxApiService, err := wechat.NewWxApiService(masterId, wxOpenThirdPartyAppList.Appid, wxOpenThirdPartyAppList.AppSecret) if err != nil { e.OutErr(c, e.ERR, err.Error()) return } err = wxApiService.DelAuthorize(appId) if err != nil { e.OutErr(c, e.ERR, err.Error()) return } e.OutSuc(c, "success", nil) return } // ShareIndex // @Summary 邀请链接 // @Tags 设置中心-邀请链接 // @Description 邀请链接界面接口 // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Accept json // @Produce json // @Success 200 {object} md.ShareIndexResp // @Failure 400 {object} md.Response "具体错误" // @Router /api/setCenter/share/index [GET] func ShareIndex(c *gin.Context) { masterId := svc.GetMasterId(c) agent := new(model.UserAppDomain) _, err := db.Db.Where("type =?", "agent").And("uuid =?", masterId).And("is_ssl =1").Get(agent) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } medium := new(model.UserAppDomain) _, err = db.Db.Where("type =?", "medium").And("uuid =?", masterId).And("is_ssl =1").Get(medium) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } agentDomain := "" if agent != nil { agentDomain = agent.Domain } mediumDomain := "" if medium != nil { mediumDomain = medium.Domain } e.OutSuc(c, md.ShareIndexResp{ MasterId: masterId, AgentDomain: "http://" + agentDomain, MediumDomain: "http://" + mediumDomain, }, nil) return } // SetMob // @Summary mob设置 // @Tags 设置中心-基础设置 // @Description 基础设置-mob设置 // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Accept json // @Produce json // @Param args body md.SetMobReq true "请求参数" // @Success 200 {string} "success" // @Failure 400 {object} md.Response "具体错误" // @Router /api/setCenter/basic/setMob [POST] func SetMob(c *gin.Context) { var req md.SetMobReq err := c.ShouldBindJSON(&req) if err != nil { err = validate.HandleValidateErr(err) err1 := err.(e.E) e.OutErr(c, err1.Code, err1.Error()) return } masterId := svc.GetMasterId(c) engine := db.DBs[masterId] sysCfgDb := implement2.NewSysCfgDb(engine, masterId) sysCfgDb.SysCfgUpdate("mob_app_key", req.MobAppKey) sysCfgDb.SysCfgUpdate("mob_app_secret", req.MobAppSecret) svc.ClearRedis(c, masterId, "mob_app_key") svc.ClearRedis(c, masterId, "mob_app_secret") svc.ClearAllRedis(c, masterId) e.OutSuc(c, "success", nil) return } // GetMob // @Summary mob获取 // @Tags 设置中心-基础设置 // @Description 基础设置-mob获取 // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Accept json // @Produce json // @Success 200 {object} md.SetOssResp // @Failure 400 {object} md.Response "具体错误" // @Router /api/setCenter/basic/getMob [GET] func GetMob(c *gin.Context) { masterId := svc.GetMasterId(c) engine := db.DBs[masterId] sysCfgDb := implement2.NewSysCfgDb(engine, masterId) res := sysCfgDb.SysCfgFindWithDb("mob_app_key", "mob_app_secret") e.OutSuc(c, md.SetMobResp{ Data: md.SetMobReq{ MobAppSecret: res["mob_app_secret"], MobAppKey: res["mob_app_key"], }, }, nil) return } // SetLogo // @Summary logo设置 // @Tags 设置中心-基础设置 // @Description 基础设置-logo设置 // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Accept json // @Produce json // @Param args body md.SetLogoReq true "请求参数" // @Success 200 {string} "success" // @Failure 400 {object} md.Response "具体错误" // @Router /api/setCenter/basic/setLogo [POST] func SetLogo(c *gin.Context) { var req md.SetLogoReq err := c.ShouldBindJSON(&req) if err != nil { err = validate.HandleValidateErr(err) err1 := err.(e.E) e.OutErr(c, err1.Code, err1.Error()) return } masterId := svc.GetMasterId(c) engine := db.DBs[masterId] sysCfgDb := implement2.NewSysCfgDb(engine, masterId) sysCfgDb.SysCfgUpdate("medium_logo", req.MediumLogo) sysCfgDb.SysCfgUpdate("agent_logo", req.AgentLogo) sysCfgDb.SysCfgUpdate("medium_login_logo", req.MediumLoginLogo) sysCfgDb.SysCfgUpdate("agent_login_logo", req.AgentLoginLogo) svc.ClearRedis(c, masterId, "medium_logo") svc.ClearRedis(c, masterId, "agent_logo") svc.ClearRedis(c, masterId, "medium_login_logo") svc.ClearRedis(c, masterId, "agent_login_logo") svc.ClearAllRedis(c, masterId) e.OutSuc(c, "success", nil) return } // GetLogo // @Summary logo获取 // @Tags 设置中心-基础设置 // @Description 基础设置-logo获取 // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Accept json // @Produce json // @Success 200 {object} md.SetLogoResp // @Failure 400 {object} md.Response "具体错误" // @Router /api/setCenter/basic/getLogo [GET] func GetLogo(c *gin.Context) { masterId := svc.GetMasterId(c) engine := db.DBs[masterId] sysCfgDb := implement2.NewSysCfgDb(engine, masterId) res := sysCfgDb.SysCfgFindWithDb("medium_logo", "agent_logo", "medium_login_logo", "agent_login_logo") e.OutSuc(c, md.SetLogoResp{ Data: md.SetLogoReq{ MediumLogo: res["medium_logo"], AgentLogo: res["agent_logo"], MediumLoginLogo: res["medium_login_logo"], AgentLoginLogo: res["agent_login_logo"], }, }, nil) return } // SetSeo // @Summary Seo设置 // @Tags 设置中心-基础设置 // @Description 基础设置-logo设置 // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Accept json // @Produce json // @Param args body md.SetSeoReq true "请求参数" // @Success 200 {string} "success" // @Failure 400 {object} md.Response "具体错误" // @Router /api/setCenter/basic/setSeo [POST] func SetSeo(c *gin.Context) { var req md.SetSeoReq err := c.ShouldBindJSON(&req) if err != nil { err = validate.HandleValidateErr(err) err1 := err.(e.E) e.OutErr(c, err1.Code, err1.Error()) return } masterId := svc.GetMasterId(c) engine := db.DBs[masterId] sysCfgDb := implement2.NewSysCfgDb(engine, masterId) sysCfgDb.SysCfgUpdate("seo_medium_title", req.SeoMediumTitle) sysCfgDb.SysCfgUpdate("seo_agent_title", req.SeoAgentTitle) sysCfgDb.SysCfgUpdate("seo_platform_title", req.SeoPlatformTitle) svc.ClearRedis(c, masterId, "seo_medium_title") svc.ClearRedis(c, masterId, "seo_agent_title") svc.ClearRedis(c, masterId, "seo_platform_title") sysCfgDb.SysCfgUpdate("seo_medium_logo", req.SeoMediumLogo) sysCfgDb.SysCfgUpdate("seo_agent_logo", req.SeoAgentLogo) sysCfgDb.SysCfgUpdate("seo_platform_logo", req.SeoPlatformLogo) svc.ClearRedis(c, masterId, "seo_medium_logo") svc.ClearRedis(c, masterId, "seo_agent_logo") svc.ClearRedis(c, masterId, "seo_platform_logo") svc.ClearAllRedis(c, masterId) e.OutSuc(c, "success", nil) return } // GetSeo // @Summary Seo获取 // @Tags 设置中心-基础设置 // @Description 基础设置-logo获取 // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Accept json // @Produce json // @Success 200 {object} md.SetSeoResp // @Failure 400 {object} md.Response "具体错误" // @Router /api/setCenter/basic/getSeo [GET] func GetSeo(c *gin.Context) { masterId := svc.GetMasterId(c) engine := db.DBs[masterId] sysCfgDb := implement2.NewSysCfgDb(engine, masterId) res := sysCfgDb.SysCfgFindWithDb("seo_medium_logo", "seo_agent_logo", "seo_platform_logo", "seo_medium_title", "seo_agent_title", "seo_platform_title") e.OutSuc(c, md.SetSeoResp{ Data: md.SetSeoReq{ SeoMediumTitle: res["seo_medium_title"], SeoAgentTitle: res["seo_agent_title"], SeoPlatformTitle: res["seo_platform_title"], SeoMediumLogo: res["seo_medium_logo"], SeoAgentLogo: res["seo_agent_logo"], SeoPlatformLogo: res["seo_platform_logo"], }, }, nil) return } // AppletGetBlackList // @Summary 获取屏蔽的广告主 // @Tags 设置中心-小程序设置-屏蔽规则 // @Description 小程序设置-屏蔽规则-获取屏蔽的广告主 // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Accept json // @Produce json // @Param args body md.AppletGetBlackListReq true "请求参数" // @Success 200 {object} md2.AgencyGetBlackListResp // @Failure 400 {object} md.Response "具体错误" // @Router /api/setCenter/basic/applet/shieldRules/getBlackList [POST] func AppletGetBlackList(c *gin.Context) { var req md.AppletGetBlackListReq err := c.ShouldBindJSON(&req) if err != nil { err = validate.HandleValidateErr(err) err1 := err.(e.E) e.OutErr(c, err1.Code, err1.Error()) return } masterId := svc.GetMasterId(c) wxOpenThirdPartyAppListDb := implement.NewWxOpenThirdPartyAppListDb(db.Db) wxOpenThirdPartyAppList, err := wxOpenThirdPartyAppListDb.GetWxOpenThirdPartyAppList(utils.StrToInt(masterId)) if err != nil { e.OutErr(c, e.ERR, err.Error()) return } if wxOpenThirdPartyAppList == nil { e.OutErr(c, e.ERR_NOT_FAN, "未查询到对应三方应用记录") return } wxApiService, err := wechat.NewWxApiService(masterId, wxOpenThirdPartyAppList.Appid, wxOpenThirdPartyAppList.AppSecret) if err != nil { e.OutErr(c, e.ERR, err.Error()) return } var resp md2.AgencyGetBlackListResp err, resp = wxApiService.GetBlackList(req.Appid) if err != nil { e.OutErr(c, e.ERR, err.Error()) return } e.OutSuc(c, resp, nil) return } // AppletAddBlackList // @Summary 添加屏蔽的广告主 // @Tags 设置中心-小程序设置-屏蔽规则 // @Description 小程序设置-屏蔽规则-添加屏蔽的广告主 // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Accept json // @Produce json // @Param args body md.AppletAddBlackListReq true "请求参数" // @Success 200 {string} "success" // @Failure 400 {object} md.Response "具体错误" // @Router /api/setCenter/basic/applet/shieldRules/addBlackList [POST] func AppletAddBlackList(c *gin.Context) { var req md.AppletAddBlackListReq err := c.ShouldBindJSON(&req) if err != nil { err = validate.HandleValidateErr(err) err1 := err.(e.E) e.OutErr(c, err1.Code, err1.Error()) return } masterId := svc.GetMasterId(c) wxOpenThirdPartyAppListDb := implement.NewWxOpenThirdPartyAppListDb(db.Db) wxOpenThirdPartyAppList, err := wxOpenThirdPartyAppListDb.GetWxOpenThirdPartyAppList(utils.StrToInt(masterId)) if err != nil { e.OutErr(c, e.ERR, err.Error()) return } if wxOpenThirdPartyAppList == nil { e.OutErr(c, e.ERR_NOT_FAN, "未查询到对应三方应用记录") return } wxApiService, err := wechat.NewWxApiService(masterId, wxOpenThirdPartyAppList.Appid, wxOpenThirdPartyAppList.AppSecret) if err != nil { e.OutErr(c, e.ERR, err.Error()) return } listStr, _ := json.Marshal([]interface{}{ map[string]interface{}{ "type": req.Kind, "id": req.Id, }, }) err = wxApiService.SetBlackList(req.Appid, 1, string(listStr)) if err != nil { e.OutErr(c, e.ERR, err.Error()) return } e.OutSuc(c, "success", nil) return } // AppletDelBlackList // @Summary 删除屏蔽的广告主 // @Tags 设置中心-小程序设置-屏蔽规则 // @Description 小程序设置-屏蔽规则-删除屏蔽的广告主 // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Accept json // @Produce json // @Param args body md.AppletDelBlackListReq true "请求参数" // @Success 200 {string} "success" // @Failure 400 {object} md.Response "具体错误" // @Router /api/setCenter/basic/applet/shieldRules/delBlackList [POST] func AppletDelBlackList(c *gin.Context) { var req md.AppletDelBlackListReq err := c.ShouldBindJSON(&req) if err != nil { err = validate.HandleValidateErr(err) err1 := err.(e.E) e.OutErr(c, err1.Code, err1.Error()) return } masterId := svc.GetMasterId(c) wxOpenThirdPartyAppListDb := implement.NewWxOpenThirdPartyAppListDb(db.Db) wxOpenThirdPartyAppList, err := wxOpenThirdPartyAppListDb.GetWxOpenThirdPartyAppList(utils.StrToInt(masterId)) if err != nil { e.OutErr(c, e.ERR, err.Error()) return } if wxOpenThirdPartyAppList == nil { e.OutErr(c, e.ERR_NOT_FAN, "未查询到对应三方应用记录") return } wxApiService, err := wechat.NewWxApiService(masterId, wxOpenThirdPartyAppList.Appid, wxOpenThirdPartyAppList.AppSecret) if err != nil { e.OutErr(c, e.ERR, err.Error()) return } listStr, _ := json.Marshal([]interface{}{ map[string]interface{}{ "type": req.Kind, "id": req.Id, }, }) err = wxApiService.SetBlackList(req.Appid, 2, string(listStr)) if err != nil { e.OutErr(c, e.ERR, err.Error()) return } e.OutSuc(c, "success", nil) return } // AppletGetAmsCategoryBlackList // @Summary 获取行业屏蔽信息 // @Tags 设置中心-小程序设置-屏蔽规则 // @Description 小程序设置-屏蔽规则-获取行业屏蔽信息 // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Accept json // @Produce json // @Param args body md.AppletGetAmsCategoryBlackListReq true "请求参数" // @Success 200 {object} md.AppletGetAmsCategoryBlackListResp // @Failure 400 {object} md.Response "具体错误" // @Router /api/setCenter/basic/applet/shieldRules/getAmsCategoryBlackList [POST] func AppletGetAmsCategoryBlackList(c *gin.Context) { var req md.AppletGetAmsCategoryBlackListReq err := c.ShouldBindJSON(&req) if err != nil { err = validate.HandleValidateErr(err) err1 := err.(e.E) e.OutErr(c, err1.Code, err1.Error()) return } masterId := svc.GetMasterId(c) wxOpenThirdPartyAppListDb := implement.NewWxOpenThirdPartyAppListDb(db.Db) wxOpenThirdPartyAppList, err := wxOpenThirdPartyAppListDb.GetWxOpenThirdPartyAppList(utils.StrToInt(masterId)) if err != nil { e.OutErr(c, e.ERR, err.Error()) return } if wxOpenThirdPartyAppList == nil { e.OutErr(c, e.ERR_NOT_FAN, "未查询到对应三方应用记录") return } wxApiService, err := wechat.NewWxApiService(masterId, wxOpenThirdPartyAppList.Appid, wxOpenThirdPartyAppList.AppSecret) if err != nil { e.OutErr(c, e.ERR, err.Error()) return } var data md2.GetAmsCategoryBlackListResp err, data = wxApiService.GetAmsCategoryBlackList(req.Appid) if err != nil { e.OutErr(c, e.ERR, err.Error()) return } var resp md.AppletGetAmsCategoryBlackListResp amsCategoryArr := strings.Split(data.AmsCategory, "|") for _, v := range amsCategoryArr { resp.CheckedAmsCategory = append(resp.CheckedAmsCategory, struct { Value string `json:"value" example:"行业标识符"` Name string `json:"name" example:"行业名称"` }{ Value: v, Name: enum.AmsCategory.String(enum.AmsCategory(v)), }) } resp.AllAmsCategory = []struct { Value string `json:"value" example:"行业标识符"` Name string `json:"name" example:"行业名称"` }{ { Value: enum.AmsCategoryForChess, Name: enum.AmsCategory.String(enum.AmsCategoryForChess), }, { Value: enum.AmsCategoryForAdultSupplies, Name: enum.AmsCategory.String(enum.AmsCategoryForAdultSupplies), }, { Value: enum.AmsCategoryForMEDICALHEALTH, Name: enum.AmsCategory.String(enum.AmsCategoryForMEDICALHEALTH), }, { Value: enum.AmsCategoryForINSURANCE, Name: enum.AmsCategory.String(enum.AmsCategoryForINSURANCE), }, { Value: enum.AmsCategoryForSECURITES, Name: enum.AmsCategory.String(enum.AmsCategoryForSECURITES), }, { Value: enum.AmsCategoryForLOAN, Name: enum.AmsCategory.String(enum.AmsCategoryForLOAN), }, { Value: enum.AmsCategoryForLIVINGSERVICESBEAUTY, Name: enum.AmsCategory.String(enum.AmsCategoryForLIVINGSERVICESBEAUTY), }, { Value: enum.AmsCategoryForLIVINGSERVICESENTERTAINMENT, Name: enum.AmsCategory.String(enum.AmsCategoryForLIVINGSERVICESENTERTAINMENT), }, { Value: enum.AmsCategoryForLIVINGSERVICESOTHERS, Name: enum.AmsCategory.String(enum.AmsCategoryForLIVINGSERVICESOTHERS), }, { Value: enum.AmsCategoryForFOODINDUSTRY, Name: enum.AmsCategory.String(enum.AmsCategoryForFOODINDUSTRY), }, { Value: enum.AmsCategoryForRETAILANDGENERALMERCHANDISE, Name: enum.AmsCategory.String(enum.AmsCategoryForRETAILANDGENERALMERCHANDISE), }, { Value: enum.AmsCategoryForFOODANDDRINK, Name: enum.AmsCategory.String(enum.AmsCategoryForFOODANDDRINK), }, { Value: enum.AmsCategoryForTECHNICALSERVICE, Name: enum.AmsCategory.String(enum.AmsCategoryForTECHNICALSERVICE), }, } e.OutSuc(c, resp, nil) return } // AppletSetAmsCategoryBlackList // @Summary 设置行业屏蔽信息 // @Tags 设置中心-小程序设置-屏蔽规则 // @Description 小程序设置-屏蔽规则-设置行业屏蔽信息 // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Accept json // @Produce json // @Param args body md.AppletSetAmsCategoryBlackListReq true "请求参数" // @Success 200 {string} "success" // @Failure 400 {object} md.Response "具体错误" // @Router /api/setCenter/basic/applet/shieldRules/setAmsCategoryBlackList [POST] func AppletSetAmsCategoryBlackList(c *gin.Context) { var req md.AppletSetAmsCategoryBlackListReq err := c.ShouldBindJSON(&req) if err != nil { err = validate.HandleValidateErr(err) err1 := err.(e.E) e.OutErr(c, err1.Code, err1.Error()) return } masterId := svc.GetMasterId(c) wxOpenThirdPartyAppListDb := implement.NewWxOpenThirdPartyAppListDb(db.Db) wxOpenThirdPartyAppList, err := wxOpenThirdPartyAppListDb.GetWxOpenThirdPartyAppList(utils.StrToInt(masterId)) if err != nil { e.OutErr(c, e.ERR, err.Error()) return } if wxOpenThirdPartyAppList == nil { e.OutErr(c, e.ERR_NOT_FAN, "未查询到对应三方应用记录") return } wxApiService, err := wechat.NewWxApiService(masterId, wxOpenThirdPartyAppList.Appid, wxOpenThirdPartyAppList.AppSecret) if err != nil { e.OutErr(c, e.ERR, err.Error()) return } amsCategory := strings.Join(req.CheckedAmsCategory, "|") err = wxApiService.SetAmsCategoryBlackList(req.Appid, amsCategory) if err != nil { e.OutErr(c, e.ERR, err.Error()) return } e.OutSuc(c, "success", nil) return }