Browse Source

电销修改线索名称移交客成

renjiaojiao 2 ngày trước cách đây
mục cha
commit
cd8a5f34b7

+ 5 - 2
api/biService.api

@@ -176,8 +176,11 @@ type (
 	}
 
 	ClueTransferReq {
-		ClueId   int64  `json:"clueId"`
-		ClueName string `json:"clueName"`
+		ClueId     int64  `json:"clueId"`
+		ClueName   string `json:"clueName"`
+		ChangeType int64  `json:"changeType,optional"`
+		KcType     int64  `json:"kcType,optional"`
+		MainClueId int64  `json:"mainClueId,optional"`
 	}
 )
 

+ 5 - 2
api/internal/logic/cluetransferlogic.go

@@ -28,8 +28,11 @@ func NewClueTransferLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Clue
 func (l *ClueTransferLogic) ClueTransfer(req *types.ClueTransferReq) (resp *types.BiResp, err error) {
 	// todo: add your logic here and delete this line
 	res, err := l.svcCtx.BiServiceRpc.ClueTransfer(l.ctx, &pb.ClueTransferReq{
-		ClueId:   req.ClueId,
-		ClueName: req.ClueName,
+		ClueId:     req.ClueId,
+		ClueName:   req.ClueName,
+		ChangeType: req.ChangeType,
+		KcType:     req.KcType,
+		MainClueId: req.MainClueId,
 	})
 	log.Println("rpc返回:", res)
 	return &types.BiResp{Error_code: res.ErrorCode, Error_msg: res.ErrorMsg}, err

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

@@ -200,6 +200,9 @@ type MaterialSaveReq struct {
 }
 
 type ClueTransferReq struct {
-	ClueId   int64  `json:"clueId"`
-	ClueName string `json:"clueName"`
+	ClueId     int64  `json:"clueId"`
+	ClueName   string `json:"clueName"`
+	ChangeType int64  `json:"changeType,optional"`
+	KcType     int64  `json:"kcType,optional"`
+	MainClueId int64  `json:"mainClueId,optional"`
 }

+ 1 - 1
rpc/biService.proto

@@ -290,7 +290,7 @@ message ClueTransferReq {
   int64 clueId = 1;
   string clueName = 2;
   int64 changeType = 3; //1:电销修改名称 2:客成中修改名称
-  int64 status = 4; //1:回电销  2:移客成
+  int64 kcType = 4; //1:回电销  2:移客成
   int64 mainClueId = 5; //原所在企业/个人主账号
 }
 

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

@@ -26,7 +26,7 @@ func NewClueTransferLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Clue
 
 func (l *ClueTransferLogic) ClueTransfer(in *pb.ClueTransferReq) (*pb.BiResp, error) {
 	// todo: add your logic here and delete this line
-	status, err := service.ClueTransfer(in.ClueId, in.ChangeType, in.ClueName)
+	status, err := service.ClueTransfer(in.ClueId, in.ChangeType, in.KcType, in.MainClueId, in.ClueName)
 	return &pb.BiResp{
 		ErrorCode: int64(status),
 		ErrorMsg:  err.Error(),

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

@@ -2979,7 +2979,7 @@ type ClueTransferReq struct {
 	ClueId     int64  `protobuf:"varint,1,opt,name=clueId,proto3" json:"clueId,omitempty"`
 	ClueName   string `protobuf:"bytes,2,opt,name=clueName,proto3" json:"clueName,omitempty"`
 	ChangeType int64  `protobuf:"varint,3,opt,name=changeType,proto3" json:"changeType,omitempty"` //1:电销修改名称 2:客成中修改名称
-	Status     int64  `protobuf:"varint,4,opt,name=status,proto3" json:"status,omitempty"`         //1:回电销  2:移客成
+	KcType     int64  `protobuf:"varint,4,opt,name=kcType,proto3" json:"kcType,omitempty"`         //1:回电销  2:移客成
 	MainClueId int64  `protobuf:"varint,5,opt,name=mainClueId,proto3" json:"mainClueId,omitempty"` //原所在企业/个人主账号
 }
 
@@ -3036,9 +3036,9 @@ func (x *ClueTransferReq) GetChangeType() int64 {
 	return 0
 }
 
-func (x *ClueTransferReq) GetStatus() int64 {
+func (x *ClueTransferReq) GetKcType() int64 {
 	if x != nil {
-		return x.Status
+		return x.KcType
 	}
 	return 0
 }
@@ -3415,8 +3415,8 @@ var file_biService_proto_rawDesc = []byte{
 	0x4e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x63, 0x6c, 0x75, 0x65,
 	0x4e, 0x61, 0x6d, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x54, 0x79,
 	0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0a, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65,
-	0x54, 0x79, 0x70, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x04,
-	0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1e, 0x0a, 0x0a,
+	0x54, 0x79, 0x70, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x6b, 0x63, 0x54, 0x79, 0x70, 0x65, 0x18, 0x04,
+	0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x6b, 0x63, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, 0x0a,
 	0x6d, 0x61, 0x69, 0x6e, 0x43, 0x6c, 0x75, 0x65, 0x49, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x03,
 	0x52, 0x0a, 0x6d, 0x61, 0x69, 0x6e, 0x43, 0x6c, 0x75, 0x65, 0x49, 0x64, 0x32, 0xb4, 0x09, 0x0a,
 	0x09, 0x42, 0x69, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x30, 0x0a, 0x0b, 0x6d, 0x79,

+ 83 - 32
service/custom.go

@@ -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 != ""`)