chart.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package controllers
  2. import (
  3. "github.com/rdlucklib/rdluck_tools/paging"
  4. "hongze/hongze_cygx/models"
  5. "hongze/hongze_cygx/services"
  6. "hongze/hongze_cygx/utils"
  7. )
  8. type ChartController struct {
  9. BaseAuthController
  10. }
  11. type BaseChartController struct {
  12. BaseCommonController
  13. }
  14. // @Title 图表标签分类
  15. // @Description 图表标签分类接口
  16. // @Success 200 {object} models.ChartPtagResp
  17. // @router /patg [get]
  18. func (this *BaseChartController) Patg() {
  19. br := new(models.BaseResponse).Init()
  20. defer func() {
  21. this.Data["json"] = br
  22. this.ServeJSON()
  23. }()
  24. list, err := services.GetChartPtagByApi()
  25. if err != nil {
  26. br.Msg = "获取图表分类失败!"
  27. br.ErrMsg = "获取图表分类失败"
  28. return
  29. }
  30. br.Ret = 200
  31. br.Success = true
  32. br.Msg = "获取成功"
  33. br.Data = list
  34. }
  35. // @Title 我的收藏
  36. // @Description 我的收藏接口
  37. // @Param PageSize query int true "每页数据条数"
  38. // @Param CurrentIndex query int true "当前页页码,从1开始"
  39. // @Success 200 {object} models.HomeChartListItem
  40. // @router /my/collection [get]
  41. func (this *ChartController) Collection() {
  42. br := new(models.BaseResponse).Init()
  43. defer func() {
  44. this.Data["json"] = br
  45. this.ServeJSON()
  46. }()
  47. user := this.User
  48. if user == nil {
  49. br.Msg = "请重新登录"
  50. br.Ret = 408
  51. return
  52. }
  53. mobile := user.Mobile
  54. if mobile == "" {
  55. br.Msg = "请绑定手机号!"
  56. return
  57. }
  58. pageSize, _ := this.GetInt("PageSize")
  59. currentIndex, _ := this.GetInt("CurrentIndex")
  60. if pageSize <= 0 {
  61. pageSize = utils.PageSize20
  62. }
  63. if currentIndex <= 0 {
  64. currentIndex = 1
  65. }
  66. list, err := services.GetChartCollectionByApi(mobile)
  67. if err != nil {
  68. br.Msg = "获取图表分类失败!"
  69. br.ErrMsg = "获取图表分类失败"
  70. return
  71. }
  72. page := paging.GetPaging(currentIndex, pageSize, len(list))
  73. resp := new(models.HomeChartListItem)
  74. resp.List = list
  75. resp.Paging = page
  76. br.Ret = 200
  77. br.Success = true
  78. br.Msg = "获取成功"
  79. br.Data = resp
  80. }