|
@@ -7,6 +7,8 @@ import (
|
|
|
"strings"
|
|
|
"time"
|
|
|
|
|
|
+ "app.yhyue.com/moapp/jybase/redis"
|
|
|
+
|
|
|
"app.yhyue.com/moapp/jybase/common"
|
|
|
"app.yhyue.com/moapp/jybase/mongodb"
|
|
|
)
|
|
@@ -21,14 +23,19 @@ func orders() {
|
|
|
sql := fmt.Sprintf(`select * from dataexport_order where order_status = 0 and product_type in ("大会员","VIP订阅","数据流量包","历史数据") and create_time <= "%s" and create_time >= "%s" and id > %s`, selectTimeEnd, selectTimeStart, fmt.Sprint(lastOrderId))
|
|
|
data := Mysql.SelectBySql(sql)
|
|
|
if data != nil && *data != nil && len(*data) > 0 {
|
|
|
- for k, v := range *data {
|
|
|
- FormatData(v, "orders")
|
|
|
- if k == len(*data)-1 {
|
|
|
- lastOrderId = common.IntAll(v["id"])
|
|
|
+ for _, v := range *data {
|
|
|
+ // FormatData(v, "orders")
|
|
|
+ // if k == len(*data)-1 {
|
|
|
+ // lastOrderId = common.IntAll(v["id"])
|
|
|
+ // }
|
|
|
+ ok1, _ := FormatData(v, "orders")
|
|
|
+ if !ok1 {
|
|
|
+ common.WriteSysConfig(&cfg)
|
|
|
+ break
|
|
|
}
|
|
|
+ cfg.LastOrderId = common.IntAll(v["id"])
|
|
|
}
|
|
|
}
|
|
|
- cfg.LastOrderId = lastOrderId
|
|
|
common.WriteSysConfig(&cfg)
|
|
|
log.Println("未支付订单定时任务结束")
|
|
|
}
|
|
@@ -90,8 +97,13 @@ func saleLeads() {
|
|
|
if !iter.Next(&thisData) {
|
|
|
break
|
|
|
}
|
|
|
+ ok1, _ := FormatData(thisData, "saleLeads")
|
|
|
+ if !ok1 {
|
|
|
+ common.WriteSysConfig(&cfg)
|
|
|
+ break
|
|
|
+ }
|
|
|
cfg.LastId = mongodb.BsonIdToSId(thisData["_id"])
|
|
|
- FormatData(thisData, "saleLeads")
|
|
|
+ // FormatData(thisData, "saleLeads")
|
|
|
}
|
|
|
common.WriteSysConfig(&cfg)
|
|
|
log.Println("用户留资定时任务结束")
|
|
@@ -162,9 +174,22 @@ func FormatData(data map[string]interface{}, item string) (bool, bool) {
|
|
|
}
|
|
|
//域外用户和内部用户和没有手机号,不存线索
|
|
|
if source == 5 || source == 6 || phone == "" {
|
|
|
+ log.Println("线索分配失败,线索过滤!!", item, source, phone, userId)
|
|
|
return true, false
|
|
|
}
|
|
|
if uId == "" {
|
|
|
+ if isExists, _ := redis.Exists("bidx", "bidx_userId_"+userId); isExists {
|
|
|
+ redisInt := redis.GetInt("bidx", "bidx_userId_"+userId)
|
|
|
+ if redisInt > 2 {
|
|
|
+ log.Println("线索分配失败,线索缺少信息,任务已执行超过3次", item, userId, phone)
|
|
|
+ return true, true
|
|
|
+ } else {
|
|
|
+ redis.Incr("bidx", "bidx_userId_"+userId)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ redis.Put("bidx", "bidx_userId_"+userId, 1, 3600)
|
|
|
+ }
|
|
|
+ log.Println("线索分配失败,线索缺少信息", item, phone, userId)
|
|
|
return false, false
|
|
|
}
|
|
|
//不是留资的要查一遍留资
|
|
@@ -189,34 +214,44 @@ func FormatData(data map[string]interface{}, item string) (bool, bool) {
|
|
|
//follow_project_area --> follow_project_monitor
|
|
|
follow_project_area = getAreaCode(userId)
|
|
|
//seatNumber position_id
|
|
|
- //自动分配规则暂不确定
|
|
|
log.Println("data +++", top_cluetype, sub_cluetype, level, follow_project_area)
|
|
|
if top_cluetype == "" || sub_cluetype == "" || level == "" {
|
|
|
+ log.Println("线索分配失败,线索过滤top_cluetype!!", item, uId, phone, userId)
|
|
|
return true, true
|
|
|
}
|
|
|
position_id, seatNumber, saleName, saleData := autoDraw(level)
|
|
|
log.Println("data -------", position_id, seatNumber, saleName)
|
|
|
- if position_id > 0 && seatNumber != "" && top_cluetype != "" && sub_cluetype != "" {
|
|
|
+ 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
|
|
|
+ log.Println("线索分配失败,私海线索数据超过限制", item, position_id, seatNumber, uId, userId, phone)
|
|
|
+ TiDb.UpdateOrDeleteBySql(`update dwd_f_crm_clue_autodraw_record set count = count + 1 where seatNumber = ? and clue_level = ?`, seatNumber, level)
|
|
|
+ return false, false
|
|
|
+ // position_id, seatNumber, saleName, saleData = autoDraw(level)
|
|
|
}
|
|
|
- uCount := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"uid": uId}, "", "")
|
|
|
+ uCount, oks := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"uid": uId}, "", ""), true
|
|
|
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)
|
|
|
+ oks = 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)
|
|
|
+ } else {
|
|
|
+ oks = SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, cluename, name, saleName, phone, position, department, industry, follow_project_area, role, seatNumber, position_id)
|
|
|
+ }
|
|
|
+ if oks {
|
|
|
+ TiDb.UpdateOrDeleteBySql(`update dwd_f_crm_clue_autodraw_record set count = count + 1 where seatNumber = ? and clue_level = ?`, seatNumber, level)
|
|
|
} else {
|
|
|
- SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, cluename, name, saleName, phone, position, department, industry, follow_project_area, role, seatNumber, position_id)
|
|
|
+ log.Println("线索分配失败!!", item, position_id, seatNumber, uId, userId, phone)
|
|
|
+ return false, false
|
|
|
}
|
|
|
}
|
|
|
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) {
|
|
|
+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) 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, seaId, uodateId1, uodateId2, uodateId3, uodateId4 := int64(0), int64(0), int64(0), int64(0), int64(0), int64(0)
|
|
|
// BCPCID := common.GetRandom(32)
|
|
|
- TiDb.ExecTx("保存线索", func(tx *sql.Tx) bool {
|
|
|
+ if TiDb.ExecTx("保存线索", func(tx *sql.Tx) bool {
|
|
|
//线索
|
|
|
- clueId := TiDb.InsertByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{
|
|
|
+ clueId = TiDb.InsertByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{
|
|
|
"userid": userId,
|
|
|
"uid": uId,
|
|
|
"seatNumber": seatNumber,
|
|
@@ -238,7 +273,7 @@ func SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, c
|
|
|
"role": role,
|
|
|
})
|
|
|
//私海 --> 任务车
|
|
|
- seaId := TiDb.InsertByTx(tx, "dwd_f_crm_private_sea", map[string]interface{}{
|
|
|
+ seaId = TiDb.InsertByTx(tx, "dwd_f_crm_private_sea", map[string]interface{}{
|
|
|
"clue_id": clueId,
|
|
|
"seatNumber": seatNumber,
|
|
|
"position_id": positionId,
|
|
@@ -251,7 +286,7 @@ func SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, c
|
|
|
"tasksource": "线索自动分配" + "-" + topname + "-" + subname,
|
|
|
})
|
|
|
//变更记录
|
|
|
- uodateId1 := TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
+ uodateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
"clue_id": clueId,
|
|
|
"position_id": positionId,
|
|
|
"change_type": "创建线索",
|
|
@@ -260,7 +295,7 @@ func SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, c
|
|
|
"BCPCID": common.GetRandom(32),
|
|
|
"operator_id": -1,
|
|
|
})
|
|
|
- uodateId2 := TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
+ uodateId2 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
"clue_id": clueId,
|
|
|
"position_id": positionId,
|
|
|
"change_field": "position_id",
|
|
@@ -271,7 +306,7 @@ func SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, c
|
|
|
"BCPCID": common.GetRandom(32),
|
|
|
"operator_id": -1,
|
|
|
})
|
|
|
- uodateId3 := TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
+ uodateId3 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
"clue_id": clueId,
|
|
|
"position_id": positionId,
|
|
|
"change_field": "trailstatus",
|
|
@@ -282,7 +317,7 @@ func SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, c
|
|
|
"BCPCID": common.GetRandom(32),
|
|
|
"operator_id": -1,
|
|
|
})
|
|
|
- uodateId4 := TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
+ uodateId4 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
"clue_id": clueId,
|
|
|
"position_id": positionId,
|
|
|
"change_type": "加入任务车",
|
|
@@ -291,11 +326,17 @@ func SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, c
|
|
|
"BCPCID": common.GetRandom(32),
|
|
|
"operator_id": -1,
|
|
|
})
|
|
|
- return clueId > 0 && seaId > 0 && uodateId1 > 0 && uodateId2 > 0 && uodateId3 > 0 && uodateId4 > 0
|
|
|
- })
|
|
|
+ return clueId > -1 && seaId > -1 && uodateId1 > -1 && uodateId2 > -1 && uodateId3 > -1 && uodateId4 > -1
|
|
|
+ }) {
|
|
|
+ log.Println("线索分配成功")
|
|
|
+ return true
|
|
|
+ } else {
|
|
|
+ log.Println("线索分配失败!!!", clueId, seaId, uodateId1, uodateId2, uodateId3, uodateId4, " 用户信息 ", item, position, seatNumber, uId, userId, phone)
|
|
|
+ return false
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-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) {
|
|
|
+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) 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 = 无意向 为变更线索状态
|
|
@@ -377,18 +418,19 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
|
|
|
insertSeaData["seatNumber"] = common.ObjToString(data["seatNumber"])
|
|
|
insertSeaData["position_id"] = common.Int64All(data["position_id"])
|
|
|
}
|
|
|
+ ok, ok1, ok2, seaId := true, true, true, int64(0)
|
|
|
+ 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 TiDb.ExecTx("更新线索", func(tx *sql.Tx) bool {
|
|
|
//线索
|
|
|
- ok := TiDb.UpdateByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{"uid": uId}, clueUpdateData)
|
|
|
- ok1, seaId := false, int64(0)
|
|
|
+ ok = TiDb.UpdateByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{"uid": uId}, clueUpdateData)
|
|
|
if is_assign == 1 {
|
|
|
ok1 = TiDb.UpdateByTx(tx, "dwd_f_crm_private_sea", map[string]interface{}{"clue_id": clueId}, seaUpdateData)
|
|
|
} else {
|
|
|
+ ok2 = TiDb.Delete("dwd_f_crm_open_sea", map[string]interface{}{"clue_id": clueId})
|
|
|
seaId = TiDb.InsertByTx(tx, "dwd_f_crm_private_sea", insertSeaData)
|
|
|
}
|
|
|
- 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{}{
|
|
@@ -396,8 +438,8 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
|
|
|
"position_id": positionId,
|
|
|
"change_field": "position_id",
|
|
|
"change_type": "所属人变更",
|
|
|
- "old_value": oldsaleName,
|
|
|
- "new_value": saleName,
|
|
|
+ "old_value": common.If(oldsaleName != "", oldsaleName, "/"),
|
|
|
+ "new_value": common.If(saleName != "", saleName, "/"),
|
|
|
"createtime": nowTime,
|
|
|
"BCPCID": common.GetRandom(32),
|
|
|
"operator_id": -1,
|
|
@@ -437,17 +479,19 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
|
|
|
"operator_id": -1,
|
|
|
})
|
|
|
} else {
|
|
|
- updateId2 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
- "clue_id": clueId,
|
|
|
- "position_id": common.Int64All(data["position_id"]),
|
|
|
- "change_field": "trailstatus",
|
|
|
- "change_type": "基本信息变更",
|
|
|
- "old_value": "商机线索",
|
|
|
- "new_value": "流失",
|
|
|
- "createtime": nowTime,
|
|
|
- "BCPCID": common.GetRandom(32),
|
|
|
- "operator_id": -1,
|
|
|
- })
|
|
|
+ if common.Int64All(data["position_id"]) > 0 {
|
|
|
+ updateId2 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
+ "clue_id": clueId,
|
|
|
+ "position_id": common.Int64All(data["position_id"]),
|
|
|
+ "change_field": "trailstatus",
|
|
|
+ "change_type": "基本信息变更",
|
|
|
+ "old_value": "商机线索",
|
|
|
+ "new_value": "流失",
|
|
|
+ "createtime": nowTime,
|
|
|
+ "BCPCID": common.GetRandom(32),
|
|
|
+ "operator_id": -1,
|
|
|
+ })
|
|
|
+ }
|
|
|
updateId3 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
"clue_id": clueId,
|
|
|
"position_id": positionId,
|
|
@@ -621,6 +665,10 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
|
|
|
"baseinfo_id": uId,
|
|
|
})
|
|
|
}
|
|
|
+ return true
|
|
|
+ } else {
|
|
|
+ log.Println("线索更新失败!!!", ok, ok1, ok2, seaId, updateId1, updateId2, updateId3, updateId4, updateId5, updateId6, updateId7, updateId8, updateId9, updateId10, updateId11, updateId12, updateId13, " 用户信息 ", item, position, seatNumber, uId, userId, phone)
|
|
|
+ return false
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -708,9 +756,11 @@ func getClueType(item string, data map[string]interface{}) (pcode, code, level,
|
|
|
|
|
|
// 获取自动分配的人
|
|
|
func autoDraw(mode string) (positionId int64, seatNumber, saleName string, saleData []map[string]interface{}) {
|
|
|
- query := `select * from jy_salesperson_info where status = 0 and position != 0`
|
|
|
+ query := `select * from jy_salesperson_info where`
|
|
|
if mode == "A" || mode == "B" {
|
|
|
- query += ` and is_complete = 1`
|
|
|
+ query += ` is_complete = 1`
|
|
|
+ } else {
|
|
|
+ query += ` is_complete = 1 or is_complete = 0`
|
|
|
}
|
|
|
data := TiDb.SelectBySql(query)
|
|
|
if data != nil && len(*data) > 0 {
|
|
@@ -795,9 +845,9 @@ func autoDraw(mode string) (positionId int64, seatNumber, saleName string, saleD
|
|
|
saleName = common.ObjToString(v["name"])
|
|
|
}
|
|
|
}
|
|
|
- if positionId > 0 {
|
|
|
- TiDb.UpdateOrDeleteBySql(`update dwd_f_crm_clue_autodraw_record set count = count + 1 where seatNumber = ? and clue_level = ?`, seatNumber, mode)
|
|
|
- }
|
|
|
+ // if positionId > 0 {
|
|
|
+ // TiDb.UpdateOrDeleteBySql(`update dwd_f_crm_clue_autodraw_record set count = count + 1 where seatNumber = ? and clue_level = ?`, seatNumber, mode)
|
|
|
+ // }
|
|
|
}
|
|
|
return
|
|
|
}
|