util.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package service
  2. import (
  3. "fmt"
  4. "strings"
  5. cm "bp.jydev.jianyu360.cn/CRM/application/api/common"
  6. "github.com/gogf/gf/v2/util/gconv"
  7. )
  8. //CanAdd 是否允许多人针对一个创建
  9. func CanAdd(entId int64, key string, employInfoId, employCustomId int64) (status int64, error_msg string) {
  10. accountData := cm.BaseMysql.SelectBySql(`select * from base_service.base_account where ent_id =? and person_id =0 and type =1 limit 1`, entId)
  11. if accountData == nil || len(*accountData) <= 0 {
  12. return 1, ""
  13. }
  14. accountId := (*accountData)[0]["id"]
  15. //
  16. tenantData := cm.BaseMysql.SelectBySql(`select * from crm.config_tenant where account_id =?`, accountId)
  17. if tenantData == nil || len(*tenantData) <= 0 {
  18. return 1, ""
  19. }
  20. //不允许
  21. if gconv.Int((*tenantData)[0][key]) == 0 {
  22. //判断是否已经创建
  23. if strings.Contains(key, "clue") {
  24. d := cm.BaseMysql.SelectBySql(`select create_person from crm.sale_clue where employ_info_id =? and ent_id =?`, employInfoId, entId)
  25. if d != nil && len(*d) > 0 {
  26. return -1, fmt.Sprintf("%v已经基于该咨询创建了线索", (*d)[0]["create_person"])
  27. }
  28. } else if strings.Contains(key, "chance") {
  29. d := cm.BaseMysql.SelectBySql(`select create_person from crm.sale_chance where employ_info_id =? and ent_id =?`, employInfoId, entId)
  30. if d != nil && len(*d) > 0 {
  31. return -1, fmt.Sprintf("%v已经基于该咨询创建了机会", (*d)[0]["create_person"])
  32. }
  33. } else if strings.Contains(key, "custom") {
  34. if employInfoId > 0 {
  35. d := cm.BaseMysql.SelectBySql(`select create_person from crm.custom where employ_info_id =? and ent_id =?`, employInfoId, entId)
  36. if d != nil && len(*d) > 0 {
  37. return -1, fmt.Sprintf("%v已经基于该咨询创建了客户", (*d)[0]["create_person"])
  38. }
  39. } else if employCustomId > 0 {
  40. d := cm.BaseMysql.SelectBySql(`select create_person from crm.custom where employ_custom_id =? and ent_id =?`, employCustomId, entId)
  41. if d != nil && len(*d) > 0 {
  42. return -1, fmt.Sprintf("%v已经基于该候选客户创建了客户", (*d)[0]["create_person"])
  43. }
  44. }
  45. }
  46. }
  47. return 1, ""
  48. }