activity.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/admin/main/growup/model"
  5. "go-common/library/log"
  6. bm "go-common/library/net/http/blademaster"
  7. "go-common/library/net/http/blademaster/render"
  8. "go-common/library/time"
  9. )
  10. func activityAdd(c *bm.Context) {
  11. username, _, err := checkCookie(c)
  12. if err != nil {
  13. c.JSON(nil, err)
  14. log.Error("checkCookie error(%v)", err)
  15. return
  16. }
  17. v := new(model.CActivity)
  18. if err = c.Bind(v); err != nil {
  19. return
  20. }
  21. if err = svr.AddActivity(c, v, username); err != nil {
  22. log.Error("svr.AddActivity error(%v)", err)
  23. c.Render(http.StatusOK, render.MapJSON(map[string]interface{}{
  24. "code": 500,
  25. "message": err.Error(),
  26. }))
  27. } else {
  28. c.JSON(nil, nil)
  29. }
  30. }
  31. func activityList(c *bm.Context) {
  32. v := new(struct {
  33. Name string `form:"name"`
  34. From int `form:"from" validate:"min=0" default:"0"`
  35. Limit int `form:"limit" validate:"min=1" default:"20"`
  36. Sort string `form:"sort"`
  37. })
  38. if err := c.Bind(v); err != nil {
  39. return
  40. }
  41. data, total, err := svr.ListActivity(c, v.Name, v.From, v.Limit, v.Sort)
  42. if err != nil {
  43. log.Error("svr.ListActivity error(%v)", err)
  44. c.JSON(nil, err)
  45. return
  46. }
  47. c.Render(http.StatusOK, render.MapJSON(map[string]interface{}{
  48. "code": 0,
  49. "data": data,
  50. "paging": map[string]int{
  51. "size": v.Limit,
  52. "total": total,
  53. },
  54. }))
  55. }
  56. func activityUpdate(c *bm.Context) {
  57. var err error
  58. v := new(model.CActivity)
  59. if err = c.Bind(v); err != nil {
  60. return
  61. }
  62. if err = svr.UpdateActivity(c, v); err != nil {
  63. log.Error("svr.UpdateActivity error(%v)", err)
  64. c.Render(http.StatusOK, render.MapJSON(map[string]interface{}{
  65. "code": 500,
  66. "message": err.Error(),
  67. }))
  68. } else {
  69. c.JSON(nil, nil)
  70. }
  71. }
  72. func activitySignUp(c *bm.Context) {
  73. v := new(struct {
  74. ID int64 `form:"id"`
  75. From int `form:"from" validate:"min=0" default:"0"`
  76. Limit int `form:"limit" validate:"min=1" default:"20"`
  77. })
  78. if err := c.Bind(v); err != nil {
  79. return
  80. }
  81. data, total, err := svr.ListActivitySignUp(c, v.ID, v.From, v.Limit)
  82. if err != nil {
  83. log.Error("svr.ListActivitySignUp error(%v)", err)
  84. c.JSON(nil, err)
  85. return
  86. }
  87. c.Render(http.StatusOK, render.MapJSON(map[string]interface{}{
  88. "code": 0,
  89. "data": data,
  90. "paging": map[string]int{
  91. "size": v.Limit,
  92. "total": total,
  93. },
  94. }))
  95. }
  96. func activityWinners(c *bm.Context) {
  97. v := new(struct {
  98. ID int64 `form:"id"`
  99. MID int64 `form:"mid"`
  100. From int `form:"from" validate:"min=0" default:"0"`
  101. Limit int `form:"limit" validate:"min=1" default:"20"`
  102. })
  103. if err := c.Bind(v); err != nil {
  104. return
  105. }
  106. data, total, err := svr.ListActivityWinners(c, v.ID, v.MID, v.From, v.Limit)
  107. if err != nil {
  108. log.Error("svr.ListActivityWinners error(%v)", err)
  109. c.JSON(nil, err)
  110. return
  111. }
  112. c.Render(http.StatusOK, render.MapJSON(map[string]interface{}{
  113. "code": 0,
  114. "data": data,
  115. "paging": map[string]int{
  116. "size": v.Limit,
  117. "total": total,
  118. },
  119. }))
  120. }
  121. func activityAward(c *bm.Context) {
  122. username, _, err := checkCookie(c)
  123. if err != nil {
  124. c.JSON(nil, err)
  125. log.Error("checkCookie error(%v)", err)
  126. return
  127. }
  128. v := new(struct {
  129. ID int64 `form:"id" validate:"required"`
  130. Name string `form:"name" validate:"required"`
  131. Date time.Time `form:"date" validate:"required"`
  132. StatisticsEnd time.Time `form:"statistics_end" validate:"required"`
  133. })
  134. if err = c.Bind(v); err != nil {
  135. return
  136. }
  137. if err = svr.ActivityAward(c, v.ID, v.Name, v.Date, v.StatisticsEnd, username); err != nil {
  138. log.Error("svr.ActivityAward error(%v)", err)
  139. c.Render(http.StatusOK, render.MapJSON(map[string]interface{}{
  140. "code": 500,
  141. "message": err.Error(),
  142. }))
  143. } else {
  144. c.JSON(nil, nil)
  145. }
  146. }