getuserinfologic.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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.Phone = common.ObjToString(ret["phone"])
  34. resp.VipStatus = common.Int64All(ret["vipStatus"])
  35. resp.MemberStatus = common.Int64All(ret["memberStatus"])
  36. resp.EntnicheStatus = common.Int64All(ret["entnicheStatus"])
  37. resp.SubscribeType = common.ObjToString(ret["subscribeType"])
  38. resp.Nickname = common.ObjToString(ret["nickname"])
  39. resp.Headimg = common.ObjToString(ret["headimg"])
  40. items, ok := ret["items"].([]map[string]interface{})
  41. if !ok {
  42. inter_items, _ := ret["items"].([]interface{})
  43. items = common.ObjArrToMapArr(inter_items)
  44. }
  45. log.Println("items:", items)
  46. log.Println("oarea:", ret["o_area"], common.ObjToMap(ret["o_area"]))
  47. buyerclass, _ := ret["buyerclass"].([]interface{})
  48. infotype, _ := ret["infotype"].([]interface{})
  49. resp.Data = &pb.Subscribe{
  50. StartTime: common.Int64All(ret["starttime"]),
  51. EndTime: common.Int64All(ret["endtime"]),
  52. Area: l.formatM(common.ObjToMap(ret["area"])),
  53. Buyerclass: common.ObjArrToStringArr(buyerclass),
  54. Infotype: common.ObjArrToStringArr(infotype),
  55. Matchway: common.Int64All(ret["matchway"]),
  56. Projectmatch: common.Int64All(ret["projectmatch"]),
  57. Items: l.formatItems(items),
  58. }
  59. return resp, nil
  60. }
  61. //格式转化 map<string,list>转化
  62. func (l *GetUserInfoLogic) formatM(m *map[string]interface{}) map[string]*pb.List {
  63. retM := map[string]*pb.List{}
  64. if len(*m) == 0 {
  65. return retM
  66. }
  67. for k, v := range *m {
  68. s_v, ok := v.([]string)
  69. if !ok {
  70. interf, _ := v.([]interface{})
  71. s_v = common.ObjArrToStringArr(interf)
  72. }
  73. retM[k] = &pb.List{
  74. Value: s_v,
  75. }
  76. }
  77. return retM
  78. }
  79. func (l *GetUserInfoLogic) formatItems(m []map[string]interface{}) []*pb.Items {
  80. items := make([]*pb.Items, len(m))
  81. for k, v := range m {
  82. items[k] = &pb.Items{
  83. SItem: common.ObjToString(v["s_item"]),
  84. UpdateTime: common.Int64All(v["updatetime"]),
  85. }
  86. akey, _ := v["a_key"].([]map[string]interface{})
  87. pbKey := make([]*pb.Keys, len(akey))
  88. for kk, vv := range akey {
  89. key, ok := vv["key"].([]string)
  90. if !ok {
  91. inter_vv, _ := vv["key"].([]interface{})
  92. key = common.ObjArrToStringArr(inter_vv)
  93. }
  94. notkey, ok := vv["notkey"].([]string)
  95. if !ok {
  96. inter_vv, _ := vv["notkey"].([]interface{})
  97. notkey = common.ObjArrToStringArr(inter_vv)
  98. }
  99. pbKey[kk] = &pb.Keys{
  100. Key: key,
  101. Notkey: notkey,
  102. UpdateTime: common.If(vv["updatetime"] == nil, int64(0), common.Int64All(vv["updatetime"])).(int64),
  103. }
  104. }
  105. items[k].AKey = pbKey
  106. }
  107. return items
  108. }