فهرست منبع

自动分配多人处理

WH01243 1 سال پیش
والد
کامیت
c4a3b6dd6e
1فایلهای تغییر یافته به همراه25 افزوده شده و 4 حذف شده
  1. 25 4
      clueSync/jobutil.go

+ 25 - 4
clueSync/jobutil.go

@@ -972,7 +972,8 @@ func autoDraw(mode, cluename, phone string, isGroup, isCommerce int) (positionId
 	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.Find("dwd_f_crm_clue_info", map[string]interface{}{"cluename": cluename, "is_assign": 1}, "", "", -1, -1)
+			//cdata := TiDb.Find("dwd_f_crm_clue_info", map[string]interface{}{"cluename": cluename, "is_assign": 1}, "", "", -1, -1)
+			cdata := TiDb.SelectBySql(`select  position_id,MAX(trail_time) as trail_time,max(last_ring_time) as last_ring_time,seatNumber,count(id) as count from   dwd_f_crm_clue_info where  cluename=? and  is_assign =1 GROUP BY  position_id `, cluename)
 			if cdata != nil && len(*cdata) > 0 { //找到了公司有人在跟进
 				isOk = true
 				pdata := TiDb.SelectBySql(`select * from dwd_f_crm_personnel_management where seat_number is not null and seat_number != ""`)
@@ -982,14 +983,12 @@ func autoDraw(mode, cluename, phone string, isGroup, isCommerce int) (positionId
 					saleName = ""
 					return
 				}
+				saleData = *pdata
 				cdataNew := []map[string]interface{}{}
 				if len(*cdata) > 1 {
 					//可能有多个人跟进
-					clueIdArr := []int64{}
 					personMap := map[int64]bool{}
 					for _, m := range *cdata {
-						clueId := gconv.Int64(m["id"])
-						clueIdArr = append(clueIdArr, clueId)
 						positionid := gconv.Int64(m["position_id"])
 						for _, v := range *pdata {
 							resign := common.IntAll(v["resign"])
@@ -997,6 +996,7 @@ func autoDraw(mode, cluename, phone string, isGroup, isCommerce int) (positionId
 								if resign == 0 {
 									if !FindUpperLimit(gconv.String(positionId), mode, true) {
 										personMap[positionid] = true
+										m["saleName"] = common.ObjToString(v["name"])
 										cdataNew = append(cdataNew, m)
 									}
 								}
@@ -1038,12 +1038,33 @@ func autoDraw(mode, cluename, phone string, isGroup, isCommerce int) (positionId
 								positionId = common.Int64All(data["position_id"])
 								noticePositionId = positionId
 								seatNumber = common.ObjToString(data["seatNumber"])
+								saleName = common.ObjToString(data["saleName"])
+								return
+							} else {
+								count := 0
+								for i, v := range cdataNew {
+									if i == 0 {
+										count = gconv.Int(v["count"])
+									} else {
+										if count < gconv.Int(v["count"]) {
+											count = gconv.Int(v["count"])
+											data = v
+										}
+									}
+
+								}
+								//
+								positionId = common.Int64All(data["position_id"])
+								noticePositionId = positionId
+								saleName = common.ObjToString(data["saleName"])
+								seatNumber = common.ObjToString(data["seatNumber"])
 								return
 							}
 						} else {
 							positionId = common.Int64All(data["position_id"])
 							noticePositionId = positionId
 							seatNumber = common.ObjToString(data["seatNumber"])
+							saleName = common.ObjToString(data["saleName"])
 							return
 						}
 					}