12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- package service
- import (
- "fmt"
- "strings"
- cm "bp.jydev.jianyu360.cn/CRM/application/api/common"
- "github.com/gogf/gf/v2/util/gconv"
- )
- //CanAdd 是否允许多人针对一个创建
- func CanAdd(entId int64, key string, employInfoId, employCustomId, positionId int64) (status int64, error_msg string) {
- accountData := cm.BaseMysql.SelectBySql(`select * from base_service.base_account where ent_id =? and person_id =0 and type =1 limit 1`, entId)
- if accountData == nil || len(*accountData) <= 0 {
- return 1, ""
- }
- accountId := (*accountData)[0]["id"]
- //
- tenantData := cm.BaseMysql.SelectBySql(`select * from crm.config_tenant where account_id =?`, accountId)
- //不允许
- if tenantData == nil || gconv.Int((*tenantData)[0][key]) == 0 {
- //判断是否已经创建
- 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)
- if d != nil && len(*d) > 0 {
- position_id := gconv.Int64((*d)[0]["position_id"])
- if positionId == position_id {
- return 1, ""
- }
- return -1, fmt.Sprintf("%v已经基于该咨询创建了线索", (*d)[0]["create_person"])
- }
- } 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)
- if d != nil && len(*d) > 0 {
- position_id := gconv.Int64((*d)[0]["position_id"])
- if positionId == position_id {
- return 1, ""
- }
- return -1, fmt.Sprintf("%v已经基于该咨询创建了机会", (*d)[0]["create_person"])
- }
- } else if strings.Contains(key, "custom") {
- if employInfoId > 0 {
- d := cm.BaseMysql.SelectBySql(`select create_person,position_id from crm.custom where employ_info_id =? and ent_id =?`, employInfoId, entId)
- if d != nil && len(*d) > 0 {
- position_id := gconv.Int64((*d)[0]["position_id"])
- if positionId == position_id {
- return 1, ""
- }
- return -1, fmt.Sprintf("%v已经基于该咨询创建了客户", (*d)[0]["create_person"])
- }
- } 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)
- if d != nil && len(*d) > 0 {
- position_id := gconv.Int64((*d)[0]["position_id"])
- if positionId == position_id {
- return 1, ""
- }
- return -1, fmt.Sprintf("%v已经基于该候选客户创建了客户", (*d)[0]["create_person"])
- }
- }
- }
- }
- return 1, ""
- }
|