Jelajahi Sumber

feat: 创建判断是否允许多人

zhangxinlei1996 1 tahun lalu
induk
melakukan
43cee513a2

+ 11 - 3
api/internal/logic/clueaddlogic.go

@@ -44,11 +44,19 @@ func (l *ClueAddLogic) ClueAdd(req *types.ClueAddReq) (resp *types.Reply, err er
 		BaseUserId:   req.BaseUserId,
 		EntDeptId:    req.EntDeptId,
 	}
-	status, groupId := clue.Add(l.ctx)
+	status, error_msg := service.CanAdd(req.EntId, "more_create_clue", req.EmployInfoId, 0)
+	if status <= 0 {
+		resp.Error_code = -1
+		resp.Error_msg = error_msg
+		resp.Data = map[string]interface{}{
+			"status": -1,
+		}
+		return
+	}
+	status, _ = clue.Add(l.ctx)
 
 	resp.Data = map[string]interface{}{
-		"status":  status,
-		"groupId": groupId,
+		"status": status,
 	}
 	return
 }

+ 12 - 3
api/internal/logic/customaddlogic.go

@@ -55,10 +55,19 @@ func (l *CustomAddLogic) CustomAdd(req *types.CustomAddReq) (resp *types.Reply,
 		Remarks:              req.Remarks,              //备注
 		CreateName:           req.CreateName,           //创建人
 	}
-	status, groupId := custom.Add(l.ctx)
+
+	status, error_msg := service.CanAdd(req.EntId, "more_create_custom", req.EmployInfoId, req.EmployCustomId)
+	if status <= 0 {
+		resp.Error_code = -1
+		resp.Error_msg = error_msg
+		resp.Data = map[string]interface{}{
+			"status": -1,
+		}
+		return
+	}
+	status, _ = custom.Add(l.ctx)
 	resp.Data = map[string]interface{}{
-		"status":  status,
-		"groupId": groupId,
+		"status": status,
 	}
 	return
 }

+ 13 - 3
api/internal/logic/salechanceaddlogic.go

@@ -50,11 +50,21 @@ func (l *SaleChanceAddLogic) SaleChanceAdd(req *types.SaleChanceReq) (resp *type
 		CustomId:          req.CustomId,          //客户id
 		CreateName:        req.CreateName,
 	}
-	status, groupId := chance.Add(l.ctx)
+
+	status, error_msg := service.CanAdd(req.EntId, "more_create_chance", req.EmployInfoId, req.CustomId)
+	if status <= 0 {
+		resp.Error_code = -1
+		resp.Error_msg = error_msg
+		resp.Data = map[string]interface{}{
+			"status": -1,
+		}
+		return
+	}
+
+	status, _ = chance.Add(l.ctx)
 
 	resp.Data = map[string]interface{}{
-		"status":  status,
-		"groupId": groupId,
+		"status": status,
 	}
 	return
 }

+ 53 - 0
service/util.go

@@ -0,0 +1,53 @@
+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, ""
+}