Browse Source

feat: 创建前状态判断

zhangxinlei1996 1 year ago
parent
commit
10cc13f3f2

+ 1 - 1
api/internal/logic/clueaddlogic.go

@@ -44,7 +44,7 @@ func (l *ClueAddLogic) ClueAdd(req *types.ClueAddReq) (resp *types.Reply, err er
 		BaseUserId:   req.BaseUserId,
 		EntDeptId:    req.EntDeptId,
 	}
-	status, error_msg := service.CanAdd(req.EntId, "more_create_clue", req.EmployInfoId, 0)
+	status, error_msg := service.CanAdd(req.EntId, "more_create_clue", req.EmployInfoId, 0, req.PositionId)
 	if status <= 0 {
 		resp.Error_code = -1
 		resp.Error_msg = error_msg

+ 1 - 1
api/internal/logic/customaddlogic.go

@@ -56,7 +56,7 @@ func (l *CustomAddLogic) CustomAdd(req *types.CustomAddReq) (resp *types.Reply,
 		CreateName:           req.CreateName,           //创建人
 	}
 
-	status, error_msg := service.CanAdd(req.EntId, "more_create_custom", req.EmployInfoId, req.EmployCustomId)
+	status, error_msg := service.CanAdd(req.EntId, "more_create_custom", req.EmployInfoId, req.EmployCustomId, req.PositionId)
 	if status <= 0 {
 		resp.Error_code = -1
 		resp.Error_msg = error_msg

+ 1 - 1
api/internal/logic/salechanceaddlogic.go

@@ -51,7 +51,7 @@ func (l *SaleChanceAddLogic) SaleChanceAdd(req *types.SaleChanceReq) (resp *type
 		CreateName:        req.CreateName,
 	}
 
-	status, error_msg := service.CanAdd(req.EntId, "more_create_chance", req.EmployInfoId, req.CustomId)
+	status, error_msg := service.CanAdd(req.EntId, "more_create_chance", req.EmployInfoId, req.CustomId, req.PositionId)
 	if status <= 0 {
 		resp.Error_code = -1
 		resp.Error_msg = error_msg

+ 1 - 1
service/custom.go

@@ -172,7 +172,7 @@ func EmployUpdate(tx *sql.Tx, employ_info_id, employ_custom_id, positionId int64
 		data := (*d)[0]
 		position_id := gconv.Int64(data["position_id"])
 		if position_id == positionId {
-			cm.CrmMysql.UpdateByTx(tx, tablename, map[string]interface{}{"id": id, "position_id": positionId}, map[string]interface{}{key: 1})
+			cm.CrmMysql.UpdateByTx(tx, tablename, map[string]interface{}{"id": id, "position_id": positionId}, map[string]interface{}{key: 1, "is_handle": 1})
 		} else {
 			//判断是否已创建该条,但是是取消收录状态、如果是则改为已收录,不是则创建一条新的
 			d2 := cm.CrmMysql.SelectBySqlByTx(tx, fmt.Sprintf(`select * from %v where source_id = ? and position_id =?`, tablename), data["source_id"], positionId)

+ 23 - 9
service/util.go

@@ -9,7 +9,7 @@ import (
 )
 
 //CanAdd 是否允许多人针对一个创建
-func CanAdd(entId int64, key string, employInfoId, employCustomId int64) (status int64, error_msg string) {
+func CanAdd(entId int64, key string, employInfoId, employCustomId, positionId 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, ""
@@ -17,32 +17,46 @@ func CanAdd(entId int64, key string, employInfoId, employCustomId int64) (status
 	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 tenantData == nil || 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)
+			d := cm.BaseMysql.SelectBySql(`select create_person,position_id from crm.sale_clue where employ_info_id =? and ent_id =?`, employInfoId, entId)
 			if d != nil && len(*d) > 0 {
+				position_id := gconv.Int64((*d)[0]["position_id"])
+				if positionId == position_id {
+					return 1, ""
+				}
 				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)
+			d := cm.BaseMysql.SelectBySql(`select create_person,position_id from crm.sale_chance where employ_info_id =? and ent_id =?`, employInfoId, entId)
 			if d != nil && len(*d) > 0 {
+				position_id := gconv.Int64((*d)[0]["position_id"])
+				if positionId == position_id {
+					return 1, ""
+				}
 				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)
+				d := cm.BaseMysql.SelectBySql(`select create_person,position_id from crm.custom where employ_info_id =? and ent_id =?`, employInfoId, entId)
 				if d != nil && len(*d) > 0 {
+					position_id := gconv.Int64((*d)[0]["position_id"])
+					if positionId == position_id {
+						return 1, ""
+					}
 					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)
+				d := cm.BaseMysql.SelectBySql(`select create_person,position_id from crm.custom where employ_custom_id =? and ent_id =?`, employCustomId, entId)
 				if d != nil && len(*d) > 0 {
+					position_id := gconv.Int64((*d)[0]["position_id"])
+					if positionId == position_id {
+						return 1, ""
+					}
 					return -1, fmt.Sprintf("%v已经基于该候选客户创建了客户", (*d)[0]["create_person"])
 				}
 			}