WH01243 2 年 前
コミット
f2b0993012

+ 10 - 8
jyBXSubscribe/rpc/internal/logic/getsublistlogic.go

@@ -1,6 +1,7 @@
 package logic
 
 import (
+	"app.yhyue.com/moapp/jybase/common"
 	"context"
 	"github.com/zeromicro/go-zero/core/logx"
 	IC "jyBXSubscribe/rpc/init"
@@ -57,16 +58,17 @@ func (l *GetSubListLogic) GetSubList(in *bxsubscribe.SubscribeInfosReq) (*bxsubs
 		BaseServiceMysql: IC.BaseServiceMysql,
 		IsEnt:            in.IsEnt,
 		BuySubject:       0,
+		UserType:         in.UserType,
 	}
 	//主体处理(fType:普通用户;vType:超级订阅用户;mType:大会员用户;eType:商机管理用户)
-	if in.UserType == "vType" || in.UserType == "mType" {
-		infoCount := IC.MainMysql.CountBySql("select  count(id) from  entniche_wait_empower where  ent_id=? and  end_time>NOW() and (product_type like '%VIP订阅%' or product_type like '%大会员%') ", in.EntId)
-		if infoCount > 0 {
-			in.UserType = "eType"
-			//主体等于企业的
-			spqp.BuySubject = 1
-		}
-
+	infoCount := IC.MainMysql.CountBySql("select  count(id) from  entniche_wait_empower where  ent_id=? and  end_time>NOW() and (product_type like '%VIP订阅%' or product_type like '%大会员%') ", in.EntId)
+	if infoCount > 0 {
+		in.UserType = model.EntnicheFlag
+		//主体等于企业的
+		spqp.BuySubject = 1
+	}
+	if in.UserType == model.EntnicheFlag {
+		spqp.UserId = common.InterfaceToStr(spqp.EntUserId)
 	}
 	hasNextPage, total, list := model.NewSubscribePush(in.UserType).Datas(spqp)
 	start1 := time.Now().Unix()

+ 4 - 3
jyBXSubscribe/rpc/internal/logic/setreadlogic.go

@@ -30,12 +30,13 @@ func (l *SetReadLogic) SetRead(in *bxsubscribe.SetReadReq) (*bxsubscribe.StatusR
 	// todo: add your logic here and delete this line
 	resp := &bxsubscribe.StatusResp{}
 	//主体处理(fType:普通用户;vType:超级订阅用户;mType:大会员用户;eType:商机管理用户)
-	if in.UserType == "vType" || in.UserType == "mType" {
+	userType := in.UserType
+	if in.UserType == model.SubVipFlag || in.UserType == model.MemberFlag {
 		infoCount := IC.MainMysql.CountBySql("select  count(id) from  entniche_wait_empower where  ent_id=? and  end_time>NOW() and (product_type like '%VIP订阅%' or product_type like '%大会员%') ", in.EntId)
 		if infoCount > 0 {
-			in.UserType = "eType"
+			in.UserType = model.EntnicheFlag
 		}
 	}
-	model.NewSubscribePush(in.UserType).SetRead(in.NewUserId, in.Vsid, in.UserId, in.EntUserId, in.EntId, in.IsEnt)
+	model.NewSubscribePush(in.UserType).SetRead(in.NewUserId, in.Vsid, in.UserId, in.EntUserId, in.EntId, in.IsEnt, userType)
 	return resp, nil
 }

+ 63 - 43
jyBXSubscribe/rpc/model/push.go

@@ -40,7 +40,7 @@ const (
 )
 
 var (
-	ennicheInsertCollKey   = []string{"entid", "deptid", "userid", "infoid", "matchkeys", "date", "source"}
+	ennicheInsertCollKey   = []string{"entid", "deptid", "userid", "infoid", "matchkeys", "date", "source", "product"}
 	subscribeInsertCollKey = []string{"userid", "infoid", "matchkeys", "date", "isvip"}
 	memberInsertCollKey    = []string{"userid", "infoid", "matchkeys", "date"}
 )
@@ -102,6 +102,7 @@ type SubPushQueryParam struct {
 	IsEnt            bool
 	SelectInfoIds    []string
 	BuySubject       int64
+	UserType         string
 }
 
 // 关键词参数
@@ -135,8 +136,8 @@ func NewSubscribePush(module ...string) *subscribePush {
 }
 
 // 从pushcache_2_a中取
-func (s *subscribePush) GetTodayCache(userId string) (*SubPush, error) {
-	pc_a, err := redis.GetNewBytes("pushcache_2_b", s.todayKey(userId))
+func (s *subscribePush) GetTodayCache(userId, userType string) (*SubPush, error) {
+	pc_a, err := redis.GetNewBytes("pushcache_2_b", s.todayKey(userId, userType))
 	if err != nil {
 		return nil, err
 	}
@@ -151,15 +152,28 @@ func (s *subscribePush) GetTodayCache(userId string) (*SubPush, error) {
 }
 
 // 往pushcache_2_a中放
-func (s *subscribePush) PutTodayCache(userId string, pc_a *SubPush) {
-	redis.Put("pushcache_2_b", s.todayKey(userId), pc_a, oneDay)
+func (s *subscribePush) PutTodayCache(userId, userType string, pc_a *SubPush) {
+	redis.Put("pushcache_2_b", s.todayKey(userId, userType), pc_a, oneDay)
 }
 
 // 获取redis key
-func (s *subscribePush) todayKey(userId string) string {
-	return fmt.Sprintf("%s_%s", aboutDbMsg[s.ModuleFlag].RedisKeyFlag, userId)
+func (s *subscribePush) todayKey(userId, userType string) string {
+	if userType == EntnicheFlag {
+		return fmt.Sprintf("%s_%s", aboutDbMsg[s.ModuleFlag].RedisKeyFlag, userId)
+	} else {
+		return fmt.Sprintf("%s_%s", aboutDbMsg[s.ModuleFlag].RedisKeyFlag, userId)
+	}
+
 }
-func (s *subscribePush) allKey(userId string) string {
+func (s *subscribePush) allKey(userId, userType string) string {
+	if s.ModuleFlag == EntnicheFlag {
+		switch userType {
+		case SubVipFlag:
+			return fmt.Sprintf("all_%s_%s_%s", aboutDbMsg[s.ModuleFlag].RedisKeyFlag, "vip", userId)
+		case MemberFlag:
+			return fmt.Sprintf("all_%s_%s_%s", aboutDbMsg[s.ModuleFlag].RedisKeyFlag, "member", userId)
+		}
+	}
 	return fmt.Sprintf("all_%s_%s", aboutDbMsg[s.ModuleFlag].RedisKeyFlag, userId)
 }
 
@@ -252,7 +266,7 @@ func (s *subscribePush) Datas(spqp *SubPushQueryParam) (hasNextPage bool, total
 		subPush := &SubPush{}
 		var err error
 		if spqp.IsEnt == false {
-			subPush, err = s.GetTodayCache(spqp.UserId)
+			subPush, err = s.GetTodayCache(spqp.UserId, spqp.UserType)
 		}
 		if err != nil {
 			logx.Info(spqp.UserId, "GetTodayCache Error", err)
@@ -265,7 +279,7 @@ func (s *subscribePush) Datas(spqp *SubPushQueryParam) (hasNextPage bool, total
 				Count: countSearch,
 			}
 			if spqp.IsEnt == false {
-				s.PutTodayCache(spqp.UserId, subPush)
+				s.PutTodayCache(spqp.UserId, spqp.UserType, subPush)
 			}
 		}
 		length := len(subPush.Datas)
@@ -283,7 +297,7 @@ func (s *subscribePush) Datas(spqp *SubPushQueryParam) (hasNextPage bool, total
 		allCache := &SubPush{}
 		var err error
 		if !spqp.IsEnt {
-			allCache, err = s.GetAllCache(spqp.UserId)
+			allCache, err = s.GetAllCache(spqp.UserId, spqp.UserType)
 		}
 		if err != nil {
 			logx.Info(spqp.UserId, "GetAllCache Error", err)
@@ -303,7 +317,7 @@ func (s *subscribePush) Datas(spqp *SubPushQueryParam) (hasNextPage bool, total
 				Count: countSearch,
 			}
 			if spqp.IsEnt == false {
-				s.PutAllCache(spqp.UserId, allCache)
+				s.PutAllCache(spqp.UserId, spqp.UserType, allCache)
 			}
 		}
 		length := len(allCache.Datas)
@@ -351,12 +365,12 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
 	} else {
 		if spqp.IsEnt {
 			if spqp.BuySubject == 1 {
-				userStr = fmt.Sprintf("   a.entid='%s' and (a.source =2 or   a.source =3) ", spqp.EntId)
+				userStr = fmt.Sprintf("   a.entid='%s' and (a.source =2 or   a.source =3) and (a.product =1 or   a.product =2) ", spqp.EntId)
 			} else {
-				userStr = fmt.Sprintf("   a.entid='%s' ", spqp.EntId)
+				userStr = fmt.Sprintf("   a.entid='%s'  and a.product !=1 and    a.product !=2 ", spqp.EntId)
 			}
 		} else {
-			userStr = fmt.Sprintf("  a.userid='%s'", common.If(s.ModuleFlag == "eType", spqp.EntUserId, common.InterfaceToStr(spqp.NewUserId)))
+			userStr = fmt.Sprintf("  a.userid='%s'", common.If(s.ModuleFlag == EntnicheFlag, spqp.EntUserId, common.InterfaceToStr(spqp.NewUserId)))
 		}
 
 		//时间
@@ -500,7 +514,7 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
 		log.Println("查询数据总数用时", start2-start)
 		findSql = "SELECT  aa.*,  bb.labelvalues as industry  FROM (select a.id,a.date,a.infoid,a.isvisit,a.matchkeys,a.type,b.isvalidfile as attachment_count,b.site," +
 			"b.title,b.area_code,b.buyerclass_code,b.subtype_code,b.publishtime,b.budget,b.bidamount,b.projectname,b.buyer,b.bidopentime "
-		if s.ModuleFlag == "eType" {
+		if s.ModuleFlag == EntnicheFlag {
 			findSql += ", IF(a.source is NULL,1,a.source) as  source "
 		}
 	}
@@ -716,12 +730,12 @@ func (s *subscribePush) GetJyPushs(datas []map[string]interface{}, codeMap *code
 }
 
 // 查看全部列表缓存
-func (s *subscribePush) PutAllCache(userId string, datas *SubPush) {
-	redis.Put("pushcache_2_a", s.allKey(userId), datas, oneDay)
+func (s *subscribePush) PutAllCache(userId, userType string, datas *SubPush) {
+	redis.Put("pushcache_2_a", s.allKey(userId, userType), datas, oneDay)
 }
 
-func (s *subscribePush) GetAllCache(userId string) (*SubPush, error) {
-	return s.GetCache("pushcache_2_a", s.allKey(userId))
+func (s *subscribePush) GetAllCache(userId, userType string) (*SubPush, error) {
+	return s.GetCache("pushcache_2_a", s.allKey(userId, userType))
 }
 
 func (s *subscribePush) GetCache(code, key string) (*SubPush, error) {
@@ -831,7 +845,7 @@ func UpdateUserPushUnread(userid string, vt string) {
 		IC.Mgo.UpdateById("user", userid, map[string]interface{}{"$set": map[string]interface{}{"i_apppushunread": 0}})
 	}
 }
-func (s *subscribePush) SetRead(newUserId, id int64, userId, entUserId, entId string, isEnt bool) error {
+func (s *subscribePush) SetRead(newUserId, id int64, userId, entUserId, entId string, isEnt bool, userType string) error {
 	if id <= 0 && newUserId == 0 {
 		return nil
 	}
@@ -839,7 +853,7 @@ func (s *subscribePush) SetRead(newUserId, id int64, userId, entUserId, entId st
 		return nil
 	}
 	if isEnt {
-		if s.ModuleFlag == "eType" {
+		if s.ModuleFlag == EntnicheFlag {
 			IC.BaseServiceMysql.UpdateOrDeleteBySql(fmt.Sprintf("update %s set isvisit=1 ,visittime=now() where entid=? and id=?", aboutDbMsg[s.ModuleFlag].MysqlTable), entId, id)
 
 		} else {
@@ -847,7 +861,7 @@ func (s *subscribePush) SetRead(newUserId, id int64, userId, entUserId, entId st
 
 		}
 	} else {
-		if s.ModuleFlag == "eType" {
+		if s.ModuleFlag == EntnicheFlag {
 			//商机管理
 			IC.BaseServiceMysql.UpdateOrDeleteBySql(fmt.Sprintf("update %s set isvisit=1,visittime=now() where userid=? and id=?", aboutDbMsg[s.ModuleFlag].MysqlTable), entUserId, id)
 		} else {
@@ -856,7 +870,7 @@ func (s *subscribePush) SetRead(newUserId, id int64, userId, entUserId, entId st
 		}
 	}
 	if !isEnt {
-		todaySubPush, err := s.GetTodayCache(userId)
+		todaySubPush, err := s.GetTodayCache(userId, userType)
 		//当天数据处理
 		if err == nil && todaySubPush != nil {
 			for _, v := range todaySubPush.Datas {
@@ -865,10 +879,10 @@ func (s *subscribePush) SetRead(newUserId, id int64, userId, entUserId, entId st
 					break
 				}
 			}
-			s.PutTodayCache(userId, todaySubPush)
+			s.PutTodayCache(userId, userType, todaySubPush)
 		}
 		//全部数据处理
-		allSubPush, err := s.GetAllCache(userId)
+		allSubPush, err := s.GetAllCache(userId, userType)
 		if err == nil && allSubPush != nil {
 			for _, v := range allSubPush.Datas {
 				if v.CaIndex == id {
@@ -876,7 +890,7 @@ func (s *subscribePush) SetRead(newUserId, id int64, userId, entUserId, entId st
 					break
 				}
 			}
-			s.PutAllCache(userId, allSubPush)
+			s.PutAllCache(userId, userType, allSubPush)
 		}
 	}
 	return nil
@@ -977,6 +991,12 @@ func (s *subscribePush) listManager(spqp *SubPushQueryParam, list []map[string]i
 	length := len(list)
 	resultList = make([]*bxsubscribe.SubscribeInfo, length)
 	pushInsert := []interface{}{}
+	product := ""
+	if spqp.UserType == SubVipFlag {
+		product = "1"
+	} else if spqp.UserType == MemberFlag {
+		product = "2"
+	}
 	for i := length - 1; i >= 0; i-- {
 		v := list[i]
 		title := strings.Replace(common.ObjToString(v["title"]), " ", "", -1)
@@ -988,13 +1008,13 @@ func (s *subscribePush) listManager(spqp *SubPushQueryParam, list []map[string]i
 		entUserId := spqp.EntUserId
 		deptid := spqp.DeptId
 		switch s.ModuleFlag {
-		case "eType":
-			pushInsert = append(pushInsert, entid, deptid, entUserId, common.InterfaceToStr(infoid), matchkey, now, 1)
-		case "mType":
+		case EntnicheFlag:
+			pushInsert = append(pushInsert, entid, deptid, entUserId, common.InterfaceToStr(infoid), matchkey, now, 1, product)
+		case MemberFlag:
 			pushInsert = append(pushInsert, common.InterfaceToStr(spqp.NewUserId), common.InterfaceToStr(infoid), matchkey, now)
-		case "vType":
+		case SubVipFlag:
 			pushInsert = append(pushInsert, common.InterfaceToStr(spqp.NewUserId), common.InterfaceToStr(infoid), matchkey, now, 1)
-		case "fType":
+		case SubFreeFlag:
 			pushInsert = append(pushInsert, common.InterfaceToStr(spqp.NewUserId), common.InterfaceToStr(infoid), matchkey, now, 0)
 		}
 		redis.Put("pushcache_2_a", redisKey, 1, 86400)
@@ -1007,9 +1027,9 @@ func (s *subscribePush) listManager(spqp *SubPushQueryParam, list []map[string]i
 	}
 	id := int64(0)
 	switch s.ModuleFlag {
-	case "eType":
+	case EntnicheFlag:
 		_, id = spqp.BaseServiceMysql.InsertIgnoreBatch(aboutDbMsg[s.ModuleFlag].MysqlTable, ennicheInsertCollKey, pushInsert)
-	case "mType":
+	case MemberFlag:
 		_, id = spqp.BaseServiceMysql.InsertIgnoreBatch(aboutDbMsg[s.ModuleFlag].MysqlTable, memberInsertCollKey, pushInsert)
 	default:
 		_, id = spqp.BaseServiceMysql.InsertIgnoreBatch(aboutDbMsg[s.ModuleFlag].MysqlTable, subscribeInsertCollKey, pushInsert)
@@ -1190,7 +1210,7 @@ func (s *subscribePush) getUserInfo(spqp *SubPushQueryParam) (vc *ViewCondition)
 		SelectType string
 	}{}
 	switch s.ModuleFlag {
-	case "mType":
+	case MemberFlag:
 		userMap, ok := IC.Mgo.FindById("user", spqp.UserId, `{"o_member_jy":1,"i_member_status":1}`)
 		if !ok || userMap == nil || len(*userMap) == 0 {
 			return &ViewCondition{}
@@ -1204,7 +1224,7 @@ func (s *subscribePush) getUserInfo(spqp *SubPushQueryParam) (vc *ViewCondition)
 			tmpInfo.SubType, _ = o_member_jy["a_infotype"].([]interface{})
 			tmpInfo.Area, _ = o_member_jy["o_area"].(map[string]interface{})
 		}
-	case "vType":
+	case SubVipFlag:
 		userMap, ok := IC.Mgo.FindById("user", spqp.UserId, `{"o_vipjy":1,"i_vip_status":1}`)
 		if !ok || userMap == nil || len(*userMap) == 0 {
 			return &ViewCondition{}
@@ -1217,7 +1237,7 @@ func (s *subscribePush) getUserInfo(spqp *SubPushQueryParam) (vc *ViewCondition)
 			tmpInfo.SubType, _ = o_vipjy["a_infotype"].([]interface{})
 			tmpInfo.Area, _ = o_vipjy["o_area"].(map[string]interface{})
 		}
-	case "eType":
+	case EntnicheFlag:
 		//商机管理
 		entUserId, _ := strconv.Atoi(spqp.EntUserId)
 		entId, _ := strconv.Atoi(spqp.EntId)
@@ -1388,7 +1408,7 @@ func (s *subscribePush) Keys(spqp *KeyParam) (result []*bxsubscribe.KeyItems) {
 		//个人关键词查找
 		//fType:普通用户;vType:超级订阅用户;mType:大会员用户;eType:商机管理用户
 		mData, ok := IC.Mgo.FindById("user", spqp.UserId, `{"o_jy":1,"o_vipjy":1,"o_member_jy":1}`)
-		if s.ModuleFlag == "vType" {
+		if s.ModuleFlag == SubVipFlag {
 			//从user表中取 o_vipjy.a_items
 			if mData == nil || len(*mData) == 0 || !ok {
 				return nil
@@ -1403,7 +1423,7 @@ func (s *subscribePush) Keys(spqp *KeyParam) (result []*bxsubscribe.KeyItems) {
 					}
 				}
 			}
-		} else if s.ModuleFlag == "mType" {
+		} else if s.ModuleFlag == MemberFlag {
 			//从user表中取 o_member_jy.a_items
 			if mData == nil || len(*mData) == 0 || !ok {
 				return nil
@@ -1418,7 +1438,7 @@ func (s *subscribePush) Keys(spqp *KeyParam) (result []*bxsubscribe.KeyItems) {
 					}
 				}
 			}
-		} else if s.ModuleFlag == "eType" {
+		} 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),
@@ -1470,7 +1490,7 @@ func (s *subscribePush) Keys(spqp *KeyParam) (result []*bxsubscribe.KeyItems) {
 
 			//2、entniche_rule表, 企业订阅关键词查询条件:  {i_entid:123,i_deptid:0},取 o_entniche.a_items
 			res_, _ := IC.Mgo.FindOneByField("entniche_rule", map[string]interface{}{
-				"i_deptid": int64(0),
+				"i_deptid": map[string]interface{}{"$exists": 0},
 				"i_entid":  common.Int64All(spqp.EntId),
 			}, `{"o_entniche":1}`)
 			o_entniche := &map[string]interface{}{}
@@ -1505,7 +1525,7 @@ func (s *subscribePush) Keys(spqp *KeyParam) (result []*bxsubscribe.KeyItems) {
 	} else {
 		//企业关键词查找
 		res_, _ := IC.Mgo.FindOneByField("entniche_rule", map[string]interface{}{
-			"i_deptid": int64(0),
+			"i_deptid": map[string]interface{}{"$exists": 0},
 			"i_entid":  common.Int64All(spqp.EntId),
 		}, `{"o_entniche":1}`)
 		o_entniche := &map[string]interface{}{}
@@ -1561,7 +1581,7 @@ func MapToarr(data map[string][]interface{}, userType string) []*bxsubscribe.Key
 			keyArr = append(keyArr, keys)
 		}
 
-		if userType == "ftype" {
+		if userType == SubFreeFlag {
 			k = ""
 		}
 		result = append(result, &bxsubscribe.KeyItems{