banner.go 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "hongze/hongze_web_mfyx/models"
  5. "hongze/hongze_web_mfyx/services"
  6. "hongze/hongze_web_mfyx/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 研选banner列表
  158. // @Description 研选banner列表接口
  159. // @Success Ret=200 {object} cygx.CygxBannerListResp
  160. // @router /listYx [get]
  161. func (this *BaseBannerController) ListYx() {
  162. br := new(models.BaseResponse).Init()
  163. defer func() {
  164. this.Data["json"] = br
  165. this.ServeJSON()
  166. }()
  167. resp := new(models.BannerUrlYxListResp)
  168. var listA []*models.BannerUrlYxResp
  169. var listB []*models.BannerUrlYxResp
  170. var listC []*models.BannerUrlYxResp
  171. listA = []*models.BannerUrlYxResp{
  172. &models.BannerUrlYxResp{IndexImg: "https://hzstatic.hzinsights.com/banner/yx/web_5.png", Path: "/index/"},
  173. &models.BannerUrlYxResp{IndexImg: "https://hzstatic.hzinsights.com/banner/yx/web_6.png", Path: ""},
  174. }
  175. listB = []*models.BannerUrlYxResp{
  176. &models.BannerUrlYxResp{IndexImg: "https://hzstatic.hzinsights.com/banner/yx/web_3.png", Path: "/index/"},
  177. }
  178. listC = []*models.BannerUrlYxResp{
  179. &models.BannerUrlYxResp{IndexImg: "https://hzstatic.hzinsights.com/banner/yx/web_4.png", Path: ""},
  180. }
  181. resp.ListA = listA
  182. resp.ListB = listB
  183. resp.ListC = listC
  184. br.Ret = 200
  185. br.Success = true
  186. br.Msg = "获取成功"
  187. br.Data = resp
  188. }
  189. // @Title 提交我要调研内容
  190. // @Description 提交我要调研内容接口
  191. // @Param request body cygx.CygxBannerIdReq true "type json string"
  192. // @Success 200 Ret=200 提交成功
  193. // @router /add/yxSurvey [post]
  194. func (this *BannerController) YxSurvey() {
  195. br := new(models.BaseResponse).Init()
  196. defer func() {
  197. this.Data["json"] = br
  198. this.ServeJSON()
  199. }()
  200. user := this.User
  201. if user == nil {
  202. br.Msg = "请登录"
  203. br.ErrMsg = "请登录,用户信息为空"
  204. br.Ret = 408
  205. return
  206. }
  207. var req models.CygxBannerYxSurveyReq
  208. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  209. if err != nil {
  210. br.Msg = "参数解析异常!"
  211. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  212. return
  213. }
  214. content := req.Content
  215. if content == "" {
  216. br.Msg = "内容不能为空"
  217. br.ErrMsg = "内容不能为空"
  218. return
  219. }
  220. item := new(models.CygxBannerYxSurvey)
  221. item.UserId = user.UserId
  222. item.CreateTime = time.Now()
  223. item.ModifyTime = time.Now()
  224. item.Mobile = user.Mobile
  225. item.Email = user.Email
  226. item.CompanyId = user.CompanyId
  227. item.CompanyName = user.CompanyName
  228. item.Content = content
  229. item.RegisterPlatform = utils.REGISTER_PLATFORM
  230. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  231. if err != nil && err.Error() != utils.ErrNoRow() {
  232. return
  233. }
  234. item.RealName = user.RealName
  235. if sellerItem != nil {
  236. item.SellerName = sellerItem.RealName
  237. }
  238. newId, err := models.AddCygxBannerYxSurvey(item)
  239. if err != nil {
  240. br.Msg = "申请失败"
  241. br.ErrMsg = "申请失败,Err:" + err.Error()
  242. return
  243. }
  244. go services.SendCygxBannerYxSurveyTemplateMsg(user, content, int(newId))
  245. br.Ret = 200
  246. br.Success = true
  247. br.Msg = "记录成功"
  248. }
  249. // @Title 首页banner图片
  250. // @Description 研选banner列表接口
  251. // @Success Ret=200 {object} cygx.BannerUrHomeListResp
  252. // @router /listhome [get]
  253. func (this *BaseBannerController) ListHome() {
  254. br := new(models.BaseResponse).Init()
  255. defer func() {
  256. this.Data["json"] = br
  257. this.ServeJSON()
  258. }()
  259. resp := new(models.BannerUrHomeListResp)
  260. key := "web_mfyx_banner_list"
  261. conf, e := models.GetConfigByCode(key)
  262. if e != nil {
  263. br.Msg = "获取失败"
  264. br.ErrMsg = "获取首页头部导航失败, Err: " + e.Error()
  265. return
  266. }
  267. if conf.ConfigValue == "" {
  268. br.Msg = "获取失败"
  269. br.ErrMsg = "首页头部导航配置值有误"
  270. return
  271. }
  272. if e = json.Unmarshal([]byte(conf.ConfigValue), &resp); e != nil {
  273. br.Msg = "获取失败"
  274. br.ErrMsg = "首页头部导航配置值解析失败, Err: " + e.Error()
  275. return
  276. }
  277. br.Ret = 200
  278. br.Success = true
  279. br.Msg = "获取成功"
  280. br.Data = resp
  281. }