getuserinfologic.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. package logic
  2. import (
  3. "context"
  4. "fmt"
  5. "log"
  6. "bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/internal/svc"
  7. "bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/pb"
  8. "app.yhyue.com/moapp/jybase/common"
  9. "github.com/zeromicro/go-zero/core/logx"
  10. )
  11. type GetUserInfoLogic struct {
  12. ctx context.Context
  13. svcCtx *svc.ServiceContext
  14. logx.Logger
  15. }
  16. func NewGetUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserInfoLogic {
  17. return &GetUserInfoLogic{
  18. ctx: ctx,
  19. svcCtx: svcCtx,
  20. Logger: logx.WithContext(ctx),
  21. }
  22. }
  23. // 获取客户信息
  24. func (l *GetUserInfoLogic) GetUserInfo(in *pb.UserReq) (*pb.UserInfo, error) {
  25. // todo: add your logic here and delete this line
  26. resp := &pb.UserInfo{}
  27. ret, msg := SubscirbeService.GetSubscribeInfo(in)
  28. if msg != "" {
  29. l.Error(fmt.Sprintf("%+v", in), msg)
  30. resp.ErrorMsg = msg
  31. resp.ErrorCode = -1
  32. }
  33. resp.Nickname = common.ObjToString(ret["nickname"])
  34. resp.Headimg = common.ObjToString(ret["headimg"])
  35. resp.IsTourist = common.Int64All(ret["is_tourist"])
  36. //非游客
  37. if resp.IsTourist < 2 {
  38. resp.Phone = common.ObjToString(ret["phone"])
  39. resp.VipStatus = common.Int64All(ret["vipStatus"])
  40. resp.MemberStatus = common.Int64All(ret["memberStatus"])
  41. resp.EntnicheStatus = common.Int64All(ret["entnicheStatus"])
  42. resp.SubscribeType = common.ObjToString(ret["subscribeType"])
  43. items, ok := ret["items"].([]map[string]interface{})
  44. if !ok {
  45. inter_items, _ := ret["items"].([]interface{})
  46. items = common.ObjArrToMapArr(inter_items)
  47. }
  48. log.Println("items:", items)
  49. log.Println("oarea:", ret["o_area"], common.ObjToMap(ret["o_area"]))
  50. buyerclass, _ := ret["buyerclass"].([]interface{})
  51. infotype, _ := ret["infotype"].([]interface{})
  52. resp.Data = &pb.Subscribe{
  53. StartTime: common.Int64All(ret["starttime"]),
  54. EndTime: common.Int64All(ret["endtime"]),
  55. Area: l.formatM(common.ObjToMap(ret["area"])),
  56. Buyerclass: common.ObjArrToStringArr(buyerclass),
  57. Infotype: common.ObjArrToStringArr(infotype),
  58. Matchway: common.Int64All(ret["matchway"]),
  59. Projectmatch: common.Int64All(ret["projectmatch"]),
  60. Items: l.formatItems(items),
  61. }
  62. }
  63. return resp, nil
  64. }
  65. // 格式转化 map<string,list>转化
  66. func (l *GetUserInfoLogic) formatM(m *map[string]interface{}) map[string]*pb.List {
  67. retM := map[string]*pb.List{}
  68. if len(*m) == 0 {
  69. return retM
  70. }
  71. for k, v := range *m {
  72. s_v, ok := v.([]string)
  73. if !ok {
  74. interf, _ := v.([]interface{})
  75. s_v = common.ObjArrToStringArr(interf)
  76. }
  77. retM[k] = &pb.List{
  78. Value: s_v,
  79. }
  80. }
  81. return retM
  82. }
  83. func (l *GetUserInfoLogic) formatItems(m []map[string]interface{}) []*pb.Items {
  84. items := make([]*pb.Items, len(m))
  85. for k, v := range m {
  86. items[k] = &pb.Items{
  87. SItem: common.ObjToString(v["s_item"]),
  88. UpdateTime: common.Int64All(v["updatetime"]),
  89. }
  90. akey, _ := v["a_key"].([]map[string]interface{})
  91. pbKey := make([]*pb.Keys, len(akey))
  92. for kk, vv := range akey {
  93. key, ok := vv["key"].([]string)
  94. if !ok {
  95. inter_vv, _ := vv["key"].([]interface{})
  96. key = common.ObjArrToStringArr(inter_vv)
  97. }
  98. notkey, ok := vv["notkey"].([]string)
  99. if !ok {
  100. inter_vv, _ := vv["notkey"].([]interface{})
  101. notkey = common.ObjArrToStringArr(inter_vv)
  102. }
  103. pbKey[kk] = &pb.Keys{
  104. Key: key,
  105. Notkey: notkey,
  106. UpdateTime: common.If(vv["updatetime"] == nil, int64(0), common.Int64All(vv["updatetime"])).(int64),
  107. }
  108. }
  109. items[k].AKey = pbKey
  110. }
  111. return items
  112. }