banner.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "hongze/hongze_cygx/models"
  5. "hongze/hongze_cygx/services"
  6. )
  7. // Banner
  8. type BannerController struct {
  9. BaseAuthController
  10. }
  11. // @Title 列表
  12. // @Description 列表接口
  13. // @Success Ret=200 {object} cygx.CygxBannerListResp
  14. // @router /list [get]
  15. func (this *BannerController) List() {
  16. br := new(models.BaseResponse).Init()
  17. defer func() {
  18. this.Data["json"] = br
  19. this.ServeJSON()
  20. }()
  21. user := this.User
  22. if user == nil {
  23. br.Msg = "请登录"
  24. br.ErrMsg = "请登录,用户信息为空"
  25. br.Ret = 408
  26. return
  27. }
  28. resp := new(models.CygxBannerListResp)
  29. var condition string
  30. var pars []interface{}
  31. condition += " AND art.status = 1 ORDER BY art. list_type ASC , art.sort ASC "
  32. list, err := models.GetCygxBannerList(condition, pars, 0, 99999)
  33. if err != nil {
  34. br.Msg = "获取失败"
  35. br.ErrMsg = "获取失败,Err:" + err.Error()
  36. return
  37. }
  38. bannerImgList, err := models.GetCygxBannerImgList()
  39. if err != nil {
  40. br.Msg = "获取失败"
  41. br.ErrMsg = "获取失败,Err:" + err.Error()
  42. return
  43. }
  44. mapImg := make(map[int]string)
  45. for _, v := range bannerImgList {
  46. mapImg[v.ImgId] = v.IndexImg
  47. }
  48. for _, v := range list {
  49. v.IndexImg = mapImg[v.ImgId]
  50. v.BannerUrlResp = services.GetBannerUrlBody(v.Link)
  51. }
  52. resp.List = list
  53. br.Ret = 200
  54. br.Success = true
  55. br.Msg = "获取成功"
  56. br.Data = resp
  57. }
  58. // @Title 记录点击信息
  59. // @Description 记录点击信息
  60. // @Param request body cygx.CygxBannerIdReq true "type json string"
  61. // @Success 200 Ret=200 发布成功
  62. // @router /add/history [post]
  63. func (this *BannerController) History() {
  64. br := new(models.BaseResponse).Init()
  65. defer func() {
  66. this.Data["json"] = br
  67. this.ServeJSON()
  68. }()
  69. user := this.User
  70. if user == nil {
  71. br.Msg = "请登录"
  72. br.ErrMsg = "请登录,用户信息为空"
  73. br.Ret = 408
  74. return
  75. }
  76. var req models.CygxBannerIdReq
  77. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  78. if err != nil {
  79. br.Msg = "参数解析异常!"
  80. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  81. return
  82. }
  83. bannerId := req.BannerId
  84. if bannerId == 0 {
  85. br.Msg = "参数错误"
  86. br.ErrMsg = "参数错误,id不可为空"
  87. return
  88. }
  89. go services.AddCygxBannerHistory(user, bannerId)
  90. br.Ret = 200
  91. br.Success = true
  92. br.Msg = "记录成功"
  93. }