123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- package timetask
- import (
- "context"
- "fmt"
- "log"
- "strings"
- "time"
- "app.yhyue.com/moapp/jybase/date"
- cm "bp.jydev.jianyu360.cn/CRM/application/api/common"
- "bp.jydev.jianyu360.cn/CRM/application/service"
- "github.com/gogf/gf/v2/os/gcron"
- "github.com/gogf/gf/v2/os/gctx"
- "github.com/gogf/gf/v2/util/gconv"
- )
- func Run() {
- if cm.Push.TimeTaskSwitch {
- sendMess()
- }
- }
- func getTime() (string, string) {
- today := time.Now()
- // 计算两天前的时间
- twoDaysAgo := today.AddDate(0, 0, cm.Push.DueDay)
- // 设置时间为 0 点
- startTime := time.Date(twoDaysAgo.Year(), twoDaysAgo.Month(), twoDaysAgo.Day(), 0, 0, 0, 0, twoDaysAgo.Location())
- // 设置时间为 24 点
- endTime := startTime.Add(time.Duration(1) * 24 * time.Hour)
- return startTime.Format(date.Date_Full_Layout), endTime.Format(date.Date_Full_Layout)
- }
- //发送推送 站内信和微信
- func sendMess() {
- ctx := gctx.New()
- _, err := gcron.Add(ctx, cm.Push.PushTime, func(ctx context.Context) {
- log.Println("start cron")
- //获取倒计时时间
- st, et := getTime()
- cm.CrmMysql.SelectByBath(500, func(l *[]map[string]interface{}) bool {
- for _, v := range *l {
- name := gconv.String(v["name"])
- taskId := gconv.Int(v["id"])
- positionId := gconv.Int64(v["position_id"])
- source := gconv.Int(v["source"]) //1:线索 2:机会 3:客户
- sourceId := gconv.Int(v["source_id"])
- title := cm.Push.SaleClue.Due.Title
- content := cm.Push.SaleClue.Due.Content
- pcHref := ""
- mobileHref := cm.Push.SaleClue.Due.MobileHref
- responsible_id := gconv.Int64(v["responsible_id"])
- //判断是自办还是转办
- if responsible_id > 0 {
- //转办
- if source == 1 {
- pcHref = fmt.Sprintf(cm.Push.SaleClue.Create.TransferPcHref, responsible_id)
- } else if source == 2 {
- pcHref = fmt.Sprintf(cm.Push.SaleChance.Create.TransferPcHref, responsible_id)
- } else if source == 3 {
- pcHref = fmt.Sprintf(cm.Push.Custom.Create.TransferPcHref, responsible_id)
- }
- } else {
- //自办
- if source == 1 {
- ///succbi/crm_system/app/crm.app/task_follow/task_follow_up.spg?E_position_id=%v&E_control_editing=1&E_task_id=%v&E_cust_oppo_lead=%v
- pcHref = fmt.Sprintf(cm.Push.SaleClue.Create.MyselfPcHref, positionId, taskId, sourceId)
- } else if source == 2 {
- pcHref = fmt.Sprintf(cm.Push.SaleClue.Create.MyselfPcHref, positionId, taskId, sourceId)
- } else if source == 3 {
- pcHref = fmt.Sprintf(cm.Push.SaleClue.Create.MyselfPcHref, positionId, taskId, sourceId)
- }
- }
- if source == 2 {
- title = cm.Push.SaleChance.Due.Title
- content = cm.Push.SaleChance.Due.Content
- mobileHref = cm.Push.SaleChance.Due.MobileHref
- } else if source == 3 {
- title = cm.Push.Custom.Due.Title
- content = cm.Push.Custom.Due.Content
- mobileHref = cm.Push.Custom.Due.MobileHref
- }
- u := &service.User{}
- resp := u.IdentityByPositionId(positionId)
- if resp == nil {
- log.Println("%v未找到身份", positionId)
- continue
- }
- user := &service.User{
- BaseUserIds: []int64{resp.UserId},
- }
- m := user.GetUserId(resp.EntId)
- for k, v := range m {
- service.StationMailPush(k, gconv.String(v), strings.Replace(title, " ", "%20", -1), strings.Replace(fmt.Sprintf(content, name), " ", "%20", -1), pcHref, mobileHref, "11")
- }
- }
- return true
- }, `SELECT a.id,a.name,b.position_id,a.source,a.source_id,c.responsible_id FROM task a
- LEFT JOIN task_team b ON (a.id =b.task_id AND b.role=1)
- LEFT JOIN task_transfer c ON(a.id =c.task_id AND c.is_transfer =1)
- WHERE a.status!=3 AND a.next_follow_time >= ? AND a.next_follow_time < ?`, st, et)
- log.Println("end cron", st, et)
- }, "sendMsg")
- if err != nil {
- log.Println("cron err:", err)
- }
- }
|