Jelajahi Sumber

Merge branch 'feature/v1.5.1' of https://jygit.jydev.jianyu360.cn/jianyu/datatools into feature/v1.5.1
wq

lizhikun 1 tahun lalu
induk
melakukan
504dd14a6e
2 mengubah file dengan 14 tambahan dan 203 penghapusan
  1. 2 1
      clueSync/jobutil.go
  2. 12 202
      clueSync/kc.go

+ 2 - 1
clueSync/jobutil.go

@@ -429,6 +429,7 @@ func autoDraw(mode, cluename, phone string, isGroup, isCommerce int) (positionId
 				if !isOk { //有新员工直接分给新员工
 					positionId = common.Int64All(v["position_id"])
 					saleName = common.ObjToString(v["name"])
+					log.Println("新员工, ", positionId, saleName)
 					rData := TiDb.FindOne("dwd_f_crm_clue_autodraw_record", map[string]interface{}{"clue_level": mode}, "", "count desc")
 					TiDb.Insert("dwd_f_crm_clue_autodraw_record", map[string]interface{}{
 						"position_id": positionId,
@@ -438,7 +439,7 @@ func autoDraw(mode, cluename, phone string, isGroup, isCommerce int) (positionId
 					break
 				}
 			}
-			if positionId > 0 {
+			if positionId == 0 {
 				res := int64(0)
 				countres := 0
 				for _, v := range *countData {

+ 12 - 202
clueSync/kc.go

@@ -774,210 +774,20 @@ func refundAuto() {
 }
 
 func refundAutoHistory() {
-	log.Println("历史数据移交销售任务开始")
-	nowTime := time.Now().Format(date.Date_Full_Layout)
-	TiDb.SelectByBath(100, func(l *[]map[string]interface{}) bool {
-		for _, v := range *l {
-			saleId, cluename, company_nature, company_verification, uid := int64(0), "", 0, 0, ""
-			clueId := common.Int64All(v["clue_id"])
-			name := common.ObjToString(v["name"])
-			kcposition_id := common.Int64All(v["position_id"])
-			isRenewalProtection := common.IntAll(v["is_renewal_protection"])
-			clueData := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, "company_nature,company_verification,cluename,userid,position_id,uid", "")
-			if clueData != nil && len(*clueData) > 0 {
-				saleId = common.Int64All((*clueData)["position_id"])
-				cluename = common.ObjToString((*clueData)["cluename"])
-				company_nature = common.IntAll((*clueData)["company_nature"])
-				company_verification = common.IntAll((*clueData)["company_verification"])
-				uid = common.ObjToString((*clueData)["uid"])
-			}
-			query1 := fmt.Sprintf(`select id from dwd_f_userbase_order_info where (product_type = "企业商机管理" or product_type = "大会员") and vip_endtime > "%s" and order_status = 1 and uid = "%s"`, nowTime, uid)
-			query2 := fmt.Sprintf(`select id from dwd_f_userbase_order_info where (product_type = "企业商机管理" or product_type = "大会员") and refund_status in (0,2) and order_status = 1 and uid = "%s"`, uid)
-			log.Println("query1 ", query1)
-			log.Println("query2 ", query2)
-			order2 := TiDb.SelectBySql(query2)
-			if order2 == nil || len(*order2) == 0 {
-				//全退款了
-				if saleId > 0 {
-					saleData := TiDb.FindOne("dwd_f_crm_personnel_management", map[string]interface{}{"position_id": saleId, "resign": 0}, "", "")
-					if saleData != nil && len(*saleData) > 0 {
-						TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_crm_clue_info SET updatetime=?,trailstatus="01",top_cluetype="532",sub_cluetype="537",taskstatus=0,tasksource="其他-成交客户续约失败",is_transfer=0 WHERE id = ?`, nowTime, clueId)
-					} else {
-						if company_nature == 0 && company_verification == 1 && cluename != "" {
-							adata := TiDb.Find("dwd_f_crm_clue_info", map[string]interface{}{"cluename": cluename, "is_assign": 1}, "seatNumber,position_id", "", -1, -1)
-							if adata != nil && len(*adata) > 0 {
-								isOks := false
-								for _, vv := range *adata {
-									position_ids := common.Int64All(vv["position_id"])
-									seatNumber := common.ObjToString(vv["seatNumber"])
-									saleDatas := TiDb.FindOne("dwd_f_crm_personnel_management", map[string]interface{}{"position_id": position_ids, "resign": 0}, "", "")
-									if saleDatas != nil && len(*saleDatas) > 0 {
-										saleId = position_ids
-										TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_crm_clue_info SET updatetime=?,trailstatus="01",position_id=?,seatNumber=?,top_cluetype="532",sub_cluetype="537",taskstatus=0,tasksource="其他-成交客户续约失败",is_transfer=0 WHERE id = ?`, nowTime, saleId, seatNumber, clueId)
-										isOks = true
-										break
-									}
-								}
-								if !isOks {
-									sdata := TiDb.SelectBySql(`SELECT b.name,b.position_id,b.seat_number from dwd_d_crm_department_level_succbi a INNER JOIN dwd_f_crm_personnel_management b on a.position_id = b.position_id where a.bi_pcode = (SELECT bi_pcode from dwd_d_crm_department_level_succbi where position_id = ?) and b.role_id = 3`, saleId)
-									if sdata != nil && len(*sdata) > 0 {
-										saleId = common.Int64All((*sdata)[0]["position_id"])
-										seatNumber := common.ObjToString((*sdata)[0]["seat_number"])
-										TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_crm_clue_info SET updatetime=?,trailstatus="01",position_id=?,seatNumber=?,top_cluetype="532",sub_cluetype="537",taskstatus=0,tasksource="其他-成交客户续约失败",is_transfer=0 WHERE id = ?`, nowTime, saleId, seatNumber, clueId)
-									}
-								}
-							}
-						} else {
-							sdata := TiDb.SelectBySql(`SELECT b.name,b.position_id,b.seat_number from dwd_d_crm_department_level_succbi a INNER JOIN dwd_f_crm_personnel_management b on a.position_id = b.position_id where a.bi_pcode = (SELECT bi_pcode from dwd_d_crm_department_level_succbi where position_id = ?) and b.role_id = 3`, saleId)
-							if sdata != nil && len(*sdata) > 0 {
-								saleId = common.Int64All((*sdata)[0]["position_id"])
-								seatNumber := common.ObjToString((*sdata)[0]["seat_number"])
-								TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_crm_clue_info SET updatetime=?,trailstatus="01",position_id=?,seatNumber=?,top_cluetype="532",sub_cluetype="537",taskstatus=0,tasksource="其他-成交客户续约失败",is_transfer=0 WHERE id = ?`, nowTime, saleId, seatNumber, clueId)
-							}
-						}
-					}
-				} else {
-					TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_crm_clue_info SET 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),
-					"change_field": "trailstatus",
-					"change_type":  "基本信息变更",
-					"old_value":    "成交客户",
-					"new_value":    "商机线索",
-					"createtime":   nowTime,
-					"BCPCID":       common.GetRandom(32),
-					"operator_id":  -1,
-				})
-				TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
-					"clue_id":      clueId,
-					"position_id":  common.If(kcposition_id > 0, kcposition_id, -1),
-					"change_type":  "客户成功经理",
-					"change_field": "position_id",
-					"old_value":    name,
-					"new_value":    "/",
-					"createtime":   nowTime,
-					"BCPCID":       common.GetRandom(32),
-					"operator_id":  -1,
-				})
-				TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
-					"clue_id":     clueId,
-					"position_id": common.If(kcposition_id > 0, kcposition_id, -1),
-					"change_type": "移交销售",
-					"new_value":   "成交客户申请退款",
-					"createtime":  nowTime,
-					"BCPCID":      common.GetRandom(32),
-					"operator_id": -1,
-				})
-				TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_csm_customer_info SET is_transfer=1 WHERE clue_id = ?`, clueId)
-			} else {
-				order1 := TiDb.SelectBySql(query1)
-				if order1 == nil || len(*order1) == 0 {
-					isOk := false
-					query3 := fmt.Sprintf(`select vip_endtime from dwd_f_userbase_order_info where (product_type = "企业商机管理" or product_type = "大会员") and vip_endtime < "%s" and order_status = 1 and uid = "%s"`, nowTime, uid)
-					log.Println("query3 ", query3)
-					order3 := TiDb.SelectBySql(query3)
-					if order3 != nil && len(*order3) > 0 {
-						for _, vv := range *order3 {
-							if isRenewalProtection == 1 {
-								vip_endtime := common.ObjToString(vv["vip_endtime"])
-								vip_endtimes, _ := time.ParseInLocation(date.Date_Full_Layout, vip_endtime, time.Local)
-								if time.Now().Unix()-vip_endtimes.Unix() < 3*30*86400 {
-									isOk = true
-								}
-							}
-						}
-					}
-					if !isOk {
-						//全到期了
-						if saleId > 0 {
-							saleData := TiDb.FindOne("dwd_f_crm_personnel_management", map[string]interface{}{"position_id": saleId, "resign": 0}, "", "")
-							if saleData != nil && len(*saleData) > 0 {
-								TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_crm_clue_info SET updatetime=?,trailstatus="01",is_task=1,tasktime=?,top_cluetype="532",sub_cluetype="537",taskstatus=0,tasksource="其他-成交客户续约失败",is_transfer=0 WHERE id = ?`, nowTime, nowTime, clueId)
-							} else {
-								if company_nature == 0 && company_verification == 1 && cluename != "" {
-									adata := TiDb.Find("dwd_f_crm_clue_info", map[string]interface{}{"cluename": cluename, "is_assign": 1}, "seatNumber,position_id", "", -1, -1)
-									if adata != nil && len(*adata) > 0 {
-										isOks := false
-										for _, vv := range *adata {
-											position_ids := common.Int64All(vv["position_id"])
-											seatNumber := common.ObjToString(vv["seatNumber"])
-											saleDatas := TiDb.FindOne("dwd_f_crm_personnel_management", map[string]interface{}{"position_id": position_ids, "resign": 0}, "", "")
-											if saleDatas != nil && len(*saleDatas) > 0 {
-												saleId = position_ids
-												TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_crm_clue_info SET updatetime=?,trailstatus="01",position_id=?,seatNumber=?,is_task=1,tasktime=?,top_cluetype="532",sub_cluetype="537",taskstatus=0,tasksource="其他-成交客户续约失败",is_transfer=0 WHERE id = ?`, nowTime, saleId, seatNumber, nowTime, clueId)
-												isOks = true
-												break
-											}
-										}
-										if !isOks {
-											sdata := TiDb.SelectBySql(`SELECT b.name,b.position_id,b.seat_number from dwd_d_crm_department_level_succbi a INNER JOIN dwd_f_crm_personnel_management b on a.position_id = b.position_id where a.bi_pcode = (SELECT bi_pcode from dwd_d_crm_department_level_succbi where position_id = ?) and b.role_id = 3`, saleId)
-											if sdata != nil && len(*sdata) > 0 {
-												saleId = common.Int64All((*sdata)[0]["position_id"])
-												seatNumber := common.ObjToString((*sdata)[0]["seat_number"])
-												TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_crm_clue_info SET updatetime=?,trailstatus="01",position_id=?,seatNumber=?,is_task=1,tasktime=?,top_cluetype="532",sub_cluetype="537",taskstatus=0,tasksource="其他-成交客户续约失败",is_transfer=0 WHERE id = ?`, nowTime, saleId, seatNumber, nowTime, clueId)
-											}
-										}
-									}
-								} else {
-									sdata := TiDb.SelectBySql(`SELECT b.name,b.position_id,b.seat_number from dwd_d_crm_department_level_succbi a INNER JOIN dwd_f_crm_personnel_management b on a.position_id = b.position_id where a.bi_pcode = (SELECT bi_pcode from dwd_d_crm_department_level_succbi where position_id = ?) and b.role_id = 3`, saleId)
-									if sdata != nil && len(*sdata) > 0 {
-										saleId = common.Int64All((*sdata)[0]["position_id"])
-										seatNumber := common.ObjToString((*sdata)[0]["seat_number"])
-										TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_crm_clue_info SET updatetime=?,trailstatus="01",position_id=?,seatNumber=?,is_task=1,tasktime=?,top_cluetype="532",sub_cluetype="537",taskstatus=0,tasksource="其他-成交客户续约失败",is_transfer=0 WHERE id = ?`, nowTime, saleId, seatNumber, nowTime, clueId)
-									}
-								}
-							}
-						} else {
-							TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_crm_clue_info SET 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),
-							"change_type":  "基本信息变更",
-							"old_value":    "成交客户",
-							"change_field": "trailstatus",
-							"new_value":    "商机线索",
-							"createtime":   nowTime,
-							"BCPCID":       common.GetRandom(32),
-							"operator_id":  -1,
-						})
-						TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
-							"clue_id":     clueId,
-							"position_id": saleId,
-							"change_type": "加入任务车",
-							"new_value":   "线索自动分配-其他-成交客户续约失败",
-							"createtime":  nowTime,
-							"BCPCID":      common.GetRandom(32),
-							"operator_id": -1,
-						})
-						TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
-							"clue_id":      clueId,
-							"position_id":  common.If(kcposition_id > 0, kcposition_id, -1),
-							"change_type":  "客户成功经理",
-							"change_field": "position_id",
-							"old_value":    name,
-							"new_value":    "/",
-							"createtime":   nowTime,
-							"BCPCID":       common.GetRandom(32),
-							"operator_id":  -1,
-						})
-						TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
-							"clue_id":     clueId,
-							"position_id": saleId,
-							"change_type": "移交销售",
-							"new_value":   "成交客户续费失败,到期自动移交",
-							"createtime":  nowTime,
-							"BCPCID":      common.GetRandom(32),
-							"operator_id": -1,
-						})
-						TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_csm_customer_info SET is_transfer=1 WHERE clue_id = ?`, clueId)
+	data := TiDb.Find("dwd_f_crm_clue_autodraw_record", nil, "", "", -1, -1)
+	if data != nil {
+		for _, v := range *data {
+			seatNumber := common.ObjToString(v["seatNumber"])
+			adata := TiDb.Find("dwd_f_crm_personnel_management", map[string]interface{}{"seat_number": seatNumber}, "", "", -1, -1)
+			if adata != nil {
+				for _, vv := range *adata {
+					if common.IntAll(vv["resign"]) == 0 {
+						position_id := common.Int64All(vv["position_id"])
+						TiDb.Update("dwd_f_crm_clue_autodraw_record", map[string]interface{}{"seatNumber": seatNumber}, map[string]interface{}{"position_id": position_id})
+						break
 					}
 				}
 			}
 		}
-		return true
-	}, `select ent_id,clue_id,position_id,name,is_renewal_protection from dwd_f_csm_customer_info where is_transfer = 0`)
-	log.Println("历史数据移交销售任务结束")
+	}
 }