util.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 (len(*tenantData) == 0) || (len(*tenantData) > 0 && gconv.Int((*tenantData)[0][key]) == 0) {
  19. employInfoIdArr := []int64{}
  20. if employInfoId > 0 {
  21. employ_info := cm.BaseMysql.SelectBySql(`select id from crm.employ_info where source_id =(SELECT source_id FROM crm.employ_info WHERE id =?) and status=1`, employInfoId)
  22. if employ_info != nil && len(*employ_info) > 0 {
  23. for _, v := range *employ_info {
  24. employInfoIdArr = append(employInfoIdArr, gconv.Int64(v["id"]))
  25. }
  26. } else {
  27. employInfoIdArr = []int64{employInfoId}
  28. }
  29. }
  30. args, ws := GetInForCommaArr(employInfoIdArr)
  31. args = append(args, entId)
  32. //判断是否已经创建
  33. if strings.Contains(key, "clue") {
  34. 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...)
  35. if d != nil && len(*d) > 0 {
  36. for _, v := range *d {
  37. position_id := gconv.Int64(v["position_id"])
  38. if positionId == position_id {
  39. return 1, ""
  40. }
  41. return -1, fmt.Sprintf("%v已经基于该咨询创建了线索", v["create_person"])
  42. }
  43. }
  44. } else if strings.Contains(key, "chance") {
  45. d := cm.BaseMysql.SelectBySql(`select create_person,position_id from crm.sale_chance where employ_info_id in ( `+ws+`) and ent_id =? `, args...)
  46. if d != nil && len(*d) > 0 {
  47. for _, v := range *d {
  48. position_id := gconv.Int64(v["position_id"])
  49. if positionId == position_id {
  50. return 1, ""
  51. }
  52. return -1, fmt.Sprintf("%v已经基于该咨询创建了机会", v["create_person"])
  53. }
  54. }
  55. } else if strings.Contains(key, "custom") {
  56. if employInfoId > 0 {
  57. d := cm.BaseMysql.SelectBySql(`select create_person,position_id from crm.custom where employ_info_id in( `+ws+`) and ent_id =? `, args...)
  58. if d != nil && len(*d) > 0 {
  59. for _, v := range *d {
  60. position_id := gconv.Int64(v["position_id"])
  61. if positionId == position_id {
  62. return 1, ""
  63. }
  64. return -1, fmt.Sprintf("%v已经基于该咨询创建了客户", v["create_person"])
  65. }
  66. }
  67. } else if employCustomId > 0 {
  68. employCustomIdArr := []int64{}
  69. employ_info := cm.BaseMysql.SelectBySql(`select id from crm.employ_custom where company_id =(SELECT company_id FROM crm.employ_custom WHERE id =?)`, employCustomId)
  70. if employ_info != nil && len(*employ_info) > 0 {
  71. for _, v := range *employ_info {
  72. employCustomIdArr = append(employCustomIdArr, gconv.Int64(v["id"]))
  73. }
  74. } else {
  75. employCustomIdArr = []int64{employCustomId}
  76. }
  77. args, ws := GetInForCommaArr(employCustomIdArr)
  78. args = append(args, entId)
  79. d := cm.BaseMysql.SelectBySql(`select create_person,position_id from crm.custom where employ_custom_id in( `+ws+`) and ent_id =? `, args...)
  80. if d != nil && len(*d) > 0 {
  81. for _, v := range *d {
  82. position_id := gconv.Int64(v["position_id"])
  83. if positionId == position_id {
  84. return 1, ""
  85. }
  86. return -1, fmt.Sprintf("%v已经基于该候选客户创建了客户", v["create_person"])
  87. }
  88. }
  89. }
  90. }
  91. }
  92. return 1, ""
  93. }
  94. //获取sql语句的in操作相关参数
  95. func GetInForCommaArr(ids []int64) ([]interface{}, string) {
  96. args := []interface{}{}
  97. ws := []string{}
  98. for _, v := range ids {
  99. args = append(args, v)
  100. ws = append(ws, "?")
  101. }
  102. return args, strings.Join(ws, ",")
  103. }