banner.go 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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. // Banner
  10. type BannerController struct {
  11. BaseAuthController
  12. }
  13. type BaseBannerController struct {
  14. BaseCommonController
  15. }
  16. // @Title 列表
  17. // @Description 列表接口
  18. // @Success Ret=200 {object} cygx.CygxBannerListResp
  19. // @router /list [get]
  20. func (this *BaseBannerController) List() {
  21. br := new(models.BaseResponse).Init()
  22. defer func() {
  23. this.Data["json"] = br
  24. this.ServeJSON()
  25. }()
  26. resp := new(models.CygxBannerListResp)
  27. var condition string
  28. var pars []interface{}
  29. condition += " AND art.show_type IN (0,2) AND art.status = 1 ORDER BY art.list_type ASC , art.sort ASC "
  30. list, err := models.GetCygxBannerList(condition, pars, 0, 99999)
  31. if err != nil {
  32. br.Msg = "获取失败"
  33. br.ErrMsg = "获取失败,Err:" + err.Error()
  34. return
  35. }
  36. bannerImgList, err := models.GetCygxBannerImgList()
  37. if err != nil {
  38. br.Msg = "获取失败"
  39. br.ErrMsg = "获取失败,Err:" + err.Error()
  40. return
  41. }
  42. mapImg := make(map[int]*models.CygxBannerImgResp)
  43. for _, v := range bannerImgList {
  44. mapImg[v.ImgId] = v
  45. }
  46. var listA []*models.CygxBannerResp
  47. var listB []*models.CygxBannerResp
  48. var listC []*models.CygxBannerResp
  49. for _, v := range list {
  50. v.BannerUrlResp = services.GetBannerUrlBody(v.Link)
  51. if v.ListType == "A" {
  52. listA = append(listA, v)
  53. } else if v.ListType == "B" {
  54. listB = append(listB, v)
  55. } else if v.ListType == "C" {
  56. listC = append(listC, v)
  57. }
  58. }
  59. var listCount int
  60. if len(listA) == 0 {
  61. listA = make([]*models.CygxBannerResp, 0)
  62. } else {
  63. listCount++
  64. }
  65. if len(listB) == 0 {
  66. listB = make([]*models.CygxBannerResp, 0)
  67. } else {
  68. listCount++
  69. }
  70. if len(listC) == 0 {
  71. listC = make([]*models.CygxBannerResp, 0)
  72. } else {
  73. listCount++
  74. }
  75. //当有一列的时候过滤图片
  76. if listCount == 1 {
  77. if len(listA) > 0 {
  78. for _, v := range listA {
  79. if mapImg[v.ImgId] != nil {
  80. v.IndexImg = mapImg[v.ImgId].Img1
  81. }
  82. }
  83. }
  84. if len(listB) > 0 {
  85. for _, v := range listB {
  86. if mapImg[v.ImgId] != nil {
  87. v.IndexImg = mapImg[v.ImgId].Img1
  88. }
  89. }
  90. }
  91. if len(listC) > 0 {
  92. for _, v := range listC {
  93. if mapImg[v.ImgId] != nil {
  94. v.IndexImg = mapImg[v.ImgId].Img1
  95. }
  96. }
  97. }
  98. }
  99. //当有两列的时候过滤图片
  100. if listCount == 2 {
  101. if len(listA) > 0 {
  102. for _, v := range listA {
  103. if mapImg[v.ImgId] != nil {
  104. v.IndexImg = mapImg[v.ImgId].Img2
  105. }
  106. }
  107. if len(listB) > 0 {
  108. for _, v := range listB {
  109. if mapImg[v.ImgId] != nil {
  110. v.IndexImg = mapImg[v.ImgId].Img3
  111. }
  112. }
  113. }
  114. } else {
  115. if len(listB) > 0 {
  116. for _, v := range listB {
  117. if mapImg[v.ImgId] != nil {
  118. v.IndexImg = mapImg[v.ImgId].Img2
  119. }
  120. }
  121. }
  122. }
  123. if len(listC) > 0 {
  124. for _, v := range listC {
  125. if mapImg[v.ImgId] != nil {
  126. v.IndexImg = mapImg[v.ImgId].Img3
  127. }
  128. }
  129. }
  130. }
  131. //当有三列的时候过滤图片
  132. if listCount == 3 {
  133. for _, v := range listA {
  134. if mapImg[v.ImgId] != nil {
  135. v.IndexImg = mapImg[v.ImgId].Img2
  136. }
  137. }
  138. for _, v := range listB {
  139. if mapImg[v.ImgId] != nil {
  140. v.IndexImg = mapImg[v.ImgId].Img4
  141. }
  142. }
  143. for _, v := range listC {
  144. if mapImg[v.ImgId] != nil {
  145. v.IndexImg = mapImg[v.ImgId].Img4
  146. }
  147. }
  148. }
  149. resp.ListA = listA
  150. resp.ListB = listB
  151. resp.ListC = listC
  152. br.Ret = 200
  153. br.Success = true
  154. br.Msg = "获取成功"
  155. br.Data = resp
  156. }
  157. // @Title 记录点击信息
  158. // @Description 记录点击信息
  159. // @Param request body cygx.CygxBannerIdReq true "type json string"
  160. // @Success 200 Ret=200 发布成功
  161. // @router /add/history [post]
  162. func (this *BannerController) History() {
  163. br := new(models.BaseResponse).Init()
  164. defer func() {
  165. this.Data["json"] = br
  166. this.ServeJSON()
  167. }()
  168. user := this.User
  169. if user == nil {
  170. br.Msg = "请登录"
  171. br.ErrMsg = "请登录,用户信息为空"
  172. br.Ret = 408
  173. return
  174. }
  175. var req models.CygxBannerIdReq
  176. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  177. if err != nil {
  178. br.Msg = "参数解析异常!"
  179. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  180. return
  181. }
  182. bannerId := req.BannerId
  183. if bannerId == 0 {
  184. br.Msg = "参数错误"
  185. br.ErrMsg = "参数错误,id不可为空"
  186. return
  187. }
  188. go services.AddCygxBannerHistory(user, bannerId)
  189. br.Ret = 200
  190. br.Success = true
  191. br.Msg = "记录成功"
  192. }
  193. // @Title 研选banner列表
  194. // @Description 研选banner列表接口
  195. // @Success Ret=200 {object} cygx.CygxBannerListResp
  196. // @router /listYx [get]
  197. func (this *BaseBannerController) ListYx() {
  198. br := new(models.BaseResponse).Init()
  199. defer func() {
  200. this.Data["json"] = br
  201. this.ServeJSON()
  202. }()
  203. resp := new(models.BannerUrlYxListResp)
  204. var listA []*models.BannerUrlYxResp
  205. var listB []*models.BannerUrlYxResp
  206. var listC []*models.BannerUrlYxResp
  207. listA = []*models.BannerUrlYxResp{
  208. //&models.BannerUrlYxResp{IndexImg: "https://hzstatic.hzinsights.com/banner/yx/web_5.png", Path: "/index/"},
  209. &models.BannerUrlYxResp{IndexImg: "https://hzstatic.hzinsights.com/banner/yx/web_6.png", Path: ""},
  210. }
  211. listB = []*models.BannerUrlYxResp{
  212. &models.BannerUrlYxResp{IndexImg: "https://hzstatic.hzinsights.com/banner/yx/web_3.png", Path: "/index/"},
  213. }
  214. listC = []*models.BannerUrlYxResp{
  215. &models.BannerUrlYxResp{IndexImg: "https://hzstatic.hzinsights.com/banner/yx/web_4.png", Path: ""},
  216. }
  217. resp.ListA = listA
  218. resp.ListB = listB
  219. resp.ListC = listC
  220. br.Ret = 200
  221. br.Success = true
  222. br.Msg = "获取成功"
  223. br.Data = resp
  224. }
  225. // @Title 提交我要调研内容
  226. // @Description 提交我要调研内容接口
  227. // @Param request body cygx.CygxBannerIdReq true "type json string"
  228. // @Success 200 Ret=200 提交成功
  229. // @router /add/yxSurvey [post]
  230. func (this *BannerController) YxSurvey() {
  231. br := new(models.BaseResponse).Init()
  232. defer func() {
  233. this.Data["json"] = br
  234. this.ServeJSON()
  235. }()
  236. user := this.User
  237. if user == nil {
  238. br.Msg = "请登录"
  239. br.ErrMsg = "请登录,用户信息为空"
  240. br.Ret = 408
  241. return
  242. }
  243. var req models.CygxBannerYxSurveyReq
  244. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  245. if err != nil {
  246. br.Msg = "参数解析异常!"
  247. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  248. return
  249. }
  250. content := req.Content
  251. if content == "" {
  252. br.Msg = "内容不能为空"
  253. br.ErrMsg = "内容不能为空"
  254. return
  255. }
  256. item := new(models.CygxBannerYxSurvey)
  257. item.UserId = user.UserId
  258. item.CreateTime = time.Now()
  259. item.ModifyTime = time.Now()
  260. item.Mobile = user.Mobile
  261. item.Email = user.Email
  262. item.CompanyId = user.CompanyId
  263. item.CompanyName = user.CompanyName
  264. item.Content = content
  265. item.RegisterPlatform = utils.REGISTER_PLATFORM
  266. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  267. if err != nil && err.Error() != utils.ErrNoRow() {
  268. return
  269. }
  270. item.RealName = user.RealName
  271. if sellerItem != nil {
  272. item.SellerName = sellerItem.RealName
  273. }
  274. newId, err := models.AddCygxBannerYxSurvey(item)
  275. if err != nil {
  276. br.Msg = "申请失败"
  277. br.ErrMsg = "申请失败,Err:" + err.Error()
  278. return
  279. }
  280. go services.SendCygxBannerYxSurveyTemplateMsg(user, content, int(newId))
  281. br.Ret = 200
  282. br.Success = true
  283. br.Msg = "记录成功"
  284. }