tips.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. package http
  2. import (
  3. "go-common/app/admin/main/vip/model"
  4. "go-common/library/ecode"
  5. "go-common/library/log"
  6. bm "go-common/library/net/http/blademaster"
  7. )
  8. // tips info.
  9. func tips(c *bm.Context) {
  10. var (
  11. res []*model.Tips
  12. err error
  13. )
  14. arg := new(struct {
  15. State int8 `form:"state"`
  16. Platform int8 `form:"platform"`
  17. Position int8 `form:"position"`
  18. })
  19. if err = c.Bind(arg); err != nil {
  20. log.Error("c.Bind err(%+v)", err)
  21. return
  22. }
  23. if res, err = vipSvc.TipList(c, arg.Platform, arg.State, arg.Position); err != nil {
  24. log.Error("vipSvc.TipList(%+v) err(%+v)", arg, err)
  25. c.JSON(nil, err)
  26. return
  27. }
  28. c.JSON(res, nil)
  29. }
  30. // tips info.
  31. func tipbyid(c *bm.Context) {
  32. var (
  33. res *model.Tips
  34. err error
  35. )
  36. arg := new(struct {
  37. ID int64 `form:"id" validate:"required,min=1,gte=1"`
  38. })
  39. if err = c.Bind(arg); err != nil {
  40. log.Error("c.Bind err(%+v)", err)
  41. return
  42. }
  43. if res, err = vipSvc.TipByID(c, arg.ID); err != nil {
  44. log.Error("vipSvc.TipByID(%d) err(%+v)", arg.ID, err)
  45. c.JSON(nil, err)
  46. return
  47. }
  48. c.JSON(res, nil)
  49. }
  50. // tips add.
  51. func tipadd(c *bm.Context) {
  52. var (
  53. err error
  54. arg = new(model.Tips)
  55. )
  56. if err = c.Bind(arg); err != nil {
  57. log.Error("c.Bind err(%+v)", err)
  58. return
  59. }
  60. opI, ok := c.Get("username")
  61. if !ok {
  62. c.JSON(nil, ecode.AccessDenied)
  63. return
  64. }
  65. arg.Operator = opI.(string)
  66. if err = vipSvc.AddTip(c, arg); err != nil {
  67. log.Error("vipSvc.AddTip(%v) err(%+v)", arg, err)
  68. c.JSON(nil, err)
  69. return
  70. }
  71. c.JSON(nil, nil)
  72. }
  73. // tips update.
  74. func tipupdate(c *bm.Context) {
  75. var (
  76. err error
  77. arg = new(model.Tips)
  78. )
  79. if err = c.Bind(arg); err != nil {
  80. log.Error("c.Bind err(%+v)", err)
  81. return
  82. }
  83. opI, ok := c.Get("username")
  84. if !ok {
  85. c.JSON(nil, ecode.AccessDenied)
  86. return
  87. }
  88. arg.Operator = opI.(string)
  89. if err = vipSvc.TipUpdate(c, arg); err != nil {
  90. log.Error("vipSvc.TipUpdate(%v) err(%+v)", arg, err)
  91. c.JSON(nil, err)
  92. return
  93. }
  94. c.JSON(nil, nil)
  95. }
  96. // tips delete.
  97. func tipdelete(c *bm.Context) {
  98. var (
  99. err error
  100. )
  101. arg := new(struct {
  102. ID int64 `form:"id" validate:"required,min=1,gte=1"`
  103. })
  104. if err = c.Bind(arg); err != nil {
  105. log.Error("c.Bind err(%+v)", err)
  106. return
  107. }
  108. opI, ok := c.Get("username")
  109. if !ok {
  110. c.JSON(nil, ecode.AccessDenied)
  111. return
  112. }
  113. if err = vipSvc.DeleteTip(c, arg.ID, opI.(string)); err != nil {
  114. log.Error("vipSvc.DeleteTip(%d) err(%+v)", arg.ID, err)
  115. c.JSON(nil, err)
  116. return
  117. }
  118. c.JSON(nil, nil)
  119. }
  120. // tips expire.
  121. func tipexpire(c *bm.Context) {
  122. var (
  123. err error
  124. )
  125. arg := new(struct {
  126. ID int64 `form:"id" validate:"required,min=1,gte=1"`
  127. })
  128. if err = c.Bind(arg); err != nil {
  129. log.Error("c.Bind err(%+v)", err)
  130. return
  131. }
  132. opI, ok := c.Get("username")
  133. if !ok {
  134. c.JSON(nil, ecode.AccessDenied)
  135. return
  136. }
  137. if err = vipSvc.ExpireTip(c, arg.ID, opI.(string)); err != nil {
  138. log.Error("vipSvc.ExpireTip(%d) err(%+v)", arg.ID, err)
  139. c.JSON(nil, err)
  140. return
  141. }
  142. c.JSON(nil, nil)
  143. }