Browse Source

wip : 自动退出公海、自动退回公海

zhangxinlei1996 2 năm trước cách đây
mục cha
commit
9ef716cca1
1 tập tin đã thay đổi với 100 bổ sung1 xóa
  1. 100 1
      telemarketingEtl/entity/dwd_f_crm_open_sea.go

+ 100 - 1
telemarketingEtl/entity/dwd_f_crm_open_sea.go

@@ -6,6 +6,7 @@ import (
 	"github.com/gogf/gf/v2/frame/g"
 	"github.com/gogf/gf/v2/util/gconv"
 	"log"
+	"strings"
 	"sync"
 	"telemarketingEtl/config"
 	"telemarketingEtl/util"
@@ -345,8 +346,8 @@ func ThreeOpenSea() {
 
 			}
 		}
+		return true
 	}, `select userid,uid from dwd_f_crm_clue_info where is_assign !=1`)
-
 }
 
 // 根据mongodb userid 获取 线索id
@@ -374,3 +375,101 @@ func AddOpenSea(m map[string]bool, level int, clue_level string) {
 		}
 	}
 }
+
+// 自动退出公海
+// 线索状态为“空号停机”自动从线索池删除。
+func DeleteOpenSea() {
+	config.JianyuSubjectdb.SelectByBath(500, func(l *[]map[string]interface{}) bool {
+		ids := []interface{}{}
+		for _, v := range *l {
+			id := v["id"]
+			ids = append(ids, id)
+		}
+		whs := []string{}
+		for i := 0; i < len(ids); i++ {
+			whs = append(whs, "?")
+		}
+		wh := strings.Join(whs, ",")
+		count := config.JianyuSubjectdb.UpdateOrDeleteBySql(`delete from dwd_f_crm_clue_info where id in (`+wh+`)`, ids...)
+		if count > 0 {
+			return true
+		}
+		return true
+	}, `select id from dwd_f_crm_clue_info where trailstatus == ?`, "00")
+}
+
+//自动退回公海
+/*
+1.处于“待签署客户”和“成交客户”状态下的客户不自动退回公海;
+2.“高意向客户”超过30天未更新跟进记录自动退回公海;
+3.“意向客户”超过30天未更新跟进记录自动退回公海;
+4.“潜在客户”超过60天未更新跟进记录自动退回公海;
+5.“沉睡客户”超过90天未更新跟进记录自动退回公海;
+6.“商机线索”超过2天未更新跟进记录自动退回公海;
+7.“无意向客户”自动退回公海;
+*/
+func ReturnOpenSea() {
+	t := time.Now()
+	t = time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, time.Local)
+	//高意向客户
+	highIntentionCustomer := g.Cfg().MustGet(ctx, "highIntentionCustomer").Int()
+	//意向客户
+	intentionCustomer := g.Cfg().MustGet(ctx, "intentionCustomer").Int()
+	//潜在客户
+	latentCustomer := g.Cfg().MustGet(ctx, "latentCustomer").Int()
+	//沉睡客户
+	sleepCustomer := g.Cfg().MustGet(ctx, "sleepCustomer").Int()
+	//商机线索
+	businessLeads := g.Cfg().MustGet(ctx, "businessLeads").Int()
+	//无意向客户
+	noIdeaCustomer := g.Cfg().MustGet(ctx, "noIdeaCustomer").Int()
+	//2.“高意向客户”超过30天未更新跟进记录自动退回公海;
+	for trailstatus, nexttime := range map[string]interface{}{
+		"04": t.AddDate(0, 0, -highIntentionCustomer),
+		"05": t.AddDate(0, 0, -intentionCustomer),
+		"06": t.AddDate(0, 0, -latentCustomer),
+		"07": t.AddDate(0, 0, -sleepCustomer),
+		"01": t.AddDate(0, 0, -businessLeads),
+		"08": t.AddDate(0, 0, -noIdeaCustomer),
+	} {
+		config.JianyuSubjectdb.SelectByBath(500, func(l *[]map[string]interface{}) bool {
+			ids := []interface{}{}
+			args := []interface{}{}
+			for _, v := range *l {
+				id := v["id"]
+				ids = append(ids, id)
+				//
+				args = append(args, id, time.Now().Format(date.Date_Full_Layout), 2)
+			}
+			whs := []string{}
+			for i := 0; i < len(ids); i++ {
+				whs = append(whs, "?")
+			}
+			wh := strings.Join(whs, ",")
+			//退出私海
+			count := config.JianyuSubjectdb.UpdateOrDeleteBySql(`delete from dwd_f_crm_private_sea  where clue_id in (`+wh+`)`, ids...)
+			//进入公海
+			config.JianyuSubjectdb.InsertIgnoreBatch("dwd_f_crm_open_sea", []string{"clue_id", "comeintime", "comeinsource"}, args)
+			//
+			if count > 0 {
+				return true
+			}
+			return true
+		}, `SELECT MAX(c.next_time) nexttime, b.id 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 b.id =c.clue_id 
+				WHERE b.trailstatus =? AND c.next_time >?  GROUP BY  b.id`, trailstatus, nexttime)
+	}
+}
+
+/*
+01		1	商机线索
+02		1	成交客户
+03		1	待签署客户
+04		1	高意向客户
+05		1	意向客户
+06		1	潜在客户
+07		1	沉睡客户
+08		1	无意向客户
+00		1	空号停机
+*/