|
@@ -2,7 +2,6 @@ package job
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
- "log"
|
|
|
"net/http"
|
|
|
"os"
|
|
|
. "public"
|
|
@@ -35,7 +34,6 @@ func init() {
|
|
|
}
|
|
|
|
|
|
type PushJob struct {
|
|
|
- taskType int
|
|
|
pool chan bool
|
|
|
wait *sync.WaitGroup
|
|
|
lock *sync.Mutex
|
|
@@ -45,29 +43,39 @@ type PushJob struct {
|
|
|
|
|
|
//taskType 1--一天三次推送 2--九点推送
|
|
|
func (p *PushJob) Execute(taskType int) {
|
|
|
- p.startPush(taskType)
|
|
|
- if taskType == 2 {
|
|
|
- p.startPush(3)
|
|
|
+ p.lock.Lock()
|
|
|
+ defer p.lock.Unlock()
|
|
|
+ p.beforePush(taskType)
|
|
|
+ //每天九点以后,推送每周每月的用户
|
|
|
+ if taskType == 2 && putil.IsVipTempPushTime() {
|
|
|
+ now := time.Now()
|
|
|
+ if now.Weekday().String() == Config.VipPushWeek { //每周
|
|
|
+ p.beforePush(3)
|
|
|
+ } else if now.Day() == Config.VipPushDay { //每月
|
|
|
+ p.beforePush(4)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//开始推送
|
|
|
-func (p *PushJob) startPush(taskType int) {
|
|
|
- defer util.Catch()
|
|
|
+func (p *PushJob) beforePush(taskType int) {
|
|
|
var pusher Pusher
|
|
|
if taskType == 1 || taskType == 2 {
|
|
|
pusher = &NormalPush{
|
|
|
SavePool: make(chan bool, Config.SavePoolSize),
|
|
|
}
|
|
|
- } else if taskType == 3 {
|
|
|
+ } else if taskType == 3 || taskType == 4 || taskType == 5 {
|
|
|
pusher = &SpecialPush{}
|
|
|
} else {
|
|
|
return
|
|
|
}
|
|
|
- p.lock.Lock()
|
|
|
- defer p.lock.Unlock()
|
|
|
- p.taskType = taskType
|
|
|
- logger.Info("推送任务", p.taskType, "开始推送。。。")
|
|
|
+ p.StartPush(pusher, taskType)
|
|
|
+}
|
|
|
+
|
|
|
+//开始推送
|
|
|
+func (p *PushJob) StartPush(pusher Pusher, taskType int) {
|
|
|
+ defer util.Catch()
|
|
|
+ logger.Info("推送任务", taskType, "开始推送。。。")
|
|
|
batchIndex := 0
|
|
|
startId := ""
|
|
|
for {
|
|
@@ -78,7 +86,7 @@ func (p *PushJob) startPush(taskType int) {
|
|
|
select {
|
|
|
case <-time.After(5 * time.Minute):
|
|
|
isTake = false
|
|
|
- logger.Error("推送任务", p.taskType, "推送放入通道超时,", temp["userid"], len(p.minutePushPool), len(p.fastigiumMinutePushPool))
|
|
|
+ logger.Error("推送任务", taskType, "推送放入通道超时,", temp["userid"], len(p.minutePushPool), len(p.fastigiumMinutePushPool))
|
|
|
go func() {
|
|
|
if Config.TimeoutWarn != "" {
|
|
|
if _, err := http.Get(Config.TimeoutWarn); err != nil {
|
|
@@ -96,44 +104,15 @@ func (p *PushJob) startPush(taskType int) {
|
|
|
}
|
|
|
p.wait.Done()
|
|
|
}()
|
|
|
- u := pusher.GetUserInfo(v)
|
|
|
+ u, pushWay := 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
|
|
|
- if u.WxPush == 1 {
|
|
|
- wxPush = 1
|
|
|
- }
|
|
|
- if u.AppPush == 1 {
|
|
|
- appPush = 1
|
|
|
- }
|
|
|
- if u.MailPush == 1 {
|
|
|
- mailPush = 1
|
|
|
- }
|
|
|
- logger.Info("推送任务", p.taskType, "用户接收方式", "userId", u.Id, "wxPush", wxPush, "appPush", appPush, "mailPush", mailPush, "pchelperPush", u.PchelperPush)
|
|
|
- if wxPush != 1 && appPush != 1 && mailPush != 1 {
|
|
|
- return
|
|
|
- }
|
|
|
- list := putil.ToSortList(v["list"])
|
|
|
- //再对取消关注以及app没有登录的用户进行过滤,但是依然可以进行助手推送
|
|
|
- if u.Subscribe == 0 {
|
|
|
- wxPush = 0
|
|
|
+ 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.RateMode, "email", u.Email, "vipStatus", u.VipStatus)
|
|
|
+ var pushResult *putil.PushResult
|
|
|
+ if pushWay.WxPush || pushWay.AppPush || pushWay.MailPush || pushWay.PcHelperPush {
|
|
|
+ pushResult = p.doPush(pusher, taskType, pushWay, u, putil.ToSortList(v["list"]))
|
|
|
}
|
|
|
- if u.Jpushid == "" && u.Opushid == "" {
|
|
|
- appPush = 0
|
|
|
- }
|
|
|
- if mailPush != 0 {
|
|
|
- if u.UserType == 0 && u.Subscribe == 0 {
|
|
|
- mailPush = 0
|
|
|
- } else if (u.UserType == 1 || u.UserType == 2) && u.Jpushid == "" && u.Opushid == "" {
|
|
|
- mailPush = 0
|
|
|
- } else if u.UserType == 5 && u.Subscribe == 0 && u.Jpushid == "" && u.Opushid == "" {
|
|
|
- mailPush = 0
|
|
|
- }
|
|
|
- }
|
|
|
- pushResult := p.selectPush(pusher, p.taskType, wxPush, appPush, mailPush, u, list)
|
|
|
- log.Println(pushResult)
|
|
|
pusher.AfterPush(pushResult, u, v)
|
|
|
}(temp, isTake)
|
|
|
}
|
|
@@ -142,21 +121,12 @@ func (p *PushJob) startPush(taskType int) {
|
|
|
}
|
|
|
}
|
|
|
p.wait.Wait()
|
|
|
- logger.Info("推送任务结束。。。", p.taskType)
|
|
|
-}
|
|
|
-
|
|
|
-//满足条件进行推送
|
|
|
-func (p *PushJob) selectPush(pusher Pusher, taskType int, wxPush, appPush, mailPush int, u *UserInfo, list SortList) (pushResult *putil.PushResult) {
|
|
|
- if wxPush == 1 || appPush == 1 || mailPush == 1 || u.PchelperPush == 1 {
|
|
|
- pushResult = p.doPush(pusher, taskType, wxPush, appPush, mailPush, u, &list)
|
|
|
- }
|
|
|
- return
|
|
|
+ logger.Info("推送任务结束。。。", taskType)
|
|
|
}
|
|
|
|
|
|
//进入具体推送
|
|
|
-func (p *PushJob) doPush(pusher Pusher, taskType int, wxPush, appPush, mailPush int, u *UserInfo, sl *SortList) (pushResult *putil.PushResult) {
|
|
|
+func (p *PushJob) doPush(pusher Pusher, taskType int, pushWay *putil.PushWay, u *UserInfo, sl *SortList) (pushResult *putil.PushResult) {
|
|
|
defer util.Catch()
|
|
|
- pushResult = &putil.PushResult{}
|
|
|
now := time.Now()
|
|
|
//限制一分钟最大的推送数量
|
|
|
if p.fastigiumMinutePushPool != nil {
|
|
@@ -166,32 +136,31 @@ func (p *PushJob) doPush(pusher Pusher, taskType int, wxPush, appPush, mailPush
|
|
|
} else if p.minutePushPool != nil {
|
|
|
<-p.minutePushPool //正常期
|
|
|
}
|
|
|
- pushParam := pusher.GetPushParam(mailPush, u, sl)
|
|
|
- if pushParam == nil {
|
|
|
+ pushParam := pusher.GetPushParam(pushWay.MailPush, u, sl)
|
|
|
+ if pushParam.InfosLength == 0 {
|
|
|
logger.Info("推送任务", taskType, "没有要推送的数据!", u.Id)
|
|
|
- return nil
|
|
|
+ return
|
|
|
+ }
|
|
|
+ pushResult = &putil.PushResult{
|
|
|
+ Infos: pushParam.Infos,
|
|
|
+ PushDate: pushParam.PushDate,
|
|
|
}
|
|
|
- pushResult.Infos = pushParam.Infos
|
|
|
- pushResult.PushDate = pushParam.PushDate
|
|
|
- pushResult.IsVipTempSave = pushParam.IsVipTempSave
|
|
|
if !pushParam.IsPush {
|
|
|
- return pushResult
|
|
|
+ return
|
|
|
}
|
|
|
logger.Info("推送任务", taskType, "开始进行终端推送", u.Id)
|
|
|
- if pushResult.PushDate > 0 {
|
|
|
- //pc端助手推送
|
|
|
- if u.S_m_openid != "" {
|
|
|
- logger.Info("推送任务", taskType, "开始助手推送", u.Id, "s_m_openid", u.S_m_openid)
|
|
|
- isPushOk := putil.SendPcHelper(map[string]interface{}{"clientCode": u.S_m_openid})
|
|
|
- logger.Info("推送任务", taskType, "助手推送结束", isPushOk, u.Id, "s_m_openid", u.S_m_openid)
|
|
|
- }
|
|
|
- if u.Phone != "" {
|
|
|
- logger.Info("推送任务", taskType, "开始助手推送", u.Id, "phone", u.Phone)
|
|
|
- isPushOk := putil.SendPcHelper(map[string]interface{}{"clientCode": u.Phone})
|
|
|
- logger.Info("推送任务", taskType, "助手推送结束", isPushOk, u.Id, "phone", u.Phone)
|
|
|
- }
|
|
|
+ //pc端助手推送
|
|
|
+ if u.S_m_openid != "" {
|
|
|
+ logger.Info("推送任务", taskType, "开始助手推送", u.Id, "s_m_openid", u.S_m_openid)
|
|
|
+ isPushOk := putil.SendPcHelper(map[string]interface{}{"clientCode": u.S_m_openid})
|
|
|
+ logger.Info("推送任务", taskType, "助手推送结束", isPushOk, u.Id, "s_m_openid", u.S_m_openid)
|
|
|
}
|
|
|
- if wxPush == 1 {
|
|
|
+ if u.Phone != "" {
|
|
|
+ logger.Info("推送任务", taskType, "开始助手推送", u.Id, "phone", u.Phone)
|
|
|
+ isPushOk := putil.SendPcHelper(map[string]interface{}{"clientCode": u.Phone})
|
|
|
+ logger.Info("推送任务", taskType, "助手推送结束", isPushOk, u.Id, "phone", u.Phone)
|
|
|
+ }
|
|
|
+ if pushWay.WxPush {
|
|
|
logger.Info("推送任务", taskType, "开始微信推送", u.ApplyStatus, u.Id)
|
|
|
isPushOk := true
|
|
|
if u.ApplyStatus == 1 {
|
|
@@ -215,7 +184,7 @@ func (p *PushJob) doPush(pusher Pusher, taskType int, wxPush, appPush, mailPush
|
|
|
}
|
|
|
LastTipLen := len([]rune(lastTip))
|
|
|
wxTitle := Config.VipWxTitle
|
|
|
- if !pushParam.IsVipUser {
|
|
|
+ if !IsVipUser(u.VipStatus) {
|
|
|
wxTitleKeys := strings.Join(u.Keys, ";")
|
|
|
if len([]rune(wxTitleKeys)) > 8 {
|
|
|
wxTitleKeys = string([]rune(wxTitleKeys)[:8]) + "..."
|
|
@@ -269,7 +238,7 @@ func (p *PushJob) doPush(pusher Pusher, taskType int, wxPush, appPush, mailPush
|
|
|
}
|
|
|
logger.Info("推送任务", taskType, "微信推送结束", u.ApplyStatus, isPushOk, u.Id)
|
|
|
}
|
|
|
- if appPush == 1 {
|
|
|
+ if pushWay.AppPush {
|
|
|
logger.Info("推送任务", taskType, "开始app推送", u.Id)
|
|
|
descriptAppend := ""
|
|
|
if pushParam.InfosLength > 1 {
|
|
@@ -301,9 +270,15 @@ func (p *PushJob) doPush(pusher Pusher, taskType int, wxPush, appPush, mailPush
|
|
|
logger.Info("推送任务", taskType, "app推送结束", isPushOk, u.Id)
|
|
|
}
|
|
|
//发送邮件
|
|
|
- if mailPush == 1 {
|
|
|
+ if pushWay.MailPush {
|
|
|
logger.Info("推送任务", taskType, "开始邮箱推送", u.Id)
|
|
|
- html := fmt.Sprintf(Config.Mail_html, strings.Replace(strings.Join(u.Keys, ";"), "+", " ", -1), pushParam.MailContent)
|
|
|
+ according := ""
|
|
|
+ if IsVipUser(u.VipStatus) {
|
|
|
+ according = Config.Vip_mail_according
|
|
|
+ } else {
|
|
|
+ according = fmt.Sprintf(Config.Mail_according, strings.Replace(strings.Join(u.Keys, ";"), "+", " ", -1))
|
|
|
+ }
|
|
|
+ html := fmt.Sprintf(Config.Mail_html, according, pushParam.MailContent)
|
|
|
isPushOk := p.sendMail(u.Email, Config.Mail_title, html, nil)
|
|
|
if isPushOk {
|
|
|
pushResult.MailStatus = 1
|