classify.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package controllers
  2. import (
  3. "hongze/hongze_api/models"
  4. )
  5. type ClassifyController struct {
  6. BaseAuthController
  7. }
  8. type ClassifyCommonController struct {
  9. BaseCommonController
  10. }
  11. // @Title 获取分类详情信息
  12. // @Description 获取分类详情信息接口
  13. // @Param ClassifyId query int true "分类id"
  14. // @Success 200 {object} models.ClassifyDetail
  15. // @router /detail [get]
  16. func (this *ClassifyController) Detail() {
  17. br := new(models.BaseResponse).Init()
  18. defer func() {
  19. this.Data["json"] = br
  20. this.ServeJSON()
  21. }()
  22. classifyId, err := this.GetInt("ClassifyId")
  23. if err != nil {
  24. br.Msg = "参数获取失败"
  25. br.ErrMsg = "参数获取失败,Err:" + err.Error()
  26. return
  27. }
  28. if classifyId <= 0 {
  29. br.Msg = "参数错误"
  30. br.ErrMsg = "参数错误,分类id小于等于0"
  31. return
  32. }
  33. item, err := models.GetClassifyDetailById(classifyId)
  34. if err != nil {
  35. br.Msg = "获取信息失败"
  36. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  37. return
  38. }
  39. commentList, err := models.GetCustomerComment()
  40. if err != nil {
  41. br.Msg = "获取信息失败"
  42. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  43. return
  44. }
  45. item.CommentList = commentList
  46. br.Ret = 200
  47. br.Success = true
  48. br.Msg = "获取数据成功"
  49. br.Data = item
  50. }
  51. // @Title 获取一级分类列表
  52. // @Description 获取一级分类列表接口
  53. // @Success 200 {object} models.Classify
  54. // @router /pc/list [get]
  55. func (this *ClassifyCommonController) List() {
  56. br := new(models.BaseResponse).Init()
  57. defer func() {
  58. this.Data["json"] = br
  59. this.ServeJSON()
  60. }()
  61. item, err := models.GetClassifyList()
  62. if err != nil {
  63. br.Msg = "获取信息失败"
  64. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  65. return
  66. }
  67. br.Ret = 200
  68. br.Success = true
  69. br.Msg = "获取数据成功"
  70. br.Data = item
  71. }
  72. // @Title 获取二级分类列表
  73. // @Description 获取二级分类列表接口
  74. // @Param ClassifyId query int true "分类id"
  75. // @Success 200 {object} models.ClassifyDetail
  76. // @router /pc/second/list [get]
  77. func (this *ClassifyCommonController) SecondList() {
  78. br := new(models.BaseResponse).Init()
  79. defer func() {
  80. this.Data["json"] = br
  81. this.ServeJSON()
  82. }()
  83. classifyId, err := this.GetInt("ClassifyId")
  84. if err != nil {
  85. br.Msg = "参数获取失败"
  86. br.ErrMsg = "参数获取失败,Err:" + err.Error()
  87. return
  88. }
  89. if classifyId <= 0 {
  90. br.Msg = "参数错误"
  91. br.ErrMsg = "参数错误,分类id小于等于0"
  92. return
  93. }
  94. item, err := models.GetClassifySecondList(classifyId)
  95. if err != nil {
  96. br.Msg = "获取信息失败"
  97. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  98. return
  99. }
  100. br.Ret = 200
  101. br.Success = true
  102. br.Msg = "获取数据成功"
  103. br.Data = item
  104. }