WH01243 1 éve
szülő
commit
2d1345da84
8 módosított fájl, 269 hozzáadás és 91 törlés
  1. 118 20
      clueSync/autoTask.go
  2. 1 0
      clueSync/config.go
  3. 9 3
      clueSync/everything.go
  4. 28 7
      clueSync/job.go
  5. 71 35
      clueSync/jobutil.go
  6. 21 23
      clueSync/kc.go
  7. 15 2
      clueSync/main.go
  8. 6 1
      clueSync/tag.go

+ 118 - 20
clueSync/autoTask.go

@@ -2,6 +2,7 @@ package main
 
 import (
 	"database/sql"
+	"fmt"
 	"github.com/gogf/gf/v2/util/gconv"
 	"log"
 	"time"
@@ -54,7 +55,7 @@ func autoTask() {
 		statusMap[status] = count
 	}
 	log.Println(statusMap)
-	for trailstatus, _ := range map[string]string{
+	for trailstatus := range map[string]string{
 		"07": "", //待签署客户
 		"06": "", //高意向客户
 		"05": "", //意向客户
@@ -157,10 +158,23 @@ func autoTasks() {
 }
 
 // 所有人达上限退公海处理
-func upperLimitAutoExitSea() {
+func UpperLimitAutoExitSea(upperLimit int64) {
+	countData := TiDb.SelectBySql(`SELECT
+	COUNT(b.ID) AS count ,a.position_id
+FROM
+	dwd_f_crm_clue_info b 
+right JOIN
+ ( 	select  position_id from  dwd_f_crm_personnel_management where  assign_type = 1 
+	AND resign = 0 ) a on  a.position_id=b.position_id
+GROUP BY
+	a.position_id HAVING count<?`, upperLimit)
+	if countData == nil || len(*countData) > 0 {
+		return
+	}
 	log.Println("所有人达上限退公海处理任务开始")
-	data := TiDb.SelectBySql(`select * from dwd_f_crm_clue_info where (trailstatus = "04" or  trailstatus = "03" or trailstatus = "01" ) and (is_assign = 1 or is_assign = 0)`)
+	data := TiDb.SelectBySql(`select * from dwd_f_crm_clue_info where (trailstatus = "04" or  trailstatus = "03" or trailstatus = "01" ) and (is_assign = 1)`)
 	if data != nil && len(*data) > 0 {
+		fool := false
 		for _, v := range *data {
 			trailstatus := gconv.String(v["trailstatus"])
 			//坐席信息查询
@@ -195,13 +209,16 @@ func upperLimitAutoExitSea() {
 			positionMap := map[int64]interface{}{}
 			if TiDb.ExecTx("退出线索", func(tx *sql.Tx) bool {
 				positionMap[positionId] = true
-				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,next_trail_time=null,is_task=null,tasktime=null,taskstatus=null,comeinsource_private=null,tasksource=null WHERE id = ?`, nowTime, clueId) //,start_trail_time=null,content=null
-				// ok1 := true
-				// if is_assign == 1 {
-				// 	ok1 = TiDb.DeleteByTx(tx, "dwd_f_crm_private_sea", map[string]interface{}{"clue_id": clueId})
-				// } else if is_assign == 0 {
-				// 	ok1 = TiDb.DeleteByTx(tx, "dwd_f_crm_open_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 = ?,comeinsource_open=null,level_open=null,next_trail_time=null,is_task=null,tasktime=null,taskstatus=null,comeinsource_private=null,tasksource=null WHERE id = ?`, nowTime, clueId) //,start_trail_time=null,content=null
+				recordId2 := TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+					"clue_id":     clueId,
+					"position_id": positionId,
+					"change_type": "退回公海",
+					"new_value":   "所有人员私海已达上限",
+					"createtime":  nowTime,
+					"BCPCID":      common.GetRandom(32),
+					"operator_id": -1,
+				})
 				recordId1 := TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
 					"clue_id":      clueId,
 					"position_id":  positionId,
@@ -213,23 +230,19 @@ func upperLimitAutoExitSea() {
 					"BCPCID":       common.GetRandom(32),
 					"operator_id":  -1,
 				})
-				recordId2 := TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
-					"clue_id":     clueId,
-					"position_id": positionId,
-					"change_type": "退出公海",
-					"new_value":   "所有人员私海已达上限",
-					"createtime":  nowTime,
-					"BCPCID":      common.GetRandom(32),
-					"operator_id": -1,
-				})
 				return recordId > -1 && recordId1 > -1 && recordId2 > -1
 			}) {
 				//发送消息,找wjh
+				fool = true
 				log.Println("达上限自动退出线索成功")
 			} else {
 				log.Println("达上限自动退出线索失败")
 			}
-
+		}
+		//释放邮件
+		//发送信息
+		if fool {
+			AutoReleaseNots()
 		}
 	}
 }
@@ -367,3 +380,88 @@ func GetPositionName(seatNumber string) string {
 	}
 	return ""
 }
+
+func Thaw() {
+	//3个工作日查询
+	k := 3
+	nowTime := time.Now()
+	for {
+		if k == 0 || IsBreak(nowTime) {
+			break
+		}
+		nowTime = nowTime.AddDate(0, 0, -1)
+		k--
+		fmt.Println(nowTime.Format("20060102"))
+	}
+	nameMap := map[int64]string{}
+	nameList := TiDb.SelectBySql("select  name,position_id from  dwd_f_crm_personnel_management")
+	if nameList != nil && len(*nameList) > 0 {
+		for _, v := range *nameList {
+			nameMap[gconv.Int64(v["position_id"])] = gconv.String(v["name"])
+		}
+	}
+	//查询
+	fmt.Println()
+	TiDb.SelectByBath(100, func(l *[]map[string]interface{}) bool {
+		for _, v := range *l {
+			clueId := gconv.Int64(v["id"])
+			positionId := gconv.Int64(v["position_id"])
+			if FindUpperLimit(gconv.String(positionId), "positionId") {
+				//退公海处理
+				if TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, map[string]interface{}{
+					"is_assign": 1,
+				}) {
+					TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
+						"clue_id":      clueId,
+						"position_id":  positionId,
+						"change_field": "position_id",
+						"change_type":  "所属人变更",
+						"old_value":    "/",
+						"new_value":    nameMap[positionId],
+						"createtime":   nowTime,
+						"BCPCID":       common.GetRandom(32),
+						"operator_id":  -1,
+					})
+				}
+			} else {
+				//分配状态改改
+				if TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, map[string]interface{}{
+					"is_assign":   0,
+					"position_id": 0,
+				}) {
+					TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
+						"clue_id":      clueId,
+						"position_id":  positionId,
+						"change_field": "position_id",
+						"change_type":  "所属人变更",
+						"old_value":    nameMap[positionId],
+						"new_value":    "/",
+						"createtime":   nowTime,
+						"BCPCID":       common.GetRandom(32),
+						"operator_id":  -1,
+					})
+				}
+			}
+		}
+		return true
+	}, `select id,position_id from dwd_f_crm_clue_info where is_assign = -3 and FREEZE_TIME<=? `, nowTime.Format(date.Date_Full_Layout))
+}
+func IsBreak(currentTime time.Time) bool {
+	if currentTime.Weekday() == time.Sunday {
+		isok := false
+		for k, v := range DateMap {
+			if currentTime.Format(date.Date_Short_Layout) == k && v == 2 {
+				isok = true
+			}
+		}
+		return isok
+	} else {
+		isok := true
+		for k, v := range DateMap {
+			if currentTime.Format(date.Date_Short_Layout) == k && v == 1 {
+				isok = false
+			}
+		}
+		return isok
+	}
+}

+ 1 - 0
clueSync/config.go

@@ -128,6 +128,7 @@ type (
 			UserName string `json:"user	Name"`
 			Password string `json:"password"`
 		} `json:"es"`
+		AllocationCap int64 `json:"allocationCap"`
 	}
 )
 

+ 9 - 3
clueSync/everything.go

@@ -67,7 +67,7 @@ func everythingSync() {
 					product_type := common.ObjToString(v["product_type"])
 					pMap[product_type] = "1"
 				}
-				for k, _ := range pMap {
+				for k := range pMap {
 					pArr = append(pArr, k)
 				}
 				if len(pArr) > 0 {
@@ -210,7 +210,7 @@ func saveEverything(user_id, phone, item, sourceName, sourceCode string) bool {
 			product_type := common.ObjToString(v["product_type"])
 			pMap[product_type] = "1"
 		}
-		for k, _ := range pMap {
+		for k := range pMap {
 			pArr = append(pArr, k)
 		}
 		if len(pArr) > 0 {
@@ -543,10 +543,16 @@ func eventReg() {
 	data := Jyactivities.SelectBySql(sql)
 	if data != nil && *data != nil && len(*data) > 0 {
 		for _, v := range *data {
-			ok1, _ := FormatData(v, "eventReg")
+			ok1, ok2 := FormatData(v, "eventReg")
 			if !ok1 {
 				common.WriteSysConfig(&cfg)
 				break
+			} else {
+				if !ok2 {
+					log.Println("用户分配已达上限")
+					common.WriteSysConfig(&cfg)
+					break
+				}
 			}
 			cfg.LastEventRegTime = common.ObjToString(v["update_time"])
 		}

+ 28 - 7
clueSync/job.go

@@ -182,7 +182,7 @@ func FormatData(data map[string]interface{}, item string) (bool, bool) {
 	if source == "0104" || strings.HasPrefix(belong_to, "02") || source == "0102" || source == "0103" || phone == "" { //参照用户来源代码表
 		log.Println("线索分配失败,线索过滤!!", item, source, phone, userId)
 		saveHlyj(belong_to, item, phone, name, sourceName, cluename, position, nowTime, isGroup, isCommerce)
-		return true, false
+		return true, true
 	}
 	if uId == "" { //没有进用户归集,等待进入,结束任务,放在下次继续执行
 		if isExists, _ := redis.Exists("bidx", "bidx_userId_"+userId); isExists {
@@ -218,13 +218,13 @@ func FormatData(data map[string]interface{}, item string) (bool, bool) {
 	top_cluetype, sub_cluetype, level, topname, subname = getClueType(item, data, sourceCode, sourceId) //查留资来源名字
 	if topname == "市场活动" && item == "saleLeads" {                                                       //市场活动的不要
 		log.Println("市场活动留资过滤 ", userId, phone)
-		return true, false
+		return true, true
 	}
 	if strings.HasPrefix(belong_to, "03") { //一切都好的不进
 		isOk := saveEverything(userId, phone, item, subname, sourceCode)
 		log.Println("渠道线索电销", userId, phone, item, subname, sourceCode)
 		if !isOk {
-			return true, false
+			return true, true
 		}
 	}
 	follow_project_area = getAreaCode(userId) //关注项目区域
@@ -233,8 +233,11 @@ func FormatData(data map[string]interface{}, item string) (bool, bool) {
 		log.Println("线索分配失败,线索过滤top_cluetype!!", item, uId, phone, userId)
 		return true, true
 	}
-	position_id, seatNumber, saleName, saleData, pIsOk := autoDraw(level, cluename, phone, isGroup, isCommerce) //查询当前分配次数最少的,如果当前线索有销售,此次找出的不会+1
+	position_id, seatNumber, saleName, saleData, pIsOk, isFreeze, isWait := autoDraw(level, cluename, phone, isGroup, isCommerce) //查询当前分配次数最少的,如果当前线索有销售,此次找出的不会+1
 	log.Println("data -------", position_id, seatNumber, saleName)
+	if isWait {
+		return true, false
+	}
 	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 {                                                               //已存在,走更新
@@ -244,7 +247,7 @@ func FormatData(data map[string]interface{}, item string) (bool, bool) {
 			}
 			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, level, position_id, source, sourceCode, remark, keyword, belong_to, isGroup, isCommerce, pIsOk)
 		} else { //不存在走新增
-			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, remark, keyword, belong_to, isGroup, isCommerce)
+			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, remark, keyword, belong_to, isGroup, isCommerce, isFreeze)
 			if oks { //新增成功,销售分配次数+1
 				TiDb.UpdateOrDeleteBySql(`update dwd_f_crm_clue_autodraw_record set count = count + 1 where position_id = ? and clue_level = ?`, position_id, level)
 			}
@@ -253,11 +256,13 @@ func FormatData(data map[string]interface{}, item string) (bool, bool) {
 			log.Println("线索分配失败!!", item, position_id, seatNumber, uId, userId, phone)
 			return false, false
 		}
+	} else {
+		return true, false
 	}
 	return true, true
 }
 
-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, sourceCode, remark string, keyword []string, belong_to string, isGroup, isCommerce 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, sourceCode, remark string, keyword []string, belong_to string, isGroup, isCommerce int, isFreeze bool) 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)
@@ -271,12 +276,13 @@ func SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, c
 		if cluename == "" {
 			cluename = phone
 		}
+
 		clueId = TiDb.InsertByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{
 			"userid":               userId,
 			"uid":                  uId,
 			"seatNumber":           seatNumber,
 			"position_id":          positionId,
-			"is_assign":            1,
+			"is_assign":            common.If(isFreeze, -3, 1),
 			"comeintime":           nowTime,
 			"createtime":           nowTime,
 			"updatetime":           nowTime,
@@ -301,6 +307,7 @@ func SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, c
 			"company_nature":       isGroup,
 			"company_verification": isCommerce,
 			"remark":               remark,
+			"FREEZE_TIME":          nowTime,
 		})
 		uodateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
 			"clue_id":     clueId,
@@ -364,6 +371,20 @@ func SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, c
 			"BCPCID":       common.GetRandom(32),
 			"operator_id":  -1,
 		})
+		//冻结处理
+		if isFreeze {
+			TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+				"createtime":  nowTime,
+				"BCPCID":      common.GetRandom(32),
+				"operator_id": -1,
+				"clue_id":     clueId,
+				"position_id": positionId,
+				"change_type": "线索冻结",
+				"new_value":   "线索冻结",
+			})
+			//消息发送
+			AssFail(positionId, cluename, phone)
+		}
 		return clueId > -1 && uodateId1 > -1 && uodateId2 > -1 && uodateId3 > -1 && uodateId4 > -1 && uodateId5 > -1 && uodateId6 > -1
 	}) {
 		log.Println("线索分配成功")

+ 71 - 35
clueSync/jobutil.go

@@ -28,10 +28,16 @@ func orders() {
 			product_type_str1 := `"大会员","VIP订阅","数据流量包","历史数据"`
 			product_type := common.ObjToString(v["product_type"])
 			if order_status == 0 && is_backstage_order == 0 && strings.Contains(product_type_str1, product_type) {
-				ok1, _ := FormatData(v, "orders")
+				ok1, ok2 := FormatData(v, "orders")
 				if !ok1 {
 					common.WriteSysConfig(&cfg)
 					break
+				} else {
+					if !ok2 {
+						log.Println("用户分配已达上限")
+						common.WriteSysConfig(&cfg)
+						break
+					}
 				}
 			}
 			cfg.LastOrderId = common.IntAll(v["id"])
@@ -48,10 +54,16 @@ func readClue() {
 	data := TiDb.SelectBySql(sql)
 	if data != nil && *data != nil && len(*data) > 0 {
 		for _, v := range *data {
-			ok1, _ := FormatData(v, "readClue")
+			ok1, ok2 := FormatData(v, "readClue")
 			if !ok1 {
 				common.WriteSysConfig(&cfg)
 				break
+			} else {
+				if !ok2 {
+					log.Println("用户分配已达上限")
+					common.WriteSysConfig(&cfg)
+					break
+				}
 			}
 			cfg.LastReadClueTime = common.ObjToString(v["updatetime"])
 		}
@@ -113,10 +125,16 @@ func saleLeads() {
 		if !iter.Next(&thisData) {
 			break
 		}
-		ok1, _ := FormatData(thisData, "saleLeads")
+		ok1, ok2 := FormatData(thisData, "saleLeads")
 		if !ok1 {
 			common.WriteSysConfig(&cfg)
 			break
+		} else {
+			if !ok2 {
+				log.Println("用户分配已达上限")
+				common.WriteSysConfig(&cfg)
+				break
+			}
 		}
 		cfg.LastId = mongodb.BsonIdToSId(thisData["_id"])
 	}
@@ -366,8 +384,9 @@ func getClueType(item string, data map[string]interface{}, sourceCode string, so
 }
 
 // 获取自动分配的人
-func autoDraw(mode, cluename, phone string, isGroup, isCommerce int) (positionId int64, seatNumber, saleName string, saleData []map[string]interface{}, isOk bool) {
+func autoDraw(mode, cluename, phone string, isGroup, isCommerce int) (positionId int64, seatNumber, saleName string, saleData []map[string]interface{}, isOk, isFreeze, isWait bool) {
 	isOk = false
+	isFreeze = false
 	if TiDb.Count("dwd_f_crm_clue_info", map[string]interface{}{"phone": phone, "is_assign": 1}) == 0 { //线索没销售进入,有销售走分配次数最少的逻辑
 		if isGroup == 0 && isCommerce == 1 && cluename != "" { //非集团在工商库线索名不为空
 			cdata := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"cluename": cluename, "is_assign": 1}, "", "")
@@ -386,19 +405,24 @@ func autoDraw(mode, cluename, phone string, isGroup, isCommerce int) (positionId
 								if resign == 1 { //离职分配,找到的销售离职了,分给组员,没离职就给他
 									sdata := TiDb.SelectBySql(`SELECT b.name,b.position_id,b.seat_number from dwd_d_crm_department_level_succbi a INNER JOIN dwd_f_crm_personnel_management b on a.position_id = b.position_id where a.bi_pcode = (SELECT bi_pcode from dwd_d_crm_department_level_succbi where position_id = ?) and b.role_id = 3`, positionId)
 									if sdata != nil && len(*sdata) > 0 {
-										positionId = common.Int64All((*sdata)[0]["position_id"])
-										seatNumber = common.ObjToString((*sdata)[0]["seat_number"])
-										saleName = common.ObjToString((*sdata)[0]["name"])
+										for _, m := range *sdata {
+											if !FindUpperLimit(gconv.String(positionId), "positionId") {
+												positionId = common.Int64All(m["position_id"])
+												seatNumber = common.ObjToString(m["seat_number"])
+												saleName = common.ObjToString(m["name"])
+												return
+											}
+										}
+										isWait = true
+										return
+
 									}
 								} else {
-									positionId = common.Int64All(v["position_id"])
 									saleName = common.ObjToString(v["name"])
 									if FindUpperLimit(gconv.String(positionId), "positionId") {
-										positionId = positionId
-										seatNumber = ""
-										saleName = ""
-										return
+										isFreeze = true
 									}
+
 								}
 							}
 						}
@@ -452,18 +476,17 @@ func autoDraw(mode, cluename, phone string, isGroup, isCommerce int) (positionId
 				countres := 0
 				for _, v := range *countData {
 					if common.IntAll(v["status"]) == 1 {
+						if FindUpperLimit(gconv.String(common.Int64All(v["position_id"])), "positionId") {
+							continue
+						}
 						if countres == 0 {
 							res = common.Int64All(v["count"])
 							positionId = common.Int64All(v["position_id"])
 						} else {
 							if common.Int64All(v["count"]) <= res {
-								seatNumber1 := common.ObjToString(v["seatNumber"])
-								if !FindUpperLimit(seatNumber1, "seatNumber") {
-									res = common.Int64All(v["count"])
-									seatNumber = common.ObjToString(v["seatNumber"])
-								}
 								res = common.Int64All(v["count"])
-								positionId = common.Int64All(v["position_id"])
+								seatNumber = common.ObjToString(v["seatNumber"])
+
 							}
 						}
 						countres++
@@ -471,21 +494,28 @@ func autoDraw(mode, cluename, phone string, isGroup, isCommerce int) (positionId
 				}
 			}
 		} else {
-			positionId = common.Int64All((*data)[0]["position_id"])
-			saleName = common.ObjToString((*data)[0]["name"])
-			rData := TiDb.FindOne("dwd_f_crm_clue_autodraw_record", map[string]interface{}{"clue_level": mode}, "", "count desc")
-			if rData != nil && len(*rData) > 0 {
-				TiDb.Insert("dwd_f_crm_clue_autodraw_record", map[string]interface{}{
-					"position_id": positionId,
-					"clue_level":  mode,
-					"count":       common.Int64All((*rData)["count"]),
-				})
-			} else {
-				TiDb.Insert("dwd_f_crm_clue_autodraw_record", map[string]interface{}{
-					"position_id": positionId,
-					"clue_level":  mode,
-					"count":       0,
-				})
+			for _, kv := range *data {
+				positionId1 := gconv.String(kv["position_id"])
+				if !FindUpperLimit(positionId1, "positionId") {
+					saleName = common.ObjToString(kv["name"])
+					positionId = common.Int64All((*data)[0]["position_id"])
+					saleName = common.ObjToString((*data)[0]["name"])
+					rData := TiDb.FindOne("dwd_f_crm_clue_autodraw_record", map[string]interface{}{"clue_level": mode}, "", "count desc")
+					if rData != nil && len(*rData) > 0 {
+						TiDb.Insert("dwd_f_crm_clue_autodraw_record", map[string]interface{}{
+							"position_id": positionId,
+							"clue_level":  mode,
+							"count":       common.Int64All((*rData)["count"]),
+						})
+					} else {
+						TiDb.Insert("dwd_f_crm_clue_autodraw_record", map[string]interface{}{
+							"position_id": positionId,
+							"clue_level":  mode,
+							"count":       0,
+						})
+					}
+					break
+				}
 			}
 		}
 		for _, v := range *data {
@@ -528,10 +558,16 @@ func FindUpperLimit(positionId string, dataType string) bool {
 	if positionId == "" {
 		return false
 	}
+
 	if dataType == "positionId" {
-		return TiDb.CountBySql(`select count(1) from dwd_f_crm_clue_info where position_id=? and is_assign=1   and trailstatus != '08'  `, positionId) >= 400
+		fmt.Println("111", positionId, TiDb.CountBySql(`select count(1) from dwd_f_crm_clue_info where position_id=? and is_assign=1    `, positionId))
+		//return TiDb.CountBySql(`select count(1) from dwd_f_crm_clue_info where position_id=? and is_assign=1   and trailstatus != '08'  `, positionId) >= cfg.AllocationCap
+		return TiDb.CountBySql(`select count(1) from dwd_f_crm_clue_info where position_id=? and is_assign=1   `, positionId) >= cfg.AllocationCap
 	} else {
-		return TiDb.CountBySql(`select count(1) from dwd_f_crm_clue_info where seatNumber=? and  is_assign and trailstatus != '08' `, positionId) >= 400
+		fmt.Println("222", positionId, TiDb.CountBySql(`select count(1) from dwd_f_crm_clue_info where seatNumber=? and  is_assign `, positionId))
+		//return TiDb.CountBySql(`select count(1) from dwd_f_crm_clue_info where seatNumber=? and  is_assign and trailstatus != '08' `, positionId) >= cfg.AllocationCap
+		return TiDb.CountBySql(`select count(1) from dwd_f_crm_clue_info where seatNumber=? and  is_assign  `, positionId) >= cfg.AllocationCap
+
 	}
 }
 func getSeatNumberPositionId(seatNumber string) (positionId int64) {

+ 21 - 23
clueSync/kc.go

@@ -458,6 +458,7 @@ func ordersClue() {
 						break
 					}
 				}
+				is_assign := 1
 				cluename = common.ObjToString(v["company_name"])
 				if cluename == "" {
 					cluename = user_phone
@@ -538,8 +539,7 @@ func ordersClue() {
 							seatNumber = common.ObjToString((*saleData)["seat_number"])
 							positionId = common.Int64All((*saleData)["position_id"])
 						}
-						is_assign := 1
-						if IsFreeze(source, pay_money, gconv.String(positionId)) && (isGroup != 1 && isCommerce == 1) {
+						if IsFreeze(source, pay_money, gconv.String(positionId)) {
 							//线索需要冻结
 							is_assign = -3
 						}
@@ -595,27 +595,22 @@ func ordersClue() {
 							"BCPCID":      common.GetRandom(32),
 							"operator_id": -1,
 						})
-						if strings.HasPrefix(saleDep, "01") || strings.HasPrefix(saleDep, "05") {
-							if IsFreeze(source, pay_money, gconv.String(positionId)) && (isGroup != 1 && isCommerce == 1) {
-								//新增冻结记录
-								TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
-									"clue_id":     clueId,
-									"position_id": positionId,
-									"change_type": "线索冻结",
-									"new_value":   "线索冻结",
-									"createtime":  nowTime,
-									"BCPCID":      common.GetRandom(32),
-									"operator_id": -1,
-								})
-								//移交失败发送消息
-								if IsFreeze(source, pay_money, gconv.String(positionId)) {
-									//发送邮件信息
-								}
-								if isGroup != 1 && isCommerce == 1 {
-									//发送邮件信息
-								}
+						if is_assign == -3 {
+							//新增冻结记录
+							TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
+								"clue_id":     clueId,
+								"position_id": positionId,
+								"change_type": "线索冻结",
+								"new_value":   "线索冻结",
+								"createtime":  nowTime,
+								"BCPCID":      common.GetRandom(32),
+								"operator_id": -1,
+							})
+							//移交失败发送消息
+							if IsFreeze(source, pay_money, gconv.String(positionId)) {
+								//发送邮件信息
+								OrderCreateFail(positionId, cluename)
 							}
-
 						}
 					}
 				}
@@ -826,7 +821,8 @@ func refundAuto() {
 								"BCPCID":      common.GetRandom(32),
 								"operator_id": -1,
 							})
-							TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_csm_customer_info SET is_transfer=1 WHERE clue_id = ?`, clueId)
+							//发送邮件
+							HandOverFail(saleId)
 						}
 					}
 				}
@@ -856,6 +852,8 @@ func refundAutoHistory() {
 	}
 }
 func IsFreeze(source string, pay_money int, positionId string) bool {
+	log.Println(source, pay_money == 0, FindUpperLimit(gconv.String(
+		positionId), "positionId"))
 	if source == "0104" && pay_money == 0 && FindUpperLimit(gconv.String(
 		positionId), "positionId") {
 		return true

+ 15 - 2
clueSync/main.go

@@ -3,6 +3,7 @@ package main
 import (
 	"flag"
 	"fmt"
+	"github.com/robfig/cron"
 	"log"
 
 	"app.yhyue.com/moapp/jybase/common"
@@ -11,7 +12,6 @@ import (
 	"app.yhyue.com/moapp/jybase/mysql"
 
 	"app.yhyue.com/moapp/jybase/redis"
-	"github.com/robfig/cron"
 )
 
 var (
@@ -103,6 +103,18 @@ func main() {
 	MgoLog = mongodb.NewMgoWithUser(cfg.MgoLog.Address, cfg.MgoLog.DbName, cfg.MgoLog.User, cfg.MgoLog.Password, cfg.MgoLog.DbSize)
 	MgoQyxy = mongodb.NewMgoWithUser(cfg.MgoQyxy.Address, cfg.MgoQyxy.DbName, cfg.MgoQyxy.User, cfg.MgoQyxy.Password, cfg.MgoQyxy.DbSize)
 	InitArea()
+	/*
+		//自动释放处理1
+		//UpperLimitAutoExitSea(cfg.AllocationCap)
+		//订单成线索处理
+		//ordersClue() //后台订单进线索
+		//客成移交失败
+		//refundAuto()
+		//自动分配1
+		//saleLeads()
+		//解冻处理
+		Thaw()*/
+
 	if *mode == 1 {
 		//30分钟一次
 		a := cron.New()
@@ -145,6 +157,7 @@ func main() {
 			go kcAuto()         //客成自动加入任务车
 			go tagAddSync()     //用户标签增量
 			go autoExitSea()    //自动退海
+			go Thaw()           //自动解冻处理
 		})
 		e.Start()
 		//5分钟一次
@@ -160,7 +173,7 @@ func main() {
 			refundAuto() //客成移交销售
 			autoTask()   //超时未跟进加入任务车
 			autoTasks()  //按照下次跟进时间提前一天加入任务车
-			upperLimitAutoExitSea()
+			UpperLimitAutoExitSea(cfg.AllocationCap)
 		})
 		g.Start()
 		h := cron.New()

+ 6 - 1
clueSync/tag.go

@@ -305,9 +305,14 @@ func messageSync() {
 				if mData != nil && len(*mData) > 0 {
 					own_id := common.Int64All((*mData)["own_id"])
 					if own_id > 0 {
-						ok1, _ := FormatData(*mData, "message")
+						ok1, ok2 := FormatData(*mData, "message")
 						if !ok1 {
 							break
+						} else {
+							if !ok2 {
+								log.Println("用户分配已达上限")
+								break
+							}
 						}
 					}
 				}