collection.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "hongze/hongze_clpt/models"
  5. "hongze/hongze_clpt/services"
  6. "hongze/hongze_clpt/utils"
  7. "time"
  8. )
  9. // Collection
  10. type CollectionController struct {
  11. BaseAuthController
  12. }
  13. type BaseCollectionController struct {
  14. BaseCommonController
  15. }
  16. // @Title 精选看板、路演banner列表
  17. // @Description 精选看板、路演banner列表接口
  18. // @Success Ret=200 {object} cygx.CollectionBannerListResp
  19. // @router /banner/list [get]
  20. func (this *BaseCollectionController) BannerList() {
  21. br := new(models.BaseResponse).Init()
  22. defer func() {
  23. this.Data["json"] = br
  24. this.ServeJSON()
  25. }()
  26. resp := new(models.CollectionBannerListResp)
  27. var listA []*models.CollectionBannerResp
  28. listB := new(models.CollectionBannerResp)
  29. listA = []*models.CollectionBannerResp{
  30. &models.CollectionBannerResp{Title: "策略系列培训视频", IndexImg: "https://hzstatic.hzinsights.com/cygx/banner/web/lyhf.png", Path: "https://web.hzinsights.com/internal/article/43"},
  31. }
  32. listB.Title = "专题看板"
  33. listB.IndexImg = "https://hzstatic.hzinsights.com/cygx/banner/web/jxkb.png"
  34. listB.IsShowSustainable = true
  35. resp.ListA = listA
  36. resp.ListB = listB
  37. br.Ret = 200
  38. br.Success = true
  39. br.Msg = "获取成功"
  40. br.Data = resp
  41. }
  42. // @Title 精选看板跳转详情地址
  43. // @Description 精选看板跳转详情地址接口
  44. // @Success Ret=200 {object} cygx.CollectionBannerListResp
  45. // @router /detail [get]
  46. func (this *CollectionController) Detail() {
  47. br := new(models.BaseResponse).Init()
  48. defer func() {
  49. this.Data["json"] = br
  50. this.ServeJSON()
  51. }()
  52. user := this.User
  53. if user == nil {
  54. br.Msg = "请登录"
  55. br.ErrMsg = "请登录,SysUser Is Empty"
  56. br.Ret = 408
  57. return
  58. }
  59. resp := new(models.CollectionDetailResp)
  60. br.Ret = 200
  61. br.Success = true
  62. br.Msg = "获取成功"
  63. br.Data = resp
  64. }
  65. // @Title 提交精选看板申请接口
  66. // @Description 提交精选看板申请接口
  67. // @Param request body cygx.CygxBannerIdReq true "type json string"
  68. // @Success 200 Ret=200 提交成功
  69. // @router /apply/add [post]
  70. func (this *CollectionController) ApplyAdd() {
  71. br := new(models.BaseResponse).Init()
  72. defer func() {
  73. this.Data["json"] = br
  74. this.ServeJSON()
  75. }()
  76. user := this.User
  77. if user == nil {
  78. br.Msg = "请登录"
  79. br.ErrMsg = "请登录,用户信息为空"
  80. br.Ret = 408
  81. return
  82. }
  83. var req models.ApplyCollectionReq
  84. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  85. if err != nil {
  86. br.Msg = "参数解析异常!"
  87. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  88. return
  89. }
  90. content := req.Content
  91. if content == "" {
  92. br.Msg = "内容不能为空"
  93. br.ErrMsg = "内容不能为空"
  94. return
  95. }
  96. item := new(models.CygxApplyCollection)
  97. item.UserId = user.UserId
  98. item.CreateTime = time.Now()
  99. item.ModifyTime = time.Now()
  100. item.Mobile = user.Mobile
  101. item.Email = user.Email
  102. item.CompanyId = user.CompanyId
  103. item.CompanyName = user.CompanyName
  104. item.Content = content
  105. item.RegisterPlatform = utils.REGISTER_PLATFORM
  106. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  107. if err != nil && err.Error() != utils.ErrNoRow() {
  108. return
  109. }
  110. item.RealName = user.RealName
  111. if sellerItem != nil {
  112. item.SellerName = sellerItem.RealName
  113. }
  114. newId, err := models.AddCygxApplyCollection(item)
  115. go services.SendCygxApplyCollectionTemplateMsg(user, content, int(newId))
  116. if err != nil {
  117. br.Msg = "申请失败"
  118. br.ErrMsg = "申请失败,Err:" + err.Error()
  119. return
  120. }
  121. br.Ret = 200
  122. br.Success = true
  123. br.Msg = "记录成功"
  124. }