home.go 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. package controllers
  2. import (
  3. "github.com/rdlucklib/rdluck_tools/paging"
  4. "hongze/hongze_clpt/models"
  5. "hongze/hongze_clpt/services"
  6. "hongze/hongze_clpt/utils"
  7. "strconv"
  8. "strings"
  9. )
  10. type HomeController struct {
  11. BaseAuthController
  12. }
  13. type BaseHomeController struct {
  14. BaseCommonController
  15. }
  16. type MobileHomeController struct {
  17. BaseAuthMobileController
  18. }
  19. // @Title 首页列表接口
  20. // @Description 首页列表接口
  21. // @Param PageSize query int true "每页数据条数"
  22. // @Param CurrentIndex query int true "当前页页码,从1开始"
  23. // @Param ChartPermissionId query int true "品类id,最新传0"
  24. // @Param CtagId query int true "图表子类ID"
  25. // @Param ListType query int true "列表类型,1最新,2 纪要 ,3图表 默认1"
  26. // @Success 200 {object} models.HomeArtAndChartListResp
  27. // @router /list [get]
  28. func (this *MobileHomeController) List() {
  29. br := new(models.BaseResponse).Init()
  30. defer func() {
  31. this.Data["json"] = br
  32. this.ServeJSON()
  33. }()
  34. user := this.User
  35. if user == nil {
  36. br.Msg = "请登录"
  37. br.ErrMsg = "请登录,用户信息为空"
  38. br.Ret = 408
  39. return
  40. }
  41. pageSize, _ := this.GetInt("PageSize")
  42. currentIndex, _ := this.GetInt("CurrentIndex")
  43. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  44. ctagId, _ := this.GetInt("CtagId")
  45. listType, _ := this.GetInt("ListType")
  46. var startSize int
  47. if pageSize <= 0 {
  48. pageSize = utils.PageSize20
  49. }
  50. if currentIndex <= 0 {
  51. currentIndex = 1
  52. }
  53. if listType <= 0 {
  54. listType = 1
  55. }
  56. startSize = paging.StartIndex(currentIndex, pageSize)
  57. var condition string
  58. var pars []interface{}
  59. var total, chartTotal int
  60. resp := new(models.HomeArtAndChartListResp)
  61. page := paging.GetPaging(currentIndex, pageSize, total)
  62. var chartList []*models.HomeChartListResp
  63. var err error
  64. if listType == 1 {
  65. if currentIndex <= 2 {
  66. listCtagId := [10]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
  67. var chartIds string
  68. for _, v := range listCtagId {
  69. chartListTwo, err := models.GetChartList(`AND ctag_id = `+strconv.Itoa(v), pars, 0, 2)
  70. if err != nil {
  71. br.Msg = "获取信息失败"
  72. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  73. return
  74. }
  75. for _, vChart := range chartListTwo {
  76. chartIds += strconv.Itoa(vChart.ChartId) + ","
  77. }
  78. }
  79. chartIds = strings.TrimRight(chartIds, ",")
  80. condition += ` AND chart_id IN (` + chartIds + `) `
  81. chartList, err = models.GetChartList(condition, pars, startSize, pageSize)
  82. if err != nil {
  83. br.Msg = "获取信息失败"
  84. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  85. return
  86. }
  87. }
  88. } else if listType == 3 {
  89. if chartPermissionId > 0 {
  90. condition += ` AND a.ptag_id =? `
  91. pars = append(pars, chartPermissionId)
  92. }
  93. if ctagId > 0 {
  94. condition += ` AND a.ctag_id =? `
  95. pars = append(pars, ctagId)
  96. }
  97. chartList, err = models.GetChartList(condition, pars, startSize, pageSize)
  98. if err != nil {
  99. br.Msg = "获取信息失败"
  100. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  101. return
  102. }
  103. chartTotal, err = models.GetChartCount(condition, pars)
  104. if err != nil {
  105. br.Msg = "获取信息失败"
  106. br.Msg = "获取帖子总数失败,Err:" + err.Error()
  107. return
  108. }
  109. }
  110. for k, v := range chartList {
  111. if v.PtagName != "" {
  112. chartList[k].CtagNamePc = v.PtagName
  113. }
  114. if v.CtagName != "" {
  115. chartList[k].CtagNamePc += "," + v.CtagName
  116. }
  117. if v.PtagNameTwo != "" {
  118. chartList[k].CtagNamePc += "," + v.PtagNameTwo
  119. }
  120. if v.CtagNameTwo != "" {
  121. chartList[k].CtagNamePc += "," + v.CtagNameTwo
  122. }
  123. chartList[k].IsNeedJump = true
  124. chartList[k].Source = 2
  125. if v.PtagName != "" {
  126. labelItem := new(models.LabelList)
  127. labelItem.PtagName = v.PtagName
  128. labelItem.CtagName = v.CtagName
  129. chartList[k].LabelList = append(chartList[k].LabelList, labelItem)
  130. }
  131. if v.PtagNameTwo != "" {
  132. labelItemTwo := new(models.LabelList)
  133. labelItemTwo.PtagName = v.PtagNameTwo
  134. labelItemTwo.CtagName = v.CtagNameTwo
  135. chartList[k].LabelList = append(chartList[k].LabelList, labelItemTwo)
  136. }
  137. if len(chartList[k].LabelList) == 0 {
  138. chartList[k].LabelList = make([]*models.LabelList, 0)
  139. }
  140. }
  141. if len(chartList) == 0 {
  142. chartList = make([]*models.HomeChartListResp, 0)
  143. }
  144. resp.ChartList = chartList
  145. if listType != 3 {
  146. userType, _, err := services.GetUserType(user.CompanyId)
  147. if err != nil {
  148. br.Msg = "获取信息失败"
  149. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  150. return
  151. }
  152. condition = ` AND is_summary = 1 `
  153. if chartPermissionId > 0 {
  154. categoryId, err := models.GetCategoryId(chartPermissionId)
  155. if err != nil && err.Error() != utils.ErrNoRow() {
  156. br.Msg = "获取信息失败"
  157. br.ErrMsg = "获取分类权限信息失败,Err:" + err.Error()
  158. return
  159. }
  160. categoryinfo, err := models.GetChartPermissionById(chartPermissionId)
  161. if err != nil {
  162. br.Msg = "获取信息失败"
  163. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  164. return
  165. }
  166. if userType == 1 && strings.Contains(categoryinfo.PermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  167. resp.Paging = page
  168. br.Ret = 200
  169. br.Success = true
  170. br.Msg = "获取成功"
  171. br.Data = resp
  172. return
  173. }
  174. page = paging.GetPaging(currentIndex, pageSize, total)
  175. if categoryId != "" {
  176. condition += ` AND category_id IN(` + categoryId + `)`
  177. //condition += ` OR ( category_name LIKE '%` + utils.CHART_PERMISSION_NAME_YANXUAN + `%' AND publish_status = 1 AND is_summary = 1 )`
  178. } else {
  179. condition += ` AND category_name LIKE '%` + utils.CHART_PERMISSION_NAME_YANXUAN + `%'`
  180. }
  181. }
  182. //永续客户无法查看研选分类的内容
  183. if userType == 1 {
  184. condition += ` AND category_name NOT LIKE '%` + utils.CHART_PERMISSION_NAME_YANXUAN + `%'`
  185. }
  186. total, err = models.GetHomeCount(condition, pars)
  187. if err != nil {
  188. br.Msg = "获取信息失败"
  189. br.Msg = "获取帖子总数失败,Err:" + err.Error()
  190. return
  191. }
  192. listPublic, err := models.GetHomeListPublic(condition, pars, startSize, pageSize)
  193. if err != nil {
  194. br.Msg = "获取信息失败"
  195. br.Msg = "获取帖子数据失败,Err:" + err.Error()
  196. return
  197. }
  198. listPublic, err = services.HandleArticleCategoryImg(listPublic)
  199. if err != nil {
  200. br.Msg = "获取失败"
  201. br.ErrMsg = "获取报告封面图片失败, Err:" + err.Error()
  202. return
  203. }
  204. var list []*models.HomeArticle
  205. if len(listPublic) == 0 {
  206. list = make([]*models.HomeArticle, 0)
  207. } else {
  208. for _, v := range listPublic {
  209. list = append(list, &models.HomeArticle{
  210. ArticleId: v.ArticleId,
  211. Title: v.Title,
  212. Annotation: v.Annotation,
  213. ImgUrlPc: v.ImgUrlPc,
  214. PublishDate: v.PublishDate,
  215. })
  216. }
  217. }
  218. resp.List = list
  219. }
  220. if chartTotal > total {
  221. total = chartTotal
  222. }
  223. page = paging.GetPaging(currentIndex, pageSize, total)
  224. resp.Paging = page
  225. br.Ret = 200
  226. br.Success = true
  227. br.Msg = "获取成功"
  228. br.Data = resp
  229. }