coupon.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. package http
  2. import (
  3. "go-common/app/admin/main/coupon/model"
  4. "go-common/library/ecode"
  5. "go-common/library/log"
  6. bm "go-common/library/net/http/blademaster"
  7. )
  8. // batchadd add.
  9. func batchadd(c *bm.Context) {
  10. var (
  11. err error
  12. )
  13. arg := new(model.ArgBatchInfo)
  14. if err = c.Bind(arg); err != nil {
  15. log.Error("c.Bind err(%+v)", err)
  16. return
  17. }
  18. operator, ok := c.Get("username")
  19. if !ok {
  20. c.JSON(nil, ecode.AccessDenied)
  21. return
  22. }
  23. b := new(model.CouponBatchInfo)
  24. b.AppID = arg.AppID
  25. b.Name = arg.Name
  26. if arg.MaxCount == 0 {
  27. b.MaxCount = -1
  28. } else {
  29. b.MaxCount = arg.MaxCount
  30. }
  31. if arg.LimitCount == 0 {
  32. b.LimitCount = -1
  33. } else {
  34. b.LimitCount = arg.LimitCount
  35. }
  36. b.StartTime = arg.StartTime
  37. b.ExpireTime = arg.ExpireTime
  38. b.Operator = operator.(string)
  39. if err = svc.AddBatchInfo(c, b); err != nil {
  40. log.Error("svc.AddBatchInfo(%v) err(%+v)", arg, err)
  41. c.JSON(nil, err)
  42. return
  43. }
  44. c.JSON(nil, nil)
  45. }
  46. func batchlist(c *bm.Context) {
  47. var (
  48. err error
  49. res []*model.CouponBatchResp
  50. )
  51. arg := new(model.ArgBatchList)
  52. if err = c.Bind(arg); err != nil {
  53. log.Error("c.Bind err(%+v)", err)
  54. return
  55. }
  56. if res, err = svc.BatchList(c, arg); err != nil {
  57. log.Error("svc.BatchList(%v) err(%+v)", arg, err)
  58. c.JSON(nil, err)
  59. return
  60. }
  61. c.JSON(res, nil)
  62. }
  63. func allAppInfo(c *bm.Context) {
  64. c.JSON(svc.AllAppInfo(c), nil)
  65. }
  66. func salaryCoupon(c *bm.Context) {
  67. var err error
  68. arg := new(model.ArgSalaryCoupon)
  69. if err = c.Bind(arg); err != nil {
  70. log.Error("c.Bind err(%+v)", err)
  71. return
  72. }
  73. if err = svc.SalaryCoupon(c, arg.Mid, arg.CouponType, arg.Count, arg.BranchToken); err != nil {
  74. log.Error("svc.SalaryCoupon(%v) err(%+v)", arg, err)
  75. c.JSON(nil, err)
  76. return
  77. }
  78. c.JSON(nil, nil)
  79. }
  80. func batchBlock(c *bm.Context) {
  81. var err error
  82. arg := new(model.ArgAllowance)
  83. if err = c.Bind(arg); err != nil {
  84. log.Error("c.Bind err(%+v)", err)
  85. return
  86. }
  87. operator, ok := c.Get("username")
  88. if !ok {
  89. c.JSON(nil, ecode.AccessDenied)
  90. return
  91. }
  92. c.JSON(nil, svc.UpdateBatchStatus(c, model.BatchStateBlock, operator.(string), arg.ID))
  93. }
  94. // allowanceUnBlock .
  95. func batchUnBlock(c *bm.Context) {
  96. var err error
  97. arg := new(model.ArgAllowance)
  98. if err = c.Bind(arg); err != nil {
  99. log.Error("c.Bind err(%+v)", err)
  100. return
  101. }
  102. operator, ok := c.Get("username")
  103. if !ok {
  104. c.JSON(nil, ecode.AccessDenied)
  105. return
  106. }
  107. c.JSON(nil, svc.UpdateBatchStatus(c, model.BatchStateNormal, operator.(string), arg.ID))
  108. }