|
@@ -28,6 +28,7 @@ func orders() {
|
|
|
}
|
|
|
}
|
|
|
cfg.LastOrderId = lastOrderId
|
|
|
+ common.WriteSysConfig(&cfg)
|
|
|
log.Println("未支付订单定时任务结束")
|
|
|
}
|
|
|
|
|
@@ -51,12 +52,16 @@ func users() {
|
|
|
|
|
|
for {
|
|
|
if !iter.Next(&thisData) {
|
|
|
- lastUserId = mongodb.BsonIdToSId(thisData["_id"])
|
|
|
break
|
|
|
}
|
|
|
- FormatData(thisData, "users")
|
|
|
+ ok1, _ := FormatData(thisData, "users")
|
|
|
+ if !ok1 {
|
|
|
+ common.WriteSysConfig(&cfg)
|
|
|
+ break
|
|
|
+ }
|
|
|
+ cfg.LastUserId = mongodb.BsonIdToSId(thisData["_id"])
|
|
|
}
|
|
|
- cfg.LastUserId = lastUserId
|
|
|
+ common.WriteSysConfig(&cfg)
|
|
|
log.Println("新注册用户定时任务结束")
|
|
|
}
|
|
|
|
|
@@ -82,16 +87,16 @@ func saleLeads() {
|
|
|
|
|
|
for {
|
|
|
if !iter.Next(&thisData) {
|
|
|
- lastId = mongodb.BsonIdToSId(thisData["_id"])
|
|
|
break
|
|
|
}
|
|
|
+ cfg.LastId = mongodb.BsonIdToSId(thisData["_id"])
|
|
|
FormatData(thisData, "saleLeads")
|
|
|
}
|
|
|
- cfg.LastId = lastId
|
|
|
+ common.WriteSysConfig(&cfg)
|
|
|
log.Println("用户留资定时任务结束")
|
|
|
}
|
|
|
|
|
|
-func FormatData(data map[string]interface{}, item string) {
|
|
|
+func FormatData(data map[string]interface{}, item string) (bool, bool) {
|
|
|
userId, uId, positionId, source, cluename, phone := common.ObjToString(data["user_id"]), "", "", 0, "", ""
|
|
|
role, industry, department, position, name, top_cluetype, sub_cluetype, follow_project_area, level := "", "", "", "", "", "", "", "", ""
|
|
|
query, topname, subname := map[string]interface{}{}, "", ""
|
|
@@ -154,9 +159,12 @@ func FormatData(data map[string]interface{}, item string) {
|
|
|
if cluename == "" {
|
|
|
cluename = phone
|
|
|
}
|
|
|
- //域外用户和内部用户,不存线索
|
|
|
- if source == 5 || source == 6 {
|
|
|
- return
|
|
|
+ //域外用户和内部用户和没有手机号,不存线索
|
|
|
+ if source == 5 || source == 6 || phone == "" {
|
|
|
+ return true, false
|
|
|
+ }
|
|
|
+ if uId == "" {
|
|
|
+ return false, false
|
|
|
}
|
|
|
//不是留资的要查一遍留资
|
|
|
if item == "orders" {
|
|
@@ -185,6 +193,9 @@ func FormatData(data map[string]interface{}, item string) {
|
|
|
position_id, seatNumber, saleName, saleData := autoDraw(level)
|
|
|
log.Println("data -------", position_id, seatNumber, saleName)
|
|
|
if position_id > 0 && seatNumber != "" {
|
|
|
+ if TiDb.Count("dwd_f_crm_private_sea", map[string]interface{}{"position_id": position_id}) >= cfg.CountLimit {
|
|
|
+ return true, false
|
|
|
+ }
|
|
|
uCount := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"uid": uId}, "", "")
|
|
|
if uCount != nil && len(*uCount) > 0 {
|
|
|
UpdateClue(*uCount, saleData, item, userId, uId, top_cluetype, sub_cluetype, topname, subname, cluename, name, saleName, phone, position, department, industry, follow_project_area, role, seatNumber, position_id)
|
|
@@ -192,6 +203,7 @@ func FormatData(data map[string]interface{}, item string) {
|
|
|
SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, cluename, name, saleName, phone, position, department, industry, follow_project_area, role, seatNumber, position_id)
|
|
|
}
|
|
|
}
|
|
|
+ return true, true
|
|
|
}
|
|
|
|
|
|
func SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, cluename, name, saleName, phone, position, department, industry, follow_project_area, role, seatNumber string, positionId int64) {
|
|
@@ -259,7 +271,7 @@ func SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, c
|
|
|
"clue_id": clueId,
|
|
|
"position_id": positionId,
|
|
|
"change_field": "trailstatus",
|
|
|
- "change_type": "线索状态变更",
|
|
|
+ "change_type": "基本信息变更",
|
|
|
"old_value": "商机线索",
|
|
|
"new_value": "新增",
|
|
|
"createtime": nowTime,
|
|
@@ -281,20 +293,33 @@ func SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, c
|
|
|
|
|
|
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, industry, follow_project_area, role, seatNumber string, positionId int64) {
|
|
|
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")
|
|
|
+ // nowTimes := time.Unix(time.Now().Unix()+3600*12, 0).Format("2006-01-02 15:04:05")
|
|
|
//trailstatus = 无意向 为变更线索状态
|
|
|
//没有变更所属人查任务车,有车不变
|
|
|
trailstatus := common.ObjToString(data["trailstatus"])
|
|
|
clueId := common.Int64All(data["id"])
|
|
|
is_assign := common.IntAll(data["is_assign"])
|
|
|
- oldsaleName := ""
|
|
|
+ oldsaleName, oldTaskTime, taskTime := "", "", ""
|
|
|
+ //已在任务车的判断任务时间
|
|
|
+ privateData := TiDb.FindOne("dwd_f_crm_private_sea", map[string]interface{}{"clue_id": clueId}, "", "")
|
|
|
+ if privateData != nil && len(*privateData) > 0 {
|
|
|
+ oldTaskTime = common.ObjToString((*privateData)["tasktime"])
|
|
|
+ }
|
|
|
+ if oldTaskTime != "" {
|
|
|
+ t1, err := time.Parse("2006-01-02 15:04:05", oldTaskTime)
|
|
|
+ if err == nil && time.Now().Before(t1) {
|
|
|
+ taskTime = oldTaskTime
|
|
|
+ } else {
|
|
|
+ taskTime = nowTime
|
|
|
+ }
|
|
|
+ }
|
|
|
clueUpdateData := map[string]interface{}{
|
|
|
"is_assign": 1,
|
|
|
"updatetime": nowTime,
|
|
|
"cluename": cluename,
|
|
|
"top_cluetype": top_cluetype,
|
|
|
"sub_cluetype": sub_cluetype,
|
|
|
- "trailstatus": "01",
|
|
|
+ "name": name,
|
|
|
"position": position,
|
|
|
"department": department,
|
|
|
"industry": industry,
|
|
@@ -305,7 +330,7 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
|
|
|
"comeinsource": 2,
|
|
|
"is_task": 1,
|
|
|
"task_time": nowTime,
|
|
|
- "tasktime": common.If(item == "users", nowTimes, nowTime),
|
|
|
+ "tasktime": taskTime,
|
|
|
"taskstatus": 0,
|
|
|
"tasksource": "线索来源自动更新" + "-" + topname + "-" + subname,
|
|
|
}
|
|
@@ -315,13 +340,14 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
|
|
|
"comeinsource": 2,
|
|
|
"is_task": 1,
|
|
|
"task_time": nowTime,
|
|
|
- "tasktime": common.If(item == "users", nowTimes, nowTime),
|
|
|
+ "tasktime": taskTime,
|
|
|
"taskstatus": 0,
|
|
|
"tasksource": "线索来源自动更新" + "-" + topname + "-" + subname,
|
|
|
}
|
|
|
if trailstatus == "00" || trailstatus == "01" {
|
|
|
clueUpdateData["seatNumber"] = seatNumber
|
|
|
clueUpdateData["position_id"] = positionId
|
|
|
+ clueUpdateData["trailstatus"] = "01"
|
|
|
seaUpdateData["seatNumber"] = seatNumber
|
|
|
seaUpdateData["position_id"] = positionId
|
|
|
insertSeaData["seatNumber"] = seatNumber
|
|
@@ -346,6 +372,7 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
|
|
|
}
|
|
|
updateId1, updateId2, updateId3, updateId4, updateId5 := int64(0), int64(0), int64(0), int64(0), int64(0)
|
|
|
updateId6, updateId7, updateId8, updateId9, updateId10 := int64(0), int64(0), int64(0), int64(0), int64(0)
|
|
|
+ updateId11, updateId12, updateId13 := int64(0), int64(0), int64(0)
|
|
|
//变更记录
|
|
|
if trailstatus == "00" || trailstatus == "01" {
|
|
|
updateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
@@ -364,7 +391,7 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
|
|
|
"clue_id": clueId,
|
|
|
"position_id": common.Int64All(data["position_id"]),
|
|
|
"change_field": "trailstatus",
|
|
|
- "change_type": "线索状态变更",
|
|
|
+ "change_type": "基本信息变更",
|
|
|
"old_value": "无意向客户",
|
|
|
"new_value": "流失",
|
|
|
"createtime": nowTime,
|
|
@@ -375,7 +402,7 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
|
|
|
"clue_id": clueId,
|
|
|
"position_id": positionId,
|
|
|
"change_field": "trailstatus",
|
|
|
- "change_type": "线索状态变更",
|
|
|
+ "change_type": "基本信息变更",
|
|
|
"old_value": "商机线索",
|
|
|
"new_value": "新增",
|
|
|
"createtime": nowTime,
|
|
@@ -386,7 +413,7 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
|
|
|
"clue_id": clueId,
|
|
|
"position_id": positionId,
|
|
|
"change_field": "trailstatus",
|
|
|
- "change_type": "线索状态变更",
|
|
|
+ "change_type": "基本信息变更",
|
|
|
"old_value": "无意向客户",
|
|
|
"new_value": "商机线索",
|
|
|
"createtime": nowTime,
|
|
@@ -398,7 +425,7 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
|
|
|
"clue_id": clueId,
|
|
|
"position_id": common.Int64All(data["position_id"]),
|
|
|
"change_field": "trailstatus",
|
|
|
- "change_type": "线索状态变更",
|
|
|
+ "change_type": "基本信息变更",
|
|
|
"old_value": "商机线索",
|
|
|
"new_value": "流失",
|
|
|
"createtime": nowTime,
|
|
@@ -409,7 +436,7 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
|
|
|
"clue_id": clueId,
|
|
|
"position_id": positionId,
|
|
|
"change_field": "trailstatus",
|
|
|
- "change_type": "线索状态变更",
|
|
|
+ "change_type": "基本信息变更",
|
|
|
"old_value": "商机线索",
|
|
|
"new_value": "新增",
|
|
|
"createtime": nowTime,
|
|
@@ -420,7 +447,7 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
|
|
|
}
|
|
|
updateId5 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
"clue_id": clueId,
|
|
|
- "position_id": positionId,
|
|
|
+ "position_id": common.If(trailstatus == "00" || trailstatus == "01", positionId, common.Int64All(data["position_id"])),
|
|
|
"change_type": "加入任务车",
|
|
|
"new_value": "线索来源自动更新" + "-" + topname + "-" + subname,
|
|
|
"createtime": nowTime,
|
|
@@ -433,14 +460,30 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
|
|
|
old_department := common.ObjToString(data["department"])
|
|
|
old_follow_project_area := common.ObjToString(data["follow_project_area"])
|
|
|
old_role := common.ObjToString(data["role"])
|
|
|
+ old_cluename := common.ObjToString(data["cluename"])
|
|
|
+ old_top_cluetype := common.ObjToString(data["top_cluetype"])
|
|
|
+ old_sub_cluetype := common.ObjToString(data["sub_cluetype"])
|
|
|
+ old_topname, old_subname := "", ""
|
|
|
+ if old_top_cluetype != "" {
|
|
|
+ pcodeData := TiDb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"code": old_top_cluetype}, "", "")
|
|
|
+ if pcodeData != nil && len(*pcodeData) > 0 {
|
|
|
+ old_topname = common.ObjToString((*pcodeData)["name"])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if old_sub_cluetype != "" {
|
|
|
+ pcodeData := TiDb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"code": old_sub_cluetype}, "", "")
|
|
|
+ if pcodeData != nil && len(*pcodeData) > 0 {
|
|
|
+ old_subname = common.ObjToString((*pcodeData)["name"])
|
|
|
+ }
|
|
|
+ }
|
|
|
if old_name != name {
|
|
|
updateId6 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
"clue_id": clueId,
|
|
|
- "position_id": positionId,
|
|
|
+ "position_id": common.If(trailstatus == "00" || trailstatus == "01", positionId, common.Int64All(data["position_id"])),
|
|
|
"change_field": "name",
|
|
|
"change_type": "基本信息变更",
|
|
|
- "old_value": old_name,
|
|
|
- "new_value": name,
|
|
|
+ "old_value": common.If(old_name != "", old_name, "/"),
|
|
|
+ "new_value": common.If(name != "", name, "/"),
|
|
|
"createtime": nowTime,
|
|
|
"BCPCID": BCPCID,
|
|
|
"operator_id": -1,
|
|
@@ -449,11 +492,11 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
|
|
|
if old_position != position {
|
|
|
updateId7 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
"clue_id": clueId,
|
|
|
- "position_id": positionId,
|
|
|
+ "position_id": common.If(trailstatus == "00" || trailstatus == "01", positionId, common.Int64All(data["position_id"])),
|
|
|
"change_field": "position",
|
|
|
"change_type": "基本信息变更",
|
|
|
- "old_value": old_position,
|
|
|
- "new_value": position,
|
|
|
+ "old_value": common.If(old_position != "", old_position, "/"),
|
|
|
+ "new_value": common.If(position != "", position, "/"),
|
|
|
"createtime": nowTime,
|
|
|
"BCPCID": BCPCID,
|
|
|
"operator_id": -1,
|
|
@@ -462,11 +505,11 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
|
|
|
if old_department != department {
|
|
|
updateId8 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
"clue_id": clueId,
|
|
|
- "position_id": positionId,
|
|
|
+ "position_id": common.If(trailstatus == "00" || trailstatus == "01", positionId, common.Int64All(data["position_id"])),
|
|
|
"change_field": "department",
|
|
|
"change_type": "基本信息变更",
|
|
|
- "old_value": old_department,
|
|
|
- "new_value": department,
|
|
|
+ "old_value": common.If(old_department != "", old_department, "/"),
|
|
|
+ "new_value": common.If(department != "", department, "/"),
|
|
|
"createtime": nowTime,
|
|
|
"BCPCID": BCPCID,
|
|
|
"operator_id": -1,
|
|
@@ -475,11 +518,11 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
|
|
|
if old_role != role {
|
|
|
updateId9 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
"clue_id": clueId,
|
|
|
- "position_id": positionId,
|
|
|
+ "position_id": common.If(trailstatus == "00" || trailstatus == "01", positionId, common.Int64All(data["position_id"])),
|
|
|
"change_field": "role",
|
|
|
"change_type": "基本信息变更",
|
|
|
- "old_value": old_role,
|
|
|
- "new_value": role,
|
|
|
+ "old_value": common.If(old_role != "", old_role, "/"),
|
|
|
+ "new_value": common.If(role != "", role, "/"),
|
|
|
"createtime": nowTime,
|
|
|
"BCPCID": BCPCID,
|
|
|
"operator_id": -1,
|
|
@@ -488,17 +531,56 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
|
|
|
if old_follow_project_area != follow_project_area {
|
|
|
updateId10 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
"clue_id": clueId,
|
|
|
- "position_id": positionId,
|
|
|
+ "position_id": common.If(trailstatus == "00" || trailstatus == "01", positionId, common.Int64All(data["position_id"])),
|
|
|
"change_field": "follow_project_area",
|
|
|
"change_type": "基本信息变更",
|
|
|
- "old_value": old_follow_project_area,
|
|
|
- "new_value": follow_project_area,
|
|
|
+ "old_value": common.If(old_follow_project_area != "", old_follow_project_area, "/"),
|
|
|
+ "new_value": common.If(follow_project_area != "", follow_project_area, "/"),
|
|
|
+ "createtime": nowTime,
|
|
|
+ "BCPCID": BCPCID,
|
|
|
+ "operator_id": -1,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if old_cluename != cluename {
|
|
|
+ updateId11 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
+ "clue_id": clueId,
|
|
|
+ "position_id": common.If(trailstatus == "00" || trailstatus == "01", positionId, common.Int64All(data["position_id"])),
|
|
|
+ "change_field": "cluename",
|
|
|
+ "change_type": "基本信息变更",
|
|
|
+ "old_value": common.If(old_cluename != "", old_cluename, "/"),
|
|
|
+ "new_value": common.If(cluename != "", cluename, "/"),
|
|
|
+ "createtime": nowTime,
|
|
|
+ "BCPCID": BCPCID,
|
|
|
+ "operator_id": -1,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if old_top_cluetype != top_cluetype {
|
|
|
+ updateId12 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
+ "clue_id": clueId,
|
|
|
+ "position_id": common.If(trailstatus == "00" || trailstatus == "01", positionId, common.Int64All(data["position_id"])),
|
|
|
+ "change_field": "top_cluetype",
|
|
|
+ "change_type": "基本信息变更",
|
|
|
+ "old_value": common.If(old_topname != "", old_topname, "/"),
|
|
|
+ "new_value": common.If(topname != "", topname, "/"),
|
|
|
+ "createtime": nowTime,
|
|
|
+ "BCPCID": BCPCID,
|
|
|
+ "operator_id": -1,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if old_sub_cluetype != sub_cluetype {
|
|
|
+ updateId13 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
+ "clue_id": clueId,
|
|
|
+ "position_id": common.If(trailstatus == "00" || trailstatus == "01", positionId, common.Int64All(data["position_id"])),
|
|
|
+ "change_field": "sub_cluetype",
|
|
|
+ "change_type": "基本信息变更",
|
|
|
+ "old_value": common.If(old_subname != "", old_subname, "/"),
|
|
|
+ "new_value": common.If(subname != "", subname, "/"),
|
|
|
"createtime": nowTime,
|
|
|
"BCPCID": BCPCID,
|
|
|
"operator_id": -1,
|
|
|
})
|
|
|
}
|
|
|
- return ok && ok1 && seaId > -1 && updateId1 > -1 && updateId2 > -1 && updateId3 > -1 && updateId4 > -1 && updateId5 > -1 && updateId6 > -1 && updateId7 > -1 && updateId8 > -1 && updateId9 > -1 && updateId10 > -1
|
|
|
+ return ok && ok1 && seaId > -1 && updateId1 > -1 && updateId2 > -1 && updateId3 > -1 && updateId4 > -1 && updateId5 > -1 && updateId6 > -1 && updateId7 > -1 && updateId8 > -1 && updateId9 > -1 && updateId10 > -1 && updateId11 > -1 && updateId12 > -1 && updateId13 > -1
|
|
|
}) {
|
|
|
log.Println("线索更新成功")
|
|
|
if TiDb.Count("dwd_f_userbase_contacts", map[string]interface{}{"phone": phone}) == 0 {
|