Browse Source

标签处理

WH01243 7 months ago
parent
commit
cf7d85f9ff
3 changed files with 84 additions and 7 deletions
  1. 5 0
      entity/entity.go
  2. 71 7
      service/clue.go
  3. 8 0
      service/company.go

+ 5 - 0
entity/entity.go

@@ -51,6 +51,11 @@ var (
 		"07": "待签署客户",
 		"08": "成交客户",
 	}
+	CodeLock = map[int64]string{
+		1: "已锁定",
+		2: "未锁定",
+		3: "无需锁定",
+	}
 	PublicKey        = ""
 	GmailAuth        []*mail.GmailAuth
 	UpdataProjectUrl string

+ 71 - 7
service/clue.go

@@ -590,7 +590,7 @@ func DrawClues(positionId, count1, count2, count3 int64) int {
 		counts, counts1 := 0, 0
 		for {
 			logx.Info("等级1线索领取", count1, counts1, counts)
-			data := JyBiTidb.SelectBySql(`SELECT a.last_ring_time as ctime,a.id,a.trailstatus,a.cluename FROM dwd_f_crm_clue_info a 
+			data := JyBiTidb.SelectBySql(`SELECT a.label,a.labelChangeTime,a.last_ring_time as ctime,a.id,a.trailstatus,a.cluename FROM dwd_f_crm_clue_info a 
 					WHERE a.level_open = 1 AND a.is_assign = 0 AND a.uid !="" AND a.is_transfer != 1 GROUP BY a.id ORDER BY ctime asc limit ?,1`, counts1)
 			counts1++
 			if data != nil && len(*data) > 0 {
@@ -614,7 +614,7 @@ func DrawClues(positionId, count1, count2, count3 int64) int {
 		counts, counts1 := 0, 0
 		for {
 			logx.Info("等级2线索领取", count2, counts1, counts)
-			data := JyBiTidb.SelectBySql(`SELECT a.last_ring_time as ctime,a.id,a.trailstatus,a.cluename FROM dwd_f_crm_clue_info a 
+			data := JyBiTidb.SelectBySql(`SELECT  a.label,a.labelChangeTime,a.last_ring_time as ctime,a.id,a.trailstatus,a.cluename FROM dwd_f_crm_clue_info a 
 					WHERE a.level_open = 2 AND a.is_assign = 0 AND a.uid !="" AND a.is_transfer != 1 GROUP BY a.id ORDER BY ctime asc limit ?,1`, counts1)
 			counts1++
 			if data != nil && len(*data) > 0 {
@@ -638,7 +638,7 @@ func DrawClues(positionId, count1, count2, count3 int64) int {
 		counts, counts1 := 0, 0
 		for {
 			logx.Info("等级3线索领取", count3, counts1, counts)
-			data := JyBiTidb.SelectBySql(`SELECT a.last_ring_time as ctime,a.id,a.trailstatus,a.cluename FROM dwd_f_crm_clue_info a 
+			data := JyBiTidb.SelectBySql(`SELECT a.label,a.labelChangeTime, a.last_ring_time as ctime,a.id,a.trailstatus,a.cluename FROM dwd_f_crm_clue_info a 
 					WHERE a.level_open = 3 AND a.is_assign = 0 AND a.uid !="" AND a.is_transfer != 1 GROUP BY a.id ORDER BY ctime asc limit ?,1`, counts1)
 			counts1++
 			if data != nil && len(*data) > 0 {
@@ -760,8 +760,12 @@ func batchDraw(data []map[string]interface{}, nowTime, seatNumber, name string,
 				"BCPCID":       common.GetRandom(32),
 				"operator_id":  positionId,
 			})
-
-			return ok1 && recordId > 0 && recordId1 > 0 && recordId2 > 0 && recordId3 > -1 && recordId4 > -1
+			//标签处理
+			labelChangeTime := gconv.String(v["labelChangeTime"])
+			label := gconv.Int64(v["label"])
+			trailstatusCode := gconv.String(v["trailstatus"])
+			LabelHandel(label, 3, clueId, "", trailstatusCode, labelChangeTime)
+			return ok1 && recordId > 0 && recordId1 > 0 && recordId2 > 0 && recordId3 > -1 && recordId4 > -1 && recordId5 > -1 && recordId6 > -1
 		}) {
 			logx.Info("领取线索成功")
 			count++
@@ -892,6 +896,7 @@ func ClueImportSync(this *biservice.ClueImportReq) (string, int) {
 						pcode := common.ObjToString((*sourceData)["pcode"])
 						dataMap["top_cluetype"] = pcode
 						dataMap["sub_cluetype"] = code
+						dataMap["clue_level"] = gconv.String((*sourceData)["clue_level"])
 					}
 				}
 				if isOK {
@@ -913,6 +918,7 @@ func ClueImportSync(this *biservice.ClueImportReq) (string, int) {
 					phone := common.ObjToString(v["phone"])
 					cluename := common.ObjToString(v["cluename"])
 					name := common.ObjToString(v["name"])
+					level := gconv.String(v["clue_level"])
 					position := common.ObjToString(v["position"])
 					isGroup, isCommerce := CompanyType(cluename)
 					clueData := JyBiTidb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"phone": phone}, "", "")
@@ -993,6 +999,9 @@ func ClueImportSync(this *biservice.ClueImportReq) (string, int) {
 						old_sub_cluetype := common.ObjToString((*clueData)["sub_cluetype"])
 						top_cluetype := common.ObjToString(v["top_cluetype"])
 						sub_cluetype := common.ObjToString(v["sub_cluetype"])
+						labelChangeTime := gconv.String(v["labelChangeTime"])
+						label := gconv.Int64(v["label"])
+						trailstatusCode := gconv.String(v["trailstatus"])
 						old_topname, old_subname := "", ""
 						if old_top_cluetype != "" {
 							pcodeData := JyBiTidb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"code": old_top_cluetype}, "", "")
@@ -1082,7 +1091,7 @@ func ClueImportSync(this *biservice.ClueImportReq) (string, int) {
 								JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
 									"clue_id":      clueId,
 									"position_id":  -1,
-									"change_field": "sub_cluetype",
+									"change_field": "sub_cluetype", //111
 									"change_type":  "基本信息变更",
 									"old_value":    common.If(old_subname == "", "/", old_subname),
 									"new_value":    v["clueSource"],
@@ -1090,6 +1099,7 @@ func ClueImportSync(this *biservice.ClueImportReq) (string, int) {
 									"BCPCID":       common.GetRandom(32),
 									"operator_id":  this.PositionId,
 								})
+								LabelHandel(label, 2, clueId, level, trailstatusCode, labelChangeTime)
 							}
 							JyBiTidb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, updateData)
 						} else if is_assign == 1 {
@@ -1165,13 +1175,14 @@ func ClueImportSync(this *biservice.ClueImportReq) (string, int) {
 									"BCPCID":       common.GetRandom(32),
 									"operator_id":  this.PositionId,
 								})
+								LabelHandel(label, 2, positionId, level, trailstatusCode, labelChangeTime)
 							}
 							if sub_cluetype != "" && sub_cluetype != old_sub_cluetype {
 								updateData["position"] = position
 								JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
 									"clue_id":      clueId,
 									"position_id":  positionId,
-									"change_field": "sub_cluetype",
+									"change_field": "sub_cluetype", //222
 									"change_type":  "基本信息变更",
 									"old_value":    common.If(old_subname == "", "/", old_subname),
 									"new_value":    v["clueSource"],
@@ -1179,6 +1190,7 @@ func ClueImportSync(this *biservice.ClueImportReq) (string, int) {
 									"BCPCID":       common.GetRandom(32),
 									"operator_id":  this.PositionId,
 								})
+
 							}
 							JyBiTidb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, updateData)
 							JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
@@ -1258,3 +1270,55 @@ func FindClueInfo(in *biservice.FindClueInfoReq) (map[string]interface{}, int64)
 	}
 	return data, 0
 }
+
+// 线索标签修改 label  labelChangeTime
+func LabelHandel(oldlabelType, labelType, clueId int64, level, trailstatusCode, labelChangeTime string) {
+	log.Println("线索标签修改:", oldlabelType, labelType, clueId, level, trailstatusCode, labelChangeTime)
+	//先查询以前什么类型
+	if trailstatusCode != "01" {
+		return
+	}
+	updateLabelType := int64(0)
+	nowStr := time.Now().Format("2006-01-02")
+	if labelType == 1 {
+		//直接更新
+		if labelChangeTime == nowStr {
+			if oldlabelType != 1 {
+				updateLabelType = labelType
+			}
+		} else {
+			updateLabelType = labelType
+		}
+	} else if labelType == 2 {
+		if level != "A" && level != "level" && level != "C" {
+			return
+		}
+		//查询以前是什么数据
+		if labelChangeTime == nowStr {
+			//同一天修改过
+			if oldlabelType != 0 {
+				updateLabelType = labelType
+			}
+		} else {
+			updateLabelType = labelType
+		}
+	} else {
+		//查询以前是什么数据
+		if labelChangeTime == nowStr {
+			//同一天修改过
+			if oldlabelType != 3 {
+				updateLabelType = oldlabelType
+			}
+		} else {
+			updateLabelType = labelType
+		}
+	}
+	if updateLabelType > 0 {
+		JyBiTidb.Update("dwd_f_crm_clue_info", map[string]interface{}{
+			"id": clueId,
+		}, map[string]interface{}{
+			"label":           updateLabelType,
+			"labelChangeTime": nowStr,
+		})
+	}
+}

+ 8 - 0
service/company.go

@@ -262,6 +262,11 @@ func dclue(v, positionId, isTask, thispositionId int64) {
 					"BCPCID":       common.GetRandom(32),
 					"operator_id":  thispositionId,
 				})
+				//标签变更
+				labelChangeTime := gconv.String((*clueData)["labelChangeTime"])
+				label := gconv.Int64((*clueData)["label"])
+				trailstatusCode := gconv.String((*clueData)["trailstatus"])
+				LabelHandel(label, 3, v, "", trailstatusCode, labelChangeTime)
 				JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
 					"clue_id":      v,
 					"position_id":  oldpositionId,
@@ -335,6 +340,9 @@ func dclue(v, positionId, isTask, thispositionId int64) {
 					"BCPCID":       common.GetRandom(32),
 					"operator_id":  thispositionId,
 				})
+				labelChangeTime := gconv.String((*clueData)["labelChangeTime"])
+				label := gconv.Int64((*clueData)["label"])
+				LabelHandel(label, 3, v, "", "01", labelChangeTime)
 				JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
 					"clue_id":      v,
 					"position_id":  positionId,