|
@@ -258,6 +258,13 @@ func kcJob(data map[string]interface{}) int {
|
|
|
"operator_id": -1,
|
|
|
})
|
|
|
}
|
|
|
+ if is_transfer == 1 {
|
|
|
+ if customerName == db.KeCheng.Admin {
|
|
|
+ TiDb.UpdateOrDeleteBySql(`update dwd_f_csm_customer_autodraw_record set count = count + 2 where name = ?`, customerName)
|
|
|
+ } else {
|
|
|
+ TiDb.UpdateOrDeleteBySql(`update dwd_f_csm_customer_autodraw_record set count = count + 1 where name = ?`, customerName)
|
|
|
+ }
|
|
|
+ }
|
|
|
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})
|
|
|
}
|
|
@@ -306,6 +313,11 @@ func kcJob(data map[string]interface{}) int {
|
|
|
return cId > -1 && ok && updateId1 > -1 && updateId2 > -1 && updateId3 > -1
|
|
|
}) {
|
|
|
//TiDb.UpdateOrDeleteBySql(`update dwd_f_csm_customer_autodraw_record set count = count + 1 where name = ?`, name)
|
|
|
+ if customerName == db.KeCheng.Admin {
|
|
|
+ TiDb.UpdateOrDeleteBySql(`update dwd_f_csm_customer_autodraw_record set count = count + 2 where name = ?`, customerName)
|
|
|
+ } else {
|
|
|
+ TiDb.UpdateOrDeleteBySql(`update dwd_f_csm_customer_autodraw_record set count = count + 1 where name = ?`, customerName)
|
|
|
+ }
|
|
|
log.Println("保存客户成功")
|
|
|
} else {
|
|
|
log.Println("保存客户失败!!!", clueId, cId, ok, updateId1, updateId2, updateId3, " 用户信息 ", customerName, customerPositionId, uId)
|
|
@@ -315,11 +327,18 @@ func kcJob(data map[string]interface{}) int {
|
|
|
}
|
|
|
|
|
|
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)
|
|
|
+ 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 ent_id=?) and resign = 0 `
|
|
|
+ data := TiDb.SelectBySql(query, db.EntId)
|
|
|
if data == nil || len(*data) == 0 {
|
|
|
return
|
|
|
}
|
|
|
+ positionId, name = findKcOldPerson(entId, orderPositionId, salesperson, saleDep, isExist, csmdata, data)
|
|
|
+ if positionId == 0 {
|
|
|
+ positionId, name = findKcNewPerson(entId, data)
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+func findKcOldPerson(entId int, orderPositionId int64, salesperson, saleDep string, isExist bool, csmdata *map[string]interface{}, data *[]map[string]interface{}) (positionId int64, name string) {
|
|
|
//判断是否需要新增客成数据
|
|
|
if isExist {
|
|
|
//用户存在客成数据
|
|
@@ -377,7 +396,66 @@ func cAutoDraw(entId int, orderPositionId int64, salesperson, saleDep string, is
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
+func findKcNewPerson(entId int, data *[]map[string]interface{}) (positionId int64, name string) {
|
|
|
+ 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 b.ent_id=? and (a.name = b.name) and b.resign = 0`
|
|
|
+ countData := TiDb.SelectBySql(sql, db.EntId)
|
|
|
+ if countData != nil && len(*countData) > 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
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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"])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ countres++
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, v := range *data {
|
|
|
|
|
|
+ if name == common.ObjToString(v["name"]) {
|
|
|
+
|
|
|
+ positionId = common.Int64All(v["position_id"])
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
+
|
|
|
+}
|
|
|
func kcAuto() {
|
|
|
log.Println("客户成功系统自动进入任务车定时任务开始")
|
|
|
nowTime := time.Now().Format(date.Date_Full_Layout)
|