activity.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. package activity
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "hongze/hongze_yb/controller/response"
  5. "hongze/hongze_yb/services/activity"
  6. "hongze/hongze_yb/services/user"
  7. "strconv"
  8. )
  9. // GetPageList 活动列表
  10. // @Tags 活动模块
  11. // @Summary 活动列表
  12. // @Description 获取活动列表
  13. // @Security ApiKeyAuth
  14. // @Param Authorization header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
  15. // @Accept json
  16. // @Product json
  17. // @Param activity_name query string false "活动名称"
  18. // @Param activity_type_name query string false "活动类别"
  19. // @Param active_state query int false "活动状态 1-未开始 2-进行中 3-已结束"
  20. // @Param activity_type query int false "活动类型 1-线上会议 3-线下沙龙"
  21. // @Param page query int false "当前页码"
  22. // @Param limit query int false "每页数量"
  23. // @Success 200 {object} []yb_activity.QueryActivity
  24. // @Router /activity/getPageList [get]
  25. func GetPageList(c *gin.Context) {
  26. where := _handleListQuery(c)
  27. page, limit := _handlePageParam(c)
  28. userInfo := user.GetUserInfoByStruct(c)
  29. listData, err := activity.PageList(where, page, limit, userInfo)
  30. if err != nil {
  31. response.Fail("活动获取失败", c)
  32. return
  33. }
  34. response.OkData("获取成功", listData, c)
  35. }
  36. func _handleListQuery(c *gin.Context) map[string]interface{} {
  37. where := make(map[string]interface{})
  38. where["is_delete ="] = 0
  39. title := c.DefaultQuery("activity_name", "")
  40. if title != "" {
  41. where["activity_name like"] = "%" + c.Query("activity_name") + "%"
  42. }
  43. typeName := c.DefaultQuery("activity_type_name", "")
  44. if typeName != "" {
  45. where["activity_type_name like"] = "%" + c.Query("activity_type_name") + "%"
  46. }
  47. reqState := c.DefaultQuery("active_state", "0")
  48. if reqState != "0" {
  49. state, _ := strconv.Atoi(reqState)
  50. where["active_state ="] = state
  51. }
  52. reqType := c.DefaultQuery("activity_type", "0")
  53. if reqType != "0" {
  54. activityType, _ := strconv.Atoi(reqType)
  55. where["activity_type_id ="] = activityType
  56. }
  57. return where
  58. }
  59. func _handlePageParam(c *gin.Context) (page, limit int) {
  60. page, _ = strconv.Atoi(c.Query("page"))
  61. limit, _ = strconv.Atoi(c.Query("limit"))
  62. return
  63. }
  64. // AddRemind 添加提醒
  65. // @Tags 活动模块
  66. // @Summary 添加提醒
  67. // @Description 添加提醒
  68. // @Security ApiKeyAuth
  69. // @Param Authorization header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
  70. // @Accept json
  71. // @Product json
  72. // @Param activity_id query int true "活动ID"
  73. // @Success 200 ""
  74. // @Router /activity/addRemind [post]
  75. func AddRemind(c *gin.Context) {
  76. reqActivityId := c.DefaultPostForm("activity_id", "0")
  77. if reqActivityId == "0" {
  78. response.Fail("参数有误: activity_id", c)
  79. return
  80. }
  81. activityId, _ := strconv.Atoi(reqActivityId)
  82. userInfo := user.GetUserInfoByStruct(c)
  83. _, err := activity.CreateRemind(activityId, userInfo)
  84. if err != nil {
  85. response.Fail("加入提醒失败", c)
  86. return
  87. }
  88. response.OkData("操作成功", "", c)
  89. }
  90. // RegisterActivity 报名活动
  91. // @Tags 活动模块
  92. // @Summary 报名活动
  93. // @Description 报名活动
  94. // @Security ApiKeyAuth
  95. // @Param Authorization header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
  96. // @Accept json
  97. // @Product json
  98. // @Param activity_id query int true "活动ID"
  99. // @Success 200 ""
  100. // @Router /activity/registerActivity [post]
  101. func RegisterActivity(c *gin.Context) {
  102. reqActivityId := c.DefaultPostForm("activity_id", "0")
  103. if reqActivityId == "0" {
  104. response.Fail("参数有误: activity_id", c)
  105. return
  106. }
  107. activityId, _ := strconv.Atoi(reqActivityId)
  108. userInfo := user.GetUserInfoByStruct(c)
  109. _, err := activity.CreateRegister(activityId, userInfo)
  110. if err != nil {
  111. response.Fail("报名失败", c)
  112. return
  113. }
  114. response.OkData("操作成功", "", c)
  115. }