autoTask.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. package main
  2. import (
  3. "log"
  4. "time"
  5. "app.yhyue.com/moapp/jybase/common"
  6. "app.yhyue.com/moapp/jybase/date"
  7. )
  8. func autoTask() {
  9. log.Println("超时未跟进定时任务开始")
  10. t := time.Now()
  11. nowTime := time.Now().Format(date.Date_Full_Layout)
  12. for trailstatus, nexttime := range map[string]interface{}{
  13. "07": t.AddDate(0, 0, -5), //待签署客户
  14. "06": t.AddDate(0, 0, -3), //高意向客户
  15. "05": t.AddDate(0, 0, -5), //意向客户
  16. "04": t.AddDate(0, 0, -7), //潜在客户
  17. } {
  18. sql := `SELECT a.clue_id,a.position_id,a.seatNumber,a.out_task_status FROM dwd_f_crm_private_sea a
  19. LEFT JOIN dwd_f_crm_clue_info b ON a.clue_id=b.id
  20. WHERE b.trailstatus =?`
  21. argsSelect := []interface{}{trailstatus}
  22. intime := ""
  23. sql += " AND a.comeintime <?"
  24. nt, _ := nexttime.(time.Time)
  25. intime = nt.Format(date.Date_Short_Layout) + " 00:00:00"
  26. argsSelect = append(argsSelect, intime)
  27. log.Println(sql)
  28. log.Println(argsSelect)
  29. //
  30. TiDb.SelectByBath(100, func(l *[]map[string]interface{}) bool {
  31. for _, v := range *l {
  32. clueId := common.Int64All(v["clue_id"])
  33. position_id := common.Int64All(v["position_id"])
  34. out_task_status := common.IntAll(v["out_task_status"])
  35. args2 := []interface{}{clueId}
  36. //获取跟进内容
  37. sql1 := `select COUNT(1) FROM dwd_f_crm_trail_content WHERE clue_id =?;`
  38. sql2 := `SELECT COUNT(1) FROM dwd_f_crm_trail_content WHERE clue_id =? `
  39. if intime != "" {
  40. sql2 += ` and createtime > ?`
  41. args2 = append(args2, intime)
  42. }
  43. //保留未跟进线索
  44. if c1, c2 := TiDb.CountBySql(sql1, clueId), TiDb.CountBySql(sql2, args2...); (c1 != 0 && c2 > 0) || out_task_status == 1 {
  45. log.Println("不满足线索过滤", clueId)
  46. continue
  47. }
  48. if TiDb.Update("dwd_f_crm_private_sea", map[string]interface{}{"clue_id": clueId}, map[string]interface{}{
  49. "is_task": 1,
  50. "task_time": nowTime,
  51. "tasktime": time.Now().Format(date.Date_Short_Layout) + " 10:00:00",
  52. "taskstatus": 0,
  53. "tasksource": "超时未跟进自动加车",
  54. }) {
  55. TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  56. "clue_id": clueId,
  57. "position_id": position_id,
  58. "change_type": "加入任务车",
  59. "new_value": "超时未跟进自动加车",
  60. "createtime": nowTime,
  61. "BCPCID": common.GetRandom(32),
  62. "operator_id": -1,
  63. })
  64. }
  65. }
  66. return true
  67. }, sql, argsSelect...)
  68. }
  69. log.Println("超时未跟进定时任务结束")
  70. }
  71. func autoTasks() {
  72. log.Println("按照跟进时间提前一天进入任务车定时任务开始")
  73. nowTime2 := time.Now().Format(date.Date_Full_Layout)
  74. nextTime := time.Now().AddDate(0, 0, 1).Format(date.Date_Full_Layout)
  75. TiDb.SelectByBath(100, func(l *[]map[string]interface{}) bool {
  76. for _, v := range *l {
  77. clueId := common.Int64All(v["clue_id"])
  78. position_id := common.Int64All(v["position_id"])
  79. out_task_status := common.IntAll(v["out_task_status"])
  80. if out_task_status != 1 {
  81. if TiDb.Update("dwd_f_crm_private_sea", map[string]interface{}{"clue_id": clueId}, map[string]interface{}{
  82. "is_task": 1,
  83. "task_time": nowTime2,
  84. "tasktime": nowTime2,
  85. "taskstatus": 0,
  86. "tasksource": "即将到达下次跟进时间",
  87. }) {
  88. TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  89. "clue_id": clueId,
  90. "position_id": position_id,
  91. "change_type": "加入任务车",
  92. "new_value": "即将到达下次跟进时间",
  93. "createtime": nowTime2,
  94. "BCPCID": common.GetRandom(32),
  95. "operator_id": -1,
  96. })
  97. }
  98. }
  99. }
  100. return true
  101. }, `SELECT a.clue_id,a.position_id,a.seatNumber,a.out_task_status FROM dwd_f_crm_private_sea a
  102. LEFT JOIN dwd_f_crm_clue_info b ON a.clue_id=b.id
  103. LEFT JOIN dwd_f_crm_trail_content c ON c.clue_id=b.id
  104. WHERE c.next_time >= "`+nowTime2+`" and c.next_time <= "`+nextTime+`"`)
  105. log.Println("按照跟进时间提前一天进入任务车定时任务结束")
  106. }