xuzhiheng 2 سال پیش
والد
کامیت
3489d6662e
2فایلهای تغییر یافته به همراه56 افزوده شده و 30 حذف شده
  1. 5 15
      clueSync/autoTask.go
  2. 51 15
      clueSync/job.go

+ 5 - 15
clueSync/autoTask.go

@@ -93,7 +93,7 @@ func autoTask() {
 					log.Println("不满足线索过滤", clueId)
 					continue
 				}
-				if TiDb.Update("dwd_f_crm_private_sea", map[string]interface{}{"clue_id": clueId}, map[string]interface{}{
+				if TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, map[string]interface{}{
 					"is_task":    1,
 					"task_time":  nowTime,
 					"tasktime":   time.Now().Format(date.Date_Short_Layout) + " 10:00:00",
@@ -164,7 +164,7 @@ func autoExitSea() {
 			nowTime := time.Now().Format(date.Date_Full_Layout)
 			// is_assign := common.IntAll(v["is_assign"])
 			if TiDb.ExecTx("退出线索", func(tx *sql.Tx) bool {
-				recordId := TiDb.UpdateOrDeleteBySqlByTx(tx, `UPDATE dwd_f_crm_clue_info SET is_assign = -1,position_id = null,seatNumber = null,updatetime = ? WHERE id = ?`, nowTime, clueId)
+				recordId := TiDb.UpdateOrDeleteBySqlByTx(tx, `UPDATE dwd_f_crm_clue_info SET is_assign=-1,position_id=null,seatNumber=null,updatetime = ?,comeinsource_open=null,level_open=null,trail_time=null,next_trail_time=null,is_task=null,tasktime=null,taskstatus=null,comeinsource_private=null,tasksource=null,task_time=null WHERE id = ?`, nowTime, clueId)
 				// ok1 := true
 				// if is_assign == 1 {
 				// 	ok1 = TiDb.DeleteByTx(tx, "dwd_f_crm_private_sea", map[string]interface{}{"clue_id": clueId})
@@ -226,13 +226,9 @@ func autoExitSea() {
 			positionId := common.Int64All(v["position_id"])
 			seatNumber := common.ObjToString(v["seatNumber"])
 			nowTime := time.Now().Format(date.Date_Full_Layout)
-			is_assign := common.IntAll(v["is_assign"])
+			// is_assign := common.IntAll(v["is_assign"])
 			if TiDb.ExecTx("自动退海", func(tx *sql.Tx) bool {
-				recordId := TiDb.UpdateOrDeleteBySqlByTx(tx, `UPDATE dwd_f_crm_clue_info SET is_assign = 0,position_id = null,seatNumber = null,updatetime = ?  WHERE id = ?`, nowTime, clueId)
-				ok1 := true
-				if is_assign == 1 {
-					ok1 = TiDb.DeleteByTx(tx, "dwd_f_crm_private_sea", map[string]interface{}{"clue_id": clueId})
-				}
+				recordId := TiDb.UpdateOrDeleteBySqlByTx(tx, `UPDATE dwd_f_crm_clue_info SET is_assign=0,position_id=null,seatNumber=null,updatetime = ?,comeintime_open = ?,comeinsource_open=8,level_open=4,trail_time=null,next_trail_time=null,is_task=null,tasktime=null,taskstatus=null,comeinsource_private=null,tasksource=null,task_time=null WHERE id = ?`, nowTime, nowTime, clueId)
 				recordId1 := TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
 					"clue_id":      clueId,
 					"position_id":  positionId,
@@ -273,13 +269,7 @@ func autoExitSea() {
 					"BCPCID":      common.GetRandom(32),
 					"operator_id": -1,
 				})
-				recordId5 := TiDb.InsertByTx(tx, "dwd_f_crm_open_sea", map[string]interface{}{
-					"clue_id":      clueId,
-					"comeintime":   nowTime,
-					"comeinsource": 2,
-					"level":        4,
-				})
-				return ok1 && recordId > -1 && recordId1 > -1 && recordId2 > -1 && recordId3 > -1 && recordId4 > -1 && recordId5 > -1
+				return recordId > -1 && recordId1 > -1 && recordId2 > -1 && recordId3 > -1 && recordId4 > -1
 			}) {
 				log.Println("自动退出私海成功")
 			} else {

+ 51 - 15
clueSync/job.go

@@ -274,8 +274,8 @@ func saleLeads() {
 }
 
 func FormatData(data map[string]interface{}, item string) (bool, bool) {
-	userId, uId, positionId, source, cluename, phone := common.ObjToString(data["user_id"]), "", "", 0, "", ""
-	role, industry, department, position, name, top_cluetype, sub_cluetype, follow_project_area, level := "", "", "", "", "", "", "", "", ""
+	userId, uId, positionId, source, cluename, phone, sourceCode, keyword := common.ObjToString(data["user_id"]), "", "", 0, "", "", "", []string{}
+	role, industry, department, departments, position, name, top_cluetype, sub_cluetype, follow_project_area, level := "", "", "", "", "", "", "", "", "", ""
 	query, topname, subname := map[string]interface{}{}, "", ""
 	if item == "orders" {
 		if !mongodb.IsObjectIdHex(userId) {
@@ -333,9 +333,11 @@ func FormatData(data map[string]interface{}, item string) (bool, bool) {
 		role = common.ObjToString(data["companyType"])
 		industry = common.ObjToString(data["industry"])
 		department = common.ObjToString(data["branch"])
+		departments = common.ObjToString(data["department"])
 		position = common.ObjToString(data["position"])
 		name = common.ObjToString(data["name"])
-		// sourceCode = common.ObjToString(data["source"])
+		sourceCode = common.ObjToString(data["source"])
+		keyword = common.ObjArrToStringArr(data["keyword"].([]interface{}))
 		contactsData := TiDb.SelectBySql("select * from dwd_f_userbase_contacts where phone = ? and is_delete = 1", phone)
 		if contactsData != nil && len(*contactsData) > 0 {
 			if common.ObjToString((*contactsData)[0]["baseinfo_id"]) != "" {
@@ -390,6 +392,7 @@ func FormatData(data map[string]interface{}, item string) (bool, bool) {
 			role = common.ObjToString(sdata["companyType"])
 			industry = common.ObjToString(sdata["industry"])
 			department = common.ObjToString(sdata["branch"])
+			departments = common.ObjToString(sdata["department"])
 			position = common.ObjToString(sdata["position"])
 			name = common.ObjToString(sdata["name"])
 		}
@@ -410,9 +413,9 @@ func FormatData(data map[string]interface{}, item string) (bool, bool) {
 	if position_id > 0 && seatNumber != "" {
 		uCount, oks := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"uid": uId}, "", ""), true
 		if uCount != nil && len(*uCount) > 0 {
-			oks = UpdateClue(*uCount, saleData, item, userId, uId, top_cluetype, sub_cluetype, topname, subname, cluename, name, saleName, phone, position, department, industry, follow_project_area, role, seatNumber, position_id, source)
+			oks = UpdateClue(*uCount, saleData, item, userId, uId, top_cluetype, sub_cluetype, topname, subname, cluename, name, saleName, phone, position, department, departments, industry, follow_project_area, role, seatNumber, position_id, source, sourceCode, keyword)
 		} else {
-			oks = SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, cluename, name, saleName, phone, position, department, industry, follow_project_area, role, seatNumber, position_id, source)
+			oks = SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, cluename, name, saleName, phone, position, department, departments, industry, follow_project_area, role, seatNumber, position_id, source, sourceCode, keyword)
 		}
 		if oks {
 			TiDb.UpdateOrDeleteBySql(`update dwd_f_crm_clue_autodraw_record set count = count + 1 where seatNumber = ? and clue_level = ?`, seatNumber, level)
@@ -424,12 +427,18 @@ func FormatData(data map[string]interface{}, item string) (bool, bool) {
 	return true, true
 }
 
-func SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, cluename, name, saleName, phone, position, department, industry, follow_project_area, role, seatNumber string, positionId int64, source int) bool {
+func SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, cluename, name, saleName, phone, position, department, departments, industry, follow_project_area, role, seatNumber string, positionId int64, source int, sourceCode string, keyword []string) bool {
 	nowTime := time.Now().Format("2006-01-02 15:04:05")
 	nowTimes := time.Unix(time.Now().Unix()+3600*12, 0).Format("2006-01-02 15:04:05")
 	clueId, uodateId1, uodateId2, uodateId3, uodateId4, uodateId5, uodateId6 := int64(0), int64(0), int64(0), int64(0), int64(0), int64(0), int64(0)
 	// BCPCID := common.GetRandom(32)
 	if TiDb.ExecTx("保存线索", func(tx *sql.Tx) bool {
+		keywords := ""
+		if sourceCode == "app_xzcyh" {
+			if len(keyword) > 0 && keyword[0] != "" {
+				keywords = strings.Join(keyword, ",")
+			}
+		}
 		//线索
 		clueId = TiDb.InsertByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{
 			"userid":               userId,
@@ -447,7 +456,7 @@ func SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, c
 			"name":                 name,
 			"phone":                phone,
 			"position":             position,
-			"department":           department,
+			"department":           common.If(sourceCode == "app_xzcyh", departments, department),
 			"industry":             industry,
 			"follow_project_area":  follow_project_area,
 			"role":                 role,
@@ -457,6 +466,7 @@ func SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, c
 			"tasktime":             common.If(item == "users", nowTimes, nowTime),
 			"taskstatus":           0,
 			"tasksource":           "线索自动分配" + "-" + topname + "-" + subname,
+			"business_scope":       common.If(sourceCode == "app_xzcyh", keywords, nil),
 		})
 		//变更记录
 		uodateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
@@ -542,7 +552,7 @@ func SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, c
 	}
 }
 
-func UpdateClue(data map[string]interface{}, saleData []map[string]interface{}, item, userId, uId, top_cluetype, sub_cluetype, topname, subname, cluename, name, saleName, phone, position, department, industry, follow_project_area, role, seatNumber string, positionId int64, source int) bool {
+func UpdateClue(data map[string]interface{}, saleData []map[string]interface{}, item, userId, uId, top_cluetype, sub_cluetype, topname, subname, cluename, name, saleName, phone, position, department, departments, industry, follow_project_area, role, seatNumber string, positionId int64, source int, sourceCode string, keyword []string) bool {
 	nowTime := time.Now().Format("2006-01-02 15:04:05")
 	nowTimes := time.Unix(time.Now().Unix()+3600*12, 0).Format("2006-01-02 15:04:05")
 	//trailstatus = 无意向 为变更线索状态
@@ -636,12 +646,38 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
 		clueUpdateData["cluename"] = cluename
 	}
 	if item != "orders" && item != "users" {
-		clueUpdateData["name"] = name
-		clueUpdateData["position"] = position
-		clueUpdateData["department"] = department
-		clueUpdateData["industry"] = industry
-		clueUpdateData["follow_project_area"] = follow_project_area
-		clueUpdateData["role"] = role
+		if name != "" {
+			clueUpdateData["name"] = name
+		}
+		if position != "" {
+			clueUpdateData["position"] = position
+		}
+		if department != "" {
+			clueUpdateData["department"] = department
+		}
+		if follow_project_area != "" {
+			clueUpdateData["follow_project_area"] = follow_project_area
+		}
+		if role != "" {
+			clueUpdateData["role"] = role
+		}
+		// clueUpdateData["industry"] = industry
+	}
+	if sourceCode == "app_xzcyh" {
+		if departments != "" {
+			clueUpdateData["department"] = departments
+			department = departments
+		}
+		business_scope := common.ObjToString(data["business_scope"])
+		keywords := ""
+		if len(keyword) > 0 && keyword[0] != "" {
+			keywords = strings.Join(keyword, ",")
+			if business_scope != "" {
+				clueUpdateData["business_scope"] = business_scope + "," + keywords
+			} else {
+				clueUpdateData["business_scope"] = keywords
+			}
+		}
 	}
 	if trailstatus == "00" || old_position_id == 0 || is_assign != 1 {
 		if trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400 {
@@ -911,7 +947,7 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
 					"operator_id":  -1,
 				})
 			}
-			if old_follow_project_area != follow_project_area {
+			if old_follow_project_area != follow_project_area && follow_project_area != "" {
 				old_area, old_area_arr := "", []string{}
 				new_area, new_area_arr := "", []string{}
 				for _, v := range strings.Split(old_follow_project_area, ",") {