|
@@ -17,6 +17,7 @@ import (
|
|
|
var GlobMsgMap map[int]map[string]interface{}
|
|
|
|
|
|
func LoadTask() {
|
|
|
+ fmt.Println(len(StatisticalUser(false)))
|
|
|
// 每隔10分钟执行一次
|
|
|
LoadMsgOnTime()
|
|
|
c := cron.New(cron.WithSeconds())
|
|
@@ -46,7 +47,7 @@ func FreeIntelUserPush() {
|
|
|
if data == nil || len(*data) == 0 {
|
|
|
return
|
|
|
}
|
|
|
- users := IntelUser(true)
|
|
|
+ users := StatisticalUser(true)
|
|
|
PushData(users, data)
|
|
|
}
|
|
|
|
|
@@ -55,7 +56,7 @@ func PayIntelUserPush() {
|
|
|
if data == nil || len(*data) == 0 {
|
|
|
return
|
|
|
}
|
|
|
- users := IntelUser(false)
|
|
|
+ users := StatisticalUser(false)
|
|
|
PushData(users, data)
|
|
|
}
|
|
|
|
|
@@ -115,89 +116,126 @@ func PushData(users []string, data *[]map[string]interface{}) {
|
|
|
}
|
|
|
|
|
|
// 用户
|
|
|
-func IntelUser(isFree bool) []string {
|
|
|
- mUser := make(map[string]bool)
|
|
|
+func StatisticalUser(isFree bool) []string {
|
|
|
+ var ids []string
|
|
|
+ mUser := make(map[string]bool) //商机管理用户
|
|
|
data := entity.Mysql.SelectBySql(`SELECT a.phone as phone FROM entniche_user a INNER JOIN entniche_info b on b.status = 1 and a.power = 1 and a.ent_id = b.id and a.phone != ''`)
|
|
|
- if data != nil { //统计商机管理用户
|
|
|
+ if data != nil && len(*data) > 0 { //统计商机管理用户
|
|
|
for _, m := range *data {
|
|
|
- mUser[common.InterfaceToStr(m["phone"])] = true
|
|
|
+ if common.InterfaceToStr(m["phone"]) != "" {
|
|
|
+ mUser[common.InterfaceToStr(m["phone"])] = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.Printf("获取商机管理用户:%d\n", len(mUser))
|
|
|
+ //企业大会员或超级订阅
|
|
|
+ entPayUser, ok := entity.MQFW.Find("ent_user", map[string]interface{}{
|
|
|
+ "$or": []map[string]interface{}{
|
|
|
+ { //个人订阅
|
|
|
+ "i_vip_status": map[string]interface{}{
|
|
|
+ "$gt": 0,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ { //个人大会员
|
|
|
+ "i_member_status": map[string]interface{}{
|
|
|
+ "$gt": 0,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }, nil, "", false, -1, -1)
|
|
|
+ if ok && entPayUser != nil && len(*entPayUser) > 0 {
|
|
|
+ var userIds []string
|
|
|
+ for k, m := range *entPayUser {
|
|
|
+ userIds = append(userIds, common.InterfaceToStr(m["i_userid"]))
|
|
|
+ if len(userIds) == 100 || k == len(*entPayUser)-1 {
|
|
|
+ idSql := fmt.Sprintf(`SELECT phone FROM entniche_user WHERE id in (%s)`, strings.Join(userIds, `,`))
|
|
|
+ phoneArr := entity.Mysql.SelectBySql(idSql)
|
|
|
+ if phoneArr != nil && len(*phoneArr) > 0 {
|
|
|
+ for _, m2 := range *phoneArr {
|
|
|
+ if common.InterfaceToStr(m2["phone"]) != "" {
|
|
|
+ mUser[common.InterfaceToStr(m2["phone"])] = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ userIds = []string{}
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- var uData []string
|
|
|
+ log.Printf("获取商机管理+企业付费用户:%d\n", len(mUser))
|
|
|
switch isFree {
|
|
|
- case false:
|
|
|
- user, ok := entity.MQFW.Find("user", map[string]interface{}{
|
|
|
- "i_appid": 2,
|
|
|
+ case false: //付费用户
|
|
|
+ payMap := make(map[string]bool)
|
|
|
+ payUsers, _ := entity.MQFW.Find("user", map[string]interface{}{
|
|
|
"$or": []map[string]interface{}{
|
|
|
- {
|
|
|
- "i_vip_status": map[string]interface{}{"$gt": 0},
|
|
|
+ { //个人订阅
|
|
|
+ "i_vip_status": map[string]interface{}{
|
|
|
+ "$gt": 0,
|
|
|
+ },
|
|
|
},
|
|
|
- {
|
|
|
- "i_member_status": map[string]interface{}{"$gt": 0},
|
|
|
+ { //个人大会员
|
|
|
+ "i_member_status": map[string]interface{}{
|
|
|
+ "$gt": 0,
|
|
|
+ },
|
|
|
},
|
|
|
},
|
|
|
- }, "", `{"_id":1,"s_phone":1,"s_m_phone":1}`, false, -1, -1)
|
|
|
- if ok && user != nil && len(*user) > 0 {
|
|
|
- for _, m := range *user {
|
|
|
+ }, nil, `{"_id":1,"s_phone":1,"s_m_phone":1}`, false, -1, -1)
|
|
|
+ if payUsers != nil && len(*payUsers) > 0 {
|
|
|
+ for _, m := range *payUsers {
|
|
|
phone := common.If(common.InterfaceToStr(m["s_phone"]) == "", common.InterfaceToStr(m["s_m_phone"]), common.InterfaceToStr(m["s_phone"])).(string)
|
|
|
- uData = append(uData, common.InterfaceToStr(m["_id"]))
|
|
|
- if mUser[phone] { //获取剩余商机管理用户
|
|
|
+ payMap[common.InterfaceToStr(m["_id"])] = true
|
|
|
+ if mUser[phone] { //避免重复获取
|
|
|
delete(mUser, phone)
|
|
|
}
|
|
|
}
|
|
|
- if len(mUser) > 0 { //统计剩余商机管理用户
|
|
|
- var (
|
|
|
- phones []string
|
|
|
- count int
|
|
|
- )
|
|
|
-
|
|
|
- for phone := range mUser {
|
|
|
- count++
|
|
|
- phones = append(phones, phone)
|
|
|
- if len(phones) == 100 || count == len(mUser) {
|
|
|
- user1, ok1 := entity.MQFW.Find("user", map[string]interface{}{
|
|
|
- "i_appid": 2,
|
|
|
- "$or": []map[string]interface{}{
|
|
|
- {
|
|
|
- "s_phone": map[string]interface{}{
|
|
|
- "$in": phones,
|
|
|
- },
|
|
|
- },
|
|
|
- {
|
|
|
- "s_m_phone": map[string]interface{}{
|
|
|
- "$in": phones,
|
|
|
- },
|
|
|
- },
|
|
|
- },
|
|
|
- }, "", `{"_id":1}`, false, -1, -1)
|
|
|
- if ok1 && user1 != nil && len(*user1) > 0 {
|
|
|
- for _, m := range *user1 {
|
|
|
- uData = append(uData, common.InterfaceToStr(m["_id"]))
|
|
|
- }
|
|
|
- }
|
|
|
- phones = []string{}
|
|
|
+ }
|
|
|
+ var (
|
|
|
+ phones []string
|
|
|
+ count int
|
|
|
+ )
|
|
|
+ maxCount := len(mUser)
|
|
|
+ for phone := range mUser { //获取剩余商机管理与企业付费用户
|
|
|
+ count++
|
|
|
+ phones = append(phones, phone)
|
|
|
+ if len(phones) == 100 || count == maxCount {
|
|
|
+ entPayUsers, _ := entity.MQFW.Find("user", map[string]interface{}{
|
|
|
+ "$or": []map[string]interface{}{
|
|
|
+ {"s_phone": map[string]interface{}{ //企业订阅||大会员||商机管理
|
|
|
+ "$in": phones,
|
|
|
+ }},
|
|
|
+ {"s_m_phone": map[string]interface{}{ //企业订阅||大会员||商机管理
|
|
|
+ "$in": phones,
|
|
|
+ }},
|
|
|
+ },
|
|
|
+ }, nil, `{"_id":1}`, false, -1, -1)
|
|
|
+ if entPayUsers != nil && len(*entPayUsers) > 0 {
|
|
|
+ for _, m := range *entPayUsers {
|
|
|
+ payMap[common.InterfaceToStr(m["_id"])] = true
|
|
|
}
|
|
|
}
|
|
|
+ phones = []string{}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ for id := range payMap {
|
|
|
+ ids = append(ids, id)
|
|
|
+ }
|
|
|
case true:
|
|
|
sess := entity.MQFW.GetMgoConn()
|
|
|
defer entity.MQFW.DestoryMongoConn(sess)
|
|
|
iter := sess.DB("qfw").C("user").Find(map[string]interface{}{
|
|
|
"i_appid": 2,
|
|
|
- }).Select(map[string]interface{}{"i_vip_status": 1, "i_member_status": 1, "_id": 1, "s_phone": 1, "s_m_phone": 1}).Iter()
|
|
|
+ }).Select(map[string]interface{}{"_id": 1, "i_vip_status": 1, "i_member_status": 1, "s_phone": 1, "s_m_phone": 1}).Iter()
|
|
|
for m := make(map[string]interface{}); iter.Next(&m); {
|
|
|
if common.IntAll(m["i_vip_status"]) <= 0 && common.IntAll(m["i_member_status"]) <= 0 {
|
|
|
phone := common.If(common.InterfaceToStr(m["s_phone"]) == "", common.InterfaceToStr(m["s_m_phone"]), common.InterfaceToStr(m["s_phone"])).(string)
|
|
|
if !mUser[phone] {
|
|
|
- uData = append(uData, common.InterfaceToStr(m["_id"]))
|
|
|
+ ids = append(ids, common.InterfaceToStr(m["_id"]))
|
|
|
}
|
|
|
}
|
|
|
m = map[string]interface{}{}
|
|
|
}
|
|
|
}
|
|
|
- return uData
|
|
|
+ log.Printf("用户类型:%v,用户数:%d", isFree, len(ids))
|
|
|
+ return ids
|
|
|
}
|
|
|
|
|
|
// 获取推送消息
|