xuzhiheng 2 år sedan
förälder
incheckning
0cdc90660f
6 ändrade filer med 327 tillägg och 45 borttagningar
  1. 1 1
      clueSync/config.json
  2. 0 41
      clueSync/config.yaml
  3. 2 2
      clueSync/job.go
  4. 9 1
      clueSync/main.go
  5. 102 0
      clueSync/subscribeAll.go
  6. 213 0
      clueSync/trailContent.go

+ 1 - 1
clueSync/config.json

@@ -19,7 +19,7 @@
 	"tiDb": {
 		"host": "192.168.3.149",
 		"port": 4000,
-		"database": "jianyu_subjectdb_test",
+		"database": "Jianyu_subjectdb",
 		"user": "root",
 		"password": "Tibi#20211222",
 		"poolsize": 20,

+ 0 - 41
clueSync/config.yaml

@@ -1,41 +0,0 @@
-cornexp1: "0 */30 * * * ?"
-cornexp2: "0 */10 * * * ?"
-cornexp3: "0 */5 * * * ?"
-lastOrderId: 1660438800
-lastUserId: 5751076de3ec62b1697b737e
-lastId: 5751076de3ec62b1697b737e
-countLimit: 1000
-tiDb:
-  host: 127.0.0.1
-  port: 4000
-  database: Jianyu_subjectdb
-  user: root
-  password: "=PDT49#80Z!RVv52_z"
-  poolsize: 10
-  maxidle: 20
-  maxleft: 20
-baseService:
-  host: 127.0.0.1
-  port: 4000
-  database: base_service
-  user: root
-  password: "=PDT49#80Z!RVv52_z"
-  poolsize: 10
-  maxidle: 20
-  maxleft: 20
-mysql:
-  host: 192.168.3.11
-  port: 3366
-  database: jianyu
-  user: root
-  password: Topnet123
-  poolsize: 10
-  maxidle: 20
-  maxleft: 20
-mgo:
-  address: 192.168.3.206:27080
-	dbName: qfw
-	dbSize: 20
-es:
-	address: http://172.17.4.184:19800
-	dbSize": 10

+ 2 - 2
clueSync/job.go

@@ -22,7 +22,7 @@ func orders() {
 	lastOrderId := cfg.LastOrderId
 	selectTimeStart := time.Unix(time.Now().Unix()-7200, 0).Format("2006-01-02 15:04:05")
 	selectTimeEnd := time.Unix(time.Now().Unix()-3600, 0).Format("2006-01-02 15:04:05")
-	sql := fmt.Sprintf(`select * from dataexport_order where order_status = 0 and product_type in ("大会员","VIP订阅","数据流量包","历史数据") and create_time <= "%s" and create_time >= "%s" and id > %s`, selectTimeEnd, selectTimeStart, fmt.Sprint(lastOrderId))
+	sql := fmt.Sprintf(`select * from dataexport_order where order_status = 0 and is_backstage_order = 0 and product_type in ("大会员","VIP订阅","数据流量包","历史数据") and create_time <= "%s" and create_time >= "%s" and id > %s`, selectTimeEnd, selectTimeStart, fmt.Sprint(lastOrderId))
 	data := Mysql.SelectBySql(sql)
 	if data != nil && *data != nil && len(*data) > 0 {
 		for _, v := range *data {
@@ -357,7 +357,7 @@ func FormatData(data map[string]interface{}, item string) (bool, bool) {
 		cluename = phone
 	}
 	//域外用户和内部用户和没有手机号,不存线索
-	if source == 5 || source == 6 || phone == "" {
+	if source == 2 || source == 5 || source == 6 || phone == "" {
 		log.Println("线索分配失败,线索过滤!!", item, source, phone, userId)
 		return true, false
 	}

+ 9 - 1
clueSync/main.go

@@ -64,7 +64,7 @@ func main() {
 	InitArea()
 	if *mode == 1 {
 		// 未支付订单 30分钟一次
-		orders()
+		// orders()
 		a := cron.New()
 		a.AddFunc(cfg.CornExp1, func() {
 			orders()
@@ -164,5 +164,13 @@ func main() {
 		userbase()
 	} else if *mode == 13 {
 		eventSync()
+	} else if *mode == 14 {
+		getXlsx()
+	} else if *mode == 15 {
+		getXlsx2()
+	} else if *mode == 16 {
+		uidSync()
+	} else if *mode == 17 {
+		privateClueSync()
 	}
 }

+ 102 - 0
clueSync/subscribeAll.go

@@ -5,6 +5,8 @@ import (
 	"strings"
 	"time"
 
+	"app.yhyue.com/moapp/jybase/date"
+
 	"log"
 
 	"app.yhyue.com/moapp/jybase/common"
@@ -207,3 +209,103 @@ func eventSync() {
 	}, `SELECT * from dwd_f_userbase_event_info where platform = 1`)
 	log.Println("app刷行为信息链接结束")
 }
+
+func uidSync() {
+	phoneMap := map[string][]map[string]interface{}{}
+	data := TiDb.SelectBySql(`SELECT * FROM dwd_f_crm_clue_info WHERE phone IN (SELECT phone FROM dwd_f_crm_clue_info GROUP BY phone HAVING COUNT(1) > 1) ORDER BY comeintime asc`)
+	if data != nil && len(*data) > 0 {
+		for _, v := range *data {
+			phone := common.ObjToString(v["phone"])
+			id1 := common.Int64All(v["id"])
+			if phone != "" {
+				phoneMap[phone] = append(phoneMap[phone], v)
+			} else {
+				TiDb.Delete("dwd_f_crm_clue_info", map[string]interface{}{"id": id1})
+				TiDb.Delete("dwd_f_crm_open_sea", map[string]interface{}{"clue_id": id1})
+				TiDb.Delete("dwd_f_crm_private_sea", map[string]interface{}{"clue_id": id1})
+				TiDb.Delete("dwd_f_crm_clue_change_record", map[string]interface{}{"clue_id": id1})
+			}
+		}
+	}
+	log.Println(len(phoneMap))
+	for _, v := range phoneMap {
+		userid1 := common.ObjToString(v[0]["userid"])
+		id1 := common.Int64All(v[0]["id"])
+		id2 := common.Int64All(v[1]["id"])
+		if userid1 != "" {
+			TiDb.Delete("dwd_f_crm_clue_info", map[string]interface{}{"id": id2})
+			TiDb.Delete("dwd_f_crm_open_sea", map[string]interface{}{"clue_id": id2})
+			TiDb.Delete("dwd_f_crm_private_sea", map[string]interface{}{"clue_id": id2})
+			TiDb.Delete("dwd_f_crm_clue_change_record", map[string]interface{}{"clue_id": id2})
+			is_assign := common.IntAll(v[0]["is_assign"])
+			DelClue(is_assign, id1)
+		} else {
+			TiDb.Delete("dwd_f_crm_clue_info", map[string]interface{}{"id": id1})
+			TiDb.Delete("dwd_f_crm_open_sea", map[string]interface{}{"clue_id": id1})
+			TiDb.Delete("dwd_f_crm_private_sea", map[string]interface{}{"clue_id": id1})
+			TiDb.Delete("dwd_f_crm_clue_change_record", map[string]interface{}{"clue_id": id1})
+			is_assign := common.IntAll(v[1]["is_assign"])
+			DelClue(is_assign, id2)
+		}
+	}
+}
+
+func DelClue(is_assign int, id2 int64) {
+	if is_assign == 1 {
+		pd := TiDb.FindOne("dwd_f_crm_private_sea", map[string]interface{}{"clue_id": id2}, "", "")
+		if pd != nil && len(*pd) > 0 {
+			TiDb.Delete("dwd_f_crm_open_sea", map[string]interface{}{"clue_id": id2})
+		} else {
+			od := TiDb.FindOne("dwd_f_crm_open_sea", map[string]interface{}{"clue_id": id2}, "", "")
+			if od != nil && len(*od) > 0 {
+				TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": id2}, map[string]interface{}{"is_assign": 0})
+			} else {
+				TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": id2}, map[string]interface{}{"is_assign": 0})
+				TiDb.Insert("dwd_f_crm_open_sea", map[string]interface{}{
+					"clue_id":      id2,
+					"comeintime":   time.Now().Format(date.Date_Full_Layout),
+					"comeinsource": 2,
+				})
+			}
+		}
+	} else if is_assign == 0 {
+		od := TiDb.FindOne("dwd_f_crm_open_sea", map[string]interface{}{"clue_id": id2}, "", "")
+		if od != nil && len(*od) > 0 {
+			TiDb.Delete("dwd_f_crm_private_sea", map[string]interface{}{"clue_id": id2})
+		} else {
+			TiDb.Insert("dwd_f_crm_open_sea", map[string]interface{}{
+				"clue_id":      id2,
+				"comeintime":   time.Now().Format(date.Date_Full_Layout),
+				"comeinsource": 2,
+			})
+			TiDb.Delete("dwd_f_crm_private_sea", map[string]interface{}{"clue_id": id2})
+		}
+	} else if is_assign == -1 {
+		TiDb.Delete("dwd_f_crm_open_sea", map[string]interface{}{"clue_id": id2})
+		TiDb.Delete("dwd_f_crm_private_sea", map[string]interface{}{"clue_id": id2})
+	}
+}
+
+func privateClueSync() {
+	phoneMap := map[int64][]map[string]interface{}{}
+	data := TiDb.SelectBySql(`SELECT * FROM dwd_f_crm_private_sea WHERE clue_id IN (SELECT clue_id FROM dwd_f_crm_private_sea GROUP BY clue_id HAVING COUNT(1) > 1)`)
+	if data != nil && len(*data) > 0 {
+		for _, v := range *data {
+			clue_id := common.Int64All(v["clue_id"])
+			if clue_id > 0 {
+				phoneMap[clue_id] = append(phoneMap[clue_id], v)
+			}
+		}
+	}
+	log.Println(len(phoneMap))
+	for _, v := range phoneMap {
+		if len(v) > 1 {
+			clue_id1 := common.Int64All(v[1]["clue_id"])
+			// seatNumber1 := common.ObjToString(v[1]["seatNumber"])
+			id1 := common.Int64All(v[1]["id"])
+			if clue_id1 > 0 {
+				TiDb.Delete("dwd_f_crm_private_sea", map[string]interface{}{"id": id1})
+			}
+		}
+	}
+}

+ 213 - 0
clueSync/trailContent.go

@@ -5,8 +5,10 @@ import (
 	"regexp"
 
 	"strings"
+	"time"
 
 	"app.yhyue.com/moapp/jybase/common"
+	"app.yhyue.com/moapp/jybase/date"
 	"github.com/tealeg/xlsx"
 )
 
@@ -86,3 +88,214 @@ func getSale(name, phone string) (positionId, clueId int64) {
 	}
 	return
 }
+
+func getXlsx() {
+	filePath := "./code1.xlsx"
+	nowTime := time.Now().Format(date.Date_Full_Layout)
+	xlFile, _ := xlsx.OpenFile(filePath)
+	//获取行数
+	// length := len(xlFile.Sheets[0].Rows)
+	//开辟除表头外的行数的数组内存
+	// resourceArr := make([]map[string]interface{}, length-1)
+	//遍历sheet
+	for _, sheet := range xlFile.Sheets {
+		//遍历每一行
+		for rowIndex, row := range sheet.Rows {
+			//跳过第一行表头信息
+			if rowIndex == 0 {
+				continue
+			}
+			company := row.Cells[1].Value
+			name := row.Cells[2].Value
+			position := row.Cells[3].Value
+			phone := row.Cells[4].Value
+			if phone != "" {
+				data := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"phone": phone}, "", "")
+				if data != nil && len(*data) > 0 {
+					isAssign := common.IntAll((*data)["is_assign"])
+					clueId := common.Int64All((*data)["id"])
+					if isAssign == 1 {
+						//在私海
+						TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, map[string]interface{}{
+							"is_assign":    1,
+							"comeintime":   nowTime,
+							"updatetime":   nowTime,
+							"top_cluetype": "377",
+							"sub_cluetype": "381",
+						})
+						TiDb.Update("dwd_f_crm_private_sea", map[string]interface{}{"clue_id": clueId}, map[string]interface{}{
+							"comeintime":   nowTime,
+							"comeinsource": 2,
+							"is_task":      1,
+							"task_time":    nowTime,
+							"tasktime":     nowTime,
+							"taskstatus":   0,
+							"tasksource":   "线索自动分配-批量导入-6月份获取拟建项目清单留资",
+						})
+					} else {
+						//在公海
+						positionId, seatNumber, _, _ := autoDraw("C")
+						TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, map[string]interface{}{
+							"seatNumber":   seatNumber,
+							"position_id":  positionId,
+							"is_assign":    1,
+							"comeintime":   nowTime,
+							"updatetime":   nowTime,
+							"trailstatus":  "01",
+							"top_cluetype": "377",
+							"sub_cluetype": "381",
+						})
+						TiDb.Delete("dwd_f_crm_open_sea", map[string]interface{}{"clue_id": clueId})
+						TiDb.Insert("dwd_f_crm_private_sea", map[string]interface{}{
+							"clue_id":      clueId,
+							"seatNumber":   seatNumber,
+							"position_id":  positionId,
+							"comeintime":   nowTime,
+							"comeinsource": 2,
+							"is_task":      1,
+							"task_time":    nowTime,
+							"tasktime":     nowTime,
+							"taskstatus":   0,
+							"tasksource":   "线索自动分配-批量导入-6月份获取拟建项目清单留资",
+						})
+					}
+				} else {
+					//无线索
+					base := TiDb.FindOne("dwd_f_userbase_baseinfo", map[string]interface{}{"phone": phone}, "", "")
+					if base != nil && len(*base) > 0 {
+						uId := common.ObjToString((*base)["uid"])
+						userId := common.ObjToString((*base)["userid"])
+						positionId, seatNumber, _, _ := autoDraw("C")
+						clueId := TiDb.Insert("dwd_f_crm_clue_info", map[string]interface{}{
+							"userid":       userId,
+							"uid":          uId,
+							"seatNumber":   seatNumber,
+							"position_id":  positionId,
+							"is_assign":    1,
+							"comeintime":   nowTime,
+							"createtime":   nowTime,
+							"updatetime":   nowTime,
+							"cluename":     common.If(company != "", company, phone),
+							"top_cluetype": "377",
+							"sub_cluetype": "381",
+							"trailstatus":  "01",
+							"name":         name,
+							"phone":        phone,
+							"position":     position,
+						})
+						if clueId > -1 {
+							TiDb.Insert("dwd_f_crm_private_sea", map[string]interface{}{
+								"clue_id":      clueId,
+								"seatNumber":   seatNumber,
+								"position_id":  positionId,
+								"comeintime":   nowTime,
+								"comeinsource": 2,
+								"is_task":      1,
+								"task_time":    nowTime,
+								"tasktime":     "2023-06-12 10:00:00",
+								"taskstatus":   0,
+								"tasksource":   "线索自动分配-批量导入-6月份获取拟建项目清单留资",
+							})
+						}
+					}
+				}
+			}
+		}
+	}
+}
+
+func getXlsx2() {
+	filePath := "./code2.xlsx"
+	nowTime := time.Now().Format(date.Date_Full_Layout)
+	xlFile, _ := xlsx.OpenFile(filePath)
+	//获取行数
+	// length := len(xlFile.Sheets[0].Rows)
+	//开辟除表头外的行数的数组内存
+	// resourceArr := make([]map[string]interface{}, length-1)
+	//遍历sheet
+	for _, sheet := range xlFile.Sheets {
+		//遍历每一行
+		for rowIndex, row := range sheet.Rows {
+			//跳过第一行表头信息
+			if rowIndex == 0 {
+				continue
+			}
+			userId := row.Cells[0].Value
+			company := row.Cells[5].Value
+			name := row.Cells[1].Value
+			position := row.Cells[6].Value
+			phone := row.Cells[7].Value
+			positionId, seatNumber := int64(2047781), "8040"
+			if phone != "" {
+				data := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"userid": userId}, "", "")
+				if data != nil && len(*data) > 0 {
+					isAssign := common.IntAll((*data)["is_assign"])
+					clueId := common.Int64All((*data)["id"])
+					if isAssign != 1 {
+						//不在私海
+						TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, map[string]interface{}{
+							"seatNumber":   seatNumber,
+							"position_id":  positionId,
+							"is_assign":    1,
+							"comeintime":   nowTime,
+							"updatetime":   nowTime,
+							"trailstatus":  "01",
+							"top_cluetype": "377",
+							"sub_cluetype": "382",
+						})
+						TiDb.Delete("dwd_f_crm_open_sea", map[string]interface{}{"clue_id": clueId})
+						TiDb.Insert("dwd_f_crm_private_sea", map[string]interface{}{
+							"clue_id":      clueId,
+							"seatNumber":   seatNumber,
+							"position_id":  positionId,
+							"comeintime":   nowTime,
+							"comeinsource": 2,
+							"is_task":      1,
+							"task_time":    nowTime,
+							"tasktime":     nowTime,
+							"taskstatus":   0,
+							"tasksource":   "线索自动分配-批量导入-医械厂商线索",
+						})
+					}
+				} else {
+					//无线索
+					base := TiDb.FindOne("dwd_f_userbase_baseinfo", map[string]interface{}{"userid": userId}, "", "")
+					if base != nil && len(*base) > 0 {
+						uId := common.ObjToString((*base)["uid"])
+						clueId := TiDb.Insert("dwd_f_crm_clue_info", map[string]interface{}{
+							"userid":       userId,
+							"uid":          uId,
+							"seatNumber":   seatNumber,
+							"position_id":  positionId,
+							"is_assign":    1,
+							"comeintime":   nowTime,
+							"createtime":   nowTime,
+							"updatetime":   nowTime,
+							"cluename":     common.If(company != "", company, phone),
+							"top_cluetype": "377",
+							"sub_cluetype": "382",
+							"trailstatus":  "01",
+							"name":         name,
+							"phone":        phone,
+							"position":     position,
+						})
+						if clueId > -1 {
+							TiDb.Insert("dwd_f_crm_private_sea", map[string]interface{}{
+								"clue_id":      clueId,
+								"seatNumber":   seatNumber,
+								"position_id":  positionId,
+								"comeintime":   nowTime,
+								"comeinsource": 2,
+								"is_task":      1,
+								"task_time":    nowTime,
+								"tasktime":     "2023-06-12 10:00:00",
+								"taskstatus":   0,
+								"tasksource":   "线索自动分配-批量导入-医械厂商线索",
+							})
+						}
+					}
+				}
+			}
+		}
+	}
+}