month.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package http
  2. import (
  3. "go-common/app/admin/main/vip/model"
  4. "go-common/library/ecode"
  5. bm "go-common/library/net/http/blademaster"
  6. )
  7. func monthList(c *bm.Context) {
  8. var (
  9. res []*model.VipMonth
  10. err error
  11. )
  12. if res, err = vipSvc.MonthList(c); err != nil {
  13. c.JSON(nil, err)
  14. return
  15. }
  16. page := &model.PageInfo{Count: len(res), Item: res}
  17. c.JSON(page, nil)
  18. }
  19. func monthEdit(c *bm.Context) {
  20. var (
  21. err error
  22. arg = new(model.ArgIDExtra)
  23. )
  24. username, ok := c.Get("username")
  25. if !ok {
  26. c.JSON(nil, ecode.AccessDenied)
  27. return
  28. }
  29. if err = c.Bind(arg); err != nil {
  30. return
  31. }
  32. arg.Operator = username.(string)
  33. c.JSON(nil, vipSvc.MonthEdit(c, arg.ID, arg.Status, arg.Operator))
  34. }
  35. func priceList(c *bm.Context) {
  36. var (
  37. res []*model.VipMonthPrice
  38. err error
  39. arg = new(model.ArgID)
  40. )
  41. if err = c.Bind(arg); err != nil {
  42. return
  43. }
  44. if res, err = vipSvc.PriceList(c, arg.ID); err != nil {
  45. c.JSON(nil, err)
  46. return
  47. }
  48. page := &model.PageInfo{Count: len(res), Item: res}
  49. c.JSON(page, nil)
  50. }
  51. func priceAdd(c *bm.Context) {
  52. var (
  53. err error
  54. mp = new(model.VipMonthPrice)
  55. )
  56. username, ok := c.Get("username")
  57. if !ok {
  58. c.JSON(nil, ecode.AccessDenied)
  59. return
  60. }
  61. mp.Operator = username.(string)
  62. if err = c.Bind(mp); err != nil {
  63. return
  64. }
  65. c.JSON(nil, vipSvc.PriceAdd(c, mp))
  66. }
  67. func priceEdit(c *bm.Context) {
  68. var (
  69. err error
  70. mp = new(model.VipMonthPrice)
  71. )
  72. username, ok := c.Get("username")
  73. if !ok {
  74. c.JSON(nil, ecode.AccessDenied)
  75. return
  76. }
  77. mp.Operator = username.(string)
  78. if err = c.Bind(mp); err != nil {
  79. return
  80. }
  81. if mp.ID <= 0 {
  82. c.JSON(nil, ecode.RequestErr)
  83. return
  84. }
  85. c.JSON(nil, vipSvc.PriceEdit(c, mp))
  86. }