|
@@ -107,21 +107,23 @@ type SubPushQueryParam struct {
|
|
|
SelectInfoIds []string
|
|
|
BuySubject int64
|
|
|
UserType string
|
|
|
+ PositionType int64
|
|
|
IsPayUser bool // 是否是付费用户
|
|
|
}
|
|
|
|
|
|
// 关键词参数
|
|
|
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 {
|
|
@@ -177,6 +179,8 @@ func (s *subscribePush) allKey(userId, userType string) string {
|
|
|
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)
|
|
|
+ case SubFreeFlag:
|
|
|
+ return fmt.Sprintf("all_%s_%s_%s", aboutDbMsg[s.ModuleFlag].RedisKeyFlag, "free", userId)
|
|
|
}
|
|
|
}
|
|
|
return fmt.Sprintf("all_%s_%s", aboutDbMsg[s.ModuleFlag].RedisKeyFlag, userId)
|
|
@@ -301,7 +305,7 @@ func (s *subscribePush) Datas(spqp *SubPushQueryParam) (hasNextPage bool, total
|
|
|
start := (spqp.PageNum - 1) * spqp.PageSize
|
|
|
end := start + spqp.PageSize
|
|
|
//时间是今天,没有别的过滤条件--首先读取当前推送缓存数据 其次查询数据库
|
|
|
- if nowFormat == date.FormatDateByInt64(&starttime, date.Date_Short_Layout) && spqp.Area == "" && spqp.City == "" && spqp.Buyerclass == "" && spqp.Subscopeclass == "" && spqp.Subtype == "" && spqp.Key == "" && spqp.Price == "" && spqp.FileExists == "" && len(spqp.Staffs) == 0 && spqp.Source == "" && spqp.IsRead == "" {
|
|
|
+ if nowFormat == date.FormatDateByInt64(&starttime, date.Date_Short_Layout) && spqp.Area == "" && spqp.City == "" && spqp.Buyerclass == "" && spqp.Subscopeclass == "" && spqp.Subtype == "" && spqp.Key == "" && spqp.Price == "" && spqp.FileExists == "" && len(spqp.Staffs) == 0 && spqp.Source == "" && spqp.IsRead == "" && len(spqp.SelectInfoIds) == 0 {
|
|
|
subPush := &SubPush{}
|
|
|
var err error
|
|
|
if spqp.IsEnt == false {
|
|
@@ -408,7 +412,6 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
|
|
|
} else if starttime == 0 && endtime > 0 {
|
|
|
userStr += fmt.Sprintf(" and a.date<=%d", endtime)
|
|
|
}
|
|
|
-
|
|
|
if spqp.Area != "" || spqp.City != "" {
|
|
|
var sqlAreaCity = ""
|
|
|
//城市
|
|
@@ -474,7 +477,6 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
|
|
|
if codeMap.Data.Subtype[v] != "" {
|
|
|
subtype = append(subtype, fmt.Sprint(codeMap.Data.Subtype[v]))
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
if len(subtype) == 1 {
|
|
|
subtype = append(subtype, "9999")
|
|
@@ -482,7 +484,6 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
|
|
|
if len(subtype) > 0 {
|
|
|
querys = append(querys, fmt.Sprintf("b.subtype_code in (%s)", strings.Join(subtype, ",")))
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
//信息行业
|
|
|
if spqp.Subscopeclass != "" {
|
|
@@ -491,7 +492,6 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
|
|
|
if codeMap.Data.Subscopeclass[v] != "" {
|
|
|
find_in_set = append(find_in_set, codeMap.Data.Subscopeclass[v])
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
if len(find_in_set) > 0 {
|
|
|
leftJoinStr = fmt.Sprintf(" STRAIGHT_JOIN %s t on t.infoid = b.infoid and t.labelcode=2 ", BidTags)
|
|
@@ -535,7 +535,6 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
|
|
|
if spqp.IsEnt {
|
|
|
var staffs []string
|
|
|
userStr += fmt.Sprintf(" and a.entid='%s' ", spqp.EntId)
|
|
|
-
|
|
|
//判断是企业管理员还是部门管理员 部门管理员获取所有子部门
|
|
|
userEnt := EntInfo(common.IntAll(spqp.EntId), common.IntAll(spqp.EntUserId))
|
|
|
if !(userEnt.Role_admin_system || userEnt.Role_admin_department) {
|
|
@@ -564,7 +563,6 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
|
|
|
} else if len(spqp.Staffs) > 0 {
|
|
|
staffs = spqp.Staffs
|
|
|
}
|
|
|
-
|
|
|
//老板商机管理需要查询全部来源
|
|
|
isNew := true
|
|
|
//商机管理判断
|
|
@@ -572,7 +570,6 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
|
|
|
if newCount > 0 {
|
|
|
isNew = false
|
|
|
}
|
|
|
-
|
|
|
// 无查询分配人员、是否已读
|
|
|
if spqp.IsRead == "" && len(staffs) == 0 {
|
|
|
//查询数量(需要去重)
|
|
@@ -610,15 +607,16 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
|
|
|
if spqp.Source == "1" || spqp.Source == "2" || spqp.Source == "3" {
|
|
|
userStr += " and a.source=" + spqp.Source
|
|
|
}
|
|
|
-
|
|
|
- if spqp.BuySubject == 1 {
|
|
|
+ if spqp.PositionType == 1 {
|
|
|
//企业主体是企业的个人查询
|
|
|
if spqp.UserType == SubVipFlag {
|
|
|
- userStr += fmt.Sprintf(" and a.userid='%s' and ( a.product=1 or a.source>1 ) ", common.If(s.ModuleFlag == EntnicheFlag, spqp.EntUserId, common.InterfaceToStr(spqp.NewUserId)))
|
|
|
+ userStr += fmt.Sprintf(" and a.userid='%s' and ( a.product=1 or a.product=3 or a.source>1 ) ", common.If(s.ModuleFlag == EntnicheFlag, spqp.EntUserId, common.InterfaceToStr(spqp.NewUserId)))
|
|
|
} else if spqp.UserType == MemberFlag {
|
|
|
- userStr += fmt.Sprintf(" and a.userid='%s' and ( a.product=2 or a.source>1 ) ", common.If(s.ModuleFlag == EntnicheFlag, spqp.EntUserId, common.InterfaceToStr(spqp.NewUserId)))
|
|
|
+ userStr += fmt.Sprintf(" and a.userid='%s' and ( a.product=2 or a.product=3 or a.source>1 ) ", common.If(s.ModuleFlag == EntnicheFlag, spqp.EntUserId, common.InterfaceToStr(spqp.NewUserId)))
|
|
|
+ } else if spqp.UserType == EntnicheFlag {
|
|
|
+ userStr += fmt.Sprintf(" and a.userid='%s' and ( a.product is null or a.product=3 or a.source>1 ) ", common.If(s.ModuleFlag == EntnicheFlag, spqp.EntUserId, common.InterfaceToStr(spqp.NewUserId)))
|
|
|
} else {
|
|
|
- userStr += fmt.Sprintf(" and a.userid='%s' and ( a.product is null or a.source>1 ) ", common.If(s.ModuleFlag == EntnicheFlag, spqp.EntUserId, common.InterfaceToStr(spqp.NewUserId)))
|
|
|
+ userStr += fmt.Sprintf(" and a.userid='%s' ", common.If(s.ModuleFlag == EntnicheFlag, spqp.EntUserId, common.InterfaceToStr(spqp.NewUserId)))
|
|
|
}
|
|
|
} else {
|
|
|
if s.ModuleFlag == EntnicheFlag {
|
|
@@ -629,13 +627,8 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
|
|
|
userStr += fmt.Sprintf(" and a.userid='%s'", common.If(s.ModuleFlag == EntnicheFlag, spqp.EntUserId, common.InterfaceToStr(spqp.NewUserId)))
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
//查询数量
|
|
|
- //if len(querys) > 1 {
|
|
|
countSql = fmt.Sprintf("select count(1) as count from %s a STRAIGHT_JOIN %s b ON a.infoid = b.infoid %s where 1=1 %s and %s", aboutDbMsg[s.ModuleFlag].MysqlTable, Baseinfo, leftJoinStr, userStr, strings.Join(querys, " and "))
|
|
|
- //} else {
|
|
|
- // countSql = fmt.Sprintf("select count(1) as count from %s a where 1=1 %s", aboutDbMsg[s.ModuleFlag].MysqlTable, userStr)
|
|
|
- //}
|
|
|
//列表查询语句
|
|
|
findSql = "select a.id,a.date,a.infoid,a.isvisit,a.matchkeys,a.type,b.isvalidfile as attachment_count"
|
|
|
if s.ModuleFlag == EntnicheFlag {
|
|
@@ -969,16 +962,16 @@ func (s *subscribePush) SetRead(newUserId, id int64, userId, entUserId, entId st
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-// 获取用户信息
|
|
|
-func (s *subscribePush) UserInfo(userId string) (*map[string]interface{}, int64) {
|
|
|
- user, ok := IC.Mgo.FindById("user", userId, `{"s_m_openid":1,"a_m_openid":1,"s_phone":1,"a_mergeorder":1,"o_jy":1,"l_firstpushtime":1,"i_vip_status":1,"l_vip_endtime":1,"o_vipjy":1,"i_member_status":1,"o_member_jy":1}`)
|
|
|
+// UserInfo 获取用户信息
|
|
|
+func (s *subscribePush) UserInfo(baseUserId int64) (*map[string]interface{}, int64) {
|
|
|
+ user, ok := IC.Mgo.FindOneByField("user", map[string]interface{}{"base_user_id": baseUserId}, `{"i_ts_guide":1,"s_m_openid":1,"a_m_openid":1,"s_phone":1,"a_mergeorder":1,"o_jy":1,"l_firstpushtime":1,"i_vip_status":1,"l_vip_endtime":1,"o_vipjy":1,"i_member_status":1,"o_member_jy":1}`)
|
|
|
if !ok || user == nil {
|
|
|
return nil, 0
|
|
|
}
|
|
|
return user, common.Int64All((*user)["l_firstpushtime"])
|
|
|
}
|
|
|
|
|
|
-// 是否有订阅词
|
|
|
+// GetKeySet 是否有订阅词
|
|
|
func GetKeySet(t string, u *map[string]interface{}, data []string) (bool, []string) {
|
|
|
var industry_ = []string{}
|
|
|
if u != nil {
|
|
@@ -1477,18 +1470,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),
|
|
|
+ "i_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{})
|
|
@@ -1498,20 +1562,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{})
|
|
@@ -1520,10 +1573,10 @@ 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),
|
|
|
+ "i_type": types,
|
|
|
}, `{"o_entniche":1}`)
|
|
|
o_entniche := &map[string]interface{}{}
|
|
|
if res_ != nil {
|
|
@@ -1539,12 +1592,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 {
|
|
@@ -1555,7 +1604,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 =?
|
|
@@ -1612,43 +1661,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)
|
|
|
|