identity.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package service
  2. import (
  3. "fmt"
  4. "strings"
  5. . "app.yhyue.com/moapp/jybase/common"
  6. "bp.jydev.jianyu360.cn/BaseService/userCenter/entity"
  7. . "bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/usercenter"
  8. )
  9. func IdentityList(userId int64) []*Identity {
  10. result := []*Identity{}
  11. list := entity.BaseMysql.SelectBySql(`SELECT DISTINCT a.id as position_id,c.person_id,a.person_name,a.account_id,a.type as position_type,a.ent_id,b.id as ent_account_id,d.phone from base_user d
  12. inner join base_position a on (d.id=? and d.id=a.user_id)
  13. left JOIN base_account b on (b.type=1 and b.person_id=0 and a.ent_id=b.ent_id)
  14. left JOIN base_account c on (a.account_id=c.id)`, userId)
  15. if list != nil {
  16. m := map[int64]*Identity{}
  17. entIds := []string{}
  18. phone := ""
  19. for _, v := range *list {
  20. i := &Identity{
  21. EntId: Int64All(v["ent_id"]),
  22. PersonId: Int64All(v["person_id"]),
  23. UserName: ObjToString(v["person_name"]),
  24. AccountId: Int64All(v["account_id"]),
  25. EntAccountId: Int64All(v["ent_account_id"]),
  26. PositionId: Int64All(v["position_id"]),
  27. PositionType: Int64All(v["position_type"]),
  28. }
  29. if i.PositionType == 0 {
  30. i.Name = "个人版"
  31. m[0] = i
  32. } else if i.EntId > 0 {
  33. m[i.EntId] = i
  34. entIds = append(entIds, fmt.Sprint(i.EntId))
  35. }
  36. if phone == "" {
  37. phone = ObjToString(v["phone"])
  38. }
  39. }
  40. if len(entIds) > 0 {
  41. ents := entity.Mysql.SelectBySql(`SELECT a.id,a.name,a.ent_id,b.name as ent_name from entniche_user a inner join entniche_info b on (a.phone=? and b.id in (`+strings.Join(entIds, ",")+`) and a.ent_id=b.id) order by b.createtime`, phone)
  42. if ents != nil {
  43. for _, v := range *ents {
  44. i := m[Int64All(v["ent_id"])]
  45. i.EntUserId = Int64All(v["id"])
  46. i.EntUserName = ObjToString(v["name"])
  47. i.Name = ObjToString(v["ent_name"])
  48. result = append(result, i)
  49. }
  50. }
  51. }
  52. if m[0] != nil {
  53. result = append(result, m[0])
  54. }
  55. }
  56. return result
  57. }