blacklist.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package http
  2. import (
  3. "fmt"
  4. "net/http"
  5. "time"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. "go-common/library/net/http/blademaster/render"
  9. )
  10. func queryBlacklist(c *bm.Context) {
  11. v := new(struct {
  12. FromTime int64 `form:"from_time"`
  13. ToTime int64 `form:"to_time"`
  14. Type int `form:"type"`
  15. Reason int `form:"reason"`
  16. MID int64 `form:"mid"`
  17. Nickname string `form:"nickname"`
  18. AID int64 `form:"aid"`
  19. From int `form:"from" validate:"min=0" default:"0"`
  20. Limit int `form:"limit" validate:"min=1" default:"20"`
  21. Sort string `form:"sort"`
  22. })
  23. if err := c.Bind(v); err != nil {
  24. return
  25. }
  26. total, blacklist, err := svr.QueryBlacklist(v.FromTime, v.ToTime, v.Type, v.Reason, v.MID, v.Nickname, v.AID, v.From, v.Limit, v.Sort)
  27. if err != nil {
  28. log.Error("growup svr.QueryBlacklist error(%v)", err)
  29. c.JSON(nil, err)
  30. return
  31. }
  32. c.Render(http.StatusOK, render.MapJSON(map[string]interface{}{
  33. "code": 0,
  34. "message": "0",
  35. "data": blacklist,
  36. "paging": map[string]int{
  37. "page_size": v.Limit,
  38. "total": total,
  39. },
  40. }))
  41. }
  42. func exportBlack(c *bm.Context) {
  43. v := new(struct {
  44. FromTime int64 `form:"from_time"`
  45. ToTime int64 `form:"to_time"`
  46. Type int `form:"type"`
  47. Reason int `form:"reason"`
  48. MID int64 `form:"mid"`
  49. Nickname string `form:"nickname"`
  50. AID int64 `form:"aid"`
  51. From int `form:"from" validate:"min=0" default:"0"`
  52. Limit int `form:"limit" validate:"min=1" default:"20"`
  53. Sort string `form:"sort"`
  54. })
  55. if err := c.Bind(v); err != nil {
  56. return
  57. }
  58. content, err := svr.ExportBlacklist(v.FromTime, v.ToTime, v.Type, v.Reason, v.MID, v.Nickname, v.AID, v.From, v.Limit, v.Sort)
  59. if err != nil {
  60. log.Error("growup svr.ExportBlacklist error(%v)", err)
  61. c.JSON(nil, err)
  62. return
  63. }
  64. c.Render(http.StatusOK, CSV{
  65. Content: content,
  66. Title: fmt.Sprintf("%s-%s", time.Now().Format("2006-01-02"), "blacklist"),
  67. })
  68. }
  69. func recoverBlacklist(c *bm.Context) {
  70. v := new(struct {
  71. AID int64 `form:"aid"`
  72. Type int `form:"type"`
  73. })
  74. if err := c.Bind(v); err != nil {
  75. return
  76. }
  77. err := svr.RecoverBlacklist(v.AID, v.Type)
  78. if err != nil {
  79. log.Error("growup svr.RecoverBlacklist error(%v)", err)
  80. }
  81. c.JSON(nil, err)
  82. }