|
@@ -17,47 +17,80 @@ func CanAdd(entId int64, key string, employInfoId, employCustomId, positionId in
|
|
accountId := (*accountData)[0]["id"]
|
|
accountId := (*accountData)[0]["id"]
|
|
//
|
|
//
|
|
tenantData := cm.BaseMysql.SelectBySql(`select * from crm.config_tenant where account_id =?`, accountId)
|
|
tenantData := cm.BaseMysql.SelectBySql(`select * from crm.config_tenant where account_id =?`, accountId)
|
|
-
|
|
|
|
//不允许
|
|
//不允许
|
|
if (len(*tenantData) == 0) || (len(*tenantData) > 0 && gconv.Int((*tenantData)[0][key]) == 0) {
|
|
if (len(*tenantData) == 0) || (len(*tenantData) > 0 && gconv.Int((*tenantData)[0][key]) == 0) {
|
|
|
|
+ employInfoIdArr := []int64{}
|
|
|
|
+ if employInfoId > 0 {
|
|
|
|
+ employ_info := cm.BaseMysql.SelectBySql(`select id from crm.employ_info where source_id =(SELECT source_id FROM crm.employ_info WHERE id =?)`, employInfoId)
|
|
|
|
+ if employ_info != nil && len(*employ_info) > 0 {
|
|
|
|
+ for _, v := range *employ_info {
|
|
|
|
+ employInfoIdArr = append(employInfoIdArr, gconv.Int64(v["id"]))
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ employInfoIdArr = []int64{employInfoId}
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ args, ws := GetInForCommaArr(employInfoIdArr)
|
|
|
|
+ args = append(args, entId)
|
|
//判断是否已经创建
|
|
//判断是否已经创建
|
|
if strings.Contains(key, "clue") {
|
|
if strings.Contains(key, "clue") {
|
|
- d := cm.BaseMysql.SelectBySql(`select create_person,position_id from crm.sale_clue where employ_info_id =? and ent_id =?`, employInfoId, entId)
|
|
|
|
|
|
+ d := cm.BaseMysql.SelectBySql(`select create_person,position_id from crm.sale_clue where employ_info_id in( `+ws+`) and ent_id =? and is_close=0`, args...)
|
|
if d != nil && len(*d) > 0 {
|
|
if d != nil && len(*d) > 0 {
|
|
- position_id := gconv.Int64((*d)[0]["position_id"])
|
|
|
|
- if positionId == position_id {
|
|
|
|
- return 1, ""
|
|
|
|
|
|
+ for _, v := range *d {
|
|
|
|
+ position_id := gconv.Int64(v["position_id"])
|
|
|
|
+ if positionId == position_id {
|
|
|
|
+ return 1, ""
|
|
|
|
+ }
|
|
|
|
+ return -1, fmt.Sprintf("%v已经基于该咨询创建了线索", v["create_person"])
|
|
}
|
|
}
|
|
- return -1, fmt.Sprintf("%v已经基于该咨询创建了线索", (*d)[0]["create_person"])
|
|
|
|
}
|
|
}
|
|
|
|
|
|
} else if strings.Contains(key, "chance") {
|
|
} else if strings.Contains(key, "chance") {
|
|
- d := cm.BaseMysql.SelectBySql(`select create_person,position_id from crm.sale_chance where employ_info_id =? and ent_id =?`, employInfoId, entId)
|
|
|
|
|
|
+ d := cm.BaseMysql.SelectBySql(`select create_person,position_id from crm.sale_chance where employ_info_id in ( `+ws+`) and ent_id =? `, args...)
|
|
if d != nil && len(*d) > 0 {
|
|
if d != nil && len(*d) > 0 {
|
|
- position_id := gconv.Int64((*d)[0]["position_id"])
|
|
|
|
- if positionId == position_id {
|
|
|
|
- return 1, ""
|
|
|
|
|
|
+ for _, v := range *d {
|
|
|
|
+ position_id := gconv.Int64(v["position_id"])
|
|
|
|
+ if positionId == position_id {
|
|
|
|
+ return 1, ""
|
|
|
|
+ }
|
|
|
|
+ return -1, fmt.Sprintf("%v已经基于该咨询创建了机会", v["create_person"])
|
|
}
|
|
}
|
|
- return -1, fmt.Sprintf("%v已经基于该咨询创建了机会", (*d)[0]["create_person"])
|
|
|
|
}
|
|
}
|
|
} else if strings.Contains(key, "custom") {
|
|
} else if strings.Contains(key, "custom") {
|
|
if employInfoId > 0 {
|
|
if employInfoId > 0 {
|
|
- d := cm.BaseMysql.SelectBySql(`select create_person,position_id from crm.custom where employ_info_id =? and ent_id =?`, employInfoId, entId)
|
|
|
|
|
|
+ d := cm.BaseMysql.SelectBySql(`select create_person,position_id from crm.custom where employ_info_id in( `+ws+`) and ent_id =? `, args...)
|
|
if d != nil && len(*d) > 0 {
|
|
if d != nil && len(*d) > 0 {
|
|
- position_id := gconv.Int64((*d)[0]["position_id"])
|
|
|
|
- if positionId == position_id {
|
|
|
|
- return 1, ""
|
|
|
|
|
|
+ for _, v := range *d {
|
|
|
|
+ position_id := gconv.Int64(v["position_id"])
|
|
|
|
+ if positionId == position_id {
|
|
|
|
+ return 1, ""
|
|
|
|
+ }
|
|
|
|
+ return -1, fmt.Sprintf("%v已经基于该咨询创建了客户", v["create_person"])
|
|
}
|
|
}
|
|
- return -1, fmt.Sprintf("%v已经基于该咨询创建了客户", (*d)[0]["create_person"])
|
|
|
|
}
|
|
}
|
|
} else if employCustomId > 0 {
|
|
} else if employCustomId > 0 {
|
|
- d := cm.BaseMysql.SelectBySql(`select create_person,position_id from crm.custom where employ_custom_id =? and ent_id =?`, employCustomId, entId)
|
|
|
|
|
|
+ employCustomIdArr := []int64{}
|
|
|
|
+ if employInfoId > 0 {
|
|
|
|
+ employ_info := cm.BaseMysql.SelectBySql(`select id from crm.employ_custom where company_id =(SELECT company_id FROM crm.employ_custom WHERE id =?)`, employCustomId)
|
|
|
|
+ if employ_info != nil && len(*employ_info) > 0 {
|
|
|
|
+ for _, v := range *employ_info {
|
|
|
|
+ employInfoIdArr = append(employInfoIdArr, gconv.Int64(v["id"]))
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ employCustomIdArr = []int64{employCustomId}
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ args, ws := GetInForCommaArr(employCustomIdArr)
|
|
|
|
+ args = append(args, entId)
|
|
|
|
+ d := cm.BaseMysql.SelectBySql(`select create_person,position_id from crm.custom where employ_custom_id in( `+ws+`) and ent_id =? `, args...)
|
|
if d != nil && len(*d) > 0 {
|
|
if d != nil && len(*d) > 0 {
|
|
- position_id := gconv.Int64((*d)[0]["position_id"])
|
|
|
|
- if positionId == position_id {
|
|
|
|
- return 1, ""
|
|
|
|
|
|
+ for _, v := range *d {
|
|
|
|
+ position_id := gconv.Int64(v["position_id"])
|
|
|
|
+ if positionId == position_id {
|
|
|
|
+ return 1, ""
|
|
|
|
+ }
|
|
|
|
+ return -1, fmt.Sprintf("%v已经基于该候选客户创建了客户", v["create_person"])
|
|
}
|
|
}
|
|
- return -1, fmt.Sprintf("%v已经基于该候选客户创建了客户", (*d)[0]["create_person"])
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -65,3 +98,14 @@ func CanAdd(entId int64, key string, employInfoId, employCustomId, positionId in
|
|
|
|
|
|
return 1, ""
|
|
return 1, ""
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+//获取sql语句的in操作相关参数
|
|
|
|
+func GetInForCommaArr(ids []int64) ([]interface{}, string) {
|
|
|
|
+ args := []interface{}{}
|
|
|
|
+ ws := []string{}
|
|
|
|
+ for _, v := range ids {
|
|
|
|
+ args = append(args, v)
|
|
|
|
+ ws = append(ws, "?")
|
|
|
|
+ }
|
|
|
|
+ return args, strings.Join(ws, ",")
|
|
|
|
+}
|