block.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package block
  2. import (
  3. "time"
  4. model "go-common/app/service/main/member/model/block"
  5. "go-common/library/ecode"
  6. bm "go-common/library/net/http/blademaster"
  7. )
  8. func info(c *bm.Context) {
  9. var (
  10. err error
  11. v = &model.ParamInfo{}
  12. )
  13. if err = bind(c, v); err != nil {
  14. return
  15. }
  16. var infos []*model.BlockInfo
  17. if infos, err = svc.Infos(c, []int64{v.MID}); err != nil {
  18. c.JSON(nil, err)
  19. return
  20. }
  21. if len(infos) != 1 {
  22. c.JSON(nil, ecode.ServerErr)
  23. return
  24. }
  25. c.JSON(infos[0], nil)
  26. }
  27. func batchInfo(c *bm.Context) {
  28. var (
  29. err error
  30. v = &model.ParamBatchInfo{}
  31. )
  32. if err = bind(c, v); err != nil {
  33. return
  34. }
  35. c.JSON(svc.Infos(c, v.MIDs))
  36. }
  37. func batchDetail(c *bm.Context) {
  38. var (
  39. err error
  40. v = &model.ParamBatchDetail{}
  41. )
  42. if err = bind(c, v); err != nil {
  43. return
  44. }
  45. c.JSON(svc.UserDetails(c, v.MIDs))
  46. }
  47. func block(c *bm.Context) {
  48. var (
  49. err error
  50. v = &model.ParamBlock{}
  51. )
  52. if err = bind(c, v); err != nil {
  53. return
  54. }
  55. duration := time.Duration(v.Duration) * time.Second
  56. c.JSON(nil, svc.Block(c, []int64{v.MID}, v.Source, v.Area, v.Action, v.StartTime, duration, v.Operator, v.Reason, v.Comment, v.Notify))
  57. }
  58. func batchBlock(c *bm.Context) {
  59. var (
  60. err error
  61. v = &model.ParamBatchBlock{}
  62. )
  63. if err = bind(c, v); err != nil {
  64. return
  65. }
  66. duration := time.Duration(v.Duration) * time.Second
  67. c.JSON(nil, svc.Block(c, v.MIDs, v.Source, v.Area, v.Action, v.StartTime, duration, v.Operator, v.Reason, v.Comment, v.Notify))
  68. }
  69. func remove(c *bm.Context) {
  70. var (
  71. err error
  72. v = &model.ParamRemove{}
  73. )
  74. if err = bind(c, v); err != nil {
  75. return
  76. }
  77. c.JSON(nil, svc.Remove(c, []int64{v.MID}, v.Source, model.BlockAreaNone, v.Operator, v.Reason, v.Comment, v.Notify))
  78. }
  79. func batchRemove(c *bm.Context) {
  80. var (
  81. err error
  82. v = &model.ParamBatchRemove{}
  83. )
  84. if err = bind(c, v); err != nil {
  85. return
  86. }
  87. c.JSON(nil, svc.Remove(c, v.MIDs, v.Source, model.BlockAreaNone, v.Operator, v.Reason, v.Comment, v.Notify))
  88. }