view.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. package http
  2. import (
  3. "mime/multipart"
  4. "go-common/app/admin/main/coupon/model"
  5. "go-common/library/ecode"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. "go-common/library/net/http/blademaster/binding"
  9. )
  10. func viewBatchAdd(c *bm.Context) {
  11. var err error
  12. arg := new(model.ArgCouponViewBatch)
  13. if err = c.Bind(arg); err != nil {
  14. log.Error("c.Bind err(%+v)", err)
  15. return
  16. }
  17. operator, ok := c.Get("username")
  18. if !ok {
  19. c.JSON(nil, ecode.AccessDenied)
  20. return
  21. }
  22. arg.Operator = operator.(string)
  23. c.JSON(nil, svc.CouponViewBatchAdd(c, arg))
  24. }
  25. func viewBatchSave(c *bm.Context) {
  26. var err error
  27. arg := new(model.ArgCouponViewBatch)
  28. if err = c.Bind(arg); err != nil {
  29. log.Error("c.Bind err(%+v)", err)
  30. return
  31. }
  32. operator, ok := c.Get("username")
  33. if !ok {
  34. c.JSON(nil, ecode.AccessDenied)
  35. return
  36. }
  37. arg.Operator = operator.(string)
  38. c.JSON(nil, svc.CouponViewbatchSave(c, arg))
  39. }
  40. func viewBlock(c *bm.Context) {
  41. var err error
  42. arg := new(struct {
  43. Mid int64 `form:"mid" validate:"required"`
  44. CouponToken string `form:"coupon_token" validate:"required"`
  45. })
  46. if err = c.Bind(arg); err != nil {
  47. log.Error("c.bind err(%+v)", err)
  48. return
  49. }
  50. _, ok := c.Get("username")
  51. if !ok {
  52. c.JSON(nil, ecode.AccessDenied)
  53. return
  54. }
  55. c.JSON(nil, svc.CouponViewBlock(c, arg.Mid, arg.CouponToken))
  56. }
  57. func viewUnblock(c *bm.Context) {
  58. var err error
  59. arg := new(struct {
  60. Mid int64 `form:"mid" validate:"required"`
  61. CouponToken string `form:"coupon_token" validate:"required"`
  62. })
  63. if err = c.Bind(arg); err != nil {
  64. log.Error("c.bind err(%+v)", err)
  65. return
  66. }
  67. _, ok := c.Get("username")
  68. if !ok {
  69. c.JSON(nil, ecode.AccessDenied)
  70. return
  71. }
  72. c.JSON(nil, svc.CouponViewUnblock(c, arg.Mid, arg.CouponToken))
  73. }
  74. func viewList(c *bm.Context) {
  75. var err error
  76. arg := new(model.ArgSearchCouponView)
  77. if err = c.Bind(arg); err != nil {
  78. log.Error("c.bind err(%+v)", err)
  79. return
  80. }
  81. res, count, err := svc.CouponViewList(c, arg)
  82. info := new(model.PageInfo)
  83. info.CurrentPage = arg.PN
  84. info.Count = int(count)
  85. info.Item = res
  86. c.JSON(info, err)
  87. }
  88. func salaryView(c *bm.Context) {
  89. var (
  90. f multipart.File
  91. h *multipart.FileHeader
  92. err error
  93. )
  94. arg := new(model.ArgAllowanceSalary)
  95. if err = c.BindWith(arg, binding.FormMultipart); err != nil {
  96. c.JSON(nil, ecode.RequestErr)
  97. return
  98. }
  99. if len(arg.Mids) <= 0 {
  100. f, h, err = c.Request.FormFile("file")
  101. if err != nil {
  102. c.JSON(nil, ecode.RequestErr)
  103. return
  104. }
  105. }
  106. c.JSON(svc.CouponViewSalary(c, f, h, arg.Mids, arg.BatchToken))
  107. }