consumer.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package http
  2. import (
  3. "net/http"
  4. "strconv"
  5. "go-common/library/ecode"
  6. bm "go-common/library/net/http/blademaster"
  7. "go-common/library/net/http/blademaster/render"
  8. )
  9. // 登录管理
  10. func on(c *bm.Context) {
  11. uid, uname := getUIDName(c)
  12. err := srv.HandsUp(c, uid, uname)
  13. if err != nil {
  14. data := map[string]interface{}{
  15. "code": ecode.RequestErr,
  16. "message": err.Error(),
  17. }
  18. c.Render(http.StatusOK, render.MapJSON(data))
  19. return
  20. }
  21. c.JSON(nil, nil)
  22. }
  23. // 踢出
  24. func forceoff(c *bm.Context) {
  25. uidS := c.Request.Form.Get("uid")
  26. uid, _ := strconv.ParseInt(uidS, 10, 64)
  27. if uid == 0 {
  28. c.JSON(nil, ecode.RequestErr)
  29. return
  30. }
  31. adminuid, _ := getUIDName(c)
  32. err := srv.HandsOff(c, adminuid, uid)
  33. if err != nil {
  34. data := map[string]interface{}{
  35. "code": ecode.RequestErr,
  36. "message": err.Error(),
  37. }
  38. c.Render(http.StatusOK, render.MapJSON(data))
  39. return
  40. }
  41. c.JSON(nil, nil)
  42. }
  43. func off(c *bm.Context) {
  44. adminuid, _ := getUIDName(c)
  45. err := srv.HandsOff(c, adminuid, 0)
  46. if err != nil {
  47. data := map[string]interface{}{
  48. "code": ecode.RequestErr,
  49. "message": err.Error(),
  50. }
  51. c.Render(http.StatusOK, render.MapJSON(data))
  52. return
  53. }
  54. c.JSON(nil, nil)
  55. }
  56. func online(c *bm.Context) {
  57. c.JSON(srv.Online(c))
  58. }
  59. func inoutlist(c *bm.Context) {
  60. v := new(struct {
  61. Unames string `form:"unames" default:""`
  62. Bt string `form:"bt" default:""`
  63. Et string `form:"et" default:""`
  64. })
  65. if err := c.Bind(v); err != nil {
  66. c.JSON(nil, ecode.RequestErr)
  67. return
  68. }
  69. c.JSON(srv.InOutList(c, v.Unames, v.Bt, v.Et))
  70. }