|
@@ -6,12 +6,12 @@ import (
|
|
|
"os"
|
|
|
. "public"
|
|
|
. "push/config"
|
|
|
+ . "push/pusher"
|
|
|
putil "push/util"
|
|
|
"qfw/util"
|
|
|
"qfw/util/mail"
|
|
|
"qfw/util/mongodb"
|
|
|
"qfw/util/redis"
|
|
|
- "sort"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"sync"
|
|
@@ -46,6 +46,14 @@ type pushJob struct {
|
|
|
|
|
|
//taskType 1--一天三次推送 2--九点推送
|
|
|
func (p *pushJob) Execute(taskType int) {
|
|
|
+ p.startPush(taskType)
|
|
|
+ if taskType == 2 {
|
|
|
+ p.startPush(3)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+//开始推送
|
|
|
+func (p *pushJob) startPush(taskType int) {
|
|
|
defer util.Catch()
|
|
|
var pusher Pusher
|
|
|
if taskType == 1 || taskType == 2 {
|
|
@@ -61,7 +69,7 @@ func (p *pushJob) Execute(taskType int) {
|
|
|
startId := ""
|
|
|
for {
|
|
|
batchIndex++
|
|
|
- batch_size, users := pusher.OncePushBatch(taskType, batchIndex, &startId)
|
|
|
+ isBreak, users := pusher.OncePushBatch(taskType, batchIndex, &startId)
|
|
|
for _, temp := range *users {
|
|
|
isTake := true
|
|
|
select {
|
|
@@ -85,29 +93,9 @@ func (p *pushJob) Execute(taskType int) {
|
|
|
}
|
|
|
p.wait.Done()
|
|
|
}()
|
|
|
- words, _ := v["words"].([]interface{})
|
|
|
- u := &UserInfo{
|
|
|
- Id: util.ObjToString(v["userid"]),
|
|
|
- Keys: util.ObjArrToStringArr(words),
|
|
|
- WxPush: util.IntAll(v["wxpush"]),
|
|
|
- AppPush: util.IntAll(v["apppush"]),
|
|
|
- MailPush: util.IntAll(v["mailpush"]),
|
|
|
- PchelperPush: util.IntAll(v["pchelperpush"]),
|
|
|
- Email: util.ObjToString(v["email"]),
|
|
|
- S_m_openid: util.ObjToString(v["s_m_openid"]),
|
|
|
- A_m_openid: util.ObjToString(v["a_m_openid"]),
|
|
|
- Phone: util.ObjToString(v["phone"]),
|
|
|
- Jpushid: util.ObjToString(v["jpushid"]),
|
|
|
- Opushid: util.ObjToString(v["opushid"]),
|
|
|
- UserType: util.IntAll(v["usertype"]),
|
|
|
- RateMode: util.IntAllDef(v["ratemode"], 1),
|
|
|
- AppPhoneType: util.ObjToString(v["appphonetype"]),
|
|
|
- ApplyStatus: util.IntAll(v["applystatus"]),
|
|
|
- Subscribe: util.IntAllDef(v["subscribe"], 1),
|
|
|
- ModifyDate: util.ObjToString(v["modifydate"]),
|
|
|
- MergeOrder: v["mergeorder"],
|
|
|
- FirstPushTime: util.Int64All(v["firstpushtime"]),
|
|
|
- VipStatus: util.IntAll(v["vipstatus"]),
|
|
|
+ u := pusher.GetUserInfo(v)
|
|
|
+ if u == nil {
|
|
|
+ return
|
|
|
}
|
|
|
logger.Info("推送任务", p.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.RateMode, "email", u.Email)
|
|
|
wxPush, appPush, mailPush := 0, 0, 0
|
|
@@ -141,49 +129,11 @@ func (p *pushJob) Execute(taskType int) {
|
|
|
mailPush = 0
|
|
|
}
|
|
|
}
|
|
|
- isSaveSuccess, isVipTempSave, wxStatus, appStatus, mailStatus := p.push(p.taskType, wxPush, appPush, mailPush, u, list)
|
|
|
- if isSaveSuccess {
|
|
|
- if u.FirstPushTime == 0 {
|
|
|
- go mongodb.Update("user", map[string]interface{}{
|
|
|
- "_id": bson.ObjectIdHex(u.Id),
|
|
|
- }, map[string]interface{}{
|
|
|
- "$set": map[string]interface{}{
|
|
|
- "l_firstpushtime": time.Now().Unix(),
|
|
|
- },
|
|
|
- }, false, false)
|
|
|
- }
|
|
|
- if isVipTempSave {
|
|
|
- p.vipTempSave(u.Id, v)
|
|
|
- }
|
|
|
- } else {
|
|
|
- return
|
|
|
- }
|
|
|
- //判断是否要删除数据
|
|
|
- sess := mongodb.GetMgoConn()
|
|
|
- defer mongodb.DestoryMongoConn(sess)
|
|
|
- err := sess.DB(DbName).C("pushspace").RemoveId(v["_id"])
|
|
|
- if err != nil {
|
|
|
- logger.Error("推送任务", p.taskType, "remove error", err)
|
|
|
- }
|
|
|
- if wxStatus == -1 || appStatus == -1 || mailStatus == -1 {
|
|
|
- v["failtime"] = time.Now().Unix()
|
|
|
- if wxStatus == -1 {
|
|
|
- v["wxfail"] = 1
|
|
|
- }
|
|
|
- if appStatus == -1 {
|
|
|
- v["appfail"] = 1
|
|
|
- }
|
|
|
- if mailStatus == -1 {
|
|
|
- v["mailfail"] = 1
|
|
|
- }
|
|
|
- _, err := sess.DB(DbName).C("pushspace_fail").UpsertId(v["_id"], map[string]interface{}{"$set": v})
|
|
|
- if err != nil {
|
|
|
- logger.Error("推送任务", p.taskType, "update error", err)
|
|
|
- }
|
|
|
- }
|
|
|
+ pushResult := p.selectPush(p.taskType, wxPush, appPush, mailPush, u, list)
|
|
|
+ pusher.AfterPush(pushResult, u, v)
|
|
|
}(temp, isTake)
|
|
|
}
|
|
|
- if batch_size < Config.PushBatch {
|
|
|
+ if isBreak {
|
|
|
break
|
|
|
}
|
|
|
}
|
|
@@ -191,14 +141,18 @@ func (p *pushJob) Execute(taskType int) {
|
|
|
logger.Info("推送任务结束。。。", p.taskType)
|
|
|
}
|
|
|
|
|
|
-func (p *pushJob) push(taskType int, wxPush, appPush, mailPush int, u *UserInfo, list SortList) (isSaveSuccess, isVipTempSave bool, wxStatus, appStatus, mailStatus int) {
|
|
|
+//满足条件进行推送
|
|
|
+func (p *pushJob) selectPush(taskType int, wxPush, appPush, mailPush int, u *UserInfo, list SortList) (pushResult *putil.PushResult) {
|
|
|
if wxPush == 1 || appPush == 1 || mailPush == 1 || u.PchelperPush == 1 {
|
|
|
- isSaveSuccess, isVipTempSave, wxStatus, appStatus, mailStatus = p.doPush(taskType, true, wxPush, appPush, mailPush, u, &list)
|
|
|
+ pushResult = p.doPush(taskType, true, wxPush, appPush, mailPush, u, &list)
|
|
|
}
|
|
|
- return isSaveSuccess, isVipTempSave, wxStatus, appStatus, mailStatus
|
|
|
+ return
|
|
|
}
|
|
|
-func (p *pushJob) doPush(taskType int, isSave bool, wxPush, appPush, mailPush int, k *UserInfo, sl *SortList) (isSaveSuccess, isVipTempSave bool, wxStatus, appStatus, mailStatus int) {
|
|
|
+
|
|
|
+//进入具体推送
|
|
|
+func (p *pushJob) doPush(taskType int, isSave bool, wxPush, appPush, mailPush int, k *UserInfo, sl *SortList) (pushResult *putil.PushResult) {
|
|
|
defer util.Catch()
|
|
|
+ pushResult = &putil.PushResult{}
|
|
|
mailContent := ""
|
|
|
jpushtitle := ""
|
|
|
lastInfoDate := int64(0)
|
|
@@ -325,17 +279,17 @@ func (p *pushJob) doPush(taskType int, isSave bool, wxPush, appPush, mailPush in
|
|
|
return
|
|
|
}
|
|
|
logger.Info("推送任务", taskType, "保存成功", pushDate, k.Id)
|
|
|
- isSaveSuccess = true
|
|
|
+ pushResult.IsSaveSuccess = true
|
|
|
}
|
|
|
if isVipUser && (k.RateMode == 3 || k.RateMode == 4) {
|
|
|
if now.Day() != 28 && now.Weekday().String() != "Friday" {
|
|
|
- isVipTempSave = true
|
|
|
+ pushResult.IsVipTempSave = true
|
|
|
return
|
|
|
} else {
|
|
|
}
|
|
|
}
|
|
|
logger.Info("推送任务", taskType, "开始进行终端推送", k.Id)
|
|
|
- if isSaveSuccess {
|
|
|
+ if pushResult.IsSaveSuccess {
|
|
|
//pc端助手推送
|
|
|
if k.S_m_openid != "" {
|
|
|
logger.Info("推送任务", taskType, "开始助手推送", k.Id, "s_m_openid", k.S_m_openid)
|
|
@@ -419,9 +373,9 @@ func (p *pushJob) doPush(taskType int, isSave bool, wxPush, appPush, mailPush in
|
|
|
//推送微信
|
|
|
isPushOk = putil.SendWeixin(k, tip+wxTplTitle+lastTip, wxTitle, pushDate)
|
|
|
if isPushOk {
|
|
|
- wxStatus = 1
|
|
|
+ pushResult.WxStatus = 1
|
|
|
} else {
|
|
|
- wxStatus = -1
|
|
|
+ pushResult.WxStatus = -1
|
|
|
}
|
|
|
}
|
|
|
logger.Info("推送任务", taskType, "微信推送结束", k.ApplyStatus, isPushOk, k.Id)
|
|
@@ -451,9 +405,9 @@ func (p *pushJob) doPush(taskType int, isSave bool, wxPush, appPush, mailPush in
|
|
|
"jgPushId": k.Jpushid, //极光-推送id
|
|
|
})
|
|
|
if isPushOk {
|
|
|
- appStatus = 1
|
|
|
+ pushResult.AppStatus = 1
|
|
|
} else {
|
|
|
- appStatus = -1
|
|
|
+ pushResult.AppStatus = -1
|
|
|
}
|
|
|
logger.Info("推送任务", taskType, "app推送结束", isPushOk, k.Id)
|
|
|
}
|
|
@@ -463,9 +417,9 @@ func (p *pushJob) doPush(taskType int, isSave bool, wxPush, appPush, mailPush in
|
|
|
html := fmt.Sprintf(Config.Mail_html, strings.Replace(strings.Join(k.Keys, ";"), "+", " ", -1), mailContent)
|
|
|
isPushOk := p.sendMail(k.Email, Config.Mail_title, html, nil)
|
|
|
if isPushOk {
|
|
|
- mailStatus = 1
|
|
|
+ pushResult.MailStatus = 1
|
|
|
} else {
|
|
|
- mailStatus = -1
|
|
|
+ pushResult.MailStatus = -1
|
|
|
}
|
|
|
logger.Info("推送任务", taskType, "邮箱推送结束", isPushOk, k.Id)
|
|
|
}
|
|
@@ -526,57 +480,3 @@ func (p *pushJob) save(k *UserInfo, matchInfos []*MatchInfo) string {
|
|
|
}
|
|
|
return fmt.Sprint(unix)
|
|
|
}
|
|
|
-
|
|
|
-//vip 每周 每月推送 暂时保存
|
|
|
-func (p *pushJob) vipTempSave(userId string, v map[string]interface{}) {
|
|
|
- newList := putil.ToSortList(v["list"])
|
|
|
- pLength := len(newList)
|
|
|
- if pLength == 0 {
|
|
|
- return
|
|
|
- }
|
|
|
- sess := mongodb.GetMgoConn()
|
|
|
- defer mongodb.DestoryMongoConn(sess)
|
|
|
- var data map[string]interface{}
|
|
|
- coll := sess.DB(DbName).C("pushspace_vip")
|
|
|
- err := coll.Find(map[string]interface{}{"userid": userId}).Select(map[string]interface{}{"size": 1, "list": 1, "date": 1, "userid": 1}).One(&data)
|
|
|
- if err != nil {
|
|
|
- logger.Error(userId, "获取用户pushspace_vip数据出错", err)
|
|
|
- return
|
|
|
- }
|
|
|
- nowymd := util.NowFormat(util.Date_yyyyMMdd)
|
|
|
- if data == nil { //批量新增
|
|
|
- err = coll.Insert(map[string]interface{}{
|
|
|
- "userid": v["userid"],
|
|
|
- "size": v["size"],
|
|
|
- "list": v["list"],
|
|
|
- "date": nowymd,
|
|
|
- "createtime": time.Now().Unix(),
|
|
|
- })
|
|
|
- if err != nil {
|
|
|
- logger.Error(userId, "保存pushspace_vip出错", err)
|
|
|
- return
|
|
|
- }
|
|
|
- } else { //批量更新
|
|
|
- upSet := map[string]interface{}{}
|
|
|
- if nowymd != util.ObjToString(data["date"]) {
|
|
|
- return
|
|
|
- }
|
|
|
- oldList := putil.ToSortList(data["list"])
|
|
|
- if len(oldList)+pLength > Config.MaxPushSize {
|
|
|
- newList = append(newList, oldList...)
|
|
|
- sort.Sort(newList)
|
|
|
- v["list"] = newList[:Config.MaxPushSize]
|
|
|
- } else { //追加
|
|
|
- upSet["$pushAll"] = map[string]interface{}{
|
|
|
- "list": newList,
|
|
|
- }
|
|
|
- }
|
|
|
- v["size"] = util.IntAll(v["size"]) + pLength
|
|
|
- upSet["$set"] = v
|
|
|
- err = coll.UpdateId(data["_id"], upSet)
|
|
|
- if err != nil {
|
|
|
- logger.Error(userId, "更新pushspace_vip出错", err)
|
|
|
- return
|
|
|
- }
|
|
|
- }
|
|
|
-}
|