1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- package activity
- import (
- "github.com/gin-gonic/gin"
- "hongze/hongze_yb/controller/response"
- "hongze/hongze_yb/services/activity"
- "strconv"
- )
- /**
- * @method GetPageList
- * @desc 获取活动分页列表
- * @param *gin.Context
- * @return json
- */
- // GetPageList 活动列表
- // @Tags 活动模块
- // @Summary 活动列表
- // @Description 获取活动列表
- // @Security ApiKeyAuth
- // @Param Authorization header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
- // @Accept json
- // @Product json
- // @Param activity_name query string false "活动名称"
- // @Param activity_type_name query string false "活动类别"
- // @Param active_state query int false "活动状态"
- // @Param page query int false "当前页码"
- // @Param limit query int false "每页数量"
- // @Success 200 {object} []yb_activity.YbActivity
- // @Router /activity/getPageList [get]
- func GetPageList(c *gin.Context) {
- where := _handleListQuery(c)
- page, limit := _handlePageParam(c)
- listData, err := activity.PageList(where, page, limit)
- if err != nil {
- response.Fail("活动获取失败", c)
- return
- }
- response.OkData("获取成功", listData, c)
- }
- func _handleListQuery(c *gin.Context) map[string]interface{} {
- where := make(map[string]interface{})
- title := c.DefaultQuery("activity_name", "")
- if title != "" {
- where["activity_name like"] = "%" + c.Query("activity_name") + "%"
- }
- typeName := c.DefaultQuery("activity_type_name", "")
- if typeName != "" {
- where["activity_type_name like"] = "%" + c.Query("activity_type_name") + "%"
- }
- requestState := c.DefaultQuery("active_state", "0")
- if requestState != "" {
- state, _ := strconv.Atoi(requestState)
- where["active_state ="] = state
- }
- return where
- }
- func _handlePageParam(c *gin.Context) (page int, limit int) {
- page, _ = strconv.Atoi(c.Query("page"))
- limit, _ = strconv.Atoi(c.Query("limit"))
- return
- }
|