collection.go 4.8 KB

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