home_pc.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. package controllers
  2. import (
  3. "github.com/rdlucklib/rdluck_tools/paging"
  4. "hongze/hongze_api/models"
  5. "hongze/hongze_api/services"
  6. "hongze/hongze_api/utils"
  7. "time"
  8. )
  9. // @Title 首页专栏接口
  10. // @Description 首页专栏接口
  11. // @Success 200 {object} models.Classify
  12. // @router /pc/column/list [get]
  13. func (this *HomeCommonController) PcColumnList() {
  14. br := new(models.BaseResponse).Init()
  15. defer func() {
  16. this.Data["json"] = br
  17. this.ServeJSON()
  18. }()
  19. list, err := models.GetColumnList()
  20. if err != nil {
  21. br.Msg = "获取数据失败"
  22. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  23. return
  24. }
  25. br.Ret = 200
  26. br.Success = true
  27. br.Msg = "获取数据成功"
  28. br.Data = list
  29. }
  30. // @Title pc-首页列表接口
  31. // @Description pc-首页列表接口
  32. // @Param PageSize query int true "每页数据条数"
  33. // @Param CurrentIndex query int true "当前页页码,从1开始"
  34. // @Param ClassifyId query int true "分类id"
  35. // @Success 200 {object} models.PcListHomeResp
  36. // @router /pc/list [get]
  37. func (this *HomeCommonController) ListHome() {
  38. br := new(models.BaseResponse).Init()
  39. defer func() {
  40. this.Data["json"] = br
  41. this.ServeJSON()
  42. }()
  43. var uid int
  44. if this.Token != "" && this.User != nil {
  45. uid = this.User.UserId
  46. }
  47. pageSize, _ := this.GetInt("PageSize")
  48. currentIndex, _ := this.GetInt("CurrentIndex")
  49. var startSize int
  50. if pageSize <= 0 {
  51. pageSize = utils.PageSize20
  52. }
  53. if currentIndex <= 0 {
  54. currentIndex = 1
  55. }
  56. startSize = paging.StartIndex(currentIndex, pageSize)
  57. classifyId, _ := this.GetInt("ClassifyId")
  58. if classifyId <= 0 {
  59. br.Msg = "参数错误"
  60. br.ErrMsg = "参数错误"
  61. return
  62. }
  63. endDate := time.Now().AddDate(0, -1, 0).Format(utils.FormatDate)
  64. total, err := models.PcListHomeCount(classifyId, endDate)
  65. if err != nil {
  66. br.Msg = "获取数据失败"
  67. br.ErrMsg = "获取数据条数失败,Err:" + err.Error()
  68. return
  69. }
  70. list, err := models.PcListHome(classifyId, uid, startSize, pageSize, endDate)
  71. if err != nil {
  72. br.Msg = "获取数据失败"
  73. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  74. return
  75. }
  76. var hasPermission bool
  77. if this.Token != "" && this.User != nil {
  78. userPermission, err := services.CheckUserPermission(uid)
  79. if err != nil {
  80. br.Msg = "获取失败"
  81. br.ErrMsg = "判断权限失败,判断权限失败:" + err.Error()
  82. return
  83. }
  84. if userPermission == 0 {
  85. hasPermission = true
  86. }
  87. }
  88. reportType := "rddp"
  89. reportPermissionList, err := models.GetReportVarietyListByUserIdExt(uid, reportType) //获取客户拥有权限的报告id
  90. if err != nil {
  91. if err.Error() != utils.ErrNoRow() {
  92. br.Msg = "获取报告详情失败"
  93. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  94. return
  95. } else {
  96. hasPermission = false
  97. }
  98. }
  99. if len(reportPermissionList) == 0 {
  100. hasPermission = false
  101. }
  102. permissionMap := make(map[int]int)
  103. for _, v := range reportPermissionList {
  104. if _, ok := permissionMap[v.ReportChapterTypeId]; !ok {
  105. permissionMap[v.ReportChapterTypeId] = v.ReportChapterTypeId
  106. }
  107. }
  108. for i := 0; i < len(list); i++ {
  109. item := list[i]
  110. if uid > 0 {
  111. count, err := models.GetReportPermission(uid, item.ClassifyNameSecond)
  112. if err != nil && err.Error() != utils.ErrNoRow() {
  113. br.Msg = "获取失败"
  114. br.ErrMsg = "判断报告是否拥有权限失败,Err:" + err.Error()
  115. return
  116. }
  117. if count <= 0 {
  118. list[i].VideoUrl = ""
  119. list[i].VideoName = ""
  120. list[i].VideoPlaySeconds = ""
  121. list[i].VideoSize = ""
  122. }
  123. }
  124. if item.ClassifyName == "权益研报" {
  125. list[i].TitleType = "权益"
  126. } else {
  127. list[i].TitleType = "FICC"
  128. }
  129. if !hasPermission {
  130. list[i].VideoUrl = ""
  131. list[i].VideoName = ""
  132. list[i].VideoPlaySeconds = ""
  133. list[i].VideoSize = ""
  134. }
  135. }
  136. if len(list) == 0 {
  137. list = make([]*models.PcHomeClassifyItem, 0)
  138. }
  139. page := paging.GetPaging(currentIndex, pageSize, total)
  140. resp := new(models.PcListHomeResp)
  141. resp.Paging = page
  142. resp.List = list
  143. br.Ret = 200
  144. br.Success = true
  145. br.Msg = "获取数据成功"
  146. br.Data = resp
  147. }
  148. // @Title 首页banner接口
  149. // @Description 首页banner接口
  150. // @Success 200 {object} models.Banner
  151. // @router /pc/banner [get]
  152. func (this *HomeCommonController) PcListBanner() {
  153. br := new(models.BaseResponse).Init()
  154. defer func() {
  155. this.Data["json"] = br
  156. this.ServeJSON()
  157. }()
  158. list, err := models.GetHomeBannerList("pc")
  159. if err != nil {
  160. br.Msg = "获取数据失败"
  161. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  162. return
  163. }
  164. br.Ret = 200
  165. br.Success = true
  166. br.Msg = "获取数据成功"
  167. br.Data = list
  168. }