point.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. package http
  2. import (
  3. "go-common/app/admin/main/point/model"
  4. pointmol "go-common/app/service/main/point/model"
  5. "go-common/library/ecode"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. )
  9. func pointConfList(c *bm.Context) {
  10. var (
  11. err error
  12. res []*model.PointConf
  13. )
  14. if res, err = svc.PointConfList(c); err != nil {
  15. return
  16. }
  17. c.JSON(&model.PageInfo{Count: len(res), Item: res}, nil)
  18. }
  19. func pointConfInfo(c *bm.Context) {
  20. var (
  21. err error
  22. res *model.PointConf
  23. )
  24. arg := &model.ArgID{}
  25. if err = c.Bind(arg); err != nil {
  26. return
  27. }
  28. if res, err = svc.PointCoinInfo(c, arg.ID); err != nil {
  29. log.Error("svc.PointCoinInfo(%d), err(%+v)", arg.ID, err)
  30. c.JSON(nil, err)
  31. return
  32. }
  33. c.JSON(res, nil)
  34. }
  35. func pointConfAdd(c *bm.Context) {
  36. var (
  37. err error
  38. )
  39. opI, ok := c.Get("username")
  40. if !ok {
  41. c.JSON(nil, ecode.AccessDenied)
  42. return
  43. }
  44. pc := &model.PointConf{}
  45. if err = c.Bind(pc); err != nil {
  46. return
  47. }
  48. pc.Operator = opI.(string)
  49. if _, err = svc.PointCoinAdd(c, pc); err != nil {
  50. log.Error("svc.PointCoinAdd(%+v), err(%+v)", pc, err)
  51. c.JSON(nil, err)
  52. return
  53. }
  54. c.JSON(nil, nil)
  55. }
  56. func pointConfEdit(c *bm.Context) {
  57. var (
  58. err error
  59. )
  60. opI, ok := c.Get("username")
  61. if !ok {
  62. c.JSON(nil, ecode.AccessDenied)
  63. return
  64. }
  65. pc := &model.PointConf{}
  66. if err = c.Bind(pc); err != nil {
  67. return
  68. } else if pc.ID == 0 {
  69. c.JSON(nil, ecode.RequestErr)
  70. return
  71. }
  72. pc.Operator = opI.(string)
  73. if err = svc.PointCoinEdit(c, pc); err != nil {
  74. log.Error("svc.PointCoinEdit(%+v), err(%+v)", pc, err)
  75. c.JSON(nil, err)
  76. return
  77. }
  78. c.JSON(nil, nil)
  79. }
  80. func pointHistory(c *bm.Context) {
  81. var err error
  82. arg := &model.ArgPointHistory{}
  83. if err = c.Bind(arg); err != nil {
  84. return
  85. }
  86. c.JSON(svc.PointHistory(c, arg))
  87. }
  88. func pointUserAdd(c *bm.Context) {
  89. var (
  90. err error
  91. )
  92. opI, ok := c.Get("username")
  93. if !ok {
  94. c.JSON(nil, ecode.AccessDenied)
  95. return
  96. }
  97. req := new(model.ArgPoint)
  98. if err = c.Bind(req); err != nil {
  99. log.Error("point add bind %+v", err)
  100. return
  101. }
  102. if req.Point <= 0 {
  103. c.JSON(nil, ecode.RequestErr)
  104. return
  105. }
  106. arg := new(pointmol.ArgPoint)
  107. arg.Mid = req.Mid
  108. arg.Point = req.Point
  109. arg.Remark = req.Remark
  110. arg.Operator = opI.(string)
  111. arg.ChangeType = model.PointSystem
  112. if err = svc.PointAdd(c, arg); err != nil {
  113. log.Error("point add(%+v) faild(%+v)", arg, err)
  114. c.JSON(nil, err)
  115. return
  116. }
  117. c.JSON(nil, nil)
  118. }