wangchuanjin 2 жил өмнө
parent
commit
a3e6757731
44 өөрчлөгдсөн 1180 нэмэгдсэн , 908 устгасан
  1. 3 0
      public/src/p/constant.go
  2. 85 43
      public/src/p/public.go
  3. 14 9
      public/src/p/struct.go
  4. 3 10
      public/src/projecter/match.go
  5. 2 1
      pushentniche/src/match/config.json
  6. 26 26
      pushentniche/src/match/config/config.go
  7. 2 2
      pushentniche/src/match/db/db.go
  8. 189 248
      pushentniche/src/match/job/matchjob.go
  9. 12 13
      pushentniche/src/match/job/projectjob.go
  10. 1 1
      pushentniche/src/match/task.json
  11. 71 39
      pushentniche/src/public/entity.go
  12. 127 35
      pushentniche/src/public/util.go
  13. 60 1
      pushentniche/src/push/config.json
  14. 57 24
      pushentniche/src/push/config/config.go
  15. 132 240
      pushentniche/src/push/job/nomsgtipjob.go
  16. 117 46
      pushentniche/src/push/job/pushjob.go
  17. 2 0
      pushentniche/src/push/main.go
  18. 24 14
      pushentniche/src/push/pusher/normalpush.go
  19. 8 4
      pushentniche/src/push/util/entity.go
  20. 17 0
      pushentniche/src/push/util/rpccall.go
  21. 2 0
      pushentniche/src/push/util/util.go
  22. 1 2
      pushmember/src/match/config/config.go
  23. 8 0
      pushmember/src/match/db.json
  24. 16 1
      pushmember/src/match/db/db.go
  25. 13 14
      pushmember/src/match/job/matchjob.go
  26. 1 1
      pushmember/src/match/task.json
  27. 7 0
      pushmember/src/public/util.go
  28. 5 3
      pushmember/src/push/config.json
  29. 2 0
      pushmember/src/push/config/config.go
  30. 7 2
      pushmember/src/push/job/nomsgtipjob.go
  31. 7 2
      pushmember/src/push/job/pushjob.go
  32. 1 0
      pushmember/src/push/util/util.go
  33. 1 2
      pushsubscribe/src/match/config/config.go
  34. 8 0
      pushsubscribe/src/match/db.json
  35. 16 1
      pushsubscribe/src/match/db/db.go
  36. 20 14
      pushsubscribe/src/match/job/matchjob.go
  37. 1 1
      pushsubscribe/src/match/task.json
  38. 0 16
      pushsubscribe/src/public/util.go
  39. 10 3
      pushsubscribe/src/push/config.json
  40. 7 0
      pushsubscribe/src/push/config/config.go
  41. 37 24
      pushsubscribe/src/push/job/nomsgtipjob.go
  42. 42 46
      pushsubscribe/src/push/job/pushjob.go
  43. 0 20
      pushsubscribe/src/push/util/util.go
  44. 16 0
      推送用的redis说明.txt

+ 3 - 0
public/src/p/constant.go

@@ -18,6 +18,7 @@ const (
 	OneDaySecond                          = 86400
 	ThreeDay                              = 259200
 	SevenDay                              = 604800
+	RelationProjectLimit                  = 50
 	Mgo_User                              = "user"
 	Es_Bidding                            = "bidding"
 	Es_Projectset                         = "projectset"
@@ -27,6 +28,8 @@ const (
 	Pushcache_2_c                         = "pushcache_2_c"
 	Es_MaxId                              = `{"query":{"filtered":{"filter":{"bool":{"must":{"range":{"id":{"gt":"%s"}}}}}}},"_source":["_id","comeintime"],"sort":{"id":"desc"},"from":0,"size":1}`
 	Es_ProjectQuery                       = `{"query":{"filtered":{"filter":{"terms":{"list.infoid":[%s]}}}},"_source":["_id","list.infoid","list.publishtime"],"sort":{"id":"desc"},"from":0,"size":%d}`
+	Ent_EmpowerVip                        = "VIP订阅"
+	Ent_EmpowerMember                     = "大会员"
 )
 
 var (

+ 85 - 43
public/src/p/public.go

@@ -6,7 +6,6 @@ import (
 	. "mongodb"
 	"qfw/util"
 	. "qfw/util"
-	"qfw/util/elastic"
 	. "qfw/util/mysql"
 	"qfw/util/redis"
 	"reflect"
@@ -388,38 +387,14 @@ func GetSubSet(isFreeUser bool, userId string, obj map[string]interface{}) *SubS
 }
 
 //加载数据到内存中
-func LoadBidding(mgo *MongodbSim, dbName, coll, lastId, lastTime string, redisCache bool) (*[]map[string]interface{}, string, string) {
+func LoadBidding(mgo *MongodbSim, dbName, coll string, startTime int64, redisCache bool) (*[]map[string]interface{}, int64) {
 	defer util.Catch()
-	//获取本次查询的最大id
-	esQuery := ""
-	if lastId == "" {
-		esQuery = strings.Replace(fmt.Sprintf(Es_MaxId, lastId), `"gt"`, `"gte"`, -1)
-	} else {
-		esQuery = fmt.Sprintf(Es_MaxId, lastId)
-	}
-	resId := elastic.Get(Es_Bidding, Es_Bidding, esQuery)
-	endId := ""
-	var endTime int64
-	if resId != nil && *resId != nil && len(*resId) == 1 {
-		endId = util.ObjToString((*resId)[0]["_id"])
-		endTime = util.Int64All((*resId)[0]["comeintime"])
-	} else {
-		logger.Info("获取本次查询的最大id的时候,未查找到数据!", esQuery)
-		return nil, "", ""
-	}
-	st, _ := time.ParseInLocation(util.Date_Full_Layout, lastTime, time.Local)
-	st_unix := st.Unix()
-	//
-	query := map[string]interface{}{}
-	idQuery := map[string]interface{}{}
-	if lastId != "" {
-		idQuery["$gt"] = StringTOBsonId(lastId)
-	}
-	if endId != "" {
-		idQuery["$lte"] = StringTOBsonId(endId)
-	}
-	if len(idQuery) > 0 {
-		query["_id"] = idQuery
+	endTime := time.Now().Unix()
+	query := map[string]interface{}{
+		"pici": map[string]interface{}{
+			"$gte": startTime,
+			"$lt":  endTime,
+		},
 	}
 	// query = map[string]interface{}{
 	// 	"_id": map[string]interface{}{
@@ -452,7 +427,6 @@ func LoadBidding(mgo *MongodbSim, dbName, coll, lastId, lastTime string, redisCa
 		"jsondata":        1,
 		"budget":          1,
 		"bidamount":       1,
-		"extracttype":     1,
 		"isValidFile":     1,
 		"spidercode":      1,
 		"site":            1,
@@ -460,14 +434,10 @@ func LoadBidding(mgo *MongodbSim, dbName, coll, lastId, lastTime string, redisCa
 	index := 0
 	for temp := make(map[string]interface{}); it.Next(&temp); {
 		_id := BsonIdToSId(temp["_id"])
-		if extracttype := util.IntAll(temp["extracttype"]); extracttype != 1 && extracttype != 9 {
-			logger.Info(_id, "extracttype", extracttype, "不参与匹配")
-			continue
-		} else if publishtime := util.Int64All(temp["publishtime"]); st_unix-publishtime > 7*86400 {
-			logger.Info(_id, "发布时间大于7天,不参与匹配", st_unix, publishtime)
+		if publishtime := util.Int64All(temp["publishtime"]); endTime-publishtime > 7*86400 {
+			logger.Info(_id, "发布时间大于7天,不参与匹配", endTime, publishtime)
 			continue
 		}
-		delete(temp, "extracttype")
 		temp["_id"] = _id
 		title, _ := temp["title"].(string)
 		title = strings.ReplaceAll(title, "\n", "")
@@ -496,10 +466,7 @@ func LoadBidding(mgo *MongodbSim, dbName, coll, lastId, lastTime string, redisCa
 		}
 	}
 	logger.Info(coll, "数据已经加载结束。。。", index)
-	if endTime <= 0 {
-		endTime = time.Now().Unix()
-	}
-	return &res, endId, util.FormatDateByInt64(&endTime, util.Date_Full_Layout)
+	return &res, endTime
 }
 
 //
@@ -647,3 +614,78 @@ func SortListSplit(list *SortList, f func(v interface{})) {
 		i += Mgo_ListSize
 	}
 }
+
+//获取企业授权超级订阅/大会员的用户
+func LoadEntProductUsers(m *Mysql) (map[string]bool, map[int]*Entniche, map[int]*Entniche, []*Entniche) {
+	logger.Info("开始加载企业授权用户。。。")
+	phoneMap := map[string]bool{}
+	userMap := map[int]*Entniche{}
+	entMap := map[int]*Entniche{}
+	all := []*Entniche{}
+	m.SelectByBath(200, func(l *[]map[string]interface{}) bool {
+		for _, v := range *l {
+			phone, _ := v["phone"].(string)
+			if phone == "" {
+				continue
+			}
+			e := &Entniche{
+				EntId:       util.IntAll(v["ent_id"]),
+				EntName:     util.ObjToString(v["ent_name"]),
+				UserId:      util.IntAll(v["ent_user_id"]),
+				ProductType: util.ObjToString(v["product_type"]),
+				PowerSource: util.IntAll(v["power_source"]),
+				Phone:       phone,
+				IsNew:       util.IntAll(v["isNew"]),
+			}
+			if strings.Contains(e.ProductType, Ent_EmpowerMember) {
+				e.MemberStatus = 1
+			} else if strings.Contains(e.ProductType, Ent_EmpowerVip) {
+				e.VipStatus = 1
+			} else {
+				continue
+			}
+			phoneMap[phone] = true
+			userMap[e.UserId] = e
+			all = append(all, e)
+			entMap[e.EntId] = e
+			logger.Info("加载企业授权用户", phone, v["product"])
+		}
+		return true
+	}, `SELECT DISTINCT a.ent_id,a.product_type,c.phone,b.ent_user_id,d.name as ent_name,d.power_source,d.isNew from entniche_wait_empower a 
+		inner join entniche_power b on (a.end_time>? and b.status=1 and a.id=b.wait_empower_id)
+		inner join entniche_user c on (b.ent_user_id=c.id)
+	    inner join entniche_info d on (d.id=a.ent_id)`, NowFormat(Date_Full_Layout))
+	logger.Info("企业授权用户加载结束。。。", len(phoneMap), len(userMap), len(entMap), len(all))
+	return phoneMap, userMap, entMap, all
+}
+
+//加载商机管理用户
+func LoadEntnicheUsers(m *Mysql) map[string]bool {
+	logger.Info("开始加载新版商机管理用户。。。")
+	r := map[string]bool{}
+	m.SelectByBath(200, func(l *[]map[string]interface{}) bool {
+		for _, v := range *l {
+			phone := util.ObjToString(v["phone"])
+			if phone != "" {
+				r[phone] = true
+				logger.Info("加载商机管理用户", phone)
+			}
+		}
+		return true
+	}, `SELECT b.phone from entniche_info a INNER JOIN entniche_user b on (a.status=1 and a.power_source is null and b.power=1 and a.id=b.ent_id)`)
+	logger.Info("商机管理用户加载结束。。。", len(r))
+	return r
+}
+
+//
+func GetWxTplMsg(subSet *SubSet) (string, string) {
+	keyword := strings.Join(subSet.Keys, " ")
+	if len([]rune(keyword)) > 10 {
+		keyword = string([]rune(keyword)[:10]) + "..."
+	}
+	area := strings.Join(subSet.Areas, " ")
+	if len([]rune(area)) > 10 {
+		area = string([]rune(area)[:10]) + "..."
+	}
+	return keyword, area
+}

+ 14 - 9
public/src/p/struct.go

@@ -118,15 +118,20 @@ type UserInfo struct {
 
 //
 type Entniche struct {
-	EntId    int    //企业id
-	EntName  string //企业名称
-	DeptId   int    //部门id
-	DeptName string //部门名称
-	DisId    string //分发id
-	UserId   int
-	Unique   string
-	OnlyPush int
-	IsNew    int
+	EntId   int    //企业id
+	EntName string //企业名称
+	DeptId  int    //部门id
+	//DeptName     string //部门名称
+	DisId        string //分发id
+	UserId       int
+	Unique       string
+	OnlyPush     int
+	IsNew        int
+	PowerSource  int    //权益来源
+	ProductType  string //产品类型
+	Phone        string //手机号
+	VipStatus    int    //超级订阅
+	MemberStatus int    //大会员
 }
 
 //用户基本信息-扩展

+ 3 - 10
public/src/projecter/match.go

@@ -55,18 +55,11 @@ func (m *Match) Execute(projectMatcher ProjectMatcher, projectUser *map[*UserInf
 			}()
 			newIds := []string{}
 			unique := projectMatcher.Unique(u)
-			needLength := int64(50 - len((*myMatchId)[unique]))
+			needLength := int64(RelationProjectLimit - len((*myMatchId)[unique]))
 			searchWaitGroup := &sync.WaitGroup{}
 			for _, _id := range *_ids {
-				//如果有信息类型,优先用订阅匹配上的信息,然后最多关联50条
-				if len(u.SubSet.Subtypes) > 0 {
-					if (*myMatchId)[unique] == nil || !(*myMatchId)[unique][_id] {
-						if surplus := atomic.AddInt64(&needLength, -1); surplus <= 0 {
-							continue
-						}
-					}
-				} else { //如果没有信息类型,只关联订阅匹配上的信息
-					if (*myMatchId)[unique] == nil || !(*myMatchId)[unique][_id] {
+				if (*myMatchId)[unique] == nil || !(*myMatchId)[unique][_id] {
+					if surplus := atomic.AddInt64(&needLength, -1); surplus <= 0 {
 						continue
 					}
 				}

+ 2 - 1
pushentniche/src/match/config.json

@@ -22,5 +22,6 @@
 	"loadProjectPoolSize":5,
 	"projectPagingSize":400,
 	"maxLoadProjectCount":50000,
-	"projectPublishTimeLimit":99999999
+	"projectPublishTimeLimit":99999999,
+	"loadEntProductUsersPoolSize":10
 }

+ 26 - 26
pushentniche/src/match/config/config.go

@@ -6,35 +6,35 @@ import (
 )
 
 type config struct {
-	TestQuery               map[string]interface{} `json:"testQuery"`
-	MaxMatchSize            int                    `json:"maxMatchSize"`
-	MatchPoolSize           int                    `json:"matchPoolSize"`
-	SavePoolSize            int                    `json:"savePoolSize"`
-	MatchDuration           int64                  `json:"matchDuration"`
-	MergePoolSize           int                    `json:"mergePoolSize"`
-	MoveBatch               int                    `json:"moveBatch"`
-	MoveDuration            int64                  `json:"moveDuration"`
-	MaxPushSize             int                    `json:"maxPushSize"`
-	NotMatchHour            []int                  `json:"notMatchHour"`
-	MaxCustomer             int64                  `json:"maxCustomer"`
-	ProjectBatch            int                    `json:"projectBatch"`
-	RelationProjectPoolSize int                    `json:"relationProjectPoolSize"`
-	ProjectRetainDay        int                    `json:"projectRetainDay"`
-	ProjectPushBatch        int                    `json:"projectPushBatch"`
-	ProjectSavePoolSize     int                    `json:"projectSavePoolSize"`
-	ProjectSaveSleep        int                    `json:"projectSaveSleep"`
-	ProjectPushTime         string                 `json:"projectPushTime"`
-	MaxRelationProject      int                    `json:"maxRelationProject"`
-	ProjectPushPoolSize     int                    `json:"projectPushPoolSize"`
-	LoadProjectPoolSize     int                    `json:"loadProjectPoolSize"`
-	ProjectPagingSize       int                    `json:"projectPagingSize"`
-	MaxLoadProjectCount     int                    `json:"maxLoadProjectCount"`
-	ProjectPublishTimeLimit int64                  `json:"projectPublishTimeLimit"`
+	TestQuery                   map[string]interface{} `json:"testQuery"`
+	MaxMatchSize                int                    `json:"maxMatchSize"`
+	MatchPoolSize               int                    `json:"matchPoolSize"`
+	SavePoolSize                int                    `json:"savePoolSize"`
+	MatchDuration               int64                  `json:"matchDuration"`
+	MergePoolSize               int                    `json:"mergePoolSize"`
+	MoveBatch                   int                    `json:"moveBatch"`
+	MoveDuration                int64                  `json:"moveDuration"`
+	MaxPushSize                 int                    `json:"maxPushSize"`
+	NotMatchHour                []int                  `json:"notMatchHour"`
+	MaxCustomer                 int64                  `json:"maxCustomer"`
+	ProjectBatch                int                    `json:"projectBatch"`
+	RelationProjectPoolSize     int                    `json:"relationProjectPoolSize"`
+	ProjectRetainDay            int                    `json:"projectRetainDay"`
+	ProjectPushBatch            int                    `json:"projectPushBatch"`
+	ProjectSavePoolSize         int                    `json:"projectSavePoolSize"`
+	ProjectSaveSleep            int                    `json:"projectSaveSleep"`
+	ProjectPushTime             string                 `json:"projectPushTime"`
+	MaxRelationProject          int                    `json:"maxRelationProject"`
+	ProjectPushPoolSize         int                    `json:"projectPushPoolSize"`
+	LoadProjectPoolSize         int                    `json:"loadProjectPoolSize"`
+	ProjectPagingSize           int                    `json:"projectPagingSize"`
+	MaxLoadProjectCount         int                    `json:"maxLoadProjectCount"`
+	ProjectPublishTimeLimit     int64                  `json:"projectPublishTimeLimit"`
+	LoadEntProductUsersPoolSize int                    `json:"loadEntProductUsersPoolSize"`
 }
 
 type taskConfig struct {
-	LastTime string `json:"lastTime"`
-	LastId   string `json:"lastId"`
+	Pici int64 `json:"pici"`
 }
 
 type projectTask struct {

+ 2 - 2
pushentniche/src/match/db/db.go

@@ -89,7 +89,7 @@ func init() {
 			Mgo_Log.InitPool()
 		}
 		if DbConf.Mysql.Main != nil {
-			log.Println("初始化 mysql")
+			log.Println("初始化 mysql main")
 			Mysql = &mysql.Mysql{
 				Address:      DbConf.Mysql.Main.Address,
 				UserName:     DbConf.Mysql.Main.UserName,
@@ -102,7 +102,7 @@ func init() {
 		}
 		//
 		if DbConf.Mysql.Push != nil {
-			log.Println("初始化 pushMysql")
+			log.Println("初始化 mysql push")
 			PushMysql = &mysql.Mysql{
 				Address:      DbConf.Mysql.Push.Address,
 				UserName:     DbConf.Mysql.Push.UserName,

+ 189 - 248
pushentniche/src/match/job/matchjob.go

@@ -40,142 +40,125 @@ type MatchJob struct {
 //定时任务,匹配数据,存库
 func (m *MatchJob) Execute() {
 	defer util.Catch()
-	logger.Info("开始匹配数据任务。。。", TaskConfig.LastId, TaskConfig.LastTime)
-	datas, endId, endTime := LoadBidding(Mgo_Bidding, DbConf.Mongodb.Bidding.DbName, DbConf.Mongodb.Bidding.Collection, TaskConfig.LastId, TaskConfig.LastTime, true)
+	logger.Info("开始匹配数据任务。。。", TaskConfig.Pici)
+	datas, endTime := LoadBidding(Mgo_Bidding, DbConf.Mongodb.Bidding.DbName, DbConf.Mongodb.Bidding.Collection, TaskConfig.Pici, true)
 	if datas == nil || len(*datas) == 0 {
 		return
 	}
 	m.Start(datas)
 	m.relationproject.AllProject = &sync.Map{}
-	TaskConfig.LastTime = endTime
-	TaskConfig.LastId = endId
-	logger.Info("匹配数据任务结束。。。", TaskConfig.LastId, TaskConfig.LastTime)
+	TaskConfig.Pici = endTime
+	logger.Info("匹配数据任务结束。。。", TaskConfig.Pici)
 }
 
 func (m *MatchJob) Start(datas *[]map[string]interface{}) {
 	defer util.Catch()
 	defer ClearEnt()
-	InitEnt(Mysql, Mgo, DbConf.Mongodb.Main.DbName)
-	subSet := m.LoadSubSet()
-	if subSet != nil && len(subSet.Users) > 0 {
-		m.ToMatch(subSet, datas)
-	}
-}
-
-func (m *MatchJob) LoadSubSet() *PayUser {
-	defer util.Catch()
-	payUser := NewPayUser()
+	_, _, entEpu, epus := LoadEntProductUsers(Mysql)
+	InitEnt(Mysql, Mgo, DbConf.Mongodb.Main.DbName, Config.TestQuery, entEpu)
+	allSubSet := NewPayUser()
 	//标题匹配
 	title_key := make(map[string]*[]*UserInfo)
 	title_notkey := make(map[string]*[]*UserInfo)
+	title_pjob := &KeyDfa{
+		Key_user:    &title_key,
+		Notkey_user: &title_notkey,
+	}
 	//正文匹配
 	detail_key := make(map[string]*[]*UserInfo)
 	detail_notkey := make(map[string]*[]*UserInfo)
+	detail_pjob := &KeyDfa{
+		Key_user:    &detail_key,
+		Notkey_user: &detail_notkey,
+	}
+	m.LoadMySubSet(entEpu, allSubSet, title_pjob, detail_pjob)
+	for k, _ := range LoadEntProductSubSet(Mgo, Config.LoadEntProductUsersPoolSize, epus) {
+		m.InitSubSet(allSubSet, k, title_pjob, detail_pjob)
+	}
 	//
+	title_pjob.CreateDaf()
+	detail_pjob.CreateDaf()
+	allSubSet.Title_KeyDfa = title_pjob
+	allSubSet.Detail_KeyDfa = detail_pjob
+	//
+	m.ToMatch(allSubSet, datas)
+}
+
+//商机管理产品我的订阅设置
+func (m *MatchJob) LoadMySubSet(epu map[int]*Entniche, allSubSet *PayUser, title_pjob, detail_pjob *KeyDfa) {
+	defer util.Catch()
 	sess := Mgo.GetMgoConn()
 	defer Mgo.DestoryMongoConn(sess)
 	query := map[string]interface{}{}
 	if len(Config.TestQuery) > 0 {
-		for k, v := range Config.TestQuery {
-			query[k] = v
-		}
+		query = Config.TestQuery
 	}
-	logger.Info("加载订阅设置", query)
+	logger.Info("商机管理产品我的订阅设置", query)
 	it := sess.DB(DbConf.Mongodb.Main.DbName).C(Entniche_rule).Find(query).Select(map[string]interface{}{
 		"i_entid":    1,
 		"i_deptid":   1,
 		"i_userid":   1,
 		"o_entniche": 1,
 	}).Iter()
-	for _temp := make(map[string]interface{}); it.Next(&_temp); {
-		func(temp map[string]interface{}) {
-			entId := util.IntAll(temp["i_entid"])
-			deptId := util.IntAll(temp["i_deptid"])
-			userId := util.IntAll(temp["i_userid"])
-			if entId == 0 || (deptId == 0 && userId == 0) {
-				return
-			} else if Ents[entId] == nil {
-				logger.Info("没有找到该企业", entId)
-				return
-			}
-			entName := Ents[entId].Name
-			if deptId > 0 && EntDepts[deptId] == nil {
-				logger.Info("没有找到该部门", entName, entId, deptId)
-				return
-			}
-			deptName := ""
-			if EntDepts[deptId] != nil {
-				deptName = EntDepts[deptId].Name
+	for temp := make(map[string]interface{}); it.Next(&temp); {
+		entId := util.IntAll(temp["i_entid"])
+		deptId := util.IntAll(temp["i_deptid"])
+		userId := util.IntAll(temp["i_userid"])
+		if entId == 0 || (deptId != 0 && userId != 0) {
+			continue
+		}
+		var entName string
+		if deptId == 0 && userId == 0 {
+			if epu[entId] == nil {
+				logger.Info("没有购买企业产品,过滤掉", entId)
+				continue
 			}
-			subSet, _ := temp["o_entniche"].(map[string]interface{})
-			if subSet == nil || len(subSet) == 0 {
-				logger.Info("订阅设置为空,过滤掉", entName, entId, deptName, deptId, userId)
-				return
+			entName = epu[entId].EntName
+		} else {
+			if Ents[entId] == nil {
+				logger.Info("没有找到该企业,过滤掉", entId)
+				continue
 			}
-			//
-			if deptId > 0 { //部门订阅
-				if Ents[entId].Model != 1 {
-					logger.Info("不是统一订阅模式,过滤掉", entName, entId, deptName, deptId)
-					return
-				} else if EntDepts[deptId] == nil {
-					logger.Info("没有找到该部门,过滤掉", entName, entId, deptName, deptId)
-					return
-				} else if EntDepts[deptId].Subdis == 0 {
-					logger.Info("该部门的订阅分发没有开启,过滤掉", entName, entId, deptName, deptId)
-					return
-				} else if EntDepts[deptId].Nodiff == 0 && EntDeptDis[deptId] == nil {
-					logger.Info("该部门开启了订阅分发,没有开启全员无差别接收,但是没有分发规则,过滤掉", entName, entId, deptName, deptId)
-					return
-				}
-				//如果我的上级部门打开了订阅分发,并且开启了全员无差别接收,本部门规则无效
-				for _, dept := range EntParentDept[deptId] {
-					if EntDepts[dept.Pid].Subdis == 1 && EntDepts[dept.Pid].Nodiff == 1 {
-						logger.Info("我的上级部门", dept.Pid, "开启了订阅分发和全员无差别,过滤掉", entName, entId, deptName, deptId)
-						return
-					}
+			entName = Ents[entId].Name
+			if deptId != 0 {
+				if EntDepts[deptId] == nil {
+					logger.Info("没有找到该部门,过滤掉", entName, entId, deptId)
+					continue
+				} else if Ents[entId].Model != 1 || Ents[entId].DeptSubscribe != 1 || EntDepts[deptId].Subdis != 1 || EntDepts[deptId].Nodiff != 0 {
+					logger.Info("不符合部门自己订阅,过滤掉", entName, entId, deptId)
+					continue
 				}
-			} else if userId > 0 { //个人订阅
-				if Ents[entId].Model != 2 {
-					logger.Info("不是个人订阅模式,过滤掉", entName, entId, userId)
-					return
-				} else if EntUsers[userId] == nil {
+			} else if userId != 0 {
+				if EntUsers[userId] == nil {
 					logger.Info("没有找到该用户,过滤掉", entName, entId, userId)
-					return
+					continue
 				} else if EntUsers[userId].Power == 0 {
 					logger.Info("该用户没有权限,过滤掉", entName, entId, userId)
-					return
+					continue
 				}
 			}
-			user := &UserInfo{
-				Entniche: &Entniche{
-					EntId:    entId,
-					EntName:  entName,
-					DeptId:   deptId,
-					DeptName: deptName,
-					UserId:   userId,
-					IsNew:    Ents[entId].IsNew,
-				},
-				SubSet: GetSubSet(false, fmt.Sprint(userId), subSet),
-			}
-			user.SubSet.AppPush = util.IntAllDef(subSet["i_apppush"], 1)
-			user.SubSet.MailPush = util.IntAll(subSet["i_mailpush"])
-			user.SubSet.RateMode = util.IntAllDef(subSet["i_ratemode"], 2)
-			user.SubSet.MatchWay = util.IntAllDef(subSet["i_matchway"], 1)
-			logger.Info("加载订阅设置", "entId", entId, "entName", entName, "deptId", deptId, "deptName", deptName, "userId", userId, "appPush", user.SubSet.AppPush, "mailPush", user.SubSet.MailPush, "rateMode", user.SubSet.RateMode, "matchWay", user.SubSet.MatchWay)
-			if m.InitSubSet(payUser, user, &title_key, &title_notkey, &detail_key, &detail_notkey) {
-				payUser.Users[user] = true
-			}
-			if deptId <= 0 {
-				return
-			}
-			//分发规则
-			if EntDepts[deptId].Nodiff == 1 {
-				logger.Info("该部门开启了全员无差别,分发规则无效", entName, entId, deptName, deptId)
-				return
-			} else if EntDeptDis[deptId] == nil {
-				logger.Info("该部门没有分发规则", entName, entId, deptName, deptId)
-				return
-			}
+		}
+		subSet, _ := temp["o_entniche"].(map[string]interface{})
+		if subSet == nil || len(subSet) == 0 {
+			logger.Info("商机管理产品我的订阅设置为空,过滤掉", entName, entId, deptId, userId)
+			continue
+		}
+		user := &UserInfo{
+			Entniche: &Entniche{
+				EntId:   entId,
+				EntName: entName,
+				DeptId:  deptId,
+				UserId:  userId,
+				IsNew:   Ents[entId].IsNew,
+			},
+			SubSet: GetSubSet(false, fmt.Sprint(userId), subSet),
+		}
+		logger.Info("加载商机管理产品我的订阅设置", "entId", entId, "entName", entName, "userId", userId, "wxPush", user.SubSet.WxPush, "appPush", user.SubSet.AppPush, "mailPush", user.SubSet.MailPush, "rateMode", user.SubSet.RateMode, "matchWay", user.SubSet.MatchWay)
+		if userId != 0 { //个人订阅
+			user.Entniche.Phone = EntUsers[user.Entniche.UserId].Phone
+			m.InitSubSet(allSubSet, user, title_pjob, detail_pjob)
+			allSubSet.Users[user] = true
+		} else { //企业/部门订阅
 			itemMap := map[string]interface{}{}
 			items, _ := subSet["a_items"].([]interface{})
 			for _, v := range items {
@@ -189,7 +172,17 @@ func (m *MatchJob) LoadSubSet() *PayUser {
 				}
 				itemMap[item_name] = item
 			}
-			for _, dis := range EntDeptDis[deptId] {
+			var diss []*EntDistribute
+			if deptId == 0 {
+				diss = EntDis[entId]
+			} else {
+				diss = EntDeptDis[deptId]
+			}
+			if diss == nil || len(diss) == 0 {
+				logger.Info("该订阅规则没有分发规则,过滤掉", entId, deptId)
+				continue
+			}
+			for _, dis := range diss {
 				child_items := []interface{}{}
 				for _, item_name := range dis.Items {
 					if itemMap[item_name] == nil {
@@ -212,54 +205,42 @@ func (m *MatchJob) LoadSubSet() *PayUser {
 				}
 				child_user := &UserInfo{
 					Entniche: &Entniche{
-						EntId:    user.Entniche.EntId,
-						EntName:  user.Entniche.EntName,
-						DeptId:   user.Entniche.DeptId,
-						DeptName: user.Entniche.DeptName,
-						DisId:    dis.Id,
-						IsNew:    user.Entniche.IsNew,
+						EntId:       user.Entniche.EntId,
+						EntName:     user.Entniche.EntName,
+						DeptId:      user.Entniche.DeptId,
+						DisId:       dis.Id,
+						IsNew:       user.Entniche.IsNew,
+						PowerSource: user.Entniche.PowerSource,
+						ProductType: user.Entniche.ProductType,
+						Phone:       user.Entniche.Phone,
 					},
 					SubSet: GetSubSet(false, dis.Id, child_subSet),
 				}
+				child_user.SubSet.WxPush = user.SubSet.WxPush
 				child_user.SubSet.AppPush = user.SubSet.AppPush
 				child_user.SubSet.MailPush = user.SubSet.MailPush
 				child_user.SubSet.RateMode = user.SubSet.RateMode
 				child_user.SubSet.MatchWay = user.SubSet.MatchWay
 				child_user.SubSet.MaxPushSize = user.SubSet.MaxPushSize
 				child_user.SubSet.MaxMailSize = user.SubSet.MaxMailSize
-				if m.InitSubSet(payUser, child_user, &title_key, &title_notkey, &detail_key, &detail_notkey) {
-					payUser.Users[child_user] = true
-				}
+				m.InitSubSet(allSubSet, child_user, title_pjob, detail_pjob)
+				allSubSet.Users[child_user] = true
 			}
-		}(_temp)
-		_temp = make(map[string]interface{})
-	}
-	//
-	title_pjob := &KeyDfa{
-		Key_user:    &title_key,
-		Notkey_user: &title_notkey,
-	}
-	title_pjob.CreateDaf()
-	detail_pjob := &KeyDfa{
-		Key_user:    &detail_key,
-		Notkey_user: &detail_notkey,
+		}
+		temp = make(map[string]interface{})
 	}
-	detail_pjob.CreateDaf()
-	payUser.Title_KeyDfa = title_pjob
-	payUser.Detail_KeyDfa = detail_pjob
-	return payUser
 }
-func (m *MatchJob) InitSubSet(payUser *PayUser, user *UserInfo, title_key_user, title_notkey_user, detail_key_user, detail_notkey_user *map[string]*[]*UserInfo) bool {
-	user.AddBuyerclass(&payUser.BuyerclassUsers)
-	user.AddAreaCity(&payUser.AreaUsers, &payUser.CityUsers)
-	user.AddSbuype(&payUser.SubtypeUsers)
-	user.MakeKeyUser(user.SubSet.Keys, title_key_user)
-	user.MakeKeyUser(user.SubSet.Notkeys, title_notkey_user)
+
+func (m *MatchJob) InitSubSet(allSubSet *PayUser, user *UserInfo, title_pjob, detail_pjob *KeyDfa) {
+	user.AddBuyerclass(&allSubSet.BuyerclassUsers)
+	user.AddAreaCity(&allSubSet.AreaUsers, &allSubSet.CityUsers)
+	user.AddSbuype(&allSubSet.SubtypeUsers)
+	user.MakeKeyUser(user.SubSet.Keys, title_pjob.Key_user)
+	user.MakeKeyUser(user.SubSet.Notkeys, title_pjob.Notkey_user)
 	if user.SubSet.MatchWay == 2 {
-		user.MakeKeyUser(user.SubSet.Keys, detail_key_user)
-		user.MakeKeyUser(user.SubSet.Notkeys, detail_notkey_user)
+		user.MakeKeyUser(user.SubSet.Keys, detail_pjob.Key_user)
+		user.MakeKeyUser(user.SubSet.Notkeys, detail_pjob.Notkey_user)
 	}
-	return true
 }
 
 //遍历数据并执行推送操作
@@ -329,14 +310,9 @@ func (m *MatchJob) ToMatch(matcher Matcher, datas *[]map[string]interface{}) {
 	logger.Info("开始保存客户和项目。。。")
 	customerMap := &sync.Map{}
 	for k, v := range *entRuleMap {
-		//分发规则,跳过
-		if k.Entniche.DeptId == 0 || EntDepts[k.Entniche.DeptId] == nil || EntDepts[k.Entniche.DeptId].Subdis == 0 || k.Entniche.DisId != "" {
+		if k.Entniche.IsNew == 1 || k.Entniche.PowerSource == 1 {
 			continue
 		}
-		//没有开全员无差别的话,此规则不进行推送
-		if EntDepts[k.Entniche.DeptId].Nodiff == 0 {
-			delete(*entRuleMap, k)
-		}
 		savePool <- true
 		saveWaitGroup.Add(1)
 		go func(user *UserInfo, infos *SortList) {
@@ -345,9 +321,6 @@ func (m *MatchJob) ToMatch(matcher Matcher, datas *[]map[string]interface{}) {
 				<-savePool
 				saveWaitGroup.Done()
 			}()
-			if user.Entniche.IsNew == 1 {
-				return
-			}
 			isLimit := Mysql.CountBySql(`select count(1) as count from entniche_customer where ent_id=?`, user.Entniche.EntId) > Config.MaxCustomer
 			nowFormat := util.NowFormat(util.Date_Full_Layout)
 			customer_count, update_customer_count := 0, 0
@@ -523,7 +496,7 @@ func (m *MatchJob) ToMatch(matcher Matcher, datas *[]map[string]interface{}) {
 				<-savePool
 				saveWaitGroup.Done()
 			}()
-			logger.Info("entId", user.Entniche.EntId, "entName", user.Entniche.EntName, "deptId", user.Entniche.DeptId, "deptName", user.Entniche.DeptName, "userId", user.Entniche.UserId, user.Id, "本轮匹配上了", len(*infos), "条")
+			logger.Info("entId", user.Entniche.EntId, "entName", user.Entniche.EntName, "deptId", user.Entniche.DeptId, "userId", user.Entniche.UserId, user.Id, "本轮匹配上了", len(*infos), "条")
 			//取最新的
 			sort.Sort(infos)
 			array := &SortList{}
@@ -557,7 +530,7 @@ func (m *MatchJob) ToMatch(matcher Matcher, datas *[]map[string]interface{}) {
 				}
 				if size == maxPushSize {
 					if k2 < len(*infos)-1 {
-						logger.Info("entId", user.Entniche.EntId, "entName", user.Entniche.EntName, "deptId", user.Entniche.DeptId, "deptName", user.Entniche.DeptName, "userId", user.Entniche.UserId, user.Id, "匹配上", len(*infos), "超过限制数", size, "丢弃", len(*infos)-size)
+						logger.Info("entId", user.Entniche.EntId, "entName", user.Entniche.EntName, "deptId", user.Entniche.DeptId, "userId", user.Entniche.UserId, user.Id, "匹配上", len(*infos), "超过限制数", size, "丢弃", len(*infos)-size)
 					}
 					break
 				}
@@ -565,117 +538,86 @@ func (m *MatchJob) ToMatch(matcher Matcher, datas *[]map[string]interface{}) {
 			if size == 0 {
 				return
 			}
+			wxtplmsg_keyword, wxtplmsg_area := GetWxTplMsg(user.SubSet)
 			lock.Lock()
 			defer lock.Unlock()
 			unique := GetUnique(user.Entniche.EntId, user.Entniche.DeptId, user.Entniche.UserId, user.Entniche.DisId)
 			myMatchId[unique] = matchId
 			//
-			var staffIds map[int]bool
-			if user.Entniche.DeptId > 0 {
-				user.Entniche.DeptName = EntDepts[user.Entniche.DeptId].Name
-				staffIds = GetDeptUserIds(&UserInfo{
-					Entniche: &Entniche{
-						EntId:    user.Entniche.EntId,
-						EntName:  user.Entniche.EntName,
-						DeptId:   user.Entniche.DeptId,
-						DeptName: user.Entniche.DeptName,
-						DisId:    user.Entniche.DisId,
-					},
-				})
-				if staffIds == nil {
-					return
-				}
-			} else if user.Entniche.UserId > 0 {
-				staffIds = map[int]bool{user.Entniche.UserId: true}
-			} else {
-				return
-			}
 			saveUnique := GetUnique(user.Entniche.EntId, user.Entniche.DeptId, user.Entniche.UserId, "")
-			for staffId, _ := range staffIds {
-				uis := NewUserInfo(Mgo, &UserInfo{
-					Entniche: &Entniche{
-						EntId:    user.Entniche.EntId,
-						EntName:  user.Entniche.EntName,
-						DeptId:   user.Entniche.DeptId,
-						DeptName: user.Entniche.DeptName,
-						UserId:   staffId,
-						DisId:    user.Entniche.DisId,
-					},
-					SubSet: user.SubSet,
-					Id:     user.Id,
-				})
-				if uis == nil {
-					continue
-				}
-				onlypush := 0
-				jpushidMap, opushidMap, mailMap := map[string]bool{}, map[string]bool{}, map[string]bool{}
-				for _, ui_v := range uis {
-					if ui_v.SubSet.AppPush == 1 && (ui_v.Jpushid != "" && jpushidMap[ui_v.Jpushid]) || (ui_v.Opushid != "" && opushidMap[ui_v.Opushid]) {
-						ui_v.SubSet.AppPush = 0
-						ui_v.Jpushid = ""
-						ui_v.Opushid = ""
-					}
-					if ui_v.SubSet.MailPush == 1 && ui_v.SubSet.Email != "" && mailMap[ui_v.SubSet.Email] {
-						ui_v.SubSet.MailPush = 0
-						ui_v.SubSet.Email = ""
-					}
-					if ui_v.Jpushid != "" {
-						jpushidMap[ui_v.Jpushid] = true
-					}
-					if ui_v.Opushid != "" {
-						opushidMap[ui_v.Opushid] = true
-					}
-					if ui_v.SubSet.Email != "" {
-						mailMap[ui_v.SubSet.Email] = true
-					}
-					if onlypush == 1 {
-						if ui_v.SubSet.AppPush == 1 && ui_v.SubSet.MailPush == 1 {
-							if ui_v.Jpushid == "" && ui_v.Opushid == "" && ui_v.SubSet.Email == "" {
-								continue
-							}
-						} else if ui_v.SubSet.AppPush == 1 {
-							if ui_v.Jpushid == "" && ui_v.Opushid == "" {
-								continue
-							}
-						} else if ui_v.SubSet.MailPush == 1 {
-							if ui_v.SubSet.Email == "" {
-								continue
-							}
-						} else {
-							continue
+			uis := UisSortByRateMode{}
+			if user.Entniche.VipStatus == 1 || user.Entniche.MemberStatus == 1 {
+				uis = append(uis, user)
+			} else {
+				disUsers := []*UserInfo{}
+				if user.Entniche.DisId != "" {
+					if dus := GetDisUser(user.Entniche); dus != nil {
+						for duk, duv := range dus {
+							disUsers = append(disUsers, &UserInfo{
+								Entniche: &Entniche{
+									EntId:   user.Entniche.EntId,
+									EntName: user.Entniche.EntName,
+									DeptId:  user.Entniche.DeptId,
+									UserId:  duk,
+									DisId:   user.Entniche.DisId,
+									Phone:   duv.Phone,
+								},
+								SubSet: user.SubSet,
+								Id:     user.Id,
+							})
 						}
 					}
-					SortListSplit(array, func(list interface{}) {
-						saveBatch = append(saveBatch, map[string]interface{}{
-							"entid":        ui_v.Entniche.EntId,
-							"entname":      ui_v.Entniche.EntName,
-							"deptid":       ui_v.Entniche.DeptId,
-							"userid":       ui_v.Entniche.UserId,
-							"mid":          ui_v.Id,
-							"unique":       saveUnique,
-							"distributeid": ui_v.Entniche.DisId,
-							"jpushid":      ui_v.Jpushid,
-							"opushid":      ui_v.Opushid,
-							"appphonetype": ui_v.AppPhoneType,
-							"ratemode":     ui_v.SubSet.RateMode,
-							"apppush":      ui_v.SubSet.AppPush,
-							"mailpush":     ui_v.SubSet.MailPush,
-							"email":        ui_v.SubSet.Email,
-							"list":         list,
-							"words":        ui_v.SubSet.Keys,
-							"maxpushsize":  ui_v.SubSet.MaxPushSize,
-							"maxmailsize":  ui_v.SubSet.MaxMailSize,
-							"timestamp":    time.Now().Unix(),
-							"onlypush":     onlypush,
-						})
-						if len(saveBatch) == Mgo_BulkSize {
-							Mgo_Log.SaveBulk(Pushspace_temp, saveBatch...)
-							saveBatch = []map[string]interface{}{}
-						}
-					})
-					onlypush = 1
+				} else if user.Entniche.UserId > 0 {
+					disUsers = append(disUsers, user)
+				} else {
+					return
+				}
+				for _, disUser := range disUsers {
+					if newUis := NewUserInfo(Mgo, disUser); newUis != nil {
+						uis = append(uis, newUis...)
+					}
 				}
 			}
+			for _, ui_v := range uis {
+				SortListSplit(array, func(list interface{}) {
+					saveBatch = append(saveBatch, map[string]interface{}{
+						"entid":        ui_v.Entniche.EntId,
+						"entname":      ui_v.Entniche.EntName,
+						"deptid":       ui_v.Entniche.DeptId,
+						"userid":       ui_v.Entniche.UserId,
+						"mid":          ui_v.Id,
+						"unique":       saveUnique,
+						"distributeid": ui_v.Entniche.DisId,
+						"jpushid":      ui_v.Jpushid,
+						"opushid":      ui_v.Opushid,
+						"appphonetype": ui_v.AppPhoneType,
+						"ratemode":     ui_v.SubSet.RateMode,
+						"wxpush":       ui_v.SubSet.WxPush,
+						"apppush":      ui_v.SubSet.AppPush,
+						"mailpush":     ui_v.SubSet.MailPush,
+						"email":        ui_v.SubSet.Email,
+						"list":         list,
+						"words":        ui_v.SubSet.Keys,
+						"maxpushsize":  ui_v.SubSet.MaxPushSize,
+						"maxmailsize":  ui_v.SubSet.MaxMailSize,
+						"timestamp":    time.Now().Unix(),
+						"onlypush":     ui_v.Entniche.OnlyPush,
+						"vipstatus":    ui_v.Entniche.VipStatus,
+						"memberstatus": ui_v.Entniche.MemberStatus,
+						"s_m_openid":   ui_v.S_m_openid,
+						"subscribe":    ui_v.Subscribe,
+						"applystatus":  ui_v.ApplyStatus,
+						"wxtplmsg": map[string]interface{}{
+							"key":  wxtplmsg_keyword,
+							"area": wxtplmsg_area,
+						},
+					})
+					if len(saveBatch) == Mgo_BulkSize {
+						Mgo_Log.SaveBulk(Pushspace_temp, saveBatch...)
+						saveBatch = []map[string]interface{}{}
+					}
+				})
+			}
 		}(k, v)
 		index++
 		if index%500 == 0 {
@@ -724,7 +666,6 @@ func (m *MatchJob) UpdateCustomer(array *[]int64) {
 		ws = append(ws, "?")
 		args = append(args, v)
 	}
-
 	Mysql.UpdateOrDeleteBySql(`update entniche_customer set updatetime=? where id in (`+strings.Join(ws, ",")+`)`, args...)
 	*array = []int64{}
 }

+ 12 - 13
pushentniche/src/match/job/projectjob.go

@@ -43,7 +43,6 @@ func (m *MyPusher) Filter(unique string) (bool, []interface{}, *UserInfo) {
 			logger.Info("没有找到该部门", ui.Entniche.DeptId)
 			return true, nil, ui
 		}
-		ui.Entniche.DeptName = EntDepts[ui.Entniche.DeptId].Name
 	} else if uniques[0] == "user" {
 		ui.Entniche.UserId = util.IntAll(uniques[2])
 		if EntUsers[ui.Entniche.UserId] == nil {
@@ -75,23 +74,23 @@ func (m *MyPusher) Filter(unique string) (bool, []interface{}, *UserInfo) {
 		"o_entniche.i_maxpushsize":  1,
 	}).One(&u)
 	if u == nil || len(u) == 0 {
-		logger.Info(ui.Entniche.EntName, ui.Entniche.EntId, ui.Entniche.DeptName, ui.Entniche.DeptId, ui.Entniche.UserId, "没有找到相关信息")
+		logger.Info(ui.Entniche.EntName, ui.Entniche.EntId, ui.Entniche.DeptId, ui.Entniche.UserId, "没有找到相关信息")
 		return true, nil, ui
 	}
 	o_entniche, _ := u["o_entniche"].(map[string]interface{})
 	if util.IntAllDef(o_entniche["i_projectmatch"], 1) == 0 {
-		logger.Info(ui.Entniche.EntName, ui.Entniche.EntId, ui.Entniche.DeptName, ui.Entniche.DeptId, ui.Entniche.UserId, "关联项目推送没有打开")
+		logger.Info(ui.Entniche.EntName, ui.Entniche.EntId, ui.Entniche.DeptId, ui.Entniche.UserId, "关联项目推送没有打开")
 		return true, nil, ui
 	}
 	ui.SubSet = &SubSet{MaxPushSize: util.IntAll(o_entniche["i_maxpushsize"])}
 	uIds := []interface{}{}
 	if ui.Entniche.DeptId > 0 {
-		if duis := GetDeptUserIds(ui); duis != nil {
+		if duis := GetDisUser(ui.Entniche); duis != nil {
 			for k, _ := range duis {
 				uIds = append(uIds, k)
 			}
 		} else {
-			logger.Info("该规则没有需要推送的员工", ui.Entniche.EntName, ui.Entniche.EntId, ui.Entniche.DeptName, ui.Entniche.DeptId, ui.Entniche.DisId)
+			logger.Info("该规则没有需要推送的员工", ui.Entniche.EntName, ui.Entniche.EntId, ui.Entniche.DeptId, ui.Entniche.DisId)
 		}
 	} else if ui.Entniche.UserId > 0 {
 		uIds = append(uIds, ui.Entniche.UserId)
@@ -101,9 +100,9 @@ func (m *MyPusher) Filter(unique string) (bool, []interface{}, *UserInfo) {
 func (m *MyPusher) SaveToMysql(u *UserInfo, matchInfos *SortList, jobTime *time.Time) int64 {
 	r := SaveToMysql(Mysql, PushMysql, savePool, Config.ProjectSaveSleep, true, u, matchInfos, jobTime)
 	if r > 0 {
-		logger.Info(u.Entniche.EntName, u.Entniche.EntId, u.Entniche.DeptName, u.Entniche.DeptId, u.Entniche.UserId, "关联项目推送保存成功", r, len(*matchInfos))
+		logger.Info(u.Entniche.EntName, u.Entniche.EntId, u.Entniche.DeptId, u.Entniche.UserId, "关联项目推送保存成功", r, len(*matchInfos))
 	} else {
-		logger.Info(u.Entniche.EntName, u.Entniche.EntId, u.Entniche.DeptName, u.Entniche.DeptId, u.Entniche.UserId, "关联项目推送保存出错", r)
+		logger.Info(u.Entniche.EntName, u.Entniche.EntId, u.Entniche.DeptId, u.Entniche.UserId, "关联项目推送保存出错", r)
 	}
 	return r
 }
@@ -116,11 +115,10 @@ func (m *MyPusher) DayCountKey(u *UserInfo, ymd string) string {
 func (m *MyPusher) ChildUserInfo(unique interface{}, parent *UserInfo) (*UserInfo, bool) {
 	return &UserInfo{
 		Entniche: &Entniche{
-			UserId:   util.IntAll(unique),
-			EntId:    parent.Entniche.EntId,
-			EntName:  parent.Entniche.EntName,
-			DeptId:   parent.Entniche.DeptId,
-			DeptName: parent.Entniche.DeptName,
+			UserId:  util.IntAll(unique),
+			EntId:   parent.Entniche.EntId,
+			EntName: parent.Entniche.EntName,
+			DeptId:  parent.Entniche.DeptId,
 		},
 		SubSet: parent.SubSet,
 	}, true
@@ -137,7 +135,8 @@ func (p *ProjectPushJob) Execute() {
 		ClearEnt()
 	}()
 	logger.Info("开始关联项目推送任务。。。")
-	InitEnt(Mysql, Mgo, DbConf.Mongodb.Main.DbName)
+	_, _, entEpu, _ := LoadEntProductUsers(Mysql)
+	InitEnt(Mysql, Mgo, DbConf.Mongodb.Main.DbName, Config.TestQuery, entEpu)
 	push := &Push{
 		Mgo_Bidding:             Mgo_Bidding,
 		Mgo_Log:                 Mgo_Log,

+ 1 - 1
pushentniche/src/match/task.json

@@ -1 +1 @@
-{"lastTime":"","lastId":"5f492fed7073b821a8d607f1"}
+{"pici":1599062400}

+ 71 - 39
pushentniche/src/public/entity.go

@@ -26,48 +26,47 @@ func (s UisSortByRateMode) Swap(i, j int) {
 
 //
 func NewUserInfo(Mgo *MongodbSim, e *UserInfo) UisSortByRateMode {
-	if EntUsers[e.Entniche.UserId] == nil {
-		return nil
-	}
-	phone := EntUsers[e.Entniche.UserId].Phone
 	var users *[]map[string]interface{}
 	var ok bool
-	field := `{"_id":1,"s_jpushid":1,"s_opushid":1,"s_appponetype":1,"o_entniche":1}`
+	field := `{"_id":1,"base_user_id":1,"s_m_openid":1,"i_applystatus":1,"i_ispush":1,"s_jpushid":1,"s_opushid":1,"s_appponetype":1,"o_entniche":1}`
 	if e.Id != "" {
 		var user *map[string]interface{}
 		user, ok = Mgo.FindById(Mgo_User, e.Id, field)
 		if ok && user != nil {
 			users = &[]map[string]interface{}{*user}
 		}
-	} else if phone != "" {
+	} else if e.Entniche.Phone != "" {
 		users, ok = Mgo.Find(Mgo_User, map[string]interface{}{
 			"i_appid": 2,
 			"$or": []map[string]interface{}{
 				map[string]interface{}{
-					"s_phone": phone,
+					"s_phone": e.Entniche.Phone,
 				},
 				map[string]interface{}{
-					"s_m_phone": phone,
+					"s_m_phone": e.Entniche.Phone,
 				},
 			},
 		}, `{"s_phone":-1}`, field, false, -1, -1)
 	} else {
+		logger.Info("mongodb中查找用户缺少查询条件", e.Entniche.EntName, e.Entniche.EntId, e.Entniche.DeptId, e.Entniche.UserId)
 		return nil
 	}
 	if !ok || users == nil || len(*users) == 0 {
-		logger.Error("mongodb中没有找到该用户", e.Entniche.EntName, e.Entniche.EntId, e.Entniche.DeptName, e.Entniche.DeptId, e.Entniche.UserId, e.Id, phone)
+		logger.Info("mongodb中没有找到该用户", e.Entniche.EntName, e.Entniche.EntId, e.Entniche.DeptId, e.Entniche.UserId, e.Id, e.Entniche.Phone)
 		return nil
 	}
 	var us UisSortByRateMode
+	onlyPush := 0
 	for _, v := range *users {
 		u := &UserInfo{
 			Id: BsonIdToSId(v["_id"]),
 			Entniche: &Entniche{
-				EntId:   e.Entniche.EntId,
-				EntName: e.Entniche.EntName,
-				DeptId:  e.Entniche.DeptId,
-				UserId:  e.Entniche.UserId,
-				DisId:   e.Entniche.DisId,
+				EntId:    e.Entniche.EntId,
+				EntName:  e.Entniche.EntName,
+				DeptId:   e.Entniche.DeptId,
+				UserId:   e.Entniche.UserId,
+				DisId:    e.Entniche.DisId,
+				OnlyPush: onlyPush,
 			},
 			SubSet: &SubSet{
 				RateMode:    e.SubSet.RateMode,
@@ -78,9 +77,13 @@ func NewUserInfo(Mgo *MongodbSim, e *UserInfo) UisSortByRateMode {
 				MaxPushSize: e.SubSet.MaxPushSize,
 				MaxMailSize: e.SubSet.MaxMailSize,
 			},
+			BaseUserId:   util.Int64All(v["base_user_id"]),
 			Jpushid:      util.ObjToString(v["s_jpushid"]),
 			Opushid:      util.ObjToString(v["s_opushid"]),
 			AppPhoneType: util.ObjToString(v["s_appponetype"]),
+			ApplyStatus:  util.IntAll(v["i_applystatus"]),
+			Subscribe:    util.IntAllDef(v["i_ispush"], 1),
+			S_m_openid:   util.ObjToString(v["s_m_openid"]),
 		}
 		if v["o_entniche"] != nil {
 			o_entniche, _ := v["o_entniche"].(map[string]interface{})
@@ -95,8 +98,9 @@ func NewUserInfo(Mgo *MongodbSim, e *UserInfo) UisSortByRateMode {
 		if !MailReg.MatchString(u.SubSet.Email) {
 			u.SubSet.MailPush = 0
 		}
-		logger.Info("mongodb中找到该用户", u.Entniche.EntName, u.Entniche.EntId, u.Entniche.DeptName, u.Entniche.DeptId, u.Entniche.UserId, u.Phone, u.Id, u.Jpushid, u.Opushid, u.AppPhoneType)
+		logger.Info("mongodb中找到该用户", u.Entniche.EntName, u.Entniche.EntId, u.Entniche.DeptId, u.Entniche.UserId, u.Phone, u.Id, u.Jpushid, u.Opushid, u.AppPhoneType)
 		us = append(us, u)
+		onlyPush = 1
 	}
 	sort.Sort(us)
 	return us
@@ -106,25 +110,27 @@ func NewUserInfo(Mgo *MongodbSim, e *UserInfo) UisSortByRateMode {
 var Ents = map[int]*Ent{}
 
 type Ent struct {
-	Id         int
-	Model      int
-	Name       string
-	DeptParent map[int][]int
-	IsNew      int
+	Id            int
+	Model         int
+	Name          string
+	DeptParent    map[int][]int
+	IsNew         int
+	DeptSubscribe int
 }
 
 func InitEnts(Mysql *mysql.Mysql) {
-	list := Mysql.SelectBySql("select id,model,name,isNew from entniche_info where status=1 and model in (1,2)")
+	list := Mysql.SelectBySql("select id,model,name,isNew,dept_subscribe from entniche_info where status=1 and model in (1,2) and power_source is null")
 	if list == nil {
 		return
 	}
 	for _, v := range *list {
 		id := util.IntAll(v["id"])
 		Ents[id] = &Ent{
-			Id:    id,
-			Model: util.IntAll(v["model"]),
-			Name:  util.ObjToString(v["name"]),
-			IsNew: util.IntAll(v["isNew"]),
+			Id:            id,
+			Model:         util.IntAll(v["model"]),
+			Name:          util.ObjToString(v["name"]),
+			IsNew:         util.IntAll(v["isNew"]),
+			DeptSubscribe: util.IntAll(v["dept_subscribe"]),
 		}
 	}
 	logger.Info("entniche_info加载完成!")
@@ -141,7 +147,8 @@ type EntUser struct {
 }
 
 func InitEntUsers(Mysql *mysql.Mysql) {
-	list := Mysql.SelectBySql(`select id,name,mail,phone,power from entniche_user`)
+	list := Mysql.SelectBySql(`select a.id,a.name,a.mail,a.phone,a.power from entniche_user a
+		inner join entniche_info b on (b.status=1 and b.model in (1,2) and b.power_source is null and a.ent_id=b.id)`)
 	if list == nil {
 		return
 	}
@@ -169,7 +176,8 @@ type EntDept struct {
 }
 
 func InitEntDepts(Mysql *mysql.Mysql) {
-	list := Mysql.SelectBySql(`select id,name,pid,subdis,nodiff from entniche_department`)
+	list := Mysql.SelectBySql(`select a.id,a.name,a.pid,a.subdis,a.nodiff from entniche_department a
+		inner join entniche_info b on (b.status=1 and b.model in (1,2) and b.power_source is null and a.ent_id=b.id)`)
 	if list == nil {
 		return
 	}
@@ -198,7 +206,9 @@ type EntDeptParent struct {
 }
 
 func InitEntDeptParents(Mysql *mysql.Mysql) {
-	list := Mysql.SelectBySql(`select id,pid from entniche_department_parent`)
+	list := Mysql.SelectBySql(`select a.id,a.pid from entniche_department_parent a
+		inner join entniche_department b on (a.id=b.id or a.pid=b.id)
+		inner join entniche_info c on (c.status=1 and c.model in (1,2) and c.power_source is null and b.ent_id=c.id)`)
 	if list == nil {
 		return
 	}
@@ -226,7 +236,9 @@ type EntDeptUser struct {
 }
 
 func InitEntDeptUsers(Mysql *mysql.Mysql) {
-	list := Mysql.SelectBySql(`select dept_id,user_id from entniche_department_user`)
+	list := Mysql.SelectBySql(`select a.dept_id,a.user_id from entniche_department_user a
+		inner join entniche_department b on (a.dept_id=b.id)
+		inner join entniche_info c on (c.status=1 and c.model in (1,2) and c.power_source is null and b.ent_id=c.id)`)
 	if list == nil {
 		return
 	}
@@ -249,10 +261,17 @@ var EntUserRules = map[int][]*EntRuleUser{}
 type EntRuleUser struct {
 	UserId int
 	RuleId string
+	Phone  string
 }
 
 func InitEntRuleUsers(Mysql *mysql.Mysql) {
-	list := Mysql.SelectBySql(`select user_id,rule_id from entniche_user_rule`)
+	list := Mysql.SelectBySql(`select a.user_id,a.rule_id,aa.phone from entniche_user_rule a 
+		inner join entniche_user aa on (a.user_id=aa.id) 
+		where exists (
+			select 1 from entniche_user b inner join entniche_info c on (c.status=1 and c.model in (1,2) and c.power_source is null and b.ent_id=c.id) where a.user_id=b.id
+		) or exists( select 1 from entniche_wait_empower b
+			inner join entniche_power c on (b.end_time>? and c.status=1 and b.id=c.wait_empower_id) where a.user_id=c.ent_user_id
+		)`, util.NowFormat(util.Date_Full_Layout))
 	if list == nil {
 		return
 	}
@@ -262,6 +281,7 @@ func InitEntRuleUsers(Mysql *mysql.Mysql) {
 		entRuleUser := &EntRuleUser{
 			UserId: userId,
 			RuleId: ruleId,
+			Phone:  util.ObjToString(v["phone"]),
 		}
 		EntRuleUsers[ruleId] = append(EntRuleUsers[ruleId], entRuleUser)
 		EntUserRules[userId] = append(EntUserRules[userId], entRuleUser)
@@ -270,21 +290,29 @@ func InitEntRuleUsers(Mysql *mysql.Mysql) {
 }
 
 var EntDeptDis = map[int][]*EntDistribute{}
+var EntDis = map[int][]*EntDistribute{}
 
 type EntDistribute struct {
 	Id         string
+	EntId      int
 	DeptId     int
 	Area       map[string]interface{}
 	Buyerclass []interface{}
 	Items      []string
 }
 
-func InitEntDistribute(mgo *MongodbSim, dbName string) {
+func InitEntDistribute(mgo *MongodbSim, dbName string, testQuery map[string]interface{}, epu map[int]*Entniche) {
+	query := map[string]interface{}{
+		"i_status": map[string]interface{}{"$ne": 1},
+	}
+	if len(testQuery) > 0 {
+		for k, v := range testQuery {
+			query[k] = v
+		}
+	}
 	sess := mgo.GetMgoConn()
 	defer mgo.DestoryMongoConn(sess)
-	it := sess.DB(dbName).C(Entniche_distribute).Find(map[string]interface{}{
-		"i_status": map[string]interface{}{"$ne": 1},
-	}).Select(map[string]interface{}{
+	it := sess.DB(dbName).C(Entniche_distribute).Find(query).Select(map[string]interface{}{
 		"_id":          1,
 		"i_entid":      1,
 		"i_deptid":     1,
@@ -293,20 +321,24 @@ func InitEntDistribute(mgo *MongodbSim, dbName string) {
 		"a_buyerclass": 1,
 	}).Iter()
 	for temp := make(map[string]interface{}); it.Next(&temp); {
-		if temp["i_deptid"] == nil {
-			continue
-		}
+		entId := util.IntAll(temp["i_entid"])
 		deptId := util.IntAll(temp["i_deptid"])
 		a_items, _ := temp["a_items"].([]interface{})
 		o_area, _ := temp["o_area"].(map[string]interface{})
 		a_buyerclass, _ := temp["a_buyerclass"].([]interface{})
-		EntDeptDis[deptId] = append(EntDeptDis[deptId], &EntDistribute{
+		entDis := &EntDistribute{
 			Id:         BsonIdToSId(temp["_id"]),
+			EntId:      entId,
 			DeptId:     deptId,
 			Area:       o_area,
 			Buyerclass: a_buyerclass,
 			Items:      util.ObjArrToStringArr(a_items),
-		})
+		}
+		if Ents[entId] != nil && Ents[entId].Model == 1 && Ents[entId].DeptSubscribe == 1 && EntDepts[deptId] != nil && EntDepts[deptId].Subdis == 1 && EntDepts[deptId].Nodiff == 0 {
+			EntDeptDis[deptId] = append(EntDeptDis[deptId])
+		} else if epu[entId] != nil {
+			EntDis[entId] = append(EntDis[entId], entDis)
+		}
 		temp = make(map[string]interface{})
 	}
 }

+ 127 - 35
pushentniche/src/public/util.go

@@ -8,6 +8,7 @@ import (
 	"qfw/util/jy"
 	. "qfw/util/mysql"
 	"strings"
+	"sync"
 	"time"
 
 	"github.com/donnie4w/go-logger/logger"
@@ -59,42 +60,135 @@ func PushInfoKey(userId int, infoId string) string {
 }
 
 //
-func GetDeptUserIds(ui *UserInfo) map[int]bool {
-	if EntDepts[ui.Entniche.DeptId].Subdis == 0 {
-		logger.Info(ui.Entniche.EntName, ui.Entniche.EntId, ui.Entniche.DeptName, ui.Entniche.DeptId, "没有开启订阅分发,过滤掉")
-		return nil
-	} else if EntDepts[ui.Entniche.DeptId].Nodiff == 0 && ui.Entniche.DisId == "" {
-		logger.Info(ui.Entniche.EntName, ui.Entniche.EntId, ui.Entniche.DeptName, ui.Entniche.DeptId, "没有开启全员无差别接收,并且没有分发规则,过滤掉")
-		return nil
+func GetUserType(e *Entniche) string {
+	if e.MemberStatus == 1 {
+		return "大会员/商机管理"
+	} else if e.VipStatus == 1 {
+		return "超级订阅/商机管理"
+	} else {
+		return "商机管理"
 	}
-	//对我的对着生效的用户
-	myIds := map[int]bool{}
-	//打开了全员无差别,下面所有员工都生效
-	if EntDepts[ui.Entniche.DeptId].Nodiff == 1 {
-		for _, v := range EntDeptUsers[ui.Entniche.DeptId] {
-			myIds[v.UserId] = true
-		}
-		for _, v := range EntChildDept[ui.Entniche.DeptId] {
-			for _, vv := range EntDeptUsers[v.Id] {
-				myIds[vv.UserId] = true
+}
+
+//加载购买企业产品用户的订阅设置
+func LoadEntProductSubSet(mgo *MongodbSim, poolSize int, epus []*Entniche) map[*UserInfo]bool {
+	defer util.Catch()
+	logger.Info("开始加载购买企业产品用户的订阅设置。。。")
+	pool := make(chan bool, poolSize)
+	wait := &sync.WaitGroup{}
+	lock := &sync.Mutex{}
+	result := map[*UserInfo]bool{}
+	for _, v := range epus {
+		pool <- true
+		wait.Add(1)
+		go func(e *Entniche) {
+			defer util.Catch()
+			defer func() {
+				<-pool
+				wait.Done()
+			}()
+			onlyPush := 0
+			list, ok := mgo.Find(Mgo_User, map[string]interface{}{"$or": []map[string]interface{}{map[string]interface{}{"s_phone": e.Phone}, map[string]interface{}{"s_m_phone": e.Phone}}}, nil, map[string]interface{}{
+				"_id":             1,
+				"s_m_openid":      1,
+				"i_applystatus":   1,
+				"i_ispush":        1,
+				"i_member_status": 1,
+				"o_member_jy":     1,
+				"o_vipjy":         1,
+				"i_vip_status":    1,
+				"s_jpushid":       1,
+				"s_opushid":       1,
+				"s_appponetype":   1,
+				"base_user_id":    1,
+			}, false, -1, -1)
+			if !ok || *list == nil {
+				logger.Info("购买企业产品用户", "没有找到该用户", fmt.Sprintf("%+v", e))
+				return
 			}
-		}
-		logger.Info(ui.Entniche.EntName, ui.Entniche.EntId, ui.Entniche.DeptName, ui.Entniche.DeptId, "该部门打开了全员无差别", len(myIds), "人接收")
-	} else if ui.Entniche.DisId != "" {
-		for _, v := range EntRuleUsers[ui.Entniche.DisId] {
-			myIds[v.UserId] = true
-		}
-		logger.Info(ui.Entniche.EntName, ui.Entniche.EntId, ui.Entniche.DeptName, ui.Entniche.DeptId, "该规则开启了订阅分发", ui.Entniche.DisId, "规则分发了", len(myIds), "人")
+			for _, vv := range *list {
+				onlyPush = 1
+				var subSet *SubSet
+				userId := BsonIdToSId(vv["_id"])
+				if e.MemberStatus == 1 {
+					if util.IntAll(vv["i_member_status"]) <= 0 {
+						logger.Info("企业分配的大会员用户", "不是大会员,过滤掉", userId)
+						return
+					}
+					subSetobj, _ := vv["o_member_jy"].(map[string]interface{})
+					subSet = GetSubSet(false, userId, subSetobj)
+					subSet.RateMode = util.IntAllDef(subSetobj["i_ratemode"], 1)
+					if util.IntAllDef(subSetobj["i_subscribe"], 1) != 1 {
+						logger.Info("企业分配的大会员用户", "开关状态是关闭的,过滤掉", userId)
+						return
+					}
+				} else if e.VipStatus == 1 {
+					if util.IntAll(vv["i_vip_status"]) <= 0 {
+						logger.Info("企业分配的超级订阅用户", "不是超级订阅,过滤掉", userId)
+						return
+					}
+					subSetobj, _ := vv["o_vipjy"].(map[string]interface{})
+					subSet = GetSubSet(false, userId, subSetobj)
+				} else {
+					logger.Info("无效的产品类型", fmt.Sprintf("%+v", e))
+					return
+				}
+				user := &UserInfo{
+					Id:           userId,
+					BaseUserId:   util.Int64All(vv["base_user_id"]),
+					Jpushid:      util.ObjToString(vv["s_jpushid"]),
+					Opushid:      util.ObjToString(vv["s_opushid"]),
+					Phone:        e.Phone,
+					AppPhoneType: util.ObjToString(vv["s_appponetype"]),
+					ApplyStatus:  util.IntAll(vv["i_applystatus"]),
+					Subscribe:    util.IntAllDef(vv["i_ispush"], 1),
+					S_m_openid:   util.ObjToString(vv["s_m_openid"]),
+					SubSet:       subSet,
+					Entniche: &Entniche{
+						EntId:        e.EntId,
+						EntName:      e.EntName,
+						DeptId:       e.DeptId,
+						UserId:       e.UserId,
+						OnlyPush:     onlyPush,
+						ProductType:  e.ProductType,
+						Phone:        e.Phone,
+						PowerSource:  e.PowerSource,
+						IsNew:        e.IsNew,
+						VipStatus:    e.VipStatus,
+						MemberStatus: e.MemberStatus,
+					},
+				}
+				logger.Info("加载商机管理产品我的订阅设置", fmt.Sprintf("%+v", user))
+				lock.Lock()
+				result[user] = true
+				lock.Unlock()
+			}
+		}(v)
+	}
+	wait.Wait()
+	logger.Info("加载购买企业产品用户的订阅设置加载结束。。。")
+	return result
+}
+
+//获取分发人员
+func GetDisUser(ei *Entniche) map[int]*EntRuleUser {
+	myIds := map[int]*EntRuleUser{}
+	for _, v := range EntRuleUsers[ei.DisId] {
+		myIds[v.UserId] = v
+	}
+	logger.Info(ei.EntName, ei.EntId, ei.DeptId, "规则分发了", len(myIds), "人")
+	if ei.DeptId == 0 {
+		return myIds
 	}
 	//我的上级部门,过滤掉本部门的人
-	for _, v := range EntParentDept[ui.Entniche.DeptId] {
+	for _, v := range EntParentDept[ei.DeptId] {
 		//看我的上级部门,有没有开启订阅分发
 		if EntDepts[v.Pid].Subdis == 0 {
 			continue
 		}
 		//看我的上级部门,有没有全员无差别接收
 		if EntDepts[v.Pid].Nodiff == 1 {
-			logger.Info(ui.Entniche.EntName, ui.Entniche.EntId, ui.Entniche.DeptName, ui.Entniche.DeptId, ui.Entniche.DisId, "上级部门", v.Pid, "打开了全员无差别开关,过滤掉")
+			logger.Info(ei.EntName, ei.EntId, ei.DeptId, ei.DisId, "上级部门", v.Pid, "打开了全员无差别开关,过滤掉")
 			return nil
 		}
 		//看我的上级部门,有没有对我设置规则
@@ -105,11 +199,11 @@ func GetDeptUserIds(ui *UserInfo) map[int]bool {
 					continue
 				}
 				delete(myIds, vvv.UserId)
-				logger.Info(ui.Entniche.EntName, ui.Entniche.EntId, ui.Entniche.DeptName, ui.Entniche.DeptId, "上级部门", v.Pid, "对我设置的有", vvv.RuleId, "分发规则,此规则作废", vvv.UserId)
+				logger.Info(ei.EntName, ei.EntId, ei.DeptId, "上级部门", v.Pid, "对我设置的有", vvv.RuleId, "分发规则,此规则作废", vvv.UserId)
 			}
 		}
 	}
-	logger.Info(ui.Entniche.EntName, ui.Entniche.EntId, ui.Entniche.DeptName, ui.Entniche.DeptId, ui.Entniche.DisId, "该规则匹配到", len(myIds), "人")
+	logger.Info(ei.EntName, ei.EntId, ei.DeptId, ei.DisId, "该规则匹配到", len(myIds), "人")
 	return myIds
 }
 
@@ -160,9 +254,6 @@ func SaveToMysql(mysql, pushMysql *Mysql, savePool chan bool, sleep int, isProje
 		if deptId == 0 {
 			deptId = EntUserDept[u.Entniche.UserId].DeptId
 		}
-		if EntDepts[deptId] != nil {
-			u.Entniche.DeptName = EntDepts[deptId].Name
-		}
 		values = append(values, u.Entniche.EntId, deptId, u.Entniche.UserId, _id, unix)
 		if len(matchInfo.Keys) > 0 {
 			values = append(values, strings.Join(matchInfo.Keys, " "))
@@ -200,7 +291,7 @@ func SaveToMysql(mysql, pushMysql *Mysql, savePool chan bool, sleep int, isProje
 				}
 				if len(user_customers) > 0 {
 					eus_count, _ := mysql.InsertIgnoreBatch("entniche_user_customer", []string{"customer_id", "user_id", "type", "timestamp"}, user_customers)
-					logger.Info(u.Entniche.EntName, u.Entniche.EntId, u.Entniche.DeptName, u.Entniche.DeptId, u.Entniche.UserId, u.Id, "自动分配客户", eus_count)
+					logger.Info(u.Entniche.EntName, u.Entniche.EntId, u.Entniche.DeptId, u.Entniche.UserId, u.Id, "自动分配客户", eus_count)
 				}
 			}
 			batchSize = 0
@@ -208,7 +299,7 @@ func SaveToMysql(mysql, pushMysql *Mysql, savePool chan bool, sleep int, isProje
 		}
 	}
 	if int(saveCount) != length {
-		logger.Error(u.Entniche.EntName, u.Entniche.EntId, u.Entniche.DeptName, u.Entniche.DeptId, u.Entniche.UserId, u.Id, "批量保存有问题", length, saveCount)
+		logger.Error(u.Entniche.EntName, u.Entniche.EntId, u.Entniche.DeptId, u.Entniche.UserId, u.Id, "批量保存有问题", length, saveCount)
 		if saveCount <= 0 {
 			return 0
 		}
@@ -267,14 +358,14 @@ func SaveToMysql(mysql, pushMysql *Mysql, savePool chan bool, sleep int, isProje
 }
 
 //
-func InitEnt(mysql *Mysql, mgo *MongodbSim, dbName string) {
+func InitEnt(mysql *Mysql, mgo *MongodbSim, dbName string, testQuery map[string]interface{}, epu map[int]*Entniche) {
 	InitEnts(mysql)
 	InitEntUsers(mysql)
 	InitEntDeptUsers(mysql)
 	InitEntRuleUsers(mysql)
 	InitEntDepts(mysql)
 	InitEntDeptParents(mysql)
-	InitEntDistribute(mgo, dbName)
+	InitEntDistribute(mgo, dbName, testQuery, epu)
 }
 
 //
@@ -289,4 +380,5 @@ func ClearEnt() {
 	EntParentDept = map[int][]*EntDeptParent{}
 	EntChildDept = map[int][]*EntDeptParent{}
 	EntDeptDis = map[int][]*EntDistribute{}
+	EntDis = map[int][]*EntDistribute{}
 }

+ 60 - 1
pushentniche/src/push/config.json

@@ -27,6 +27,7 @@
 	],
 	"maxPushSize":50000,
 	"testQuery":{"i_entid":14628},
+	"weixinRpcServer":"127.0.0.1:8083",
 	"appPushServiceRpc":"127.0.0.1:5566",
 	"oncePushTime":"9:00",
 	"otherPushTimes":[
@@ -45,18 +46,76 @@
 	"mailSleep":200,
 	"saveSleep":200,
 	"appSleep":5,
+	"wxSleep":5,
 	"isPushMail":true,
 	"pushBatch":10,
 	"bulkSize":50,
 	"bigBulkSize":100,
+	"loadEntProductUsersPoolSize":10,
 	"timeoutWarn":"http://172.17.4.195:19281/_send/_mail?program=pushentniche_push&to=wangchuanjin@topnet.net.cn&title=商机管理推送程序报警&body=放入通道超时",
+	"subMsgTip":{
+		"wx":{
+			"id":"ahEQafQBYZX8cVYXko-XaU1QkJ8MHiR-O9UNv_BRMzk",
+			"first":{
+				"value":"005",
+				"color":"#686868"
+			},
+			"keyword1":{
+				"color":"#44BEF3"
+			},
+			"keyword2":{
+				"color":"#44BEF3"
+			},
+			"keyword3":{
+				"color":"#44BEF3"
+			},
+			"keyword4":{
+				"color":"#44BEF3"
+			},
+			"remark_title":{
+				"value":"亲爱的%s用户,剑鱼标讯为你推送以下信息。\n\n"
+			},
+			"remark":{
+				"color":"#686868"
+			},
+			"url":"/swordfish/newhistorypush?f=push&t=%s&pushtime=%d&advertcode=%s"
+		},
+		"app":{
+			"title":"亲爱的%s用户:您有新的订阅信息啦,快来查看吧!",
+			"url":"/jyapp/swordfish/historypush?f=push&t=%s&pushtime=%d"
+		}
+	},
 	"noMsgTip":{
 		"available":true,
 		"checkMaxPushPersion":2,
 		"selectPoolSize":5,
+		"wx":{
+			"first":{
+				"value":"003",
+				"color":"#686868"
+			},
+			"keyword1":{
+				"color":"#44BEF3"
+			},
+			"keyword2":{
+				"color":"#44BEF3"
+			},
+			"keyword3":{
+				"color":"#44BEF3"
+			},
+			"keyword4":{
+				"color":"#44BEF3"
+			},
+			"remark":{
+				"color":"#686868"
+			},
+			"url":"/front/vipsubscribe/toSubVipSetPage?vSwitch=%s&advertcode=%s"
+		},
 		"app":{
 			"title":"剑鱼推送消息!",
-			"descript":"亲爱的商机管理用户,根据您当前的订阅,%s剑鱼标讯未能匹配到您需要的招标信息,请检查您的订阅是否需要进行优化,如需获取帮助,可点击“我的”页面内的使用帮助按钮,或者联系剑鱼标讯客服。"
+			"descript":"亲爱的%s用户,根据您当前的订阅,%s剑鱼标讯未能匹配到您需要的招标信息,请检查您的订阅是否需要进行优化,如需获取帮助,可点击“我的”页面内的使用帮助按钮,或者联系剑鱼标讯客服。",
+			"url":"/jyapp/vipsubscribe/toSubVipSetPage?vSwitch=%s",
+			"entUrl":"/page_entniche/page/subsetting/sub_entrance.html"
 		},
 		"mail":{
 			"title":"剑鱼推送消息!",

+ 57 - 24
pushentniche/src/push/config/config.go

@@ -3,6 +3,7 @@ package config
 import (
 	"qfw/util"
 	"qfw/util/mail"
+	qrpc "qfw/util/rpc"
 	"strings"
 )
 
@@ -16,35 +17,67 @@ type config struct {
 		Html        string `json:"html"`
 		MaxPushSize int    `json:"maxPushSize"`
 	}
-	Mails                   []*pushMail            `json:"mails"`
-	MaxPushSize             int                    `json:"maxPushSize"`
-	TestQuery               map[string]interface{} `json:"testQuery"`
-	AppPushServiceRpc       string                 `json:"appPushServiceRpc"`
-	PushBatch               int                    `json:"pushBatch"`
-	OncePushTime            string                 `json:"oncePushTime"`
-	OtherPushTimes          []string               `json:"otherPushTimes"`
-	PushDay                 int                    `json:"pushDay"`
-	PushWeek                string                 `json:"pushWeek"`
-	AppPoolSize             int                    `json:"appPoolSize"`
-	MailSleep               int                    `json:"mailSleep"`
-	SaveSleep               int                    `json:"saveSleep"`
-	AppSleep                int                    `json:"appSleep"`
-	IsPushMail              bool                   `json:"isPushMail"`
-	SavePoolSize            int                    `json:"savePoolSize"`
-	MinutePushSize          int                    `json:"minutePushSize"`
-	FastigiumMinutePushSize int                    `json:"fastigiumMinutePushSize"`
-	FastigiumTime           string                 `json:"fastigiumTime"`
-	NinePushRedisTimeout    int                    `json:"ninePushRedisTimeout"`
-	BulkSize                int                    `json:"bulkSize"`
-	BigBulkSize             int                    `json:"bigBulkSize"`
-	TimeoutWarn             string                 `json:"timeoutWarn"`
-	NoMsgTip                struct {
+	Mails                       []*pushMail            `json:"mails"`
+	MaxPushSize                 int                    `json:"maxPushSize"`
+	TestQuery                   map[string]interface{} `json:"testQuery"`
+	WeixinRpcServer             string                 `json:"weixinRpcServer"`
+	AppPushServiceRpc           string                 `json:"appPushServiceRpc"`
+	PushBatch                   int                    `json:"pushBatch"`
+	OncePushTime                string                 `json:"oncePushTime"`
+	OtherPushTimes              []string               `json:"otherPushTimes"`
+	PushDay                     int                    `json:"pushDay"`
+	PushWeek                    string                 `json:"pushWeek"`
+	WxPoolSize                  int                    `json:"wxPoolSize"`
+	AppPoolSize                 int                    `json:"appPoolSize"`
+	MailSleep                   int                    `json:"mailSleep"`
+	SaveSleep                   int                    `json:"saveSleep"`
+	AppSleep                    int                    `json:"appSleep"`
+	WxSleep                     int                    `json:"wxSleep"`
+	IsPushMail                  bool                   `json:"isPushMail"`
+	SavePoolSize                int                    `json:"savePoolSize"`
+	MinutePushSize              int                    `json:"minutePushSize"`
+	FastigiumMinutePushSize     int                    `json:"fastigiumMinutePushSize"`
+	FastigiumTime               string                 `json:"fastigiumTime"`
+	NinePushRedisTimeout        int                    `json:"ninePushRedisTimeout"`
+	BulkSize                    int                    `json:"bulkSize"`
+	BigBulkSize                 int                    `json:"bigBulkSize"`
+	LoadEntProductUsersPoolSize int                    `json:"loadEntProductUsersPoolSize"`
+	TimeoutWarn                 string                 `json:"timeoutWarn"`
+	SubMsgTip                   struct {
+		Wx struct {
+			Id           string
+			First        *qrpc.TmplItem
+			Keyword1     *qrpc.TmplItem
+			Keyword2     *qrpc.TmplItem
+			Keyword3     *qrpc.TmplItem
+			Keyword4     *qrpc.TmplItem
+			Remark_title *qrpc.TmplItem
+			Remark       *qrpc.TmplItem
+			Url          string
+		} `json:"wx"`
+		App struct {
+			Title string `json:"title"`
+			Url   string `json:"url"`
+		} `json:"app"`
+	} `json:"subMsgTip"`
+	NoMsgTip struct {
 		Available           bool `json:"available"`
 		CheckMaxPushPersion int  `json:"checkMaxPushPersion"`
 		SelectPoolSize      int  `json:"selectPoolSize"`
-		App                 struct {
+		Wx                  struct {
+			First    *qrpc.TmplItem
+			Keyword1 *qrpc.TmplItem
+			Keyword2 *qrpc.TmplItem
+			Keyword3 *qrpc.TmplItem
+			Keyword4 *qrpc.TmplItem
+			Remark   *qrpc.TmplItem
+			Url      string
+		} `json:"wx"`
+		App struct {
 			Title    string `json:"title"`
 			Descript string `json:"descript"`
+			Url      string `json:"url"`
+			EntUrl   string `json:"entUrl"`
 		} `json:"app"`
 		Mail struct {
 			Title string `json:"title"`

+ 132 - 240
pushentniche/src/push/job/nomsgtipjob.go

@@ -11,6 +11,7 @@ import (
 	. "pusher"
 	"qfw/util"
 	"qfw/util/redis"
+	qrpc "qfw/util/rpc"
 	"strconv"
 	"strings"
 	"sync"
@@ -41,96 +42,21 @@ func (n *NoMsgTipJob) Execute(taskType int) {
 		return
 	}
 	defer ClearEnt()
-	InitEnt(Mysql, Mgo, DbConf.Mongodb.Main.DbName)
+	_, _, entEpu, epus := LoadEntProductUsers(Mysql)
+	users := LoadEntProductSubSet(Mgo, Config.LoadEntProductUsersPoolSize, epus)
+	InitEnt(Mysql, Mgo, DbConf.Mongodb.Main.DbName, Config.TestQuery, entEpu)
 	pushPool := make(chan bool, Config.PushPoolSize)
 	pushWait := &sync.WaitGroup{}
 	entSubSet := n.LoadSubSet(taskType)
-	users := map[string]*UserInfo{}
 	for entRule, _ := range entSubSet {
-		//分发规则,跳过
-		if entRule.Entniche.DeptId != 0 && EntDepts[entRule.Entniche.DeptId] != nil && EntDepts[entRule.Entniche.DeptId].Subdis == 1 && entRule.Entniche.DisId == "" && EntDepts[entRule.Entniche.DeptId].Nodiff == 0 {
-			continue
-		}
-		//
-		var staffIds map[int]bool
-		if entRule.Entniche.DeptId > 0 {
-			entRule.Entniche.DeptName = EntDepts[entRule.Entniche.DeptId].Name
-			staffIds = GetDeptUserIds(&UserInfo{
-				Entniche: entRule.Entniche,
-			})
-			if staffIds == nil {
-				return
-			}
-		} else if entRule.Entniche.UserId > 0 {
-			staffIds = map[int]bool{entRule.Entniche.UserId: true}
-		} else {
-			return
-		}
-		for staffId, _ := range staffIds {
-			uis := NewUserInfo(Mgo, &UserInfo{
-				Entniche: &Entniche{
-					EntId:    entRule.Entniche.EntId,
-					EntName:  entRule.Entniche.EntName,
-					DeptId:   entRule.Entniche.DeptId,
-					DeptName: entRule.Entniche.DeptName,
-					UserId:   staffId,
-					DisId:    entRule.Entniche.DisId,
-				},
-				SubSet: entRule.SubSet,
-				Id:     entRule.Id,
-			})
-			if uis == nil {
-				continue
-			}
-			onlypush := 0
-			jpushidMap, opushidMap, mailMap := map[string]bool{}, map[string]bool{}, map[string]bool{}
-			for _, ui_v := range uis {
-				if ui_v.SubSet.AppPush == 1 && (ui_v.Jpushid != "" && jpushidMap[ui_v.Jpushid]) || (ui_v.Opushid != "" && opushidMap[ui_v.Opushid]) {
-					ui_v.SubSet.AppPush = 0
-					ui_v.Jpushid = ""
-					ui_v.Opushid = ""
-				}
-				if ui_v.SubSet.MailPush == 1 && ui_v.SubSet.Email != "" && mailMap[ui_v.SubSet.Email] {
-					ui_v.SubSet.MailPush = 0
-					ui_v.SubSet.Email = ""
-				}
-				if ui_v.Jpushid != "" {
-					jpushidMap[ui_v.Jpushid] = true
-				}
-				if ui_v.Opushid != "" {
-					opushidMap[ui_v.Opushid] = true
-				}
-				if ui_v.SubSet.Email != "" {
-					mailMap[ui_v.SubSet.Email] = true
-				}
-				if onlypush == 1 {
-					if ui_v.SubSet.AppPush == 1 && ui_v.SubSet.MailPush == 1 {
-						if ui_v.Jpushid == "" && ui_v.Opushid == "" && ui_v.SubSet.Email == "" {
-							continue
-						}
-					} else if ui_v.SubSet.AppPush == 1 {
-						if ui_v.Jpushid == "" && ui_v.Opushid == "" {
-							continue
-						}
-					} else if ui_v.SubSet.MailPush == 1 {
-						if ui_v.SubSet.Email == "" {
-							continue
-						}
-					} else {
-						continue
-					}
-				}
-				onlypush = 1
-				users[ui_v.Id] = ui_v
-			}
-		}
+		users[entRule] = true
 	}
-	for _, v := range users {
+	for k, _ := range users {
 		isTake := true
 		select {
 		case <-time.After(1 * time.Minute):
 			isTake = false
-			logger.Error("推送任务", taskType, "推送放入通道超时,", v.Entniche.EntName, v.Entniche.EntId, v.Entniche.DeptName, v.Entniche.DeptId, v.Entniche.UserId, v.Id)
+			logger.Error("推送任务", taskType, "推送放入通道超时,", k.Entniche.EntName, k.Entniche.EntId, k.Entniche.DeptId, k.Entniche.UserId, k.Id)
 			go func() {
 				if Config.TimeoutWarn != "" {
 					if _, err := http.Get(Config.TimeoutWarn); err != nil {
@@ -153,7 +79,7 @@ func (n *NoMsgTipJob) Execute(taskType int) {
 				(taskType == 4 && user.SubSet.RateMode == 4) || (taskType == 5 && (user.SubSet.RateMode == 3 || user.SubSet.RateMode == 4)) {
 				n.tip(taskType, user)
 			}
-		}(v, isTake)
+		}(k, isTake)
 	}
 	pushWait.Wait()
 	logger.Info("无消息提醒任务结束。。。", taskType)
@@ -166,11 +92,16 @@ func (n *NoMsgTipJob) LoadSubSet(taskType int) map[*UserInfo]bool {
 	//
 	sess := Mgo.GetMgoConn()
 	defer Mgo.DestoryMongoConn(sess)
-	query := map[string]interface{}{}
+	query := map[string]interface{}{
+		"i_entid": map[string]interface{}{
+			"$gt": 0,
+		},
+		"i_userid": map[string]interface{}{
+			"$gt": 0,
+		},
+	}
 	if len(Config.TestQuery) > 0 {
-		for k, v := range Config.TestQuery {
-			query[k] = v
-		}
+		query = Config.TestQuery
 	}
 	logger.Info("无消息提醒任务", taskType, "加载订阅设置", query)
 	it := sess.DB(DbConf.Mongodb.Main.DbName).C(Entniche_rule).Find(query).Select(map[string]interface{}{
@@ -179,148 +110,41 @@ func (n *NoMsgTipJob) LoadSubSet(taskType int) map[*UserInfo]bool {
 		"i_userid":   1,
 		"o_entniche": 1,
 	}).Iter()
-	for _temp := make(map[string]interface{}); it.Next(&_temp); {
-		func(temp map[string]interface{}) {
-			entId := util.IntAll(temp["i_entid"])
-			deptId := util.IntAll(temp["i_deptid"])
-			userId := util.IntAll(temp["i_userid"])
-			if entId == 0 || (deptId == 0 && userId == 0) {
-				return
-			} else if Ents[entId] == nil {
-				logger.Info("无消息提醒任务", taskType, "没有找到该企业", entId)
-				return
-			}
-			entName := Ents[entId].Name
-			if deptId > 0 && EntDepts[deptId] == nil {
-				logger.Info("无消息提醒任务", taskType, "没有找到该部门", entName, entId, deptId)
-				return
-			}
-			deptName := ""
-			if EntDepts[deptId] != nil {
-				deptName = EntDepts[deptId].Name
-			}
-			subSet, _ := temp["o_entniche"].(map[string]interface{})
-			if subSet == nil || len(subSet) == 0 {
-				logger.Info("无消息提醒任务", taskType, "订阅设置为空,过滤掉", entName, entId, deptName, deptId, userId)
-				return
-			}
-			//
-			if deptId > 0 { //部门订阅
-				if Ents[entId].Model != 1 {
-					logger.Info("无消息提醒任务", taskType, "不是统一订阅模式,过滤掉", entName, entId, deptName, deptId)
-					return
-				} else if EntDepts[deptId] == nil {
-					logger.Info("无消息提醒任务", taskType, "没有找到该部门,过滤掉", entName, entId, deptName, deptId)
-					return
-				} else if EntDepts[deptId].Subdis == 0 {
-					logger.Info("无消息提醒任务", taskType, "该部门的订阅分发没有开启,过滤掉", entName, entId, deptName, deptId)
-					return
-				} else if EntDepts[deptId].Nodiff == 0 && EntDeptDis[deptId] == nil {
-					logger.Info("无消息提醒任务", taskType, "该部门开启了订阅分发,没有开启全员无差别接收,但是没有分发规则,过滤掉", entName, entId, deptName, deptId)
-					return
-				}
-				//如果我的上级部门打开了订阅分发,并且开启了全员无差别接收,本部门规则无效
-				for _, dept := range EntParentDept[deptId] {
-					if EntDepts[dept.Pid].Subdis == 1 && EntDepts[dept.Pid].Nodiff == 1 {
-						logger.Info("无消息提醒任务", taskType, "我的上级部门", dept.Pid, "开启了订阅分发和全员无差别,过滤掉", entName, entId, deptName, deptId)
-						return
-					}
-				}
-			} else if userId > 0 { //个人订阅
-				if Ents[entId].Model != 2 {
-					logger.Info("无消息提醒任务", taskType, "不是个人订阅模式,过滤掉", entName, entId, userId)
-					return
-				} else if EntUsers[userId] == nil {
-					logger.Info("无消息提醒任务", taskType, "没有找到该用户,过滤掉", entName, entId, userId)
-					return
-				} else if EntUsers[userId].Power == 0 {
-					logger.Info("无消息提醒任务", taskType, "该用户没有权限,过滤掉", entName, entId, userId)
-					return
-				}
-			}
-			rule := &UserInfo{
-				Entniche: &Entniche{
-					EntId:    entId,
-					EntName:  entName,
-					DeptId:   deptId,
-					DeptName: deptName,
-					UserId:   userId,
-					IsNew:    Ents[entId].IsNew,
-				},
-				SubSet: &SubSet{
-					AppPush:  util.IntAllDef(subSet["i_apppush"], 1),
-					MailPush: util.IntAll(subSet["i_mailpush"]),
-					RateMode: util.IntAllDef(subSet["i_ratemode"], 2),
-					MatchWay: util.IntAllDef(subSet["i_matchway"], 1),
-				},
-			}
-			logger.Info("无消息提醒任务", taskType, "加载订阅设置", "entId", entId, "entName", entName, "deptId", deptId, "deptName", deptName, "userId", userId, "appPush", rule.SubSet.AppPush, "mailPush", rule.SubSet.MailPush, "rateMode", rule.SubSet.RateMode, "matchWay", rule.SubSet.MatchWay)
-			if len(GetSubSet(false, fmt.Sprintf("%+v", rule), subSet).Keys) > 0 {
-				entSubSet[rule] = true
-			}
-			if deptId <= 0 {
-				return
-			}
-			//分发规则
-			if EntDepts[deptId].Nodiff == 1 {
-				logger.Info("无消息提醒任务", taskType, "该部门开启了全员无差别,分发规则无效", entName, entId, deptName, deptId)
-				return
-			} else if EntDeptDis[deptId] == nil {
-				logger.Info("无消息提醒任务", taskType, "该部门没有分发规则", entName, entId, deptName, deptId)
-				return
-			}
-			itemMap := map[string]interface{}{}
-			items, _ := subSet["a_items"].([]interface{})
-			for _, v := range items {
-				item, _ := v.(map[string]interface{})
-				if item == nil {
-					continue
-				}
-				item_name, _ := item["s_item"].(string)
-				if item_name == "" {
-					continue
-				}
-				itemMap[item_name] = item
-			}
-			for _, dis := range EntDeptDis[deptId] {
-				child_rule := &UserInfo{
-					Entniche: &Entniche{
-						EntId:    rule.Entniche.EntId,
-						EntName:  rule.Entniche.EntName,
-						DeptId:   rule.Entniche.DeptId,
-						DeptName: rule.Entniche.DeptName,
-						DisId:    dis.Id,
-						IsNew:    rule.Entniche.IsNew,
-					},
-					SubSet: rule.SubSet,
-				}
-				child_items := []interface{}{}
-				for _, item_name := range dis.Items {
-					if itemMap[item_name] == nil {
-						continue
-					}
-					child_items = append(child_items, itemMap[item_name])
-				}
-				child_subSet := map[string]interface{}{}
-				if len(dis.Buyerclass) > 0 {
-					child_subSet["a_buyerclass"] = dis.Buyerclass
-				}
-				if len(dis.Area) > 0 {
-					child_subSet["o_area"] = dis.Area
-				}
-				if len(child_items) > 0 {
-					child_subSet["a_items"] = child_items
-				}
-				if len(child_subSet) == 0 {
-					continue
-				}
-				if child_keySet := GetSubSet(false, fmt.Sprintf("%+v", child_rule), child_subSet); len(child_keySet.Keys) > 0 {
-					child_rule.SubSet.Keys = child_keySet.Keys
-					entSubSet[child_rule] = true
-				}
-			}
-		}(_temp)
-		_temp = make(map[string]interface{})
+	for temp := make(map[string]interface{}); it.Next(&temp); {
+		userId := util.IntAll(temp["i_userid"])
+		if util.IntAll(temp["i_deptid"]) != 0 || userId == 0 {
+			continue
+		}
+		entId := util.IntAll(temp["i_entid"])
+		var entName string
+		if Ents[entId] == nil {
+			logger.Info("无消息提醒任务", taskType, "没有找到该企业,过滤掉", entId)
+			continue
+		}
+		if EntUsers[userId] == nil {
+			logger.Info("无消息提醒任务", taskType, "没有找到该用户,过滤掉", entName, entId, userId)
+			continue
+		} else if EntUsers[userId].Power == 0 {
+			logger.Info("无消息提醒任务", taskType, "该用户没有权限,过滤掉", entName, entId, userId)
+			continue
+		}
+		subSet, _ := temp["o_entniche"].(map[string]interface{})
+		if subSet == nil || len(subSet) == 0 {
+			logger.Info("无消息提醒任务", taskType, "商机管理产品我的订阅设置为空,过滤掉", entName, entId, userId)
+			continue
+		}
+		user := &UserInfo{
+			Entniche: &Entniche{
+				EntId:   entId,
+				EntName: entName,
+				UserId:  userId,
+				IsNew:   Ents[entId].IsNew,
+			},
+			SubSet: GetSubSet(false, fmt.Sprint(userId), subSet),
+		}
+		entSubSet[user] = true
+		logger.Info("无消息提醒任务", taskType, "加载商机管理产品我的订阅设置", "entId", entId, "entName", entName, "userId", userId, "wxPush", user.SubSet.WxPush, "appPush", user.SubSet.AppPush, "mailPush", user.SubSet.MailPush, "rateMode", user.SubSet.RateMode, "matchWay", user.SubSet.MatchWay)
+		temp = make(map[string]interface{})
 	}
 	return entSubSet
 }
@@ -328,16 +152,16 @@ func (n *NoMsgTipJob) LoadSubSet(taskType int) map[*UserInfo]bool {
 //提醒
 func (n *NoMsgTipJob) tip(taskType int, user *UserInfo) {
 	if exists, err := redis.Exists(Pushcache_2_c, HasPushKey(user.Entniche.UserId)); err != nil {
-		logger.Error("无消息提醒任务", taskType, "redis判断今天是否推送过出错", err, user.Entniche.EntName, user.Entniche.EntId, user.Entniche.DeptName, user.Entniche.DeptId, user.Entniche.UserId, user.Id)
+		logger.Error("无消息提醒任务", taskType, "redis判断今天是否推送过出错", err, user.Entniche.EntName, user.Entniche.EntId, user.Entniche.DeptId, user.Entniche.UserId, user.Id)
 		return
 	} else if exists {
-		logger.Info("无消息提醒任务", taskType, "redis判断今天推送过,过滤掉", user.Entniche.EntName, user.Entniche.EntId, user.Entniche.DeptName, user.Entniche.DeptId, user.Entniche.UserId, user.Id)
+		logger.Info("无消息提醒任务", taskType, "redis判断今天推送过,过滤掉", user.Entniche.EntName, user.Entniche.EntId, user.Entniche.DeptId, user.Entniche.UserId, user.Id)
 		return
 	} else if exists, err := redis.Exists(Pushcache_2_c, NoMsgTipKey(user.Id)); err != nil {
-		logger.Error("无消息提醒任务", taskType, "redis判断今天是否提醒过出错", err, user.Entniche.EntName, user.Entniche.EntId, user.Entniche.DeptName, user.Entniche.DeptId, user.Entniche.UserId, user.Id)
+		logger.Error("无消息提醒任务", taskType, "redis判断今天是否提醒过出错", err, user.Entniche.EntName, user.Entniche.EntId, user.Entniche.DeptId, user.Entniche.UserId, user.Id)
 		return
 	} else if exists {
-		logger.Info("无消息提醒任务", taskType, "redis判断今天提醒过,过滤掉", user.Entniche.EntName, user.Entniche.EntId, user.Entniche.DeptName, user.Entniche.DeptId, user.Entniche.UserId, user.Id)
+		logger.Info("无消息提醒任务", taskType, "redis判断今天提醒过,过滤掉", user.Entniche.EntName, user.Entniche.EntId, user.Entniche.DeptId, user.Entniche.UserId, user.Id)
 		return
 	}
 	var start time.Time
@@ -359,7 +183,7 @@ func (n *NoMsgTipJob) tip(taskType int, user *UserInfo) {
 		return
 	}
 	if n.pushCount(user.Entniche.UserId, start.Unix(), now.Unix()) != 0 {
-		logger.Info("无消息提醒任务", taskType, "mysql判断用户该时间段推送过,过滤掉", start.Unix(), now.Unix(), user.Entniche.EntName, user.Entniche.EntId, user.Entniche.DeptName, user.Entniche.DeptId, user.Entniche.UserId, user.Id)
+		logger.Info("无消息提醒任务", taskType, "mysql判断用户该时间段推送过,过滤掉", start.Unix(), now.Unix(), user.Entniche.EntName, user.Entniche.EntId, user.Entniche.DeptId, user.Entniche.UserId, user.Id)
 		return
 	}
 	redis.Put(Pushcache_2_c, NoMsgTipKey(user.Id), 1, OneDaySecond)
@@ -367,27 +191,95 @@ func (n *NoMsgTipJob) tip(taskType int, user *UserInfo) {
 	if endMd := fmt.Sprintf("%d月%d日", now.Month(), now.Day()); startEndMd != endMd {
 		startEndMd += "-" + endMd
 	}
-	logger.Info("无消息提醒任务", taskType, "开始推送", user.Entniche.EntName, user.Entniche.EntId, user.Entniche.DeptName, user.Entniche.DeptId, user.Entniche.UserId, user.Id, "rateMode", user.SubSet.RateMode, "jpushid", user.Jpushid, "opushid", user.Opushid, "appponetype", user.AppPhoneType, "email", user.SubSet.Email)
+	logger.Info("无消息提醒任务", taskType, "开始推送", user.Entniche.EntName, user.Entniche.EntId, user.Entniche.DeptId, user.Entniche.UserId, user.Id, "rateMode", user.SubSet.RateMode, "jpushid", user.Jpushid, "opushid", user.Opushid, "appponetype", user.AppPhoneType, "email", user.SubSet.Email)
 	pushWay := putil.NewPushWay(user)
+	if pushWay.WxPush {
+		logger.Info("无消息提醒任务", taskType, "开始微信推送", user.Id)
+		isPushOk, firstData, advertCode := n.sendWeixin(user, startEndMd, GetUserType(user.Entniche))
+		logger.Info("无消息提醒任务", taskType, "微信推送结束", isPushOk, user.Id, firstData, advertCode)
+	}
 	if pushWay.AppPush {
-		logger.Info("无消息提醒任务", taskType, "开始app推送", user.Entniche.EntName, user.Entniche.EntId, user.Entniche.DeptName, user.Entniche.DeptId, user.Entniche.UserId, user.Id)
+		logger.Info("无消息提醒任务", taskType, "开始app推送", user.Entniche.EntName, user.Entniche.EntId, user.Entniche.DeptId, user.Entniche.UserId, user.Id)
+		url := ""
+		if user.Entniche.MemberStatus == 1 {
+			url = fmt.Sprintf(Config.NoMsgTip.App.Url, "m")
+		} else if user.Entniche.VipStatus == 1 {
+			url = fmt.Sprintf(Config.NoMsgTip.App.Url, "v")
+		} else {
+			url = Config.NoMsgTip.App.EntUrl
+		}
 		isPushOk := putil.SendApp(map[string]interface{}{
 			"phoneType":   user.AppPhoneType,
 			"descript":    fmt.Sprintf(Config.NoMsgTip.App.Descript, startEndMd),
-			"title":       Config.NoMsgTip.App.Title,
+			"title":       fmt.Sprintf(Config.NoMsgTip.App.Title, GetUserType(user.Entniche)),
 			"type":        "entniche_nomsgtip",
 			"userId":      user.Id,
-			"url":         "/jyapp/free/sess/" + Se.EncodeString(user.Id+",_id,"+strconv.Itoa(int(now.Unix()))+",entnichepush") + "__" + fmt.Sprint(now.Unix()) + "__" + util.SE.Encode2HexByCheck(fmt.Sprintf("entniche_%d_%d", user.Entniche.EntId, user.Entniche.UserId)) + "__" + util.SE.Encode2HexByCheck(user.Entniche.EntName) + "__nomsgtip",
+			"url":         "/jyapp/free/sess/" + Se.EncodeString(user.Id+",_id,"+strconv.Itoa(int(now.Unix()))+",") + "__" + Se.EncodeString(url) + "__" + Se.EncodeString(fmt.Sprintf("%d_%d_%s", user.Entniche.EntId, user.Entniche.UserId, user.Entniche.EntName)),
 			"otherPushId": user.Opushid,
 			"jgPushId":    user.Jpushid, //极光-推送id
 		})
-		logger.Info("无消息提醒任务", taskType, "app推送结束", isPushOk, user.Entniche.EntName, user.Entniche.EntId, user.Entniche.DeptName, user.Entniche.DeptId, user.Entniche.UserId, user.Id)
+		logger.Info("无消息提醒任务", taskType, "app推送结束", isPushOk, user.Entniche.EntName, user.Entniche.EntId, user.Entniche.DeptId, user.Entniche.UserId, user.Id)
 	}
 	if pushWay.MailPush {
-		logger.Info("无消息提醒任务", taskType, "开始邮箱推送", user.Entniche.EntName, user.Entniche.EntId, user.Entniche.DeptName, user.Entniche.DeptId, user.Entniche.UserId, user.Id)
+		logger.Info("无消息提醒任务", taskType, "开始邮箱推送", user.Entniche.EntName, user.Entniche.EntId, user.Entniche.DeptId, user.Entniche.UserId, user.Id)
 		isPushOk := VarPush.SendMail(Config.IsPushMail, Config.MailSleep, Gmails, user.SubSet.Email, Config.NoMsgTip.Mail.Title, fmt.Sprintf(Config.NoMsgTip.Mail.Html, Config.JianyuDomain, startEndMd, Config.JianyuDomain, Config.JianyuDomain, Config.JianyuDomain, Config.JianyuDomain, Config.JianyuDomain, Config.JianyuDomain))
-		logger.Info("无消息提醒任务", taskType, "邮箱推送结束", isPushOk, user.Entniche.EntName, user.Entniche.EntId, user.Entniche.DeptName, user.Entniche.DeptId, user.Entniche.UserId, user.Id)
+		logger.Info("无消息提醒任务", taskType, "邮箱推送结束", isPushOk, user.Entniche.EntName, user.Entniche.EntId, user.Entniche.DeptId, user.Entniche.UserId, user.Id)
+	}
+}
+
+//推送微信
+func (n *NoMsgTipJob) sendWeixin(user *UserInfo, startEndMd, userType string) (bool, string, string) {
+	wxtplmsg_area := strings.Join(user.SubSet.Areas, " ")
+	if len([]rune(wxtplmsg_area)) > 10 {
+		wxtplmsg_area = string([]rune(wxtplmsg_area)[:10]) + "..."
+	}
+	if wxtplmsg_area == "" {
+		wxtplmsg_area = "全国"
+	}
+	wxtplmsg_key := strings.Join(user.SubSet.Keys, " ")
+	if len([]rune(wxtplmsg_key)) > 10 {
+		wxtplmsg_key = string([]rune(wxtplmsg_key)[:10]) + "..."
+	}
+	wtmc := putil.WTMCS.Get(Config.NoMsgTip.Wx.First.Value)
+	tmplData := map[string]*qrpc.TmplItem{
+		"first": &qrpc.TmplItem{
+			Value: strings.ReplaceAll(strings.ReplaceAll(wtmc.FirstData, "@动态时间范围", startEndMd), "@用户类型", userType),
+			Color: Config.NoMsgTip.Wx.First.Color,
+		},
+		"keyword1": &qrpc.TmplItem{
+			Value: wxtplmsg_key,
+			Color: Config.NoMsgTip.Wx.Keyword1.Color,
+		},
+		"keyword2": &qrpc.TmplItem{
+			Value: "0条",
+			Color: Config.NoMsgTip.Wx.Keyword2.Color,
+		},
+		"keyword3": &qrpc.TmplItem{
+			Value: wxtplmsg_area,
+			Color: Config.NoMsgTip.Wx.Keyword3.Color,
+		},
+		"keyword4": &qrpc.TmplItem{
+			Value: util.NowFormat(util.Date_Time_Layout),
+			Color: Config.NoMsgTip.Wx.Keyword4.Color,
+		},
+		"remark": &qrpc.TmplItem{
+			Value: "-",
+			Color: Config.NoMsgTip.Wx.Remark.Color,
+		},
+	}
+	url := ""
+	if user.Entniche.MemberStatus == 1 {
+		url = fmt.Sprintf(Config.NoMsgTip.Wx.Url, "member", wtmc.AdvertCode)
+	} else if user.Entniche.VipStatus == 1 {
+		url = fmt.Sprintf(Config.NoMsgTip.Wx.Url, "vip", wtmc.AdvertCode)
 	}
+	ok := putil.SendWeixin(user, &qrpc.WxTmplMsg{
+		OpenId:   user.S_m_openid,
+		TplId:    Config.SubMsgTip.Wx.Id,
+		TmplData: tmplData,
+		Url:      Config.JianyuDomain + "/front/sess/" + Se.EncodeString(user.Id+",_id,"+strconv.Itoa(int(time.Now().Unix()))+",") + "__" + Se.EncodeString(url),
+	})
+	return ok, wtmc.FirstData, wtmc.AdvertCode
 }
 
 //

+ 117 - 46
pushentniche/src/push/job/pushjob.go

@@ -9,9 +9,10 @@ import (
 	. "push/config"
 	. "push/db"
 	. "push/pusher"
-	. "push/util"
+	putil "push/util"
 	. "pusher"
 	"qfw/util"
+	qrpc "qfw/util/rpc"
 	"strconv"
 	"sync"
 	"time"
@@ -43,7 +44,6 @@ func (p *PushJob) Execute(taskType int) {
 		ClearEnt()
 		p.lock.Unlock()
 	}()
-	InitEnt(Mysql, Mgo, DbConf.Mongodb.Main.DbName)
 	p.beforePush(taskType)
 	//每天九点以后,推送每周每月的用户
 	if taskType == 2 {
@@ -75,8 +75,8 @@ func (p *PushJob) StartPush(pusher Pusher, taskType int) {
 	//
 	pushPool := make(chan bool, Config.PushPoolSize)
 	pushWait := &sync.WaitGroup{}
-	hasPushMap := map[string]bool{}
-	hasPushLock := &sync.Mutex{}
+	_, entUserEpu, entEpu, _ := LoadEntProductUsers(Mysql)
+	InitEnt(Mysql, Mgo, DbConf.Mongodb.Main.DbName, Config.TestQuery, entEpu)
 	for {
 		batchIndex++
 		isBreak, users := pusher.OncePushBatch(taskType, batchIndex, &entId, &mId)
@@ -85,7 +85,7 @@ func (p *PushJob) StartPush(pusher Pusher, taskType int) {
 			select {
 			case <-time.After(1 * time.Minute):
 				isTake = false
-				logger.Error("推送任务", taskType, "推送放入通道超时,", temp.Info["entid"], temp.Info["entname"], temp.Info["deptid"], temp.Info["userid"], len(p.minutePushPool), len(p.fastigiumMinutePushPool))
+				logger.Error("推送任务", taskType, "推送放入通道超时,", temp.Info["entid"], temp.Info["entname"], temp.Info["userid"], len(p.minutePushPool), len(p.fastigiumMinutePushPool))
 				go func() {
 					if Config.TimeoutWarn != "" {
 						if _, err := http.Get(Config.TimeoutWarn); err != nil {
@@ -106,38 +106,41 @@ func (p *PushJob) StartPush(pusher Pusher, taskType int) {
 				}()
 				ui := pusher.GetUserInfo(v.Info)
 				delPushResult := &PushResult{PushDate: time.Now().Unix()}
-				if ui == nil || ui.Entniche.UserId == 0 {
-					pusher.AfterPush(delPushResult, v.Ids)
-					return
-				} else if Ents[ui.Entniche.EntId] == nil {
-					logger.Info("没有找到该企业", ui.Entniche.EntId)
-					pusher.AfterPush(delPushResult, v.Ids)
-					return
-				} else if EntUsers[ui.Entniche.UserId] == nil {
-					logger.Error("mysql中没有找到该用户", ui.Entniche.EntName, ui.Entniche.EntId, ui.Entniche.DeptName, ui.Entniche.DeptId, ui.Entniche.UserId)
-					pusher.AfterPush(delPushResult, v.Ids)
-					return
-				} else if EntUsers[ui.Entniche.UserId].Power == 0 {
-					logger.Error("该用户没有权限", ui.Entniche.EntName, ui.Entniche.EntId, ui.Entniche.DeptName, ui.Entniche.DeptId, ui.Entniche.UserId)
+				if ui == nil {
 					pusher.AfterPush(delPushResult, v.Ids)
 					return
 				}
-				ui.Entniche.EntName = Ents[ui.Entniche.EntId].Name
+				if ui.Entniche.MemberStatus == 1 {
+					if entUserEpu[ui.Entniche.UserId] == nil {
+						logger.Info("没有授权大会员,过滤掉", ui.Entniche.EntName, ui.Entniche.EntId, ui.Entniche.UserId)
+						pusher.AfterPush(delPushResult, v.Ids)
+						return
+					}
+				} else if ui.Entniche.VipStatus == 1 {
+					if entUserEpu[ui.Entniche.UserId] == nil {
+						logger.Info("没有授权超级订阅,过滤掉", ui.Entniche.EntName, ui.Entniche.EntId, ui.Entniche.UserId)
+						pusher.AfterPush(delPushResult, v.Ids)
+						return
+					}
+				} else {
+					if Ents[ui.Entniche.EntId] == nil {
+						logger.Info("没有找到该企业,过滤掉", ui.Entniche.EntId)
+						pusher.AfterPush(delPushResult, v.Ids)
+						return
+					} else if EntUsers[ui.Entniche.UserId] == nil {
+						logger.Error("没有找到该员工,过滤掉", ui.Entniche.EntName, ui.Entniche.EntId, ui.Entniche.UserId)
+						pusher.AfterPush(delPushResult, v.Ids)
+						return
+					} else if EntUsers[ui.Entniche.UserId].Power == 0 {
+						logger.Error("该员工没有权限,过滤掉", ui.Entniche.EntName, ui.Entniche.EntId, ui.Entniche.UserId)
+						pusher.AfterPush(delPushResult, v.Ids)
+						return
+					}
+				}
 				//
 				var pushResult *PushResult
-				logger.Info("推送任务", taskType, "开始推送用户", ui.Entniche.EntName, ui.Entniche.EntId, ui.Entniche.DeptName, ui.Entniche.DeptId, "id", ui.Entniche.UserId, "MId", ui.Id, "phone", ui.Phone, "jpushid", ui.Jpushid, "opushid", ui.Opushid, "phoneType", ui.AppPhoneType, "rateMode", ui.SubSet.RateMode, "email", ui.SubSet.Email)
-				//去重 -- start
-				hasPushLock.Lock()
-				exists_key := fmt.Sprintf("%d_%s", ui.Entniche.EntId, ui.Id)
-				if hasPushMap[exists_key] {
-					logger.Info("推送任务", taskType, "过滤掉重复推送用户", ui.Entniche.EntName, ui.Entniche.EntId, ui.Entniche.DeptName, ui.Entniche.DeptId, "id", ui.Entniche.UserId, "MId", ui.Id, "phone", ui.Phone)
-					hasPushLock.Unlock()
-					return
-				}
-				hasPushMap[exists_key] = true
-				hasPushLock.Unlock()
-				//去重 -- end
-				pushWay := NewPushWay(ui)
+				logger.Info("推送任务", taskType, "开始推送用户", ui.Entniche.EntName, ui.Entniche.EntId, "id", ui.Entniche.UserId, "MId", ui.Id, "phone", ui.Phone, "jpushid", ui.Jpushid, "opushid", ui.Opushid, "phoneType", ui.AppPhoneType, "rateMode", ui.SubSet.RateMode, "email", ui.SubSet.Email)
+				pushWay := putil.NewPushWay(ui)
 				pr := p.doPush(pusher, taskType, pushWay, ui, ToSortList(v.Info["list"]), util.IntAll(v.Info["onlypush"]))
 				if pr != nil && pr.PushDate > 0 {
 					pushResult = pr
@@ -167,7 +170,7 @@ func (p *PushJob) doPush(pusher Pusher, taskType int, pushWay *PushWay, u *UserI
 	}
 	pushParam := pusher.GetPushParam(onlypush, pushWay.MailPush, u, sl)
 	if pushParam == nil || pushParam.InfosLength == 0 {
-		logger.Info("推送任务", taskType, "没有要推送的数据!", u.Entniche.EntName, u.Entniche.EntId, u.Entniche.DeptName, u.Entniche.DeptId, u.Entniche.UserId, u.Id)
+		logger.Info("推送任务", taskType, "没有要推送的数据!", u.Entniche.EntName, u.Entniche.EntId, u.Entniche.UserId, u.Id)
 		return
 	}
 	pushResult = &PushResult{
@@ -177,27 +180,39 @@ func (p *PushJob) doPush(pusher Pusher, taskType int, pushWay *PushWay, u *UserI
 	if !pushParam.IsPush {
 		return
 	}
-	logger.Info("推送任务", taskType, "开始进行终端推送", u.Entniche.EntName, u.Entniche.EntId, u.Entniche.DeptName, u.Entniche.DeptId, u.Entniche.UserId, u.Id)
+	logger.Info("推送任务", taskType, "开始进行终端推送", u.Entniche.EntName, u.Entniche.EntId, u.Entniche.UserId, u.Id)
+	if pushWay.WxPush {
+		logger.Info("推送任务", taskType, "开始微信推送", u.ApplyStatus, u.Id)
+		isPushOk := true
+		advertCode, firstData := "", ""
+		if u.ApplyStatus == 1 {
+			//推送微信
+			isPushOk, advertCode, firstData = p.sendWeixin(u, pushParam)
+			if isPushOk {
+				pushResult.WxStatus = 1
+			} else {
+				pushResult.WxStatus = -1
+			}
+		} else {
+			pushResult.WxStatus = 1
+		}
+		logger.Info("推送任务", taskType, "微信推送结束", u.ApplyStatus, isPushOk, u.Id, advertCode, firstData)
+	}
 	if pushWay.AppPush {
-		logger.Info("推送任务", taskType, "开始app推送", u.Entniche.EntName, u.Entniche.EntId, u.Entniche.DeptName, u.Entniche.DeptId, u.Entniche.UserId, u.Id)
+		logger.Info("推送任务", taskType, "开始app推送", u.Entniche.EntName, u.Entniche.EntId, u.Entniche.UserId, u.Id)
 		descriptAppend := ""
 		if pushParam.InfosLength > 1 {
 			descriptAppend = fmt.Sprintf("\n...(共%d条)", pushParam.InfosLength)
 			pushParam.JpushTitle = fmt.Sprintf("1. %s", pushParam.JpushTitle)
 		}
-		url := "/jyapp/free/sess/" + Se.EncodeString(u.Id+",_id,"+strconv.Itoa(int(now.Unix()))+",entnichepush") + "__" + fmt.Sprint(pushParam.PushDate) + "__" + util.SE.Encode2HexByCheck(fmt.Sprintf("entniche_%d_%d", u.Entniche.EntId, u.Entniche.UserId)) + "__" + util.SE.Encode2HexByCheck(u.Entniche.EntName) + "__"
-		if Ents[u.Entniche.EntId] != nil && Ents[u.Entniche.EntId].IsNew == 1 {
-			url += "subscribepush"
-		} else {
-			url += "old_subscribepush"
-		}
-		isPushOk := SendApp(map[string]interface{}{
+		isPushOk := putil.SendApp(map[string]interface{}{
 			"phoneType":      u.AppPhoneType,
+			"title":          fmt.Sprintf(Config.SubMsgTip.App.Title, GetUserType(u.Entniche)),
 			"descript":       pushParam.JpushTitle,
 			"descriptAppend": descriptAppend,
 			"type":           "entnichepush",
 			"userId":         u.Id,
-			"url":            url,
+			"url":            "/jyapp/free/sess/" + Se.EncodeString(u.Id+",_id,"+strconv.Itoa(int(now.Unix()))+",") + "__" + util.SE.Encode2HexByCheck(fmt.Sprintf(Config.SubMsgTip.App.Url, pushParam.PushDate)) + "__" + Se.EncodeString(fmt.Sprintf("%d_%d_%s", u.Entniche.EntId, u.Entniche.UserId, u.Entniche.EntName)),
 			"otherPushId":    u.Opushid,
 			"jgPushId":       u.Jpushid, //极光-推送id
 			"menuName":       "subscribe",
@@ -207,18 +222,74 @@ func (p *PushJob) doPush(pusher Pusher, taskType int, pushWay *PushWay, u *UserI
 		} else {
 			pushResult.AppStatus = -1
 		}
-		logger.Info("推送任务", taskType, "app推送结束", isPushOk, u.Entniche.EntName, u.Entniche.EntId, u.Entniche.DeptName, u.Entniche.DeptId, u.Entniche.UserId, u.Id)
+		logger.Info("推送任务", taskType, "app推送结束", isPushOk, u.Entniche.EntName, u.Entniche.EntId, u.Entniche.UserId, u.Id)
 	}
 	//发送邮件
 	if pushWay.MailPush {
-		logger.Info("推送任务", taskType, "开始邮箱推送", u.Entniche.EntName, u.Entniche.EntId, u.Entniche.DeptName, u.Entniche.DeptId, u.Entniche.UserId, u.Id)
+		logger.Info("推送任务", taskType, "开始邮箱推送", u.Entniche.EntName, u.Entniche.EntId, u.Entniche.UserId, u.Id)
 		isPushOk := VarPush.SendMail(Config.IsPushMail, Config.MailSleep, Gmails, u.SubSet.Email, Config.Mail.Title, pushParam.MailHtml)
 		if isPushOk {
 			pushResult.MailStatus = 1
 		} else {
 			pushResult.MailStatus = -1
 		}
-		logger.Info("推送任务", taskType, "邮箱推送结束", isPushOk, u.Entniche.EntName, u.Entniche.EntId, u.Entniche.DeptName, u.Entniche.DeptId, u.Entniche.UserId, u.Id)
+		logger.Info("推送任务", taskType, "邮箱推送结束", isPushOk, u.Entniche.EntName, u.Entniche.EntId, u.Entniche.UserId, u.Id)
 	}
 	return
 }
+
+//微信远程调用,实现模板发送消息
+func (p *PushJob) sendWeixin(k *UserInfo, pushParam *PushParam) (bool, string, string) {
+	var wtmc *WxTplMsgCustom
+	wtmc = putil.WTMCS.Get(Config.SubMsgTip.Wx.First.Value)
+	if wtmc == nil {
+		logger.Error(k.Id, "没有找到模板消息", Config.SubMsgTip.Wx.First.Value)
+		return false, "", ""
+	}
+	first_color := Config.SubMsgTip.Wx.First.Color
+	remark_value := fmt.Sprintf(Config.SubMsgTip.Wx.Remark_title.Value, GetUserType(k.Entniche))
+	keyword2_value := fmt.Sprintf("%d条", pushParam.InfosLength)
+	keyword1_value, keyword3_value := "", ""
+	if k.WxTplMsg != nil {
+		keyword1_value = k.WxTplMsg.Key
+		keyword3_value = k.WxTplMsg.Area
+		if keyword3_value == "" {
+			keyword3_value = "全国"
+		}
+	}
+	keyword4_value := util.NowFormat(util.Date_Time_Layout)
+	remark_value += WxTplRemark(pushParam.TitleArray, pushParam.LastInfoDate, len([]rune(wtmc.FirstData))+len([]rune(keyword1_value))+len([]rune(keyword2_value))+len([]rune(keyword3_value))+len([]rune(keyword4_value))+len([]rune(remark_value)))
+	tmplData := map[string]*qrpc.TmplItem{
+		"first": &qrpc.TmplItem{
+			Value: wtmc.FirstData,
+			Color: first_color,
+		},
+		"keyword1": &qrpc.TmplItem{
+			Value: keyword1_value,
+			Color: Config.SubMsgTip.Wx.Keyword1.Color,
+		},
+		"keyword2": &qrpc.TmplItem{
+			Value: keyword2_value,
+			Color: Config.SubMsgTip.Wx.Keyword2.Color,
+		},
+		"keyword3": &qrpc.TmplItem{
+			Value: keyword3_value,
+			Color: Config.SubMsgTip.Wx.Keyword3.Color,
+		},
+		"keyword4": &qrpc.TmplItem{
+			Value: keyword4_value,
+			Color: Config.SubMsgTip.Wx.Keyword4.Color,
+		},
+		"remark": &qrpc.TmplItem{
+			Value: remark_value,
+			Color: Config.SubMsgTip.Wx.Remark.Color,
+		},
+	}
+	ok := putil.SendWeixin(k, &qrpc.WxTmplMsg{
+		OpenId:   k.S_m_openid,
+		TplId:    Config.SubMsgTip.Wx.Id,
+		TmplData: tmplData,
+		Url:      Config.JianyuDomain + "/front/sess/" + Se.EncodeString(k.Id+",_id,"+strconv.Itoa(int(time.Now().Unix()))+",") + "__" + Se.EncodeString(fmt.Sprintf(Config.SubMsgTip.Wx.Url, pushParam.PushDate, wtmc.AdvertCode)) + "__" + Se.EncodeString(fmt.Sprintf("%d_%d_%s", k.Entniche.EntId, k.Entniche.UserId, k.Entniche.EntName)),
+	})
+	return ok, wtmc.AdvertCode, wtmc.FirstData
+}

+ 2 - 0
pushentniche/src/push/main.go

@@ -7,6 +7,7 @@ import (
 	. "public"
 	_ "push/db"
 	. "push/job"
+	"push/util"
 
 	"github.com/donnie4w/go-logger/logger"
 )
@@ -15,6 +16,7 @@ func main() {
 	modle := flag.Int("m", 0, "0 定时任务模式推送;1 非定时任务模式推送;2 定时任务模式推送之前先执行-t的任务;3 无消息推送提醒;")
 	taskType := flag.Int("t", 1, "1 一天三次推送;2 九点推送;3 每周;4 每月;5 每周+每月")
 	flag.Parse()
+	util.WTMCS.ForceVerify()
 	logger.SetConsole(false)
 	logger.SetRollingDaily("./logs", "push.log")
 	//

+ 24 - 14
pushentniche/src/push/pusher/normalpush.go

@@ -2,6 +2,7 @@ package pusher
 
 import (
 	. "db"
+	"encoding/json"
 	. "p"
 	. "public"
 	. "push/config"
@@ -68,15 +69,20 @@ func (n *NormalPush) OncePushBatch(taskType, batchIndex int, entId *int, mId *st
 }
 
 func (n *NormalPush) GetUserInfo(m map[string]interface{}) *UserInfo {
+	var wxTplMsg *WxTplMsg
+	wxtplmsg, _ := json.Marshal(m["wxtplmsg"])
+	json.Unmarshal(wxtplmsg, &wxTplMsg)
 	words, _ := m["words"].([]interface{})
 	ui := &UserInfo{
 		Entniche: &Entniche{
-			UserId:  util.IntAll(m["userid"]),
-			EntId:   util.IntAll(m["entid"]),
-			EntName: util.ObjToString(m["entname"]),
-			DisId:   util.ObjToString(m["distributeid"]),
-			DeptId:  util.IntAll(m["deptid"]),
-			Unique:  util.ObjToString(m["unique"]),
+			UserId:       util.IntAll(m["userid"]),
+			EntId:        util.IntAll(m["entid"]),
+			EntName:      util.ObjToString(m["entname"]),
+			DisId:        util.ObjToString(m["distributeid"]),
+			DeptId:       util.IntAll(m["deptid"]),
+			Unique:       util.ObjToString(m["unique"]),
+			VipStatus:    util.IntAll(m["vipstatus"]),
+			MemberStatus: util.IntAll(m["memberstatus"]),
 		},
 		SubSet: &SubSet{
 			Keys:        util.ObjArrToStringArr(words),
@@ -91,6 +97,10 @@ func (n *NormalPush) GetUserInfo(m map[string]interface{}) *UserInfo {
 		AppPhoneType: util.ObjToString(m["appphonetype"]),
 		Opushid:      util.ObjToString(m["opushid"]),
 		Jpushid:      util.ObjToString(m["jpushid"]),
+		ApplyStatus:  util.IntAll(m["applystatus"]),
+		Subscribe:    util.IntAllDef(m["subscribe"], 1),
+		S_m_openid:   util.ObjToString(m["s_m_openid"]),
+		WxTplMsg:     wxTplMsg,
 	}
 	if ui.SubSet.MaxPushSize <= 0 {
 		ui.SubSet.MaxPushSize = Config.MaxPushSize
@@ -135,10 +145,10 @@ func (n *NormalPush) GetPushParam(onlypush int, mailPush bool, u *UserInfo, sl *
 				redis.Put(Pushcache_2_a, PushInfoKey(u.Entniche.UserId, util.ObjToString((*v.Info)["_id"])), 1, OneDaySecond)
 			}
 		} else {
-			logger.Info(u.Entniche.EntName, u.Entniche.EntId, u.Entniche.DeptName, u.Entniche.DeptId, u.Entniche.UserId, u.Id, "商机管理推送保存出错", pushParam.InfosLength)
+			logger.Info(u.Entniche.EntName, u.Entniche.EntId, u.Entniche.UserId, u.Id, "商机管理推送保存出错", pushParam.InfosLength)
 			return pushParam
 		}
-		logger.Info(u.Entniche.EntName, u.Entniche.EntId, u.Entniche.DeptName, u.Entniche.DeptId, u.Entniche.UserId, u.Id, "商机管理推送保存成功", pushParam.PushDate, pushParam.InfosLength)
+		logger.Info(u.Entniche.EntName, u.Entniche.EntId, u.Entniche.UserId, u.Id, "商机管理推送保存成功", pushParam.PushDate, pushParam.InfosLength)
 	}
 	if u.SubSet.RateMode == 3 || u.SubSet.RateMode == 4 {
 		pushParam.IsPush = false
@@ -152,7 +162,7 @@ func (n *NormalPush) GetPushParam(onlypush int, mailPush bool, u *UserInfo, sl *
 //每周 每月推送 暂时保存
 func (n *NormalPush) weekMonthSave(u *UserInfo, pushParam *PushParam) {
 	pLength := len(*pushParam.Infos)
-	logger.Info(u.Entniche.EntName, u.Entniche.EntId, u.Entniche.DeptName, u.Entniche.DeptId, u.Entniche.UserId, u.Id, "每周每月开始保存", pLength)
+	logger.Info(u.Entniche.EntName, u.Entniche.EntId, u.Entniche.UserId, u.Id, "每周每月开始保存", pLength)
 	if pLength == 0 {
 		return
 	}
@@ -188,7 +198,7 @@ func (n *NormalPush) weekMonthSave(u *UserInfo, pushParam *PushParam) {
 			delArray = append(delArray, v["_id"])
 			if len(delArray) == Mgo_BulkSize {
 				if err := MyMgo.DelBulk(Mgo_Log, sess, DbConf.Mongodb.Log.DbName, Pushspace_wait, &delArray); err != nil {
-					logger.Error(u.Entniche.EntName, u.Entniche.EntId, u.Entniche.DeptName, u.Entniche.DeptId, u.Entniche.UserId, u.Id, "每周每月删除出错", err)
+					logger.Error(u.Entniche.EntName, u.Entniche.EntId, u.Entniche.UserId, u.Id, "每周每月删除出错", err)
 				}
 			}
 		}
@@ -210,19 +220,19 @@ func (n *NormalPush) weekMonthSave(u *UserInfo, pushParam *PushParam) {
 		})
 		if len(saveArray) == Mgo_BulkSize {
 			if err := MyMgo.SaveBulk(Mgo_Log, sess, DbConf.Mongodb.Log.DbName, Pushspace_wait, &saveArray); err != nil {
-				logger.Error(u.Entniche.EntName, u.Entniche.EntId, u.Entniche.DeptName, u.Entniche.DeptId, u.Entniche.UserId, u.Id, "每周每月保存出错", err)
+				logger.Error(u.Entniche.EntName, u.Entniche.EntId, u.Entniche.UserId, u.Id, "每周每月保存出错", err)
 			}
 		}
 	})
 	if len(saveArray) > 0 {
 		if err := MyMgo.SaveBulk(Mgo_Log, nil, DbConf.Mongodb.Log.DbName, Pushspace_wait, &saveArray); err != nil {
-			logger.Error(u.Entniche.EntName, u.Entniche.EntId, u.Entniche.DeptName, u.Entniche.DeptId, u.Entniche.UserId, u.Id, "每周每月保存出错", err)
+			logger.Error(u.Entniche.EntName, u.Entniche.EntId, u.Entniche.UserId, u.Id, "每周每月保存出错", err)
 		}
 	}
 	if len(delArray) > 0 {
 		if err := MyMgo.DelBulk(Mgo_Log, nil, DbConf.Mongodb.Log.DbName, Pushspace_wait, &delArray); err != nil {
-			logger.Error(u.Entniche.EntName, u.Entniche.EntId, u.Entniche.DeptName, u.Entniche.DeptId, u.Entniche.UserId, u.Id, "每周每月删除出错", err)
+			logger.Error(u.Entniche.EntName, u.Entniche.EntId, u.Entniche.UserId, u.Id, "每周每月删除出错", err)
 		}
 	}
-	logger.Info(u.Entniche.EntName, u.Entniche.EntId, u.Entniche.DeptName, u.Entniche.DeptId, u.Entniche.UserId, u.Id, "每周每月保存结束", pLength)
+	logger.Info(u.Entniche.EntName, u.Entniche.EntId, u.Entniche.UserId, u.Id, "每周每月保存结束", pLength)
 }

+ 8 - 4
pushentniche/src/push/util/entity.go

@@ -11,7 +11,10 @@ import (
 
 //获取推送方式
 func NewPushWay(u *UserInfo) *PushWay {
-	appPush, mailPush := false, false
+	wxPush, appPush, mailPush := false, false, false
+	if u.SubSet.WxPush == 1 {
+		wxPush = true
+	}
 	if u.SubSet.AppPush == 1 {
 		appPush = true
 	}
@@ -21,14 +24,15 @@ func NewPushWay(u *UserInfo) *PushWay {
 	if u.Jpushid == "" && u.Opushid == "" {
 		appPush = false
 	}
-	if u.SubSet.Email == "" {
-		mailPush = false
+	if u.Subscribe == 0 || u.S_m_openid == "" {
+		wxPush = false
 	}
 	pushWay := &PushWay{
 		AppPush:  appPush,
 		MailPush: mailPush,
+		WxPush:   wxPush,
 	}
-	logger.Info("用户接收方式", u.Entniche.EntName, u.Entniche.EntId, u.Entniche.DeptName, u.Entniche.DeptId, "id", u.Entniche.UserId, "Mid", u.Id, "appPush", pushWay.AppPush, "mailPush", pushWay.MailPush)
+	logger.Info("用户接收方式", u.Entniche.EntName, u.Entniche.EntId, u.Entniche.DeptId, "id", u.Entniche.UserId, "Mid", u.Id, "wxPush", pushWay.WxPush, "appPush", pushWay.AppPush, "mailPush", pushWay.MailPush)
 	return pushWay
 }
 

+ 17 - 0
pushentniche/src/push/util/rpccall.go

@@ -1,15 +1,32 @@
 package util
 
 import (
+	. "p"
 	. "push/config"
+	. "push/db"
 	qrpc "qfw/util/rpc"
 	"time"
 )
 
 var (
+	wxPushPool  = make(chan bool, Config.WxPoolSize)
 	appPushPool = make(chan bool, Config.AppPoolSize)
 )
 
+//微信远程调用,实现模板发送消息
+func SendWeixin(k *UserInfo, wxTmplMsg *qrpc.WxTmplMsg) bool {
+	wxPushPool <- true
+	defer func() {
+		<-wxPushPool
+	}()
+	if Config.WxSleep > 0 {
+		time.Sleep(time.Duration(Config.WxSleep) * time.Millisecond)
+	}
+	ok, err := qrpc.WxSendTmplMsg(Config.WeixinRpcServer, wxTmplMsg)
+	UpdateUserIsPush(Mgo, k.Id, err)
+	return ok
+}
+
 func SendApp(m map[string]interface{}) bool {
 	appPushPool <- true
 	defer func() {

+ 2 - 0
pushentniche/src/push/util/util.go

@@ -10,6 +10,8 @@ import (
 	"github.com/donnie4w/go-logger/logger"
 )
 
+var WTMCS = NewWxTplMsgCustoms(Mysql, Config.SubMsgTip.Wx.Id, Config.SubMsgTip.Wx.First.Value, Config.NoMsgTip.Wx.First.Value)
+
 /*获取一批次推送的数据
  *batchIndex < 0 不走分批次加载
  */

+ 1 - 2
pushmember/src/match/config/config.go

@@ -32,8 +32,7 @@ type config struct {
 }
 
 type taskConfig struct {
-	LastTime string `json:"lastTime"`
-	LastId   string `json:"lastId"`
+	Pici int64 `json:"pici"`
 }
 
 type projectTask struct {

+ 8 - 0
pushmember/src/match/db.json

@@ -36,6 +36,14 @@
 		}
     },
     "mysql": {
+    	"main": {
+	        "dbName": "jianyu",
+	        "address": "192.168.3.11:3366",
+	        "userName": "root",
+	        "passWord": "Topnet123",
+			"maxOpenConns": 5,
+			"maxIdleConns": 5
+	    },
 	    "push": {
 	        "dbName": "base_service",
 	        "address": "192.168.3.217:4000",

+ 16 - 1
pushmember/src/match/db/db.go

@@ -16,6 +16,7 @@ var (
 	Mgo_Bidding *m.MongodbSim
 	Mgo_Log     *m.MongodbSim
 	Mysql       *mysql.Mysql
+	Mysql_Main  *mysql.Mysql
 )
 
 type dbConf struct {
@@ -32,6 +33,7 @@ type dbConf struct {
 		Login *RedisConf
 	}
 	Mysql struct {
+		Main *MysqlConf
 		Push *MysqlConf
 	}
 }
@@ -86,8 +88,21 @@ func init() {
 			Mgo_Log.InitPool()
 		}
 		//
+		if DbConf.Mysql.Main != nil {
+			log.Println("初始化 mysql main")
+			Mysql_Main = &mysql.Mysql{
+				Address:      DbConf.Mysql.Main.Address,
+				UserName:     DbConf.Mysql.Main.UserName,
+				PassWord:     DbConf.Mysql.Main.PassWord,
+				DBName:       DbConf.Mysql.Main.DbName,
+				MaxOpenConns: DbConf.Mysql.Main.MaxOpenConns,
+				MaxIdleConns: DbConf.Mysql.Main.MaxIdleConns,
+			}
+			Mysql_Main.Init()
+		}
+		//
 		if DbConf.Mysql.Push != nil {
-			log.Println("初始化 pushMysql")
+			log.Println("初始化 mysql push")
 			Mysql = &mysql.Mysql{
 				Address:      DbConf.Mysql.Push.Address,
 				UserName:     DbConf.Mysql.Push.UserName,

+ 13 - 14
pushmember/src/match/job/matchjob.go

@@ -10,7 +10,6 @@ import (
 	. "public"
 	"qfw/util"
 	"sort"
-	"strings"
 	"sync"
 	"time"
 
@@ -30,16 +29,18 @@ func (m *MyProjectMatcher) UpSetAppend(u *UserInfo) map[string]interface{} {
 
 type MatchJob struct {
 	relationproject *Match
+	entProductUsers map[string]bool
 }
 
 //定时任务,匹配数据,存库
 func (m *MatchJob) Execute() {
 	defer util.Catch()
-	logger.Info("开始匹配数据任务。。。", TaskConfig.LastId, TaskConfig.LastTime)
-	datas, endId, endTime := LoadBidding(Mgo_Bidding, DbConf.Mongodb.Bidding.DbName, DbConf.Mongodb.Bidding.Collection, TaskConfig.LastId, TaskConfig.LastTime, true)
+	logger.Info("开始匹配数据任务。。。", TaskConfig.Pici)
+	datas, endTime := LoadBidding(Mgo_Bidding, DbConf.Mongodb.Bidding.DbName, DbConf.Mongodb.Bidding.Collection, TaskConfig.Pici, true)
 	if datas == nil || len(*datas) == 0 {
 		return
 	}
+	m.entProductUsers, _, _, _ = LoadEntProductUsers(Mysql_Main)
 	lastUserId := ""
 	batchIndex := 0
 	for {
@@ -56,9 +57,9 @@ func (m *MatchJob) Execute() {
 		}
 	}
 	m.relationproject.AllProject = &sync.Map{}
-	TaskConfig.LastTime = endTime
-	TaskConfig.LastId = endId
-	logger.Info("匹配数据任务结束。。。", TaskConfig.LastId, TaskConfig.LastTime)
+	m.entProductUsers = nil
+	TaskConfig.Pici = endTime
+	logger.Info("匹配数据任务结束。。。", TaskConfig.Pici)
 }
 
 //加载需要推送的用户
@@ -113,6 +114,9 @@ func (m *MatchJob) OnceUserBatch(batchIndex int, lastUserId *string) (int, *PayU
 			} else if user.BaseUserId == 0 {
 				logger.Info("过滤掉,base_user_id不存在", user.Id)
 				return
+			} else if m.entProductUsers[user.Phone] {
+				logger.Info(user.Id, "过滤掉,企业授权产品的用户")
+				return
 			}
 			logger.Info("第", batchIndex, "批用户,userid", user.Id, "jpushid", user.Jpushid, "opushid", user.Opushid, "email", user.SubSet.Email, "rateMode", user.SubSet.RateMode, "apppush", user.SubSet.AppPush, "mailpush", user.SubSet.MailPush, "matchway", user.SubSet.MatchWay, "matchbuyerclass_other", user.SubSet.Matchbuyerclass_other)
 			if len(user.SubSet.Keys) == 0 && user.SubSet.Subtype == nil && user.SubSet.Area == nil && user.SubSet.Buyerclass == nil {
@@ -281,14 +285,7 @@ func (m *MatchJob) ToMatch(batchIndex int, matcher Matcher, datas *[]map[string]
 			if size == 0 {
 				return
 			}
-			wxtplmsg_keyword := strings.Join(user.SubSet.Keys, " ")
-			if len([]rune(wxtplmsg_keyword)) > 10 {
-				wxtplmsg_keyword = string([]rune(wxtplmsg_keyword)[:10]) + "..."
-			}
-			wxtplmsg_area := strings.Join(user.SubSet.Areas, " ")
-			if len([]rune(wxtplmsg_area)) > 10 {
-				wxtplmsg_area = string([]rune(wxtplmsg_area)[:10]) + "..."
-			}
+			wxtplmsg_keyword, wxtplmsg_area := GetWxTplMsg(user.SubSet)
 			lock.Lock()
 			defer lock.Unlock()
 			myMatchId[user.Id] = matchId
@@ -325,6 +322,8 @@ func (m *MatchJob) ToMatch(batchIndex int, matcher Matcher, datas *[]map[string]
 						"wxpush":       u.SubSet.WxPush,
 						"s_m_openid":   u.S_m_openid,
 						"applystatus":  u.ApplyStatus,
+						"subscribe":    u.Subscribe,
+						"phone":        u.Phone,
 						"wxtplmsg": map[string]interface{}{
 							"key":  wxtplmsg_keyword,
 							"area": wxtplmsg_area,

+ 1 - 1
pushmember/src/match/task.json

@@ -1 +1 @@
-{"lastTime":"","lastId":"5f492fed7073b821a8d607f1"}
+{"pici":1599062400}

+ 7 - 0
pushmember/src/public/util.go

@@ -37,6 +37,8 @@ var (
 		"s_member_mainid":     1,
 		"i_member_sub_status": 1,
 		"base_user_id":        1,
+		"s_phone":             1,
+		"s_m_phone":           1,
 	}
 	MyLock = &Lock{
 		Key:   "pushcache_2_b",
@@ -84,11 +86,16 @@ func NewUserInfoByUserColl(temp map[string]interface{}) (user *UserInfo) {
 	appPhoneType := util.ObjToString(temp["s_appponetype"])
 	subSet := GetSubSet(false, userId, o_msgset)
 	subSet.RateMode = util.IntAllDef(o_msgset["i_ratemode"], 1)
+	s_phone := util.ObjToString(temp["s_phone"])
+	if s_phone == "" {
+		s_phone = util.ObjToString(temp["s_m_phone"])
+	}
 	user = &UserInfo{
 		Id:               userId,
 		BaseUserId:       baseUserId,
 		Jpushid:          jpushid,
 		Opushid:          opushid,
+		Phone:            s_phone,
 		AppPhoneType:     appPhoneType,
 		ApplyStatus:      util.IntAll(temp["i_applystatus"]),
 		Subscribe:        util.IntAllDef(temp["i_ispush"], 1),

+ 5 - 3
pushmember/src/push/config.json

@@ -77,10 +77,11 @@
 		"remark":{
 			"color":"#686868"
 		},
-		"url":"/swordfish/newhistorypush?times=%d&advertcode=%s&msg=1&t=member"
+		"url":"/swordfish/newhistorypush?f=push&t=member&pushtime=%d&advertcode=%s"
 	},
 	"appMsg":{
-		"title":"亲爱的大会员用户:您有新的订阅信息啦,快来查看吧!"
+		"title":"亲爱的大会员用户:您有新的订阅信息啦,快来查看吧!",
+		"url":"/jyapp/swordfish/historypush?f=push&t=member&pushtime=%d"
 	},
 	"noMsgTip":{
 		"available":true,
@@ -110,7 +111,8 @@
 		},
 		"app":{
 			"title":"剑鱼推送消息!",
-			"descript":"亲爱的大会员用户,根据您当前的订阅,%s剑鱼标讯未能匹配到您需要的招标信息,请检查您的订阅是否需要进行优化,如需获取帮助,可点击“我的”页面内的使用帮助按钮,或者联系剑鱼标讯客服。"
+			"descript":"亲爱的大会员用户,根据您当前的订阅,%s剑鱼标讯未能匹配到您需要的招标信息,请检查您的订阅是否需要进行优化,如需获取帮助,可点击“我的”页面内的使用帮助按钮,或者联系剑鱼标讯客服。",
+			"url":"/jyapp/vipsubscribe/toSubVipSetPage?vSwitch=m"
 		},
 		"mail":{
 			"title":"剑鱼推送消息!",

+ 2 - 0
pushmember/src/push/config/config.go

@@ -61,6 +61,7 @@ type config struct {
 	} `json:"wxTplMsg"`
 	AppMsg struct {
 		Title string `json:"title"`
+		Url   string `json:"url"`
 	} `json:"appMsg"`
 	NoMsgTip struct {
 		Available           bool `json:"available"`
@@ -78,6 +79,7 @@ type config struct {
 		App struct {
 			Title    string `json:"title"`
 			Descript string `json:"descript"`
+			Url      string `json:"url"`
 		} `json:"app"`
 		Mail struct {
 			Title string `json:"title"`

+ 7 - 2
pushmember/src/push/job/nomsgtipjob.go

@@ -57,6 +57,7 @@ func (n *NoMsgTipJob) Execute(taskType int) {
 	it := sess.DB(DbConf.Mongodb.Main.DbName).C(Mgo_User).Find(query).Select(UserCollFields).Iter()
 	pushPool := make(chan bool, Config.PushPoolSize)
 	pushWait := &sync.WaitGroup{}
+	entProductUsers, _, _, _ := LoadEntProductUsers(Mysql_Main)
 	for temp := make(map[string]interface{}); it.Next(&temp); {
 		isTake := true
 		select {
@@ -85,6 +86,10 @@ func (n *NoMsgTipJob) Execute(taskType int) {
 			if user == nil {
 				return
 			}
+			if entProductUsers[user.Phone] {
+				logger.Info("无消息提醒任务", taskType, "企业授权产品的用户不推送", user.Id)
+				return
+			}
 			if user.SonAccountStatus == 1 {
 				if user.MemberMainid == "" {
 					return
@@ -172,7 +177,7 @@ func (n *NoMsgTipJob) tip(taskType int, user *UserInfo) {
 			"title":       Config.NoMsgTip.App.Title,
 			"type":        "member_nomsgtip",
 			"userId":      user.Id,
-			"url":         "/jyapp/free/sess/" + Se.EncodeString(user.Id+",_id,"+strconv.Itoa(int(now.Unix()))+",viphomepage") + "__m",
+			"url":         "/jyapp/free/sess/" + Se.EncodeString(user.Id+",_id,"+strconv.Itoa(int(now.Unix()))+",") + "__" + Se.EncodeString(Config.NoMsgTip.App.Url),
 			"otherPushId": user.Opushid,
 			"jgPushId":    user.Jpushid, //极光-推送id
 		})
@@ -229,7 +234,7 @@ func (n *NoMsgTipJob) sendWeixin(user *UserInfo, startEndMd, userType string) (b
 		OpenId:   user.S_m_openid,
 		TplId:    Config.WxTplMsg.Id,
 		TmplData: tmplData,
-		Url:      Config.JianyuDomain + "/front/sess/" + Se.EncodeString(user.S_m_openid+",uid,"+strconv.Itoa(int(time.Now().Unix()))+",") + "__" + Se.EncodeString(fmt.Sprintf(Config.NoMsgTip.Wx.Url, wtmc.AdvertCode)),
+		Url:      Config.JianyuDomain + "/front/sess/" + Se.EncodeString(user.Id+",_id,"+strconv.Itoa(int(time.Now().Unix()))+",") + "__" + Se.EncodeString(fmt.Sprintf(Config.NoMsgTip.Wx.Url, wtmc.AdvertCode)),
 	})
 	return ok, wtmc.FirstData, wtmc.AdvertCode
 }

+ 7 - 2
pushmember/src/push/job/pushjob.go

@@ -70,6 +70,7 @@ func (p *PushJob) StartPush(pusher Pusher, taskType int) {
 	//
 	pushPool := make(chan bool, Config.PushPoolSize)
 	pushWait := &sync.WaitGroup{}
+	entProductUsers, _, _, _ := LoadEntProductUsers(Mysql_Main)
 	for {
 		batchIndex++
 		isBreak, users := pusher.OncePushBatch(taskType, batchIndex, &startId)
@@ -101,6 +102,10 @@ func (p *PushJob) StartPush(pusher Pusher, taskType int) {
 				if u == nil || pushWay == nil {
 					pusher.AfterPush(&PushResult{PushDate: time.Now().Unix()}, v.Ids)
 					return
+				} else if entProductUsers[u.Phone] {
+					pusher.AfterPush(&PushResult{PushDate: time.Now().Unix()}, v.Ids)
+					logger.Info(u.Id, "过滤掉,企业授权产品的用户")
+					return
 				}
 				logger.Info("推送任务", taskType, "开始推送用户", "userId", u.Id, "s_m_openid", u.S_m_openid, "subscribe", u.Subscribe, "applystatus", u.ApplyStatus, "jpushid", u.Jpushid, "opushid", u.Opushid, "phoneType", u.AppPhoneType, "rateMode", u.SubSet.RateMode, "email", u.SubSet.Email)
 				pushResult := p.doPush(pusher, taskType, pushWay, u, ToSortList(v.Info["list"]))
@@ -178,7 +183,7 @@ func (p *PushJob) doPush(pusher Pusher, taskType int, pushWay *PushWay, u *UserI
 			"title":          Config.AppMsg.Title,
 			"type":           "bid",
 			"userId":         u.Id,
-			"url":            "/jyapp/free/sess/" + Se.EncodeString(u.Id+",_id,"+strconv.Itoa(int(now.Unix()))+",historypush") + "__member__" + fmt.Sprint(pushParam.PushDate),
+			"url":            "/jyapp/free/sess/" + Se.EncodeString(u.Id+",_id,"+strconv.Itoa(int(now.Unix()))+",") + "__" + Se.EncodeString(fmt.Sprintf(Config.AppMsg.Url, pushParam.PushDate)),
 			"otherPushId":    u.Opushid,
 			"jgPushId":       u.Jpushid, //极光-推送id
 		})
@@ -254,7 +259,7 @@ func (p *PushJob) sendWeixin(k *UserInfo, pushParam *PushParam) (bool, string, s
 		OpenId:   k.S_m_openid,
 		TplId:    Config.WxTplMsg.Id,
 		TmplData: tmplData,
-		Url:      Config.JianyuDomain + "/front/sess/" + Se.EncodeString(k.S_m_openid+",uid,"+strconv.Itoa(int(time.Now().Unix()))+",") + "__" + Se.EncodeString(fmt.Sprintf(Config.WxTplMsg.Url, pushParam.PushDate, wtmc.AdvertCode)),
+		Url:      Config.JianyuDomain + "/front/sess/" + Se.EncodeString(k.Id+",_id,"+strconv.Itoa(int(time.Now().Unix()))+",") + "__" + Se.EncodeString(fmt.Sprintf(Config.WxTplMsg.Url, pushParam.PushDate, wtmc.AdvertCode)),
 	})
 	return ok, wtmc.AdvertCode, wtmc.FirstData
 }

+ 1 - 0
pushmember/src/push/util/util.go

@@ -32,6 +32,7 @@ func NewUserInfoByPushSpaceColl(user map[string]interface{}) *UserInfo {
 		S_m_openid:   util.ObjToString(user["s_m_openid"]),
 		Jpushid:      util.ObjToString(user["jpushid"]),
 		Opushid:      util.ObjToString(user["opushid"]),
+		Phone:        util.ObjToString(user["phone"]),
 		AppPhoneType: util.ObjToString(user["appphonetype"]),
 		ApplyStatus:  util.IntAll(user["applystatus"]),
 		Subscribe:    util.IntAllDef(user["subscribe"], 1),

+ 1 - 2
pushsubscribe/src/match/config/config.go

@@ -33,8 +33,7 @@ type config struct {
 }
 
 type taskConfig struct {
-	LastTime string `json:"lastTime"`
-	LastId   string `json:"lastId"`
+	Pici int64 `json:"pici"`
 }
 
 type projectTask struct {

+ 8 - 0
pushsubscribe/src/match/db.json

@@ -36,6 +36,14 @@
 		}
     },
     "mysql": {
+    	"main": {
+	        "dbName": "jianyu",
+	        "address": "192.168.3.11:3366",
+	        "userName": "root",
+	        "passWord": "Topnet123",
+			"maxOpenConns": 5,
+			"maxIdleConns": 5
+	    },
 	    "push": {
 	        "dbName": "base_service",
 	        "address": "192.168.3.217:4000",

+ 16 - 1
pushsubscribe/src/match/db/db.go

@@ -16,6 +16,7 @@ var (
 	Mgo_Bidding *m.MongodbSim
 	Mgo_Log     *m.MongodbSim
 	Mysql       *mysql.Mysql
+	Mysql_Main  *mysql.Mysql
 )
 
 type dbConf struct {
@@ -32,6 +33,7 @@ type dbConf struct {
 		Login *RedisConf
 	}
 	Mysql struct {
+		Main *MysqlConf
 		Push *MysqlConf
 	}
 }
@@ -86,8 +88,21 @@ func init() {
 			Mgo_Log.InitPool()
 		}
 		//
+		if DbConf.Mysql.Main != nil {
+			log.Println("初始化 mysql main")
+			Mysql_Main = &mysql.Mysql{
+				Address:      DbConf.Mysql.Main.Address,
+				UserName:     DbConf.Mysql.Main.UserName,
+				PassWord:     DbConf.Mysql.Main.PassWord,
+				DBName:       DbConf.Mysql.Main.DbName,
+				MaxOpenConns: DbConf.Mysql.Main.MaxOpenConns,
+				MaxIdleConns: DbConf.Mysql.Main.MaxIdleConns,
+			}
+			Mysql_Main.Init()
+		}
+		//
 		if DbConf.Mysql.Push != nil {
-			log.Println("初始化 pushMysql")
+			log.Println("初始化 mysql push")
 			Mysql = &mysql.Mysql{
 				Address:      DbConf.Mysql.Push.Address,
 				UserName:     DbConf.Mysql.Push.UserName,

+ 20 - 14
pushsubscribe/src/match/job/matchjob.go

@@ -11,7 +11,6 @@ import (
 	. "public"
 	"qfw/util"
 	"sort"
-	"strings"
 	"sync"
 	"time"
 
@@ -31,16 +30,20 @@ func (m *MyProjectMatcher) UpSetAppend(u *UserInfo) map[string]interface{} {
 
 type MatchJob struct {
 	relationproject *Match
+	entnicheUsers   map[string]bool
+	entProductUsers map[string]bool
 }
 
 //定时任务,匹配数据,存库
 func (m *MatchJob) Execute() {
 	defer util.Catch()
-	logger.Info("开始匹配数据任务。。。", TaskConfig.LastId, TaskConfig.LastTime)
-	datas, endId, endTime := LoadBidding(Mgo_Bidding, DbConf.Mongodb.Bidding.DbName, DbConf.Mongodb.Bidding.Collection, TaskConfig.LastId, TaskConfig.LastTime, true)
+	logger.Info("开始匹配数据任务。。。", TaskConfig.Pici)
+	datas, endTime := LoadBidding(Mgo_Bidding, DbConf.Mongodb.Bidding.DbName, DbConf.Mongodb.Bidding.Collection, TaskConfig.Pici, true)
 	if datas == nil || len(*datas) == 0 {
 		return
 	}
+	m.entnicheUsers = LoadEntnicheUsers(Mysql_Main)
+	m.entProductUsers, _, _, _ = LoadEntProductUsers(Mysql_Main)
 	lastUserId := ""
 	batchIndex := 0
 	for {
@@ -60,9 +63,10 @@ func (m *MatchJob) Execute() {
 		}
 	}
 	m.relationproject.AllProject = &sync.Map{}
-	TaskConfig.LastTime = endTime
-	TaskConfig.LastId = endId
-	logger.Info("匹配数据任务结束。。。", TaskConfig.LastId, TaskConfig.LastTime)
+	m.entnicheUsers = nil
+	m.entProductUsers = nil
+	TaskConfig.Pici = endTime
+	logger.Info("匹配数据任务结束。。。", TaskConfig.Pici)
 }
 
 //加载需要推送的用户
@@ -115,6 +119,15 @@ func (m *MatchJob) OnceUserBatch(batchIndex int, lastUserId *string) (int, *PayU
 			} else if user.BaseUserId == 0 {
 				logger.Info(user.Id, "过滤掉,base_user_id不存在")
 				return
+			} else if user.MemberStatus > 0 && user.VipStatus <= 0 {
+				logger.Info(user.Id, "过滤掉,大会员用户")
+				return
+			} else if m.entnicheUsers[user.Phone] && user.VipStatus <= 0 {
+				logger.Info(user.Id, "过滤掉,商机管理用户")
+				return
+			} else if m.entProductUsers[user.Phone] {
+				logger.Info(user.Id, "过滤掉,企业授权产品的用户")
+				return
 			}
 			isVipUser := IsVipUser(user.VipStatus)
 			if !isVipUser && len(user.SubSet.Keys) == 0 {
@@ -299,14 +312,7 @@ func (m *MatchJob) ToMatch(batchIndex int, matcher Matcher, datas *[]map[string]
 			if size == 0 {
 				return
 			}
-			wxtplmsg_keyword := strings.Join(user.SubSet.Keys, " ")
-			if len([]rune(wxtplmsg_keyword)) > 10 {
-				wxtplmsg_keyword = string([]rune(wxtplmsg_keyword)[:10]) + "..."
-			}
-			wxtplmsg_area := strings.Join(user.SubSet.Areas, " ")
-			if len([]rune(wxtplmsg_area)) > 10 {
-				wxtplmsg_area = string([]rune(wxtplmsg_area)[:10]) + "..."
-			}
+			wxtplmsg_keyword, wxtplmsg_area := GetWxTplMsg(user.SubSet)
 			lock.Lock()
 			defer lock.Unlock()
 			myMatchId[user.Id] = matchId

+ 1 - 1
pushsubscribe/src/match/task.json

@@ -1 +1 @@
-{"lastTime":"","lastId":"5f492fed7073b821a8d607f1"}	
+{"pici":1599062400}

+ 0 - 16
pushsubscribe/src/public/util.go

@@ -36,8 +36,6 @@ var (
 		"i_ispush":        1,
 		"s_appponetype":   1,
 		"i_applystatus":   1,
-		"a_mergeorder":    1,
-		"s_nickname":      1,
 		"i_member_status": 1,
 		"base_user_id":    1,
 	}
@@ -265,19 +263,5 @@ func SaveToMysql(mysql *Mysql, savePool chan bool, saveSleep int, isVipUser, isP
 		allCache.Count = allCache.Count + int64(len(subPush_datas))
 		jy.NewSubscribePush().PutAllCache(u.Id, allCache)
 	}
-	//最近7天50条redis缓存处理
-	sevenDayCache, err := jy.NewSubscribePush().GetSevenDayCache(u.Id)
-	if err == nil && sevenDayCache != nil && len(sevenDayCache) > 0 {
-		new_sevenDayCache := subPush_datas[:]
-		for _, v := range sevenDayCache {
-			if v != nil && v.Ca_date > unix-SevenDay {
-				new_sevenDayCache = append(new_sevenDayCache, v)
-			}
-		}
-		if len(new_sevenDayCache) > 50 {
-			new_sevenDayCache = new_sevenDayCache[:50]
-		}
-		jy.NewSubscribePush().PutSevenDayCache(u.Id, new_sevenDayCache)
-	}
 	return unix
 }

+ 10 - 3
pushsubscribe/src/push/config.json

@@ -94,7 +94,12 @@
 		},
 		"remark":{
 			"color":"#686868"
-		}
+		},
+		"url":"/swordfish/newhistorypush?f=push&t=%s&pushtime=%d&advertcode=%s"
+	},
+	"appMsg":{
+		"title":"剑鱼推送消息!",
+		"url":"/jyapp/swordfish/historypush?f=push&t=%s&pushtime=%d"
 	},
 	"timeoutWarn":"http://172.17.4.195:19281/_send/_mail?program=pushsubscribe_push&to=wangchuanjin@topnet.net.cn&title=订阅推送程序报警&body=放入通道超时",
 	"noMsgTip":{
@@ -121,11 +126,13 @@
 			},
 			"remark":{
 				"color":"#686868"
-			}
+			},
+			"url":"/front/vipsubscribe/toSubVipSetPage?vSwitch=%s&advertcode=%s"
 		},
 		"app":{
 			"title":"剑鱼推送消息!",
-			"descript":"亲爱的%s用户,根据您当前的订阅,%s剑鱼标讯未能匹配到您需要的招标信息,请检查您的订阅是否需要进行优化,如需获取帮助,可点击“我的”页面内的使用帮助按钮,或者联系剑鱼标讯客服。"
+			"descript":"亲爱的%s用户,根据您当前的订阅,%s剑鱼标讯未能匹配到您需要的招标信息,请检查您的订阅是否需要进行优化,如需获取帮助,可点击“我的”页面内的使用帮助按钮,或者联系剑鱼标讯客服。",
+			"url":"/jyapp/vipsubscribe/toSubVipSetPage?vSwitch=%s"
 		},
 		"mail":{
 			"title":"剑鱼推送消息!",

+ 7 - 0
pushsubscribe/src/push/config/config.go

@@ -62,7 +62,12 @@ type config struct {
 		Remark_title     *qrpc.TmplItem
 		Vip_remark_title *qrpc.TmplItem
 		Remark           *qrpc.TmplItem
+		Url              string
 	} `json:"wxTplMsg"`
+	AppMsg struct {
+		Title string `json:"title"`
+		Url   string `json:"url"`
+	} `json:"appMsg"`
 	NoMsgTip struct {
 		Available              bool `json:"available"`
 		CheckMaxPushPersion    int  `json:"checkMaxPushPersion"`
@@ -75,10 +80,12 @@ type config struct {
 			Keyword3 *qrpc.TmplItem
 			Keyword4 *qrpc.TmplItem
 			Remark   *qrpc.TmplItem
+			Url      string
 		} `json:"wx"`
 		App struct {
 			Title    string `json:"title"`
 			Descript string `json:"descript"`
+			Url      string `json:"url"`
 		} `json:"app"`
 		Mail struct {
 			Title string `json:"title"`

+ 37 - 24
pushsubscribe/src/push/job/nomsgtipjob.go

@@ -112,8 +112,9 @@ func (n *NoMsgTipJob) Execute(taskType int) {
 	pushWait := &sync.WaitGroup{}
 	entnicheUsers := map[string]bool{}
 	if taskType == 1 || taskType == 6 {
-		entnicheUsers = putil.LoadEntnicheUsers()
+		entnicheUsers = LoadEntnicheUsers(Mysql_Main)
 	}
+	entProductUsers, _, _, _ := LoadEntProductUsers(Mysql_Main)
 	for temp := make(map[string]interface{}); it.Next(&temp); {
 		isTake := true
 		select {
@@ -145,12 +146,22 @@ func (n *NoMsgTipJob) Execute(taskType int) {
 			if len(user.SubSet.Keys) == 0 {
 				logger.Info("无消息提醒任务", taskType, "没有订阅词,过滤掉", user.Id)
 				return
+			} else if user.MemberStatus > 0 && user.VipStatus <= 0 {
+				logger.Info("无消息提醒任务", taskType, "大会员用户,免费订阅不推送", user.Id)
+				return
+			} else if entProductUsers[user.Phone] {
+				logger.Info("无消息提醒任务", taskType, "企业授权产品的用户不推送", user.Id)
+				return
 			}
 			if taskType == 1 || (user.VipStatus <= 0 && taskType == 6) {
-				n.tip(taskType, user, entnicheUsers[user.Phone])
+				if entnicheUsers[user.Phone] && user.VipStatus <= 0 {
+					logger.Info("无消息提醒任务", taskType, "商机管理用户,免费订阅不推送", user.Id)
+					return
+				}
+				n.tip(taskType, user)
 			} else if user.VipStatus > 0 && (((taskType == 7 || taskType == 8) && user.SubSet.RateMode == 1) || (taskType == 2 && user.SubSet.RateMode == 2) || (taskType == 3 && user.SubSet.RateMode == 3) ||
 				(taskType == 4 && user.SubSet.RateMode == 4) || (taskType == 5 && (user.SubSet.RateMode == 3 || user.SubSet.RateMode == 4)) || (taskType == 9 && user.SubSet.RateMode == 5)) {
-				n.tip(taskType, user, false)
+				n.tip(taskType, user)
 			}
 		}(temp, isTake)
 		temp = make(map[string]interface{})
@@ -160,7 +171,7 @@ func (n *NoMsgTipJob) Execute(taskType int) {
 }
 
 //提醒
-func (n *NoMsgTipJob) tip(taskType int, user *UserInfo, isEntnicheUser bool) {
+func (n *NoMsgTipJob) tip(taskType int, user *UserInfo) {
 	if exists, err := redis.Exists(Pushcache_2_c, HasPushKey(user.Id)); err != nil {
 		logger.Error("无消息提醒任务", taskType, "redis判断今天是否推送过出错", err, user.Id)
 		return
@@ -219,27 +230,23 @@ func (n *NoMsgTipJob) tip(taskType int, user *UserInfo, isEntnicheUser bool) {
 	pushWay := putil.NewPushWay(user)
 	if pushWay.AppPush {
 		logger.Info("无消息提醒任务", taskType, "开始app推送", user.Id)
-		if user.MemberStatus > 0 && user.VipStatus <= 0 {
-			logger.Info("无消息提醒任务", taskType, "大会员用户,免费订阅不进行app推送", user.Id)
-		} else if isEntnicheUser && user.VipStatus <= 0 {
-			logger.Info("无消息提醒任务", taskType, "商机管理用户,免费订阅不进行app推送", user.Id)
+		url := ""
+		if user.VipStatus > 0 {
+			url = fmt.Sprintf(Config.NoMsgTip.App.Url, "v")
 		} else {
-			url := "/jyapp/free/sess/" + Se.EncodeString(user.Id+",_id,"+strconv.Itoa(int(now.Unix()))+",viphomepage")
-			if user.VipStatus > 0 {
-				url += "__v"
-			}
-			isPushOk := putil.SendApp(map[string]interface{}{
-				"phoneType":   user.AppPhoneType,
-				"descript":    fmt.Sprintf(Config.NoMsgTip.App.Descript, userType, startEndMd),
-				"title":       Config.NoMsgTip.App.Title,
-				"type":        "nomsgtip",
-				"userId":      user.Id,
-				"url":         url,
-				"otherPushId": user.Opushid,
-				"jgPushId":    user.Jpushid, //极光-推送id
-			})
-			logger.Info("无消息提醒任务", taskType, "app推送结束", isPushOk, user.Id)
+			url = fmt.Sprintf(Config.NoMsgTip.App.Url, "")
 		}
+		isPushOk := putil.SendApp(map[string]interface{}{
+			"phoneType":   user.AppPhoneType,
+			"descript":    fmt.Sprintf(Config.NoMsgTip.App.Descript, userType, startEndMd),
+			"title":       Config.NoMsgTip.App.Title,
+			"type":        "nomsgtip",
+			"userId":      user.Id,
+			"url":         "/jyapp/free/sess/" + Se.EncodeString(user.Id+",_id,"+strconv.Itoa(int(now.Unix()))+",") + "__" + Se.EncodeString(url),
+			"otherPushId": user.Opushid,
+			"jgPushId":    user.Jpushid, //极光-推送id
+		})
+		logger.Info("无消息提醒任务", taskType, "app推送结束", isPushOk, user.Id)
 	}
 	if pushWay.WxPush {
 		logger.Info("无消息提醒任务", taskType, "开始微信推送", user.Id)
@@ -293,11 +300,17 @@ func (n *NoMsgTipJob) sendWeixin(user *UserInfo, startEndMd, userType string) (b
 			Color: Config.NoMsgTip.Wx.Remark.Color,
 		},
 	}
+	url := ""
+	if user.VipStatus > 0 {
+		url = fmt.Sprintf(Config.NoMsgTip.Wx.Url, "v", wtmc.AdvertCode)
+	} else {
+		url = fmt.Sprintf(Config.NoMsgTip.Wx.Url, "", wtmc.AdvertCode)
+	}
 	ok := putil.SendWeixin(user, &qrpc.WxTmplMsg{
 		OpenId:   user.S_m_openid,
 		TplId:    Config.WxTplMsg.Id,
 		TmplData: tmplData,
-		Url:      Config.JianyuDomain + "/front/sess/" + Se.EncodeString(user.S_m_openid+",uid,"+strconv.Itoa(int(time.Now().Unix()))+",toSubVipSetPage") + "__" + wtmc.AdvertCode,
+		Url:      Config.JianyuDomain + "/front/sess/" + Se.EncodeString(user.Id+",_id,"+strconv.Itoa(int(time.Now().Unix()))+",") + "__" + Se.EncodeString(url),
 	})
 	return ok, wtmc.FirstData, wtmc.AdvertCode
 }

+ 42 - 46
pushsubscribe/src/push/job/pushjob.go

@@ -86,8 +86,9 @@ func (p *PushJob) StartPush(pusher Pusher, taskType int) {
 	pushWait := &sync.WaitGroup{}
 	entnicheUsers := map[string]bool{}
 	if taskType == 1 || taskType == 6 {
-		entnicheUsers = putil.LoadEntnicheUsers()
+		entnicheUsers = LoadEntnicheUsers(Mysql_Main)
 	}
+	entProductUsers, _, _, _ := LoadEntProductUsers(Mysql_Main)
 	for {
 		batchIndex++
 		isBreak, users := pusher.OncePushBatch(taskType, batchIndex, &startId)
@@ -119,14 +120,20 @@ func (p *PushJob) StartPush(pusher Pusher, taskType int) {
 				if u == nil || pushWay == nil {
 					pusher.AfterPush(&PushResult{PushDate: time.Now().Unix()}, v.Ids)
 					return
-				}
-				if taskType == 7 && !((u.UserType == 0 || u.UserType == 5) && (u.SubSet.WxPush == 1 || u.SubSet.MailPush == 1)) {
+				} else if entProductUsers[u.Phone] {
+					pusher.AfterPush(&PushResult{PushDate: time.Now().Unix()}, v.Ids)
+					logger.Info("推送任务", taskType, "过滤掉,企业授权产品的用户", u.Id)
 					return
-				}
-				if taskType == 8 && !(u.UserType == 1 || u.UserType == 2 || ((u.UserType == 0 || u.UserType == 5) && !(u.SubSet.WxPush == 1) && !(u.SubSet.MailPush == 1) && u.SubSet.AppPush == 1)) {
+				} else if (taskType == 1 || taskType == 6) && entnicheUsers[u.Phone] && u.VipStatus <= 0 {
+					pusher.AfterPush(&PushResult{PushDate: time.Now().Unix()}, v.Ids)
+					logger.Info("推送任务", taskType, "过滤掉,商机管理用户", u.Id)
+					return
+				} else if taskType == 7 && u.S_m_openid == "" {
+					return
+				} else if taskType == 8 && u.S_m_openid != "" {
 					return
 				}
-				logger.Info("推送任务", taskType, "开始推送用户", "userType", u.UserType, "userId", u.Id, "s_m_openid", u.S_m_openid, "a_m_openid", u.A_m_openid, "phone", u.Phone, "subscribe", u.Subscribe, "applystatus", u.ApplyStatus, "jpushid", u.Jpushid, "opushid", u.Opushid, "phoneType", u.AppPhoneType, "rateMode", u.SubSet.RateMode, "email", u.SubSet.Email, "vipStatus", u.VipStatus)
+				logger.Info("推送任务", taskType, "开始推送用户", "userId", u.Id, "s_m_openid", u.S_m_openid, "a_m_openid", u.A_m_openid, "phone", u.Phone, "subscribe", u.Subscribe, "applystatus", u.ApplyStatus, "jpushid", u.Jpushid, "opushid", u.Opushid, "phoneType", u.AppPhoneType, "rateMode", u.SubSet.RateMode, "email", u.SubSet.Email, "vipStatus", u.VipStatus)
 				pcHelperKeys := []string{}
 				if u.S_m_openid != "" {
 					if _, ok := p.PcHelperAllOnLine.Load(u.S_m_openid); ok {
@@ -139,11 +146,7 @@ func (p *PushJob) StartPush(pusher Pusher, taskType int) {
 					}
 				}
 				if IsVipUser(u.VipStatus) || pushWay.WxPush || pushWay.AppPush || pushWay.MailPush || len(pcHelperKeys) > 0 {
-					isEntnicheUser := false
-					if taskType == 1 || taskType == 6 {
-						isEntnicheUser = entnicheUsers[u.Phone]
-					}
-					pushResult := p.doPush(pusher, taskType, pushWay, u, ToSortList(v.Info["list"]), pcHelperKeys, isEntnicheUser)
+					pushResult := p.doPush(pusher, taskType, pushWay, u, ToSortList(v.Info["list"]), pcHelperKeys)
 					pusher.AfterPush(pushResult, v.Ids)
 				} else {
 					pusher.AfterPush(&PushResult{PushDate: time.Now().Unix()}, v.Ids)
@@ -159,7 +162,7 @@ func (p *PushJob) StartPush(pusher Pusher, taskType int) {
 }
 
 //进入具体推送
-func (p *PushJob) doPush(pusher Pusher, taskType int, pushWay *PushWay, u *UserInfo, sl *SortList, pcHelperKeys []string, isEntnicheUser bool) (pushResult *PushResult) {
+func (p *PushJob) doPush(pusher Pusher, taskType int, pushWay *PushWay, u *UserInfo, sl *SortList, pcHelperKeys []string) (pushResult *PushResult) {
 	defer util.Catch()
 	now := time.Now()
 	//限制一分钟最大的推送数量
@@ -208,42 +211,35 @@ func (p *PushJob) doPush(pusher Pusher, taskType int, pushWay *PushWay, u *UserI
 	}
 	if pushWay.AppPush {
 		logger.Info("推送任务", taskType, "开始app推送", u.Id)
-		if u.MemberStatus > 0 && u.VipStatus <= 0 {
-			pushResult.AppStatus = 1
-			logger.Info("推送任务", taskType, "大会员用户,免费订阅不进行app推送", u.Id)
-		} else if isEntnicheUser && u.VipStatus <= 0 {
+		descriptAppend := ""
+		if pushParam.InfosLength > 1 {
+			descriptAppend = fmt.Sprintf("\n...(共%d条)", pushParam.InfosLength)
+			pushParam.JpushTitle = fmt.Sprintf("1. %s", pushParam.JpushTitle)
+		}
+		go Mgo.Update(Mgo_User, map[string]interface{}{
+			"_id": StringTOBsonId(u.Id),
+		}, map[string]interface{}{
+			"$inc": map[string]interface{}{
+				"i_apppushunread": 1,
+			},
+		}, false, false)
+		isPushOk := putil.SendApp(map[string]interface{}{
+			"title":          Config.AppMsg.Title,
+			"phoneType":      u.AppPhoneType,
+			"descript":       pushParam.JpushTitle,
+			"descriptAppend": descriptAppend,
+			"type":           "bid",
+			"userId":         u.Id,
+			"url":            "/jyapp/free/sess/" + Se.EncodeString(u.Id+",_id,"+strconv.Itoa(int(now.Unix()))+",") + "__" + Se.EncodeString(fmt.Sprintf(Config.AppMsg.Url, util.If(IsVipUser(u.VipStatus), "vip", "free").(string), pushParam.PushDate)),
+			"otherPushId":    u.Opushid,
+			"jgPushId":       u.Jpushid, //极光-推送id
+		})
+		if isPushOk {
 			pushResult.AppStatus = 1
-			logger.Info("推送任务", taskType, "新版商机管理用户,免费订阅不进行app推送", u.Id)
 		} else {
-			descriptAppend := ""
-			if pushParam.InfosLength > 1 {
-				descriptAppend = fmt.Sprintf("\n...(共%d条)", pushParam.InfosLength)
-				pushParam.JpushTitle = fmt.Sprintf("1. %s", pushParam.JpushTitle)
-			}
-			go Mgo.Update(Mgo_User, map[string]interface{}{
-				"_id": StringTOBsonId(u.Id),
-			}, map[string]interface{}{
-				"$inc": map[string]interface{}{
-					"i_apppushunread": 1,
-				},
-			}, false, false)
-			isPushOk := putil.SendApp(map[string]interface{}{
-				"phoneType":      u.AppPhoneType,
-				"descript":       pushParam.JpushTitle,
-				"descriptAppend": descriptAppend,
-				"type":           "bid",
-				"userId":         u.Id,
-				"url":            "/jyapp/free/sess/" + Se.EncodeString(u.Id+",_id,"+strconv.Itoa(int(now.Unix()))+",historypush") + "__" + util.If(IsVipUser(u.VipStatus), "vip", "free").(string) + "__" + fmt.Sprint(pushParam.PushDate),
-				"otherPushId":    u.Opushid,
-				"jgPushId":       u.Jpushid, //极光-推送id
-			})
-			if isPushOk {
-				pushResult.AppStatus = 1
-			} else {
-				pushResult.AppStatus = -1
-			}
-			logger.Info("推送任务", taskType, "app推送结束", isPushOk, u.Id)
+			pushResult.AppStatus = -1
 		}
+		logger.Info("推送任务", taskType, "app推送结束", isPushOk, u.Id)
 	}
 	//发送邮件
 	if pushWay.MailPush {
@@ -321,7 +317,7 @@ func (p *PushJob) sendWeixin(k *UserInfo, pushParam *PushParam) (bool, string, s
 		OpenId:   k.S_m_openid,
 		TplId:    Config.WxTplMsg.Id,
 		TmplData: tmplData,
-		Url:      Config.JianyuDomain + "/front/sess/" + Se.EncodeString(k.S_m_openid+",uid,"+strconv.Itoa(int(time.Now().Unix()))+",historypush") + "__" + fmt.Sprint(pushParam.PushDate) + "__" + wtmc.AdvertCode,
+		Url:      Config.JianyuDomain + "/front/sess/" + Se.EncodeString(k.Id+",_id,"+strconv.Itoa(int(time.Now().Unix()))+",") + "__" + Se.EncodeString(fmt.Sprintf(Config.WxTplMsg.Url, util.If(IsVipUser(k.VipStatus), "vip", "free").(string), pushParam.PushDate, wtmc.AdvertCode)),
 	})
 	return ok, wtmc.AdvertCode, wtmc.FirstData
 }

+ 0 - 20
pushsubscribe/src/push/util/util.go

@@ -6,8 +6,6 @@ import (
 	. "push/config"
 	. "push/db"
 	"qfw/util"
-
-	"github.com/donnie4w/go-logger/logger"
 )
 
 var WTMCS = NewWxTplMsgCustoms(Mysql_Main, Config.WxTplMsg.Id, Config.WxTplMsg.First.Value, Config.WxTplMsg.Vip_first.Value, Config.NoMsgTip.Wx.First.Value)
@@ -58,21 +56,3 @@ func NewUserInfoByPushSpaceColl(user map[string]interface{}) *UserInfo {
 	}
 	return ui
 }
-
-//加载商机管理用户
-func LoadEntnicheUsers() map[string]bool {
-	logger.Info("开始加载新版商机管理用户。。。")
-	m := map[string]bool{}
-	Mysql_Main.SelectByBath(200, func(l *[]map[string]interface{}) bool {
-		for _, v := range *l {
-			phone := util.ObjToString(v["phone"])
-			if phone != "" {
-				m[phone] = true
-				logger.Info("加载新版商机管理用户", phone)
-			}
-		}
-		return true
-	}, `SELECT b.phone from entniche_info a INNER JOIN entniche_user b on (a.status=1 and a.isNew=1 and b.power=1 and a.id=b.ent_id)`)
-	logger.Info("新版商机管理用户加载结束。。。", len(m))
-	return m
-}

+ 16 - 0
推送用的redis说明.txt

@@ -0,0 +1,16 @@
+pushcache_1
+	1、推送的招标采购信息基本字段,有效期三天
+pushcache_2_a
+	1、免费\超级订阅\大会员\商机管理每个用户推送过的信息id,有效期一天
+	2、免费\超级订阅\大会员\商机管理每个用户今天推送的总数,有效期一天
+	3、免费\超级订阅\大会员\商机管理每个用户最后一次推送的总数,有效期一天
+	4、免费\超级订阅最新推送的7天内50条数据,有效期七天
+	5、免费\超级订阅\大会员\商机管理每个用户全部推送数据最新的250条,有效期三天
+pushcache_2_b
+	1、免费\超级订阅\大会员\商机管理每个用户今天的推送数据,有效期一天
+	2、所有推送程序迁移数据和推送数据之间的锁
+pushcache_2_c
+	1、免费\超级订阅\大会员\商机管理今天推送的总人数,有效期永久
+	2、免费\超级订阅\大会员\商机管理订阅无消息提醒今天是否提醒过,有效期一天
+	3、免费\超级订阅\大会员\商机管理上次订阅无消息提醒的时间,有效期四天
+	3、免费\超级订阅\大会员\商机管理每个用户今天是否推送过,有效期一天