Ver Fonte

新增字段

WH01243 há 2 anos atrás
pai
commit
9cd7c9933f

+ 14 - 13
jyBXSubscribe/api/bxsubscribe.api

@@ -76,18 +76,19 @@ type (
 		UserType  string `path:"userType,optional"`
 	}
 	GetKeyReq {
-		AppId       string `header:"appId"`
-		UserId      string `header:"userId"`
-		EntId       string `header:"entId,optional"`
-		EntUserId   string `header:"entUserId,optional"`
-		DeptId      string `header:"deptId,optional"` //部门id
-		NewUserId   int64  `header:"newUserId"`
-		IsEnt       bool   `form:"isEnt,optional"`
-		UserType    string `path:"userType,optional"`
-		VipPower    int64  `form:"ent_buy_vip ,optional"`
-		MemberPower int64  `form:"ent_buy_member ,optional"`
-		PowerSource int64  `form:"powerSource,optional"`
-		UserPower   int64  `form:"userPower,optional"`
+		AppId        string `header:"appId"`
+		UserId       string `header:"userId"`
+		EntId        string `header:"entId,optional"`
+		EntUserId    string `header:"entUserId,optional"`
+		DeptId       string `header:"deptId,optional"` //部门id
+		NewUserId    int64  `header:"newUserId"`
+		IsEnt        bool   `form:"isEnt,optional"`
+		UserType     string `path:"userType,optional"`
+		VipPower     int64  `form:"ent_buy_vip ,optional"`
+		MemberPower  int64  `form:"ent_buy_member ,optional"`
+		PowerSource  int64  `form:"powerSource,optional"`
+		UserPower    int64  `form:"userPower,optional"`
+		PositionType int64  `header:"positionType,optional"`
 	}
 	DistributorReq {
 		AppId     string `header:"appId"`
@@ -132,4 +133,4 @@ service bxsubscribe-api {
 	post /jybx/subscribe/:userType/viewStatus(viewStatusReq) returns (commonResp)
 	@handler msgDistributor
 	post /jybx/subscribe/msgDistributor(msgDistributor) returns (commonResp)
-}
+}

+ 12 - 11
jyBXSubscribe/api/internal/logic/getKeyLogic.go

@@ -27,17 +27,18 @@ func NewGetKeyLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetKeyLogi
 func (l *GetKeyLogic) GetKey(req *types.GetKeyReq) (resp *types.CommonResp, err error) {
 	// todo: add your logic here and delete this line
 	res, err := l.svcCtx.Suscribe.GetKey(l.ctx, &bxsubscribe.GetKeyReq{
-		UserType:    req.UserType,
-		UserId:      req.UserId,
-		EntId:       req.EntId,
-		EntUserId:   req.EntUserId,
-		NewUserId:   req.NewUserId,
-		IsEnt:       req.IsEnt,
-		PowerSource: req.PowerSource,
-		UserPower:   req.UserPower,
-		VipPower:    req.VipPower,
-		MemberPower: req.MemberPower,
-		DeptId:      req.DeptId,
+		UserType:     req.UserType,
+		UserId:       req.UserId,
+		EntId:        req.EntId,
+		EntUserId:    req.EntUserId,
+		NewUserId:    req.NewUserId,
+		IsEnt:        req.IsEnt,
+		PowerSource:  req.PowerSource,
+		UserPower:    req.UserPower,
+		VipPower:     req.VipPower,
+		MemberPower:  req.MemberPower,
+		DeptId:       req.DeptId,
+		PositionType: req.PositionType,
 	})
 	if err != nil {
 		return &types.CommonResp{

+ 13 - 12
jyBXSubscribe/api/internal/types/types.go

@@ -70,18 +70,19 @@ type SetReadReq struct {
 }
 
 type GetKeyReq struct {
-	AppId       string `header:"appId"`
-	UserId      string `header:"userId"`
-	EntId       string `header:"entId,optional"`
-	EntUserId   string `header:"entUserId,optional"`
-	DeptId      string `header:"deptId,optional"` //部门id
-	NewUserId   int64  `header:"newUserId"`
-	IsEnt       bool   `form:"isEnt,optional"`
-	UserType    string `path:"userType,optional"`
-	VipPower    int64  `form:"ent_buy_vip ,optional"`
-	MemberPower int64  `form:"ent_buy_member ,optional"`
-	PowerSource int64  `form:"powerSource,optional"`
-	UserPower   int64  `form:"userPower,optional"`
+	AppId        string `header:"appId"`
+	UserId       string `header:"userId"`
+	EntId        string `header:"entId,optional"`
+	EntUserId    string `header:"entUserId,optional"`
+	DeptId       string `header:"deptId,optional"` //部门id
+	NewUserId    int64  `header:"newUserId"`
+	IsEnt        bool   `form:"isEnt,optional"`
+	UserType     string `path:"userType,optional"`
+	VipPower     int64  `form:"ent_buy_vip ,optional"`
+	MemberPower  int64  `form:"ent_buy_member ,optional"`
+	PowerSource  int64  `form:"powerSource,optional"`
+	UserPower    int64  `form:"userPower,optional"`
+	PositionType int64  `header:"positionType,optional"`
 }
 
 type DistributorReq struct {

+ 1 - 1
jyBXSubscribe/go.mod

@@ -10,7 +10,6 @@ require (
 	github.com/zeromicro/go-zero v1.4.0
 	go.mongodb.org/mongo-driver v1.10.1
 	google.golang.org/grpc v1.48.0
-	google.golang.org/protobuf v1.28.1
 )
 
 require (
@@ -81,6 +80,7 @@ require (
 	golang.org/x/time v0.0.0-20220411224347-583f2d630306 // indirect
 	google.golang.org/appengine v1.6.7 // indirect
 	google.golang.org/genproto v0.0.0-20220602131408-e326c6e8e9c8 // indirect
+	google.golang.org/protobuf v1.28.1 // indirect
 	gopkg.in/inf.v0 v0.9.1 // indirect
 	gopkg.in/yaml.v2 v2.4.0 // indirect
 	gopkg.in/yaml.v3 v3.0.1 // indirect

+ 1 - 0
jyBXSubscribe/rpc/bxsubscribe.proto

@@ -177,6 +177,7 @@ message GetKeyReq{
   int64   powerSource = 11;
   int64   userPower = 12;
   string  deptId = 13;
+  int64   positionType = 14;
 }
 
 message GetDistributorReq{

+ 4 - 2
jyBXSubscribe/rpc/bxsubscribe/bxsubscribe.go

@@ -1,7 +1,7 @@
 // Code generated by goctl. DO NOT EDIT.
 // Source: bxsubscribe.proto
 
-package bxsubscribeclient
+package bxsubscribe
 
 import (
 	"context"
@@ -38,8 +38,8 @@ type (
 	SubscribeInfosResp     = bxsubscribe.SubscribeInfosResp
 	UpdateSubScribeInfoReq = bxsubscribe.UpdateSubScribeInfoReq
 	UserReq                = bxsubscribe.UserReq
-	UserResq               = bxsubscribe.UserResq
 	UserResp               = bxsubscribe.UserResp
+	UserResq               = bxsubscribe.UserResq
 	UserStatus             = bxsubscribe.UserStatus
 	ViewStatusResp         = bxsubscribe.ViewStatusResp
 
@@ -117,6 +117,8 @@ func (m *defaultBxsubscribe) GetKey(ctx context.Context, in *GetKeyReq, opts ...
 func (m *defaultBxsubscribe) GetSubScribeInfo(ctx context.Context, in *UserReq, opts ...grpc.CallOption) (*UserResq, error) {
 	client := bxsubscribe.NewBxsubscribeClient(m.cli.Conn())
 	return client.GetSubScribeInfo(ctx, in, opts...)
+}
+
 // 信息分发
 func (m *defaultBxsubscribe) MsgDistributor(ctx context.Context, in *MsgDistributorReq, opts ...grpc.CallOption) (*StatusResp, error) {
 	client := bxsubscribe.NewBxsubscribeClient(m.cli.Conn())

+ 11 - 10
jyBXSubscribe/rpc/internal/logic/getkeylogic.go

@@ -27,16 +27,17 @@ func NewGetKeyLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetKeyLogi
 func (l *GetKeyLogic) GetKey(in *bxsubscribe.GetKeyReq) (*bxsubscribe.KeyResp, error) {
 	// todo: add your logic here and delete this line
 	spqp := &model.KeyParam{
-		UserId:      in.UserId,    //用户id
-		EntId:       in.EntId,     //商机管理企业id
-		EntUserId:   in.EntUserId, //商机管理用户id
-		NewUserId:   in.NewUserId,
-		IsEnt:       in.IsEnt,
-		VipPower:    in.VipPower,
-		MemberPower: in.MemberPower,
-		PowerSource: in.PowerSource,
-		UserPower:   in.UserPower,
-		DeptId:      in.DeptId,
+		UserId:       in.UserId,    //用户id
+		EntId:        in.EntId,     //商机管理企业id
+		EntUserId:    in.EntUserId, //商机管理用户id
+		NewUserId:    in.NewUserId,
+		IsEnt:        in.IsEnt,
+		VipPower:     in.VipPower,
+		MemberPower:  in.MemberPower,
+		PowerSource:  in.PowerSource,
+		UserPower:    in.UserPower,
+		DeptId:       in.DeptId,
+		PositionType: in.PositionType,
 	}
 	data := model.NewSubscribePush(in.UserType).Keys(spqp)
 	return &bxsubscribe.KeyResp{

+ 1 - 1
jyBXSubscribe/rpc/internal/logic/getsubsomeinfologic_test.go

@@ -3,8 +3,8 @@ package logic
 import (
 	"context"
 	"github.com/zeromicro/go-zero/core/logx"
-	"jyBXSubscribe/rpc/bxsubscribe"
 	"jyBXSubscribe/rpc/internal/svc"
+	"jyBXSubscribe/rpc/type/bxsubscribe"
 	"reflect"
 	"testing"
 )

+ 6 - 38
jyBXSubscribe/rpc/model/distributor.go

@@ -87,54 +87,22 @@ func Distributor(region []string, entId, entUserId int) []*User {
 					}
 				}
 			}
-			if isEnt && v.Power == 1 { // 企业未分配规则 商机管理用户查询个人
-				data, ok := IC.Mgo.FindOne("entniche_rule", map[string]interface{}{
+			if (isEnt && v.Power == 1) || n1 != 0 || n2 != 0 { // 企业未分配规则 商机管理用户查询个人
+				data, _ := IC.Mgo.Find("entniche_rule", map[string]interface{}{
 					"i_userid": v.Id,
 					"i_entid":  entId,
-				})
-				if ok && data != nil && len(*data) > 0 {
-					o_entniche, _ := (*data)["o_entniche"].(map[string]interface{})
-					o_area, _ := o_entniche["o_area"].(map[string]interface{})
+				}, "", nil, false, -1, 1)
+				for _, value := range *data {
+					o_entniche := common.ObjToMap(value["o_entniche"])
+					o_area, _ := (*o_entniche)["o_area"].(map[string]interface{})
 					if regionCheck(o_area, regions) {
 						ss = append(ss, v)
 						continue //商机管理
 					}
 				}
 			}
-
-			// 企业未分配规则 非商机管理用户  判断是否分配大会员或超级订阅
-			//user表 判断区域是否符合
-			if (n1 != 0 || n2 != 0) && v.Phone != "" {
-				//查询user表订阅区域
-				data, ok := IC.Mgo.FindOne("user", map[string]interface{}{
-					"$or": []map[string]interface{}{{"s_phone": v.Phone}, {"s_m_phone": v.Phone}},
-				})
-				if ok && data != nil && len(*data) > 0 {
-					o_area := make(map[string]interface{})
-					i_member_status := common.IntAll((*data)["i_member_status"])
-					i_vip_status := common.IntAll((*data)["i_vip_status"])
-					o_member_jy, _ := (*data)["o_member_jy"].(map[string]interface{})
-					o_vipjy, _ := (*data)["o_vipjy"].(map[string]interface{})
-					if n2 != 0 && i_member_status > 0 { //有大会员权益 校验区域
-						o_area, _ = o_member_jy["o_area"].(map[string]interface{})
-						if regionCheck(o_area, regions) {
-							ss = append(ss, v)
-							continue
-						}
-					}
-					if n1 != 0 && i_vip_status > 0 { //有超级订阅权益 校验区域
-						o_area, _ = o_vipjy["o_area"].(map[string]interface{})
-						if regionCheck(o_area, regions) {
-							ss = append(ss, v)
-							continue
-						}
-					}
-				}
-			}
 		}
-
 	}
-
 	return ss
 }
 

+ 94 - 73
jyBXSubscribe/rpc/model/push.go

@@ -111,16 +111,17 @@ type SubPushQueryParam struct {
 
 // 关键词参数
 type KeyParam struct {
-	UserId      string //用户id
-	EntUserId   string //商机管理用户id
-	DeptId      string //商机管理用户部门id
-	NewUserId   int64
-	IsEnt       bool
-	VipPower    int64
-	EntId       string //企业id
-	MemberPower int64
-	PowerSource int64
-	UserPower   int64
+	UserId       string //用户id
+	EntUserId    string //商机管理用户id
+	DeptId       string //商机管理用户部门id
+	NewUserId    int64
+	IsEnt        bool
+	VipPower     int64
+	EntId        string //企业id
+	MemberPower  int64
+	PowerSource  int64
+	UserPower    int64
+	PositionType int64
 }
 
 func (spqp *SubPushQueryParam) IsEmpty() bool {
@@ -1442,18 +1443,89 @@ func (s *subscribePush) IsInTsGuide(userid string) bool {
 }
 func (s *subscribePush) Keys(spqp *KeyParam) (result []*bxsubscribe.KeyItems) {
 	keyData := map[string][]interface{}{}
-	if !spqp.IsEnt {
+	if spqp.IsEnt {
+		//企业关键词查找
+		res_, _ := IC.Mgo.Find("entniche_rule", map[string]interface{}{
+			"i_userid": map[string]interface{}{
+				"$exists": false,
+			},
+			"i_entid": common.Int64All(spqp.EntId),
+		}, "", `{"o_entniche":1}`, false, -1, -1)
+		o_entniche := map[string]interface{}{}
+		if res_ == nil || len(*res_) == 0 {
+			return MapToarr(keyData)
+		}
+		for _, ruleV := range *res_ {
+			o_entniche = common.StructToMapMore(ruleV["o_entniche"])
+			if o_entniche["a_items"] != nil {
+				a_item := common.ObjArrToMapArr(o_entniche["a_items"].([]interface{}))
+				for _, v := range a_item {
+					if v["a_key"] != nil {
+						a_key_arr := v["a_key"].([]interface{})
+						s_item := common.InterfaceToStr(v["s_item"])
+						if keyData[s_item] != nil {
+							//第一次搜索存在
+							//去重
+							keyData[s_item] = MergeArray(a_key_arr, keyData[s_item])
+						} else {
+							//第一次搜索不存在
+							keyData[s_item] = a_key_arr
+						}
+					}
+				}
+			}
+		}
+
+	} else {
 		//个人关键词查找
 		//fType:普通用户;vType:超级订阅用户;mType:大会员用户;eType:商机管理用户
-		mData, ok := IC.Mgo.FindById("user", spqp.UserId, `{"o_jy":1,"o_vipjy":1,"o_member_jy":1,""i_member_sub_status":1,"s_member_mainid":1}`)
-		if s.ModuleFlag == SubVipFlag {
-			//从user表中取 o_vipjy.a_items
+		types := 2
+		typeKey := ""
+		switch s.ModuleFlag {
+		case SubVipFlag:
+			types = 1
+			typeKey = "o_vipjy"
+		case MemberFlag:
+			types = 1
+			typeKey = "o_member_jy"
+		case EntnicheFlag:
+			types = 0
+			typeKey = "o_entniche"
+		}
+		if spqp.PositionType == 1 {
+			typeKey = "o_entniche"
+		}
+		o_entniche := &map[string]interface{}{}
+		if spqp.PositionType == 0 {
+			mData, ok := IC.Mgo.FindById("user", spqp.UserId, `{"o_jy":1,"o_vipjy":1,"o_member_jy":1,""i_member_sub_status":1,"s_member_mainid":1}`)
 			if mData == nil || len(*mData) == 0 || !ok {
 				return nil
 			}
-			o_vipjy := common.ObjToMap((*mData)["o_vipjy"])
-			if (*o_vipjy)["a_items"] != nil {
-				a_items := common.ObjArrToMapArr((*o_vipjy)["a_items"].([]interface{}))
+			if s.ModuleFlag == MemberFlag {
+				sub_status := common.Int64All((*mData)["i_member_sub_status"])
+				if sub_status == 1 {
+					//大会员子账号处理
+					mData, ok = IC.Mgo.FindById("user", common.InterfaceToStr((*mData)["s_member_mainid"]), `{"o_jy":1,"o_vipjy":1,"o_member_jy":1,""i_member_sub_status":1,"s_member_mainid":1}`)
+					if mData == nil || len(*mData) == 0 || !ok {
+						return nil
+					}
+				}
+			}
+			o_entniche = common.ObjToMap((*mData)[typeKey])
+		} else {
+			res_, _ := IC.Mgo.FindOneByField("entniche_rule", map[string]interface{}{
+				"i_userid": common.Int64All(spqp.EntUserId),
+				"i_entid":  common.Int64All(spqp.EntId),
+				"type":     types,
+			}, `{"o_entniche":1}`)
+			if res_ != nil {
+				o_entniche = common.ObjToMap((*res_)["o_entniche"])
+			}
+		}
+		if s.ModuleFlag == SubVipFlag {
+			//从user表中取 o_vipjy.a_items
+			if (*o_entniche)["a_items"] != nil {
+				a_items := common.ObjArrToMapArr((*o_entniche)["a_items"].([]interface{}))
 				for _, v := range a_items {
 					if v["a_key"] != nil {
 						a_key_arr := v["a_key"].([]interface{})
@@ -1463,20 +1535,9 @@ func (s *subscribePush) Keys(spqp *KeyParam) (result []*bxsubscribe.KeyItems) {
 			}
 		} else if s.ModuleFlag == MemberFlag {
 			//从user表中取 o_member_jy.a_items
-			if mData == nil || len(*mData) == 0 || !ok {
-				return nil
-			}
-			sub_status := common.Int64All((*mData)["i_member_sub_status"])
-			if sub_status == 1 {
-				//大会员子账号处理
-				mData, ok = IC.Mgo.FindById("user", common.InterfaceToStr((*mData)["s_member_mainid"]), `{"o_jy":1,"o_vipjy":1,"o_member_jy":1,""i_member_sub_status":1,"s_member_mainid":1}`)
-				if mData == nil || len(*mData) == 0 || !ok {
-					return nil
-				}
-			}
-			o_memeberjy := common.ObjToMap((*mData)["o_member_jy"])
-			if (*o_memeberjy)["a_items"] != nil {
-				a_items := common.ObjArrToMapArr((*o_memeberjy)["a_items"].([]interface{}))
+			//o_memeberjy := common.ObjToMap((*mData)["o_member_jy"])
+			if (*o_entniche)["a_items"] != nil {
+				a_items := common.ObjArrToMapArr((*o_entniche)["a_items"].([]interface{}))
 				for _, v := range a_items {
 					if v["a_key"] != nil {
 						a_key_arr := v["a_key"].([]interface{})
@@ -1485,7 +1546,6 @@ func (s *subscribePush) Keys(spqp *KeyParam) (result []*bxsubscribe.KeyItems) {
 				}
 			}
 		} else if s.ModuleFlag == EntnicheFlag {
-			//entniche_rule表,查询条件:{i_entid:123,i_userid:456},取 o_entniche.a_items
 			res_, _ := IC.Mgo.FindOneByField("entniche_rule", map[string]interface{}{
 				"i_userid": common.Int64All(spqp.EntUserId),
 				"i_entid":  common.Int64All(spqp.EntId),
@@ -1504,12 +1564,8 @@ func (s *subscribePush) Keys(spqp *KeyParam) (result []*bxsubscribe.KeyItems) {
 				}
 			}
 		} else {
-			if mData == nil || len(*mData) == 0 || !ok {
-				return nil
-			}
-			o_jy, _ := (*mData)["o_jy"].(map[string]interface{})
 			//免费用户
-			a_key, _ := o_jy["a_key"].([]interface{})
+			a_key, _ := (*o_entniche)["a_key"].([]interface{})
 			if len(a_key) > 0 {
 				for _, v := range a_key {
 					if keyData["未分类"] != nil {
@@ -1520,7 +1576,7 @@ func (s *subscribePush) Keys(spqp *KeyParam) (result []*bxsubscribe.KeyItems) {
 				}
 			}
 		}
-		if (spqp.VipPower == 1 || spqp.MemberPower == 1) || (spqp.UserPower == 1 && spqp.PowerSource == 0) {
+		if spqp.PositionType == 1 && s.ModuleFlag != SubFreeFlag {
 			//1、mysql entniche_user_rule表中获取自己的分发规则id
 			data := IC.MainMysql.SelectBySql(`SELECT rule_id FROM entniche_user_rule a 
                                                                         INNER JOIN entniche_department b ON  a.dept_id = b.id AND a.user_id =?
@@ -1577,43 +1633,8 @@ func (s *subscribePush) Keys(spqp *KeyParam) (result []*bxsubscribe.KeyItems) {
 						keyData[v] = entnicheRule[v]
 					}
 				}
-
-			}
-		}
-	} else {
-		//企业关键词查找
-		res_, _ := IC.Mgo.Find("entniche_rule", map[string]interface{}{
-			"i_userid": map[string]interface{}{
-				"$exists": false,
-			},
-			"i_entid": common.Int64All(spqp.EntId),
-		}, "", `{"o_entniche":1}`, false, -1, -1)
-		o_entniche := map[string]interface{}{}
-		if res_ == nil || len(*res_) == 0 {
-
-			return MapToarr(keyData)
-		}
-		for _, ruleV := range *res_ {
-			o_entniche = common.StructToMapMore(ruleV["o_entniche"])
-			if o_entniche["a_items"] != nil {
-				a_item := common.ObjArrToMapArr(o_entniche["a_items"].([]interface{}))
-				for _, v := range a_item {
-					if v["a_key"] != nil {
-						a_key_arr := v["a_key"].([]interface{})
-						s_item := common.InterfaceToStr(v["s_item"])
-						if keyData[s_item] != nil {
-							//第一次搜索存在
-							//去重
-							keyData[s_item] = MergeArray(a_key_arr, keyData[s_item])
-						} else {
-							//第一次搜索不存在
-							keyData[s_item] = a_key_arr
-						}
-					}
-				}
 			}
 		}
-
 	}
 	return MapToarr(keyData)
 

+ 0 - 1
jyBXSubscribe/rpc/model/service/subscribe.go

@@ -44,7 +44,6 @@ func (this *SubseribeService) Update() (int64, error) {
 	}
 	//查询字段
 	fields := `{"i_vip_status":1,"o_vipjy":1}`
-
 	//查询用户信息
 	r, ok := this.Mgo.FindOneByField(entity.User, query, fields)
 	if !ok || r == nil || len(*r) == 0 {