banner.go 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. }
  134. listB = []*models.BannerUrlYxResp{
  135. //&models.BannerUrlYxResp{IndexImg: "https://hzstatic.hzinsights.com/banner/yx/4_short.png", Path: "pages-purchaser/specialColumn/specialColumn"},
  136. &models.BannerUrlYxResp{IndexImg: "https://hzstatic.hzinsights.com/banner/yx/3.png", Path: "pages-purchaser/researchList/researchList"},
  137. }
  138. }
  139. resp.ListA = listA
  140. resp.ListB = listB
  141. br.Ret = 200
  142. br.Success = true
  143. br.Msg = "获取成功"
  144. br.Data = resp
  145. }
  146. // @Title 提交我要调研内容
  147. // @Description 提交我要调研内容接口
  148. // @Param request body cygx.CygxBannerIdReq true "type json string"
  149. // @Success 200 Ret=200 提交成功
  150. // @router /add/yxSurvey [post]
  151. func (this *BannerController) YxSurvey() {
  152. br := new(models.BaseResponse).Init()
  153. defer func() {
  154. this.Data["json"] = br
  155. this.ServeJSON()
  156. }()
  157. user := this.User
  158. if user == nil {
  159. br.Msg = "请登录"
  160. br.ErrMsg = "请登录,用户信息为空"
  161. br.Ret = 408
  162. return
  163. }
  164. var req models.CygxBannerYxSurveyReq
  165. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  166. if err != nil {
  167. br.Msg = "参数解析异常!"
  168. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  169. return
  170. }
  171. content := req.Content
  172. if content == "" {
  173. br.Msg = "内容不能为空"
  174. br.ErrMsg = "内容不能为空"
  175. return
  176. }
  177. item := new(models.CygxBannerYxSurvey)
  178. item.UserId = user.UserId
  179. item.CreateTime = time.Now()
  180. item.ModifyTime = time.Now()
  181. item.Mobile = user.Mobile
  182. item.Email = user.Email
  183. item.CompanyId = user.CompanyId
  184. item.CompanyName = user.CompanyName
  185. item.Content = content
  186. item.RegisterPlatform = utils.REGISTER_PLATFORM
  187. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  188. if err != nil && err.Error() != utils.ErrNoRow() {
  189. return
  190. }
  191. item.RealName = user.RealName
  192. if sellerItem != nil {
  193. item.SellerName = sellerItem.RealName
  194. }
  195. newId, err := models.AddCygxBannerYxSurvey(item)
  196. if err != nil {
  197. br.Msg = "申请失败"
  198. br.ErrMsg = "申请失败,Err:" + err.Error()
  199. return
  200. }
  201. go services.SendCygxBannerYxSurveyTemplateMsg(user, content, int(newId))
  202. br.Ret = 200
  203. br.Success = true
  204. br.Msg = "记录成功"
  205. }
  206. // @Title 我要调研内容详情
  207. // @Description 我要调研内容详情接口
  208. // @Param SuveryId query int true "ID"
  209. // @Success Ret=200 {object} cygx.CygxBannerListResp
  210. // @router /yxSurvey/detail [get]
  211. func (this *BannerController) YxSurveyDetail() {
  212. br := new(models.BaseResponse).Init()
  213. defer func() {
  214. this.Data["json"] = br
  215. this.ServeJSON()
  216. }()
  217. user := this.User
  218. if user == nil {
  219. br.Msg = "请登录"
  220. br.ErrMsg = "请登录,用户信息为空"
  221. br.Ret = 408
  222. return
  223. }
  224. suveryId, _ := this.GetInt("SuveryId")
  225. resp := new(models.CygxBannerYxSurveyRespDetailResp)
  226. detail, err := models.GetCygxBannerYxSurveyDetail(suveryId)
  227. if err != nil {
  228. br.Msg = "详情不存在"
  229. br.ErrMsg = "获取失败,Err:" + err.Error()
  230. return
  231. }
  232. resp.Detail = detail
  233. br.Ret = 200
  234. br.Success = true
  235. br.Msg = "获取成功"
  236. br.Data = resp
  237. }