소스 검색

客成处理

WH01243 6 달 전
부모
커밋
a04f274afd
3개의 변경된 파일198개의 추가작업 그리고 153개의 파일을 삭제
  1. 1 1
      clueSync/db.json
  2. 196 151
      clueSync/kc.go
  3. 1 1
      clueSync/util.go

+ 1 - 1
clueSync/db.json

@@ -164,7 +164,7 @@
   "newRegistration": 1,
   "expirationPeriod": 30,
   "handoverCycle": 60,
-  "customerTime": 1733846400,
+  "customerTime": 1603846400,
   "mail": {
     "smtpHost": "smtp.exmail.qq.com",
     "smtpPort": 465,

+ 196 - 151
clueSync/kc.go

@@ -18,16 +18,22 @@ import (
 
 func kcSync() {
 	log.Println("客户成功系统移交定时任务开始")
-	sql := `select * from dwd_f_userbase_order_info where payable_money > 0 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 (payable_money > 0 or  (payable_money=0 and  ( filter  like "%分期付款补充权益%"  or   filter  like "%原订单不支持开通多项权益%"  or    filter  like "%原订单不支持开通多项权益%")))
+	  and  data_spec!="dhy4" and  order_status=1  and refund_status!=1  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="160431577234"  `
 	data := TiDb.SelectBySql(sql)
 	if data != nil && *data != nil && len(*data) > 0 {
+		arr := []string{}
 		for _, v := range *data {
 			product_type := common.ObjToString(v["product_type"])
-			data_spec := common.ObjToString(v["data_spec"])
-			starttime := common.ObjToString(v["vip_starttime"])
-			order_status := common.IntAll(v["order_status"])
-			refund_status := common.IntAll(v["refund_status"])
-			if (product_type == "大会员" || product_type == "企业商机管理") && order_status == 1 && data_spec != "dhy4" && !strings.HasPrefix(starttime, "2099") && refund_status != 1 {
+			vip_starttime := common.ObjToString(v["vip_starttime"])
+			vip_endtime := common.ObjToString(v["vip_endtime"])
+			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)
 				status := kcJob(v)
 				if status == 0 {
 					break
@@ -35,81 +41,90 @@ func kcSync() {
 			}
 			cfg.LastkcTime = common.ObjToString(v["autoUpdate"])
 		}
+		log.Println(strings.Join(arr, "`,`"))
 	}
+
 	common.WriteSysConfig(&cfg)
 	log.Println("客户成功系统移交定时任务结束")
 }
 
 func kcJob(data map[string]interface{}) int {
 	nowTime := time.Now().Format(date.Date_Full_Layout)
-	uId, entId, clueId, saveMap, name, positionId, status := common.ObjToString(data["uid"]), fmt.Sprint(data["ent_id"]), int64(0), map[string]interface{}{}, "", int64(0), 1
+	uId, entId, clueId, saveMap, status := common.ObjToString(data["uid"]), fmt.Sprint(data["ent_id"]), int64(0), map[string]interface{}{}, 1
 	clueData := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"uid": uId}, "", "")
 	orderCode := gconv.String(data["order_code"])
 	saleDep, orderPositionId, salesperson := FindSaleRecord(orderCode)
+	log.Println(data["order_code"], saleDep, orderPositionId, salesperson)
 	if clueData == nil || len(*clueData) == 0 {
-		role, industry, department, departments, position, name, top_cluetype, sub_cluetype, follow_project_area := "", "", "", "", "", "", "", "", ""
-		query, topname, subname, belong_to, remark, sourceId := map[string]interface{}{}, "", "", "01", "", int64(0)
+		if saleDep == "销售部" || saleDep == "市场部" {
+			return 1
+		}
 		//创建线索
 		//原始订单获取
+		position_id := int64(0)
 		orderData := Mysql.FindOne("dataexport_order", map[string]interface{}{
 			"order_code": orderCode,
 		}, "", "")
 		if orderData == nil {
 			log.Println("原始订单查询不到:", orderCode)
 		}
-		userId, uId, source, cluename, phone, sourceCode, keyword, _, positionId := common.ObjToString((*orderData)["user_id"]), "", "", "", "", "", []string{}, "", ""
+		userId, cluename, phone := common.ObjToString((*orderData)["user_id"]), "", ""
 		seatNumber := ""
 		if saleDep == "客户成功组" {
 			//新增线索
-			orderPositionId = 0
+			position_id = 0
+		} else if saleDep == "销售部" {
+			log.Println("该订单数据销售部业绩,不会创建线索")
+			return 0
 		} else {
+			position_id = orderPositionId
 			//其他信息
 			seatNumber = "0000"
 		}
-		if !mongodb.IsObjectIdHex(userId) {
-			positionId = 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"])
-			}
-		}
-		query["userid"] = userId
-		userInfo := TiDb.FindOne("dwd_f_userbase_baseinfo", query, "", "")
-		if userInfo != nil && len(*userInfo) > 0 {
-			uId = common.ObjToString((*userInfo)["uid"])
-			source = common.ObjToString((*userInfo)["source"])       //用户来源
-			belong_to = common.ObjToString((*userInfo)["belong_to"]) //用户归属
-		}
 		cluename = common.ObjToString(data["company_name"])
 		phone = common.ObjToString(data["user_phone"])
-		//线索信息处理
-		isGroup, isCommerce := GetCompanyType(cluename, uId)
-		if source == "0104" || strings.HasPrefix(belong_to, "02") || source == "0102" || source == "0103" || phone == "" { //参照用户来源代码表
-			return 0
+		if cluename == "" {
+			cluename = phone
 		}
-		qid := positionId
-		if qid == "" {
-			qid = userId
-		}
-		saleLeadsData, ok := Mgo.Find("saleLeads", map[string]interface{}{"userid": qid}, map[string]interface{}{"_id": -1}, nil, false, 0, 1)
-		if ok && saleLeadsData != nil && len(*saleLeadsData) > 0 {
-			sdata := (*saleLeadsData)[0]
-			role = common.ObjToString(sdata["companyType"])
-			industry = common.ObjToString(sdata["industry"])
-			department = common.ObjToString(sdata["branch"])
-			departments = common.ObjToString(sdata["department"])
-			position = common.ObjToString(sdata["position"])
-			name = common.ObjToString(sdata["name"])
-		}
-		top_cluetype, sub_cluetype, _, topname, subname = getClueType("order", data, sourceCode, sourceId) //查留资来源名字
-		kcClue(userId, uId, seatNumber, cluename, top_cluetype, sub_cluetype,
-			name, phone, position, sourceCode, industry, follow_project_area,
-			role, "order", subname, topname, remark, "", department, departments, salesperson, source,
-			orderPositionId, isGroup, isCommerce,
-			keyword)
-		clueData = TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"uid": uId}, "", "")
-		if clueData == nil || len(*clueData) == 0 {
-			return 0
+		trailstatus := "08"
+		isGroup, isCommerce := GetCompanyType(cluename, uId) //判断是否集团公司、工商库
+		clueId = TiDb.Insert("dwd_f_crm_clue_info", map[string]interface{}{
+			"userid":               userId,
+			"uid":                  uId,
+			"is_assign":            common.If(position_id > 0, 1, 0),
+			"createtime":           nowTime,
+			"updatetime":           nowTime,
+			"cluename":             cluename,
+			"seatNumber":           seatNumber,
+			"position_id":          position_id,
+			"top_cluetype":         "4",
+			"sub_cluetype":         "154",
+			"trailstatus":          trailstatus,
+			"name":                 phone,
+			"phone":                phone,
+			"is_task":              0,
+			"taskstatus":           0,
+			"company_nature":       isGroup,
+			"company_verification": isCommerce,
+			"FREEZE_TIME":          nowTime,
+			"label":                common.If(position_id > 0, 1, nil),
+		})
+		if clueId > 0 {
+			TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
+				"clue_id":     clueId,
+				"position_id": common.If(position_id > 0, position_id, -1),
+				"change_type": "创建线索",
+				"new_value":   "系统自动创建",
+				"createtime":  nowTime,
+				"BCPCID":      common.GetRandom(32),
+				"operator_id": -1,
+			})
+			clueData = TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"uid": uId}, "", "")
+			if clueData == nil || len(*clueData) == 0 {
+				return 0
+			}
+		} else {
+			return 1
 		}
 	}
 	clueId = common.Int64All((*clueData)["id"])
@@ -159,12 +174,10 @@ func kcJob(data map[string]interface{}) int {
 		}
 	}
 	//同一公司名称(以客户详情-组织机构-公司名称)下的线索需分配给同1人
-	log.Println("移交客成positionId", positionId, name, saleDep, orderPositionId, salesperson)
+
 	saveMap = map[string]interface{}{
 		"clue_id":                   clueId,
 		"transfertime":              nowTime,
-		"position_id":               positionId,
-		"name":                      name,
 		"service_starttime":         starttime,
 		"service_endtime":           endtime,
 		"ent_id":                    entId,
@@ -185,9 +198,12 @@ func kcJob(data map[string]interface{}) int {
 	if TiDb.Count("dwd_f_csm_customer_info", map[string]interface{}{"clue_id": clueId}) > 0 {
 		csmdata := TiDb.FindOne("dwd_f_csm_customer_info", map[string]interface{}{"clue_id": clueId}, "", "")
 		if csmdata != nil && len(*csmdata) > 0 {
-			positionId = int64(gconv.Int((*csmdata)["position_id"]))
-			name = gconv.String((*csmdata)["(*csmdata)[\"name\"]"])
-			TiDb.Update("dwd_f_csm_customer_info", map[string]interface{}{"clue_id": clueId}, map[string]interface{}{
+			id := gconv.Int64((*csmdata)["id"])
+			log.Println(1111111, id, orderCode)
+			customerPositionId, customerName := cAutoDraw(0, orderPositionId, salesperson, saleDep, true, csmdata)
+			log.Println("移交客成positionId", customerPositionId, customerName, saleDep, orderPositionId, salesperson, true)
+			oldName := gconv.String((*csmdata)["name"])
+			updateMap := map[string]interface{}{
 				"is_transfer":           0,
 				"is_renewal_protection": 0,
 				"product_access":        product,
@@ -197,52 +213,58 @@ func kcJob(data map[string]interface{}) int {
 				"service_endtime":       endtime,
 				"ent_id":                entId,
 				"company_name":          company_name,
-			})
+				"name":                  customerName,
+				"position_id":           customerPositionId,
+			}
+			TiDb.Update("dwd_f_csm_customer_info", map[string]interface{}{"clue_id": clueId}, updateMap)
 			TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
 				"clue_id":     clueId,
-				"position_id": positionId,
+				"position_id": customerPositionId,
 				"change_type": "成交客户移交",
 				"new_value":   "移交至客户成功组",
 				"createtime":  nowTime,
 				"BCPCID":      common.GetRandom(32),
 				"operator_id": -1,
 			})
-			if positionId > 0 {
+			if customerPositionId > 0 {
 				TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
 					"clue_id":      clueId,
-					"position_id":  positionId,
+					"position_id":  customerPositionId,
 					"change_field": "position_id",
 					"change_type":  "客户成功经理",
-					"old_value":    "/",
-					"new_value":    name,
+					"old_value":    common.If(oldName != customerName, customerName, common.If(oldName == "", "/", oldName)),
+					"new_value":    customerName,
 					"createtime":   nowTime,
 					"BCPCID":       common.GetRandom(32),
 					"operator_id":  -1,
 				})
-				KcSend(orderCode, name)
+				TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
+					"clue_id":     clueId,
+					"position_id": customerPositionId,
+					"change_type": "加入任务车",
+					"new_value":   "未建联",
+					"createtime":  nowTime,
+					"BCPCID":      common.GetRandom(32),
+					"operator_id": -1,
+				})
+				KcSend(orderCode, customerName)
 			}
-
 			TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, map[string]interface{}{"is_transfer": 1, "updatetime": nowTime, "name": userName})
 		}
 	} else {
 		entIds := common.IntAll(data["ent_id"])
-		if saleDep == "客户成功组" {
-			if orderPositionId == 0 {
-				positionId, name = orderPositionId, salesperson
-			} else {
-				positionId, name = cAutoDraw(entIds)
-			}
-		} else {
-			positionId, name = cAutoDraw(entIds)
-		}
-		cId, ok, updateId1, updateId2, updateId3 := int64(-1), false, int64(-1), int64(-1), int64(-1)
+		customerPositionId, customerName := cAutoDraw(entIds, orderPositionId, salesperson, saleDep, false, nil)
+		log.Println("移交客成positionId", customerPositionId, customerName, saleDep, orderPositionId, salesperson, false)
+		cId, ok, updateId1, updateId2, updateId3 := int64(0), false, int64(0), int64(0), int64(0)
 		if TiDb.ExecTx("保存客户", func(tx *sql.Tx) bool {
+			saveMap["position_id"] = customerPositionId
+			saveMap["name"] = customerName
 			cId = TiDb.InsertByTx(tx, "dwd_f_csm_customer_info", saveMap)
 			ok = TiDb.UpdateByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, map[string]interface{}{"is_transfer": 1, "updatetime": nowTime, "name": userName})
-			if positionId > 0 {
+			if customerPositionId > 0 {
 				updateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
 					"clue_id":     clueId,
-					"position_id": positionId,
+					"position_id": customerPositionId,
 					"change_type": "加入任务车",
 					"new_value":   "未建联",
 					"createtime":  nowTime,
@@ -251,20 +273,20 @@ func kcJob(data map[string]interface{}) int {
 				})
 				updateId3 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
 					"clue_id":      clueId,
-					"position_id":  positionId,
+					"position_id":  customerPositionId,
 					"change_field": "position_id",
 					"change_type":  "客户成功经理",
 					"old_value":    "/",
-					"new_value":    name,
+					"new_value":    customerName,
 					"createtime":   nowTime,
 					"BCPCID":       common.GetRandom(32),
 					"operator_id":  -1,
 				})
-				KcSend(orderCode, name)
+				KcSend(orderCode, customerName)
 			}
 			updateId2 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
 				"clue_id":     clueId,
-				"position_id": positionId,
+				"position_id": customerPositionId,
 				"change_type": "成交客户移交",
 				"new_value":   "移交至客户成功组",
 				"createtime":  nowTime,
@@ -276,68 +298,74 @@ func kcJob(data map[string]interface{}) int {
 			//TiDb.UpdateOrDeleteBySql(`update dwd_f_csm_customer_autodraw_record set count = count + 1 where name = ?`, name)
 			log.Println("保存客户成功")
 		} else {
-			log.Println("保存客户失败!!!", clueId, cId, ok, updateId1, updateId2, updateId3, " 用户信息 ", name, positionId, uId)
+			log.Println("保存客户失败!!!", clueId, cId, ok, updateId1, updateId2, updateId3, " 用户信息 ", customerName, customerPositionId, uId)
 		}
 	}
 	return status
 }
 
-func cAutoDraw(entId int) (positionId int64, name string) {
-	query := `SELECT name,position_id FROM dwd_d_crm_department_level_succbi WHERE bi_pcode = (SELECT bi_code FROM dwd_d_crm_department_level_succbi WHERE name = "客户成功组" and resign=0) and resign = 0`
+func cAutoDraw(entId int, orderPositionId int64, salesperson, saleDep string, isExist bool, csmdata *map[string]interface{}) (positionId int64, name string) {
+	query := `SELECT name,position_id FROM dwd_d_crm_department_level_succbi WHERE bi_pcode = (SELECT bi_code FROM dwd_d_crm_department_level_succbi WHERE name = "客户成功部" and resign=0) and resign = 0 `
 	data := TiDb.SelectBySql(query)
-	if data != nil && len(*data) > 0 {
-		if entId > 0 {
-			entdata := TiDb.FindOne("dwd_f_csm_customer_info", map[string]interface{}{"ent_id": entId}, "", "")
-			if entdata != nil && len(*entdata) > 0 {
-				positionId = common.Int64All((*entdata)["position_id"])
-				name = common.ObjToString((*entdata)["name"])
-				return
-			}
-		}
-		/*sql := `select a.name,a.count from dwd_f_csm_customer_autodraw_record a INNER JOIN dwd_d_crm_department_level_succbi b on (a.name = b.name) where b.resign = 0`
-		countData := TiDb.SelectBySql(sql)
-		if countData != nil && len(*countData) > 0 {
+	if data == nil || len(*data) == 0 {
+		return
+	}
+	//判断是否需要新增客成数据
+	if isExist {
+		//用户存在客成数据
+		positionid := common.Int64All((*csmdata)["position_id"])
+		if positionid != 0 {
+			//以前没有,需要找一个新的
 			for _, v := range *data {
-				//判断是否有新员工
-				isOk := false
-				for _, vv := range *countData {
-					if common.ObjToString(v["name"]) == common.ObjToString(vv["name"]) {
-						isOk = true
-					}
-				}
-				//有新员工直接分给新员工
-				if !isOk {
-					name = common.ObjToString(v["name"])
-					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{}{
-						"name":  name,
-						"count": common.Int64All((*rData)["count"]),
-					})
-					break
+				deptPositionId := gconv.Int64(v["position_id"])
+				if deptPositionId == positionid {
+					positionId = positionid
+					name = common.ObjToString((*csmdata)["name"])
+					return
 				}
 			}
-			res := int64(0)
-			countres := 0
-			for _, v := range *countData {
-				if countres == 0 {
-					res = common.Int64All(v["count"])
-					name = common.ObjToString(v["name"])
-				} else {
-					if common.Int64All(v["count"]) <= res {
-						res = common.Int64All(v["count"])
-						name = common.ObjToString(v["name"])
+		}
+		//原始用户已离职 查看订单是否有合适的订单
+		if saleDep == "客户成功组" {
+			positionId = orderPositionId
+			name = salesperson
+			return
+		}
+	}
+	//客成数据不存在的时候
+	//查找企业有没有其他信息
+	if entId > 0 {
+		entdata := TiDb.Find("dwd_f_csm_customer_info", map[string]interface{}{"ent_id": entId}, "", "", -1, -1)
+		if entdata != nil && len(*entdata) > 0 {
+			for _, v := range *entdata {
+				positionid := common.Int64All(v["position_id"])
+				name = common.ObjToString(v["name"])
+				for _, v := range *data {
+					deptPositionId := gconv.Int64(v["position_id"])
+					if deptPositionId == positionId {
+						positionId = positionid
+						name = common.ObjToString((*csmdata)["name"])
+						return
 					}
 				}
-				countres++
-			}
-		}*/
-		/*for _, v := range *data {
-			if name == common.ObjToString(v["name"]) {
-				positionId = common.Int64All(v["position_id"])
 			}
-		}*/
+		}
+		//原始用户已离职 或者没有查找相关企业客成信息    以订单信息为主
+		if saleDep == "客户成功组" {
+			positionId = orderPositionId
+			name = salesperson
+		}
+		return
+		//没有相同企业的客成信息
+	} else {
+		//没有人  分配给自己
+		if saleDep == "客户成功组" {
+			positionId = orderPositionId
+			name = salesperson
+			return
+		}
+		return
 	}
-	return
 }
 
 func kcAuto() {
@@ -595,7 +623,7 @@ func refundAuto() {
 			if isRenewalProtection == 0 {
 				aaa := TiDb.CountBySql(`select count(1) from dwd_f_userbase_order_info where uid=?   and (product_type = "企业商机管理" or product_type = "大会员") and order_status = 1  and  refund_status!=1 and vip_endtime < ? and  vip_endtime > ? `, uid, time.Now().AddDate(0, 0, -db.ExpirationPeriod+1).Format(date.Date_Short_Layout), time.Now().AddDate(0, 0, -db.ExpirationPeriod).Format(date.Date_Short_Layout))
 				log.Println(aaa)
-				if TiDb.CountBySql(`select count(1) from dwd_f_userbase_order_info where uid=?   and (product_type = "企业商机管理" or product_type = "大会员") and order_status = 1  and  refund_status!=1 and vip_endtime < ? and  vip_endtime < ? `, uid, time.Now().AddDate(0, 0, -db.ExpirationPeriod+1).Format(date.Date_Short_Layout), time.Now().AddDate(0, 0, -db.ExpirationPeriod).Format(date.Date_Short_Layout)) > 0 {
+				if aaa > 0 {
 					//即将到期
 					mailData[name] = append(mailData[name], map[string]interface{}{
 						"company_name": company_name,
@@ -680,22 +708,26 @@ func refundAuto() {
 						for _, vv := range *order3 {
 							if isRenewalProtection == 1 {
 								vip_endtime := common.ObjToString(vv["vip_endtime"])
-								vip_endtimes, _ := time.ParseInLocation(date.Date_Short_Layout, vip_endtime, time.Local)
+								vip_endtimes, _ := time.ParseInLocation(date.Date_Full_Layout, vip_endtime, time.Local)
 								//查询申请保护时间
-								renewalTime := time.Time{}
+								renewalTime := time.Now()
 								timeData := TiDb.SelectBySql(`select  max(createtime) as createtime from   dwd_f_crm_clue_change_record   where   clue_id =  ?  and  change_type="申请续费保护"`, clueId)
 								if timeData != nil && len(*timeData) > 0 {
-									renewalTime, _ = time.ParseInLocation(date.Date_Short_Layout, gconv.String((*timeData)[0]["createtime"]), time.Local)
+									if gconv.String(gconv.String((*timeData)[0]["createtime"])) != "" {
+										renewalTime, _ = time.ParseInLocation(date.Date_Short_Layout, gconv.String((*timeData)[0]["createtime"]), time.Local)
+									}
 								}
 								renewalInt := renewalTime.Unix()
 								log.Println("申请保护期时间", clueId, renewalInt)
+								log.Println("申请保护期时间222", time.Now().Unix()-vip_endtimes.Unix(), (db.HandoverCycle-1)*86400, (db.HandoverCycle)*86400)
+								log.Println("申请保护期时间333", (db.HandoverCycle-1)*86400 < time.Now().Unix()-vip_endtimes.Unix(), time.Now().Unix()-vip_endtimes.Unix() < (db.HandoverCycle)*86400)
 								//查看服务到期时间
 								if renewalInt != 0 && renewalInt < db.CustomerTime {
 									//三个月
 									if time.Now().Unix()-vip_endtimes.Unix() < 3*30*86400 {
 										isOk = true
 									}
-								} else if time.Now().Unix()-vip_endtimes.Unix() < (db.HandoverCycle-1)*86400 {
+								} else if (db.HandoverCycle-2)*86400 < time.Now().Unix()-vip_endtimes.Unix() && time.Now().Unix()-vip_endtimes.Unix() < (db.HandoverCycle-1)*86400 {
 									//提前一天提示
 									mailData[name] = append(mailData[name], map[string]interface{}{
 										"company_name": company_name,
@@ -766,6 +798,14 @@ func refundAuto() {
 									}
 								}
 							}
+						} else {
+							if isFull {
+								TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_crm_clue_info SET is_unfollow=0,updatetime=?,trailstatus="01",top_cluetype="532",sub_cluetype="537",is_transfer=0,is_assign=-3,FREEZE_TIME=? WHERE id = ?`, nowTime, nowTime, clueId)
+							} else {
+								TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_crm_clue_info SET is_unfollow=0,updatetime=?,trailstatus="01",top_cluetype="532",sub_cluetype="537",is_transfer=0 WHERE id = ?`, nowTime, clueId)
+							}
+						}
+						if kcposition_id > 0 {
 							mailData[name] = append(mailData[name], map[string]interface{}{
 								"company_name": company_name,
 								"phone":        phone,
@@ -773,14 +813,7 @@ func refundAuto() {
 								"remrk":        "已移交",
 								"reason":       "成交客户续费失败",
 							})
-						} else {
-							if isFull {
-								TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_crm_clue_info SET is_unfollow=0,updatetime=?,trailstatus="01",top_cluetype="532",sub_cluetype="537",is_transfer=0,is_assign=-3,FREEZE_TIME=? WHERE id = ?`, nowTime, nowTime, clueId)
-							} else {
-								TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_crm_clue_info SET is_unfollow=0,updatetime=?,trailstatus="01",top_cluetype="532",sub_cluetype="537",is_transfer=0 WHERE id = ?`, nowTime, clueId)
-							}
 						}
-
 						TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
 							"clue_id":      clueId,
 							"position_id":  common.If(kcposition_id > 0, kcposition_id, -1),
@@ -855,8 +888,8 @@ func refundAuto() {
 			}
 		}
 		return true
-		//}, `select ent_id,clue_id,position_id,name,is_renewal_protection from dwd_f_csm_customer_info where is_transfer = 0`)
-	}, `select ent_id,clue_id,position_id,name,is_renewal_protection from dwd_f_csm_customer_info where id =150022`)
+	}, `select ent_id,clue_id,position_id,name,is_renewal_protection from dwd_f_csm_customer_info where is_transfer = 0`)
+	//}, `select ent_id,clue_id,position_id,name,is_renewal_protection from dwd_f_csm_customer_info where id =150022`)
 	//移交电销提醒
 	for i, v := range mailData {
 		if i != "" {
@@ -1067,12 +1100,19 @@ func KcSend(orderCode, personName string) {
 			tableAppend += fmt.Sprintf(db.KeCheng.Mail.ReturnMoney, orderInfo.ReturnMoney)
 		}
 		table := ""
-		deptData := Mysql.SelectBySql("select b.mail from jianyu.entniche_department_user a inner join jianyu.entniche_user b on a.dept_id=? and a.user_id=b.id and b.name=? ", db.KeCheng.DeptId, personName)
+		deptData := Mysql.SelectBySql(`select  b.mail  as  mail from jianyu.entniche_department_user a inner join jianyu.entniche_user b on a.dept_id=? and a.user_id=b.id `, db.KeCheng.DeptId)
 		table += fmt.Sprintf(db.KeCheng.Mail.Table, orderInfo.ProductType, orderInfo.CompanyName, orderInfo.UserPhone, orderInfo.UserName, orderInfo.OrderCode, orderInfo.PayMoney, orderInfo.StartEnd, orderInfo.DisKcName, orderInfo.SaleName, tableAppend)
 		//发送邮件
 		if deptData != nil && len(*deptData) > 0 && table != "" {
-			mailStr := gconv.String((*deptData)[0]["mail"])
-			if mailStr != "" {
+			mailArr := []string{}
+			for _, m := range *deptData {
+				mail := gconv.String(m["mail"])
+				if mail != "" {
+					mailArr = append(mailArr, gconv.String(m["mail"]))
+				}
+			}
+			if len(mailArr) > 0 {
+				mailStr := strings.Join(mailArr, "|")
 				gmail := &mail.GmailAuth{
 					SmtpHost: db.Mail.SmtpHost,
 					SmtpPort: db.Mail.SmtpPort,
@@ -1090,8 +1130,13 @@ func KcSend(orderCode, personName string) {
 func ExitKcSend(personName string, infoList []map[string]interface{}) {
 	//退出客成 即将退出客成信息
 	deptData := Mysql.SelectBySql("select b.mail from jianyu.entniche_department_user a inner join jianyu.entniche_user b on a.dept_id=? and a.user_id=b.id and b.name=? ", db.KeCheng.DeptId, personName)
+	adminData := Mysql.SelectBySql(`	select c.mail   from entniche_department_user  a   INNER JOIN     entniche_user_role b  on  a.dept_id=59005 and  a.user_id = b.user_id and  b.role_id=2  INNER JOIN   entniche_user c  on a.user_id=c.id`)
 	if deptData != nil && len(*deptData) > 0 {
 		mailStr := gconv.String((*deptData)[0]["mail"])
+		adminMailStr := ""
+		if adminData != nil && len(*adminData) > 0 {
+			adminMailStr = gconv.String((*adminData)[0]["mail"])
+		}
 		if mailStr != "" {
 			gmail := &mail.GmailAuth{
 				SmtpHost: db.Mail.SmtpHost,
@@ -1100,13 +1145,13 @@ func ExitKcSend(personName string, infoList []map[string]interface{}) {
 				Pwd:      db.Mail.Pwd,
 			}
 			//正文拼接
-			startStr := `<html lang="zh-CN"><head><meta charset="UTF-8"><meta name="viewport"content="width=device-width, initial-scale=1.0"><style>table{width:100%;border-collapse:collapse}th,td{border:1px solid#000;padding:8px;text-align:left}th{background-color:#f2f2f2}</style></head><body><table><thead><tr><th>序号</th><th>公司名称</th><th>联系人</th><th>姓名</th><th>移交状态</th><th>移交销售原因</th></tr></thead><tbody>`
+			startStr := `<html lang="zh-CN"><head><meta charset="UTF-8"><meta name="viewport"content="width=device-width, initial-scale=1.0"><style>table{width:100%;border-collapse:collapse}th,td{border:1px solid#000;padding:8px;text-align:left}th{background-color:#f2f2f2}</style></head><body><p>以下客户已从或即将从客成系统退出,并移交销售跟进,请收悉,客户明细如下:</p><table><thead><tr><th>序号</th><th>公司名称</th><th>联系人</th><th>姓名</th><th>移交状态</th><th>移交销售原因</th></tr></thead><tbody>`
 			for i, v := range infoList {
-				startStr += fmt.Sprintf(`<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>`, i+1, gconv.String(v["company_name"]), gconv.String(v["phone"]), gconv.String(v["name"]), gconv.String(v["remrk"]), gconv.String(v["reason"]))
+				startStr += fmt.Sprintf(`<tr><td>%d</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>`, i+1, gconv.String(v["company_name"]), gconv.String(v["phone"]), gconv.String(v["name"]), gconv.String(v["remrk"]), gconv.String(v["reason"]))
 			}
 			endStr := `</tbody></table><p></body></html>`
 			startStr += endStr
-			status := mail.GSendMail_q("剑鱼标讯", mailStr, "", "", "客户退出客成系统通知", startStr, "", "", gmail)
+			status := mail.GSendMail_q("剑鱼标讯", mailStr, adminMailStr, "", "客户退出客成系统通知", startStr, "", "", gmail)
 			if status {
 				log.Println("客成发邮件 send mail success", startStr, mailStr)
 			}

+ 1 - 1
clueSync/util.go

@@ -6,7 +6,7 @@ import (
 )
 
 func TimeStrcount(start, end string) int64 {
-	timeFormat := "2006-01-02" // 定义时间格式
+	timeFormat := "2006-01-02 15:04:05" // 定义时间格式
 	// 两个时间字符串
 	// 解析时间字符串为 Time 对象
 	startTime, err := time.Parse(timeFormat, start)