user.go 985 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package api
  2. import (
  3. "log"
  4. "strconv"
  5. "strings"
  6. "github.com/710leo/urlooker/dataobj"
  7. "github.com/710leo/urlooker/modules/web/model"
  8. )
  9. type UsersResponse struct {
  10. Message string
  11. Data []*dataobj.User
  12. }
  13. func (this *Web) GetUsersByTeam(req string, reply *UsersResponse) error {
  14. tids := strings.Split(req, ",")
  15. if len(tids) < 1 || tids[0] == "" {
  16. reply.Message = "user no exists!"
  17. return nil
  18. }
  19. allUsers := make([]*dataobj.User, 0)
  20. for _, tid := range tids {
  21. id, err := strconv.ParseInt(tid, 10, 64)
  22. if err != nil {
  23. log.Println("tid error:", err)
  24. continue
  25. }
  26. users, err := model.UsersInfoOfTeam(id)
  27. if err != nil {
  28. reply.Message = err.Error()
  29. }
  30. for _, user := range users {
  31. u := &dataobj.User{
  32. Id: user.Id,
  33. Name: user.Name,
  34. Cnname: user.Cnname,
  35. Email: user.Email,
  36. Phone: user.Phone,
  37. Wechat: user.Wechat,
  38. Role: user.Role,
  39. }
  40. allUsers = append(allUsers, u)
  41. }
  42. }
  43. reply.Data = allUsers
  44. return nil
  45. }