getuserinfologic.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. package logic
  2. import (
  3. "context"
  4. "fmt"
  5. "log"
  6. "app.yhyue.com/moapp/jybase/common"
  7. "bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/internal/svc"
  8. "bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/pb"
  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. items, ok := ret["items"].([]map[string]interface{})
  39. if !ok {
  40. inter_items, _ := ret["items"].([]interface{})
  41. items = common.ObjArrToMapArr(inter_items)
  42. }
  43. log.Println("items:", items)
  44. log.Println("oarea:", ret["o_area"], common.ObjToMap(ret["o_area"]))
  45. buyerclass, _ := ret["buyerclass"].([]interface{})
  46. infotype, _ := ret["infotype"].([]interface{})
  47. resp.Data = &pb.Subscribe{
  48. StartTime: common.Int64All(ret["starttime"]),
  49. EndTime: common.Int64All(ret["endtime"]),
  50. Area: l.formatM(common.ObjToMap(ret["area"])),
  51. Buyerclass: common.ObjArrToStringArr(buyerclass),
  52. Infotype: common.ObjArrToStringArr(infotype),
  53. Matchway: common.Int64All(ret["matchway"]),
  54. Projectmatch: common.Int64All(ret["projectmatch"]),
  55. Items: l.formatItems(items),
  56. }
  57. return resp, nil
  58. }
  59. //格式转化 map<string,list>转化
  60. func (l *GetUserInfoLogic) formatM(m *map[string]interface{}) map[string]*pb.List {
  61. retM := map[string]*pb.List{}
  62. if len(*m) == 0 {
  63. return retM
  64. }
  65. for k, v := range *m {
  66. s_v, ok := v.([]string)
  67. if !ok {
  68. interf, _ := v.([]interface{})
  69. s_v = common.ObjArrToStringArr(interf)
  70. }
  71. retM[k] = &pb.List{
  72. Value: s_v,
  73. }
  74. }
  75. return retM
  76. }
  77. func (l *GetUserInfoLogic) formatItems(m []map[string]interface{}) []*pb.Items {
  78. items := make([]*pb.Items, len(m))
  79. for k, v := range m {
  80. items[k] = &pb.Items{
  81. SItem: common.ObjToString(v["s_item"]),
  82. UpdateTime: common.Int64All(v["updatetime"]),
  83. }
  84. akey, _ := v["a_key"].([]map[string]interface{})
  85. pbKey := make([]*pb.Keys, len(akey))
  86. for kk, vv := range akey {
  87. key, ok := vv["key"].([]string)
  88. if !ok {
  89. inter_vv, _ := vv["key"].([]interface{})
  90. key = common.ObjArrToStringArr(inter_vv)
  91. }
  92. notkey, ok := vv["notkey"].([]string)
  93. if !ok {
  94. inter_vv, _ := vv["notkey"].([]interface{})
  95. notkey = common.ObjArrToStringArr(inter_vv)
  96. }
  97. pbKey[kk] = &pb.Keys{
  98. Key: key,
  99. Notkey: notkey,
  100. UpdateTime: common.If(vv["updatetime"] == nil, int64(0), common.Int64All(vv["updatetime"])).(int64),
  101. }
  102. }
  103. items[k].AKey = pbKey
  104. }
  105. return items
  106. }