package main import ( "log" "time" "app.yhyue.com/moapp/jybase/common" "app.yhyue.com/moapp/jybase/date" ) func autoTask() { log.Println("超时未跟进定时任务开始") t := time.Now() nowTime := time.Now().Format(date.Date_Full_Layout) // statusMap := map[string]int{ // "07": 5, //待签署客户 // "06": 3, //高意向客户 // "05": 5, //意向客户 // "04": 7, //潜在客户 // } // statusMaps := map[string]int{} //判断节假日 // for status, statusInt := range statusMap { // count, counts := 0, 0 // for { // count++ // currentTime := t.AddDate(0, 0, -count) // if currentTime.Weekday() == time.Sunday || currentTime.Weekday() == time.Saturday { // isok := false // for k, v := range DateMap { // if currentTime.Format(date.Date_Short_Layout) == k && v == 2 { // isok = true // } // } // if isok { // counts++ // } // } else { // isok := true // for k, v := range DateMap { // if currentTime.Format(date.Date_Short_Layout) == k && v == 1 { // isok = false // } // } // if isok { // counts++ // } // } // if counts >= statusInt { // break // } // } // statusMap[status] = count // } // log.Println(statusMap) for trailstatus, nexttime := range map[string]interface{}{ "07": t.AddDate(0, 0, -5), //待签署客户 "06": t.AddDate(0, 0, -3), //高意向客户 "05": t.AddDate(0, 0, -5), //意向客户 "04": t.AddDate(0, 0, -7), //潜在客户 } { sql := `SELECT a.clue_id,a.position_id,a.seatNumber,a.out_task_status FROM dwd_f_crm_private_sea a LEFT JOIN dwd_f_crm_clue_info b ON a.clue_id=b.id WHERE b.trailstatus =?` argsSelect := []interface{}{trailstatus} intime := "" sql += " AND a.comeintime ?` args2 = append(args2, position_id) args2 = append(args2, intime) } //保留未跟进线索 // if c1, c2 := TiDb.CountBySql(sql1, clueId), TiDb.CountBySql(sql2, args2...); (c1 != 0 && c2 > 0) || out_task_status == 1 { // log.Println("不满足线索过滤", clueId) // continue // } log.Println("intime ", clueId, intime, sql2) if c2 := TiDb.CountBySql(sql2, args2...); c2 > 0 || out_task_status == 1 { log.Println("不满足线索过滤", clueId) continue } if TiDb.Update("dwd_f_crm_private_sea", map[string]interface{}{"clue_id": clueId}, map[string]interface{}{ "is_task": 1, "task_time": nowTime, "tasktime": time.Now().Format(date.Date_Short_Layout) + " 10:00:00", "taskstatus": 0, "tasksource": "超时未跟进自动加车", }) { TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{ "clue_id": clueId, "position_id": position_id, "change_type": "加入任务车", "new_value": "超时未跟进自动加车", "createtime": nowTime, "BCPCID": common.GetRandom(32), "operator_id": -1, }) } } return true }, sql, argsSelect...) } log.Println("超时未跟进定时任务结束") } func autoTasks() { log.Println("按照跟进时间提前一天进入任务车定时任务开始") nowTime2 := time.Now().Format(date.Date_Full_Layout) nextTime := time.Now().AddDate(0, 0, 1).Format(date.Date_Full_Layout) TiDb.SelectByBath(100, func(l *[]map[string]interface{}) bool { for _, v := range *l { clueId := common.Int64All(v["clue_id"]) position_id := common.Int64All(v["position_id"]) out_task_status := common.IntAll(v["out_task_status"]) if out_task_status != 1 { if TiDb.Update("dwd_f_crm_private_sea", map[string]interface{}{"clue_id": clueId}, map[string]interface{}{ "is_task": 1, "task_time": nowTime2, "tasktime": nowTime2, "taskstatus": 0, "tasksource": "即将到达下次跟进时间", }) { TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{ "clue_id": clueId, "position_id": position_id, "change_type": "加入任务车", "new_value": "即将到达下次跟进时间", "createtime": nowTime2, "BCPCID": common.GetRandom(32), "operator_id": -1, }) } } } return true }, `SELECT a.clue_id,a.position_id,a.seatNumber,a.out_task_status FROM dwd_f_crm_private_sea a LEFT JOIN dwd_f_crm_clue_info b ON a.clue_id=b.id LEFT JOIN dwd_f_crm_trail_content c ON c.clue_id=b.id WHERE c.next_time >= "`+nowTime2+`" and c.next_time <= "`+nextTime+`"`) log.Println("按照跟进时间提前一天进入任务车定时任务结束") }