home.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. package controllers
  2. import (
  3. "hongze/hongze_api/models"
  4. "hongze/hongze_api/services"
  5. "hongze/hongze_api/utils"
  6. "rdluck_tools/paging"
  7. )
  8. //首页
  9. type HomeController struct {
  10. BaseAuthController
  11. }
  12. type HomeCommonController struct {
  13. BaseCommonController
  14. }
  15. // @Title 首页列表接口
  16. // @Description 首页列表接口
  17. // @Success 200 {object} models.HomeList
  18. // @router /list [get]
  19. func (this *HomeController) ListHome() {
  20. br := new(models.BaseResponse).Init()
  21. defer func() {
  22. this.Data["json"] = br
  23. this.ServeJSON()
  24. }()
  25. user := this.User
  26. if user == nil {
  27. br.Msg = "请登录"
  28. br.ErrMsg = "请登录,用户信息为空"
  29. br.Ret = 408
  30. return
  31. }
  32. list, err := services.HomeList(user.UserId, user.CompanyId)
  33. if err != nil {
  34. br.Msg = "获取数据失败"
  35. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  36. return
  37. }
  38. for i := 0; i < len(list); i++ {
  39. item := list[i]
  40. for k := 0; k < len(item.Child); k++ {
  41. if item.ClassifyName == "权益研报" {
  42. if item.Child[k].Child.ClassifyNameSecond == "近期路演精华" {
  43. list[i].Child[k].TitleType = "图说逻辑"
  44. } else {
  45. list[i].Child[k].TitleType = "权益"
  46. }
  47. } else {
  48. list[i].Child[k].TitleType = "FICC"
  49. }
  50. }
  51. }
  52. br.Ret = 200
  53. br.Success = true
  54. br.Msg = "获取数据成功"
  55. br.Data = list
  56. }
  57. // @Title 首页列表接口
  58. // @Description 首页列表接口
  59. // @Success 200 {object} models.Banner
  60. // @router /banner [get]
  61. func (this *HomeController) ListBanner() {
  62. br := new(models.BaseResponse).Init()
  63. defer func() {
  64. this.Data["json"] = br
  65. this.ServeJSON()
  66. }()
  67. list, err := models.GetHomeBannerList()
  68. if err != nil {
  69. br.Msg = "获取数据失败"
  70. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  71. return
  72. }
  73. br.Ret = 200
  74. br.Success = true
  75. br.Msg = "获取数据成功"
  76. br.Data = list
  77. }
  78. // @Title pc-首页列表接口
  79. // @Description pc-首页列表接口
  80. // @Param PageSize query int true "每页数据条数"
  81. // @Param CurrentIndex query int true "当前页页码,从1开始"
  82. // @Param ClassifyId query int true "分类id"
  83. // @Success 200 {object} models.PcListHomeResp
  84. // @router /pc/list [get]
  85. func (this *HomeCommonController) ListHome() {
  86. br := new(models.BaseResponse).Init()
  87. defer func() {
  88. this.Data["json"] = br
  89. this.ServeJSON()
  90. }()
  91. authorization := this.Ctx.Input.Header("Authorization")
  92. pageSize, _ := this.GetInt("PageSize")
  93. currentIndex, _ := this.GetInt("CurrentIndex")
  94. var startSize int
  95. if pageSize <= 0 {
  96. pageSize = utils.PageSize20
  97. }
  98. if currentIndex <= 0 {
  99. currentIndex = 1
  100. }
  101. startSize = paging.StartIndex(currentIndex, pageSize)
  102. classifyId, _ := this.GetInt("ClassifyId")
  103. if classifyId <= 0 {
  104. br.Msg = "参数错误"
  105. br.ErrMsg = "参数错误"
  106. return
  107. }
  108. total, err := models.PcListHomeCount(classifyId)
  109. if err != nil {
  110. br.Msg = "获取数据失败"
  111. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  112. return
  113. }
  114. list, err := models.PcListHome(classifyId, startSize, pageSize)
  115. if err != nil {
  116. br.Msg = "获取数据失败"
  117. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  118. return
  119. }
  120. for i := 0; i < len(list); i++ {
  121. item := list[i]
  122. if item.ClassifyName == "权益研报" {
  123. list[i].ReportInfo.TitleType = "权益"
  124. } else {
  125. list[i].ReportInfo.TitleType = "FICC"
  126. }
  127. if authorization == "" {
  128. list[i].ReportInfo.VideoUrl = ""
  129. }
  130. }
  131. page := paging.GetPaging(currentIndex, pageSize, total)
  132. resp := new(models.PcListHomeResp)
  133. resp.Paging = page
  134. resp.List = list
  135. br.Ret = 200
  136. br.Success = true
  137. br.Msg = "获取数据成功"
  138. br.Data = resp
  139. }