|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919 |
- 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: agentDomain,
- MediumDomain: 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)
- svc.ClearRedis(c, masterId, "medium_logo")
- svc.ClearRedis(c, masterId, "agent_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")
-
- e.OutSuc(c, md.SetLogoResp{
- Data: md.SetLogoReq{
- MediumLogo: res["medium_logo"],
- AgentLogo: res["agent_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
- }
|