banner.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package controllers
  2. import (
  3. "eta/eta_mini_api/models"
  4. "eta/eta_mini_api/utils"
  5. )
  6. type BannerController struct {
  7. BaseAuthController
  8. }
  9. // @Title List
  10. // @Description create users
  11. // @Param PageSize query int true "每页数据条数"
  12. // @Param CurrentIndex query int true "当前页页码,从1开始"
  13. // @Success 200 {object} models.BaseResponse
  14. // @router /list [get]
  15. func (this *BannerController) List() {
  16. br := new(models.BaseResponse).Init()
  17. defer func() {
  18. this.Data["json"] = br
  19. this.ServeJSON()
  20. }()
  21. pageSize, _ := this.GetInt("PageSize")
  22. currentIndex, _ := this.GetInt("CurrentIndex")
  23. if currentIndex <= 0 {
  24. currentIndex = 1
  25. }
  26. if pageSize <= 0 {
  27. pageSize = utils.PageSize20
  28. }
  29. startSize := utils.StartIndex(currentIndex, pageSize)
  30. banners, err := models.GetBannerList(startSize, pageSize)
  31. if err != nil {
  32. br.Msg = "获取banner列表失败"
  33. br.ErrMsg = "获取banner列表失败,系统异常,Err:" + err.Error()
  34. return
  35. }
  36. br.Data = banners
  37. br.Msg = "获取banner列表成功"
  38. br.Success = true
  39. br.Ret = 200
  40. }
  41. // @Title Detail
  42. // @Description banner详情
  43. // @Param BannerId query int true "bannerId"
  44. // @Success 200 {object} models.BaseResponse
  45. // @router /detail [get]
  46. func (this *BannerController) Detail() {
  47. br := new(models.BaseResponse).Init()
  48. defer func() {
  49. this.Data["json"] = br
  50. this.ServeJSON()
  51. }()
  52. bannerId, _ := this.GetInt("BannerId")
  53. banners, err := models.GetBannerById(bannerId)
  54. if err != nil {
  55. br.Msg = "获取banner详情失败"
  56. br.ErrMsg = "获取banner详情失败,系统异常,Err:" + err.Error()
  57. return
  58. }
  59. br.Data = banners
  60. br.Msg = "获取banner列表成功"
  61. br.Success = true
  62. br.Ret = 200
  63. }