Browse Source

订单查询调整

WH01243 2 months ago
parent
commit
ac059a08fd
6 changed files with 472 additions and 246 deletions
  1. 12 5
      clueSync/everything.go
  2. 4 5
      clueSync/jobutil.go
  3. 310 143
      clueSync/kc.go
  4. 90 90
      clueSync/main.go
  5. 5 3
      clueSync/tag.go
  6. 51 0
      clueSync/util.go

+ 12 - 5
clueSync/everything.go

@@ -61,7 +61,8 @@ func everythingSync() {
 			if vData != nil {
 			if vData != nil {
 				last_login_time = common.ObjToString((*vData)["date"])
 				last_login_time = common.ObjToString((*vData)["date"])
 			}
 			}
-			dData := Mysql.Find("dataexport_order", map[string]interface{}{"user_id": user_id}, "", "", -1, -1)
+			dDataSql := fmt.Sprintf(`select b.product_type  from  dataexport_order  a   INNER JOIN   jy_order_detail   b    on   a.order_code=b.order_code and    a.user_id = ?`, user_id)
+			dData := Mysql.SelectBySql(dDataSql)
 			if dData != nil && len(*dData) > 0 {
 			if dData != nil && len(*dData) > 0 {
 				pMap := map[string]string{}
 				pMap := map[string]string{}
 				pArr := []string{}
 				pArr := []string{}
@@ -204,7 +205,8 @@ func saveEverything(user_id, phone, item, sourceName, sourceCode string) bool {
 		unique_id = common.ObjToString((*cuData)["unique_id"])
 		unique_id = common.ObjToString((*cuData)["unique_id"])
 		owner = common.ObjToString((*cuData)["owner"])
 		owner = common.ObjToString((*cuData)["owner"])
 	}*/
 	}*/
-	dData := Mysql.Find("dataexport_order", map[string]interface{}{"user_id": user_id}, "", "", -1, -1)
+	dDataSql := fmt.Sprintf(`select b.product_type  from  dataexport_order  a   INNER JOIN   jy_order_detail   b    on   a.order_code=b.order_code and    a.user_id = ?`, user_id)
+	dData := Mysql.SelectBySql(dDataSql)
 	if dData != nil && len(*dData) > 0 {
 	if dData != nil && len(*dData) > 0 {
 		pMap := map[string]string{}
 		pMap := map[string]string{}
 		pArr := []string{}
 		pArr := []string{}
@@ -436,12 +438,15 @@ func bigCustomer() {
 		}
 		}
 	}
 	}
 	cfg.BigSaleTime = bigSaleTime
 	cfg.BigSaleTime = bigSaleTime
-	orderData := Mysql.SelectBySql(`SELECT * FROM dataexport_order WHERE create_time > "` + bigOrderTime + `" AND (product_type = '历史数据' or product_type = '数据流量包') AND order_status IN (0,1) AND salesperson IS NULL AND is_backstage_order = 0`)
+	orderDataSql := `select a.*,b.product_type as  productType,b.filter as  productFilter  from  dataexport_order  a   INNER JOIN   jy_order_detail   b    on
+	a.order_code=b.order_code
+	and   a.create_time>?  and  b.product_type in  ("数据流量包","历史数据") and  a.order_status IN (0,1) AND a.salesperson IS NULL AND a.is_backstage_order = 0 `
+	orderData := Mysql.SelectBySql(orderDataSql, bigOrderTime)
 	if orderData != nil && len(*orderData) > 0 {
 	if orderData != nil && len(*orderData) > 0 {
 		for _, v := range *orderData {
 		for _, v := range *orderData {
 			phone := common.ObjToString(v["user_phone"])
 			phone := common.ObjToString(v["user_phone"])
 			order_status := common.IntAll(v["order_status"])
 			order_status := common.IntAll(v["order_status"])
-			product_type := common.ObjToString(v["product_type"])
+			product_type := common.ObjToString(v["productType"])
 			orderUserId := gconv.String(v["user_id"])
 			orderUserId := gconv.String(v["user_id"])
 			query := map[string]interface{}{}
 			query := map[string]interface{}{}
 			if !mongodb.IsObjectIdHex(orderUserId) {
 			if !mongodb.IsObjectIdHex(orderUserId) {
@@ -493,6 +498,8 @@ func bigCustomer() {
 				continue
 				continue
 			}
 			}
 			data[key] = true
 			data[key] = true
+			productFilterMap := gconv.Map(v["productFilter"])
+			data_count := productFilterMap["pNum"]
 			dataArr = append(dataArr, map[string]interface{}{
 			dataArr = append(dataArr, map[string]interface{}{
 				"createTime":     nowTime,
 				"createTime":     nowTime,
 				"lastUpdateTime": nowTime,
 				"lastUpdateTime": nowTime,
@@ -505,7 +512,7 @@ func bigCustomer() {
 				"email":          v["user_mail"],
 				"email":          v["user_mail"],
 				"belongTo":       "大客户",
 				"belongTo":       "大客户",
 				"source":         source,
 				"source":         source,
-				"data_count":     v["data_count"],
+				"data_count":     data_count,
 				"unpayorderinfo": unpayorderinfo,
 				"unpayorderinfo": unpayorderinfo,
 				"payorderinfo":   payorderinfo, //增加客户需求
 				"payorderinfo":   payorderinfo, //增加客户需求
 			})
 			})

+ 4 - 5
clueSync/jobutil.go

@@ -500,11 +500,10 @@ func orders() {
 	lastOrderId := cfg.LastOrderId
 	lastOrderId := cfg.LastOrderId
 	selectTimeStart := time.Unix(time.Now().Unix()-7200, 0).Format(date.Date_Full_Layout)
 	selectTimeStart := time.Unix(time.Now().Unix()-7200, 0).Format(date.Date_Full_Layout)
 	selectTimeEnd := time.Unix(time.Now().Unix()-3600, 0).Format(date.Date_Full_Layout)
 	selectTimeEnd := time.Unix(time.Now().Unix()-3600, 0).Format(date.Date_Full_Layout)
-	sql := fmt.Sprintf(`select * from dataexport_order where create_time <= "%s" and create_time >= "%s" and id > %s`, selectTimeEnd, selectTimeStart, fmt.Sprint(lastOrderId))
-	//sql := fmt.Sprintf(`select * from dataexport_order where id=260265`)
-	data := Mysql.SelectBySql(sql)
-	if data != nil && *data != nil && len(*data) > 0 {
-		for _, v := range *data {
+	dDataSql := fmt.Sprintf(`select a.*,b.product_type as productType ,b.service_starttime,b.service_endtime  from  dataexport_order  a   INNER JOIN   jy_order_detail   b    on   a.order_code=b.order_code and    a.create_time<="%s" and a.create_time>="%s" and  a.id> %s`, selectTimeEnd, selectTimeStart, gconv.String(lastOrderId))
+	data, _ := getOrderData(dDataSql)
+	if data != nil && data != nil && len(data) > 0 {
+		for _, v := range data {
 			order_status := common.IntAll(v["order_status"])
 			order_status := common.IntAll(v["order_status"])
 			is_backstage_order := common.IntAll(v["is_backstage_order"])
 			is_backstage_order := common.IntAll(v["is_backstage_order"])
 			product_type_str1 := `"大会员","VIP订阅","数据流量包","历史数据"`
 			product_type_str1 := `"大会员","VIP订阅","数据流量包","历史数据"`

+ 310 - 143
clueSync/kc.go

@@ -19,22 +19,45 @@ import (
 
 
 func kcSync() {
 func kcSync() {
 	log.Println("客户成功系统移交定时任务开始")
 	log.Println("客户成功系统移交定时任务开始")
-	sql := `select * from dwd_f_userbase_order_info where (payable_money > 0 or  (payable_money=0 and  ( filter  like "%分期付款补充权益%"  or   filter  like "%原订单不支持开通多项权益%"  or    filter  like "%权益码兑换%")))
-	  and  data_spec!="dhy4" and phone not   like "9%" and  order_status=1  and (refund_status!=1  or  refund_status is null  ) and  vip_starttime<"2099-01-01"
-	  and vip_endtime > "` + time.Now().Format(date.Date_Full_Layout) + `" and autoUpdate > "` + cfg.LastkcTime + `" order by autoUpdate asc`
-	//sql := `select * from dwd_f_userbase_order_info where order_code="173943424276"  `
-	data := TiDb.SelectBySql(sql)
+	//商品查询
+	productArr, _ := KcProduct()
+	if len(productArr) == 0 {
+		log.Println("查询不到进客成商品类型")
+		return
+	}
+	sql := `SELECT
+	a.*,b.product_type,b.service_starttime,b.service_endtime,b.filter as  productFilter
+FROM
+	dataexport_order a
+	INNER JOIN jy_order_detail b ON a.order_code = b.order_code 
+	and  b.product_type  in  (%s)
+	AND (
+		a.pay_money > 0 
+		OR (
+			a.pay_money = 0 
+		AND ( zero_type = "分期付款补充权益" OR zero_type = "原订单不支持开通多项权益" OR zero_type = "权益码兑换" ))) 
+
+	AND a.user_phone NOT LIKE "9%" 
+	AND a.order_status = 1 
+	AND ( a.refund_status != 1 OR a.refund_status IS NULL ) 
+	AND b.service_starttime < "2099-01-01" AND b.service_endtime > now() 
+	AND a.autoUpdate > %s
+ORDER BY
+	a.autoUpdate ASC,
+	a.order_code ASC,
+	b.final_price DESC `
+	sql = fmt.Sprintf(sql, strings.Join(productArr, ","), cfg.LastkcTime)
+	data := Mysql.SelectBySql(sql)
 	customList := gconv.Strings(redis.Get("newother", "customList"))
 	customList := gconv.Strings(redis.Get("newother", "customList"))
 	if data != nil && *data != nil && len(*data) > 0 {
 	if data != nil && *data != nil && len(*data) > 0 {
-		arr := []string{}
+		orderMap := map[string]map[string]interface{}{}
 		for _, v := range *data {
 		for _, v := range *data {
-			product_type := common.ObjToString(v["product_type"])
-			vip_starttime := common.ObjToString(v["vip_starttime"])
-			vip_endtime := common.ObjToString(v["vip_endtime"])
+			orderCode := gconv.String(v["order_code"])
+			product_type := gconv.String(v["product_type"])
+			vip_starttime := gconv.String(v["service_starttime"])
+			vip_endtime := gconv.String(v["service_endtime"])
 			order_change := gconv.Int64(v["order_change"])
 			order_change := gconv.Int64(v["order_change"])
-			if (product_type == "大会员" || product_type == "企业商机管理") && ((order_change != 0) || (order_change == 0 && TimeStrcount(vip_starttime, vip_endtime) > 95)) {
-				orderCode := gconv.String(v["order_code"])
-				arr = append(arr, orderCode)
+			if (order_change != 0) || (order_change == 0 && TimeStrcount(vip_starttime, vip_endtime) > 95) {
 				isExit := false
 				isExit := false
 				for _, v := range customList {
 				for _, v := range customList {
 					if v == orderCode {
 					if v == orderCode {
@@ -45,25 +68,62 @@ func kcSync() {
 				if isExit {
 				if isExit {
 					continue
 					continue
 				}
 				}
+				//判断一下服务周期
+				difference := GetTimeDifference(vip_starttime, vip_endtime)
+				productInt64 := GetOrderProduct(product_type, gconv.String(v["productFilter"]))
+				if productInt64 == 0 {
+					continue
+				}
+				if _, exists := orderMap[orderCode]; exists {
+					//判断服务周期
+					data := orderMap[orderCode]
+					//商品类型获取
+					oldDifference := gconv.Int(data["difference"])
+					if oldDifference >= difference {
+						//需要更换
+						v["difference"] = difference
+						v["product"] = productInt64
+						v["service_endtime"] = vip_endtime
+						v["service_starttime"] = vip_starttime
+						orderMap[orderCode] = v
+					}
+				} else {
+					v["difference"] = difference
+					v["product"] = productInt64
+					orderMap[orderCode] = v
+				}
+			}
+			cfg.LastkcTime = gconv.String(v["autoUpdate"])
+		}
+
+		for _, v := range *data {
+			orderCode := gconv.String(v["order_code"])
+			if _, exists := orderMap[orderCode]; exists {
 				status := kcJob(v)
 				status := kcJob(v)
 				log.Println("订单进客成打印", orderCode, status)
 				log.Println("订单进客成打印", orderCode, status)
 				if status == 0 {
 				if status == 0 {
 					break
 					break
 				}
 				}
 				customList = append(customList, orderCode)
 				customList = append(customList, orderCode)
+				delete(orderMap, orderCode)
 			}
 			}
-			cfg.LastkcTime = common.ObjToString(v["autoUpdate"])
 		}
 		}
-		redis.Put("newother", "customList", customList, 0)
-		log.Println(strings.Join(arr, "`,`"))
 	}
 	}
+	redis.Put("newother", "customList", customList, 0)
 	common.WriteSysConfig(&cfg)
 	common.WriteSysConfig(&cfg)
 	log.Println("客户成功系统移交定时任务结束")
 	log.Println("客户成功系统移交定时任务结束")
 }
 }
 
 
 func kcJob(data map[string]interface{}) int {
 func kcJob(data map[string]interface{}) int {
 	nowTime := time.Now().Format(date.Date_Full_Layout)
 	nowTime := time.Now().Format(date.Date_Full_Layout)
-	uId, entId, clueId, saveMap, status := common.ObjToString(data["uid"]), fmt.Sprint(data["ent_id"]), int64(0), map[string]interface{}{}, 1
+	uId, entId, clueId, saveMap, status := "", gconv.Int(data["ent_id"]), int64(0), map[string]interface{}{}, 1
+	userId, cluename, phone := "", "", ""
+	phone = gconv.String(data["user_phone"])
+	uId, userId = GetUidToUserId(gconv.String(data["user_id"]), "")
+	if uId == "" {
+		log.Println("移交客成缺少基本信息,缺少用户信息", uId)
+		return 0
+	}
 	clueData := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"uid": uId}, "", "")
 	clueData := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"uid": uId}, "", "")
 	orderCode := gconv.String(data["order_code"])
 	orderCode := gconv.String(data["order_code"])
 	saleDep, orderPositionId, salesperson := FindSaleRecord(orderCode)
 	saleDep, orderPositionId, salesperson := FindSaleRecord(orderCode)
@@ -73,16 +133,8 @@ func kcJob(data map[string]interface{}) int {
 			log.Println("移交客成缺少基本信息", uId)
 			log.Println("移交客成缺少基本信息", uId)
 			return 0
 			return 0
 		}
 		}
-		//创建线索
 		//原始订单获取
 		//原始订单获取
 		position_id := int64(0)
 		position_id := int64(0)
-		orderData := Mysql.FindOne("dataexport_order", map[string]interface{}{
-			"order_code": orderCode,
-		}, "", "")
-		if orderData == nil {
-			log.Println("原始订单查询不到:", orderCode)
-		}
-		userId, cluename, phone := common.ObjToString((*orderData)["user_id"]), "", ""
 		seatNumber := ""
 		seatNumber := ""
 		if saleDep == "客户成功组" {
 		if saleDep == "客户成功组" {
 			//新增线索
 			//新增线索
@@ -95,8 +147,7 @@ func kcJob(data map[string]interface{}) int {
 			//其他信息
 			//其他信息
 			seatNumber = "0000"
 			seatNumber = "0000"
 		}
 		}
-		cluename = common.ObjToString(data["company_name"])
-		phone = common.ObjToString(data["phone"])
+		cluename = gconv.String(data["company_name"])
 		if cluename == "" {
 		if cluename == "" {
 			cluename = phone
 			cluename = phone
 		}
 		}
@@ -142,53 +193,23 @@ func kcJob(data map[string]interface{}) int {
 		}
 		}
 	}
 	}
 	clueId = common.Int64All((*clueData)["id"])
 	clueId = common.Int64All((*clueData)["id"])
-	starttime := common.ObjToString(data["vip_starttime"])
-	endtime := common.ObjToString(data["vip_endtime"])
+	starttime := gconv.String(data["service_starttime"])
+	endtime := gconv.String(data["service_endtime"])
 	buy_subject := common.IntAll(data["buy_subject"])
 	buy_subject := common.IntAll(data["buy_subject"])
-	product_type := common.ObjToString(data["product_type"])
-	data_spec := common.ObjToString(data["data_spec"])
-	userName := common.ObjToString((*clueData)["name"])
-	product, company_name := 0, common.ObjToString(data["company_name"])
-	productMap := map[string]int{
-		"dhy6":   1,
-		"dhy7":   2,
-		"dhy3":   4,
-		"dhy1":   5,
-		"dhy2":   6,
-		"dhy5":   7,
-		"企业商机管理": 8,
-	}
-	if buy_subject == 1 || buy_subject == 0 {
-		entId = common.ObjToString(data["userid"])
-	}
-	if product_type == "企业商机管理" {
-		product = productMap[product_type]
+	product_type := gconv.String(data["product_type"])
+	userName := gconv.String((*clueData)["name"])
+	product, company_name := gconv.String(data["product"]), gconv.String(data["company_name"])
+	if product_type != "大会员" {
 		powerData := TiDb.FindOne("dwd_f_data_equity_info", map[string]interface{}{"uid": uId, "product_type": "商机管理"}, "", "comeintime desc")
 		powerData := TiDb.FindOne("dwd_f_data_equity_info", map[string]interface{}{"uid": uId, "product_type": "商机管理"}, "", "comeintime desc")
 		if powerData != nil {
 		if powerData != nil {
-			starttime = common.ObjToString((*powerData)["starttime"])
-			endtime = common.ObjToString((*powerData)["endtime"])
+			starttime = gconv.String((*powerData)["starttime"])
+			endtime = gconv.String((*powerData)["endtime"])
 		} else {
 		} else {
 			log.Println("客成移交权限未查到--", uId)
 			log.Println("客成移交权限未查到--", uId)
 			return 0
 			return 0
 		}
 		}
-	} else {
-		if data_spec == "dhy6" {
-			product = 1
-			filter := common.ObjToString(data["filter"])
-			filterMap := map[string]interface{}{}
-			json.Unmarshal([]byte(filter), &filterMap)
-			if len(filterMap) > 0 {
-				areaCount := common.IntAll(filterMap["areaCount"])
-				if areaCount == 1 {
-					product = 3
-				}
-			}
-		} else {
-			product = productMap[data_spec]
-		}
 	}
 	}
 	//同一公司名称(以客户详情-组织机构-公司名称)下的线索需分配给同1人
 	//同一公司名称(以客户详情-组织机构-公司名称)下的线索需分配给同1人
-
 	saveMap = map[string]interface{}{
 	saveMap = map[string]interface{}{
 		"clue_id":                   clueId,
 		"clue_id":                   clueId,
 		"transfertime":              nowTime,
 		"transfertime":              nowTime,
@@ -285,8 +306,7 @@ func kcJob(data map[string]interface{}) int {
 			TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, map[string]interface{}{"is_transfer": 1, "updatetime": nowTime, "name": userName})
 			TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, map[string]interface{}{"is_transfer": 1, "updatetime": nowTime, "name": userName})
 		}
 		}
 	} else {
 	} else {
-		entIds := common.IntAll(data["ent_id"])
-		customerPositionId, customerName := cAutoDraw(entIds, orderPositionId, salesperson, saleDep, false, nil)
+		customerPositionId, customerName := cAutoDraw(entId, orderPositionId, salesperson, saleDep, false, nil)
 		log.Println("移交客成positionId", customerPositionId, customerName, saleDep, orderPositionId, salesperson, false)
 		log.Println("移交客成positionId", customerPositionId, customerName, saleDep, orderPositionId, salesperson, false)
 		cId, ok, updateId1, updateId2, updateId3 := int64(0), false, int64(0), int64(0), int64(0)
 		cId, ok, updateId1, updateId2, updateId3 := int64(0), false, int64(0), int64(0), int64(0)
 		if TiDb.ExecTx("保存客户", func(tx *sql.Tx) bool {
 		if TiDb.ExecTx("保存客户", func(tx *sql.Tx) bool {
@@ -328,7 +348,6 @@ func kcJob(data map[string]interface{}) int {
 			})
 			})
 			return cId > -1 && ok && updateId1 > -1 && updateId2 > -1 && updateId3 > -1
 			return cId > -1 && ok && updateId1 > -1 && updateId2 > -1 && updateId3 > -1
 		}) {
 		}) {
-			//TiDb.UpdateOrDeleteBySql(`update dwd_f_csm_customer_autodraw_record set count = count + 1 where name = ?`, name)
 			if customerName == db.KeCheng.Admin {
 			if customerName == db.KeCheng.Admin {
 				TiDb.UpdateOrDeleteBySql(`update dwd_f_csm_customer_autodraw_record set count = count + 2 where name = ?`, customerName)
 				TiDb.UpdateOrDeleteBySql(`update dwd_f_csm_customer_autodraw_record set count = count + 2 where name = ?`, customerName)
 			} else {
 			} else {
@@ -365,7 +384,7 @@ func findKcOldPerson(entId int, orderPositionId int64, salesperson, saleDep stri
 				deptPositionId := gconv.Int64(v["position_id"])
 				deptPositionId := gconv.Int64(v["position_id"])
 				if deptPositionId == positionid {
 				if deptPositionId == positionid {
 					positionId = positionid
 					positionId = positionid
-					name = common.ObjToString((*csmdata)["name"])
+					name = gconv.String((*csmdata)["name"])
 					return
 					return
 				}
 				}
 			}
 			}
@@ -384,12 +403,12 @@ func findKcOldPerson(entId int, orderPositionId int64, salesperson, saleDep stri
 		if entdata != nil && len(*entdata) > 0 {
 		if entdata != nil && len(*entdata) > 0 {
 			for _, v := range *entdata {
 			for _, v := range *entdata {
 				positionid := common.Int64All(v["position_id"])
 				positionid := common.Int64All(v["position_id"])
-				name = common.ObjToString(v["name"])
+				name = gconv.String(v["name"])
 				for _, v := range *data {
 				for _, v := range *data {
 					deptPositionId := gconv.Int64(v["position_id"])
 					deptPositionId := gconv.Int64(v["position_id"])
 					if deptPositionId == positionId {
 					if deptPositionId == positionId {
 						positionId = positionid
 						positionId = positionid
-						name = common.ObjToString((*csmdata)["name"])
+						name = gconv.String((*csmdata)["name"])
 						return
 						return
 					}
 					}
 				}
 				}
@@ -417,7 +436,7 @@ func findKcNewPerson(entId int, data *[]map[string]interface{}) (positionId int6
 		entdata := TiDb.FindOne("dwd_f_csm_customer_info", map[string]interface{}{"ent_id": entId}, "", "")
 		entdata := TiDb.FindOne("dwd_f_csm_customer_info", map[string]interface{}{"ent_id": entId}, "", "")
 		if entdata != nil && len(*entdata) > 0 {
 		if entdata != nil && len(*entdata) > 0 {
 			positionId = common.Int64All((*entdata)["position_id"])
 			positionId = common.Int64All((*entdata)["position_id"])
-			name = common.ObjToString((*entdata)["name"])
+			name = gconv.String((*entdata)["name"])
 			return
 			return
 		}
 		}
 	}
 	}
@@ -428,13 +447,13 @@ func findKcNewPerson(entId int, data *[]map[string]interface{}) (positionId int6
 			//判断是否有新员工
 			//判断是否有新员工
 			isOk := false
 			isOk := false
 			for _, vv := range *countData {
 			for _, vv := range *countData {
-				if common.ObjToString(v["name"]) == common.ObjToString(vv["name"]) {
+				if gconv.String(v["name"]) == gconv.String(vv["name"]) {
 					isOk = true
 					isOk = true
 				}
 				}
 			}
 			}
 			//有新员工直接分给新员工
 			//有新员工直接分给新员工
 			if !isOk {
 			if !isOk {
-				name = common.ObjToString(v["name"])
+				name = gconv.String(v["name"])
 				rData := TiDb.FindOne("dwd_f_csm_customer_autodraw_record", map[string]interface{}{}, "", "count desc")
 				rData := TiDb.FindOne("dwd_f_csm_customer_autodraw_record", map[string]interface{}{}, "", "count desc")
 				TiDb.Insert("dwd_f_csm_customer_autodraw_record", map[string]interface{}{
 				TiDb.Insert("dwd_f_csm_customer_autodraw_record", map[string]interface{}{
 					"name":  name,
 					"name":  name,
@@ -448,18 +467,18 @@ func findKcNewPerson(entId int, data *[]map[string]interface{}) (positionId int6
 		for _, v := range *countData {
 		for _, v := range *countData {
 			if countres == 0 {
 			if countres == 0 {
 				res = common.Int64All(v["count"])
 				res = common.Int64All(v["count"])
-				name = common.ObjToString(v["name"])
+				name = gconv.String(v["name"])
 			} else {
 			} else {
 				if common.Int64All(v["count"]) <= res {
 				if common.Int64All(v["count"]) <= res {
 					res = common.Int64All(v["count"])
 					res = common.Int64All(v["count"])
-					name = common.ObjToString(v["name"])
+					name = gconv.String(v["name"])
 				}
 				}
 			}
 			}
 			countres++
 			countres++
 		}
 		}
 	}
 	}
 	for _, v := range *data {
 	for _, v := range *data {
-		if name == common.ObjToString(v["name"]) {
+		if name == gconv.String(v["name"]) {
 			positionId = common.Int64All(v["position_id"])
 			positionId = common.Int64All(v["position_id"])
 		}
 		}
 	}
 	}
@@ -477,7 +496,7 @@ func kcAuto() {
 			training_way := common.IntAll(v["training_way"])
 			training_way := common.IntAll(v["training_way"])
 			positionId := common.Int64All(v["position_id"])
 			positionId := common.Int64All(v["position_id"])
 			clueId := common.Int64All(v["clue_id"])
 			clueId := common.Int64All(v["clue_id"])
-			tasksource, tasksources := common.ObjToString(v["tasksource"]), ""
+			tasksource, tasksources := gconv.String(v["tasksource"]), ""
 			taskstatus := common.IntAll(v["taskstatus"])
 			taskstatus := common.IntAll(v["taskstatus"])
 			if relationship_building_way != 1 && inventory_way == 1 {
 			if relationship_building_way != 1 && inventory_way == 1 {
 				tasksources = "2"
 				tasksources = "2"
@@ -537,11 +556,11 @@ func ordersClue() {
 			pay_money := common.IntAll(v["pay_money"])
 			pay_money := common.IntAll(v["pay_money"])
 			orderCode := gconv.String(v["order_code"])
 			orderCode := gconv.String(v["order_code"])
 			saleDep, _, salesperson := FindSaleRecord(orderCode)
 			saleDep, _, salesperson := FindSaleRecord(orderCode)
-			user_phone := common.ObjToString(v["user_phone"])
-			createperson := common.ObjToString(v["create_person"])
-			userId, uId, cluename, seatNumber, positionId, trailstatus, clueId := common.ObjToString(v["user_id"]), "", "", "", int64(0), "", int64(0)
+			user_phone := gconv.String(v["user_phone"])
+			createperson := gconv.String(v["create_person"])
+			userId, uId, cluename, seatNumber, positionId, trailstatus, clueId := gconv.String(v["user_id"]), "", "", "", int64(0), "", int64(0)
 			product_type_str2 := `"大会员","企业商机管理","VIP订阅"`
 			product_type_str2 := `"大会员","企业商机管理","VIP订阅"`
-			product_type := common.ObjToString(v["product_type"])
+			product_type := gconv.String(v["product_type"])
 			if order_status == 1 && is_backstage_order == 1 && saleDep != "" && !strings.HasPrefix(user_phone, "9") && strings.Contains(product_type_str2, product_type) {
 			if order_status == 1 && is_backstage_order == 1 && saleDep != "" && !strings.HasPrefix(user_phone, "9") && strings.Contains(product_type_str2, product_type) {
 				//销售部
 				//销售部
 				query := map[string]interface{}{}
 				query := map[string]interface{}{}
@@ -550,9 +569,9 @@ func ordersClue() {
 					query["phone"] = user_phone
 					query["phone"] = user_phone
 					userInfo := TiDb.FindOne("dwd_f_userbase_baseinfo", query, "", "")
 					userInfo := TiDb.FindOne("dwd_f_userbase_baseinfo", query, "", "")
 					if userInfo != nil && len(*userInfo) > 0 {
 					if userInfo != nil && len(*userInfo) > 0 {
-						uId = common.ObjToString((*userInfo)["uid"])
-						userId = common.ObjToString((*userInfo)["userid"])
-						source = common.ObjToString((*userInfo)["source"])
+						uId = gconv.String((*userInfo)["uid"])
+						userId = gconv.String((*userInfo)["userid"])
+						source = gconv.String((*userInfo)["source"])
 					} else {
 					} else {
 						log.Println("后台订单--未查询到 ", user_phone)
 						log.Println("后台订单--未查询到 ", user_phone)
 						break
 						break
@@ -561,7 +580,7 @@ func ordersClue() {
 					if !mongodb.IsObjectIdHex(userId) {
 					if !mongodb.IsObjectIdHex(userId) {
 						userMapping := TiDb.FindOne("dwd_f_userbase_id_mapping", map[string]interface{}{"position_id": userId}, "", "")
 						userMapping := TiDb.FindOne("dwd_f_userbase_id_mapping", map[string]interface{}{"position_id": userId}, "", "")
 						if userMapping != nil && len(*userMapping) > 0 {
 						if userMapping != nil && len(*userMapping) > 0 {
-							userId = common.ObjToString((*userMapping)["userid"])
+							userId = gconv.String((*userMapping)["userid"])
 						} else {
 						} else {
 							log.Println("后台订单--未查询到 ", user_phone)
 							log.Println("后台订单--未查询到 ", user_phone)
 							break
 							break
@@ -570,8 +589,8 @@ func ordersClue() {
 					query["userid"] = userId
 					query["userid"] = userId
 					userInfo := TiDb.FindOne("dwd_f_userbase_baseinfo", query, "", "")
 					userInfo := TiDb.FindOne("dwd_f_userbase_baseinfo", query, "", "")
 					if userInfo != nil && len(*userInfo) > 0 {
 					if userInfo != nil && len(*userInfo) > 0 {
-						uId = common.ObjToString((*userInfo)["uid"])
-						source = common.ObjToString((*userInfo)["source"])
+						uId = gconv.String((*userInfo)["uid"])
+						source = gconv.String((*userInfo)["source"])
 					} else {
 					} else {
 						log.Println("后台订单--未查询到 ", query, user_phone)
 						log.Println("后台订单--未查询到 ", query, user_phone)
 						break
 						break
@@ -579,7 +598,7 @@ func ordersClue() {
 				}
 				}
 				is_assign := 1
 				is_assign := 1
 				mailContent := ""
 				mailContent := ""
-				cluename = common.ObjToString(v["company_name"])
+				cluename = gconv.String(v["company_name"])
 				mailContent = fmt.Sprintf("%s(%s)", cluename, user_phone)
 				mailContent = fmt.Sprintf("%s(%s)", cluename, user_phone)
 				if cluename == "" {
 				if cluename == "" {
 					cluename = user_phone
 					cluename = user_phone
@@ -606,7 +625,7 @@ func ordersClue() {
 						log.Println("销售部订单salesperson", salesperson)
 						log.Println("销售部订单salesperson", salesperson)
 						saleData := TiDb.FindOne("dwd_f_crm_personnel_management", map[string]interface{}{"name": salesperson}, "", "")
 						saleData := TiDb.FindOne("dwd_f_crm_personnel_management", map[string]interface{}{"name": salesperson}, "", "")
 						if saleData != nil {
 						if saleData != nil {
-							seatNumber = common.ObjToString((*saleData)["seat_number"])
+							seatNumber = gconv.String((*saleData)["seat_number"])
 							positionId = common.Int64All((*saleData)["position_id"])
 							positionId = common.Int64All((*saleData)["position_id"])
 						}
 						}
 						if IsFreeze(source, pay_money, gconv.String(positionId), trailstatus) {
 						if IsFreeze(source, pay_money, gconv.String(positionId), trailstatus) {
@@ -686,7 +705,7 @@ func ordersClue() {
 					}
 					}
 				}
 				}
 			}
 			}
-			cfg.LastOrderClueId = common.ObjToString(v["autoUpdate"])
+			cfg.LastOrderClueId = gconv.String(v["autoUpdate"])
 		}
 		}
 	}
 	}
 	common.WriteSysConfig(&cfg)
 	common.WriteSysConfig(&cfg)
@@ -705,31 +724,39 @@ func refundAuto() {
 			saleId, newSeatNumber, newPerson := int64(0), "", ""
 			saleId, newSeatNumber, newPerson := int64(0), "", ""
 			clueId := common.Int64All(v["clue_id"])
 			clueId := common.Int64All(v["clue_id"])
 			company_name := gconv.String(v["company_name"])
 			company_name := gconv.String(v["company_name"])
-			name := common.ObjToString(v["name"])
+			name := gconv.String(v["name"])
 			kcposition_id := common.Int64All(v["position_id"])
 			kcposition_id := common.Int64All(v["position_id"])
 			isRenewalProtection := common.IntAll(v["is_renewal_protection"])
 			isRenewalProtection := common.IntAll(v["is_renewal_protection"])
 			clueData := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, "name,phone,company_nature,company_verification,cluename,userid,position_id,uid", "")
 			clueData := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, "name,phone,company_nature,company_verification,cluename,userid,position_id,uid", "")
 			if clueData != nil && len(*clueData) > 0 {
 			if clueData != nil && len(*clueData) > 0 {
-				saleId, newPerson, newSeatNumber = FindPositionIdClueId(clueId)
+				uid := gconv.String((*clueData)["uid"])
+				saleId, newPerson, newSeatNumber = FindPositionIdClueId(uid)
 				oldSaleId = common.Int64All((*clueData)["position_id"])
 				oldSaleId = common.Int64All((*clueData)["position_id"])
 				oldPersonData := FindPersonOne(oldSaleId)
 				oldPersonData := FindPersonOne(oldSaleId)
 				if oldSaleId != 0 {
 				if oldSaleId != 0 {
 					oldsaleName = gconv.String(oldPersonData["name"])
 					oldsaleName = gconv.String(oldPersonData["name"])
 				}
 				}
-				cluename = common.ObjToString((*clueData)["cluename"])
+				cluename = gconv.String((*clueData)["cluename"])
 				userName = gconv.String((*clueData)["name"])
 				userName = gconv.String((*clueData)["name"])
 				company_nature = common.IntAll((*clueData)["company_nature"])
 				company_nature = common.IntAll((*clueData)["company_nature"])
 				company_verification = common.IntAll((*clueData)["company_verification"])
 				company_verification = common.IntAll((*clueData)["company_verification"])
-				uid = common.ObjToString((*clueData)["uid"])
-				phone = common.ObjToString((*clueData)["phone"])
+				uid = gconv.String((*clueData)["uid"])
+				phone = gconv.String((*clueData)["phone"])
+			}
+			personArr := getUserIdToUid(uid)
+			productArr, _ := KcProduct()
+			if len(productArr) == 0 || len(personArr) == 0 {
+				log.Println("查询不到进客成商品类型或查询不到用户信息")
+				continue
 			}
 			}
 			//查询即将到期数据
 			//查询即将到期数据
 			if isRenewalProtection == 0 {
 			if isRenewalProtection == 0 {
-				orderData := TiDb.SelectBySql(`select * from dwd_f_userbase_order_info where uid=?   and (product_type = "企业商机管理" or product_type = "大会员") and order_status = 1  and  refund_status!=1 ORDER BY   vip_endtime  desc  `, uid)
-				if orderData != nil && len(*orderData) > 0 {
+				sqlStr := fmt.Sprintf(`select  a.*,b.product_type as productType,b.service_starttime,b.service_endtime from  dataexport_order  a   INNER JOIN   jy_order_detail   b    on   a.order_code=b.order_code and    a.user_id    in   (%s) and    b.product_type in (%s)  ORDER BY  b.service_endtime  desc     `, strings.Join(personArr, ","), strings.Join(productArr, ","))
+				_, vipEndDateStr := getOrderData(sqlStr)
+				if vipEndDateStr != "" {
 					endDate := time.Now().AddDate(0, 0, -db.ExpirationPeriod+3).Unix()
 					endDate := time.Now().AddDate(0, 0, -db.ExpirationPeriod+3).Unix()
 					startDate := time.Now().AddDate(0, 0, -db.ExpirationPeriod+2).Unix()
 					startDate := time.Now().AddDate(0, 0, -db.ExpirationPeriod+2).Unix()
-					vipEndDate, _ := time.ParseInLocation(time.DateTime, gconv.String((*orderData)[0]["vip_endtime"]), time.Local)
+					vipEndDate, _ := time.ParseInLocation(time.DateTime, vipEndDateStr, time.Local)
 					log.Println(vipEndDate.Unix() > startDate, vipEndDate.Unix() < endDate)
 					log.Println(vipEndDate.Unix() > startDate, vipEndDate.Unix() < endDate)
 					log.Println(vipEndDate.Unix(), startDate, endDate)
 					log.Println(vipEndDate.Unix(), startDate, endDate)
 					if vipEndDate.Unix() > startDate && vipEndDate.Unix() < endDate {
 					if vipEndDate.Unix() > startDate && vipEndDate.Unix() < endDate {
@@ -748,15 +775,16 @@ func refundAuto() {
 			}
 			}
 			isFull := false
 			isFull := false
 			isAllRefund := false
 			isAllRefund := false
-			myOrders := TiDb.SelectBySql(`select refund_status from dwd_f_userbase_order_info where uid=? and (product_type = "企业商机管理" or product_type = "大会员") and order_status = 1 `, uid)
-			if myOrders != nil {
+			orderSql := fmt.Sprintf(`  select  a.*,b.product_type as productType,b.service_starttime,b.service_endtime from  dataexport_order  a   INNER JOIN   jy_order_detail   b    on   a.order_code=b.order_code and    a.user_id    in   (%s) and    b.product_type in (%s)  and   order_status = 1  ORDER BY  b.service_endtime  desc   `, strings.Join(personArr, ","), strings.Join(productArr, ","))
+			myOrders, _ := getOrderData(orderSql)
+			if myOrders != nil || len(myOrders) > 0 {
 				refundCount := 0
 				refundCount := 0
-				for _, v := range *myOrders {
+				for _, v := range myOrders {
 					if common.IntAll(v["refund_status"]) == 1 {
 					if common.IntAll(v["refund_status"]) == 1 {
 						refundCount++
 						refundCount++
 					}
 					}
 				}
 				}
-				if len(*myOrders) > 0 && len(*myOrders) == refundCount {
+				if len(myOrders) > 0 && len(myOrders) == refundCount {
 					isAllRefund = true
 					isAllRefund = true
 				}
 				}
 			}
 			}
@@ -812,15 +840,15 @@ func refundAuto() {
 				})
 				})
 				TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_csm_customer_info SET is_transfer=1 WHERE clue_id = ?`, clueId)
 				TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_csm_customer_info SET is_transfer=1 WHERE clue_id = ?`, clueId)
 			} else {
 			} else {
-				order1 := TiDb.SelectBySql(`select id from dwd_f_userbase_order_info where uid=? and (product_type = "企业商机管理" or product_type = "大会员") and vip_endtime > ? and order_status = 1 `, uid, findNowTime)
-				if order1 == nil || len(*order1) == 0 {
+				order1Sql := fmt.Sprintf(`select  refund_status from  dataexport_order  a   INNER JOIN   jy_order_detail   b    on   a.order_code=b.order_code and    a.user_id    in   (%s) and    b.product_type in (%s)  and   order_status = 1  and  vip_endtime>%s ORDER BY  b.service_endtime  desc  `, strings.Join(personArr, ","), strings.Join(productArr, ","), findNowTime)
+				order1, _ := getOrderData(order1Sql)
+				if order1 == nil || len(order1) == 0 {
 					isOk := false
 					isOk := false
-					order3 := TiDb.SelectBySql(`select vip_endtime from dwd_f_userbase_order_info where uid=? and (product_type = "企业商机管理" or product_type = "大会员") and vip_endtime < ? and order_status = 1 ORDER BY   vip_endtime  desc limit 1  `, uid, findNowTime)
-					if order3 != nil && len(*order3) > 0 {
+					order3Sql := fmt.Sprintf(`select  refund_status from  dataexport_order  a   INNER JOIN   jy_order_detail   b    on   a.order_code=b.order_code and    a.user_id    in   (%s) and    b.product_type in (%s)  and   order_status = 1  and  vip_endtime<%s ORDER BY  b.service_endtime  desc  `, strings.Join(personArr, ","), strings.Join(productArr, ","), findNowTime)
+					_, vip_endtime := getOrderData(order3Sql)
+					if vip_endtime != "" {
 						//获取最后一个订单信息
 						//获取最后一个订单信息
-						vv := (*order3)[0]
 						if isRenewalProtection == 1 {
 						if isRenewalProtection == 1 {
-							vip_endtime := common.ObjToString(vv["vip_endtime"])
 							vip_endtimes, _ := time.ParseInLocation(date.Date_Full_Layout, vip_endtime, time.Local)
 							vip_endtimes, _ := time.ParseInLocation(date.Date_Full_Layout, vip_endtime, time.Local)
 							//查询申请保护时间
 							//查询申请保护时间
 							renewalTime := time.Now()
 							renewalTime := time.Now()
@@ -867,7 +895,7 @@ func refundAuto() {
 										isOks := false
 										isOks := false
 										for _, vv := range *adata {
 										for _, vv := range *adata {
 											position_ids := common.Int64All(vv["position_id"])
 											position_ids := common.Int64All(vv["position_id"])
-											newSeatNumber = common.ObjToString(vv["seatNumber"])
+											newSeatNumber = gconv.String(vv["seatNumber"])
 											saleDatas := TiDb.FindOne("dwd_f_crm_personnel_management", map[string]interface{}{"position_id": position_ids, "resign": 0}, "", "")
 											saleDatas := TiDb.FindOne("dwd_f_crm_personnel_management", map[string]interface{}{"position_id": position_ids, "resign": 0}, "", "")
 											if saleDatas != nil && len(*saleDatas) > 0 {
 											if saleDatas != nil && len(*saleDatas) > 0 {
 												saleId = position_ids
 												saleId = position_ids
@@ -883,7 +911,7 @@ func refundAuto() {
 											}
 											}
 											if sdata != nil && len(*sdata) > 0 {
 											if sdata != nil && len(*sdata) > 0 {
 												saleId = common.Int64All((*sdata)[0]["position_id"])
 												saleId = common.Int64All((*sdata)[0]["position_id"])
-												newSeatNumber = common.ObjToString((*sdata)[0]["seat_number"])
+												newSeatNumber = gconv.String((*sdata)[0]["seat_number"])
 												newPerson = gconv.String((*sdata)[0]["name"])
 												newPerson = gconv.String((*sdata)[0]["name"])
 											}
 											}
 										}
 										}
@@ -905,8 +933,8 @@ func refundAuto() {
 									}
 									}
 									if sdata != nil && len(*sdata) > 0 {
 									if sdata != nil && len(*sdata) > 0 {
 										saleId = common.Int64All((*sdata)[0]["position_id"])
 										saleId = common.Int64All((*sdata)[0]["position_id"])
-										newSeatNumber = common.ObjToString((*sdata)[0]["seat_number"])
-										newPerson = common.ObjToString((*sdata)[0]["name"])
+										newSeatNumber = gconv.String((*sdata)[0]["seat_number"])
+										newPerson = gconv.String((*sdata)[0]["name"])
 									}
 									}
 								}
 								}
 							}
 							}
@@ -1387,10 +1415,11 @@ func CustomerChangeHandle(data map[string]interface{}) map[string]interface{} {
 	if clueData == nil || len(*clueData) == 0 {
 	if clueData == nil || len(*clueData) == 0 {
 		return nil
 		return nil
 	}
 	}
-	phone = common.ObjToString((*clueData)["phone"])
+	uid := gconv.String((*clueData)["uid"])
+	phone = gconv.String((*clueData)["phone"])
 	userName = gconv.String((*clueData)["name"])
 	userName = gconv.String((*clueData)["name"])
 	//positionId := gconv.Int64((*clueData)["position_id"])
 	//positionId := gconv.Int64((*clueData)["position_id"])
-	positionId, _, _ := FindPositionIdClueId(clueId)
+	positionId, _, _ := FindPositionIdClueId(uid)
 	clueName = gconv.String((*clueData)["cluename"])
 	clueName = gconv.String((*clueData)["cluename"])
 	customData := TiDb.FindOne("dwd_f_csm_customer_info", map[string]interface{}{
 	customData := TiDb.FindOne("dwd_f_csm_customer_info", map[string]interface{}{
 		"clue_id": clueId,
 		"clue_id": clueId,
@@ -1411,32 +1440,55 @@ func CustomerChangeHandle(data map[string]interface{}) map[string]interface{} {
 }
 }
 
 
 // 查找订单实际业绩归属
 // 查找订单实际业绩归属
-func FindPositionIdClueId(clueId int64) (int64, string, string) {
-	querySql := `
-	SELECT
-		e.username as salesperson ,c.position_id,f.dept_name,c.seat_number
+func FindPositionIdClueId(uid string) (int64, string, string) {
+	/*querySql := `
+		SELECT
+			e.username as salesperson ,c.position_id,f.dept_name,c.seat_number
+		FROM
+			dwd_f_crm_clue_info a
+	INNER JOIN dwd_f_userbase_order_info b ON a.id = ?
+			AND a.uid = b.uid
+			AND (
+				b.payable_money > 0
+				OR (
+					b.payable_money = 0
+				AND ( b.filter LIKE "%分期付款补充权益%" OR b.filter LIKE "%原订单不支持开通多项权益%" OR b.filter LIKE "%权益码兑换%" )))
+			AND b.data_spec != "dhy4"
+			AND b.order_status = 1 and b.phone not   like "9%"
+			AND ( b.refund_status != 1 OR b.refund_status IS NULL )
+			AND b.vip_starttime < "2099-01-01"
+			AND b.product_type IN ( "大会员", "企业商机管理" )
+			AND ( b.order_change != 0 or  b.order_change  is  NULL OR ( b.order_change = 0 AND DATEDIFF( b.vip_endtime, b.vip_starttime )> 90 ) )
+			inner JOIN  jianyu.order_sale_record d on  b.order_code=d.ordercode and  d.state=1
+			INNER JOIN cadmin.admin_user e   on  d.saler_Id = e.id
+			INNER JOIN   dwd_f_crm_personnel_management c   on c.ent_id =?  and    e.username=c.name
+			inner  join dwd_d_crm_department_level_succbi  f  on   c.position_id=f.position_id
+		ORDER BY
+			b.vip_endtime desc ,b.payable_money DESC `*/
+	personArr := getUserIdToUid(uid)
+	productArr, _ := KcProduct()
+	querySql := fmt.Sprintf(`	SELECT
+		e.username as salesperson ,c.position_id,f.dept_name,c.seat_number,b.product_type,b.filter
 	FROM
 	FROM
-		dwd_f_crm_clue_info a
-INNER JOIN dwd_f_userbase_order_info b ON a.id = ?
-		AND a.uid = b.uid 
+   jianyu.dataexport_order  a INNER JOIN   jianyu.jy_order_detail   b     on  
+	 a.order_code=b.order_code  and    a.user_id    in   (%s)  
 		AND (
 		AND (
-			b.payable_money > 0 
+			b.final_price > 0 
 			OR (
 			OR (
-				b.payable_money = 0 
-			AND ( b.filter LIKE "%分期付款补充权益%" OR b.filter LIKE "%原订单不支持开通多项权益%" OR b.filter LIKE "%权益码兑换%" ))) 
-		AND b.data_spec != "dhy4" 
-		AND b.order_status = 1 and b.phone not   like "9%"
-		AND ( b.refund_status != 1 OR b.refund_status IS NULL ) 
-		AND b.vip_starttime < "2099-01-01" 
-		AND b.product_type IN ( "大会员", "企业商机管理" ) 
-		AND ( b.order_change != 0 or  b.order_change  is  NULL OR ( b.order_change = 0 AND DATEDIFF( b.vip_endtime, b.vip_starttime )> 90 ) ) 
+				b.final_price = 0 
+			AND ( a.zero_type= "分期付款补充权益" OR a.zero_type=  "原订单不支持开通多项权益" OR a.zero_type=  "权益码兑换" ))) 
+		AND a.order_status = 1 and a.user_phone not   like "9%"
+		AND ( a.refund_status != 1 OR a.refund_status IS NULL ) 
+		AND b.service_starttime < "2099-01-01" 
+		AND b.product_type IN ("%s" ) 
+		AND ( b.service_type != 4 or  b.service_type  is  NULL OR ( b.service_type = 4 AND DATEDIFF( b.service_starttime, b.service_endtime )> 90 ) ) 
 		inner JOIN  jianyu.order_sale_record d on  b.order_code=d.ordercode and  d.state=1 
 		inner JOIN  jianyu.order_sale_record d on  b.order_code=d.ordercode and  d.state=1 
 		INNER JOIN cadmin.admin_user e   on  d.saler_Id = e.id
 		INNER JOIN cadmin.admin_user e   on  d.saler_Id = e.id
 		INNER JOIN   dwd_f_crm_personnel_management c   on c.ent_id =?  and    e.username=c.name 
 		INNER JOIN   dwd_f_crm_personnel_management c   on c.ent_id =?  and    e.username=c.name 
 		inner  join dwd_d_crm_department_level_succbi  f  on   c.position_id=f.position_id
 		inner  join dwd_d_crm_department_level_succbi  f  on   c.position_id=f.position_id
 	ORDER BY
 	ORDER BY
-		b.vip_endtime desc ,b.payable_money DESC `
-	clueData := TiDb.SelectBySql(querySql, clueId, db.EntId)
+		b.service_endtime desc ,b.final_price DESC`, strings.Join(personArr, ","), strings.Join(productArr, ","))
+	clueData := TiDb.SelectBySql(querySql, db.EntId)
 	if clueData == nil || len(*clueData) == 0 {
 	if clueData == nil || len(*clueData) == 0 {
 		return 0, "", ""
 		return 0, "", ""
 	}
 	}
@@ -1452,7 +1504,7 @@ func refundAutoHistory() {
 	data := TiDb.Find("dwd_f_crm_clue_autodraw_record", nil, "", "", -1, -1)
 	data := TiDb.Find("dwd_f_crm_clue_autodraw_record", nil, "", "", -1, -1)
 	if data != nil {
 	if data != nil {
 		for _, v := range *data {
 		for _, v := range *data {
-			seatNumber := common.ObjToString(v["seatNumber"])
+			seatNumber := gconv.String(v["seatNumber"])
 			adata := TiDb.Find("dwd_f_crm_personnel_management", map[string]interface{}{"seat_number": seatNumber}, "", "", -1, -1)
 			adata := TiDb.Find("dwd_f_crm_personnel_management", map[string]interface{}{"seat_number": seatNumber}, "", "", -1, -1)
 			if adata != nil {
 			if adata != nil {
 				for _, vv := range *adata {
 				for _, vv := range *adata {
@@ -1661,11 +1713,11 @@ func KcSend(orderCode, personName string) {
 	bigmemberService := map[int64]string{}
 	bigmemberService := map[int64]string{}
 	combo := map[int64]string{}
 	combo := map[int64]string{}
 	Mysql.SelectByBath(1, func(l *[]map[string]interface{}) bool {
 	Mysql.SelectByBath(1, func(l *[]map[string]interface{}) bool {
-		bigmemberService[common.Int64All((*l)[0]["id"])] = common.ObjToString((*l)[0]["s_name"])
+		bigmemberService[common.Int64All((*l)[0]["id"])] = gconv.String((*l)[0]["s_name"])
 		return true
 		return true
 	}, `select id,s_name from jianyu.bigmember_service`)
 	}, `select id,s_name from jianyu.bigmember_service`)
 	Mysql.SelectByBath(1, func(l *[]map[string]interface{}) bool {
 	Mysql.SelectByBath(1, func(l *[]map[string]interface{}) bool {
-		combo[common.Int64All((*l)[0]["id"])] = common.ObjToString((*l)[0]["s_name"])
+		combo[common.Int64All((*l)[0]["id"])] = gconv.String((*l)[0]["s_name"])
 		return true
 		return true
 	}, `select id,s_name from jianyu.bigmember_combo`)
 	}, `select id,s_name from jianyu.bigmember_combo`)
 	orderInfo := KcOrderFormat(orderCode, bigmemberService, combo)
 	orderInfo := KcOrderFormat(orderCode, bigmemberService, combo)
@@ -1808,16 +1860,16 @@ func KcOrderFormat(orderCode string, bigmemberService, combo map[int64]string) *
 	data := &OrderInfo{}
 	data := &OrderInfo{}
 	if orderData != nil && len(*orderData) > 0 {
 	if orderData != nil && len(*orderData) > 0 {
 		id := common.Int64All((*orderData)[0]["id"])
 		id := common.Int64All((*orderData)[0]["id"])
-		user_phone := common.ObjToString((*orderData)[0]["user_phone"])
-		user_id := common.ObjToString((*orderData)[0]["user_id"])
-		product_type := common.ObjToString((*orderData)[0]["product_type"])
+		user_phone := gconv.String((*orderData)[0]["user_phone"])
+		user_id := gconv.String((*orderData)[0]["user_id"])
+		product_type := gconv.String((*orderData)[0]["product_type"])
 		serviceList := []string{}
 		serviceList := []string{}
-		if filter := common.ObjToString((*orderData)[0]["filter"]); filter != "" {
+		if filter := gconv.String((*orderData)[0]["filter"]); filter != "" {
 			filterMap := map[string]interface{}{}
 			filterMap := map[string]interface{}{}
 			json.Unmarshal([]byte(filter), &filterMap)
 			json.Unmarshal([]byte(filter), &filterMap)
 			if level := common.Int64All(filterMap["level"]); level == 5 {
 			if level := common.Int64All(filterMap["level"]); level == 5 {
 				product_type += "自定义版"
 				product_type += "自定义版"
-				for _, serversId := range strings.Split(common.ObjToString(filterMap["serversId"]), ",") {
+				for _, serversId := range strings.Split(gconv.String(filterMap["serversId"]), ",") {
 					if serviceName := bigmemberService[common.Int64All(serversId)]; serviceName != "" {
 					if serviceName := bigmemberService[common.Int64All(serversId)]; serviceName != "" {
 						serviceList = append(serviceList, serviceName)
 						serviceList = append(serviceList, serviceName)
 					}
 					}
@@ -1843,16 +1895,16 @@ func KcOrderFormat(orderCode string, bigmemberService, combo map[int64]string) *
 		}
 		}
 		data = &OrderInfo{
 		data = &OrderInfo{
 			Id:          id,
 			Id:          id,
-			CompanyName: common.ObjToString((*orderData)[0]["company_name"]),
+			CompanyName: gconv.String((*orderData)[0]["company_name"]),
 			UserId:      user_id,
 			UserId:      user_id,
 			ProductType: product_type,
 			ProductType: product_type,
 			OrderCode:   orderCode,
 			OrderCode:   orderCode,
 			PayMoney:    common.Float64All((*orderData)[0]["pay_money"]) / 100,
 			PayMoney:    common.Float64All((*orderData)[0]["pay_money"]) / 100,
 			ReturnMoney: common.Float64All((*orderData)[0]["return_money"]) / 100,
 			ReturnMoney: common.Float64All((*orderData)[0]["return_money"]) / 100,
 			UserPhone:   user_phone,
 			UserPhone:   user_phone,
-			StartEnd:    fmt.Sprintf("%s--%s", strings.Split(common.ObjToString((*orderData)[0]["vip_starttime"]), " ")[0], strings.Split(common.ObjToString((*orderData)[0]["vip_endtime"]), " ")[0]),
+			StartEnd:    fmt.Sprintf("%s--%s", strings.Split(gconv.String((*orderData)[0]["vip_starttime"]), " ")[0], strings.Split(gconv.String((*orderData)[0]["vip_endtime"]), " ")[0]),
 			SeriveList:  serviceList,
 			SeriveList:  serviceList,
-			SaleName:    common.ObjToString((*orderData)[0]["create_person"]),
+			SaleName:    gconv.String((*orderData)[0]["create_person"]),
 			UserName:    userName,
 			UserName:    userName,
 		}
 		}
 	}
 	}
@@ -1919,3 +1971,118 @@ func FindPersonOne(positionId int64) map[string]interface{} {
 	}
 	}
 	return (*personData)[0]
 	return (*personData)[0]
 }
 }
+
+// 进客成商品查询
+func KcProduct() ([]string, map[string]bool) {
+	var strArr []string
+	var strMap map[string]bool
+	productData := Mysql.SelectBySql(`SELECT
+	CONCAT( '"', class_name,'"' )  as   product   
+FROM
+	jy_product_class 
+WHERE
+	s_service = 1`)
+	if productData == nil && len(*productData) == 0 {
+		return strArr, strMap
+	}
+	for _, m := range *productData {
+		strMap[gconv.String(m["product"])] = true
+		strArr = append(strArr, gconv.String(m["product"]))
+	}
+	return strArr, strMap
+}
+func GetOrderProduct(productType string, file string) int64 {
+	fileJson := gconv.Map(file)
+	if fileJson == nil || len(fileJson) == 0 {
+		return 0
+	}
+	productName := ""
+	switch productType {
+	case "大会员":
+		comboId := gconv.Int(fileJson["comboId"])
+		// {1: "专家版", 2: "智慧版", 3: "商机版", 4: "试用版", 5: "定制版", 6: "商机版2.0", 7: "专家版2.0"}
+		switch comboId {
+		case 1:
+			productName = "大会员专家版"
+		case 2:
+			productName = "大会员智慧版"
+		case 3:
+			productName = "大会员商家版"
+		case 5:
+			productName = "大会员自定义"
+		case 6:
+			areaCount := common.IntAll(fileJson["areaCount"])
+			if areaCount == 1 {
+				productName = "大会员商机版2.0(单省版)"
+			} else {
+				productName = "大会员商机版2.0"
+			}
+		case 7:
+			productName = "大会员专家版2.0"
+		}
+	default:
+		productName = productType
+	}
+	productData := TiDb.FindOne("dwd_d_csm_product_access_code", map[string]interface{}{
+		"name": productName,
+	}, "", "")
+	if productData == nil || len(*productData) == 0 {
+		return 0
+	}
+	return gconv.Int64((*productData)["code"])
+}
+
+func GetTimeDifference(timeStr1, timeStr2 string) int {
+	// 解析时间字符串
+	t1, err1 := time.Parse(time.DateTime, timeStr1)
+	t2, err2 := time.Parse(time.DateTime, timeStr2)
+	if err1 != nil || err2 != nil {
+		fmt.Println("时间格式错误:", err1, err2)
+		return 0
+	}
+	// 计算时间差
+	daysDiff := gconv.Int(t2.Sub(t1).Hours() / 24)
+	fmt.Printf("两个时间相差 %.0f 天\n", daysDiff)
+	return daysDiff
+}
+func getOrderData(sql string) (map[string]map[string]interface{}, string) {
+	data := Mysql.SelectBySql(sql)
+	orderMap := map[string]map[string]interface{}{}
+	lastEndTime := ""
+	for _, v := range *data {
+		orderCode := gconv.String(v["order_code"])
+		product_type := gconv.String(v["productType"])
+		vip_starttime := gconv.String(v["service_starttime"])
+		vip_endtime := gconv.String(v["service_endtime"])
+		//判断一下服务周期
+		difference := GetTimeDifference(vip_starttime, vip_endtime)
+		productInt64 := GetOrderProduct(product_type, gconv.String(v["productFilter"]))
+		if productInt64 == 0 {
+			continue
+		}
+		if _, exists := orderMap[orderCode]; exists {
+			//判断服务周期
+			data := orderMap[orderCode]
+			//商品类型获取
+			oldDifference := gconv.Int(data["difference"])
+			if oldDifference >= difference {
+				//需要更换
+				lastEndTime = vip_endtime
+				v["difference"] = difference
+				v["product"] = productInt64
+				v["service_endtime"] = vip_endtime
+				v["service_starttime"] = vip_starttime
+				v["product_type"] = product_type
+				orderMap[orderCode] = v
+			}
+		} else {
+			lastEndTime = vip_endtime
+			v["difference"] = difference
+			v["product"] = productInt64
+			v["product_type"] = product_type
+			orderMap[orderCode] = v
+		}
+	}
+
+	return orderMap, lastEndTime
+}

+ 90 - 90
clueSync/main.go

@@ -7,10 +7,8 @@ import (
 	"app.yhyue.com/moapp/jybase/mongodb"
 	"app.yhyue.com/moapp/jybase/mongodb"
 	"app.yhyue.com/moapp/jybase/mysql"
 	"app.yhyue.com/moapp/jybase/mysql"
 	"app.yhyue.com/moapp/jybase/redis"
 	"app.yhyue.com/moapp/jybase/redis"
-	"bp.jydev.jianyu360.cn/BaseService/pushpkg/p"
 	"flag"
 	"flag"
 	"fmt"
 	"fmt"
-	"github.com/robfig/cron"
 	"log"
 	"log"
 )
 )
 
 
@@ -146,103 +144,105 @@ func main() {
 		MaxIdleConns: db.DataAnalysis.MaxIdle,
 		MaxIdleConns: db.DataAnalysis.MaxIdle,
 	}
 	}
 	DataAnalysisService.Init()
 	DataAnalysisService.Init()
-	Es = elastic.NewEs(db.Es.Version, db.Es.Address, db.Es.DbSize, db.Es.UserName, db.Es.Password)
+	//Es = elastic.NewEs(db.Es.Version, db.Es.Address, db.Es.DbSize, db.Es.UserName, db.Es.Password)
 	redis.InitRedis(db.RedisServer)
 	redis.InitRedis(db.RedisServer)
 	Mgo = mongodb.NewMgo(db.Mgo.Address, db.Mgo.DbName, db.Mgo.DbSize)
 	Mgo = mongodb.NewMgo(db.Mgo.Address, db.Mgo.DbName, db.Mgo.DbSize)
 	MgoLog = mongodb.NewMgoWithUser(db.MgoLog.Address, db.MgoLog.DbName, db.MgoLog.User, db.MgoLog.Password, db.MgoLog.DbSize)
 	MgoLog = mongodb.NewMgoWithUser(db.MgoLog.Address, db.MgoLog.DbName, db.MgoLog.User, db.MgoLog.Password, db.MgoLog.DbSize)
 	MgoQyxy = mongodb.NewMgoWithUser(db.MgoQyxy.Address, db.MgoQyxy.DbName, db.MgoQyxy.User, db.MgoQyxy.Password, db.MgoQyxy.DbSize)
 	MgoQyxy = mongodb.NewMgoWithUser(db.MgoQyxy.Address, db.MgoQyxy.DbName, db.MgoQyxy.User, db.MgoQyxy.Password, db.MgoQyxy.DbSize)
-	InitArea()
-	InitProduct(db.ProductArr)
-	if *mode == 1 {
-		go ordersClue() //后台订单进线索
-		//一秒钟一次
-		go p.VarTimeTask.RunInSecondTimeLoop("1秒钟定时任务", "", "", db.CornExp8, true, true, nil, func() {
-			LockHandle() //绑定状态处理
-		})
-		//30分钟一次
-		go p.VarTimeTask.RunInTimeLoop("30分钟定时任务", "", "", db.CornExp1, true, true, nil, func() {
-			orders()      //未支付订单
-			messageSync() //聊天记录进线索
-			userbase()    //新绑定手机号进线索
-		})
-		//5分钟一次
-		go p.VarTimeTask.RunInTimeSection("5分钟定时任务1", db.CornExp2Start, db.CornExp2End, db.CornExp2, func(dayFirst bool) {
+	//InitArea()
+	//InitProduct(db.ProductArr)
+	//refundAuto()
+	MarketCustomer() //客成移交销售
+	/*	if *mode == 1 {
+			go ordersClue() //后台订单进线索
+			//一秒钟一次
+			go p.VarTimeTask.RunInSecondTimeLoop("1秒钟定时任务", "", "", db.CornExp8, true, true, nil, func() {
+				LockHandle() //绑定状态处理
+			})
+			//30分钟一次
+			go p.VarTimeTask.RunInTimeLoop("30分钟定时任务", "", "", db.CornExp1, true, true, nil, func() {
+				orders()      //未支付订单
+				messageSync() //聊天记录进线索
+				userbase()    //新绑定手机号进线索
+			})
+			//5分钟一次
+			go p.VarTimeTask.RunInTimeSection("5分钟定时任务1", db.CornExp2Start, db.CornExp2End, db.CornExp2, func(dayFirst bool) {
 
 
-			users()               //新注册用户进线索
-			saleLeads()           //留资进线索
-			eventReg()            //渠道
-			bigCustomer()         //大客户线索
-			MarketCustomer()      //市场部线索
-			AdvisoryCommittee()   //咨询组线索
-			SelectionDepartment() //运营部线索
-			rebind()              //取关重新关注处理
-			activeUsers()         //活跃用户处理
-			inviteUser()          //邀请用户
-			nextYearActivity()    //开年活动
-		})
-		//每天8点30
-		c := cron.New()
-		c.AddFunc(db.CornExp3, func() {
-			users()       //新注册用户进线索
-			saleLeads()   //留资进线索
-			activeUsers() //活跃用户处理
-		})
-		c.Start()
-		// 一天一次
-		// tagAllSync()
-		d := cron.New()
-		d.AddFunc(db.CornExp4, func() {
-			tagAllSync() //用户标签
-		})
-		d.Start()
-		// 5分钟一次
-		go p.VarTimeTask.RunInTimeLoop("5分钟定时任务2", "", "", db.CornExp5, true, true, nil, func() {
-			//go p.VarTimeTask.RunInTimeSection("5分钟定时任务2", startTime, endTime, db.CornExp5, func(dayFirst bool) {
-			everythingSync()   //渠道
-			ordersClue()       //后台订单进线索
-			kcSync()           //移交客成
-			kcAuto()           //客成自动加入任务车
-			tagAddSync()       //用户标签增量
-			autoExitSea()      //自动退海
-			Thaw()             //自动解冻处理
-			subscribeAddSync() //订阅增量
-			CustomerChange()
-		})
-		//5分钟一次
-		go p.VarTimeTask.RunInTimeLoop("5分钟定时任务3", "", "", db.CornExp6, true, true, nil, func() {
-			//go p.VarTimeTask.RunInTimeSection("5分钟定时任务3", startTime, endTime, db.CornExp6, func(dayFirst bool) {
-			subscribeAddSync() //订阅增量
-			rderAcceptance()   //工单生成
-		})
-		//自动进入任务车 1天一次
+				users()               //新注册用户进线索
+				saleLeads()           //留资进线索
+				eventReg()            //渠道
+				bigCustomer()         //大客户线索
+				MarketCustomer()      //市场部线索
+				AdvisoryCommittee()   //咨询组线索
+				SelectionDepartment() //运营部线索
+				rebind()              //取关重新关注处理
+				activeUsers()         //活跃用户处理
+				inviteUser()          //邀请用户
+				nextYearActivity()    //开年活动
+			})
+			//每天8点30
+			c := cron.New()
+			c.AddFunc(db.CornExp3, func() {
+				users()       //新注册用户进线索
+				saleLeads()   //留资进线索
+				activeUsers() //活跃用户处理
+			})
+			c.Start()
+			// 一天一次
+			// tagAllSync()
+			d := cron.New()
+			d.AddFunc(db.CornExp4, func() {
+				tagAllSync() //用户标签
+			})
+			d.Start()
+			// 5分钟一次
+			go p.VarTimeTask.RunInTimeLoop("5分钟定时任务2", "", "", db.CornExp5, true, true, nil, func() {
+				//go p.VarTimeTask.RunInTimeSection("5分钟定时任务2", startTime, endTime, db.CornExp5, func(dayFirst bool) {
+				everythingSync()   //渠道
+				ordersClue()       //后台订单进线索
+				kcSync()           //移交客成
+				kcAuto()           //客成自动加入任务车
+				tagAddSync()       //用户标签增量
+				autoExitSea()      //自动退海
+				Thaw()             //自动解冻处理
+				subscribeAddSync() //订阅增量
+				CustomerChange()
+			})
+			//5分钟一次
+			go p.VarTimeTask.RunInTimeLoop("5分钟定时任务3", "", "", db.CornExp6, true, true, nil, func() {
+				//go p.VarTimeTask.RunInTimeSection("5分钟定时任务3", startTime, endTime, db.CornExp6, func(dayFirst bool) {
+				subscribeAddSync() //订阅增量
+				rderAcceptance()   //工单生成
+			})
+			//自动进入任务车 1天一次
 
 
-		g := cron.New()
-		g.AddFunc(db.CornExp7, func() {
-			readClue()   //读取中间表进线索
-			refundAuto() //客成移交销售
-			autoTask()   //超时未跟进加入任务车
-			autoTasks()  //按照下次跟进时间提前一天加入任务车
-			ClueToDxTask()
-		})
-		g.Start()
-		log.Println("个人邮件告警查询开始")
-		WarningPerl() // 个人
-		log.Println("部门邮件告警查询开始")
-		WarningDm() // 部门
-		log.Println("个人/部门邮件告警查询结束")
-		h := cron.New()
-		h.AddFunc(db.CornMail, func() {
+			g := cron.New()
+			g.AddFunc(db.CornExp7, func() {
+				readClue()   //读取中间表进线索
+				refundAuto() //客成移交销售
+				autoTask()   //超时未跟进加入任务车
+				autoTasks()  //按照下次跟进时间提前一天加入任务车
+				ClueToDxTask()
+			})
+			g.Start()
 			log.Println("个人邮件告警查询开始")
 			log.Println("个人邮件告警查询开始")
 			WarningPerl() // 个人
 			WarningPerl() // 个人
 			log.Println("部门邮件告警查询开始")
 			log.Println("部门邮件告警查询开始")
 			WarningDm() // 部门
 			WarningDm() // 部门
 			log.Println("个人/部门邮件告警查询结束")
 			log.Println("个人/部门邮件告警查询结束")
-			UpperLimitAutoExitSea(db.AllocationCap)
-		})
-		h.Start()
-		select {}
-	} else {
-		users()
-		saleLeads()
-	}
+			h := cron.New()
+			h.AddFunc(db.CornMail, func() {
+				log.Println("个人邮件告警查询开始")
+				WarningPerl() // 个人
+				log.Println("部门邮件告警查询开始")
+				WarningDm() // 部门
+				log.Println("个人/部门邮件告警查询结束")
+				UpperLimitAutoExitSea(db.AllocationCap)
+			})
+			h.Start()
+			select {}
+		} else {
+			users()
+			saleLeads()
+		}*/
 }
 }

+ 5 - 3
clueSync/tag.go

@@ -261,15 +261,17 @@ func tagAddSync() {
 			if k == 0 {
 			if k == 0 {
 				cfg.LastOrderTime = autoUpdate
 				cfg.LastOrderTime = autoUpdate
 			}
 			}
-			orderDatas := TiDb.Find("dwd_f_userbase_order_info", map[string]interface{}{"uid": uId, "order_status": 1, "delete_status": 0}, "", "", -1, -1)
+			personArr := getUserIdToUid(uId)
+			orderDataSql := fmt.Sprintf(`select  a.*,b.product_type as  productType from  dataexport_order  a   INNER JOIN   jy_order_detail   b    on   a.order_code=b.order_code and    a.user_id    in   (%s) and   a.order_status = 1  and  a.delete_status =0 ORDER BY  b.service_endtime  desc  `, strings.Join(personArr, ","))
+			orderDatas := Mysql.SelectBySql(orderDataSql)
 			if orderDatas != nil && len(*orderDatas) > 0 {
 			if orderDatas != nil && len(*orderDatas) > 0 {
 				product_type_arr, product_type_arrs := []string{}, []string{}
 				product_type_arr, product_type_arrs := []string{}, []string{}
 				for _, v := range *orderDatas {
 				for _, v := range *orderDatas {
-					payable_money := gconv.Int64(v["payable_money"])
+					payable_money := gconv.Int64(v["pay_money"])
 					if payable_money <= 0 {
 					if payable_money <= 0 {
 						continue
 						continue
 					}
 					}
-					product_type := common.ObjToString(v["product_type"])
+					product_type := common.ObjToString(v["productType"])
 					log.Println("product_type ", product_type)
 					log.Println("product_type ", product_type)
 					if product_type != "" {
 					if product_type != "" {
 						product_type_arr = append(product_type_arr, product_type)
 						product_type_arr = append(product_type_arr, product_type)

+ 51 - 0
clueSync/util.go

@@ -1,7 +1,10 @@
 package main
 package main
 
 
 import (
 import (
+	"app.yhyue.com/moapp/jybase/common"
+	"app.yhyue.com/moapp/jybase/mongodb"
 	"fmt"
 	"fmt"
+	"github.com/gogf/gf/v2/util/gconv"
 	"time"
 	"time"
 )
 )
 
 
@@ -26,3 +29,51 @@ func TimeStrcount(start, end string) int64 {
 	fmt.Printf("相差的天数: %d 天\n", days)
 	fmt.Printf("相差的天数: %d 天\n", days)
 	return days
 	return days
 }
 }
+
+// 用户信息转uid查询
+func GetUidToUserId(userId string, phone string) (string, string) {
+	uId := ""
+	query := map[string]interface{}{}
+	if userId == "" {
+		query["phone"] = phone
+		userInfo := TiDb.FindOne("dwd_f_userbase_baseinfo", query, "", "")
+		if userInfo != nil && len(*userInfo) > 0 {
+			uId = gconv.String((*userInfo)["uid"])
+			userId = gconv.String((*userInfo)["userid"])
+		}
+	} else {
+		if !mongodb.IsObjectIdHex(userId) {
+			userMapping := TiDb.FindOne("dwd_f_userbase_id_mapping", map[string]interface{}{"position_id": userId}, "", "")
+			if userMapping != nil && len(*userMapping) > 0 {
+				userId = common.ObjToString((*userMapping)["userid"])
+			} else {
+				return uId, userId
+			}
+		}
+		query["userid"] = userId
+		userInfo := TiDb.FindOne("dwd_f_userbase_baseinfo", query, "", "")
+		if userInfo != nil && len(*userInfo) > 0 {
+			uId = common.ObjToString((*userInfo)["uid"])
+		} else {
+			return uId, userId
+		}
+	}
+	return uId, userId
+}
+func getUserIdToUid(uid string) []string {
+	personData := TiDb.SelectBySql(`SELECT
+	CONCAT( '"', position_id,'"' )  as   positionId   
+FROM
+	dwd_f_userbase_id_mapping 
+WHERE
+	uid = %s and  type=1`, uid)
+	if personData == nil || len(*personData) == 0 {
+		return []string{}
+	}
+	var personArr []string
+	for _, v := range *personData {
+		personArr = append(personArr, gconv.String(v["positionId"]))
+	}
+	return personArr
+
+}