activity.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package activity
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "hongze/hongze_yb/controller/response"
  5. "hongze/hongze_yb/services/activity"
  6. "strconv"
  7. )
  8. /**
  9. * @method GetPageList
  10. * @desc 获取活动分页列表
  11. * @param *gin.Context
  12. * @return json
  13. */
  14. // GetPageList 活动列表
  15. // @Tags 活动模块
  16. // @Summary 活动列表
  17. // @Description 获取活动列表
  18. // @Security ApiKeyAuth
  19. // @Param Authorization header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
  20. // @Accept json
  21. // @Product json
  22. // @Param activity_name query string false "活动名称"
  23. // @Param activity_type_name query string false "活动类别"
  24. // @Param active_state query int false "活动状态"
  25. // @Param page query int false "当前页码"
  26. // @Param limit query int false "每页数量"
  27. // @Success 200 {object} []yb_activity.YbActivity
  28. // @Router /activity/getPageList [get]
  29. func GetPageList(c *gin.Context) {
  30. where := _handleListQuery(c)
  31. page, limit := _handlePageParam(c)
  32. listData, err := activity.PageList(where, page, limit)
  33. if err != nil {
  34. response.Fail("活动获取失败", c)
  35. return
  36. }
  37. response.OkData("获取成功", listData, c)
  38. }
  39. func _handleListQuery(c *gin.Context) map[string]interface{} {
  40. where := make(map[string]interface{})
  41. title := c.DefaultQuery("activity_name", "")
  42. if title != "" {
  43. where["activity_name like"] = "%" + c.Query("activity_name") + "%"
  44. }
  45. typeName := c.DefaultQuery("activity_type_name", "")
  46. if typeName != "" {
  47. where["activity_type_name like"] = "%" + c.Query("activity_type_name") + "%"
  48. }
  49. requestState := c.DefaultQuery("active_state", "0")
  50. if requestState != "" {
  51. state, _ := strconv.Atoi(requestState)
  52. where["active_state ="] = state
  53. }
  54. return where
  55. }
  56. func _handlePageParam(c *gin.Context) (page int, limit int) {
  57. page, _ = strconv.Atoi(c.Query("page"))
  58. limit, _ = strconv.Atoi(c.Query("limit"))
  59. return
  60. }