spy.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. package http
  2. import (
  3. "encoding/json"
  4. "strconv"
  5. "go-common/app/service/main/spy/model"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. bm "go-common/library/net/http/blademaster"
  9. )
  10. func info(c *bm.Context) {
  11. var (
  12. err error
  13. mid int64
  14. midStr = c.Request.Form.Get("mid")
  15. )
  16. if mid, err = strconv.ParseInt(midStr, 10, 64); err != nil {
  17. c.JSON(nil, ecode.RequestErr)
  18. return
  19. }
  20. ui, err := spySvc.Info(c, mid)
  21. if err != nil {
  22. log.Error("spySvc.UserInfo(%d), ui(%v), err(%v)", mid, ui, err)
  23. c.JSON(nil, ecode.ServerErr)
  24. return
  25. }
  26. c.JSON(&model.UserScore{Mid: ui.Mid, Score: ui.Score}, nil)
  27. }
  28. func purgeUser(c *bm.Context) {
  29. var (
  30. err error
  31. mid int64
  32. params = c.Request.Form
  33. midStr = params.Get("mid")
  34. action = params.Get("modifiedAttr")
  35. )
  36. if mid, err = strconv.ParseInt(midStr, 10, 64); err != nil {
  37. c.JSON(nil, ecode.RequestErr)
  38. return
  39. }
  40. if action == "" {
  41. c.JSON(nil, ecode.RequestErr)
  42. return
  43. }
  44. err = spySvc.PurgeUser(c, mid, action)
  45. c.JSON(nil, err)
  46. }
  47. func purgeUser2(c *bm.Context) {
  48. var (
  49. err error
  50. params = c.Request.Form
  51. msg = params.Get("msg")
  52. info = new(model.NotifyInfo)
  53. )
  54. if err = json.Unmarshal([]byte(msg), &info); err != nil {
  55. log.Error("purgeUser2 (%s) json.Unmarshal error(%v)", msg, err)
  56. c.JSON(nil, ecode.RequestErr)
  57. return
  58. }
  59. if info == nil {
  60. c.JSON(nil, ecode.RequestErr)
  61. return
  62. }
  63. if info.Action == "" || info.Mid == 0 {
  64. c.JSON(nil, ecode.RequestErr)
  65. return
  66. }
  67. if err = spySvc.PurgeUser(c, info.Mid, info.Action); err != nil {
  68. log.Error("purgeUser2 (%+v) error(%v)", info, err)
  69. }
  70. c.JSON(nil, err)
  71. }
  72. func stat(c *bm.Context) {
  73. var (
  74. err error
  75. mid, id int64
  76. params = c.Request.Form
  77. midStr = params.Get("mid")
  78. idStr = params.Get("id")
  79. )
  80. if mid, err = strconv.ParseInt(midStr, 10, 64); midStr != "" && err != nil {
  81. c.JSON(nil, ecode.RequestErr)
  82. return
  83. }
  84. if id, err = strconv.ParseInt(idStr, 10, 64); idStr != "" && err != nil {
  85. c.JSON(nil, ecode.RequestErr)
  86. return
  87. }
  88. if id == 0 && mid == 0 {
  89. c.JSON(nil, ecode.RequestErr)
  90. return
  91. }
  92. stat, err := spySvc.StatByID(c, mid, id)
  93. if err != nil {
  94. log.Error("spySvc.StatByID err(%v)", err)
  95. c.JSON(nil, ecode.ServerErr)
  96. return
  97. }
  98. c.JSON(stat, nil)
  99. }