123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- 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)
- 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 <?"
- nt, _ := nexttime.(time.Time)
- intime = nt.Format(date.Date_Short_Layout) + " 00:00:00"
- argsSelect = append(argsSelect, intime)
- log.Println(sql)
- log.Println(argsSelect)
- //
- 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"])
- args2 := []interface{}{clueId}
- //获取跟进内容
- sql1 := `select COUNT(1) FROM dwd_f_crm_trail_content WHERE clue_id =?;`
- sql2 := `SELECT COUNT(1) FROM dwd_f_crm_trail_content WHERE clue_id =? `
- if intime != "" {
- sql2 += ` and createtime > ?`
- 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
- }
- 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("按照跟进时间提前一天进入任务车定时任务结束")
- }
|