banner.go 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. // Banner
  10. type BannerController struct {
  11. BaseAuthController
  12. }
  13. // @Title 列表
  14. // @Description 列表接口
  15. // @Success Ret=200 {object} cygx.CygxBannerListResp
  16. // @router /list [get]
  17. func (this *BannerController) List() {
  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 = "请登录,用户信息为空"
  27. br.Ret = 408
  28. return
  29. }
  30. resp := new(models.CygxBannerListResp)
  31. var condition string
  32. var pars []interface{}
  33. condition += " AND art.show_type IN (0,1) AND art.status = 1 ORDER BY art.list_type ASC , art.sort ASC "
  34. list, err := models.GetCygxBannerList(condition, pars, 0, 99999)
  35. if err != nil {
  36. br.Msg = "获取失败"
  37. br.ErrMsg = "获取失败,Err:" + err.Error()
  38. return
  39. }
  40. bannerImgList, err := models.GetCygxBannerImgList()
  41. if err != nil {
  42. br.Msg = "获取失败"
  43. br.ErrMsg = "获取失败,Err:" + err.Error()
  44. return
  45. }
  46. mapImg := make(map[int]string)
  47. for _, v := range bannerImgList {
  48. mapImg[v.ImgId] = v.IndexImg
  49. }
  50. for _, v := range list {
  51. v.IndexImg = mapImg[v.ImgId]
  52. v.BannerUrlResp = services.GetBannerUrlBody(v.Link)
  53. }
  54. resp.List = list
  55. br.Ret = 200
  56. br.Success = true
  57. br.Msg = "获取成功"
  58. br.Data = resp
  59. }
  60. // @Title 记录点击信息
  61. // @Description 记录点击信息
  62. // @Param request body cygx.CygxBannerIdReq true "type json string"
  63. // @Success 200 Ret=200 发布成功
  64. // @router /add/history [post]
  65. func (this *BannerController) History() {
  66. br := new(models.BaseResponse).Init()
  67. defer func() {
  68. this.Data["json"] = br
  69. this.ServeJSON()
  70. }()
  71. user := this.User
  72. if user == nil {
  73. br.Msg = "请登录"
  74. br.ErrMsg = "请登录,用户信息为空"
  75. br.Ret = 408
  76. return
  77. }
  78. var req models.CygxBannerIdReq
  79. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  80. if err != nil {
  81. br.Msg = "参数解析异常!"
  82. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  83. return
  84. }
  85. bannerId := req.BannerId
  86. if bannerId == 0 {
  87. br.Msg = "参数错误"
  88. br.ErrMsg = "参数错误,id不可为空"
  89. return
  90. }
  91. go services.AddCygxBannerHistory(user, bannerId)
  92. br.Ret = 200
  93. br.Success = true
  94. br.Msg = "记录成功"
  95. }
  96. // @Title 研选banner列表
  97. // @Description 研选banner列表接口
  98. // @Success Ret=200 {object} cygx.CygxBannerListResp
  99. // @router /listYx [get]
  100. func (this *BannerController) ListYx() {
  101. br := new(models.BaseResponse).Init()
  102. defer func() {
  103. this.Data["json"] = br
  104. this.ServeJSON()
  105. }()
  106. user := this.User
  107. if user == nil {
  108. br.Msg = "请登录"
  109. br.ErrMsg = "请登录,用户信息为空"
  110. br.Ret = 408
  111. return
  112. }
  113. resp := new(models.BannerUrlYxListResp)
  114. var listA []*models.BannerUrlYxResp
  115. var listB []*models.BannerUrlYxResp
  116. if utils.RunMode == "release" {
  117. listA = []*models.BannerUrlYxResp{
  118. //&models.BannerUrlYxResp{IndexImg: "https://hzstatic.hzinsights.com/banner/yx/1.png", Path: "pages-purchaser/leaflet/leaflet?leafletImage=https%3A%2F%2Fhzstatic.hzinsights.com%2Fcygx%2Fconfig%2Fresearch_11_0.png"},
  119. //&models.BannerUrlYxResp{IndexImg: "https://hzstatic.hzinsights.com/banner/yx/1.png", Path: "pages-purchaser/leaflet/leaflet?leafletImage=https%3A%2F%2Fhzstatic.hzinsights.com%2Fcygx%2Fconfig%2Fresearch_11_1.png"},
  120. &models.BannerUrlYxResp{IndexImg: "https://hzstatic.hzinsights.com/banner/yx/2.png", Path: "pages-purchaser/survey/surveySubmit"},
  121. //&models.BannerUrlYxResp{IndexImg: "https://hzstatic.hzinsights.com/banner/yx/4.png", Path: "pages-purchaser/specialColumn/specialColumn"},
  122. &models.BannerUrlYxResp{IndexImg: "https://hzstatic.hzinsights.com/banner/yx/3_long.png", Path: "pages-purchaser/researchList/researchList"},
  123. }
  124. listB = []*models.BannerUrlYxResp{
  125. //&models.BannerUrlYxResp{IndexImg: "https://hzstatic.hzinsights.com/banner/yx/3.png", Path: "pages-purchaser/researchList/researchList"},
  126. &models.BannerUrlYxResp{IndexImg: "https://hzstatic.hzinsights.com/banner/yx/4_short.png", Path: "pages-purchaser/specialColumn/specialColumn"},
  127. }
  128. } else {
  129. listA = []*models.BannerUrlYxResp{
  130. //&models.BannerUrlYxResp{IndexImg: "https://hzstatic.hzinsights.com/banner/yx/1.png", Path: "pages-purchaser/leaflet/leaflet?leafletImage=https%3A%2F%2Fhzstatic.hzinsights.com%2Fcygx%2Fconfig%2Fresearch_11_0.png"},
  131. &models.BannerUrlYxResp{IndexImg: "https://hzstatic.hzinsights.com/banner/yx/1.png", Path: "pages-purchaser/leaflet/leaflet?leafletImage=https%3A%2F%2Fhzstatic.hzinsights.com%2Fcygx%2Fconfig%2Fresearch_11_1.png"},
  132. &models.BannerUrlYxResp{IndexImg: "https://hzstatic.hzinsights.com/banner/yx/2.png", Path: "pages-purchaser/survey/surveySubmit"},
  133. //&models.BannerUrlYxResp{IndexImg: "https://hzstatic.hzinsights.com/banner/yx/3_long.png", Path: "pages-purchaser/researchList/researchList"},
  134. }
  135. listB = []*models.BannerUrlYxResp{
  136. //&models.BannerUrlYxResp{IndexImg: "https://hzstatic.hzinsights.com/banner/yx/4_short.png", Path: "pages-purchaser/specialColumn/specialColumn"},
  137. &models.BannerUrlYxResp{IndexImg: "https://hzstatic.hzinsights.com/banner/yx/3.png", Path: "pages-purchaser/researchList/researchList"},
  138. }
  139. }
  140. resp.ListA = listA
  141. resp.ListB = listB
  142. br.Ret = 200
  143. br.Success = true
  144. br.Msg = "获取成功"
  145. br.Data = resp
  146. }
  147. // @Title 提交我要调研内容
  148. // @Description 提交我要调研内容接口
  149. // @Param request body cygx.CygxBannerIdReq true "type json string"
  150. // @Success 200 Ret=200 提交成功
  151. // @router /add/yxSurvey [post]
  152. func (this *BannerController) YxSurvey() {
  153. br := new(models.BaseResponse).Init()
  154. defer func() {
  155. this.Data["json"] = br
  156. this.ServeJSON()
  157. }()
  158. user := this.User
  159. if user == nil {
  160. br.Msg = "请登录"
  161. br.ErrMsg = "请登录,用户信息为空"
  162. br.Ret = 408
  163. return
  164. }
  165. var req models.CygxBannerYxSurveyReq
  166. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  167. if err != nil {
  168. br.Msg = "参数解析异常!"
  169. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  170. return
  171. }
  172. content := req.Content
  173. if content == "" {
  174. br.Msg = "内容不能为空"
  175. br.ErrMsg = "内容不能为空"
  176. return
  177. }
  178. item := new(models.CygxBannerYxSurvey)
  179. item.UserId = user.UserId
  180. item.CreateTime = time.Now()
  181. item.ModifyTime = time.Now()
  182. item.Mobile = user.Mobile
  183. item.Email = user.Email
  184. item.CompanyId = user.CompanyId
  185. item.CompanyName = user.CompanyName
  186. item.Content = content
  187. item.RegisterPlatform = utils.REGISTER_PLATFORM
  188. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  189. if err != nil && err.Error() != utils.ErrNoRow() {
  190. return
  191. }
  192. item.RealName = user.RealName
  193. if sellerItem != nil {
  194. item.SellerName = sellerItem.RealName
  195. }
  196. newId, err := models.AddCygxBannerYxSurvey(item)
  197. if err != nil {
  198. br.Msg = "申请失败"
  199. br.ErrMsg = "申请失败,Err:" + err.Error()
  200. return
  201. }
  202. go services.SendCygxBannerYxSurveyTemplateMsg(user, content, int(newId))
  203. br.Ret = 200
  204. br.Success = true
  205. br.Msg = "记录成功"
  206. }
  207. // @Title 我要调研内容详情
  208. // @Description 我要调研内容详情接口
  209. // @Param SuveryId query int true "ID"
  210. // @Success Ret=200 {object} cygx.CygxBannerListResp
  211. // @router /yxSurvey/detail [get]
  212. func (this *BannerController) YxSurveyDetail() {
  213. br := new(models.BaseResponse).Init()
  214. defer func() {
  215. this.Data["json"] = br
  216. this.ServeJSON()
  217. }()
  218. user := this.User
  219. if user == nil {
  220. br.Msg = "请登录"
  221. br.ErrMsg = "请登录,用户信息为空"
  222. br.Ret = 408
  223. return
  224. }
  225. suveryId, _ := this.GetInt("SuveryId")
  226. resp := new(models.CygxBannerYxSurveyRespDetailResp)
  227. detail, err := models.GetCygxBannerYxSurveyDetail(suveryId)
  228. if err != nil {
  229. br.Msg = "详情不存在"
  230. br.ErrMsg = "获取失败,Err:" + err.Error()
  231. return
  232. }
  233. resp.Detail = detail
  234. br.Ret = 200
  235. br.Success = true
  236. br.Msg = "获取成功"
  237. br.Data = resp
  238. }