浏览代码

fenzhihebimng

lianbingjie 1 年之前
父节点
当前提交
21330b9760
共有 9 个文件被更改,包括 1260 次插入93 次删除
  1. 10 8
      clueSync/config.go
  2. 5 1
      clueSync/config.json
  3. 3 0
      clueSync/db.json
  4. 15 2
      clueSync/everything.go
  5. 2 3
      clueSync/go.mod
  6. 1071 7
      clueSync/go.sum
  7. 5 2
      clueSync/job.go
  8. 112 43
      clueSync/jobutil.go
  9. 37 27
      clueSync/main.go

+ 10 - 8
clueSync/config.go

@@ -30,14 +30,16 @@ type (
 		RebindTime         string  `json:"rebindTime"`
 	}
 	DB struct {
-		CornExp1 string `json:"cornexp1"`
-		CornExp2 string `json:"cornexp2"`
-		CornExp3 string `json:"cornexp3"`
-		CornExp4 string `json:"cornexp4"`
-		CornExp5 string `json:"cornexp5"`
-		CornExp6 string `json:"cornexp6"`
-		CornExp7 string `json:"cornexp7"`
-		TiDb     struct {
+		CornExp1      int64  `json:"cornexp1"`
+		CornExp2      int64  `json:"cornexp2"`
+		CornExp2Start string `json:"cornexp2Strat"`
+		CornExp2End   string `json:"cornexp2End"`
+		CornExp3      string `json:"cornexp3"`
+		CornExp4      string `json:"cornexp4"`
+		CornExp5      int64  `json:"cornexp5"`
+		CornExp6      int64  `json:"cornexp6"`
+		CornExp7      string `json:"cornexp7"`
+		TiDb          struct {
 			Host        string `json:"host"`
 			Port        int    `json:"port"`
 			Database    string `json:"database"`

+ 5 - 1
clueSync/config.json

@@ -1,3 +1,4 @@
+<<<<<<< HEAD
 {
   "lastOrderId": 258784,
   "lastOrderClueId": "2024-05-25 02:23:21",
@@ -19,4 +20,7 @@
   "lastXcxUserId": "2024-07-09 14:59:37",
   "activeTime": "2024-07-01 14:59:37",
   "rebindTime": "2024-07-01 14:59:37"
-}
+}
+=======
+{"lastOrderId":258784,"lastOrderClueId":"2024-05-25 02:23:21","lastUserId":"2024-07-11 13:38:02","lastXcxUserId":"2024-07-10 16:30:03","lastId":"668e2be1d1f99a10cd6416a9","lastOrderTime":"2024-07-10 18:10:33","lastUserTime":"2024-07-10 17:55:03","lastSubscribeId":"668e3ec29a9f357bd3e3da06","lastMessageTime":"2024-07-09 17:24:47","lastkcTime":"","lastEverythingTime":"","lastEventRegTime":"","lastReadClueTime":"","bigSaleTime":1718241923,"bigOrderTime":"2024-06-12 17:01:39","marketSaleTime":1708160200,"allocationTime":"2024-07-01 14:59:37","allocationRatio":2}
+>>>>>>> master

+ 3 - 0
clueSync/db.json

@@ -59,6 +59,7 @@
     "maxidle": 40,
     "maxleft": 40
   },
+<<<<<<< HEAD
   "biService": {
     "host": "192.168.3.14",
     "port": 4000,
@@ -69,6 +70,8 @@
     "maxidle": 40,
     "maxleft": 40
   },
+=======
+>>>>>>> master
   "thirdParty": {
     "host": "192.168.3.14",
     "port": 4000,

+ 15 - 2
clueSync/everything.go

@@ -394,7 +394,6 @@ func bigCustomer() {
 				email := common.ObjToString(v["mail"])
 				interest := common.ObjToString(v["interest"])
 				data_requirement := common.ObjToString(v["data_requirement"])
-
 				belongTo, usernickname := "大客户", ""
 				userData := TiDb.FindOne("dwd_f_userbase_baseinfo", map[string]interface{}{"uid": uid}, "", "")
 				if userData != nil {
@@ -431,9 +430,23 @@ func bigCustomer() {
 			phone := common.ObjToString(v["user_phone"])
 			order_status := common.IntAll(v["order_status"])
 			product_type := common.ObjToString(v["product_type"])
-			userData := TiDb.FindOne("dwd_f_userbase_baseinfo", map[string]interface{}{"phone": phone}, "", "")
+			orderUserId := gconv.String(v["user_id"])
+			query := map[string]interface{}{}
+			if !mongodb.IsObjectIdHex(orderUserId) {
+				userMapping := TiDb.FindOne("dwd_f_userbase_id_mapping", map[string]interface{}{"position_id": orderUserId}, "", "")
+				if userMapping != nil && len(*userMapping) > 0 {
+					uid := common.ObjToString((*userMapping)["uid"])
+					query["uid"] = uid
+				}
+			} else {
+				query["userid"] = orderUserId
+			}
+			userData := TiDb.FindOne("dwd_f_userbase_baseinfo", query, "", "")
 			username, usernickname, userid, uid, source, payorderinfo, unpayorderinfo := "", "", "", "", "", "", ""
 			if userData != nil {
+				if phone == "" {
+					phone = common.ObjToString((*userData)["phone"])
+				}
 				username = common.ObjToString((*userData)["name"])
 				usernickname = common.ObjToString((*userData)["nickname"])
 				uid = common.ObjToString((*userData)["uid"])

+ 2 - 3
clueSync/go.mod

@@ -3,7 +3,8 @@ module clueSync
 go 1.14
 
 require (
-	app.yhyue.com/moapp/jybase v0.0.0-20240514063605-a33a48d6be14
+	app.yhyue.com/moapp/jybase v0.0.0-20240523083821-42a82b37ae20
+	bp.jydev.jianyu360.cn/BaseService/pushpkg v0.0.0-20240627084125-22b4217112c7
 	github.com/go-xweb/httpsession v0.0.0-20141220075701-356d3b4d38d6 // indirect
 	github.com/go-xweb/log v0.0.0-20140701090824-270d183ad77e // indirect
 	github.com/go-xweb/uuid v0.0.0-20140604020037-d7dce341f851 // indirect
@@ -11,8 +12,6 @@ require (
 	github.com/gogf/gf v1.16.9
 	github.com/gogf/gf/v2 v2.7.0
 	github.com/lunny/csession v0.0.0-20130910075847-fe53c5de3dfd // indirect
-	github.com/mattn/go-runewidth v0.0.13 // indirect
-	github.com/mattn/go-sqlite3 v1.9.0 // indirect
 	github.com/robfig/cron v1.2.0
 	github.com/tealeg/xlsx v1.0.5
 )

文件差异内容过多而无法显示
+ 1071 - 7
clueSync/go.sum


+ 5 - 2
clueSync/job.go

@@ -3,6 +3,7 @@ package main
 import (
 	"database/sql"
 	"fmt"
+	"github.com/gogf/gf/v2/util/gconv"
 	"log"
 	"strings"
 	"time"
@@ -203,6 +204,7 @@ func FormatData(data map[string]interface{}, item string) (bool, bool) {
 	if cluename == "" && item != "message" && item != "orders" && item != "readClue" {
 		cluename = phone //没有线索名,手机号代替
 	}
+	cluename = strings.ReplaceAll(cluename, " ", "")
 	isGroup, isCommerce := GetCompanyType(cluename)                                                                    //判断是否集团公司、工商库
 	if source == "0104" || strings.HasPrefix(belong_to, "02") || source == "0102" || source == "0103" || phone == "" { //参照用户来源代码表
 		//log.Println("线索分配失败,线索过滤!!", item, source, phone, userId)
@@ -733,7 +735,7 @@ func WorkUpdateClue(data map[string]interface{}, saleData []map[string]interface
 		"sub_cluetype":         sub_cluetype,
 		"userid":               userId,
 		"comeinsource_private": 2,
-		"tasksource":           "线索来源自动更新" + "-" + topname + "-" + subname,
+		"tasksource":           gconv.String(common.If(gconv.Int64(data["position_id"]) == 0, "线索自动分配", "线索来源自动更新")) + "-" + topname + "-" + subname,
 		"company_nature":       isGroup,
 		"company_verification": isCommerce,
 	}
@@ -1233,6 +1235,7 @@ func WorkUpdateClue(data map[string]interface{}, saleData []map[string]interface
 	}
 }
 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, level string, positionId int64, source, sourceCode, remark string, keyword []string, belong_to string, isGroup, isCommerce int, pIsOk bool) bool {
+	name = strings.ReplaceAll(name, " ", "")
 	log.Println("线索修改前", data)
 	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")
@@ -1602,7 +1605,7 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
 							"clue_id":     clueId,
 							"position_id": common.If(trailstatus == "00" || is_assign == 0 || is_assign == -1, positionId, common.Int64All(data["position_id"])),
 							"change_type": "加入任务车",
-							"new_value":   "线索来源自动更新" + "-" + topname + "-" + subname,
+							"new_value":   gconv.String(common.If(gconv.Int64(data["position_id"]) == 0, "线索自动分配", "线索来源自动更新")) + "-" + topname + "-" + subname,
 							"createtime":  nowTime,
 							"BCPCID":      common.GetRandom(32),
 							"operator_id": -1,

+ 112 - 43
clueSync/jobutil.go

@@ -573,16 +573,11 @@ func users() {
 				log.Println(v, "用户是否有小程序且未使用过剑鱼其他产品")
 			} else {
 				ok1, ok2 := FormatData(v, "users")
-				//ok1, ok2 := true, true
 				if !ok1 {
-					common.WriteSysConfig(&cfg)
 					log.Println("线索卡点", "users", v, selectTimeEnd)
-					break
 				} else {
 					if !ok2 {
 						log.Println("用户分配已达上限", "users", v, selectTimeEnd)
-						common.WriteSysConfig(&cfg)
-						break
 					}
 				}
 			}
@@ -684,14 +679,10 @@ func saleLeads() {
 		}
 		ok1, ok2 := FormatData(thisData, "saleLeads")
 		if !ok1 {
-			common.WriteSysConfig(&cfg)
 			log.Println("线索卡点", "saleLeads", thisData, lastId)
-			break
 		} else {
 			if !ok2 {
 				log.Println("用户分配已达上限", "saleLeads", thisData, lastId)
-				common.WriteSysConfig(&cfg)
-				break
 			}
 		}
 		cfg.LastId = mongodb.BsonIdToSId(thisData["_id"])
@@ -1025,52 +1016,130 @@ 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.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"cluename": cluename, "is_assign": 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
-				positionId = common.Int64All((*cdata)["position_id"])
-				noticePositionId = positionId
-				seatNumber = common.ObjToString((*cdata)["seatNumber"])
-				if positionId > 0 {
-					pdata := TiDb.SelectBySql(`select * from dwd_f_crm_personnel_management where seat_number is not null and seat_number != ""`)
-					if pdata != nil {
-						saleData = *pdata
+				pdata := TiDb.SelectBySql(`select * from dwd_f_crm_personnel_management where seat_number is not null and seat_number != ""`)
+				if pdata == nil {
+					positionId = 0
+					seatNumber = ""
+					saleName = ""
+					return
+				}
+				saleData = *pdata
+				cdataNew := []map[string]interface{}{}
+				if len(*cdata) > 1 {
+					//可能有多个人跟进
+					personMap := map[int64]bool{}
+					for _, m := range *cdata {
+						positionid := gconv.Int64(m["position_id"])
 						for _, v := range *pdata {
 							resign := common.IntAll(v["resign"])
-							if positionId == common.Int64All(v["position_id"]) {
-								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 {
-										for _, m := range *sdata {
-											if !FindUpperLimit(gconv.String(positionId), mode, true) {
-												positionId = common.Int64All(m["position_id"])
-												noticePositionId = positionId
-												seatNumber = common.ObjToString(m["seat_number"])
-												saleName = common.ObjToString(m["name"])
-												return
-											}
+							if positionid == common.Int64All(v["position_id"]) {
+								if resign == 0 {
+									if !FindUpperLimit(gconv.String(positionId), mode, true) {
+										personMap[positionid] = true
+										m["saleName"] = common.ObjToString(v["name"])
+										cdataNew = append(cdataNew, m)
+									}
+								}
+							}
+						}
+					}
+					//查询是否都有没有离职
+					if len(personMap) != 0 && len(cdataNew) > 0 {
+						layout := "2006-01-02 15:04:05"
+						//有人没有离职
+						data := map[string]interface{}{}
+						trailTime := int64(0)
+						for _, m := range cdataNew {
+							currentTime := int64(0)
+							if gconv.String(m["trail_time"]) == "" {
+								continue
+							}
+							t, _ := time.Parse(layout, gconv.String(m["trail_time"]))
+							currentTime = t.Unix()
+							if currentTime > trailTime {
+								trailTime = currentTime
+								data = m
+							}
+						}
+						if trailTime == 0 {
+							//需要查看通话记录
+							lastRingTime := int64(0)
+							for _, m := range cdataNew {
+								currentTime := int64(0)
+								if gconv.String(m["last_ring_time"]) == "" {
+									continue
+								}
+								t, _ := time.Parse(layout, gconv.String(m["last_ring_time"]))
+								currentTime = t.Unix()
+								if currentTime > lastRingTime {
+									lastRingTime = currentTime
+									data = m
+								}
+							}
+							if lastRingTime != 0 {
+								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"])
+										data = v
+									} else {
+										if count < gconv.Int(v["count"]) {
+											count = gconv.Int(v["count"])
+											data = v
 										}
-										isFreeze = true
-										positionId = 0
-										seatNumber = ""
-										saleName = ""
-										return
 									}
+
+								}
+								//
+								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
+						}
+					}
+				} else {
+					//只有一人跟进
+					//(1)该销售人员未离职,则继续分配给该销售人员(保持现状);
+					//该销售人员已离职,则随机分配
+					positionId = common.Int64All((*cdata)[0]["position_id"])
+					noticePositionId = positionId
+					seatNumber = common.ObjToString((*cdata)[0]["seatNumber"])
+					for _, v := range *pdata {
+						resign := common.IntAll(v["resign"])
+						if positionId == common.Int64All(v["position_id"]) {
+							if resign == 0 {
+								if FindUpperLimit(gconv.String(positionId), mode, true) {
+									isFreeze = true
+									positionId = 0
+									seatNumber = ""
+									saleName = ""
+									break
 								} else {
-									if FindUpperLimit(gconv.String(positionId), mode, true) {
-										isFreeze = true
-									}
 									saleName = common.ObjToString(v["name"])
+									return
 								}
+
 							}
 						}
 					}
-					if isFreeze {
-						positionId = 0
-						seatNumber = ""
-						saleName = ""
-					}
-					return
 				}
 			}
 		}

+ 37 - 27
clueSync/main.go

@@ -1,20 +1,20 @@
 package main
 
 import (
-	"flag"
-	"fmt"
-	"github.com/robfig/cron"
-	"log"
-
 	"app.yhyue.com/moapp/jybase/common"
 	elastic "app.yhyue.com/moapp/jybase/es"
 	"app.yhyue.com/moapp/jybase/mongodb"
 	"app.yhyue.com/moapp/jybase/mysql"
-
 	"app.yhyue.com/moapp/jybase/redis"
+	"bp.jydev.jianyu360.cn/BaseService/pushpkg/p"
+	"flag"
+	"fmt"
+	"github.com/robfig/cron"
+	"log"
 )
 
 var (
+<<<<<<< HEAD
 	cfg          = new(Config)
 	db           = new(DB)
 	Mysql        *mysql.Mysql
@@ -31,6 +31,24 @@ var (
 	MgoLog       *mongodb.MongodbSim
 	MgoQyxy      *mongodb.MongodbSim
 	mode         = flag.Int("m", 1, "")
+=======
+	cfg                = new(Config)
+	db                 = new(DB)
+	Mysql              *mysql.Mysql
+	TiDb               *mysql.Mysql
+	TiDbData           *mysql.Mysql
+	TiDbPower          *mysql.Mysql
+	WorkOrder          *mysql.Mysql
+	ThirdParty         *mysql.Mysql
+	Jyactivities       *mysql.Mysql
+	Base               *mysql.Mysql
+	Es                 elastic.Es
+	Mgo                *mongodb.MongodbSim
+	MgoLog             *mongodb.MongodbSim
+	MgoQyxy            *mongodb.MongodbSim
+	mode               = flag.Int("m", 1, "")
+	startTime, endTime = "00:00", "23:59"
+>>>>>>> master
 )
 
 func main() {
@@ -136,16 +154,13 @@ func main() {
 	activeUsers() //取关重新关注处理
 	if *mode == 1 {
 		//30分钟一次
-		a := cron.New()
-		a.AddFunc(db.CornExp1, func() {
+		go p.VarTimeTask.RunInTimeSection("30分钟定时任务", startTime, endTime, db.CornExp1, func(dayFirst bool) {
 			orders()      //未支付订单
 			messageSync() //聊天记录进线索
 			userbase()    //新绑定手机号进线索
 		})
-		a.Start()
 		//5分钟一次
-		b := cron.New()
-		b.AddFunc(db.CornExp2, func() {
+		go p.VarTimeTask.RunInTimeSection("5分钟定时任务1", db.CornExp2Start, db.CornExp2End, db.CornExp2, func(dayFirst bool) {
 			users()          //新注册用户进线索
 			saleLeads()      //留资进线索
 			eventReg()       //渠道
@@ -153,7 +168,6 @@ func main() {
 			marketCustomer() //市场部线索
 			rebind()         //取关重新关注处理
 		})
-		b.Start()
 		//每天8点30
 		c := cron.New()
 		c.AddFunc(db.CornExp3, func() {
@@ -171,24 +185,22 @@ func main() {
 		d.Start()
 		// 5分钟一次
 		go ordersClue() //后台订单进线索
-		e := cron.New()
-		e.AddFunc(db.CornExp5, func() {
-			go everythingSync() //渠道
-			go ordersClue()     //后台订单进线索
-			go kcSync()         //移交客成
-			go kcAuto()         //客成自动加入任务车
-			go tagAddSync()     //用户标签增量
-			go autoExitSea()    //自动退海
-			go Thaw()           //自动解冻处理
+		go p.VarTimeTask.RunInTimeSection("5分钟定时任务2", startTime, endTime, db.CornExp5, func(dayFirst bool) {
+			everythingSync()   //渠道
+			ordersClue()       //后台订单进线索
+			kcSync()           //移交客成
+			kcAuto()           //客成自动加入任务车
+			tagAddSync()       //用户标签增量
+			autoExitSea()      //自动退海
+			Thaw()             //自动解冻处理
+			subscribeAddSync() //订阅增量
+			rderAcceptance()   //工单生成
 		})
-		e.Start()
 		//5分钟一次
-		f := cron.New()
-		f.AddFunc(db.CornExp6, func() {
+		go p.VarTimeTask.RunInTimeSection("5分钟定时任务3", startTime, endTime, db.CornExp6, func(dayFirst bool) {
 			subscribeAddSync() //订阅增量
 			rderAcceptance()   //工单生成
 		})
-		f.Start()
 		//自动进入任务车 1天一次
 		g := cron.New()
 		g.AddFunc(db.CornExp7, func() {
@@ -196,10 +208,8 @@ func main() {
 			refundAuto() //客成移交销售
 			autoTask()   //超时未跟进加入任务车
 			autoTasks()  //按照下次跟进时间提前一天加入任务车
-
 		})
 		g.Start()
-
 		log.Println("个人邮件告警查询开始")
 		WarningPerl() // 个人
 		log.Println("部门邮件告警查询开始")

部分文件因为文件数量过多而无法显示