|
@@ -16,8 +16,6 @@ const (
|
|
|
threeday = 259200
|
|
|
)
|
|
|
|
|
|
-var Se = qutil.SimpleEncrypt{Key: "topnet"}
|
|
|
-
|
|
|
func Run() {
|
|
|
go syncVipUpgrade()
|
|
|
go checkIsExpire()
|
|
@@ -26,7 +24,7 @@ func Run() {
|
|
|
|
|
|
//vip升级 下个月生效 同步
|
|
|
func syncVipUpgrade() {
|
|
|
- crontab(true, TimetaskConfig.SyncVipUpgrade, func() {
|
|
|
+ crontab(true, TimeTaskConfig.SyncVipUpgrade, func() {
|
|
|
log.Println("定时任务,开始同步vip升级数据")
|
|
|
sess := util.MQFW.GetMgoConn()
|
|
|
defer util.MQFW.DestoryMongoConn(sess)
|
|
@@ -73,7 +71,7 @@ func syncVipUpgrade() {
|
|
|
|
|
|
//每天0点 检查试用、vip服务是否到期
|
|
|
func checkIsExpire() {
|
|
|
- crontab(true, TimetaskConfig.CheckIsExpire, func() {
|
|
|
+ crontab(true, TimeTaskConfig.CheckIsExpire, func() {
|
|
|
log.Println("定时任务,开始更新vip状态")
|
|
|
now_unix := time.Now().Unix()
|
|
|
sess := util.MQFW.GetMgoConn()
|
|
@@ -103,16 +101,15 @@ func checkIsExpire() {
|
|
|
delSess := util.MQFW.GetMgoConn()
|
|
|
defer util.MQFW.DestoryMongoConn(delSess)
|
|
|
for _, pushColl := range []string{"pushspace", "pushspace_temp", "pushspace_vip", "pushspace_fail", "pushspace_project"} {
|
|
|
- log.Println("用户", _id, "已到期开始删除", pushColl, "表数据。。。")
|
|
|
_, err := delSess.DB("qfw").C(pushColl).RemoveAll(map[string]interface{}{"userid": _id})
|
|
|
if err != nil {
|
|
|
log.Println("用户", _id, "已到期删除", pushColl, "表数据出错", err)
|
|
|
} else {
|
|
|
- log.Println("用户", _id, "已到期删除", pushColl, "表数据结束。。。")
|
|
|
+ log.Println("用户", _id, "已到期删除", pushColl, "表数据")
|
|
|
}
|
|
|
}
|
|
|
log.Println("用户", _id, i_vip_status, l_vip_endtime, "修改已到期状态")
|
|
|
- } else if l_vip_endtime-now_unix <= threeday && i_vip_expire_tip != 1 && i_vip_expire_tip != -1 {
|
|
|
+ } else if l_vip_endtime-now_unix <= threeday && i_vip_expire_tip != 1 {
|
|
|
updateOk := util.MQFW.UpdateById("user", _id, map[string]interface{}{
|
|
|
"$set": map[string]interface{}{
|
|
|
"i_vip_expire_tip": 1,
|
|
@@ -128,8 +125,8 @@ func checkIsExpire() {
|
|
|
|
|
|
//即将到期或者已到期发推送消息
|
|
|
func expireRemind() {
|
|
|
- crontab(false, TimetaskConfig.ExpireRemind, func() {
|
|
|
- log.Println("定时任务,开始推送消息")
|
|
|
+ crontab(true, TimeTaskConfig.ExpireRemind, func() {
|
|
|
+ log.Println("定时任务,到期提醒,开始推送消息")
|
|
|
sess := util.MQFW.GetMgoConn()
|
|
|
defer util.MQFW.DestoryMongoConn(sess)
|
|
|
it := sess.DB("qfw").C("user").Find(map[string]interface{}{
|
|
@@ -142,7 +139,6 @@ func expireRemind() {
|
|
|
"s_jpushid": 1,
|
|
|
"s_opushid": 1,
|
|
|
"s_appponetype": 1,
|
|
|
- "i_applystatus": 1,
|
|
|
"s_nickname": 1,
|
|
|
"i_ispush": 1,
|
|
|
"i_vip_status": 1,
|
|
@@ -152,19 +148,17 @@ func expireRemind() {
|
|
|
}).Iter()
|
|
|
for m := make(map[string]interface{}); it.Next(&m); {
|
|
|
_id := qutil.BsonIdToSId(m["_id"])
|
|
|
- i_vip_expire_tip := qutil.Int64All(m["i_vip_expire_tip"])
|
|
|
+ i_vip_status := qutil.IntAll(m["i_vip_status"])
|
|
|
+ i_vip_expire_tip := qutil.IntAll(m["i_vip_expire_tip"])
|
|
|
wxPushOk, appPushOk := false, false
|
|
|
if i_vip_expire_tip == 1 || i_vip_expire_tip == 2 {
|
|
|
tp := "will"
|
|
|
- tpMsg := "即将"
|
|
|
if i_vip_expire_tip == 2 {
|
|
|
tp = "exprie"
|
|
|
- tpMsg = "已"
|
|
|
}
|
|
|
l_vip_starttime := qutil.Int64All(m["l_vip_starttime"])
|
|
|
l_vip_endtime := qutil.Int64All(m["l_vip_endtime"])
|
|
|
s_m_openid := qutil.ObjToString(m["s_m_openid"])
|
|
|
- i_applystatus := qutil.IntAll(m["i_applystatus"])
|
|
|
isPushWx := qutil.IntAllDef(m["i_ispush"], 1)
|
|
|
s_jpushid := qutil.ObjToString(m["s_jpushid"])
|
|
|
s_opushid := qutil.ObjToString(m["s_opushid"])
|
|
@@ -178,45 +172,80 @@ func expireRemind() {
|
|
|
if order != nil && len(*order) > 0 {
|
|
|
orderId = fmt.Sprint((*order)["id"])
|
|
|
}
|
|
|
- log.Println("推送消息", _id, "i_vip_status", m["i_vip_status"], "orderId", orderId, "l_vip_starttime", l_vip_starttime, "l_vip_endtime", l_vip_endtime, "i_vip_expire_tip", i_vip_expire_tip, "s_m_openid", s_m_openid, "isPushWx", isPushWx, "i_applystatus", i_applystatus, "s_appponetype", s_appponetype, "s_jpushid", s_jpushid, "s_opushid", s_opushid)
|
|
|
- if isPushWx == 1 && i_applystatus == 1 && s_m_openid != "" {
|
|
|
+ log.Println("到期提醒,推送消息", _id, "i_vip_status", i_vip_status, "orderId", orderId, "l_vip_starttime", l_vip_starttime, "l_vip_endtime", l_vip_endtime, "i_vip_expire_tip", i_vip_expire_tip, "s_m_openid", s_m_openid, "isPushWx", isPushWx, "s_appponetype", s_appponetype, "s_jpushid", s_jpushid, "s_opushid", s_opushid)
|
|
|
+ if isPushWx == 1 && s_m_openid != "" {
|
|
|
+ tplId, first_value, keyword1_value, keyword2_value, keyword3_value, keyword4_value, remark := "", "", "", "", "", "", ""
|
|
|
+ switch i_vip_status {
|
|
|
+ case 1, -1:
|
|
|
+ if i_vip_expire_tip == 1 {
|
|
|
+ tplId = MessageConfig.WxTpl_OnTrial_SoonExpire.Id
|
|
|
+ first_value = MessageConfig.WxTpl_OnTrial_SoonExpire.First.Value
|
|
|
+ remark = MessageConfig.WxTpl_OnTrial_SoonExpire.Remark.Value
|
|
|
+ } else if i_vip_expire_tip == 2 {
|
|
|
+ tplId = MessageConfig.WxTpl_OnTrial_Expired.Id
|
|
|
+ first_value = MessageConfig.WxTpl_OnTrial_Expired.First.Value
|
|
|
+ remark = MessageConfig.WxTpl_OnTrial_Expired.Remark.Value
|
|
|
+ }
|
|
|
+ keyword1_value = qutil.ObjToString(m["s_nickname"])
|
|
|
+ keyword2_value = qutil.FormatDateByInt64(&l_vip_endtime, qutil.Date_Short_Layout)
|
|
|
+ break
|
|
|
+ case 2, -2:
|
|
|
+ if i_vip_expire_tip == 1 {
|
|
|
+ tplId = MessageConfig.WxTpl_SoonExpire.Id
|
|
|
+ first_value = MessageConfig.WxTpl_SoonExpire.First.Value
|
|
|
+ keyword2_value = MessageConfig.WxTpl_SoonExpire.Keyword2.Value
|
|
|
+ keyword3_value = MessageConfig.WxTpl_SoonExpire.Keyword3.Value
|
|
|
+ remark = MessageConfig.WxTpl_SoonExpire.Remark.Value
|
|
|
+ } else if i_vip_expire_tip == 2 {
|
|
|
+ tplId = MessageConfig.WxTpl_Expired.Id
|
|
|
+ first_value = MessageConfig.WxTpl_Expired.First.Value
|
|
|
+ keyword2_value = MessageConfig.WxTpl_Expired.Keyword2.Value
|
|
|
+ keyword3_value = MessageConfig.WxTpl_Expired.Keyword3.Value
|
|
|
+ remark = MessageConfig.WxTpl_Expired.Remark.Value
|
|
|
+ }
|
|
|
+ keyword1_value = qutil.ObjToString(m["s_nickname"])
|
|
|
+ keyword4_value = qutil.FormatDateByInt64(&l_vip_endtime, qutil.Date_Short_Layout)
|
|
|
+ break
|
|
|
+ }
|
|
|
tmplData := map[string]*qrpc.TmplItem{
|
|
|
"first": &qrpc.TmplItem{
|
|
|
- Value: fmt.Sprintf(MessageConfig.WxTplExpire.First.Value, tpMsg),
|
|
|
- Color: MessageConfig.WxTplExpire.First.Color,
|
|
|
+ Value: first_value,
|
|
|
},
|
|
|
"keyword1": &qrpc.TmplItem{
|
|
|
- Value: qutil.ObjToString(m["s_nickname"]),
|
|
|
+ Value: keyword1_value,
|
|
|
},
|
|
|
"keyword2": &qrpc.TmplItem{
|
|
|
- Value: MessageConfig.WxTplExpire.Keyword2.Value,
|
|
|
+ Value: keyword2_value,
|
|
|
},
|
|
|
"keyword3": &qrpc.TmplItem{
|
|
|
- Value: MessageConfig.WxTplExpire.Keyword3.Value,
|
|
|
+ Value: keyword3_value,
|
|
|
},
|
|
|
"keyword4": &qrpc.TmplItem{
|
|
|
- Value: qutil.FormatDateByInt64(&l_vip_endtime, qutil.Date_Short_Layout),
|
|
|
+ Value: keyword4_value,
|
|
|
+ },
|
|
|
+ "remark": &qrpc.TmplItem{
|
|
|
+ Value: remark,
|
|
|
},
|
|
|
}
|
|
|
wxPushOk, _ = qrpc.WxSendTmplMsg(Config.Weixinrpc, &qrpc.WxTmplMsg{
|
|
|
OpenId: s_m_openid,
|
|
|
- TplId: MessageConfig.WxTplExpire.Id,
|
|
|
+ TplId: tplId,
|
|
|
TmplData: tmplData,
|
|
|
- Url: Config.WebDomain + "/front/sess/" + Se.EncodeString(s_m_openid+",uid,"+strconv.Itoa(int(time.Now().Unix()))+",expireTip") + "__" + tp + "__" + fmt.Sprint(orderId) + "__" + fmt.Sprint(l_vip_starttime) + "__" + fmt.Sprint(l_vip_endtime),
|
|
|
+ Url: Config.WebDomain + "/front/sess/" + util.Se_Topnet.EncodeString(s_m_openid+",uid,"+strconv.Itoa(int(time.Now().Unix()))+",msgremind") + "__" + fmt.Sprint("type=%s&orderid=%d", tp, orderId),
|
|
|
})
|
|
|
- log.Println("微信推送", _id, wxPushOk)
|
|
|
+ log.Println("到期提醒,微信推送", _id, wxPushOk)
|
|
|
}
|
|
|
}
|
|
|
if wxPushOk || appPushOk {
|
|
|
util.MQFW.UpdateById("user", _id, map[string]interface{}{
|
|
|
"$set": map[string]interface{}{
|
|
|
- "i_vip_expire_tip": -i_vip_expire_tip,
|
|
|
+ "i_vip_expire_tip": 0,
|
|
|
},
|
|
|
})
|
|
|
}
|
|
|
m = make(map[string]interface{})
|
|
|
}
|
|
|
- log.Println("定时任务,推送消息结束")
|
|
|
+ log.Println("定时任务,到期提醒,推送消息结束")
|
|
|
})
|
|
|
}
|
|
|
|