소스 검색

电销工单生成

WH01243 1 년 전
부모
커밋
3aed971c73
6개의 변경된 파일323개의 추가작업 그리고 69개의 파일을 삭제
  1. 7 0
      clueSync/config.go
  2. 10 4
      clueSync/config.json
  3. 10 4
      clueSync/job.go
  4. 285 35
      clueSync/jobutil.go
  5. 7 23
      clueSync/kc.go
  6. 4 3
      clueSync/main.go

+ 7 - 0
clueSync/config.go

@@ -142,6 +142,7 @@ type (
 		WarningValue  int64             `json:"warningValue"`
 		NameToMail    map[string]string `json:"nameToMail"`
 		ThawDay       int64             `json:"thawDay"`
+		ProductArr    []string          `json:"productArr"`
 	}
 )
 
@@ -149,6 +150,7 @@ var AreaCode = map[string]string{}
 var CodeArea = map[string]string{}
 var CodeTrail = map[string]string{}
 var DateMap = map[string]int{}
+var ProductMap = map[string]string{}
 
 func InitArea() {
 	info := TiDb.Find("d_area_code", nil, "", "", -1, -1)
@@ -173,3 +175,8 @@ func InitArea() {
 		}
 	}
 }
+func InitProduct(product []string) {
+	for _, v := range product {
+		ProductMap[v] = "dk"
+	}
+}

+ 10 - 4
clueSync/config.json

@@ -34,11 +34,11 @@
     "maxleft": 40
   },
   "tiDbData": {
-    "host": "192.168.3.14",
+    "host": "192.168.3.149",
     "port": 4000,
     "database": "Call_Accounting",
-    "user": "root",
-    "password": "=PDT49#80Z!RVv52_z",
+    "user": "datagroup",
+    "password": "Dgrpdb#2024@36",
     "poolsize": 20,
     "maxidle": 40,
     "maxleft": 40
@@ -132,5 +132,11 @@
   "allocationCap": 400,
   "warningValue": 350,
   "nameToMail": null,
-  "thawDay": 3
+  "thawDay": 3,
+  "productArr": [
+    "数据流量包",
+    "结构化数据",
+    "API接口",
+    "广告服务"
+  ]
 }

+ 10 - 4
clueSync/job.go

@@ -248,9 +248,9 @@ func FormatData(data map[string]interface{}, item string) (bool, bool) {
 			if batch_import != "" && item == "users" { //有导入批次号还是新用户,不执行
 				return true, true
 			}
-			oks = UpdateClue(*uCount, saleData, item, userId, uId, top_cluetype, sub_cluetype, topname, subname, cluename, name, saleName, phone, position, department, departments, industry, follow_project_area, role, seatNumber, level, position_id, source, sourceCode, remark, keyword, belong_to, isGroup, isCommerce, pIsOk)
+			oks = UpdateClue(*uCount, saleData, item, userId, uId, top_cluetype, sub_cluetype, topname, subname, cluename, name, saleName, phone, position, department, departments, industry, follow_project_area, role, seatNumber, level, position_id, source, sourceCode, remark, keyword, belong_to, isGroup, isCommerce, pIsOk, "")
 		} else { //不存在走新增
-			oks = SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, cluename, name, saleName, phone, position, department, departments, industry, follow_project_area, role, seatNumber, position_id, source, sourceCode, remark, keyword, belong_to, isGroup, isCommerce, isFreeze)
+			oks = SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, cluename, name, saleName, phone, position, department, departments, industry, follow_project_area, role, seatNumber, position_id, source, sourceCode, remark, keyword, belong_to, isGroup, isCommerce, isFreeze, "")
 			if oks { //新增成功,销售分配次数+1
 				TiDb.UpdateOrDeleteBySql(`update dwd_f_crm_clue_autodraw_record set count = count + 1 where position_id = ? and clue_level = ?`, position_id, level)
 			}
@@ -411,7 +411,7 @@ func FormatData(data map[string]interface{}, item string) (bool, bool) {
 	return true, true
 }
 
-func SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, cluename, name, saleName, phone, position, department, departments, industry, follow_project_area, role, seatNumber string, positionId int64, source, sourceCode, remark string, keyword []string, belong_to string, isGroup, isCommerce int, isFreeze bool) bool {
+func SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, cluename, name, saleName, phone, position, department, departments, industry, follow_project_area, role, seatNumber string, positionId int64, source, sourceCode, remark string, keyword []string, belong_to string, isGroup, isCommerce int, isFreeze bool, demand string) bool {
 	nowTime := time.Now().Format("2006-01-02 15:04:05")
 	nowTimes := time.Unix(time.Now().Unix()+3600*12, 0).Format("2006-01-02 15:04:05")
 	clueId, uodateId1, uodateId2, uodateId3, uodateId4, uodateId5, uodateId6 := int64(0), int64(0), int64(0), int64(0), int64(0), int64(0), int64(0)
@@ -456,6 +456,7 @@ func SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, c
 			"company_nature":       isGroup,
 			"company_verification": isCommerce,
 			"remark":               remark,
+			"customer_demand":      demand,
 			"FREEZE_TIME":          nowTime,
 		})
 		uodateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
@@ -633,7 +634,7 @@ func SaveClue0(item, userId, uId, top_cluetype, sub_cluetype, topname, subname,
 	}
 }
 
-func UpdateClue(data map[string]interface{}, saleData []map[string]interface{}, item, userId, uId, top_cluetype, sub_cluetype, topname, subname, cluename, name, saleName, phone, position, department, departments, industry, follow_project_area, role, seatNumber, level string, positionId int64, source, sourceCode, remark string, keyword []string, belong_to string, isGroup, isCommerce int, pIsOk bool) bool {
+func UpdateClue(data map[string]interface{}, saleData []map[string]interface{}, item, userId, uId, top_cluetype, sub_cluetype, topname, subname, cluename, name, saleName, phone, position, department, departments, industry, follow_project_area, role, seatNumber, level string, positionId int64, source, sourceCode, remark string, keyword []string, belong_to string, isGroup, isCommerce int, pIsOk bool, demand string) bool {
 	nowTime := time.Now().Format("2006-01-02 15:04:05")
 	nowTimes := time.Unix(time.Now().Unix()+3600*12, 0).Format("2006-01-02 15:04:05")
 	trailstatus := common.ObjToString(data["trailstatus"]) //data都为原线索数据
@@ -721,6 +722,11 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
 		remark = old_remark + ";" + remark //备注不能替换,只能往上拼接
 	}
 	clueUpdateData["remark"] = remark
+	old_demand := common.ObjToString(data["customer_demand"])
+	if demand != old_demand {
+		clueUpdateData["customer_demand"] = demand
+	}
+
 	if cluename != "" {
 		clueUpdateData["cluename"] = cluename //新的线索名不为空才替换
 	}

+ 285 - 35
clueSync/jobutil.go

@@ -1,6 +1,7 @@
 package main
 
 import (
+	"app.yhyue.com/moapp/jybase/redis"
 	"fmt"
 	"log"
 	"strings"
@@ -13,10 +14,10 @@ import (
 	"app.yhyue.com/moapp/jybase/mongodb"
 )
 
-/*// 电销工单生成
+// 电销工单生成
 func rderAcceptance() {
 	sql := fmt.Sprintf(`select * from order_acceptance where is_clue=2 order by propose_time  `)
-	data := Mysql.SelectBySql(sql)
+	data := WorkOrder.SelectBySql(sql)
 	if data != nil && len(*data) > 0 {
 		for _, v := range *data {
 			acceptance_no := gconv.String(v["acceptance_no"])
@@ -27,24 +28,31 @@ func rderAcceptance() {
 				company := ""
 				phone := ""
 				demand := ""
+				name := ""
+				product := ""
 				for _, v1 := range *childrenArr {
-					if gconv.String(v1["file_name"]) == "公司名称" {
-						company = gconv.String(v1["file_value"])
+					if gconv.String(v1["field_name"]) == "公司名称" {
+						company = gconv.String(v1["field_value"])
+					}
+					if gconv.String(v1["field_name"]) == "联系方式num" {
+						phone = gconv.String(v1["field_value"])
 					}
-					if gconv.String(v1["file_name"]) == "联系方式" {
-						phone = gconv.String(v1["file_value"])
+					if gconv.String(v1["field_name"]) == "客户姓名" {
+						name = gconv.String(v1["field_value"])
 					}
-					if gconv.String(v1["file_name"]) == "客户需求" {
-						demand = gconv.String(v1["file_value"])
+					if gconv.String(v1["field_name"]) == "客户需求" {
+						demand = gconv.String(v1["field_value"])
+					}
+					if gconv.String(v1["field_name"]) == "咨询产品" {
+						product = gconv.String(v1["field_value"])
 					}
 				}
-				WorkDataHandle(company, phone, demand)
+				WorkDataHandle(company, phone, demand, name, product, v)
 			}
 		}
 	}
-}*/
-/*func WorkDataHandle(company, phone, demand string) bool {
-	positionId, seatNumber, saleNam := AutoDrawPerson(company, phone, demand)
+}
+func WorkDataHandle(company, phone, demand, name, product string, acceptanceData map[string]interface{}) bool {
 	uId := ""
 	query := map[string]interface{}{}
 	contactsData := TiDb.SelectBySql("select * from dwd_f_userbase_contacts where phone = ? and is_delete = 1", phone)
@@ -57,26 +65,209 @@ func rderAcceptance() {
 	if uId == "" {
 		return false
 	}
+	cluename := company
+	if cluename == "" {
+		cluename = phone //没有线索名,手机号代替
+	}
+	ok, data, saleData := false, map[string]interface{}{}, []map[string]interface{}{}
+	isGroup, isCommerce := GetCompanyType(cluename)
 	uCount, _ := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"uid": uId}, "", ""), true //查当前线索是否已存在
 	if uCount != nil && len(*uCount) > 0 {
 		positionId := gconv.Int64((*uCount)["position_id"])
 		if positionId == 0 {
 			//线索变更
+			ok, data, saleData = FindPosition(positionId, "")
+			if !ok {
+				return false
+			}
+			UpdateClue(*uCount, saleData, "", "", uId, "", "", "", "", company, name, gconv.String(data["name"]), phone, "", "", "", "", "", "", gconv.String(data["seat_number"]), "", gconv.Int64(data["position_id"]), "", "", "", []string{}, "", isGroup, isCommerce, true, demand)
 		} else {
 			trailstatusl := gconv.String((*uCount)["trailstatusl"])
-			if trailstatusl == "" {
+			if trailstatusl == "01" || trailstatusl == "03" || trailstatusl == "04" {
 				//变更销售员
 			} else {
 				//线索变更
+				ok, data, saleData = FindPosition(positionId, trailstatusl)
+				if !ok {
+					return false
+				}
+				UpdateClue(*uCount, saleData, "", "", uId, "", "", "", "", company, name, gconv.String(data["name"]), phone, "", "", "", "", "", "", gconv.String(data["seat_number"]), "", gconv.Int64(data["position_id"]), "", "", "", []string{}, "", isGroup, isCommerce, true, demand)
 			}
 		}
 	} else {
 		//新增线索
-
+		ok, data, _ = FindPosition(0, "")
+		if !ok {
+			return false
+		}
+		SaveClue("", "", uId, "", "", "", "", cluename, name, gconv.String(data["name"]), phone, "", "", "", "", "", "", gconv.String(data["seat_number"]), gconv.Int64(data["position_id"]), "", "", "", []string{}, "", isGroup, isCommerce, false, demand)
 	}
+	//工单生成
+	AddOrderWork(acceptanceData, data, product)
 	return true
 }
-func FindPosition(positionId int64) int64 {
+func AddOrderWork(acceptanceData map[string]interface{}, userData map[string]interface{}, product string) {
+	nowTime := time.Now().Format(date.Date_Full_Layout)
+	work_order_no := fmt.Sprintf("GD%s%s", time.Now().Format(date.Date_Short_Layout), FindNumber("gd"))
+	productArr := []string{}
+	for _, v := range strings.Split(product, ",") {
+		switch ProductMap[v] {
+		case "dk":
+			continue
+		default:
+			productArr = append(productArr, v)
+		}
+	}
+	orderWorkMap := map[string]interface{}{
+		"work_order_no":         work_order_no,
+		"acceptance_no":         gconv.String(acceptanceData["acceptance_no"]),
+		"type":                  strings.Join(productArr, ","),
+		"status":                1,
+		"initiator_name":        gconv.String(acceptanceData["creator_name"]),
+		"initiator_position_id": gconv.String(acceptanceData["initiator_position_id"]),
+		"current_name":          userData["name"],
+		"current_position_id":   userData["position_id"],
+		"is_delete":             1,
+		"creator_name":          gconv.String(acceptanceData["creator_name"]),
+		"creator_position_id":   gconv.String(acceptanceData["gconv.String(acceptanceData[\"department_name\"])"]),
+		"creator_time":          nowTime,
+		"two_type":              "dx",
+		"department_no":         gconv.String(acceptanceData["department_no"]),
+		"department_name":       gconv.String(acceptanceData["department_name"]),
+	}
+	ok3 := WorkOrder.Insert("order_work", orderWorkMap)
+	if ok3 > 0 {
+		WorkOrder.Update("order_acceptance", map[string]interface{}{
+			"id": acceptanceData["id"],
+		}, map[string]interface{}{
+			"is_clue": 3,
+		})
+		//发送邮件
+	}
+}
+
+// 编号查询
+func FindNumber(moudle string) string {
+	today := time.Now().Format("2006-01-02")
+	yesterday := time.Now().AddDate(0, 0, -1).Format("2006-01-02")
+	key := fmt.Sprintf("%s_%s", today, moudle)
+	yesterdayKey := fmt.Sprintf("%s_%s", yesterday, moudle)
+	if ok, _ := redis.Exists("newother", yesterdayKey); ok {
+		//删除之前数据
+		redis.Del("newother", yesterdayKey)
+	}
+	count := redis.Incr("newother", key)
+	return fmt.Sprintf("%04d", count)
+}
+
+/*func updateClue(uCount *map[string]interface{}, company, phone, demand, name string, position string, administrators map[string]interface{}) {
+	clueId := gconv.Int64((*uCount)["id"])
+	oldCompany := gconv.String((*uCount)["oldCompany"])
+	oldPhone := gconv.String((*uCount)["oldPhone"])
+	oldDemand := gconv.String((*uCount)["oldDemand"])
+	oldName := gconv.String((*uCount)["oldName"])
+	nowTime := time.Now().Format(date.Date_Full_Layout)
+	old_position := gconv.String((*uCount)["position_id"])
+	updateData := map[string]interface{}{}
+	if company != "" && company != oldCompany {
+		updateData["cluename"] = company
+		TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
+			"clue_id":      clueId,
+			"position_id":  common.If(position != "", position, "-1"),
+			"change_field": "cluename",
+			"change_type":  "基本信息变更",
+			"old_value":    oldCompany,
+			"new_value":    company,
+			"createtime":   nowTime,
+			"BCPCID":       common.GetRandom(32),
+			"operator_id":  -1,
+		})
+	}
+	if phone != "" && phone != oldPhone {
+		updateData["phone"] = phone
+		TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
+			"clue_id":      clueId,
+			"position_id":  common.If(position != "", position, "-1"),
+			"change_field": "phone",
+			"change_type":  "基本信息变更",
+			"old_value":    oldPhone,
+			"new_value":    phone,
+			"createtime":   nowTime,
+			"BCPCID":       common.GetRandom(32),
+			"operator_id":  -1,
+		})
+	}
+	if name != "" && name != oldName {
+		updateData["name"] = name
+		TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
+			"clue_id":      clueId,
+			"position_id":  common.If(position != "", position, "-1"),
+			"change_field": "name",
+			"change_type":  "基本信息变更",
+			"old_value":    oldName,
+			"new_value":    name,
+			"createtime":   nowTime,
+			"BCPCID":       common.GetRandom(32),
+			"operator_id":  -1,
+		})
+	}
+	if demand != "" && demand != oldDemand {
+		updateData["demand"] = demand
+		TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
+			"clue_id":      clueId,
+			"position_id":  common.If(position != "", position, "-1"),
+			"change_field": "demand",
+			"change_type":  "基本信息变更",
+			"old_value":    oldDemand,
+			"new_value":    demand,
+			"createtime":   nowTime,
+			"BCPCID":       common.GetRandom(32),
+			"operator_id":  -1,
+		})
+	}
+	if old_position != position && position != "" {
+		//员工更改
+		updateData["position_id"] = position
+		updateData["seatNumber"] = "seatNumber"
+		TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
+			"clue_id":      clueId,
+			"change_field": "position",
+			"position_id":  0,
+			"change_type":  "基本信息变更",
+			"old_value":    common.If(old_position != "", old_position, "/"),
+			"new_value":    common.If(position != "", position, "/"),
+			"createtime":   nowTime,
+			"BCPCID":       common.GetRandom(32),
+			"operator_id":  -1})
+		TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
+			"clue_id":      clueId,
+			"change_field": "position",
+			"position_id":  0,
+			"change_type":  "基本信息变更",
+			"old_value":    common.If(old_position != "", old_position, "/"),
+			"new_value":    common.If(position != "", position, "/"),
+			"createtime":   nowTime,
+			"BCPCID":       common.GetRandom(32),
+			"operator_id":  -1})
+	}
+	if updateData != nil {
+		TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{
+			"uid": clueId,
+		},
+			updateData)
+	}
+}
+*/
+// 人员查询
+func FindPosition(positionId int64, trailstatusl string) (bool, map[string]interface{}, []map[string]interface{}) {
+	allData := []map[string]interface{}{}
+	full := false
+	//查询是否满了
+	if positionId != 0 {
+		if FindUpperLimit(gconv.String(positionId), "", false) {
+			full = true
+		}
+	}
 	//查询两个部门高级管理员
 	//查询两个部门所有人员标识
 	//电销三部
@@ -103,54 +294,113 @@ FROM
 	AND a.dept_name LIKE "%销售三部"
 	AND a.position_id = b.position_id`)
 	if userData3 == nil || len(*userData3) == 0 || userData1 == nil || len(*userData1) == 0 {
-		return 0
+		return false, map[string]interface{}{}, allData
 	}
+	//一部管理员信息
 	administrators1 := map[string]interface{}{}
+	//三部管理员信息
 	administrators3 := map[string]interface{}{}
+	//返回当前人信息
 	administrators := map[string]interface{}{}
 	//电销一部
-	positionIdArr1 := []int64{}
-	positionIdArr3 := []int64{}
+	positionIdArr1 := []string{}
+	positionIdArr3 := []string{}
+	proportion1 := float64(0)
+	proportion3 := float64(0)
 	for _, v := range *userData3 {
 		v["type"] = 3
 		personName := gconv.String(v["name"])
 		id := gconv.Int64(v["position_id"])
-		if personName == "孙鹏" {
-			administrators3 = v
+		if id == positionId && full {
 			administrators = v
 		}
-		if id == positionId {
-			administrators = v
+		if personName == "孙鹏" {
+			administrators3 = v
+			proportion3 += 0.5
+		} else {
+			proportion3 += 1
 		}
-		positionIdArr3 = append(positionIdArr3, id)
+		positionIdArr3 = append(positionIdArr3, gconv.String(id))
+		allData = append(allData, v)
 	}
 	for _, v := range *userData1 {
 		v["type"] = 1
 		personName := gconv.String(v["name"])
 		id := gconv.Int64(v["position_id"])
+		if id == positionId && full {
+			administrators = v
+		}
 		if personName == "沈炳毅" {
 			administrators1 = v
-
+			proportion1 += 0.5
+		} else {
+			proportion1 += 1
 		}
-
-		positionIdArr1 = append(positionIdArr1, id)
+		positionIdArr1 = append(positionIdArr1, gconv.String(id))
+		allData = append(allData, v)
 	}
 	if positionId != 0 {
 		positiontype := gconv.Int64(administrators["type"])
-		isBool := false
-		if FindUpperLimit(gconv.String(positionId), "", false) {
-			if positiontype == 1 {
-				administrators1
-			} else {
-				administrators1
+		if full {
+			switch positiontype {
+			case 1:
+				if trailstatusl == "01" || trailstatusl == "03" || trailstatusl == "04" {
+					//找他上级
+					positionId1 := gconv.String(administrators1["position_id"])
+					administrators = administrators1
+					if FindUpperLimit(positionId1, "", false) {
+						return false, map[string]interface{}{}, allData
+					}
+				}
+			case 3:
+				if trailstatusl == "01" || trailstatusl == "03" || trailstatusl == "04" {
+					//找他上级
+					positionId1 := gconv.String(administrators3["position_id"])
+					administrators = administrators3
+					if FindUpperLimit(positionId1, "", false) {
+						return false, map[string]interface{}{}, allData
+					}
+				}
 			}
 		} else {
-
+			return true, administrators, allData
 		}
 	}
-
+	//按照比例分配选择一部还是三部
+	//一部查询
+	deptCount1 := CalculateProportion(strings.Join(positionIdArr1, ","), "", 1)
+	//三部查询
+	deptCount3 := CalculateProportion(strings.Join(positionIdArr3, ","), "", 1)
+	if deptCount1 == 0 {
+		return true, administrators1, allData
+	}
+	if deptCount3 == 0 {
+		return true, administrators3, allData
+	}
+	if deptCount1/deptCount3 > proportion1/proportion3 {
+		return true, administrators3, allData
+	} else {
+		return true, administrators1, allData
+	}
+	return false, map[string]interface{}{}, allData
 }
-*/
+func CalculateProportion(positionIsStr, createTime string, proportion float64) float64 {
+	count := float64(0)
+	sql := `SELECT
+			sum(1) as  count
+		FROM
+			order_work 
+		WHERE
+			  FIND_IN_SET(current_position_id ,?) 
+			AND is_delete=1
+			and   creator_time>?`
+	data := WorkOrder.SelectBySql(sql, positionIsStr, createTime)
+	if data != nil && len(*data) > 0 {
+		count = gconv.Float64((*data)[0]["count"])
+	}
+	return count
+}
+
 // 未支付订单 30分钟一次
 func orders() {
 	//一个小时未支付进入线索 A

+ 7 - 23
clueSync/kc.go

@@ -19,22 +19,7 @@ import (
 
 func kcSync() {
 	log.Println("客户成功系统移交定时任务开始")
-	//sql := `select * from dwd_f_userbase_order_info where pay_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
-	uid in ("4b534cf8e67811ed972200163e3214c2","1928dfe0e69611ed972200163e3214c2","9949f6384e5511eebd3a00163e3214c2","9912accee69411ed972200163e3214c2","98de316406b011efbb0e00163e3214c2","d35a5734e69811ed972200163e3214c2","274e8eaae67b11ed972200163e3214c2","937f16bce69411ed972200163e3214c2","8cd465fac48e11eeb38300163e3214c2","a83cb826e68411ed972200163e3214c2","ed9f9ebce69111ed972200163e3214c2","b27abc84e69311ed972200163e3214c2","7e40357ce67d11ed972200163e3214c2","14e1a9d6e68b11ed972200163e3214c2","7ce2192ee69211ed972200163e3214c2","741f3ff2e68711ed972200163e3214c2","b54b3148e69111ed972200163e3214c2","6bd34a0e098811eeb04a00163e3214c2","62c887f0e69a11ed972200163e3214c2","47f24806e67911ed972200163e3214c2","b9929da2e69311ed972200163e3214c2","421a0dace69611ed972200163e3214c2","c9300b46e67011ed972200163e3214c2","0b01efc8e69711ed972200163e3214c2","c796378e05d111efaee600163e3214c2","47fe4f58e69611ed972200163e3214c2","5867d45a3d9811ee829800163e3214c2","c484486ce69a11ed972200163e3214c2","018261e2e67611ed972200163e3214c2","bace9eb8e69911ed972200163e3214c2","c292fc6ce67511ed972200163e3214c2","092c4d12e69011ed972200163e3214c2","49f7912ee67411ed972200163e3214c2","cbe2589ce68111ed972200163e3214c2")
-	AND pay_money > 0 
-	AND vip_endtime > now() 
-	AND product_type IN ( "大会员", "企业商机管理" ) 
-	AND order_status = 1 
-	AND data_spec != "dhy4" 
-	AND refund_status != 1 
-	AND vip_starttime != "2099-01-01 00:00:00"
-
-`
+	sql := `select * from dwd_f_userbase_order_info where pay_money > 0 and vip_endtime > "` + time.Now().Format(date.Date_Full_Layout) + `" and autoUpdate > "` + cfg.LastkcTime + `" order by autoUpdate asc`
 	data := TiDb.SelectBySql(sql)
 	if data != nil && *data != nil && len(*data) > 0 {
 		for _, v := range *data {
@@ -44,16 +29,15 @@ WHERE
 			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 {
-				kcJob(v)
-				//status := kcJob(v)
-				/*if status == 0 {
+				status := kcJob(v)
+				if status == 0 {
 					break
-				}*/
+				}
 			}
-			//cfg.LastkcTime = common.ObjToString(v["autoUpdate"])
+			cfg.LastkcTime = common.ObjToString(v["autoUpdate"])
 		}
 	}
-	//common.WriteSysConfig(&cfg)
+	common.WriteSysConfig(&cfg)
 	log.Println("客户成功系统移交定时任务结束")
 }
 
@@ -86,7 +70,7 @@ func kcJob(data map[string]interface{}) int {
 		}
 		if product_type == "企业商机管理" {
 			product = productMap[product_type]
-			powerData := TiDb.FindOne("dwd_f_data_equity_info", map[string]interface{}{"phone": phone, "product_type": "商机管理"}, "", "comeintime desc")
+			powerData := TiDb.FindOne("dwd_f_data_equity_info", map[string]interface{}{"uid": uId, "product_type": "商机管理"}, "", "comeintime desc")
 			if powerData != nil {
 				starttime = common.ObjToString((*powerData)["starttime"])
 				endtime = common.ObjToString((*powerData)["endtime"])

+ 4 - 3
clueSync/main.go

@@ -3,7 +3,6 @@ package main
 import (
 	"flag"
 	"fmt"
-	"github.com/robfig/cron"
 	"log"
 
 	"app.yhyue.com/moapp/jybase/common"
@@ -113,8 +112,10 @@ func main() {
 	MgoLog = mongodb.NewMgoWithUser(cfg.MgoLog.Address, cfg.MgoLog.DbName, cfg.MgoLog.User, cfg.MgoLog.Password, cfg.MgoLog.DbSize)
 	MgoQyxy = mongodb.NewMgoWithUser(cfg.MgoQyxy.Address, cfg.MgoQyxy.DbName, cfg.MgoQyxy.User, cfg.MgoQyxy.Password, cfg.MgoQyxy.DbSize)
 	InitArea()
+	InitProduct(cfg.ProductArr)
+	rderAcceptance()
 	//kcSync() //移交客成
-	if *mode == 1 {
+	/*if *mode == 1 {
 		//30分钟一次
 		a := cron.New()
 		a.AddFunc(cfg.CornExp1, func() {
@@ -196,5 +197,5 @@ func main() {
 		//refundAutoHistory()
 		users()
 		saleLeads()
-	}
+	}*/
 }