bws.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/app/interface/main/activity/model/bws"
  5. "go-common/library/ecode"
  6. bm "go-common/library/net/http/blademaster"
  7. )
  8. func user(c *bm.Context) {
  9. var loginMid int64
  10. v := new(struct {
  11. Bid int64 `form:"bid" validate:"min=1"`
  12. Mid int64 `form:"mid"`
  13. Key string `form:"key"`
  14. })
  15. if err := c.Bind(v); err != nil {
  16. return
  17. }
  18. if midInter, ok := c.Get("mid"); ok {
  19. loginMid = midInter.(int64)
  20. }
  21. if v.Mid == 0 {
  22. v.Mid = loginMid
  23. }
  24. if v.Mid == 0 && v.Key == "" {
  25. c.JSON(nil, ecode.RequestErr)
  26. return
  27. }
  28. c.JSON(bwsSvc.User(c, v.Bid, v.Mid, v.Key))
  29. }
  30. func points(c *bm.Context) {
  31. p := new(bws.ParamPoints)
  32. if err := c.Bind(p); err != nil {
  33. return
  34. }
  35. c.JSON(bwsSvc.Points(c, p))
  36. }
  37. func point(c *bm.Context) {
  38. p := new(bws.ParamID)
  39. if err := c.Bind(p); err != nil {
  40. return
  41. }
  42. c.JSON(bwsSvc.Point(c, p))
  43. }
  44. func achievements(c *bm.Context) {
  45. p := new(bws.ParamID)
  46. if err := c.Bind(p); err != nil {
  47. return
  48. }
  49. if p.Day != "" {
  50. var (
  51. day int64
  52. err error
  53. )
  54. if day, err = strconv.ParseInt(p.Day, 10, 64); err != nil {
  55. c.JSON(nil, ecode.RequestErr)
  56. return
  57. }
  58. if day < 20180719 || day > 20180722 {
  59. c.JSON(nil, ecode.RequestErr)
  60. return
  61. }
  62. }
  63. c.JSON(bwsSvc.Achievements(c, p))
  64. }
  65. func achievement(c *bm.Context) {
  66. p := new(bws.ParamID)
  67. if err := c.Bind(p); err != nil {
  68. return
  69. }
  70. c.JSON(bwsSvc.Achievement(c, p))
  71. }
  72. func unlock(c *bm.Context) {
  73. v := new(bws.ParamUnlock)
  74. if err := c.Bind(v); err != nil {
  75. return
  76. }
  77. midStr, _ := c.Get("mid")
  78. mid := midStr.(int64)
  79. if v.Mid == 0 && v.Key == "" {
  80. c.JSON(nil, ecode.RequestErr)
  81. return
  82. }
  83. c.JSON(nil, bwsSvc.Unlock(c, mid, v))
  84. }
  85. func binding(c *bm.Context) {
  86. p := new(bws.ParamBinding)
  87. if err := c.Bind(p); err != nil {
  88. return
  89. }
  90. midStr, _ := c.Get("mid")
  91. mid := midStr.(int64)
  92. c.JSON(nil, bwsSvc.Binding(c, mid, p))
  93. }
  94. func award(c *bm.Context) {
  95. p := new(bws.ParamAward)
  96. if err := c.Bind(p); err != nil {
  97. return
  98. }
  99. if p.Mid == 0 && p.Key == "" {
  100. c.JSON(nil, ecode.RequestErr)
  101. return
  102. }
  103. midStr, _ := c.Get("mid")
  104. mid := midStr.(int64)
  105. c.JSON(nil, bwsSvc.Award(c, mid, p))
  106. }
  107. func lottery(c *bm.Context) {
  108. p := new(struct {
  109. Bid int64 `form:"bid" validate:"min=1"`
  110. Aid int64 `form:"aid" validate:"min=1"`
  111. Day string `form:"day"`
  112. })
  113. if err := c.Bind(p); err != nil {
  114. return
  115. }
  116. if p.Day != "" {
  117. var (
  118. day int64
  119. err error
  120. )
  121. if day, err = strconv.ParseInt(p.Day, 10, 64); err != nil {
  122. c.JSON(nil, ecode.RequestErr)
  123. return
  124. }
  125. if day < 20180719 || day > 20180722 {
  126. c.JSON(nil, ecode.RequestErr)
  127. return
  128. }
  129. }
  130. midStr, _ := c.Get("mid")
  131. mid := midStr.(int64)
  132. c.JSON(bwsSvc.Lottery(c, p.Bid, mid, p.Aid, p.Day))
  133. }
  134. func redisInfo(c *bm.Context) {
  135. v := new(struct {
  136. Mid int64 `form:"mid"`
  137. Key string `form:"key"`
  138. Type string `form:"type" validate:"required"`
  139. Day string `form:"day"`
  140. Del int `form:"del"`
  141. })
  142. if err := c.Bind(v); err != nil {
  143. return
  144. }
  145. midStr, _ := c.Get("mid")
  146. loginMid := midStr.(int64)
  147. c.JSON(bwsSvc.RedisInfo(c, loginMid, v.Mid, v.Key, v.Day, v.Type, v.Del))
  148. }
  149. func keyInfo(c *bm.Context) {
  150. v := new(struct {
  151. ID int64 `form:"id"`
  152. Mid int64 `form:"mid"`
  153. Key string `form:"key"`
  154. Type string `form:"type" validate:"required"`
  155. Del int `form:"del"`
  156. })
  157. if err := c.Bind(v); err != nil {
  158. return
  159. }
  160. midStr, _ := c.Get("mid")
  161. loginMid := midStr.(int64)
  162. c.JSON(bwsSvc.KeyInfo(c, loginMid, v.ID, v.Mid, v.Key, v.Type, v.Del))
  163. }
  164. func lotteryCheck(c *bm.Context) {
  165. v := new(struct {
  166. Aid int64 `form:"aid" validate:"min=1"`
  167. Day string `form:"day"`
  168. })
  169. if err := c.Bind(v); err != nil {
  170. return
  171. }
  172. midStr, _ := c.Get("mid")
  173. mid := midStr.(int64)
  174. c.JSON(bwsSvc.LotteryCheck(c, mid, v.Aid, v.Day))
  175. }
  176. func adminInfo(c *bm.Context) {
  177. v := new(struct {
  178. Bid int64 `form:"bid" validate:"min=1"`
  179. })
  180. if err := c.Bind(v); err != nil {
  181. return
  182. }
  183. midStr, _ := c.Get("mid")
  184. mid := midStr.(int64)
  185. c.JSON(bwsSvc.AdminInfo(c, v.Bid, mid))
  186. }