Jianghan 1 an în urmă
părinte
comite
88f7812011
1 a modificat fișierele cu 12 adăugiri și 17 ștergeri
  1. 12 17
      service/clueByPhone.go

+ 12 - 17
service/clueByPhone.go

@@ -16,7 +16,7 @@ import (
 // @Date 2024/5/28
 func CreateClue(in *pb.CreateCuleReq) (result *pb.BiReply, err error) {
 	info := entity.JyBiTidb.FindOne("dwd_f_userbase_contacts", bson.M{"phone": in.Phone}, "id, baseinfo_id", "")
-	if info == nil && len(*info) == 0 {
+	if info == nil || len(*info) == 0 {
 		return &pb.BiReply{
 			ErrorCode: -1,
 			ErrorMsg:  "手机号不存在",
@@ -24,6 +24,14 @@ func CreateClue(in *pb.CreateCuleReq) (result *pb.BiReply, err error) {
 		}, nil
 	}
 	uId := common.ObjToString((*info)["baseinfo_id"])
+	clueInfo := entity.JyBiTidb.FindOne("dwd_f_crm_clue_info", bson.M{"uid": uId}, "", "")
+	if clueInfo == nil || len(*clueInfo) == 0 {
+		return &pb.BiReply{
+			ErrorCode: -1,
+			ErrorMsg:  "线索已经存在",
+			Data:      nil,
+		}, nil
+	}
 	isGroup, isCommerce := CompanyType(in.Phone) //判断是否集团公司、工商库
 	clueId := int64(0)
 	if entity.JyBiTidb.ExecTx("保存线索", func(tx *sql.Tx) bool {
@@ -40,15 +48,14 @@ func CreateClue(in *pb.CreateCuleReq) (result *pb.BiReply, err error) {
 			"trailstatus":          "01",
 			"name":                 in.Phone,
 			"phone":                in.Phone,
-			"is_task":              0,
-			"taskstatus":           0,
 			"company_nature":       isGroup,
 			"company_verification": isCommerce,
+			"comeintime_open":      nowTime,
 			"FREEZE_TIME":          nowTime,
 		})
 		uodateId1 := entity.JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
 			"clue_id":       clueId,
-			"position_id":   in.PositionId,
+			"position_id":   -1,
 			"change_type":   "创建线索",
 			"new_value":     "系统自动创建",
 			"createtime":    nowTime,
@@ -56,19 +63,7 @@ func CreateClue(in *pb.CreateCuleReq) (result *pb.BiReply, err error) {
 			"operator_id":   -1,
 			"change_reason": "根据手机号创建线索(接口)",
 		})
-		uodateId2 := entity.JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
-			"clue_id":       clueId,
-			"position_id":   in.PositionId,
-			"change_field":  "trailstatus",
-			"change_type":   "基本信息变更",
-			"old_value":     "商机线索",
-			"new_value":     "新增",
-			"createtime":    nowTime,
-			"BCPCID":        common.GetRandom(32),
-			"operator_id":   -1,
-			"change_reason": "根据手机号创建线索(接口)",
-		})
-		return clueId > -1 && uodateId1 > -1 && uodateId2 > -1
+		return clueId > -1 && uodateId1 > -1
 	}) {
 		return &pb.BiReply{
 			ErrorCode: 0,