|
@@ -20,20 +20,18 @@ func RelatedCompanyIsCustom(companyName string) bool {
|
|
|
return entity.JyBiTidb.CountBySql("SELECT count(1) FROM dwd_f_csm_customer_info WHERE company_name = ? and account_type= 1 and is_transfer = 0", companyName) > 0
|
|
|
}
|
|
|
|
|
|
-// 电销系统修改线索名称移交客成
|
|
|
-func ClueTransfer(clueId, changeType int64, clueName string) (status int, err error) {
|
|
|
- /*clueData := entity.JyBiTidb.FindOne("dwd_f_crm_clue_info", bson.M{"id": clueId}, "cluename", "")
|
|
|
- if clueData == nil || len(*clueData) == 0 {
|
|
|
- return -1, errors.New("未查询到线索信息")
|
|
|
- }
|
|
|
- clueName := common.InterfaceToStr((*clueData)["cluename"])*/
|
|
|
-
|
|
|
- if changeType == 1 {
|
|
|
- //DxUpdateClueName
|
|
|
+// 修改线索名称
|
|
|
+func ClueTransfer(clueId, changeType, kcType, mainClueId int64, clueName string) (status int, err error) {
|
|
|
+ if changeType == 1 { //电销中修改线索名称
|
|
|
+ status, err = DxUpdateClueName(clueId, clueName)
|
|
|
} else { //客成修改名称
|
|
|
-
|
|
|
+ if kcType == 1 { //回电销
|
|
|
+ status, err = ClueTransferDx(clueId, mainClueId)
|
|
|
+ } else { //划转到关联客户客成
|
|
|
+ status, err = ClueTransferKc(clueId, clueName)
|
|
|
+ }
|
|
|
}
|
|
|
- return 0, err
|
|
|
+ return status, err
|
|
|
|
|
|
}
|
|
|
|
|
@@ -66,6 +64,7 @@ func DxUpdateClueName(clueId int64, clueName string) (status int, err error) {
|
|
|
"is_admin": 0,
|
|
|
"primary_id": cusId,
|
|
|
"account_type": 4,
|
|
|
+ "is_task": 0,
|
|
|
})
|
|
|
in := entity.JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
"clue_id": clueId,
|
|
@@ -126,18 +125,12 @@ func DxUpdateClueName(clueId int64, clueName string) (status int, err error) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func KcUpdateClueName(clueId, types, mainClueId int64, clueName string) (status int, err error) {
|
|
|
- if types == 1 { //回电销
|
|
|
-
|
|
|
- } else { //划转到关联客户客成
|
|
|
-
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-func ClueTransferDx(clueId, mainClueId int64) {
|
|
|
+// 客成系统修改线索名称,移交电销
|
|
|
+func ClueTransferDx(clueId, mainClueId int64) (status int, err error) {
|
|
|
//查询原主账号电销人员
|
|
|
is_assign := 1
|
|
|
- positionId, seatNumber, isFreeze := GetSalePerson(mainClueId)
|
|
|
+ status = 1
|
|
|
+ positionId, kcPositionId, seatNumber, isFreeze := GetSalePerson(mainClueId)
|
|
|
if isFreeze || positionId == 0 {
|
|
|
is_assign = 0
|
|
|
}
|
|
@@ -150,15 +143,20 @@ func ClueTransferDx(clueId, mainClueId int64) {
|
|
|
"position_id": positionId,
|
|
|
"seatNumber": seatNumber,
|
|
|
"is_transfer": 0,
|
|
|
+ //"is_renewal_protection": 0,
|
|
|
}
|
|
|
|
|
|
ok1 := entity.JyBiTidb.UpdateByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, updateClueMap)
|
|
|
ok2 := entity.JyBiTidb.UpdateByTx(tx, "dwd_f_csm_customer_info", map[string]interface{}{"clue_id": clueId}, map[string]interface{}{
|
|
|
- "is_transfer": 1,
|
|
|
+ "is_transfer": 1,
|
|
|
+ "position_id": 0,
|
|
|
+ "name": "",
|
|
|
+ "account_type": 0,
|
|
|
+ "primary_id": "",
|
|
|
})
|
|
|
in1 := entity.JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
"clue_id": clueId,
|
|
|
- "position_id": common.If(kcpositionId > 0, kcpositionId, -1),
|
|
|
+ "position_id": common.If(kcPositionId > 0, kcPositionId, -1),
|
|
|
"change_type": "退回公海",
|
|
|
"new_value": "不再是非集团公司成交客户关联线索,移交销售",
|
|
|
"createtime": nowTime,
|
|
@@ -167,30 +165,83 @@ func ClueTransferDx(clueId, mainClueId int64) {
|
|
|
})
|
|
|
in2 := entity.JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
"clue_id": clueId,
|
|
|
- "position_id": common.If(kcpositionId > 0, kcpositionId, -1),
|
|
|
+ "position_id": common.If(kcPositionId > 0, kcPositionId, -1),
|
|
|
"change_type": "移交销售",
|
|
|
"new_value": "不再是非集团公司成交客户关联线索,移交销售",
|
|
|
"createtime": nowTime,
|
|
|
"BCPCID": common.GetRandom(32),
|
|
|
"operator_id": -1,
|
|
|
})
|
|
|
- return ok1 && ok2 && in1 > 0 && in2 > 0
|
|
|
+ in3 := entity.JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
+ "clue_id": clueId,
|
|
|
+ "position_id": common.If(kcPositionId > 0, kcPositionId, -1),
|
|
|
+ "change_field": "position_id",
|
|
|
+ "change_type": "客户成功经理",
|
|
|
+ "old_value": kcPositionId,
|
|
|
+ "new_value": "/",
|
|
|
+ "createtime": nowTime,
|
|
|
+ "BCPCID": common.GetRandom(32),
|
|
|
+ "operator_id": -1,
|
|
|
+ })
|
|
|
+ return ok1 && ok2 && in1 > 0 && in2 > 0 && in3 > 0
|
|
|
})
|
|
|
if !ok {
|
|
|
log.Printf("子账号或免费账号移交销售失败:clueId:%d\n", clueId)
|
|
|
+ status = -1
|
|
|
+ err = errors.New("子账号或免费账号移交销售失败")
|
|
|
}
|
|
|
+ return status, err
|
|
|
}
|
|
|
|
|
|
-func ClueTransferKc() {
|
|
|
-
|
|
|
+// 移交客成
|
|
|
+func ClueTransferKc(clueId int64, clueName string) (int, error) {
|
|
|
+ mainKcData := entity.JyBiTidb.FindOne("dwd_f_csm_customer_info", map[string]interface{}{"company_name": clueName, "is_transfer": 0, "is_admin": 1}, "", "")
|
|
|
+ if mainKcData == nil || len(*mainKcData) == 0 {
|
|
|
+ return -1, errors.New("未查询到关联客户")
|
|
|
+ }
|
|
|
+ nowTime := time.Now().Format(date.Date_Full_Layout)
|
|
|
+ cusId := common.Int64All((*mainKcData)["id"])
|
|
|
+ entId := common.Int64All((*mainKcData)["ent_id"])
|
|
|
+ companyName := common.InterfaceToStr((*mainKcData)["company_name"])
|
|
|
+ positionId := common.Int64All((*mainKcData)["position_id"])
|
|
|
+ name := common.Int64All((*mainKcData)["name"])
|
|
|
+ up1 := entity.JyBiTidb.Update("dwd_f_csm_customer_info", map[string]interface{}{"clue_id": clueId}, bson.M{
|
|
|
+ "is_transfer": 0,
|
|
|
+ "is_renewal_protection": 0,
|
|
|
+ "transfertime": nowTime,
|
|
|
+ "ent_id": entId,
|
|
|
+ "company_name": companyName,
|
|
|
+ "position_id": positionId,
|
|
|
+ "name": name,
|
|
|
+ "is_admin": 0,
|
|
|
+ "primary_id": cusId,
|
|
|
+ "account_type": 4,
|
|
|
+ "is_task": 0,
|
|
|
+ })
|
|
|
+ in := entity.JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
+ "clue_id": clueId,
|
|
|
+ "position_id": positionId,
|
|
|
+ "change_type": "成交客户移交",
|
|
|
+ "new_value": "移交至客户成功部",
|
|
|
+ "createtime": nowTime,
|
|
|
+ "BCPCID": common.GetRandom(32),
|
|
|
+ "operator_id": -1,
|
|
|
+ "change_reason": "与主账号线索名称保持一致",
|
|
|
+ })
|
|
|
+ up2 := entity.JyBiTidb.Update("dwd_f_crm_clue_info", bson.M{"id": clueId}, map[string]interface{}{"is_transfer": 1, "updatetime": nowTime})
|
|
|
+ if up1 && up2 && in > 0 {
|
|
|
+ return 1, nil
|
|
|
+ }
|
|
|
+ return -1, errors.New("更新客成信息出错")
|
|
|
}
|
|
|
|
|
|
-func GetSalePerson(mainClueId int64) (positionId int64, seatNumber string, isFreeze bool) {
|
|
|
+func GetSalePerson(mainClueId int64) (positionId, kcPosId int64, seatNumber string, isFreeze bool) {
|
|
|
isFreeze = false
|
|
|
- clueData := entity.JyBiTidb.FindOne("dwd_f_crm_clue_info", bson.M{"id": mainClueId}, "position_id,seatNumber", "")
|
|
|
+ clueData := entity.JyBiTidb.SelectBySql("SELECT a.position_id,a.seatNumber,b.position_id as kcPosId FROM dwd_f_crm_clue_info a LEFT JOIN dwd_f_csm_customer_info b ON a.id = b.clue_id WHERE a.id = ?", mainClueId)
|
|
|
if clueData != nil && len(*clueData) > 0 {
|
|
|
- positionId = common.Int64All((*clueData)["position_id"])
|
|
|
- seatNumber = common.InterfaceToStr((*clueData)["seatNumber"])
|
|
|
+ positionId = common.Int64All((*clueData)[0]["position_id"])
|
|
|
+ seatNumber = common.InterfaceToStr((*clueData)[0]["seatNumber"])
|
|
|
+ kcPosId = common.Int64All((*clueData)[0]["kcPosId"])
|
|
|
}
|
|
|
|
|
|
pdata := entity.JyBiTidb.SelectBySql(`select * from dwd_f_crm_personnel_management where seat_number is not null and seat_number != ""`)
|