util.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 =?)`, 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. if employInfoId > 0 {
  70. employ_info := cm.BaseMysql.SelectBySql(`select id from crm.employ_custom where company_id =(SELECT company_id FROM crm.employ_custom WHERE id =?)`, employCustomId)
  71. if employ_info != nil && len(*employ_info) > 0 {
  72. for _, v := range *employ_info {
  73. employInfoIdArr = append(employInfoIdArr, gconv.Int64(v["id"]))
  74. }
  75. } else {
  76. employCustomIdArr = []int64{employCustomId}
  77. }
  78. }
  79. args, ws := GetInForCommaArr(employCustomIdArr)
  80. args = append(args, entId)
  81. d := cm.BaseMysql.SelectBySql(`select create_person,position_id from crm.custom where employ_custom_id in( `+ws+`) and ent_id =? `, args...)
  82. if d != nil && len(*d) > 0 {
  83. for _, v := range *d {
  84. position_id := gconv.Int64(v["position_id"])
  85. if positionId == position_id {
  86. return 1, ""
  87. }
  88. return -1, fmt.Sprintf("%v已经基于该候选客户创建了客户", v["create_person"])
  89. }
  90. }
  91. }
  92. }
  93. }
  94. return 1, ""
  95. }
  96. //获取sql语句的in操作相关参数
  97. func GetInForCommaArr(ids []int64) ([]interface{}, string) {
  98. args := []interface{}{}
  99. ws := []string{}
  100. for _, v := range ids {
  101. args = append(args, v)
  102. ws = append(ws, "?")
  103. }
  104. return args, strings.Join(ws, ",")
  105. }