util.go 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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, positionId 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. //不允许
  18. if tenantData == nil || gconv.Int((*tenantData)[0][key]) == 0 {
  19. //判断是否已经创建
  20. if strings.Contains(key, "clue") {
  21. d := cm.BaseMysql.SelectBySql(`select create_person,position_id from crm.sale_clue where employ_info_id =? and ent_id =?`, employInfoId, entId)
  22. if d != nil && len(*d) > 0 {
  23. position_id := gconv.Int64((*d)[0]["position_id"])
  24. if positionId == position_id {
  25. return 1, ""
  26. }
  27. return -1, fmt.Sprintf("%v已经基于该咨询创建了线索", (*d)[0]["create_person"])
  28. }
  29. } else if strings.Contains(key, "chance") {
  30. d := cm.BaseMysql.SelectBySql(`select create_person,position_id from crm.sale_chance where employ_info_id =? and ent_id =?`, employInfoId, entId)
  31. if d != nil && len(*d) > 0 {
  32. position_id := gconv.Int64((*d)[0]["position_id"])
  33. if positionId == position_id {
  34. return 1, ""
  35. }
  36. return -1, fmt.Sprintf("%v已经基于该咨询创建了机会", (*d)[0]["create_person"])
  37. }
  38. } else if strings.Contains(key, "custom") {
  39. if employInfoId > 0 {
  40. d := cm.BaseMysql.SelectBySql(`select create_person,position_id from crm.custom where employ_info_id =? and ent_id =?`, employInfoId, entId)
  41. if d != nil && len(*d) > 0 {
  42. position_id := gconv.Int64((*d)[0]["position_id"])
  43. if positionId == position_id {
  44. return 1, ""
  45. }
  46. return -1, fmt.Sprintf("%v已经基于该咨询创建了客户", (*d)[0]["create_person"])
  47. }
  48. } else if employCustomId > 0 {
  49. d := cm.BaseMysql.SelectBySql(`select create_person,position_id from crm.custom where employ_custom_id =? and ent_id =?`, employCustomId, entId)
  50. if d != nil && len(*d) > 0 {
  51. position_id := gconv.Int64((*d)[0]["position_id"])
  52. if positionId == position_id {
  53. return 1, ""
  54. }
  55. return -1, fmt.Sprintf("%v已经基于该候选客户创建了客户", (*d)[0]["create_person"])
  56. }
  57. }
  58. }
  59. }
  60. return 1, ""
  61. }