广告平台(站长使用)
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.

hdl_set_center.go 34 KiB

3 months ago
1 month ago
3 months ago
1 month ago
3 months ago
1 month ago
3 months ago
2 months ago
2 months ago
3 months ago
1 month ago
3 months ago
1 month ago
3 months ago
1 month ago
3 months ago
1 month ago
3 months ago
1 month ago
3 months ago
2 months ago
3 months ago
1 month ago
3 months ago
1 month ago
3 months ago
1 month ago
3 months ago
2 months ago
3 months ago
2 months ago
2 months ago
3 months ago
2 months ago
2 months ago
3 months ago
1 month ago
3 months ago
3 months ago
2 months ago
2 months ago
3 months ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
2 months ago
2 months ago
1 month ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993
  1. package hdl
  2. import (
  3. "applet/app/cfg"
  4. implement2 "applet/app/db/implement"
  5. "applet/app/e"
  6. "applet/app/enum"
  7. "applet/app/lib/validate"
  8. "applet/app/lib/wechat"
  9. md2 "applet/app/lib/wechat/md"
  10. "applet/app/md"
  11. "applet/app/svc"
  12. "applet/app/utils"
  13. db "code.fnuoos.com/zhimeng/model.git/src"
  14. "code.fnuoos.com/zhimeng/model.git/src/super/implement"
  15. "code.fnuoos.com/zhimeng/model.git/src/super/model"
  16. "encoding/json"
  17. "github.com/gin-gonic/gin"
  18. "strings"
  19. "time"
  20. )
  21. // SetOss
  22. // @Summary oss设置
  23. // @Tags 设置中心-基础设置
  24. // @Description 基础设置-oss设置
  25. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  26. // @Accept json
  27. // @Produce json
  28. // @Param args body md.SetOssReq true "请求参数"
  29. // @Success 200 {string} "success"
  30. // @Failure 400 {object} md.Response "具体错误"
  31. // @Router /api/setCenter/basic/setOss [POST]
  32. func SetOss(c *gin.Context) {
  33. var req md.SetOssReq
  34. err := c.ShouldBindJSON(&req)
  35. if err != nil {
  36. err = validate.HandleValidateErr(err)
  37. err1 := err.(e.E)
  38. e.OutErr(c, err1.Code, err1.Error())
  39. return
  40. }
  41. masterId := svc.GetMasterId(c)
  42. engine := db.DBs[masterId]
  43. sysCfgDb := implement2.NewSysCfgDb(engine, masterId)
  44. sysCfgDb.SysCfgUpdate(enum.FileAccessKey, req.FileAccessKey)
  45. sysCfgDb.SysCfgUpdate(enum.FileSecretKey, req.FileSecretKey)
  46. sysCfgDb.SysCfgUpdate(enum.FileBucketHost, req.FileBucketHost)
  47. sysCfgDb.SysCfgUpdate(enum.FileBucketRegion, req.FileBucketRegion)
  48. sysCfgDb.SysCfgUpdate(enum.FileBucket, req.FileBucket)
  49. svc.ClearRedis(c, masterId, enum.FileAccessKey)
  50. svc.ClearRedis(c, masterId, enum.FileSecretKey)
  51. svc.ClearRedis(c, masterId, enum.FileBucketHost)
  52. svc.ClearRedis(c, masterId, enum.FileBucketRegion)
  53. svc.ClearRedis(c, masterId, enum.FileBucket)
  54. svc.ClearAllRedis(c, masterId)
  55. e.OutSuc(c, "success", nil)
  56. return
  57. }
  58. // GetOss
  59. // @Summary oss获取
  60. // @Tags 设置中心-基础设置
  61. // @Description 基础设置-oss获取
  62. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  63. // @Accept json
  64. // @Produce json
  65. // @Success 200 {object} md.SetOssResp
  66. // @Failure 400 {object} md.Response "具体错误"
  67. // @Router /api/setCenter/basic/getOss [GET]
  68. func GetOss(c *gin.Context) {
  69. masterId := svc.GetMasterId(c)
  70. engine := db.DBs[masterId]
  71. sysCfgDb := implement2.NewSysCfgDb(engine, masterId)
  72. res := sysCfgDb.SysCfgFindWithDb(enum.FileAccessKey, enum.FileSecretKey, enum.FileBucketHost, enum.FileBucketRegion, enum.FileBucket)
  73. e.OutSuc(c, md.SetOssResp{
  74. Data: md.SetOssReq{
  75. FileAccessKey: res[enum.FileAccessKey],
  76. FileSecretKey: res[enum.FileSecretKey],
  77. FileBucketHost: res[enum.FileBucketHost],
  78. FileBucketRegion: res[enum.FileBucketRegion],
  79. FileBucket: res[enum.FileBucket],
  80. },
  81. QiNiuBucketRegionList: md.QiNiuBucketRegionList,
  82. }, nil)
  83. return
  84. }
  85. // WxOpenSet
  86. // @Summary 微信三方应用设置
  87. // @Tags 设置中心-基础设置
  88. // @Description 基础设置-微信三方应用设置
  89. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  90. // @Accept json
  91. // @Produce json
  92. // @Param args body md.WxOpenSetReq true "请求参数"
  93. // @Success 200 {string} "success"
  94. // @Failure 400 {object} md.Response "具体错误"
  95. // @Router /api/setCenter/basic/wxOpenSet [POST]
  96. func WxOpenSet(c *gin.Context) {
  97. var req md.WxOpenSetReq
  98. err := c.ShouldBindJSON(&req)
  99. if err != nil {
  100. err = validate.HandleValidateErr(err)
  101. err1 := err.(e.E)
  102. e.OutErr(c, err1.Code, err1.Error())
  103. return
  104. }
  105. masterId := svc.GetMasterId(c)
  106. // 1、查找对应 wx_open_third_party_app_list 记录
  107. wxOpenThirdPartyAppListDb := implement.NewWxOpenThirdPartyAppListDb(db.Db)
  108. UserWxAppletList, err := wxOpenThirdPartyAppListDb.GetWxOpenThirdPartyAppList(utils.StrToInt(masterId))
  109. if err != nil {
  110. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  111. return
  112. }
  113. if UserWxAppletList == nil {
  114. UserWxAppletList = &model.WxOpenThirdPartyAppList{
  115. Uuid: utils.StrToInt(masterId),
  116. Token: req.Token,
  117. AesKey: req.AesKey,
  118. Appid: req.Appid,
  119. AppSecret: req.AppSecret,
  120. ComponentVerifyTicket: "",
  121. ComponentAccessToken: "",
  122. CreateAt: time.Now().Format("2006-01-02 15:04:05"),
  123. UpdateAt: time.Now().Format("2006-01-02 15:04:05"),
  124. }
  125. _, err = wxOpenThirdPartyAppListDb.WxOpenThirdPartyAppListInsert(UserWxAppletList)
  126. if err != nil {
  127. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  128. return
  129. }
  130. } else {
  131. UserWxAppletList.Token = req.Token
  132. UserWxAppletList.AesKey = req.AesKey
  133. UserWxAppletList.Appid = req.Appid
  134. UserWxAppletList.AppSecret = req.AppSecret
  135. _, err = wxOpenThirdPartyAppListDb.UpdateWxOpenThirdPartyAppList(UserWxAppletList,
  136. "token", "aes_key", "appid", "app_secret")
  137. if err != nil {
  138. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  139. return
  140. }
  141. }
  142. e.OutSuc(c, "success", nil)
  143. return
  144. }
  145. // WxOpenGet
  146. // @Summary 微信三方应用获取
  147. // @Tags 设置中心-基础设置
  148. // @Description 基础设置-微信三方应用获取
  149. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  150. // @Accept json
  151. // @Produce json
  152. // @Success 200 {object} md.WxOpenGetResp
  153. // @Failure 400 {object} md.Response "具体错误"
  154. // @Router /api/setCenter/basic/wxOpenGet [GET]
  155. func WxOpenGet(c *gin.Context) {
  156. masterId := svc.GetMasterId(c)
  157. // 1、查找对应 wx_open_third_party_app_list 记录
  158. wxOpenThirdPartyAppListDb := implement.NewWxOpenThirdPartyAppListDb(db.Db)
  159. UserWxAppletList, err := wxOpenThirdPartyAppListDb.GetWxOpenThirdPartyAppList(utils.StrToInt(masterId))
  160. if err != nil {
  161. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  162. return
  163. }
  164. if UserWxAppletList == nil {
  165. UserWxAppletList = &model.WxOpenThirdPartyAppList{
  166. Uuid: utils.StrToInt(masterId),
  167. Token: "",
  168. AesKey: "",
  169. Appid: "",
  170. AppSecret: "",
  171. ComponentVerifyTicket: "",
  172. ComponentAccessToken: "",
  173. CreateAt: time.Now().Format("2006-01-02 15:04:05"),
  174. UpdateAt: time.Now().Format("2006-01-02 15:04:05"),
  175. }
  176. _, err = wxOpenThirdPartyAppListDb.WxOpenThirdPartyAppListInsert(UserWxAppletList)
  177. if err != nil {
  178. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  179. return
  180. }
  181. }
  182. sysCfgDb := implement2.NewSysCfgDb(db.Db, "")
  183. res := sysCfgDb.SysCfgFindWithDb(enum.WxOpenAppletServerDomain, enum.WxOpenAuthorizationEventReceivingConfiguration,
  184. enum.WxOpenDomainOfTheInitiatingPageForLoginAuthorization, enum.WxOpenMessageAndEventReceptionConfiguration, enum.WxOpenWhiteListIp)
  185. e.OutSuc(c, md.WxOpenGetResp{
  186. Token: UserWxAppletList.Token,
  187. AesKey: UserWxAppletList.AesKey,
  188. Appid: UserWxAppletList.Appid,
  189. AppSecret: UserWxAppletList.AppSecret,
  190. WxOpenAppletServerDomain: res[enum.WxOpenAppletServerDomain],
  191. WxOpenAuthorizationEventReceivingConfiguration: res[enum.WxOpenAuthorizationEventReceivingConfiguration],
  192. WxOpenDomainOfTheInitiatingPageForLoginAuthorization: res[enum.WxOpenDomainOfTheInitiatingPageForLoginAuthorization],
  193. WxOpenMessageAndEventReceptionConfiguration: res[enum.WxOpenMessageAndEventReceptionConfiguration],
  194. WxOpenWhiteListIp: res[enum.WxOpenWhiteListIp],
  195. }, nil)
  196. return
  197. }
  198. type WxOpenThirdPartyAppList struct {
  199. Id int `json:"id" xorm:"not null pk autoincr unique(IDX_UUID_TYPE) INT(11)"`
  200. Uuid int `json:"uuid" xorm:"not null comment('站长id') index unique(IDX_UUID_TYPE) INT(10)"`
  201. Token string `json:"token" xorm:"not null default '' comment('消息校验Token') VARCHAR(255)"`
  202. AesKey string `json:"aes_key" xorm:"not null default '' comment('消息加解密Key') VARCHAR(255)"`
  203. Appid string `json:"appid" xorm:"not null default '' comment('appid') CHAR(50)"`
  204. AppSecret string `json:"app_secret" xorm:"not null default '' comment('appSecret') VARCHAR(255)"`
  205. ComponentVerifyTicket string `json:"component_verify_ticket" xorm:"not null default '' comment('验证票据') VARCHAR(255)"`
  206. ComponentAccessToken string `json:"component_access_token" xorm:"not null default '' comment('接口令牌') VARCHAR(255)"`
  207. CreateAt string `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"`
  208. UpdateAt string `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"`
  209. }
  210. // AppletList
  211. // @Summary 列表
  212. // @Tags 设置中心-小程序设置
  213. // @Description 小程序设置-列表
  214. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  215. // @Accept json
  216. // @Produce json
  217. // @Success 200 {object} WxOpenThirdPartyAppList
  218. // @Failure 400 {object} md.Response "具体错误"
  219. // @Router /api/setCenter/applet/list [GET]
  220. func AppletList(c *gin.Context) {
  221. masterId := svc.GetMasterId(c)
  222. // 1、查找对应 user_wx_applet_list 记录
  223. userWxAppletListDb := implement.NewUserWxAppletListDb(db.Db)
  224. UserWxAppletList, err := userWxAppletListDb.GetUserWxAppletList(masterId)
  225. if err != nil {
  226. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  227. return
  228. }
  229. e.OutSuc(c, UserWxAppletList, nil)
  230. return
  231. }
  232. // AppletAdd
  233. // @Summary 新增
  234. // @Tags 设置中心-小程序设置
  235. // @Description 小程序设置-新增
  236. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  237. // @Accept json
  238. // @Produce json
  239. // @Param args body md.AppletAddReq true "请求参数"
  240. // @Success 200 {string} "success"
  241. // @Failure 400 {object} md.Response "具体错误"
  242. // @Router /api/setCenter/applet/add [POST]
  243. func AppletAdd(c *gin.Context) {
  244. var req md.AppletAddReq
  245. err := c.ShouldBindJSON(&req)
  246. if err != nil {
  247. err = validate.HandleValidateErr(err)
  248. err1 := err.(e.E)
  249. e.OutErr(c, err1.Code, err1.Error())
  250. return
  251. }
  252. masterId := svc.GetMasterId(c)
  253. // 1、查找对应 user_wx_applet_list 记录
  254. userWxAppletListDb := implement.NewUserWxAppletListDb(db.Db)
  255. UserWxAppletList, err := userWxAppletListDb.GetUserWxAppletList(masterId)
  256. if err != nil {
  257. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  258. return
  259. }
  260. if UserWxAppletList != nil {
  261. e.OutErr(c, e.ERR, "当前仅支持单个小程序")
  262. return
  263. }
  264. _, err = userWxAppletListDb.UserWxAppletListInsert(&model.UserWxAppletList{
  265. Name: req.Name,
  266. Logo: req.Logo,
  267. Appid: req.Appid,
  268. OriginalId: req.OriginalId,
  269. AuthorizerRefreshToken: "",
  270. IsAuth: 0,
  271. Uuid: masterId,
  272. CreateAt: time.Now().Format("2006-01-02 15:04:05"),
  273. UpdateAt: time.Now().Format("2006-01-02 15:04:05"),
  274. })
  275. if err != nil {
  276. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  277. return
  278. }
  279. e.OutSuc(c, "success", nil)
  280. return
  281. }
  282. // AppletUpdate
  283. // @Summary 更新
  284. // @Tags 设置中心-小程序设置
  285. // @Description 小程序设置-更新
  286. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  287. // @Accept json
  288. // @Produce json
  289. // @Param args body md.AppletUpdateReq true "请求参数"
  290. // @Success 200 {string} "success"
  291. // @Failure 400 {object} md.Response "具体错误"
  292. // @Router /api/setCenter/applet/update [POST]
  293. func AppletUpdate(c *gin.Context) {
  294. var req md.AppletUpdateReq
  295. err := c.ShouldBindJSON(&req)
  296. if err != nil {
  297. err = validate.HandleValidateErr(err)
  298. err1 := err.(e.E)
  299. e.OutErr(c, err1.Code, err1.Error())
  300. return
  301. }
  302. masterId := svc.GetMasterId(c)
  303. // 1、查找对应 user_wx_applet_list 记录
  304. userWxAppletListDb := implement.NewUserWxAppletListDb(db.Db)
  305. UserWxAppletList, err := userWxAppletListDb.GetUserWxAppletList(masterId)
  306. if err != nil {
  307. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  308. return
  309. }
  310. if UserWxAppletList == nil {
  311. e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录")
  312. return
  313. }
  314. UserWxAppletList.Logo = req.Logo
  315. UserWxAppletList.Name = req.Name
  316. _, err = userWxAppletListDb.UpdateUserWxAppletList(UserWxAppletList, "logo", "name")
  317. if err != nil {
  318. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  319. return
  320. }
  321. e.OutSuc(c, "success", nil)
  322. return
  323. }
  324. // AppletDelete
  325. // @Summary 删除
  326. // @Tags 设置中心-小程序设置
  327. // @Description 小程序设置-删除
  328. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  329. // @Accept json
  330. // @Produce json
  331. // @Success 200 {string} "success"
  332. // @Failure 400 {object} md.Response "具体错误"
  333. // @Router /v1/banner/delete/{$id} [DELETE]
  334. func AppletDelete(c *gin.Context) {
  335. id := c.Param("id")
  336. masterId := svc.GetMasterId(c)
  337. // 1、查找对应 user_wx_applet_list 记录
  338. userWxAppletListDb := implement.NewUserWxAppletListDb(db.Db)
  339. UserWxAppletList, err := userWxAppletListDb.GetUserWxAppletList(masterId)
  340. if err != nil {
  341. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  342. return
  343. }
  344. if UserWxAppletList == nil {
  345. e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录")
  346. return
  347. }
  348. _, err = userWxAppletListDb.UserWxAppletListDelete(id)
  349. if err != nil {
  350. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  351. return
  352. }
  353. e.OutSuc(c, "success", nil)
  354. return
  355. }
  356. // AppletAuthorize
  357. // @Summary 设置中心-基础设置-微信三方应用获取
  358. // @Tags 设置中心
  359. // @Description 设置中心-基础设置
  360. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  361. // @Accept json
  362. // @Produce json
  363. // @Success 200 {string} "微信授权界面url"
  364. // @Failure 400 {object} md.Response "具体错误"
  365. // @Router /api/setCenter/applet/authorize [GET]
  366. func AppletAuthorize(c *gin.Context) {
  367. masterId := svc.GetMasterId(c)
  368. url := "http://super.advertisement.dengbiao.top/api/wxOpen/getPreAuthCode?master_id=" + masterId
  369. if cfg.Prd {
  370. url = "http://ad.zhios.cn/api/wxOpen/getPreAuthCode?master_id=" + masterId
  371. }
  372. e.OutSuc(c, map[string]string{
  373. "url": url,
  374. }, nil)
  375. return
  376. }
  377. // AppletUnauthorized
  378. // @Summary 设置中心-基础设置-微信三方应用获取
  379. // @Tags 设置中心
  380. // @Description 设置中心-基础设置
  381. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  382. // @Accept json
  383. // @Produce json
  384. // @Success 200 {string} "success"
  385. // @Failure 400 {object} md.Response "具体错误"
  386. // @Router /api/setCenter/applet/unauthorized [GET]
  387. func AppletUnauthorized(c *gin.Context) {
  388. appId := c.DefaultQuery("app_id", "")
  389. masterId := svc.GetMasterId(c)
  390. // 1、查找对应 user_wx_applet_list 记录
  391. userWxAppletListDb := implement.NewUserWxAppletListDb(db.Db)
  392. UserWxAppletList, err := userWxAppletListDb.GetUserWxAppletList(masterId)
  393. if err != nil {
  394. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  395. return
  396. }
  397. if UserWxAppletList == nil {
  398. e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录")
  399. return
  400. }
  401. wxOpenThirdPartyAppListDb := implement.NewWxOpenThirdPartyAppListDb(db.Db)
  402. wxOpenThirdPartyAppList, err := wxOpenThirdPartyAppListDb.GetWxOpenThirdPartyAppList(utils.StrToInt(masterId))
  403. if err != nil {
  404. e.OutErr(c, e.ERR, err.Error())
  405. return
  406. }
  407. if wxOpenThirdPartyAppList == nil {
  408. e.OutErr(c, e.ERR_NOT_FAN, "未查询到对应三方应用记录")
  409. return
  410. }
  411. wxApiService, err := wechat.NewWxApiService(masterId, wxOpenThirdPartyAppList.Appid, wxOpenThirdPartyAppList.AppSecret)
  412. if err != nil {
  413. e.OutErr(c, e.ERR, err.Error())
  414. return
  415. }
  416. err = wxApiService.DelAuthorize(appId)
  417. if err != nil {
  418. e.OutErr(c, e.ERR, err.Error())
  419. return
  420. }
  421. e.OutSuc(c, "success", nil)
  422. return
  423. }
  424. // ShareIndex
  425. // @Summary 邀请链接
  426. // @Tags 设置中心-邀请链接
  427. // @Description 邀请链接界面接口
  428. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  429. // @Accept json
  430. // @Produce json
  431. // @Success 200 {object} md.ShareIndexResp
  432. // @Failure 400 {object} md.Response "具体错误"
  433. // @Router /api/setCenter/share/index [GET]
  434. func ShareIndex(c *gin.Context) {
  435. masterId := svc.GetMasterId(c)
  436. agent := new(model.UserAppDomain)
  437. _, err := db.Db.Where("type =?", "agent").And("uuid =?", masterId).And("is_ssl =1").Get(agent)
  438. if err != nil {
  439. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  440. return
  441. }
  442. medium := new(model.UserAppDomain)
  443. _, err = db.Db.Where("type =?", "medium").And("uuid =?", masterId).And("is_ssl =1").Get(medium)
  444. if err != nil {
  445. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  446. return
  447. }
  448. agentDomain := ""
  449. if agent != nil {
  450. agentDomain = agent.Domain
  451. }
  452. mediumDomain := ""
  453. if medium != nil {
  454. mediumDomain = medium.Domain
  455. }
  456. e.OutSuc(c, md.ShareIndexResp{
  457. MasterId: masterId,
  458. AgentDomain: "http://" + agentDomain,
  459. MediumDomain: "http://" + mediumDomain,
  460. }, nil)
  461. return
  462. }
  463. // SetMob
  464. // @Summary mob设置
  465. // @Tags 设置中心-基础设置
  466. // @Description 基础设置-mob设置
  467. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  468. // @Accept json
  469. // @Produce json
  470. // @Param args body md.SetMobReq true "请求参数"
  471. // @Success 200 {string} "success"
  472. // @Failure 400 {object} md.Response "具体错误"
  473. // @Router /api/setCenter/basic/setMob [POST]
  474. func SetMob(c *gin.Context) {
  475. var req md.SetMobReq
  476. err := c.ShouldBindJSON(&req)
  477. if err != nil {
  478. err = validate.HandleValidateErr(err)
  479. err1 := err.(e.E)
  480. e.OutErr(c, err1.Code, err1.Error())
  481. return
  482. }
  483. masterId := svc.GetMasterId(c)
  484. engine := db.DBs[masterId]
  485. sysCfgDb := implement2.NewSysCfgDb(engine, masterId)
  486. sysCfgDb.SysCfgUpdate("mob_app_key", req.MobAppKey)
  487. sysCfgDb.SysCfgUpdate("mob_app_secret", req.MobAppSecret)
  488. svc.ClearRedis(c, masterId, "mob_app_key")
  489. svc.ClearRedis(c, masterId, "mob_app_secret")
  490. svc.ClearAllRedis(c, masterId)
  491. e.OutSuc(c, "success", nil)
  492. return
  493. }
  494. // GetMob
  495. // @Summary mob获取
  496. // @Tags 设置中心-基础设置
  497. // @Description 基础设置-mob获取
  498. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  499. // @Accept json
  500. // @Produce json
  501. // @Success 200 {object} md.SetOssResp
  502. // @Failure 400 {object} md.Response "具体错误"
  503. // @Router /api/setCenter/basic/getMob [GET]
  504. func GetMob(c *gin.Context) {
  505. masterId := svc.GetMasterId(c)
  506. engine := db.DBs[masterId]
  507. sysCfgDb := implement2.NewSysCfgDb(engine, masterId)
  508. res := sysCfgDb.SysCfgFindWithDb("mob_app_key", "mob_app_secret")
  509. e.OutSuc(c, md.SetMobResp{
  510. Data: md.SetMobReq{
  511. MobAppSecret: res["mob_app_secret"],
  512. MobAppKey: res["mob_app_key"],
  513. },
  514. }, nil)
  515. return
  516. }
  517. // SetLogo
  518. // @Summary logo设置
  519. // @Tags 设置中心-基础设置
  520. // @Description 基础设置-logo设置
  521. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  522. // @Accept json
  523. // @Produce json
  524. // @Param args body md.SetLogoReq true "请求参数"
  525. // @Success 200 {string} "success"
  526. // @Failure 400 {object} md.Response "具体错误"
  527. // @Router /api/setCenter/basic/setLogo [POST]
  528. func SetLogo(c *gin.Context) {
  529. var req md.SetLogoReq
  530. err := c.ShouldBindJSON(&req)
  531. if err != nil {
  532. err = validate.HandleValidateErr(err)
  533. err1 := err.(e.E)
  534. e.OutErr(c, err1.Code, err1.Error())
  535. return
  536. }
  537. masterId := svc.GetMasterId(c)
  538. engine := db.DBs[masterId]
  539. sysCfgDb := implement2.NewSysCfgDb(engine, masterId)
  540. sysCfgDb.SysCfgUpdate("medium_logo", req.MediumLogo)
  541. sysCfgDb.SysCfgUpdate("agent_logo", req.AgentLogo)
  542. sysCfgDb.SysCfgUpdate("medium_login_logo", req.MediumLoginLogo)
  543. sysCfgDb.SysCfgUpdate("agent_login_logo", req.AgentLoginLogo)
  544. svc.ClearRedis(c, masterId, "medium_logo")
  545. svc.ClearRedis(c, masterId, "agent_logo")
  546. svc.ClearRedis(c, masterId, "medium_login_logo")
  547. svc.ClearRedis(c, masterId, "agent_login_logo")
  548. svc.ClearAllRedis(c, masterId)
  549. e.OutSuc(c, "success", nil)
  550. return
  551. }
  552. // GetLogo
  553. // @Summary logo获取
  554. // @Tags 设置中心-基础设置
  555. // @Description 基础设置-logo获取
  556. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  557. // @Accept json
  558. // @Produce json
  559. // @Success 200 {object} md.SetLogoResp
  560. // @Failure 400 {object} md.Response "具体错误"
  561. // @Router /api/setCenter/basic/getLogo [GET]
  562. func GetLogo(c *gin.Context) {
  563. masterId := svc.GetMasterId(c)
  564. engine := db.DBs[masterId]
  565. sysCfgDb := implement2.NewSysCfgDb(engine, masterId)
  566. res := sysCfgDb.SysCfgFindWithDb("medium_logo", "agent_logo", "medium_login_logo", "agent_login_logo")
  567. e.OutSuc(c, md.SetLogoResp{
  568. Data: md.SetLogoReq{
  569. MediumLogo: res["medium_logo"],
  570. AgentLogo: res["agent_logo"],
  571. MediumLoginLogo: res["medium_login_logo"],
  572. AgentLoginLogo: res["agent_login_logo"],
  573. },
  574. }, nil)
  575. return
  576. }
  577. // SetSeo
  578. // @Summary Seo设置
  579. // @Tags 设置中心-基础设置
  580. // @Description 基础设置-logo设置
  581. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  582. // @Accept json
  583. // @Produce json
  584. // @Param args body md.SetSeoReq true "请求参数"
  585. // @Success 200 {string} "success"
  586. // @Failure 400 {object} md.Response "具体错误"
  587. // @Router /api/setCenter/basic/setSeo [POST]
  588. func SetSeo(c *gin.Context) {
  589. var req md.SetSeoReq
  590. err := c.ShouldBindJSON(&req)
  591. if err != nil {
  592. err = validate.HandleValidateErr(err)
  593. err1 := err.(e.E)
  594. e.OutErr(c, err1.Code, err1.Error())
  595. return
  596. }
  597. masterId := svc.GetMasterId(c)
  598. engine := db.DBs[masterId]
  599. sysCfgDb := implement2.NewSysCfgDb(engine, masterId)
  600. sysCfgDb.SysCfgUpdate("seo_medium_title", req.SeoMediumTitle)
  601. sysCfgDb.SysCfgUpdate("seo_agent_title", req.SeoAgentTitle)
  602. sysCfgDb.SysCfgUpdate("seo_platform_title", req.SeoPlatformTitle)
  603. svc.ClearRedis(c, masterId, "seo_medium_title")
  604. svc.ClearRedis(c, masterId, "seo_agent_title")
  605. svc.ClearRedis(c, masterId, "seo_platform_title")
  606. sysCfgDb.SysCfgUpdate("seo_medium_logo", req.SeoMediumLogo)
  607. sysCfgDb.SysCfgUpdate("seo_agent_logo", req.SeoAgentLogo)
  608. sysCfgDb.SysCfgUpdate("seo_platform_logo", req.SeoPlatformLogo)
  609. svc.ClearRedis(c, masterId, "seo_medium_logo")
  610. svc.ClearRedis(c, masterId, "seo_agent_logo")
  611. svc.ClearRedis(c, masterId, "seo_platform_logo")
  612. svc.ClearAllRedis(c, masterId)
  613. e.OutSuc(c, "success", nil)
  614. return
  615. }
  616. // GetSeo
  617. // @Summary Seo获取
  618. // @Tags 设置中心-基础设置
  619. // @Description 基础设置-logo获取
  620. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  621. // @Accept json
  622. // @Produce json
  623. // @Success 200 {object} md.SetSeoResp
  624. // @Failure 400 {object} md.Response "具体错误"
  625. // @Router /api/setCenter/basic/getSeo [GET]
  626. func GetSeo(c *gin.Context) {
  627. masterId := svc.GetMasterId(c)
  628. engine := db.DBs[masterId]
  629. sysCfgDb := implement2.NewSysCfgDb(engine, masterId)
  630. res := sysCfgDb.SysCfgFindWithDb("seo_medium_logo", "seo_agent_logo", "seo_platform_logo", "seo_medium_title", "seo_agent_title", "seo_platform_title")
  631. e.OutSuc(c, md.SetSeoResp{
  632. Data: md.SetSeoReq{
  633. SeoMediumTitle: res["seo_medium_title"],
  634. SeoAgentTitle: res["seo_agent_title"],
  635. SeoPlatformTitle: res["seo_platform_title"],
  636. SeoMediumLogo: res["seo_medium_logo"],
  637. SeoAgentLogo: res["seo_agent_logo"],
  638. SeoPlatformLogo: res["seo_platform_logo"],
  639. },
  640. }, nil)
  641. return
  642. }
  643. // AppletGetBlackList
  644. // @Summary 获取屏蔽的广告主
  645. // @Tags 设置中心-小程序设置-屏蔽规则
  646. // @Description 小程序设置-屏蔽规则-获取屏蔽的广告主
  647. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  648. // @Accept json
  649. // @Produce json
  650. // @Param args body md.AppletGetBlackListReq true "请求参数"
  651. // @Success 200 {object} md2.AgencyGetBlackListResp
  652. // @Failure 400 {object} md.Response "具体错误"
  653. // @Router /api/setCenter/basic/applet/shieldRules/getBlackList [POST]
  654. func AppletGetBlackList(c *gin.Context) {
  655. var req md.AppletGetBlackListReq
  656. err := c.ShouldBindJSON(&req)
  657. if err != nil {
  658. err = validate.HandleValidateErr(err)
  659. err1 := err.(e.E)
  660. e.OutErr(c, err1.Code, err1.Error())
  661. return
  662. }
  663. masterId := svc.GetMasterId(c)
  664. wxOpenThirdPartyAppListDb := implement.NewWxOpenThirdPartyAppListDb(db.Db)
  665. wxOpenThirdPartyAppList, err := wxOpenThirdPartyAppListDb.GetWxOpenThirdPartyAppList(utils.StrToInt(masterId))
  666. if err != nil {
  667. e.OutErr(c, e.ERR, err.Error())
  668. return
  669. }
  670. if wxOpenThirdPartyAppList == nil {
  671. e.OutErr(c, e.ERR_NOT_FAN, "未查询到对应三方应用记录")
  672. return
  673. }
  674. wxApiService, err := wechat.NewWxApiService(masterId, wxOpenThirdPartyAppList.Appid, wxOpenThirdPartyAppList.AppSecret)
  675. if err != nil {
  676. e.OutErr(c, e.ERR, err.Error())
  677. return
  678. }
  679. var resp md2.AgencyGetBlackListResp
  680. err, resp = wxApiService.GetBlackList(req.Appid)
  681. if err != nil {
  682. e.OutErr(c, e.ERR, err.Error())
  683. return
  684. }
  685. e.OutSuc(c, resp, nil)
  686. return
  687. }
  688. // AppletAddBlackList
  689. // @Summary 添加屏蔽的广告主
  690. // @Tags 设置中心-小程序设置-屏蔽规则
  691. // @Description 小程序设置-屏蔽规则-添加屏蔽的广告主
  692. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  693. // @Accept json
  694. // @Produce json
  695. // @Param args body md.AppletAddBlackListReq true "请求参数"
  696. // @Success 200 {string} "success"
  697. // @Failure 400 {object} md.Response "具体错误"
  698. // @Router /api/setCenter/basic/applet/shieldRules/addBlackList [POST]
  699. func AppletAddBlackList(c *gin.Context) {
  700. var req md.AppletAddBlackListReq
  701. err := c.ShouldBindJSON(&req)
  702. if err != nil {
  703. err = validate.HandleValidateErr(err)
  704. err1 := err.(e.E)
  705. e.OutErr(c, err1.Code, err1.Error())
  706. return
  707. }
  708. masterId := svc.GetMasterId(c)
  709. wxOpenThirdPartyAppListDb := implement.NewWxOpenThirdPartyAppListDb(db.Db)
  710. wxOpenThirdPartyAppList, err := wxOpenThirdPartyAppListDb.GetWxOpenThirdPartyAppList(utils.StrToInt(masterId))
  711. if err != nil {
  712. e.OutErr(c, e.ERR, err.Error())
  713. return
  714. }
  715. if wxOpenThirdPartyAppList == nil {
  716. e.OutErr(c, e.ERR_NOT_FAN, "未查询到对应三方应用记录")
  717. return
  718. }
  719. wxApiService, err := wechat.NewWxApiService(masterId, wxOpenThirdPartyAppList.Appid, wxOpenThirdPartyAppList.AppSecret)
  720. if err != nil {
  721. e.OutErr(c, e.ERR, err.Error())
  722. return
  723. }
  724. listStr, _ := json.Marshal([]interface{}{
  725. map[string]interface{}{
  726. "type": req.Kind,
  727. "id": req.Id,
  728. },
  729. })
  730. err = wxApiService.SetBlackList(req.Appid, 1, string(listStr))
  731. if err != nil {
  732. e.OutErr(c, e.ERR, err.Error())
  733. return
  734. }
  735. e.OutSuc(c, "success", nil)
  736. return
  737. }
  738. // AppletDelBlackList
  739. // @Summary 删除屏蔽的广告主
  740. // @Tags 设置中心-小程序设置-屏蔽规则
  741. // @Description 小程序设置-屏蔽规则-删除屏蔽的广告主
  742. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  743. // @Accept json
  744. // @Produce json
  745. // @Param args body md.AppletDelBlackListReq true "请求参数"
  746. // @Success 200 {string} "success"
  747. // @Failure 400 {object} md.Response "具体错误"
  748. // @Router /api/setCenter/basic/applet/shieldRules/delBlackList [POST]
  749. func AppletDelBlackList(c *gin.Context) {
  750. var req md.AppletDelBlackListReq
  751. err := c.ShouldBindJSON(&req)
  752. if err != nil {
  753. err = validate.HandleValidateErr(err)
  754. err1 := err.(e.E)
  755. e.OutErr(c, err1.Code, err1.Error())
  756. return
  757. }
  758. masterId := svc.GetMasterId(c)
  759. wxOpenThirdPartyAppListDb := implement.NewWxOpenThirdPartyAppListDb(db.Db)
  760. wxOpenThirdPartyAppList, err := wxOpenThirdPartyAppListDb.GetWxOpenThirdPartyAppList(utils.StrToInt(masterId))
  761. if err != nil {
  762. e.OutErr(c, e.ERR, err.Error())
  763. return
  764. }
  765. if wxOpenThirdPartyAppList == nil {
  766. e.OutErr(c, e.ERR_NOT_FAN, "未查询到对应三方应用记录")
  767. return
  768. }
  769. wxApiService, err := wechat.NewWxApiService(masterId, wxOpenThirdPartyAppList.Appid, wxOpenThirdPartyAppList.AppSecret)
  770. if err != nil {
  771. e.OutErr(c, e.ERR, err.Error())
  772. return
  773. }
  774. listStr, _ := json.Marshal([]interface{}{
  775. map[string]interface{}{
  776. "type": req.Kind,
  777. "id": req.Id,
  778. },
  779. })
  780. err = wxApiService.SetBlackList(req.Appid, 2, string(listStr))
  781. if err != nil {
  782. e.OutErr(c, e.ERR, err.Error())
  783. return
  784. }
  785. e.OutSuc(c, "success", nil)
  786. return
  787. }
  788. // AppletGetAmsCategoryBlackList
  789. // @Summary 获取行业屏蔽信息
  790. // @Tags 设置中心-小程序设置-屏蔽规则
  791. // @Description 小程序设置-屏蔽规则-获取行业屏蔽信息
  792. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  793. // @Accept json
  794. // @Produce json
  795. // @Param args body md.AppletGetAmsCategoryBlackListReq true "请求参数"
  796. // @Success 200 {object} md.AppletGetAmsCategoryBlackListResp
  797. // @Failure 400 {object} md.Response "具体错误"
  798. // @Router /api/setCenter/basic/applet/shieldRules/getAmsCategoryBlackList [POST]
  799. func AppletGetAmsCategoryBlackList(c *gin.Context) {
  800. var req md.AppletGetAmsCategoryBlackListReq
  801. err := c.ShouldBindJSON(&req)
  802. if err != nil {
  803. err = validate.HandleValidateErr(err)
  804. err1 := err.(e.E)
  805. e.OutErr(c, err1.Code, err1.Error())
  806. return
  807. }
  808. masterId := svc.GetMasterId(c)
  809. wxOpenThirdPartyAppListDb := implement.NewWxOpenThirdPartyAppListDb(db.Db)
  810. wxOpenThirdPartyAppList, err := wxOpenThirdPartyAppListDb.GetWxOpenThirdPartyAppList(utils.StrToInt(masterId))
  811. if err != nil {
  812. e.OutErr(c, e.ERR, err.Error())
  813. return
  814. }
  815. if wxOpenThirdPartyAppList == nil {
  816. e.OutErr(c, e.ERR_NOT_FAN, "未查询到对应三方应用记录")
  817. return
  818. }
  819. wxApiService, err := wechat.NewWxApiService(masterId, wxOpenThirdPartyAppList.Appid, wxOpenThirdPartyAppList.AppSecret)
  820. if err != nil {
  821. e.OutErr(c, e.ERR, err.Error())
  822. return
  823. }
  824. var data md2.GetAmsCategoryBlackListResp
  825. err, data = wxApiService.GetAmsCategoryBlackList(req.Appid)
  826. if err != nil {
  827. e.OutErr(c, e.ERR, err.Error())
  828. return
  829. }
  830. var resp md.AppletGetAmsCategoryBlackListResp
  831. amsCategoryArr := strings.Split(data.AmsCategory, "|")
  832. for _, v := range amsCategoryArr {
  833. resp.CheckedAmsCategory = append(resp.CheckedAmsCategory, struct {
  834. Value string `json:"value" example:"行业标识符"`
  835. Name string `json:"name" example:"行业名称"`
  836. }{
  837. Value: v,
  838. Name: enum.AmsCategory.String(enum.AmsCategory(v)),
  839. })
  840. }
  841. resp.AllAmsCategory = []struct {
  842. Value string `json:"value" example:"行业标识符"`
  843. Name string `json:"name" example:"行业名称"`
  844. }{
  845. {
  846. Value: enum.AmsCategoryForChess,
  847. Name: enum.AmsCategory.String(enum.AmsCategoryForChess),
  848. },
  849. {
  850. Value: enum.AmsCategoryForAdultSupplies,
  851. Name: enum.AmsCategory.String(enum.AmsCategoryForAdultSupplies),
  852. },
  853. {
  854. Value: enum.AmsCategoryForMEDICALHEALTH,
  855. Name: enum.AmsCategory.String(enum.AmsCategoryForMEDICALHEALTH),
  856. },
  857. {
  858. Value: enum.AmsCategoryForINSURANCE,
  859. Name: enum.AmsCategory.String(enum.AmsCategoryForINSURANCE),
  860. },
  861. {
  862. Value: enum.AmsCategoryForSECURITES,
  863. Name: enum.AmsCategory.String(enum.AmsCategoryForSECURITES),
  864. },
  865. {
  866. Value: enum.AmsCategoryForLOAN,
  867. Name: enum.AmsCategory.String(enum.AmsCategoryForLOAN),
  868. },
  869. {
  870. Value: enum.AmsCategoryForLIVINGSERVICESBEAUTY,
  871. Name: enum.AmsCategory.String(enum.AmsCategoryForLIVINGSERVICESBEAUTY),
  872. },
  873. {
  874. Value: enum.AmsCategoryForLIVINGSERVICESENTERTAINMENT,
  875. Name: enum.AmsCategory.String(enum.AmsCategoryForLIVINGSERVICESENTERTAINMENT),
  876. },
  877. {
  878. Value: enum.AmsCategoryForLIVINGSERVICESOTHERS,
  879. Name: enum.AmsCategory.String(enum.AmsCategoryForLIVINGSERVICESOTHERS),
  880. },
  881. {
  882. Value: enum.AmsCategoryForFOODINDUSTRY,
  883. Name: enum.AmsCategory.String(enum.AmsCategoryForFOODINDUSTRY),
  884. },
  885. {
  886. Value: enum.AmsCategoryForRETAILANDGENERALMERCHANDISE,
  887. Name: enum.AmsCategory.String(enum.AmsCategoryForRETAILANDGENERALMERCHANDISE),
  888. },
  889. {
  890. Value: enum.AmsCategoryForFOODANDDRINK,
  891. Name: enum.AmsCategory.String(enum.AmsCategoryForFOODANDDRINK),
  892. },
  893. {
  894. Value: enum.AmsCategoryForTECHNICALSERVICE,
  895. Name: enum.AmsCategory.String(enum.AmsCategoryForTECHNICALSERVICE),
  896. },
  897. }
  898. e.OutSuc(c, resp, nil)
  899. return
  900. }
  901. // AppletSetAmsCategoryBlackList
  902. // @Summary 设置行业屏蔽信息
  903. // @Tags 设置中心-小程序设置-屏蔽规则
  904. // @Description 小程序设置-屏蔽规则-设置行业屏蔽信息
  905. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  906. // @Accept json
  907. // @Produce json
  908. // @Param args body md.AppletSetAmsCategoryBlackListReq true "请求参数"
  909. // @Success 200 {string} "success"
  910. // @Failure 400 {object} md.Response "具体错误"
  911. // @Router /api/setCenter/basic/applet/shieldRules/setAmsCategoryBlackList [POST]
  912. func AppletSetAmsCategoryBlackList(c *gin.Context) {
  913. var req md.AppletSetAmsCategoryBlackListReq
  914. err := c.ShouldBindJSON(&req)
  915. if err != nil {
  916. err = validate.HandleValidateErr(err)
  917. err1 := err.(e.E)
  918. e.OutErr(c, err1.Code, err1.Error())
  919. return
  920. }
  921. masterId := svc.GetMasterId(c)
  922. wxOpenThirdPartyAppListDb := implement.NewWxOpenThirdPartyAppListDb(db.Db)
  923. wxOpenThirdPartyAppList, err := wxOpenThirdPartyAppListDb.GetWxOpenThirdPartyAppList(utils.StrToInt(masterId))
  924. if err != nil {
  925. e.OutErr(c, e.ERR, err.Error())
  926. return
  927. }
  928. if wxOpenThirdPartyAppList == nil {
  929. e.OutErr(c, e.ERR_NOT_FAN, "未查询到对应三方应用记录")
  930. return
  931. }
  932. wxApiService, err := wechat.NewWxApiService(masterId, wxOpenThirdPartyAppList.Appid, wxOpenThirdPartyAppList.AppSecret)
  933. if err != nil {
  934. e.OutErr(c, e.ERR, err.Error())
  935. return
  936. }
  937. amsCategory := strings.Join(req.CheckedAmsCategory, "|")
  938. err = wxApiService.SetAmsCategoryBlackList(req.Appid, amsCategory)
  939. if err != nil {
  940. e.OutErr(c, e.ERR, err.Error())
  941. return
  942. }
  943. e.OutSuc(c, "success", nil)
  944. return
  945. }