coupon.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package http
  2. import (
  3. "go-common/app/interface/main/account/model"
  4. v1 "go-common/app/service/main/coupon/api"
  5. col "go-common/app/service/main/coupon/model"
  6. "go-common/library/ecode"
  7. bm "go-common/library/net/http/blademaster"
  8. "go-common/library/net/metadata"
  9. )
  10. func allowanceList(c *bm.Context) {
  11. var (
  12. err error
  13. )
  14. mid, exists := c.Get("mid")
  15. if !exists {
  16. c.JSON(nil, ecode.AccountNotLogin)
  17. return
  18. }
  19. arg := new(model.ArgAllowanceList)
  20. if err = c.Bind(arg); err != nil {
  21. return
  22. }
  23. c.JSON(couponSvc.AllowanceList(c, mid.(int64), arg.State))
  24. }
  25. func couponPage(c *bm.Context) {
  26. var err error
  27. mid, exists := c.Get("mid")
  28. if !exists {
  29. c.JSON(nil, ecode.AccountNotLogin)
  30. return
  31. }
  32. arg := new(model.ArgCouponPage)
  33. if err = c.Bind(arg); err != nil {
  34. return
  35. }
  36. c.JSON(couponSvc.CouponPage(c, &col.ArgRPCPage{
  37. Mid: mid.(int64),
  38. State: arg.State,
  39. Pn: arg.Pn,
  40. Ps: arg.Ps,
  41. }))
  42. }
  43. // func couponCartoonPage(c *bm.Context) {
  44. // var err error
  45. // mid, exists := c.Get("mid")
  46. // if !exists {
  47. // c.JSON(nil, ecode.AccountNotLogin)
  48. // return
  49. // }
  50. // arg := new(model.ArgCouponPage)
  51. // if err = c.Bind(arg); err != nil {
  52. // return
  53. // }
  54. // c.JSON(couponSvc.CouponCartoonPage(c, &col.ArgRPCPage{
  55. // Mid: mid.(int64),
  56. // State: arg.State,
  57. // Pn: arg.Pn,
  58. // Ps: arg.Ps,
  59. // }))
  60. // }
  61. func prizeCards(c *bm.Context) {
  62. mid, exists := c.Get("mid")
  63. if !exists {
  64. c.JSON(nil, ecode.AccountNotLogin)
  65. return
  66. }
  67. c.JSON(couponSvc.PrizeCards(c, &col.ArgCount{Mid: mid.(int64)}))
  68. }
  69. func prizeDraw(c *bm.Context) {
  70. var err error
  71. mid, exists := c.Get("mid")
  72. if !exists {
  73. c.JSON(nil, ecode.AccountNotLogin)
  74. return
  75. }
  76. arg := new(model.ArgPrizeDraw)
  77. if err = c.Bind(arg); err != nil {
  78. return
  79. }
  80. if arg.CardType == -1 {
  81. c.JSON(nil, ecode.RequestErr)
  82. return
  83. }
  84. c.JSON(couponSvc.PrizeDraw(c, &col.ArgPrizeDraw{Mid: mid.(int64), CardType: arg.CardType}))
  85. }
  86. func captchaToken(c *bm.Context) {
  87. c.JSON(couponSvc.CaptchaToken(c, &v1.CaptchaTokenReq{Ip: metadata.String(c, metadata.RemoteIP)}))
  88. }
  89. func useCouponCode(c *bm.Context) {
  90. var err error
  91. mid, exists := c.Get("mid")
  92. if !exists {
  93. c.JSON(nil, ecode.AccountNotLogin)
  94. return
  95. }
  96. arg := new(col.ArgUseCouponCode)
  97. if err = c.Bind(arg); err != nil {
  98. return
  99. }
  100. arg.IP = metadata.String(c, metadata.RemoteIP)
  101. arg.Mid = mid.(int64)
  102. c.JSON(couponSvc.UseCouponCode(c, arg))
  103. }