Просмотр исходного кода

Merge branch 'master' into feature/v1.5.13

yuelujie 11 месяцев назад
Родитель
Сommit
44e44f0a01
8 измененных файлов с 134 добавлено и 66 удалено
  1. 7 0
      clueSync/config.go
  2. 8 1
      clueSync/db.json
  3. 0 3
      clueSync/everything.go
  4. 8 1
      clueSync/job.go
  5. 96 55
      clueSync/jobutil.go
  6. 8 1
      clueSync/main.go
  7. 7 3
      clueSync/subscribeAll.go
  8. 0 2
      clueSync/tag.go

+ 7 - 0
clueSync/config.go

@@ -120,6 +120,13 @@ type (
 			MaxIdle     int    `json:"maxidle"`
 			MaxLeftTime int    `json:"maxleft"`
 		} `json:"jyactivities"`
+		DebrisProduct struct {
+			Host     string `json:"host"`
+			Port     int    `json:"port"`
+			Database string `json:"database"`
+			User     string `json:"user"`
+			Password string `json:"password"`
+		} `json:"debrisProduct"`
 		Mysql struct {
 			Host        string `json:"host"`
 			Port        int    `json:"port"`

+ 8 - 1
clueSync/db.json

@@ -79,6 +79,13 @@
     "maxidle": 40,
     "maxleft": 40
   },
+  "debrisProduct": {
+    "host": "192.168.3.14",
+    "port": 4000,
+    "database": "debris_product",
+    "user": "root",
+    "password": "=PDT49#80Z!RVv52_z"
+  },
   "dataAnalysis": {
     "host": "192.168.3.14",
     "port": 4000,
@@ -134,7 +141,7 @@
     "市场分析报告"
   ],
   "marketSaleMail": "wanghao@jianyu360.com",
-  "allocationCap": 5,
+  "allocationCap": 400,
   "warningValue": 350,
   "corn_mail": "",
   "regTimes": 7,

+ 0 - 3
clueSync/everything.go

@@ -907,13 +907,10 @@ func eventReg() {
 			if !ok1 {
 				common.WriteSysConfig(&cfg)
 				log.Println("线索卡点", "eventReg", v, lastEventRegTime)
-				break
 			} else {
 				if !ok2 {
 					log.Println("用户分配已达上限", "eventReg", v, lastEventRegTime)
-
 					common.WriteSysConfig(&cfg)
-					break
 				}
 			}
 			cfg.LastEventRegTime = common.ObjToString(v["update_time"])

+ 8 - 1
clueSync/job.go

@@ -82,11 +82,18 @@ func FormatData(data map[string]interface{}, item string) (bool, bool) {
 				belong_to = common.ObjToString((*userInfo)["belong_to"])
 			}
 			if item == "xcxusers" {
-				sourceCode = common.ObjToString(data["s_sourceid"])
+				sourceCode = common.ObjToString(data["industry"])
 				if sourceCode == "" {
 					log.Println("留资没有source", phone)
 					return true, true
 				}
+				//线索名称查询处理
+				clueData, _ := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"uid": uId}, "", ""), true //查当前线索是否已存在
+				if clueData != nil && len(*clueData) > 0 {
+					cluename = gconv.String((*clueData)["cluename"])
+				} else {
+					cluename = phone
+				}
 			}
 
 		}

+ 96 - 55
clueSync/jobutil.go

@@ -512,12 +512,10 @@ func orders() {
 				if !ok1 {
 					common.WriteSysConfig(&cfg)
 					log.Println("线索卡点", "orders", v, selectTimeEnd, selectTimeStart)
-					break
 				} else {
 					if !ok2 {
 						log.Println("用户分配已达上限", "orders", v, selectTimeEnd, selectTimeStart)
 						common.WriteSysConfig(&cfg)
-						break
 					}
 				}
 			}
@@ -539,12 +537,10 @@ func readClue() {
 			if !ok1 {
 				common.WriteSysConfig(&cfg)
 				log.Println("线索卡点", "readClue", v, lastReadClueTime)
-				break
 			} else {
 				if !ok2 {
 					log.Println("用户分配已达上限", "readClue", v, lastReadClueTime)
 					common.WriteSysConfig(&cfg)
-					break
 				}
 			}
 			cfg.LastReadClueTime = common.ObjToString(v["updatetime"])
@@ -565,27 +561,20 @@ func users() {
 	//新用户注册后5分钟内进入线索 C
 	log.Println("新注册用户定时任务开始")
 	selectTimeEnd := cfg.LastUserId
-	sql := fmt.Sprintf(`select * from dwd_f_userbase_baseinfo where createtime > "%s" and source = "0101" and status != 2  order by  createtime asc`, selectTimeEnd)
+	sql := fmt.Sprintf(`select * from dwd_f_userbase_baseinfo   where createtime > "%s" and (s_platform != 'xcx' or  s_platform is  NULL)  and source = "0101" and status != 2  order by  createtime asc`, selectTimeEnd)
 	data := TiDb.SelectBySql(sql)
 	if data != nil && *data != nil && len(*data) > 0 {
 		for k, v := range *data {
 			//判断用户是否有小程序切使用过剑鱼其他产品
-			s_platform := gconv.String(v["s_platform"])
-			login_positionid := gconv.Int64(v["login_positionid"])
 			createtime := common.ObjToString(v["createtime"])
-			if s_platform == "xcx" && login_positionid == 0 {
-				log.Println(v, "用户是否有小程序且未使用过剑鱼其他产品")
+			ok1, ok2 := FormatData(v, "users")
+			if !ok1 {
+				log.Println("线索卡点", "users", v, selectTimeEnd)
 			} else {
-				ok1, ok2 := FormatData(v, "users")
-				if !ok1 {
-					log.Println("线索卡点", "users", v, selectTimeEnd)
-				} else {
-					if !ok2 {
-						log.Println("用户分配已达上限", "users", v, selectTimeEnd)
-					}
+				if !ok2 {
+					log.Println("用户分配已达上限", "users", v, selectTimeEnd)
 				}
 			}
-
 			if k == len(*data)-1 {
 				cfg.LastUserId = createtime
 			}
@@ -593,34 +582,74 @@ func users() {
 	}
 	common.WriteSysConfig(&cfg)
 	selectXcxTimeEnd := cfg.LastXcxUserId
-	xcxSql := fmt.Sprintf(`select * from dwd_f_userbase_baseinfo where s_platform ="xcx"  and   updatetime> "%s"  and source = "0101" and status != 2 and  clue_operate_status!=1 order by  createtime asc`, selectXcxTimeEnd)
-	xcxData := TiDb.SelectBySql(xcxSql)
+	xcxSql := fmt.Sprintf(`SELECT DISTINCT
+	aa.mgo_id as  userId,
+	cc.NAME as   industry ,
+	aa.phone,
+	IF
+			( aa.phone_time IS NULL, aa.create_time, aa.phone_time ) as  time 
+FROM
+	debris_product.miniprogram_user aa
+	INNER JOIN debris_product.miniprogram bb ON (
+		aa.phone <> '' 
+	AND
+	IF
+		( aa.phone_time IS NULL, aa.create_time, aa.phone_time ) > '%s' 
+		AND aa.miniprogram_code = bb.CODE 
+	)
+	INNER JOIN debris_product.industry cc ON ( bb.industry_code = cc.CODE ) 
+WHERE
+	NOT EXISTS (
+	SELECT
+		1 
+	FROM
+		debris_product.miniprogram_user a
+		INNER JOIN debris_product.miniprogram b ON (
+			aa.unionid = a.unionid 
+			AND aa.miniprogram_code = a.miniprogram_code 
+			AND aa.id != a.id 
+		AND
+		IF
+			( a.phone_time IS NULL, a.create_time, a.phone_time ) <= '%s' 
+			AND a.miniprogram_code = b.CODE 
+		)
+	INNER JOIN debris_product.miniprogram_user c ON ( a.unionid = c.unionid AND b.CODE = c.miniprogram_code ))
+	ORDER BY time
+	`, selectXcxTimeEnd, selectXcxTimeEnd)
+	xcxData := debrisProductMysql.SelectBySql(xcxSql)
 	if xcxData != nil && *xcxData != nil && len(*xcxData) > 0 {
 		for k, v := range *xcxData {
 			//判断用户是否有小程序切使用过剑鱼其他产品
-			s_platform := gconv.String(v["s_platform"])
-			login_positionid := gconv.Int64(v["login_positionid"])
-			updatetime := common.ObjToString(v["updatetime"])
-			if s_platform == "xcx" && login_positionid == 0 {
-				log.Println(gconv.String(v["id"]), "用户是否有小程序且未使用过剑鱼其他产品")
+			//判断uid
+			uId := ""
+			for i := 0; i < 10; i++ {
+				phone := common.ObjToString(v["phone"])
+				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"]) != "" {
+						uId = common.ObjToString((*contactsData)[0]["baseinfo_id"])
+					}
+				}
+				if uId == "" {
+					time.Sleep(1 * time.Minute)
+				} else {
+					break
+				}
+			}
+			updatetime := common.ObjToString(v["time"])
+			if uId == "" {
+				cfg.LastXcxUserId = updatetime
+				continue
+			}
+			ok1, ok2 := FormatData(v, "xcxusers")
+			if !ok1 {
+				common.WriteSysConfig(&cfg)
+				log.Println("小程序用户分配线索卡点", "xcxusers", v, selectXcxTimeEnd)
 			} else {
-				ok1, ok2 := FormatData(v, "xcxusers")
-				if !ok1 {
+				if !ok2 {
+					log.Println("小程序用户分配已达上限", "xcxusers", v, selectXcxTimeEnd)
 					common.WriteSysConfig(&cfg)
-					log.Println("小程序用户分配线索卡点", "xcxusers", v, selectXcxTimeEnd)
-					break
-				} else {
-					if !ok2 {
-						log.Println("小程序用户分配已达上限", "xcxusers", v, selectXcxTimeEnd)
-						common.WriteSysConfig(&cfg)
-						break
-					}
 				}
-				TiDb.Update("dwd_f_userbase_baseinfo", map[string]interface{}{
-					"id": gconv.Int64(v["id"]),
-				}, map[string]interface{}{
-					"clue_operate_status": 1,
-				})
 			}
 
 			if k == len(*xcxData)-1 {
@@ -815,12 +844,10 @@ func userbase() {
 								if !ok1 {
 									common.WriteSysConfig(&cfg)
 									log.Println("线索卡点", "userbase uid", v, uId)
-									break
 								} else {
 									if !ok2 {
 										log.Println("用户分配已达上限", "userbase uid", v, uId)
 										common.WriteSysConfig(&cfg)
-										break
 									}
 								}
 							} else {
@@ -956,19 +983,31 @@ func getClueType(item string, data map[string]interface{}, sourceCode string, so
 			subname = "7天后到期"
 		}
 	} else if item == "xcxusers" {
-		level = "C"
-		if sourceCode != "" {
-			codeData := TiDb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"source": sourceCode}, "", "")
-			if codeData != nil && len(*codeData) > 0 {
-				pcode = common.ObjToString((*codeData)["pcode"])
-				code = common.ObjToString((*codeData)["code"])
-				level = common.ObjToString((*codeData)["clue_level"])
-				subname = common.ObjToString((*codeData)["name"])
-				pcodeData := TiDb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"code": pcode}, "", "")
-				if pcodeData != nil && len(*pcodeData) > 0 {
-					topname = common.ObjToString((*pcodeData)["name"])
-				}
-			}
+		level = "S"
+		pcode = "532"
+		code = "477"
+		topname = "其他"
+		switch sourceCode {
+		case "环境采购":
+			pcode = "532"
+			code = "696"
+			subname = `首次使用“环境”小程序`
+		case "物业":
+			pcode = "532"
+			code = "693"
+			subname = `首次使用“物业”小程序`
+		case "印务商机":
+			pcode = "532"
+			code = "697"
+			subname = `首次使用“印务”小程序`
+		case "家具":
+			pcode = "532"
+			code = "695"
+			subname = `首次使用“家具”小程序`
+		case "车辆租赁":
+			pcode = "532"
+			code = "694"
+			subname = `首次使用“车辆”小程序`
 		}
 	} else if item == "allocation" {
 		pcode = "532"
@@ -1197,8 +1236,10 @@ func autoDraw(mode, cluename, phone string, isGroup, isCommerce int) (positionId
 		query += ` assign_level like "%B%"`
 	} else if mode == "D" {
 		query += ` assign_level like "%D%"`
-	} else {
+	} else if mode == "C" {
 		query += ` assign_level like "%C%"`
+	} else if mode == "S" {
+		query += ` assign_level like "%S%"`
 	}
 	data := TiDb.SelectBySql(query)
 	if data != nil && len(*data) > 0 {

+ 8 - 1
clueSync/main.go

@@ -23,6 +23,7 @@ var (
 	WorkOrder           *mysql.Mysql
 	ThirdParty          *mysql.Mysql
 	Jyactivities        *mysql.Mysql
+	debrisProductMysql  *mysql.Mysql
 	Base                *mysql.Mysql
 	BiService           *mysql.Mysql
 	DataAnalysisService *mysql.Mysql
@@ -85,6 +86,13 @@ func main() {
 		MaxIdleConns: db.Jyactivities.MaxIdle,
 	}
 	Jyactivities.Init()
+	debrisProductMysql = &mysql.Mysql{
+		Address:  db.DebrisProduct.Host + ":" + fmt.Sprint(db.DebrisProduct.Port),
+		UserName: db.DebrisProduct.User,
+		PassWord: db.DebrisProduct.Password,
+		DBName:   db.DebrisProduct.Database,
+	}
+	debrisProductMysql.Init()
 	WorkOrder = &mysql.Mysql{
 		Address:      db.WorderOrder.Host + ":" + fmt.Sprint(db.WorderOrder.Port),
 		UserName:     db.WorderOrder.User,
@@ -145,7 +153,6 @@ func main() {
 			userbase()    //新绑定手机号进线索
 		})
 		//5分钟一次
-
 		go p.VarTimeTask.RunInTimeSection("5分钟定时任务1", db.CornExp2Start, db.CornExp2End, db.CornExp2, func(dayFirst bool) {
 			users()             //新注册用户进线索
 			saleLeads()         //留资进线索

+ 7 - 3
clueSync/subscribeAll.go

@@ -1,6 +1,7 @@
 package main
 
 import (
+	"github.com/gogf/gf/v2/util/gconv"
 	"strings"
 	"time"
 
@@ -36,9 +37,12 @@ func FormatSubscribeAllData(data map[string]interface{}) {
 	keywords := ""
 	keyArrs := []string{}
 	if data["o_member_jy"] != nil {
-		stype = "大会员订阅"
-		types = "o_member_jy"
-	} else {
+		if gconv.Int64(data["i_member_status"]) > 0 {
+			stype = "大会员订阅"
+			types = "o_member_jy"
+		}
+	}
+	if stype == "" {
 		if data["o_vipjy"] != nil {
 			stype = "超级订阅"
 			types = "o_vipjy"

+ 0 - 2
clueSync/tag.go

@@ -324,11 +324,9 @@ func messageSync() {
 						ok1, ok2 := FormatData(*mData, "message")
 						if !ok1 {
 							log.Println("线索卡点", "message", mData, messag_id)
-							break
 						} else {
 							if !ok2 {
 								log.Println("用户分配已达上限", "message", mData, messag_id)
-								break
 							}
 						}
 					}