zhangxinlei1996 1 жил өмнө
parent
commit
e155d51a6f

+ 22 - 11
service/custom.go

@@ -142,6 +142,7 @@ func (this *CustomService) Add(ctx context.Context) (int64, string) {
 }
 
 //
+
 func SaleCustomAdd(tx *sql.Tx, args []interface{}) int64 {
 	fields := []string{"position_id", "ent_id", "ent_user_id", "employ_info_id", "employ_custom_id", "type", "full_name", "sort_name", "summary", "level", "industry", "subdivision_industry", "province", "city", "county", "address", "phone", "remark", "create_person", "create_time"}
 	_, id := cm.CrmMysql.InsertBatchByTx(tx, entity.CUSTOM, fields, args)
@@ -149,8 +150,8 @@ func SaleCustomAdd(tx *sql.Tx, args []interface{}) int64 {
 }
 
 //EmployUpdate 是否创建线索/机会/客户修改
-func EmployUpdate(tx *sql.Tx, employ_info_id, employ_custom_id, positionId int64, key string, entId, entUserId, entDeptId int64) bool {
-	ok := true
+//return employ_info_id,employ_custom_id
+func EmployUpdate(tx *sql.Tx, employ_info_id, employ_custom_id, positionId int64, key string, entId, entUserId, entDeptId int64) (int64, int64) {
 	tablename := ""
 	id := int64(0)
 	if employ_custom_id > 0 {
@@ -161,7 +162,7 @@ func EmployUpdate(tx *sql.Tx, employ_info_id, employ_custom_id, positionId int64
 		id = employ_info_id
 	}
 	if tablename == "" || id == 0 {
-		return ok
+		return employ_info_id, employ_custom_id
 	}
 	//判断该条信息是不是当前资讯分配员的
 	d := cm.CrmMysql.SelectBySqlByTx(tx, fmt.Sprintf(`select * from %v where id = ?`, tablename), id)
@@ -169,14 +170,13 @@ func EmployUpdate(tx *sql.Tx, employ_info_id, employ_custom_id, positionId int64
 		data := (*d)[0]
 		position_id := gconv.Int64(data["position_id"])
 		if position_id == positionId {
-			return cm.CrmMysql.UpdateByTx(tx, tablename, map[string]interface{}{"id": id, "position_id": positionId}, map[string]interface{}{key: 1})
+			cm.CrmMysql.UpdateByTx(tx, tablename, map[string]interface{}{"id": id, "position_id": positionId}, map[string]interface{}{key: 1})
 		} else {
 			//判断是否已创建该条,但是是取消收录状态、如果是则改为已收录,不是则创建一条新的
-			//TODO
 			d2 := cm.CrmMysql.SelectBySqlByTx(tx, fmt.Sprintf(`select * from %v where source_id = ? and position_id =?`, tablename), data["source_id"], positionId)
 			if d2 != nil && len(*d2) > 0 {
 				//已创建
-				return cm.CrmMysql.UpdateByTx(tx, tablename, map[string]interface{}{
+				cm.CrmMysql.UpdateByTx(tx, tablename, map[string]interface{}{
 					"source_id":   data["source_id"],
 					"position_id": positionId,
 				}, map[string]interface{}{
@@ -205,11 +205,16 @@ func EmployUpdate(tx *sql.Tx, employ_info_id, employ_custom_id, positionId int64
 					}
 				}
 				delete(data, "id")
-				return cm.CrmMysql.InsertByTx(tx, tablename, data) > 0
+				newId := cm.CrmMysql.InsertByTx(tx, tablename, data)
+				if tablename == entity.EMPLOY_INFO {
+					employ_info_id = newId
+				} else if tablename == entity.EMPLOY_CUSTOM {
+					employ_custom_id = newId
+				}
 			}
 		}
 	}
-	return ok
+	return employ_info_id, employ_custom_id
 }
 
 func SaveCustom(ctx context.Context, argsCustom, argsTask, argsTaskTeam []interface{}, employ_info_id, employ_custom_id, positionId int64, createPerson string, transferArr []int64, entId, entUserId, entDeptId int64) (int64, int64) {
@@ -217,19 +222,25 @@ func SaveCustom(ctx context.Context, argsCustom, argsTask, argsTaskTeam []interf
 	taskId := int64(-1)
 	//存库
 	cm.CrmMysql.ExecTx("创建客户", func(tx *sql.Tx) bool {
+		//修改状态
+		employ_info_id_new, employ_custom_id_new := EmployUpdate(tx, employ_info_id, employ_custom_id, positionId, "is_create_custom", entId, entUserId, entDeptId)
 		//插入客户
+
+		//修改客户id、咨询id
+		argsCustom[3] = employ_info_id_new
+		argsCustom[4] = employ_custom_id_new
+
 		customId = SaleCustomAdd(tx, argsCustom)
 		//传过来的argTask没有来源id,需要append
 		argsTask = append(argsTask, customId)
 		//任务车存储
 		taskId = TaskAdd(tx, argsTask, argsTaskTeam, transferArr, positionId)
-		ok := EmployUpdate(tx, employ_info_id, employ_custom_id, positionId, "is_create_custom", entId, entUserId, entDeptId)
 		//插入台账
 		ok2 := SaveLedger(ctx, positionId, customId, taskId, "创建客户", fmt.Sprintf("%s创建了客户", createPerson), createPerson)
-		if customId > 0 && taskId > 0 && ok && ok2 {
+		if customId > 0 && taskId > 0 && ok2 {
 			return true
 		}
-		log.Println("SaveCustom err:", customId, taskId, ok)
+		log.Println("SaveCustom err:", customId, taskId)
 		return false
 	})
 	return customId, taskId

+ 8 - 4
service/sale_chance.go

@@ -158,6 +158,12 @@ func SaveChange(ctx context.Context, argsChange, argsTask, argsTaskTeam []interf
 	//存库
 	changeId, taskId := int64(-1), int64(-1)
 	cm.CrmMysql.ExecTx("创建机会", func(tx *sql.Tx) bool {
+		//
+		employ_info_id_new, employ_custom_id_new := EmployUpdate(tx, employ_info_id, employ_custom_id, positionId, "is_create_chance", entId, entUserId, entDeptId)
+
+		argsChange[3] = employ_info_id_new
+		argsChange[4] = employ_custom_id_new
+
 		//插入机会
 		changeId = SaleChangeAdd(tx, argsChange)
 		//传过来的argTask没有来源id,需要append
@@ -166,14 +172,12 @@ func SaveChange(ctx context.Context, argsChange, argsTask, argsTaskTeam []interf
 		taskId = TaskAdd(tx, argsTask, argsTaskTeam, transferArr, positionId)
 		//操作台帐
 		ok1 := SaveLedger(ctx, positionId, changeId, taskId, "创建销售机会", fmt.Sprintf("%s创建了销售机会", createName), createName)
-		//是否创建销售计划
-		ok2 := EmployUpdate(tx, employ_info_id, 0, positionId, "is_create_chance", entId, entUserId, entDeptId)
 		//任务执行计划
 		planId := TaskExecutePlanAdd(tx, tplId, taskId)
-		if changeId > 0 && taskId > 0 && ok1 && ok2 && planId > 0 {
+		if changeId > 0 && taskId > 0 && ok1 && planId > 0 {
 			return true
 		}
-		log.Println("save change err: ", changeId, taskId, ok1, ok2, planId)
+		log.Println("save change err: ", changeId, taskId, ok1, planId)
 		return false
 	})
 

+ 5 - 4
service/sale_clue.go

@@ -169,20 +169,21 @@ func Save(ctx context.Context, argsClue, argsTask, argsTaskTeam []interface{}, e
 	clueId, taskId := int64(-1), int64(-1)
 	//存库
 	cm.CrmMysql.ExecTx("创建线索", func(tx *sql.Tx) bool {
+		//是否创建销售线索
+		employ_info_id_new, _ := EmployUpdate(tx, employ_info_id, employ_custom_id, positionId, "is_create_clue", entId, entUserId, entDeptId)
 		//插入线索
+		argsClue[6] = employ_info_id_new
 		clueId = SaleClueAdd(tx, argsClue)
 		//传过来的argTask没有来源id,需要append
 		argsTask = append(argsTask, clueId)
 		//任务车存储
 		taskId = TaskAdd(tx, argsTask, argsTaskTeam, transferArr, positionId)
-		//是否创建销售线索
-		ok1 := EmployUpdate(tx, employ_info_id, employ_custom_id, positionId, "is_create_clue", entId, entUserId, entDeptId)
 		//操作台帐
 		ok2 := SaveLedger(ctx, positionId, clueId, taskId, "创建销售线索", fmt.Sprintf("%s创建了销售线索", createName), createName)
-		if clueId > 0 && taskId > 0 && ok1 && ok2 {
+		if clueId > 0 && taskId > 0 && ok2 {
 			return true
 		}
-		log.Println("save clue err: ", clueId, taskId, ok1, ok2)
+		log.Println("save clue err: ", clueId, taskId, ok2)
 		return false
 	})
 	return clueId, taskId