|
@@ -5,9 +5,12 @@ import (
|
|
"context"
|
|
"context"
|
|
"encoding/json"
|
|
"encoding/json"
|
|
"fmt"
|
|
"fmt"
|
|
|
|
+ "log"
|
|
. "pushjyinside/config"
|
|
. "pushjyinside/config"
|
|
. "pushjyinside/db"
|
|
. "pushjyinside/db"
|
|
|
|
+ . "pushjyinside/util"
|
|
"strings"
|
|
"strings"
|
|
|
|
+ "time"
|
|
|
|
|
|
"app.yhyue.com/moapp/MessageCenter/rpc/messageclient"
|
|
"app.yhyue.com/moapp/MessageCenter/rpc/messageclient"
|
|
"app.yhyue.com/moapp/MessageCenter/rpc/type/message"
|
|
"app.yhyue.com/moapp/MessageCenter/rpc/type/message"
|
|
@@ -16,6 +19,7 @@ import (
|
|
"app.yhyue.com/moapp/jybase/logger"
|
|
"app.yhyue.com/moapp/jybase/logger"
|
|
. "app.yhyue.com/moapp/jybase/mail"
|
|
. "app.yhyue.com/moapp/jybase/mail"
|
|
. "app.yhyue.com/moapp/jybase/mongodb"
|
|
. "app.yhyue.com/moapp/jybase/mongodb"
|
|
|
|
+ "app.yhyue.com/moapp/jybase/redis"
|
|
)
|
|
)
|
|
|
|
|
|
//有成单给客成发邮件,部门id:59005
|
|
//有成单给客成发邮件,部门id:59005
|
|
@@ -26,103 +30,159 @@ type PushKcJob struct {
|
|
func (p *PushKcJob) Execute() {
|
|
func (p *PushKcJob) Execute() {
|
|
defer util.Catch()
|
|
defer util.Catch()
|
|
nowFormat := NowFormat(Date_Full_Layout)
|
|
nowFormat := NowFormat(Date_Full_Layout)
|
|
- logger.Info(p.TaskName, "开始。。。", TaskConfig.OrderPayTime, nowFormat)
|
|
|
|
- table := ""
|
|
|
|
|
|
+ logger.Info(p.TaskName, "开始。。。", TaskConfig.OrderEachTime, nowFormat)
|
|
count := 0
|
|
count := 0
|
|
orderCodes := []string{}
|
|
orderCodes := []string{}
|
|
messageConents := []string{}
|
|
messageConents := []string{}
|
|
combo := map[int64]string{}
|
|
combo := map[int64]string{}
|
|
- Mysql_Main.SelectByBath(1, func(l *[]map[string]interface{}) bool {
|
|
|
|
|
|
+ Tidb_Main.SelectByBath(1, func(l *[]map[string]interface{}) bool {
|
|
combo[util.Int64All((*l)[0]["id"])] = util.ObjToString((*l)[0]["s_name"])
|
|
combo[util.Int64All((*l)[0]["id"])] = util.ObjToString((*l)[0]["s_name"])
|
|
return true
|
|
return true
|
|
- }, `select id,s_name from bigmember_combo`)
|
|
|
|
- Mysql_Main.SelectByBath(1, func(l *[]map[string]interface{}) bool {
|
|
|
|
- product_type := util.ObjToString((*l)[0]["product_type"])
|
|
|
|
- if product_type != "大会员" && product_type != "大会员-子账号" {
|
|
|
|
|
|
+ }, `select id,s_name from jianyu.bigmember_combo`)
|
|
|
|
+ orderInfos := []*OrderInfo{}
|
|
|
|
+ userIds := []string{}
|
|
|
|
+ Tidb_Main.SelectByBath(1, func(l *[]map[string]interface{}) bool {
|
|
|
|
+ order_code := util.ObjToString((*l)[0]["order_code"])
|
|
|
|
+ id := util.Int64All((*l)[0]["id"])
|
|
|
|
+ if exists, err := redis.Exists(RedisCode, fmt.Sprintf(RedisKcOrderTip, id)); exists {
|
|
|
|
+ logger.Info(p.TaskName, "redis判重已经提醒过", id, order_code)
|
|
|
|
+ return true
|
|
|
|
+ } else if err != nil {
|
|
|
|
+ logger.Error(p.TaskName, err)
|
|
|
|
+ return true
|
|
|
|
+ }
|
|
|
|
+ user_id := util.ObjToString((*l)[0]["user_id"])
|
|
|
|
+ if user_id == "" {
|
|
return true
|
|
return true
|
|
}
|
|
}
|
|
count++
|
|
count++
|
|
|
|
+ product_type := util.ObjToString((*l)[0]["product_type"])
|
|
if filter := util.ObjToString((*l)[0]["filter"]); filter != "" {
|
|
if filter := util.ObjToString((*l)[0]["filter"]); filter != "" {
|
|
filterMap := map[string]interface{}{}
|
|
filterMap := map[string]interface{}{}
|
|
json.Unmarshal([]byte(filter), &filterMap)
|
|
json.Unmarshal([]byte(filter), &filterMap)
|
|
product_type += combo[util.Int64All(filterMap["comboId"])]
|
|
product_type += combo[util.Int64All(filterMap["comboId"])]
|
|
}
|
|
}
|
|
- order_code := util.ObjToString((*l)[0]["order_code"])
|
|
|
|
- user_phone := util.ObjToString((*l)[0]["user_phone"])
|
|
|
|
- startEnd := fmt.Sprintf("%s--%s", strings.Split(util.ObjToString((*l)[0]["vip_starttime"]), " ")[0], strings.Split(util.ObjToString((*l)[0]["vip_endtime"]), " ")[0])
|
|
|
|
|
|
+ if entId := util.Int64All((*l)[0]["ent_id"]); entId > 0 {
|
|
|
|
+ user_id = fmt.Sprint(entId)
|
|
|
|
+ }
|
|
|
|
+ userIds = append(userIds, user_id)
|
|
orderCodes = append(orderCodes, order_code)
|
|
orderCodes = append(orderCodes, order_code)
|
|
- table += fmt.Sprintf(Config.KeCheng.Mail.Table, product_type, user_phone, order_code, startEnd)
|
|
|
|
- messageConents = append(messageConents, fmt.Sprintf(Config.KeCheng.Message, product_type, user_phone, order_code, startEnd))
|
|
|
|
|
|
+ orderInfos = append(orderInfos, &OrderInfo{
|
|
|
|
+ Id: id,
|
|
|
|
+ UserId: user_id,
|
|
|
|
+ ProductType: product_type,
|
|
|
|
+ OrderCode: order_code,
|
|
|
|
+ UserPhone: util.ObjToString((*l)[0]["user_phone"]),
|
|
|
|
+ StartEnd: fmt.Sprintf("%s--%s", strings.Split(util.ObjToString((*l)[0]["vip_starttime"]), " ")[0], strings.Split(util.ObjToString((*l)[0]["vip_endtime"]), " ")[0]),
|
|
|
|
+ })
|
|
return true
|
|
return true
|
|
- }, `select order_code,user_phone,vip_starttime,vip_endtime,product_type,filter from jianyu.dataexport_order where pay_time>=? and pay_time<?`, TaskConfig.OrderPayTime, nowFormat)
|
|
|
|
|
|
+ }, `select id,order_code,user_phone,vip_starttime,vip_endtime,product_type,filter,user_id,ent_id from jianyu.dataexport_order where autoUpdate>=? and autoUpdate<? and order_status=1 and (product_type='大会员' or product_type='大会员-子账号') order by autoUpdate`, TaskConfig.OrderEachTime, nowFormat)
|
|
logger.Info(p.TaskName, count, "个订单需要发送提醒", orderCodes)
|
|
logger.Info(p.TaskName, count, "个订单需要发送提醒", orderCodes)
|
|
- phones := []string{}
|
|
|
|
- if table != "" {
|
|
|
|
- Mysql_Main.SelectByBath(1, func(l *[]map[string]interface{}) bool {
|
|
|
|
- name, phone, mail := util.ObjToString((*l)[0]["name"]), util.ObjToString((*l)[0]["phone"]), util.ObjToString((*l)[0]["mail"])
|
|
|
|
- phones = append(phones, phone)
|
|
|
|
- logger.Info(p.TaskName, "开始邮箱推送", name, phone, mail)
|
|
|
|
- isPushOk := false
|
|
|
|
- //发送邮件
|
|
|
|
- if mail != "" {
|
|
|
|
- isPushOk = PollingMail(mail, Gmails, func(gmail *GmailAuth) bool {
|
|
|
|
- return GSendMail(Config.MailFrom, mail, "", "", Config.KeCheng.Title, fmt.Sprintf(Config.KeCheng.Mail.Content, table), "", "", gmail)
|
|
|
|
- })
|
|
|
|
|
|
+ if len(orderCodes) > 0 {
|
|
|
|
+ table := ""
|
|
|
|
+ startTime := time.Now()
|
|
|
|
+ whs, args := util.WhArgs(userIds)
|
|
|
|
+ L:
|
|
|
|
+ for {
|
|
|
|
+ customerInfo := map[string]string{}
|
|
|
|
+ Tidb_Subjectdb.SelectByBath(1, func(l *[]map[string]interface{}) bool {
|
|
|
|
+ customerInfo[util.ObjToString((*l)[0]["ent_id"])] = util.ObjToString((*l)[0]["name"])
|
|
|
|
+ return true
|
|
|
|
+ }, `select ent_id,name from dwd_f_csm_customer_info where ent_id in (`+whs+`) and is_transfer=0`, args...)
|
|
|
|
+ log.Println(customerInfo, args)
|
|
|
|
+ for k, v := range orderInfos {
|
|
|
|
+ if _, ok := customerInfo[v.UserId]; !ok {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ v.DisKcName = customerInfo[v.UserId]
|
|
|
|
+ if k == len(orderInfos)-1 {
|
|
|
|
+ break L
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- logger.Info(p.TaskName, "邮箱推送结束", isPushOk, name, phone, mail)
|
|
|
|
- return true
|
|
|
|
- }, `select b.name,b.phone,b.mail from jianyu.entniche_department_user a inner join jianyu.entniche_user b on (a.dept_id=? and a.user_id=b.id)`, Config.KeCheng.DeptId)
|
|
|
|
- //发送站内信
|
|
|
|
- if len(phones) > 0 {
|
|
|
|
- logger.Info(p.TaskName, "开始站内信推送", phones)
|
|
|
|
- users, ok := Mgo.Find("user", map[string]interface{}{
|
|
|
|
- "$or": []map[string]interface{}{
|
|
|
|
- map[string]interface{}{
|
|
|
|
- "s_phone": map[string]interface{}{
|
|
|
|
- "$in": phones,
|
|
|
|
|
|
+ if time.Now().Sub(startTime) > Config.KeCheng.MaxTime*time.Minute {
|
|
|
|
+ logger.Info(p.TaskName, "查找移交客成人员信息,超过", Config.KeCheng.MaxTime, "分钟终止")
|
|
|
|
+ break
|
|
|
|
+ } else {
|
|
|
|
+ logger.Info(p.TaskName, "查找移交客成人员信息,休眠", Config.KeCheng.ReTryTime, "分钟")
|
|
|
|
+ time.Sleep(Config.KeCheng.ReTryTime * time.Minute)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ for _, v := range orderInfos {
|
|
|
|
+ table += fmt.Sprintf(Config.KeCheng.Mail.Table, v.ProductType, v.UserPhone, v.OrderCode, v.StartEnd, v.DisKcName)
|
|
|
|
+ messageConents = append(messageConents, fmt.Sprintf(Config.KeCheng.Message, v.ProductType, v.UserPhone, v.OrderCode, v.StartEnd, v.DisKcName))
|
|
|
|
+ redis.Put(RedisCode, fmt.Sprintf(RedisKcOrderTip, v.Id), 1, Day30Sec)
|
|
|
|
+ }
|
|
|
|
+ if table != "" {
|
|
|
|
+ mails, phones := []string{}, []string{}
|
|
|
|
+ Tidb_Main.SelectByBath(1, func(l *[]map[string]interface{}) bool {
|
|
|
|
+ mails = append(mails, util.ObjToString((*l)[0]["mail"]))
|
|
|
|
+ phones = append(phones, util.ObjToString((*l)[0]["phone"]))
|
|
|
|
+ return true
|
|
|
|
+ }, `select b.name,b.phone,b.mail from jianyu.entniche_department_user a inner join jianyu.entniche_user b on (a.dept_id=? and a.user_id=b.id)`, Config.KeCheng.DeptId)
|
|
|
|
+ //发送邮件
|
|
|
|
+ if len(mails) == 0 && len(phones) == 0 {
|
|
|
|
+ logger.Info(p.TaskName, "没有找到客成部门下要推送的人", Config.KeCheng.DeptId)
|
|
|
|
+ } else if len(mails) > 0 {
|
|
|
|
+ for _, v := range mails {
|
|
|
|
+ logger.Info(p.TaskName, "开始邮箱推送", v)
|
|
|
|
+ isPushOk := false
|
|
|
|
+ //发送邮件
|
|
|
|
+ if v != "" {
|
|
|
|
+ isPushOk = PollingMail(v, Gmails, func(gmail *GmailAuth) bool {
|
|
|
|
+ return GSendMail(Config.MailFrom, v, "", "", Config.KeCheng.Title, fmt.Sprintf(Config.KeCheng.Mail.Content, table), "", "", gmail)
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ logger.Info(p.TaskName, "邮箱推送结束", isPushOk, v)
|
|
|
|
+ }
|
|
|
|
+ } else if len(phones) > 0 { //发送站内信
|
|
|
|
+ logger.Info(p.TaskName, "开始站内信推送", phones)
|
|
|
|
+ users, ok := Mgo.Find("user", map[string]interface{}{
|
|
|
|
+ "$or": []map[string]interface{}{
|
|
|
|
+ map[string]interface{}{
|
|
|
|
+ "s_phone": map[string]interface{}{
|
|
|
|
+ "$in": phones,
|
|
|
|
+ },
|
|
},
|
|
},
|
|
- },
|
|
|
|
- map[string]interface{}{
|
|
|
|
- "s_m_phone": map[string]interface{}{
|
|
|
|
- "$in": phones,
|
|
|
|
|
|
+ map[string]interface{}{
|
|
|
|
+ "s_m_phone": map[string]interface{}{
|
|
|
|
+ "$in": phones,
|
|
|
|
+ },
|
|
},
|
|
},
|
|
},
|
|
},
|
|
- },
|
|
|
|
- }, nil, `{"_id":1}`, false, -1, -1)
|
|
|
|
- userIds := []string{}
|
|
|
|
- if ok && len(*users) > 0 {
|
|
|
|
- for _, v := range *users {
|
|
|
|
- userIds = append(userIds, BsonIdToSId(v["_id"]))
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if len(userIds) > 0 && len(messageConents) > 0 {
|
|
|
|
- for _, v := range messageConents {
|
|
|
|
- req := &message.MultipleSaveMsgReq{
|
|
|
|
- UserIds: strings.Join(userIds, ","),
|
|
|
|
- Title: Config.KeCheng.Title,
|
|
|
|
- Content: v,
|
|
|
|
- MsgType: 11,
|
|
|
|
- Link: "",
|
|
|
|
- Appid: "10000",
|
|
|
|
- AppPushUrl: "",
|
|
|
|
- WxPushUrl: "",
|
|
|
|
- IosPushUrl: "",
|
|
|
|
|
|
+ }, nil, `{"_id":1}`, false, -1, -1)
|
|
|
|
+ userIds := []string{}
|
|
|
|
+ if ok && len(*users) > 0 {
|
|
|
|
+ for _, v := range *users {
|
|
|
|
+ userIds = append(userIds, BsonIdToSId(v["_id"]))
|
|
}
|
|
}
|
|
- resp, err := messageclient.NewMessage(MessageClient).MultipleSaveMsg(context.Background(), req)
|
|
|
|
- if err != nil {
|
|
|
|
- logger.Error(fmt.Sprintf("%+v", req), "发站内信出错", err)
|
|
|
|
- } else if resp.Code == 1 {
|
|
|
|
- logger.Error(fmt.Sprintf("%+v", req), "发送站内信成功")
|
|
|
|
- } else {
|
|
|
|
- logger.Error(fmt.Sprintf("%+v", req), "发送站内信失败")
|
|
|
|
|
|
+ }
|
|
|
|
+ if len(userIds) > 0 && len(messageConents) > 0 {
|
|
|
|
+ for _, v := range messageConents {
|
|
|
|
+ req := &message.MultipleSaveMsgReq{
|
|
|
|
+ UserIds: strings.Join(userIds, ","),
|
|
|
|
+ Title: Config.KeCheng.Title,
|
|
|
|
+ Content: v,
|
|
|
|
+ MsgType: 11,
|
|
|
|
+ Link: "",
|
|
|
|
+ Appid: "10000",
|
|
|
|
+ AppPushUrl: "",
|
|
|
|
+ WxPushUrl: "",
|
|
|
|
+ IosPushUrl: "",
|
|
|
|
+ }
|
|
|
|
+ resp, err := messageclient.NewMessage(MessageClient).MultipleSaveMsg(context.Background(), req)
|
|
|
|
+ if err != nil {
|
|
|
|
+ logger.Error(fmt.Sprintf("%+v", req), "发站内信出错", err)
|
|
|
|
+ } else if resp.Code == 1 {
|
|
|
|
+ logger.Error(fmt.Sprintf("%+v", req), "发送站内信成功")
|
|
|
|
+ } else {
|
|
|
|
+ logger.Error(fmt.Sprintf("%+v", req), "发送站内信失败")
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ logger.Info(p.TaskName, "站内信推送结束", phones, userIds)
|
|
}
|
|
}
|
|
- logger.Info(p.TaskName, "站内信推送结束", phones, userIds)
|
|
|
|
- } else {
|
|
|
|
- logger.Info(p.TaskName, "没有找到客成部门下要推送的人", Config.KeCheng.DeptId)
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- TaskConfig.OrderPayTime = nowFormat
|
|
|
|
- logger.Info(p.TaskName, "结束。。。", TaskConfig.OrderPayTime, nowFormat)
|
|
|
|
|
|
+ TaskConfig.OrderEachTime = nowFormat
|
|
|
|
+ logger.Info(p.TaskName, "结束。。。", TaskConfig.OrderEachTime, nowFormat)
|
|
}
|
|
}
|