1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- 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 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 || len(*tenantData) <= 0 {
- return 1, ""
- }
- //不允许
- if gconv.Int((*tenantData)[0][key]) == 0 {
- //判断是否已经创建
- if strings.Contains(key, "clue") {
- d := cm.BaseMysql.SelectBySql(`select create_person from crm.sale_clue where employ_info_id =? and ent_id =?`, employInfoId, entId)
- if d != nil && len(*d) > 0 {
- return -1, fmt.Sprintf("%v已经基于该咨询创建了线索", (*d)[0]["create_person"])
- }
- } else if strings.Contains(key, "chance") {
- d := cm.BaseMysql.SelectBySql(`select create_person from crm.sale_chance where employ_info_id =? and ent_id =?`, employInfoId, entId)
- if d != nil && len(*d) > 0 {
- 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 from crm.custom where employ_info_id =? and ent_id =?`, employInfoId, entId)
- if d != nil && len(*d) > 0 {
- return -1, fmt.Sprintf("%v已经基于该咨询创建了客户", (*d)[0]["create_person"])
- }
- } else if employCustomId > 0 {
- d := cm.BaseMysql.SelectBySql(`select create_person from crm.custom where employ_custom_id =? and ent_id =?`, employCustomId, entId)
- if d != nil && len(*d) > 0 {
- return -1, fmt.Sprintf("%v已经基于该候选客户创建了客户", (*d)[0]["create_person"])
- }
- }
- }
- }
- return 1, ""
- }
|