collection.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "hongze/hongze_cygx/models"
  5. "hongze/hongze_cygx/services"
  6. "hongze/hongze_cygx/utils"
  7. "time"
  8. )
  9. // Collection
  10. type CollectionController struct {
  11. BaseAuthController
  12. }
  13. // @Title 精选看板、路演banner列表
  14. // @Description 精选看板、路演banner列表接口
  15. // @Success Ret=200 {object} cygx.CollectionBannerListResp
  16. // @router /banner/list [get]
  17. func (this *CollectionController) BannerList() {
  18. br := new(models.BaseResponse).Init()
  19. defer func() {
  20. this.Data["json"] = br
  21. this.ServeJSON()
  22. }()
  23. user := this.User
  24. if user == nil {
  25. br.Msg = "请登录"
  26. br.ErrMsg = "请登录,SysUser Is Empty"
  27. br.Ret = 408
  28. return
  29. }
  30. resp := new(models.CollectionBannerListResp)
  31. var listA []*models.CollectionBannerResp
  32. listB := new(models.CollectionBannerResp)
  33. listA = []*models.CollectionBannerResp{
  34. &models.CollectionBannerResp{Title: "", IndexImg: "https://hzstatic.hzinsights.com/cygx/banner/xcx/lyhf.png", Path: "/reportPages/trainVideoPages/trainVideoPages"},
  35. }
  36. listB.Title = ""
  37. listB.IndexImg = "https://hzstatic.hzinsights.com/cygx/banner/xcx/jxkb.png"
  38. listB.IsShowSustainable = true
  39. resp.ListA = listA
  40. resp.ListB = listB
  41. br.Ret = 200
  42. br.Success = true
  43. br.Msg = "获取成功"
  44. br.Data = resp
  45. }
  46. // @Title 精选看板跳转详情地址
  47. // @Description 精选看板跳转详情地址接口
  48. // @Success Ret=200 {object} cygx.CollectionBannerListResp
  49. // @router /detail [get]
  50. func (this *CollectionController) Detail() {
  51. br := new(models.BaseResponse).Init()
  52. defer func() {
  53. this.Data["json"] = br
  54. this.ServeJSON()
  55. }()
  56. user := this.User
  57. if user == nil {
  58. br.Msg = "请登录"
  59. br.ErrMsg = "请登录,SysUser Is Empty"
  60. br.Ret = 408
  61. return
  62. }
  63. resp := new(models.CollectionDetailResp)
  64. if user.Mobile != "" {
  65. userTokenByMobile, _ := services.GetUserTokenByMobile(user.Mobile)
  66. resp.HttpUrl = utils.COLLECTIONS_INFO_HTTP_URL + "?token=" + userTokenByMobile
  67. } else {
  68. resp.HttpUrl = utils.COLLECTIONS_INFO_HTTP_URL
  69. }
  70. br.Ret = 200
  71. br.Success = true
  72. br.Msg = "获取成功"
  73. br.Data = resp
  74. }
  75. // @Title 提交精选看板申请接口
  76. // @Description 提交精选看板申请接口
  77. // @Param request body cygx.CygxBannerIdReq true "type json string"
  78. // @Success 200 Ret=200 提交成功
  79. // @router /apply/add [post]
  80. func (this *CollectionController) ApplyAdd() {
  81. br := new(models.BaseResponse).Init()
  82. defer func() {
  83. this.Data["json"] = br
  84. this.ServeJSON()
  85. }()
  86. user := this.User
  87. if user == nil {
  88. br.Msg = "请登录"
  89. br.ErrMsg = "请登录,用户信息为空"
  90. br.Ret = 408
  91. return
  92. }
  93. var req models.ApplyCollectionReq
  94. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  95. if err != nil {
  96. br.Msg = "参数解析异常!"
  97. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  98. return
  99. }
  100. content := req.Content
  101. if content == "" {
  102. br.Msg = "内容不能为空"
  103. br.ErrMsg = "内容不能为空"
  104. return
  105. }
  106. item := new(models.CygxApplyCollection)
  107. item.UserId = user.UserId
  108. item.CreateTime = time.Now()
  109. item.ModifyTime = time.Now()
  110. item.Mobile = user.Mobile
  111. item.Email = user.Email
  112. item.CompanyId = user.CompanyId
  113. item.CompanyName = user.CompanyName
  114. item.Content = content
  115. item.RegisterPlatform = utils.REGISTER_PLATFORM
  116. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  117. if err != nil && err.Error() != utils.ErrNoRow() {
  118. return
  119. }
  120. item.RealName = user.RealName
  121. if sellerItem != nil {
  122. item.SellerName = sellerItem.RealName
  123. }
  124. newId, err := models.AddCygxApplyCollection(item)
  125. services.SendCygxApplyCollectionTemplateMsg(user, content, int(newId))
  126. if err != nil {
  127. br.Msg = "申请失败"
  128. br.ErrMsg = "申请失败,Err:" + err.Error()
  129. return
  130. }
  131. br.Ret = 200
  132. br.Success = true
  133. br.Msg = "记录成功"
  134. }
  135. // @Title 获取申请详情
  136. // @Description 获取申请详情接口
  137. // @Param ApplyCollectionId query int true "ID"
  138. // @Success Ret=200 {object} cygx.CygxApplyCollectionDetailResp
  139. // @router /apply/detail [get]
  140. func (this *CollectionController) ApplyDetail() {
  141. br := new(models.BaseResponse).Init()
  142. defer func() {
  143. this.Data["json"] = br
  144. this.ServeJSON()
  145. }()
  146. user := this.User
  147. if user == nil {
  148. br.Msg = "请登录"
  149. br.ErrMsg = "请登录,用户信息为空"
  150. br.Ret = 408
  151. return
  152. }
  153. resp := new(models.CygxApplyCollectionDetailResp)
  154. applyCollectionId, _ := this.GetInt("ApplyCollectionId")
  155. if applyCollectionId < 1 {
  156. br.Msg = "请输入详情ID"
  157. return
  158. }
  159. detail, err := models.GetCygxApplyCollectionDetail(applyCollectionId)
  160. if err != nil {
  161. br.Msg = "详情不存在"
  162. br.ErrMsg = "获取失败,Err:" + err.Error()
  163. return
  164. }
  165. resp.Detail = detail
  166. br.Ret = 200
  167. br.Success = true
  168. br.Msg = "获取成功"
  169. br.Data = resp
  170. }