coupon.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. package http
  2. import (
  3. "go-common/app/service/main/coupon/model"
  4. "go-common/library/log"
  5. bm "go-common/library/net/http/blademaster"
  6. )
  7. func userCoupon(c *bm.Context) {
  8. var (
  9. err error
  10. count int
  11. )
  12. arg := new(model.ArgMid)
  13. if err = c.Bind(arg); err != nil {
  14. log.Error("user coupon bind %+v", err)
  15. return
  16. }
  17. switch arg.Type {
  18. case model.CouponVideo:
  19. if count, err = svc.VideoCouponCount(c, arg.Mid, arg.Type); err != nil {
  20. log.Error("user coupon(%d) %+v", arg.Mid, err)
  21. }
  22. case model.CouponCartoon:
  23. if count, err = svc.CarToonCouponCount(c, arg.Mid, arg.Type); err != nil {
  24. log.Error("user coupon(%d) %+v", arg.Mid, err)
  25. }
  26. }
  27. c.JSON(map[string]interface{}{
  28. "count": count,
  29. "mid": arg.Mid,
  30. }, nil)
  31. }
  32. func useCoupon(c *bm.Context) {
  33. var (
  34. err error
  35. state int8
  36. token string
  37. )
  38. arg := new(model.ArgUseCoupon)
  39. if err = c.Bind(arg); err != nil {
  40. log.Error("use coupon bind %+v", err)
  41. return
  42. }
  43. if state, token, err = svc.UseCoupon(c, arg.Mid, arg.Oid, arg.Remark, arg.OrderNO, arg.Type, arg.Ver); err != nil {
  44. log.Error("use coupon(%d) %+v", arg.Mid, err)
  45. }
  46. log.Info("use coupon ret(%d,%s)", state, token)
  47. c.JSON(map[string]interface{}{
  48. "state": state,
  49. "coupon_token": token,
  50. }, nil)
  51. }
  52. func useCartoonCoupon(c *bm.Context) {
  53. var (
  54. err error
  55. state int8
  56. token string
  57. )
  58. arg := new(model.ArgUseCartoonCoupon)
  59. if err = c.Bind(arg); err != nil {
  60. log.Error("use coupon bind %+v", err)
  61. return
  62. }
  63. if state, token, err = svc.CartoonUse(c, arg.Mid, arg.OrderNO, arg.Type, arg.Ver, arg.Remark, arg.Tips, arg.Count); err != nil {
  64. log.Error("use coupon(%d) %+v", arg.Mid, err)
  65. c.JSON(nil, err)
  66. return
  67. }
  68. c.JSON(map[string]interface{}{
  69. "state": state,
  70. "coupon_token": token,
  71. }, nil)
  72. }
  73. func couponInfo(c *bm.Context) {
  74. var err error
  75. arg := new(model.ArgCoupon)
  76. if err = c.Bind(arg); err != nil {
  77. log.Error("coupon info bind %+v", err)
  78. return
  79. }
  80. c.JSON(svc.CouponInfo(c, arg.Mid, arg.CouponToken))
  81. }
  82. func addCoupon(c *bm.Context) {
  83. var err error
  84. arg := new(model.ArgAdd)
  85. if err = c.Bind(arg); err != nil {
  86. log.Error("add coupon bind %+v", err)
  87. return
  88. }
  89. c.JSON(nil, svc.AddCoupon(c, arg.Mid, arg.StartTime, arg.ExpireTime, arg.Type, arg.Origin))
  90. }
  91. func changeCoupon(c *bm.Context) {
  92. var err error
  93. arg := new(model.ChangeCoupon)
  94. if err = c.Bind(arg); err != nil {
  95. log.Error("coupon info bind %+v", err)
  96. return
  97. }
  98. c.JSON(nil, svc.ChangeState(c, arg.Mid, arg.UseVer, arg.Ver, arg.CouponToken))
  99. }
  100. func salaryCoupon(c *bm.Context) {
  101. var err error
  102. arg := new(model.ArgSalaryCoupon)
  103. if err = c.Bind(arg); err != nil {
  104. log.Error("coupon info bind %+v", err)
  105. return
  106. }
  107. arg.Origin = int64(model.VipSalary)
  108. if err = svc.SalaryCoupon(c, arg); err != nil {
  109. log.Error("svc.SalaryCoupon(%d) %+v", arg.Mid, err)
  110. c.JSON(nil, err)
  111. return
  112. }
  113. c.JSON(nil, nil)
  114. }