|
@@ -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
|