accountquery.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package events
  2. import (
  3. "fmt"
  4. "box-gm/utils"
  5. "log"
  6. "strconv"
  7. "time"
  8. "github.com/garyburd/redigo/redis"
  9. )
  10. func AccountQuery_get_account_info(account string) (role_map map[string]map[string]string, account_status string) {
  11. if account == "" {
  12. return
  13. }
  14. uid_map, err := utils.Hgetall(fmt.Sprintf("tb_acc:%s", account))
  15. if err != nil || len(uid_map) == 0 {
  16. return
  17. }
  18. role_map = make(map[string]map[string]string)
  19. for k, v := range uid_map {
  20. if k != "status" && v != "" {
  21. info := PlayerQuery_get_player_info(v)
  22. role_map[v] = info
  23. }
  24. if k == "status" {
  25. account_status = v
  26. }
  27. }
  28. if account_status == "" {
  29. account_status = "0"
  30. }
  31. return
  32. }
  33. func AccountQuery_set_account_ban(account string, status int) error {
  34. if account == "" {
  35. return nil
  36. }
  37. err := utils.Hset(fmt.Sprintf("tb_acc:%s", account), "status", status)
  38. if err != nil {
  39. log.Printf("AccountQuery_set_account_ban :account[%v] err[%v]", account, err)
  40. }
  41. return err
  42. }
  43. func AccountQuery_get_account_status(account string) int {
  44. if account == "" {
  45. return 0
  46. }
  47. rep, err := utils.Hget(fmt.Sprintf("tb_acc:%s", account), "status")
  48. status, err := redis.Int(rep, err)
  49. if err != nil {
  50. log.Printf("AccountQuery_get_account_status :account[%v] err[%v]", account, err)
  51. }
  52. return status
  53. }
  54. func AccountQuery_get_show_data(account string) (role_map map[string]map[string]string, account_status string) {
  55. role_map, account_status = AccountQuery_get_account_info(account)
  56. if len(role_map) != 0 {
  57. for _, info := range role_map {
  58. for k, v := range info {
  59. if k == "login_time" || k == "logout_time" || k == "create_time" {
  60. tick, err := strconv.ParseInt(v, 10, 64)
  61. if err == nil {
  62. info[k] = time.Unix(tick, 0).Format("2006-01-02 15:04:05")
  63. }
  64. }
  65. if k == "status" {
  66. if v == "0" {
  67. info[k] = "正常"
  68. }
  69. if v == "1" {
  70. info[k] = "封禁"
  71. }
  72. }
  73. }
  74. }
  75. if account_status == "0" {
  76. account_status = "正常"
  77. }
  78. if account_status == "1" {
  79. account_status = "封禁"
  80. }
  81. }
  82. return role_map, account_status
  83. }