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

670 lines
23 KiB

  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. "applet/app/md"
  10. "applet/app/svc"
  11. "applet/app/utils"
  12. db "code.fnuoos.com/zhimeng/model.git/src"
  13. "code.fnuoos.com/zhimeng/model.git/src/super/implement"
  14. "code.fnuoos.com/zhimeng/model.git/src/super/model"
  15. "github.com/gin-gonic/gin"
  16. "time"
  17. )
  18. // SetOss
  19. // @Summary oss设置
  20. // @Tags 设置中心-基础设置
  21. // @Description 基础设置-oss设置
  22. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  23. // @Accept json
  24. // @Produce json
  25. // @Param args body md.SetOssReq true "请求参数"
  26. // @Success 200 {string} "success"
  27. // @Failure 400 {object} md.Response "具体错误"
  28. // @Router /api/setCenter/basic/setOss [POST]
  29. func SetOss(c *gin.Context) {
  30. var req md.SetOssReq
  31. err := c.ShouldBindJSON(&req)
  32. if err != nil {
  33. err = validate.HandleValidateErr(err)
  34. err1 := err.(e.E)
  35. e.OutErr(c, err1.Code, err1.Error())
  36. return
  37. }
  38. masterId := svc.GetMasterId(c)
  39. engine := db.DBs[masterId]
  40. sysCfgDb := implement2.NewSysCfgDb(engine, masterId)
  41. sysCfgDb.SysCfgUpdate(enum.FileAccessKey, req.FileAccessKey)
  42. sysCfgDb.SysCfgUpdate(enum.FileSecretKey, req.FileSecretKey)
  43. sysCfgDb.SysCfgUpdate(enum.FileBucketHost, req.FileBucketHost)
  44. sysCfgDb.SysCfgUpdate(enum.FileBucketRegion, req.FileBucketRegion)
  45. sysCfgDb.SysCfgUpdate(enum.FileBucket, req.FileBucket)
  46. svc.ClearRedis(c, masterId, enum.FileAccessKey)
  47. svc.ClearRedis(c, masterId, enum.FileSecretKey)
  48. svc.ClearRedis(c, masterId, enum.FileBucketHost)
  49. svc.ClearRedis(c, masterId, enum.FileBucketRegion)
  50. svc.ClearRedis(c, masterId, enum.FileBucket)
  51. svc.ClearAllRedis(c, masterId)
  52. e.OutSuc(c, "success", nil)
  53. return
  54. }
  55. // GetOss
  56. // @Summary oss获取
  57. // @Tags 设置中心-基础设置
  58. // @Description 基础设置-oss获取
  59. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  60. // @Accept json
  61. // @Produce json
  62. // @Success 200 {object} md.SetOssResp
  63. // @Failure 400 {object} md.Response "具体错误"
  64. // @Router /api/setCenter/basic/getOss [GET]
  65. func GetOss(c *gin.Context) {
  66. masterId := svc.GetMasterId(c)
  67. engine := db.DBs[masterId]
  68. sysCfgDb := implement2.NewSysCfgDb(engine, masterId)
  69. res := sysCfgDb.SysCfgFindWithDb(enum.FileAccessKey, enum.FileSecretKey, enum.FileBucketHost, enum.FileBucketRegion, enum.FileBucket)
  70. e.OutSuc(c, md.SetOssResp{
  71. Data: md.SetOssReq{
  72. FileAccessKey: res[enum.FileAccessKey],
  73. FileSecretKey: res[enum.FileSecretKey],
  74. FileBucketHost: res[enum.FileBucketHost],
  75. FileBucketRegion: res[enum.FileBucketRegion],
  76. FileBucket: res[enum.FileBucket],
  77. },
  78. QiNiuBucketRegionList: md.QiNiuBucketRegionList,
  79. }, nil)
  80. return
  81. }
  82. // WxOpenSet
  83. // @Summary 微信三方应用设置
  84. // @Tags 设置中心-基础设置
  85. // @Description 基础设置-微信三方应用设置
  86. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  87. // @Accept json
  88. // @Produce json
  89. // @Param args body md.WxOpenSetReq true "请求参数"
  90. // @Success 200 {string} "success"
  91. // @Failure 400 {object} md.Response "具体错误"
  92. // @Router /api/setCenter/basic/wxOpenSet [POST]
  93. func WxOpenSet(c *gin.Context) {
  94. var req md.WxOpenSetReq
  95. err := c.ShouldBindJSON(&req)
  96. if err != nil {
  97. err = validate.HandleValidateErr(err)
  98. err1 := err.(e.E)
  99. e.OutErr(c, err1.Code, err1.Error())
  100. return
  101. }
  102. masterId := svc.GetMasterId(c)
  103. //1、查找对应 wx_open_third_party_app_list 记录
  104. wxOpenThirdPartyAppListDb := implement.NewWxOpenThirdPartyAppListDb(db.Db)
  105. UserWxAppletList, err := wxOpenThirdPartyAppListDb.GetWxOpenThirdPartyAppList(utils.StrToInt(masterId))
  106. if err != nil {
  107. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  108. return
  109. }
  110. if UserWxAppletList == nil {
  111. UserWxAppletList = &model.WxOpenThirdPartyAppList{
  112. Uuid: utils.StrToInt(masterId),
  113. Token: req.Token,
  114. AesKey: req.AesKey,
  115. Appid: req.Appid,
  116. AppSecret: req.AppSecret,
  117. ComponentVerifyTicket: "",
  118. ComponentAccessToken: "",
  119. CreateAt: time.Now().Format("2006-01-02 15:04:05"),
  120. UpdateAt: time.Now().Format("2006-01-02 15:04:05"),
  121. }
  122. _, err = wxOpenThirdPartyAppListDb.WxOpenThirdPartyAppListInsert(UserWxAppletList)
  123. if err != nil {
  124. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  125. return
  126. }
  127. } else {
  128. UserWxAppletList.Token = req.Token
  129. UserWxAppletList.AesKey = req.AesKey
  130. UserWxAppletList.Appid = req.Appid
  131. UserWxAppletList.AppSecret = req.AppSecret
  132. _, err = wxOpenThirdPartyAppListDb.UpdateWxOpenThirdPartyAppList(UserWxAppletList,
  133. "token", "aes_key", "appid", "app_secret")
  134. if err != nil {
  135. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  136. return
  137. }
  138. }
  139. e.OutSuc(c, "success", nil)
  140. return
  141. }
  142. // WxOpenGet
  143. // @Summary 微信三方应用获取
  144. // @Tags 设置中心-基础设置
  145. // @Description 基础设置-微信三方应用获取
  146. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  147. // @Accept json
  148. // @Produce json
  149. // @Success 200 {object} md.WxOpenGetResp
  150. // @Failure 400 {object} md.Response "具体错误"
  151. // @Router /api/setCenter/basic/wxOpenGet [GET]
  152. func WxOpenGet(c *gin.Context) {
  153. masterId := svc.GetMasterId(c)
  154. //1、查找对应 wx_open_third_party_app_list 记录
  155. wxOpenThirdPartyAppListDb := implement.NewWxOpenThirdPartyAppListDb(db.Db)
  156. UserWxAppletList, err := wxOpenThirdPartyAppListDb.GetWxOpenThirdPartyAppList(utils.StrToInt(masterId))
  157. if err != nil {
  158. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  159. return
  160. }
  161. if UserWxAppletList == nil {
  162. UserWxAppletList = &model.WxOpenThirdPartyAppList{
  163. Uuid: utils.StrToInt(masterId),
  164. Token: "",
  165. AesKey: "",
  166. Appid: "",
  167. AppSecret: "",
  168. ComponentVerifyTicket: "",
  169. ComponentAccessToken: "",
  170. CreateAt: time.Now().Format("2006-01-02 15:04:05"),
  171. UpdateAt: time.Now().Format("2006-01-02 15:04:05"),
  172. }
  173. _, err = wxOpenThirdPartyAppListDb.WxOpenThirdPartyAppListInsert(UserWxAppletList)
  174. if err != nil {
  175. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  176. return
  177. }
  178. }
  179. sysCfgDb := implement2.NewSysCfgDb(db.Db, "")
  180. res := sysCfgDb.SysCfgFindWithDb(enum.WxOpenAppletServerDomain, enum.WxOpenAuthorizationEventReceivingConfiguration,
  181. enum.WxOpenDomainOfTheInitiatingPageForLoginAuthorization, enum.WxOpenMessageAndEventReceptionConfiguration, enum.WxOpenWhiteListIp)
  182. e.OutSuc(c, md.WxOpenGetResp{
  183. Token: UserWxAppletList.Token,
  184. AesKey: UserWxAppletList.AesKey,
  185. Appid: UserWxAppletList.Appid,
  186. AppSecret: UserWxAppletList.AppSecret,
  187. WxOpenAppletServerDomain: res[enum.WxOpenAppletServerDomain],
  188. WxOpenAuthorizationEventReceivingConfiguration: res[enum.WxOpenAuthorizationEventReceivingConfiguration],
  189. WxOpenDomainOfTheInitiatingPageForLoginAuthorization: res[enum.WxOpenDomainOfTheInitiatingPageForLoginAuthorization],
  190. WxOpenMessageAndEventReceptionConfiguration: res[enum.WxOpenMessageAndEventReceptionConfiguration],
  191. WxOpenWhiteListIp: res[enum.WxOpenWhiteListIp],
  192. }, nil)
  193. return
  194. }
  195. type WxOpenThirdPartyAppList struct {
  196. Id int `json:"id" xorm:"not null pk autoincr unique(IDX_UUID_TYPE) INT(11)"`
  197. Uuid int `json:"uuid" xorm:"not null comment('站长id') index unique(IDX_UUID_TYPE) INT(10)"`
  198. Token string `json:"token" xorm:"not null default '' comment('消息校验Token') VARCHAR(255)"`
  199. AesKey string `json:"aes_key" xorm:"not null default '' comment('消息加解密Key') VARCHAR(255)"`
  200. Appid string `json:"appid" xorm:"not null default '' comment('appid') CHAR(50)"`
  201. AppSecret string `json:"app_secret" xorm:"not null default '' comment('appSecret') VARCHAR(255)"`
  202. ComponentVerifyTicket string `json:"component_verify_ticket" xorm:"not null default '' comment('验证票据') VARCHAR(255)"`
  203. ComponentAccessToken string `json:"component_access_token" xorm:"not null default '' comment('接口令牌') VARCHAR(255)"`
  204. CreateAt string `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"`
  205. UpdateAt string `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"`
  206. }
  207. // AppletList
  208. // @Summary 列表
  209. // @Tags 设置中心-小程序设置
  210. // @Description 小程序设置-列表
  211. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  212. // @Accept json
  213. // @Produce json
  214. // @Success 200 {object} WxOpenThirdPartyAppList
  215. // @Failure 400 {object} md.Response "具体错误"
  216. // @Router /api/setCenter/applet/list [GET]
  217. func AppletList(c *gin.Context) {
  218. masterId := svc.GetMasterId(c)
  219. //1、查找对应 user_wx_applet_list 记录
  220. userWxAppletListDb := implement.NewUserWxAppletListDb(db.Db)
  221. UserWxAppletList, err := userWxAppletListDb.GetUserWxAppletList(masterId)
  222. if err != nil {
  223. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  224. return
  225. }
  226. e.OutSuc(c, UserWxAppletList, nil)
  227. return
  228. }
  229. // AppletAdd
  230. // @Summary 新增
  231. // @Tags 设置中心-小程序设置
  232. // @Description 小程序设置-新增
  233. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  234. // @Accept json
  235. // @Produce json
  236. // @Param args body md.AppletAddReq true "请求参数"
  237. // @Success 200 {string} "success"
  238. // @Failure 400 {object} md.Response "具体错误"
  239. // @Router /api/setCenter/applet/add [POST]
  240. func AppletAdd(c *gin.Context) {
  241. var req md.AppletAddReq
  242. err := c.ShouldBindJSON(&req)
  243. if err != nil {
  244. err = validate.HandleValidateErr(err)
  245. err1 := err.(e.E)
  246. e.OutErr(c, err1.Code, err1.Error())
  247. return
  248. }
  249. masterId := svc.GetMasterId(c)
  250. //1、查找对应 user_wx_applet_list 记录
  251. userWxAppletListDb := implement.NewUserWxAppletListDb(db.Db)
  252. UserWxAppletList, err := userWxAppletListDb.GetUserWxAppletList(masterId)
  253. if err != nil {
  254. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  255. return
  256. }
  257. if UserWxAppletList != nil {
  258. e.OutErr(c, e.ERR, "当前仅支持单个小程序")
  259. return
  260. }
  261. _, err = userWxAppletListDb.UserWxAppletListInsert(&model.UserWxAppletList{
  262. Name: req.Name,
  263. Logo: req.Logo,
  264. Appid: req.Appid,
  265. OriginalId: req.OriginalId,
  266. AuthorizerRefreshToken: "",
  267. IsAuth: 0,
  268. Uuid: masterId,
  269. CreateAt: time.Now().Format("2006-01-02 15:04:05"),
  270. UpdateAt: time.Now().Format("2006-01-02 15:04:05"),
  271. })
  272. if err != nil {
  273. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  274. return
  275. }
  276. e.OutSuc(c, "success", nil)
  277. return
  278. }
  279. // AppletUpdate
  280. // @Summary 更新
  281. // @Tags 设置中心-小程序设置
  282. // @Description 小程序设置-更新
  283. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  284. // @Accept json
  285. // @Produce json
  286. // @Param args body md.AppletUpdateReq true "请求参数"
  287. // @Success 200 {string} "success"
  288. // @Failure 400 {object} md.Response "具体错误"
  289. // @Router /api/setCenter/applet/update [POST]
  290. func AppletUpdate(c *gin.Context) {
  291. var req md.AppletUpdateReq
  292. err := c.ShouldBindJSON(&req)
  293. if err != nil {
  294. err = validate.HandleValidateErr(err)
  295. err1 := err.(e.E)
  296. e.OutErr(c, err1.Code, err1.Error())
  297. return
  298. }
  299. masterId := svc.GetMasterId(c)
  300. //1、查找对应 user_wx_applet_list 记录
  301. userWxAppletListDb := implement.NewUserWxAppletListDb(db.Db)
  302. UserWxAppletList, err := userWxAppletListDb.GetUserWxAppletList(masterId)
  303. if err != nil {
  304. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  305. return
  306. }
  307. if UserWxAppletList == nil {
  308. e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录")
  309. return
  310. }
  311. UserWxAppletList.Logo = req.Logo
  312. UserWxAppletList.Name = req.Name
  313. _, err = userWxAppletListDb.UpdateUserWxAppletList(UserWxAppletList, "logo", "name")
  314. if err != nil {
  315. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  316. return
  317. }
  318. e.OutSuc(c, "success", nil)
  319. return
  320. }
  321. // AppletDelete
  322. // @Summary 删除
  323. // @Tags 设置中心-小程序设置
  324. // @Description 小程序设置-删除
  325. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  326. // @Accept json
  327. // @Produce json
  328. // @Success 200 {string} "success"
  329. // @Failure 400 {object} md.Response "具体错误"
  330. // @Router /v1/banner/delete/{$id} [DELETE]
  331. func AppletDelete(c *gin.Context) {
  332. id := c.Param("id")
  333. masterId := svc.GetMasterId(c)
  334. //1、查找对应 user_wx_applet_list 记录
  335. userWxAppletListDb := implement.NewUserWxAppletListDb(db.Db)
  336. UserWxAppletList, err := userWxAppletListDb.GetUserWxAppletList(masterId)
  337. if err != nil {
  338. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  339. return
  340. }
  341. if UserWxAppletList == nil {
  342. e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录")
  343. return
  344. }
  345. _, err = userWxAppletListDb.UserWxAppletListDelete(id)
  346. if err != nil {
  347. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  348. return
  349. }
  350. e.OutSuc(c, "success", nil)
  351. return
  352. }
  353. // AppletAuthorize
  354. // @Summary 设置中心-基础设置-微信三方应用获取
  355. // @Tags 设置中心
  356. // @Description 设置中心-基础设置
  357. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  358. // @Accept json
  359. // @Produce json
  360. // @Success 200 {string} "微信授权界面url"
  361. // @Failure 400 {object} md.Response "具体错误"
  362. // @Router /api/setCenter/applet/authorize [GET]
  363. func AppletAuthorize(c *gin.Context) {
  364. masterId := svc.GetMasterId(c)
  365. url := "http://super.advertisement.dengbiao.top/api/wxOpen/getPreAuthCode?master_id=" + masterId
  366. if cfg.Prd {
  367. url = "http://super.advertisement.dengbiao.top/api/wxOpen/getPreAuthCode?master_id=" + masterId
  368. }
  369. e.OutSuc(c, map[string]string{
  370. "url": url,
  371. }, nil)
  372. return
  373. }
  374. // AppletUnauthorized
  375. // @Summary 设置中心-基础设置-微信三方应用获取
  376. // @Tags 设置中心
  377. // @Description 设置中心-基础设置
  378. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  379. // @Accept json
  380. // @Produce json
  381. // @Success 200 {string} "success"
  382. // @Failure 400 {object} md.Response "具体错误"
  383. // @Router /api/setCenter/applet/unauthorized [GET]
  384. func AppletUnauthorized(c *gin.Context) {
  385. appId := c.DefaultQuery("app_id", "")
  386. masterId := svc.GetMasterId(c)
  387. //1、查找对应 user_wx_applet_list 记录
  388. userWxAppletListDb := implement.NewUserWxAppletListDb(db.Db)
  389. UserWxAppletList, err := userWxAppletListDb.GetUserWxAppletList(masterId)
  390. if err != nil {
  391. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  392. return
  393. }
  394. if UserWxAppletList == nil {
  395. e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录")
  396. return
  397. }
  398. wxOpenThirdPartyAppListDb := implement.NewWxOpenThirdPartyAppListDb(db.Db)
  399. wxOpenThirdPartyAppList, err := wxOpenThirdPartyAppListDb.GetWxOpenThirdPartyAppList(utils.StrToInt(masterId))
  400. if err != nil {
  401. e.OutErr(c, e.ERR, err.Error())
  402. return
  403. }
  404. if wxOpenThirdPartyAppList == nil {
  405. e.OutErr(c, e.ERR_NOT_FAN, "未查询到对应三方应用记录")
  406. return
  407. }
  408. wxApiService, err := wechat.NewWxApiService(masterId, wxOpenThirdPartyAppList.Appid, wxOpenThirdPartyAppList.AppSecret)
  409. if err != nil {
  410. e.OutErr(c, e.ERR, err.Error())
  411. return
  412. }
  413. err = wxApiService.DelAuthorize(appId)
  414. if err != nil {
  415. e.OutErr(c, e.ERR, err.Error())
  416. return
  417. }
  418. e.OutSuc(c, "success", nil)
  419. return
  420. }
  421. // ShareIndex
  422. // @Summary 邀请链接
  423. // @Tags 设置中心-邀请链接
  424. // @Description 邀请链接界面接口
  425. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  426. // @Accept json
  427. // @Produce json
  428. // @Success 200 {object} md.ShareIndexResp
  429. // @Failure 400 {object} md.Response "具体错误"
  430. // @Router /api/setCenter/share/index [GET]
  431. func ShareIndex(c *gin.Context) {
  432. masterId := svc.GetMasterId(c)
  433. agent := new(model.UserAppDomain)
  434. _, err := db.Db.Where("type =?", "agent").And("uuid =?", masterId).And("is_ssl =1").Get(agent)
  435. if err != nil {
  436. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  437. return
  438. }
  439. medium := new(model.UserAppDomain)
  440. _, err = db.Db.Where("type =?", "medium").And("uuid =?", masterId).And("is_ssl =1").Get(medium)
  441. if err != nil {
  442. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  443. return
  444. }
  445. agentDomain := ""
  446. if agent != nil {
  447. agentDomain = agent.Domain
  448. }
  449. mediumDomain := ""
  450. if medium != nil {
  451. mediumDomain = medium.Domain
  452. }
  453. e.OutSuc(c, md.ShareIndexResp{
  454. MasterId: masterId,
  455. AgentDomain: agentDomain,
  456. MediumDomain: mediumDomain,
  457. }, nil)
  458. return
  459. }
  460. // SetMob
  461. // @Summary mob设置
  462. // @Tags 设置中心-基础设置
  463. // @Description 基础设置-mob设置
  464. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  465. // @Accept json
  466. // @Produce json
  467. // @Param args body md.SetMobReq true "请求参数"
  468. // @Success 200 {string} "success"
  469. // @Failure 400 {object} md.Response "具体错误"
  470. // @Router /api/setCenter/basic/setMob [POST]
  471. func SetMob(c *gin.Context) {
  472. var req md.SetMobReq
  473. err := c.ShouldBindJSON(&req)
  474. if err != nil {
  475. err = validate.HandleValidateErr(err)
  476. err1 := err.(e.E)
  477. e.OutErr(c, err1.Code, err1.Error())
  478. return
  479. }
  480. masterId := svc.GetMasterId(c)
  481. engine := db.DBs[masterId]
  482. sysCfgDb := implement2.NewSysCfgDb(engine, masterId)
  483. sysCfgDb.SysCfgUpdate("mob_app_key", req.MobAppKey)
  484. sysCfgDb.SysCfgUpdate("mob_app_secret", req.MobAppSecret)
  485. svc.ClearRedis(c, masterId, "mob_app_key")
  486. svc.ClearRedis(c, masterId, "mob_app_secret")
  487. svc.ClearAllRedis(c, masterId)
  488. e.OutSuc(c, "success", nil)
  489. return
  490. }
  491. // GetMob
  492. // @Summary mob获取
  493. // @Tags 设置中心-基础设置
  494. // @Description 基础设置-mob获取
  495. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  496. // @Accept json
  497. // @Produce json
  498. // @Success 200 {object} md.SetOssResp
  499. // @Failure 400 {object} md.Response "具体错误"
  500. // @Router /api/setCenter/basic/getMob [GET]
  501. func GetMob(c *gin.Context) {
  502. masterId := svc.GetMasterId(c)
  503. engine := db.DBs[masterId]
  504. sysCfgDb := implement2.NewSysCfgDb(engine, masterId)
  505. res := sysCfgDb.SysCfgFindWithDb("mob_app_key", "mob_app_secret")
  506. e.OutSuc(c, md.SetMobResp{
  507. Data: md.SetMobReq{
  508. MobAppSecret: res["mob_app_secret"],
  509. MobAppKey: res["mob_app_key"],
  510. },
  511. }, nil)
  512. return
  513. }
  514. // SetLogo
  515. // @Summary logo设置
  516. // @Tags 设置中心-基础设置
  517. // @Description 基础设置-logo设置
  518. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  519. // @Accept json
  520. // @Produce json
  521. // @Param args body md.SetLogoReq true "请求参数"
  522. // @Success 200 {string} "success"
  523. // @Failure 400 {object} md.Response "具体错误"
  524. // @Router /api/setCenter/basic/setLogo [POST]
  525. func SetLogo(c *gin.Context) {
  526. var req md.SetLogoReq
  527. err := c.ShouldBindJSON(&req)
  528. if err != nil {
  529. err = validate.HandleValidateErr(err)
  530. err1 := err.(e.E)
  531. e.OutErr(c, err1.Code, err1.Error())
  532. return
  533. }
  534. masterId := svc.GetMasterId(c)
  535. engine := db.DBs[masterId]
  536. sysCfgDb := implement2.NewSysCfgDb(engine, masterId)
  537. sysCfgDb.SysCfgUpdate("medium_logo", req.MediumLogo)
  538. sysCfgDb.SysCfgUpdate("agent_logo", req.AgentLogo)
  539. sysCfgDb.SysCfgUpdate("medium_login_logo", req.MediumLoginLogo)
  540. sysCfgDb.SysCfgUpdate("agent_login_logo", req.AgentLoginLogo)
  541. svc.ClearRedis(c, masterId, "medium_logo")
  542. svc.ClearRedis(c, masterId, "agent_logo")
  543. svc.ClearRedis(c, masterId, "medium_login_logo")
  544. svc.ClearRedis(c, masterId, "agent_login_logo")
  545. svc.ClearAllRedis(c, masterId)
  546. e.OutSuc(c, "success", nil)
  547. return
  548. }
  549. // GetLogo
  550. // @Summary logo获取
  551. // @Tags 设置中心-基础设置
  552. // @Description 基础设置-logo获取
  553. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  554. // @Accept json
  555. // @Produce json
  556. // @Success 200 {object} md.SetLogoResp
  557. // @Failure 400 {object} md.Response "具体错误"
  558. // @Router /api/setCenter/basic/getLogo [GET]
  559. func GetLogo(c *gin.Context) {
  560. masterId := svc.GetMasterId(c)
  561. engine := db.DBs[masterId]
  562. sysCfgDb := implement2.NewSysCfgDb(engine, masterId)
  563. res := sysCfgDb.SysCfgFindWithDb("medium_logo", "agent_logo", "medium_login_logo", "agent_login_logo")
  564. e.OutSuc(c, md.SetLogoResp{
  565. Data: md.SetLogoReq{
  566. MediumLogo: res["medium_logo"],
  567. AgentLogo: res["agent_logo"],
  568. MediumLoginLogo: res["medium_login_logo"],
  569. AgentLoginLogo: res["agent_login_logo"],
  570. },
  571. }, nil)
  572. return
  573. }
  574. // SetSeo
  575. // @Summary Seo设置
  576. // @Tags 设置中心-基础设置
  577. // @Description 基础设置-logo设置
  578. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  579. // @Accept json
  580. // @Produce json
  581. // @Param args body md.SetSeoReq true "请求参数"
  582. // @Success 200 {string} "success"
  583. // @Failure 400 {object} md.Response "具体错误"
  584. // @Router /api/setCenter/basic/setSeo [POST]
  585. func SetSeo(c *gin.Context) {
  586. var req md.SetSeoReq
  587. err := c.ShouldBindJSON(&req)
  588. if err != nil {
  589. err = validate.HandleValidateErr(err)
  590. err1 := err.(e.E)
  591. e.OutErr(c, err1.Code, err1.Error())
  592. return
  593. }
  594. masterId := svc.GetMasterId(c)
  595. engine := db.DBs[masterId]
  596. sysCfgDb := implement2.NewSysCfgDb(engine, masterId)
  597. sysCfgDb.SysCfgUpdate("seo_medium_title", req.SeoMediumTitle)
  598. sysCfgDb.SysCfgUpdate("seo_agent_title", req.SeoAgentTitle)
  599. sysCfgDb.SysCfgUpdate("seo_platform_title", req.SeoPlatformTitle)
  600. svc.ClearRedis(c, masterId, "seo_medium_title")
  601. svc.ClearRedis(c, masterId, "seo_agent_title")
  602. svc.ClearRedis(c, masterId, "seo_platform_title")
  603. sysCfgDb.SysCfgUpdate("seo_medium_logo", req.SeoMediumLogo)
  604. sysCfgDb.SysCfgUpdate("seo_agent_logo", req.SeoAgentLogo)
  605. sysCfgDb.SysCfgUpdate("seo_platform_logo", req.SeoPlatformLogo)
  606. svc.ClearRedis(c, masterId, "seo_medium_logo")
  607. svc.ClearRedis(c, masterId, "seo_agent_logo")
  608. svc.ClearRedis(c, masterId, "seo_platform_logo")
  609. svc.ClearAllRedis(c, masterId)
  610. e.OutSuc(c, "success", nil)
  611. return
  612. }
  613. // GetSeo
  614. // @Summary Seo获取
  615. // @Tags 设置中心-基础设置
  616. // @Description 基础设置-logo获取
  617. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  618. // @Accept json
  619. // @Produce json
  620. // @Success 200 {object} md.SetSeoResp
  621. // @Failure 400 {object} md.Response "具体错误"
  622. // @Router /api/setCenter/basic/getSeo [GET]
  623. func GetSeo(c *gin.Context) {
  624. masterId := svc.GetMasterId(c)
  625. engine := db.DBs[masterId]
  626. sysCfgDb := implement2.NewSysCfgDb(engine, masterId)
  627. res := sysCfgDb.SysCfgFindWithDb("seo_medium_logo", "seo_agent_logo", "seo_platform_logo", "seo_medium_title", "seo_agent_title", "seo_platform_title")
  628. e.OutSuc(c, md.SetSeoResp{
  629. Data: md.SetSeoReq{
  630. SeoMediumTitle: res["seo_medium_title"],
  631. SeoAgentTitle: res["seo_agent_title"],
  632. SeoPlatformTitle: res["seo_platform_title"],
  633. SeoMediumLogo: res["seo_medium_logo"],
  634. SeoAgentLogo: res["seo_agent_logo"],
  635. SeoPlatformLogo: res["seo_platform_logo"],
  636. },
  637. }, nil)
  638. return
  639. }