Browse Source

主账号修改线索名称移交客成

renjiaojiao 1 day ago
parent
commit
f74036fba6

+ 13 - 2
api/biService.api

@@ -145,11 +145,12 @@ type (
 	}
 	TransferClueReq {
 		UserId     string `header:"userId,optional"`
-		BaseUserId int64  `header:"newUserId"`
+		BaseUserId int64  `header:"newUserId,optional"`
 		PositionId int64  `header:"positionId,optional"`
 		EntUserId  int64  `header:"entUserId,optional"`
 		Phone      string `json:"phone"`
 		OrderNo    string `json:"orderNo"`
+		OldCusId   int64  `json:"oldCusId"`
 	}
 	FindClueInfoReq {
 		UserId     string `header:"userId,optional"`
@@ -179,10 +180,17 @@ type (
 	ClueTransferReq {
 		ClueId     int64  `json:"clueId"`
 		ClueName   string `json:"clueName"`
-		ChangeType int64  `json:"changeType,optional"`
+		ChangeType int64  `json:"changeType"`
 		KcType     int64  `json:"kcType,optional"`
 		MainClueId int64  `json:"mainClueId,optional"`
 	}
+	UpdateCompanyNameReq {
+		MainClueId     int64  `json:"mainClueId"`
+		NewCompanyName string `json:"newCompanyName"`
+		NewEntId       int64  `json:"newEntId"`
+		OldCompanyName string `json:"oldCompanyName"`
+		OldEntId       int64  `json:"oldEntId"`
+	}
 )
 
 @server (
@@ -287,4 +295,7 @@ service biService-api {
 	post /biService/materialSave (MaterialSaveReq) returns (biResp)
 	@handler ClueTransfer
 	post /biService/clueTransfer (ClueTransferReq) returns (biResp)
+	
+	@handler UpdateCompanyNameReq
+	post /biService/updateCompanyNameReq (UpdateCompanyNameReq) returns (biResp)
 }

+ 5 - 0
api/internal/handler/routes.go

@@ -152,6 +152,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 				Path:    "/biService/clueTransfer",
 				Handler: ClueTransferHandler(serverCtx),
 			},
+			{
+				Method:  http.MethodPost,
+				Path:    "/biService/updateCompanyNameReq",
+				Handler: UpdateCompanyNameReqHandler(serverCtx),
+			},
 		},
 	)
 }

+ 1 - 0
api/internal/logic/transfercluesucclogic.go

@@ -34,6 +34,7 @@ func (l *TransferClueSuccLogic) TransferClueSucc(req *types.TransferClueReq) (re
 		UserId:     req.UserId,
 		Phone:      req.Phone,
 		OrderNo:    req.OrderNo,
+		OldCusId:   req.OldCusId,
 	})
 	return &types.BiResp{Error_code: res.ErrorCode, Error_msg: res.ErrorMsg, Data: gconv.Map(gconv.UnsafeBytesToStr(res.Data))}, err
 }

+ 11 - 2
api/internal/types/types.go

@@ -167,11 +167,12 @@ type CreateClueReq struct {
 
 type TransferClueReq struct {
 	UserId     string `header:"userId,optional"`
-	BaseUserId int64  `header:"newUserId"`
+	BaseUserId int64  `header:"newUserId,optional"`
 	PositionId int64  `header:"positionId,optional"`
 	EntUserId  int64  `header:"entUserId,optional"`
 	Phone      string `json:"phone"`
 	OrderNo    string `json:"orderNo"`
+	OldCusId   int64  `json:"oldCusId"`
 }
 
 type FindClueInfoReq struct {
@@ -203,7 +204,15 @@ type MaterialSaveReq struct {
 type ClueTransferReq struct {
 	ClueId     int64  `json:"clueId"`
 	ClueName   string `json:"clueName"`
-	ChangeType int64  `json:"changeType,optional"`
+	ChangeType int64  `json:"changeType"`
 	KcType     int64  `json:"kcType,optional"`
 	MainClueId int64  `json:"mainClueId,optional"`
 }
+
+type UpdateCompanyNameReq struct {
+	MainClueId     int64  `json:"mainClueId"`
+	NewCompanyName string `json:"newCompanyName"`
+	NewEntId       int64  `json:"newEntId"`
+	OldCompanyName string `json:"oldCompanyName"`
+	OldEntId       int64  `json:"oldEntId"`
+}

+ 6 - 6
rpc/biService.proto

@@ -298,12 +298,12 @@ message ClueTransferReq {
 }
 
 message UpdateCompanyNameReq {
-  int64 mainClueId = 1;
-  string NewCompanyName = 2;
-  int64 NewEntId = 3;
-  int64 cusId = 4;
-  string OldCompanyName = 5;
-  int64 OldEntId = 6;
+  int64 mainClueId = 1;//主账号线索id
+  string newCompanyName = 2; //新企业名称
+  int64 newEntId = 3; //新企业id
+  int64 cusId = 4; //不必须参数
+  string oldCompanyName = 5; //原企业名称
+  int64 oldEntId = 6; //原企业id
 }
 
 service BiService {

+ 1 - 1
rpc/internal/logic/transfercluebyphonelogic.go

@@ -25,6 +25,6 @@ func NewTransferClueByPhoneLogic(ctx context.Context, svcCtx *svc.ServiceContext
 }
 
 func (l *TransferClueByPhoneLogic) TransferClueByPhone(in *pb.TransferClueReq) (*pb.BiReply, error) {
-	result, err := service.TransferClue(in)
+	result, err := service.TransferClueByOrder(in)
 	return result, err
 }

+ 14 - 14
rpc/pb/biService.pb.go

@@ -3079,12 +3079,12 @@ type UpdateCompanyNameReq struct {
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 
-	MainClueId     int64  `protobuf:"varint,1,opt,name=mainClueId,proto3" json:"mainClueId,omitempty"`
-	NewCompanyName string `protobuf:"bytes,2,opt,name=NewCompanyName,proto3" json:"NewCompanyName,omitempty"`
-	NewEntId       int64  `protobuf:"varint,3,opt,name=NewEntId,proto3" json:"NewEntId,omitempty"`
-	CusId          int64  `protobuf:"varint,4,opt,name=cusId,proto3" json:"cusId,omitempty"`
-	OldCompanyName string `protobuf:"bytes,5,opt,name=OldCompanyName,proto3" json:"OldCompanyName,omitempty"`
-	OldEntId       int64  `protobuf:"varint,6,opt,name=OldEntId,proto3" json:"OldEntId,omitempty"`
+	MainClueId     int64  `protobuf:"varint,1,opt,name=mainClueId,proto3" json:"mainClueId,omitempty"`        //主账号线索id
+	NewCompanyName string `protobuf:"bytes,2,opt,name=newCompanyName,proto3" json:"newCompanyName,omitempty"` //新企业名称
+	NewEntId       int64  `protobuf:"varint,3,opt,name=newEntId,proto3" json:"newEntId,omitempty"`            //新企业id
+	CusId          int64  `protobuf:"varint,4,opt,name=cusId,proto3" json:"cusId,omitempty"`                  //不必须参数
+	OldCompanyName string `protobuf:"bytes,5,opt,name=oldCompanyName,proto3" json:"oldCompanyName,omitempty"` //原企业名称
+	OldEntId       int64  `protobuf:"varint,6,opt,name=oldEntId,proto3" json:"oldEntId,omitempty"`            //原企业id
 }
 
 func (x *UpdateCompanyNameReq) Reset() {
@@ -3538,16 +3538,16 @@ var file_biService_proto_rawDesc = []byte{
 	0x70, 0x64, 0x61, 0x74, 0x65, 0x43, 0x6f, 0x6d, 0x70, 0x61, 0x6e, 0x79, 0x4e, 0x61, 0x6d, 0x65,
 	0x52, 0x65, 0x71, 0x12, 0x1e, 0x0a, 0x0a, 0x6d, 0x61, 0x69, 0x6e, 0x43, 0x6c, 0x75, 0x65, 0x49,
 	0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0a, 0x6d, 0x61, 0x69, 0x6e, 0x43, 0x6c, 0x75,
-	0x65, 0x49, 0x64, 0x12, 0x26, 0x0a, 0x0e, 0x4e, 0x65, 0x77, 0x43, 0x6f, 0x6d, 0x70, 0x61, 0x6e,
-	0x79, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x4e, 0x65, 0x77,
-	0x43, 0x6f, 0x6d, 0x70, 0x61, 0x6e, 0x79, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x4e,
-	0x65, 0x77, 0x45, 0x6e, 0x74, 0x49, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x4e,
+	0x65, 0x49, 0x64, 0x12, 0x26, 0x0a, 0x0e, 0x6e, 0x65, 0x77, 0x43, 0x6f, 0x6d, 0x70, 0x61, 0x6e,
+	0x79, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x6e, 0x65, 0x77,
+	0x43, 0x6f, 0x6d, 0x70, 0x61, 0x6e, 0x79, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x6e,
+	0x65, 0x77, 0x45, 0x6e, 0x74, 0x49, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x6e,
 	0x65, 0x77, 0x45, 0x6e, 0x74, 0x49, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x75, 0x73, 0x49, 0x64,
 	0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x63, 0x75, 0x73, 0x49, 0x64, 0x12, 0x26, 0x0a,
-	0x0e, 0x4f, 0x6c, 0x64, 0x43, 0x6f, 0x6d, 0x70, 0x61, 0x6e, 0x79, 0x4e, 0x61, 0x6d, 0x65, 0x18,
-	0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x4f, 0x6c, 0x64, 0x43, 0x6f, 0x6d, 0x70, 0x61, 0x6e,
-	0x79, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x4f, 0x6c, 0x64, 0x45, 0x6e, 0x74, 0x49,
-	0x64, 0x18, 0x06, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x4f, 0x6c, 0x64, 0x45, 0x6e, 0x74, 0x49,
+	0x0e, 0x6f, 0x6c, 0x64, 0x43, 0x6f, 0x6d, 0x70, 0x61, 0x6e, 0x79, 0x4e, 0x61, 0x6d, 0x65, 0x18,
+	0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x6f, 0x6c, 0x64, 0x43, 0x6f, 0x6d, 0x70, 0x61, 0x6e,
+	0x79, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x6f, 0x6c, 0x64, 0x45, 0x6e, 0x74, 0x49,
+	0x64, 0x18, 0x06, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x6f, 0x6c, 0x64, 0x45, 0x6e, 0x74, 0x49,
 	0x64, 0x32, 0xe9, 0x09, 0x0a, 0x09, 0x42, 0x69, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12,
 	0x30, 0x0a, 0x0b, 0x6d, 0x79, 0x44, 0x61, 0x74, 0x61, 0x41, 0x73, 0x73, 0x65, 0x74, 0x12, 0x0f,
 	0x2e, 0x4d, 0x79, 0x44, 0x61, 0x74, 0x61, 0x41, 0x73, 0x73, 0x65, 0x74, 0x52, 0x65, 0x71, 0x1a,

+ 14 - 8
service/custom.go

@@ -9,6 +9,7 @@ import (
 	"github.com/gogf/gf/v2/util/gconv"
 	"go.mongodb.org/mongo-driver/bson"
 	"log"
+	"regexp"
 	"strings"
 	"time"
 )
@@ -17,6 +18,9 @@ func RelatedCompanyIsCustom(companyName, uid string, isGroup bool) (isCustomer,
 	if companyName == "" {
 		return false, false
 	}
+	if ValidatePhone(companyName) {
+		return false, false
+	}
 	mainData := entity.JyBiTidb.SelectBySql("SELECT a.id,a.ent_id FROM dwd_f_csm_customer_info a LEFT JOIN dwd_f_crm_clue_info b ON b.id=a.clue_id WHERE b.cluename = ? AND a.is_transfer = 0 AND a.account_type = 1", companyName)
 	if mainData != nil && len(*mainData) > 0 {
 		isCustomer = true
@@ -32,6 +36,13 @@ func RelatedCompanyIsCustom(companyName, uid string, isGroup bool) (isCustomer,
 	return
 }
 
+// 预编译正则表达式提升性能
+var phoneRegex = regexp.MustCompile(`^1[3-9]\d{9}$`)
+
+func ValidatePhone(phone string) bool {
+	return phoneRegex.MatchString(phone)
+}
+
 // 修改线索名称
 func ClueTransfer(clueId, changeType, kcType, mainClueId int64, clueName string) (status int, err error) {
 	if changeType == 1 { //电销中修改线索名称
@@ -166,7 +177,7 @@ func ClueTransferDx(clueId, mainClueId int64) (status int, err error) {
 			"account_type": 0,
 			"primary_id":   "",
 		})
-		in1 := entity.JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
+		in1 := entity.JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
 			"clue_id":     clueId,
 			"position_id": common.If(kcPositionId > 0, kcPositionId, -1),
 			"change_type": "退回公海",
@@ -175,7 +186,7 @@ func ClueTransferDx(clueId, mainClueId int64) (status int, err error) {
 			"BCPCID":      common.GetRandom(32),
 			"operator_id": -1,
 		})
-		in2 := entity.JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
+		in2 := entity.JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
 			"clue_id":     clueId,
 			"position_id": common.If(kcPositionId > 0, kcPositionId, -1),
 			"change_type": "移交销售",
@@ -184,7 +195,7 @@ func ClueTransferDx(clueId, mainClueId int64) (status int, err error) {
 			"BCPCID":      common.GetRandom(32),
 			"operator_id": -1,
 		})
-		in3 := entity.JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
+		in3 := entity.JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
 			"clue_id":      clueId,
 			"position_id":  common.If(kcPositionId > 0, kcPositionId, -1),
 			"change_field": "position_id",
@@ -323,8 +334,3 @@ func FindPersonOne(positionId int64) map[string]interface{} {
 	}
 	return (*personData)[0]
 }
-
-func KcUpdateClueName() {
-	//入参   线索id   新线索名称
-
-}

+ 223 - 25
service/updateClueName.go

@@ -2,46 +2,75 @@ package service
 
 import (
 	"app.yhyue.com/moapp/jybase/common"
+	"app.yhyue.com/moapp/jybase/date"
 	"bp.jydev.jianyu360.cn/BaseService/biService/entity"
 	"bp.jydev.jianyu360.cn/BaseService/biService/rpc/pb"
+	"database/sql"
 	"errors"
+	"go.mongodb.org/mongo-driver/bson"
+	"log"
 	"time"
 )
 
+type RelatedClue struct {
+	ClueId       int64
+	CompanyName  string
+	EntId        int64
+	KcPositionId int64
+	KcName       string
+	MainCusId    int64
+}
+
 func UpdateClueName(in *pb.UpdateCompanyNameReq) error {
 	newIsGroup, _ := CompanyType(in.NewCompanyName)
 	oldIsGroup, _ := CompanyType(in.OldCompanyName)
 
-	mainData := entity.JyBiTidb.FindOne("dwd_f_csm_customer_info", map[string]interface{}{"clue_id": in.MainClueId, "is_transfer": 0, "primary_id": 1}, "", "")
+	mainData := entity.JyBiTidb.FindOne("dwd_f_csm_customer_info", map[string]interface{}{"clue_id": in.MainClueId, "is_transfer": 0, "account_type": 1}, "", "")
 	if mainData == nil || len(*mainData) == 0 {
 		return errors.New("主账号没有移交客成")
 	}
 	mainCusId := common.Int64All((*mainData)["id"])
+	mainKcPositionId := common.Int64All((*mainData)["position_id"])
+	mainKcName := common.InterfaceToStr((*mainData)["name"])
 	//把主账号、子账号和企业组织架构免费账号修改线索名称
 	//更新主账号线索、客成信息
+	nowTime := time.Now().Format("2006-01-02 15:04:05")
 	entity.JyBiTidb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": in.MainClueId}, map[string]interface{}{"cluename": in.NewCompanyName})
 	entity.JyBiTidb.Update("dwd_f_csm_customer_info", map[string]interface{}{"clue_id": in.MainClueId}, map[string]interface{}{"company_name": in.NewCompanyName, "ent_id": in.NewEntId})
+	entity.JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
+		"clue_id":       in.MainClueId,
+		"change_field":  "cluename",
+		"change_type":   "基本信息变更",
+		"old_value":     common.If(in.OldCompanyName != "", in.OldCompanyName, "/"),
+		"new_value":     common.If(in.NewCompanyName != "", in.NewCompanyName, "/"),
+		"createtime":    nowTime,
+		"BCPCID":        common.GetRandom(32),
+		"position_id":   mainKcPositionId,
+		"operator_id":   -1,
+		"change_reason": "主账号修改线索名称",
+	})
 	//子账号和企业组织架构免费账号修改线索名称
 	subAndFreeData := entity.JyBiTidb.SelectBySql("SELECT * FROM dwd_f_csm_customer_info WHERE primary_id = ? AND is_transfer = 0 AND (account_type=2 OR account_type=3)", mainCusId)
 	if subAndFreeData != nil && len(*subAndFreeData) > 0 {
-		nowTime := time.Now().Format("2006-01-02 15:04:05")
 		for _, val := range *subAndFreeData {
 			//更新线索、客成信息
 			kcPositionId := common.Int64All(val["position_id"])
 			subClueId := common.Int64All(val["clue_id"]) //子账号或者企业组织架构免费账号线索id
-			entity.JyBiTidb.UpdateOrDeleteBySql("UPDATE dwd_f_crm_clue_info SET cluename = ? WHERE id = ?", subClueId)
-			entity.JyBiTidb.UpdateOrDeleteBySql("UPDATE dwd_f_csm_customer_info SET company_name = ?,ent_id=? WHERE clue_id = ?")
+			entity.JyBiTidb.UpdateOrDeleteBySql("UPDATE dwd_f_crm_clue_info SET cluename = ? WHERE id = ?", in.NewCompanyName, subClueId)
+			entity.JyBiTidb.UpdateOrDeleteBySql("UPDATE dwd_f_csm_customer_info SET company_name = ?,ent_id=? WHERE clue_id = ?", in.NewCompanyName, in.NewEntId, subClueId)
 			//插入变更记录
 			entity.JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
-				"clue_id":      subClueId,
-				"change_field": "cluename",
-				"change_type":  "基本信息变更",
-				"old_value":    common.If(in.OldCompanyName != "", in.OldCompanyName, "/"),
-				"new_value":    common.If(in.NewCompanyName != "", in.NewCompanyName, "/"),
-				"createtime":   nowTime,
-				"BCPCID":       common.GetRandom(32),
-				"position_id":  kcPositionId,
-				"operator_id":  -1})
+				"clue_id":       subClueId,
+				"change_field":  "cluename",
+				"change_type":   "基本信息变更",
+				"old_value":     common.If(in.OldCompanyName != "", in.OldCompanyName, "/"),
+				"new_value":     common.If(in.NewCompanyName != "", in.NewCompanyName, "/"),
+				"createtime":    nowTime,
+				"BCPCID":        common.GetRandom(32),
+				"position_id":   kcPositionId,
+				"operator_id":   -1,
+				"change_reason": "与主账号线索名称保持一致",
+			})
 		}
 	}
 
@@ -49,32 +78,201 @@ func UpdateClueName(in *pb.UpdateCompanyNameReq) error {
 	if !oldIsGroup {
 		//查非集团免费账号
 		freeData := entity.JyBiTidb.SelectBySql("SELECT * FROM dwd_f_csm_customer_info WHERE primary_id = ? AND account_type = 4 AND is_transfer = 0", mainCusId)
-		if freeData != nil && len(*freeData) > 0 {
+		if freeData != nil && len(*freeData) > 0 { //查企业下是否存在其他主账号存在客成
 			oldOtherCus := entity.JyBiTidb.FindOne("dwd_f_csm_customer_info", map[string]interface{}{"company_name": in.OldCompanyName, "is_transfer": 0, "primary_id": 1}, "", "")
 			if oldOtherCus != nil && len(*oldOtherCus) > 0 {
+				updateMap := map[string]interface{}{
+					"primary_id":   (*oldOtherCus)["id"],
+					"company_name": (*oldOtherCus)["company_name"],
+					"ent_id":       (*oldOtherCus)["ent_id"],
+				}
 				//把非集团免费账号移交另外的主账号下
+				queryMap := map[string]interface{}{
+					"primary_id":   mainCusId,
+					"account_type": 4,
+					"is_transfer":  0,
+				}
+				entity.JyBiTidb.Update("dwd_f_csm_customer_info", queryMap, updateMap)
 
 			} else {
 				//把非集团免费账号移交电销
-				/*data := entity.JyBiTidb.SelectBySql("SELECT * FROM dwd_f_csm_customer_info WHERE primary_id = ? AND is_transfer = 0", mainCusId)
-				if data != nil && len(*data) > 0 {
-					for _, val := range *data {
-						//移交电销
-					}
-				}*/
+				for _, val := range *freeData {
+					//移交电销
+					clueId := common.Int64All(val["clue_id"])
+					kcPositionId := common.Int64All(val["position_id"])
+					kcName := common.InterfaceToStr(val["name"])
+					FreeClueToDx(clueId, kcPositionId, kcName)
+				}
 			}
 		}
 	}
 
-	if !oldIsGroup && !newIsGroup {
+	if !newIsGroup {
 		//把线索名称是新企业名称的线索移交客成
-	}
-
-	if oldIsGroup && !newIsGroup {
-		//关联线索处理
+		//(2)产生1条“成交客户移交”的线索动态,备注:移交至客户成功部;
+		//(3)不加入任务车;
 		//(4)该线索的客户成功经理,由空调整为其关联客户的客户成功经理,并新增1条“客户成功经理变更”的线索动态;
 		//(5)“线索归属”标记为“客户成功部”。
+		newData := entity.JyBiTidb.Find("dwd_f_crm_clue_info", map[string]interface{}{"cluename": in.NewCompanyName, "is_transfer": 0}, "", "", -1, -1)
+		if newData != nil && len(*newData) > 0 {
+			for _, val := range *newData {
+				clueEntity := RelatedClue{
+					ClueId:       common.Int64All(val["id"]),
+					CompanyName:  common.InterfaceToStr(val["cluename"]),
+					EntId:        in.NewEntId,
+					KcPositionId: mainKcPositionId,
+					KcName:       mainKcName,
+					MainCusId:    mainCusId,
+				}
+				clueEntity.RelatedClueToKc()
+			}
+		}
 	}
 
 	return nil
 }
+
+func (rc RelatedClue) RelatedClueToKc() {
+	//判断之前该线索是否移交过客成
+	nowTime := time.Now().Format("2006-01-02 15:04:05")
+	cusData := entity.JyBiTidb.FindOne("dwd_f_csm_customer_info", map[string]interface{}{"clue_id": rc.ClueId}, "is_transfer", "")
+	if cusData != nil && len(*cusData) > 0 { //该线索曾经移交过客成
+		entity.JyBiTidb.Update("dwd_f_csm_customer_info", map[string]interface{}{"clue_id": rc.ClueId}, bson.M{
+			"is_transfer":           0,
+			"is_renewal_protection": 0,
+			"transfertime":          nowTime,
+			"ent_id":                rc.EntId,
+			"company_name":          rc.CompanyName,
+			"position_id":           rc.KcPositionId,
+			"name":                  rc.KcName,
+			"is_admin":              0,
+			"primary_id":            rc.MainCusId,
+			"account_type":          4,
+			"is_task":               0,
+		})
+		entity.JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
+			"clue_id":       rc.ClueId,
+			"position_id":   rc.KcPositionId,
+			"change_type":   "成交客户移交",
+			"new_value":     "移交至客户成功部",
+			"createtime":    nowTime,
+			"BCPCID":        common.GetRandom(32),
+			"operator_id":   -1,
+			"change_reason": "与主账号线索名称保持一致",
+		})
+		entity.JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
+			"clue_id":      rc.ClueId,
+			"position_id":  common.If(rc.KcPositionId > 0, rc.KcPositionId, -1),
+			"change_field": "position_id",
+			"change_type":  "客户成功经理",
+			"old_value":    "/",
+			"new_value":    rc.KcName,
+			"createtime":   nowTime,
+			"BCPCID":       common.GetRandom(32),
+			"operator_id":  -1,
+		})
+		entity.JyBiTidb.Update("dwd_f_crm_clue_info", bson.M{"id": rc.ClueId}, map[string]interface{}{"is_transfer": 1, "updatetime": nowTime})
+
+	} else {
+		saveMap := map[string]interface{}{
+			"clue_id":                   rc.ClueId,
+			"transfertime":              nowTime,
+			"position_id":               rc.KcPositionId,
+			"name":                      rc.KcName,
+			"ent_id":                    rc.EntId,
+			"is_task":                   0,
+			"tasktime":                  nowTime,
+			"taskstatus":                0,
+			"tasksource":                "1",
+			"is_admin":                  0,
+			"relationship_building_way": 1,
+			"inventory_way":             1,
+			"training_way":              1,
+			"is_pre_sales_training":     0,
+			"service_stage":             1,
+			"company_name":              rc.CompanyName,
+			"primary_id":                rc.MainCusId,
+			"account_type":              4,
+		}
+		cId, ok := int64(-1), false
+		if !entity.JyBiTidb.ExecTx("保存客户", func(tx *sql.Tx) bool {
+			cId = entity.JyBiTidb.InsertByTx(tx, "dwd_f_csm_customer_info", saveMap)
+			ok = entity.JyBiTidb.UpdateByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{"id": rc.ClueId}, map[string]interface{}{"is_transfer": 1, "updatetime": nowTime})
+			ok1 := entity.JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+				"clue_id":       rc.ClueId,
+				"position_id":   rc.KcPositionId,
+				"change_type":   "成交客户移交",
+				"new_value":     "移交至客户成功部",
+				"createtime":    nowTime,
+				"BCPCID":        common.GetRandom(32),
+				"operator_id":   -1,
+				"change_reason": "与主账号线索名称保持一致",
+			})
+			ok2 := entity.JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+				"clue_id":      rc.ClueId,
+				"position_id":  common.If(rc.KcPositionId > 0, rc.KcPositionId, -1),
+				"change_field": "position_id",
+				"change_type":  "客户成功经理",
+				"old_value":    "/",
+				"new_value":    rc.KcName,
+				"createtime":   nowTime,
+				"BCPCID":       common.GetRandom(32),
+				"operator_id":  -1,
+			})
+			return cId > -1 && ok && ok1 > -1 && ok2 > -1
+		}) {
+			log.Printf("非集团公司关联线索移交客成失败,线索id:%d", rc.ClueId)
+		}
+	}
+}
+
+func FreeClueToDx(clueId, kcPositionId int64, kcName string) {
+	nowTime := time.Now().Format(date.Date_Full_Layout)
+	updateClueMap := map[string]interface{}{
+		"is_assign":       0,
+		"updatetime":      nowTime,
+		"comeintime_open": nowTime,
+		"position_id":     0,
+		"seatNumber":      "",
+		"is_transfer":     0,
+	}
+
+	entity.JyBiTidb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, updateClueMap)
+	entity.JyBiTidb.Update("dwd_f_csm_customer_info", map[string]interface{}{"clue_id": clueId}, map[string]interface{}{
+		"is_transfer":  1,
+		"position_id":  0,
+		"name":         "",
+		"account_type": 0,
+		"primary_id":   "",
+	})
+	entity.JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
+		"clue_id":     clueId,
+		"position_id": common.If(kcPositionId > 0, kcPositionId, -1),
+		"change_type": "退回公海",
+		"new_value":   "不再是非集团公司成交客户关联线索,移交销售",
+		"createtime":  nowTime,
+		"BCPCID":      common.GetRandom(32),
+		"operator_id": -1,
+	})
+	entity.JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
+		"clue_id":     clueId,
+		"position_id": common.If(kcPositionId > 0, kcPositionId, -1),
+		"change_type": "移交销售",
+		"new_value":   "不再是非集团公司成交客户关联线索,移交销售",
+		"createtime":  nowTime,
+		"BCPCID":      common.GetRandom(32),
+		"operator_id": -1,
+	})
+	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":     kcName,
+		"new_value":     "/",
+		"createtime":    nowTime,
+		"BCPCID":        common.GetRandom(32),
+		"operator_id":   -1,
+		"change_reason": "主账号修改线索名称,该线索原是非集团免费账号",
+	})
+}