Преглед на файлове

Merge remote-tracking branch 'origin/master'

WH01243 преди 1 година
родител
ревизия
98572b77d5

+ 5 - 0
README.md

@@ -0,0 +1,5 @@
+CRM应用程序,只提供api服务
+
+goctl api go -api application.api -dir .
+
+go test -v -coverprofile=coverage go tool cover -html=coverage -o coverage.html

BIN
api/api.exe


+ 3 - 0
api/application.api

@@ -14,6 +14,7 @@ type (
 		EntUserId    int64   `header:"entUserId,optional"`
 		EntId        int64   `header:"entId,optional"`
 		AccountId    int64   `header:"accountId,optional"`
+		EntDeptId    int64   `header:"entDeptId,optional"`
 		CluesSource  string  `json:"cluesSource"`           //线索来源
 		ClueName     string  `json:"clueName"`              //线索名称
 		Summary      string  `json:"summary"`               //概要信息
@@ -31,6 +32,7 @@ type (
 		EntUserId         int64   `header:"entUserId,optional"`
 		EntId             int64   `header:"entId,optional"`
 		AccountId         int64   `header:"accountId,optional"`
+		EntDeptId         int64   `header:"entDeptId,optional"`
 		ChanceName        string  `json:"chanceName"`                 //机会名称
 		Summary           string  `json:"summary"`                    //概要信息
 		ChanceClassify    int64   `json:"chanceClassify"`             //机会分类
@@ -99,6 +101,7 @@ type (
 		EntUserId            int64   `header:"entUserId,optional"`
 		EntId                int64   `header:"entId,optional"`
 		AccountId            int64   `header:"accountId,optional"`
+		EntDeptId            int64   `header:"entDeptId,optional"`
 		CustomType           int64   `json:"customType"`                //客户类型
 		Summary              string  `json:"summary"`                   //概要信息
 		CustomAllName        string  `json:"customAllName"`             //客户全称

BIN
api/application_api


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

@@ -42,6 +42,7 @@ func (l *ClueAddLogic) ClueAdd(req *types.ClueAddReq) (resp *types.Reply, err er
 		FollowUpTime: req.FollowUpTime,
 		CreateName:   req.CreateName,
 		BaseUserId:   req.BaseUserId,
+		EntDeptId:    req.EntDeptId,
 	}
 	status, groupId := clue.Add(l.ctx)
 

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

@@ -34,6 +34,7 @@ func (l *CustomAddLogic) CustomAdd(req *types.CustomAddReq) (resp *types.Reply,
 		EntId:                req.EntId,
 		AppId:                req.AppId,
 		AccountId:            req.AccountId,
+		EntDeptId:            req.EntDeptId,
 		CustomType:           req.CustomType,           //客户类型
 		Summary:              req.Summary,              //概要信息
 		CustomAllName:        req.CustomAllName,        //客户全称

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

@@ -34,6 +34,7 @@ func (l *SaleChanceAddLogic) SaleChanceAdd(req *types.SaleChanceReq) (resp *type
 		EntId:             req.EntId,
 		AppId:             req.AppId,
 		AccountId:         req.AccountId,
+		EntDeptId:         req.EntDeptId,
 		ChanceName:        req.ChanceName,        //机会名称
 		Summary:           req.Summary,           //概要信息
 		ChanceClassify:    req.ChanceClassify,    //机会分类

+ 3 - 0
api/internal/types/types.go

@@ -14,6 +14,7 @@ type ClueAddReq struct {
 	EntUserId    int64   `header:"entUserId,optional"`
 	EntId        int64   `header:"entId,optional"`
 	AccountId    int64   `header:"accountId,optional"`
+	EntDeptId    int64   `header:"entDeptId,optional"`
 	CluesSource  string  `json:"cluesSource"`           //线索来源
 	ClueName     string  `json:"clueName"`              //线索名称
 	Summary      string  `json:"summary"`               //概要信息
@@ -31,6 +32,7 @@ type SaleChanceReq struct {
 	EntUserId         int64   `header:"entUserId,optional"`
 	EntId             int64   `header:"entId,optional"`
 	AccountId         int64   `header:"accountId,optional"`
+	EntDeptId         int64   `header:"entDeptId,optional"`
 	ChanceName        string  `json:"chanceName"`                 //机会名称
 	Summary           string  `json:"summary"`                    //概要信息
 	ChanceClassify    int64   `json:"chanceClassify"`             //机会分类
@@ -99,6 +101,7 @@ type CustomAddReq struct {
 	EntUserId            int64   `header:"entUserId,optional"`
 	EntId                int64   `header:"entId,optional"`
 	AccountId            int64   `header:"accountId,optional"`
+	EntDeptId            int64   `header:"entDeptId,optional"`
 	CustomType           int64   `json:"customType"`                //客户类型
 	Summary              string  `json:"summary"`                   //概要信息
 	CustomAllName        string  `json:"customAllName"`             //客户全称

+ 51 - 8
service/custom.go

@@ -25,6 +25,7 @@ type CustomService struct {
 	EntId                int64
 	AppId                string
 	AccountId            int64
+	EntDeptId            int64
 	CustomType           int64   //客户类型
 	Summary              string  //概要信息
 	CustomAllName        string  //客户全称
@@ -77,12 +78,12 @@ func (this *CustomService) Add(ctx context.Context) (int64, string) {
 			baseUserIdArr = append(baseUserIdArr, resp.UserId)
 		}
 
-		//客户
+		//客户3
 		args = append(args, this.PositionId, this.EntId, this.EntUserId, this.EmployInfoId, this.EmployCustomId, this.CustomType, this.CustomAllName, this.CustomAbbreviation, this.Summary, qu.If(this.CustomLevel == 0, nil, this.CustomLevel), this.CustomIndustry, this.CustomDetailIndustry, qu.If(this.Province == "", nil, this.Province), qu.If(this.City == "", nil, this.City), qu.If(this.District == "", nil, this.District), qu.If(this.Address == "", nil, this.Address), qu.If(this.CompanyPhone == "", nil, this.CompanyPhone), qu.If(this.Remarks == "", nil, this.Remarks), this.CreateName, nowtime)
 		//任务
 		argsTask = append(argsTask, this.EntId, this.CustomAllName+"的跟进任务", 3, this.PositionId, 1, nowtime, 1, 0, qu.If(this.NextfollowUpTime == 0, nil, nextFollowTime), nil, nil)
 
-		customId, taskId = SaveCustom(ctx, args, argsTask, argsTaskTeam, this.EmployInfoId, this.EmployCustomId, this.PositionId, this.CreateName, transferArr)
+		customId, taskId = SaveCustom(ctx, args, argsTask, argsTaskTeam, this.EmployInfoId, this.EmployCustomId, this.PositionId, this.CreateName, transferArr, this.EntId, this.EntUserId, this.EntDeptId)
 		if customId < 0 {
 			return -1, groupId
 		}
@@ -94,7 +95,7 @@ func (this *CustomService) Add(ctx context.Context) (int64, string) {
 		//任务团队
 		argsTaskTeam = append(argsTaskTeam, this.PositionId, this.EntUserId, this.CreateName, 1, nowtime)
 		//存库
-		customId, taskId = SaveCustom(ctx, args, argsTask, argsTaskTeam, this.EmployInfoId, this.EmployCustomId, this.PositionId, this.CreateName, []int64{})
+		customId, taskId = SaveCustom(ctx, args, argsTask, argsTaskTeam, this.EmployInfoId, this.EmployCustomId, this.PositionId, this.CreateName, []int64{}, this.EntId, this.EntUserId, this.EntDeptId)
 		if customId < 0 {
 			return -1, groupId
 		}
@@ -148,7 +149,8 @@ func SaleCustomAdd(tx *sql.Tx, args []interface{}) int64 {
 }
 
 //EmployUpdate 是否创建线索/机会/客户修改
-func EmployUpdate(tx *sql.Tx, employ_info_id, employ_custom_id, positionId int64, key string) bool {
+func EmployUpdate(tx *sql.Tx, employ_info_id, employ_custom_id, positionId int64, key string, entId, entUserId, entDeptId int64) bool {
+	ok := true
 	tablename := ""
 	id := int64(0)
 	if employ_custom_id > 0 {
@@ -159,12 +161,44 @@ func EmployUpdate(tx *sql.Tx, employ_info_id, employ_custom_id, positionId int64
 		id = employ_info_id
 	}
 	if tablename == "" || id == 0 {
-		return true
+		return ok
+	}
+	//判断该条信息是不是当前资讯分配员的
+	d := cm.CrmMysql.SelectBySqlByTx(tx, fmt.Sprintf(`select * from %v where id = ?`, tablename), id)
+	if d != nil && len(*d) > 0 {
+		data := (*d)[0]
+		position_id := gconv.Int64(data["position_id"])
+		if position_id == positionId {
+			return cm.CrmMysql.UpdateByTx(tx, tablename, map[string]interface{}{"id": id, "position_id": positionId}, map[string]interface{}{key: 1})
+		} else {
+			data["position_id"] = positionId
+			data["ent_id"] = entId
+			data["ent_dept_id"] = entDeptId
+			data["ent_user_id"] = entUserId
+			//当前咨询不是分配员的 创建该条
+			if employ_custom_id > 0 {
+				//
+				data["is_handle"] = 1
+				data["is_ignore"] = 0
+				data["is_create_custom"] = 1
+
+			} else if employ_info_id > 0 {
+				data["is_handle"] = 1
+				data["is_ignore"] = 0
+				data["is_dis"] = 0
+				data[key] = 1
+				for _, v := range GetOtherKey(key) {
+					data[v] = 0
+				}
+			}
+			delete(data, "id")
+			return cm.CrmMysql.InsertByTx(tx, tablename, data) > 0
+		}
 	}
-	return cm.CrmMysql.UpdateByTx(tx, tablename, map[string]interface{}{"id": id, "position_id": positionId}, map[string]interface{}{key: 1})
+	return ok
 }
 
-func SaveCustom(ctx context.Context, argsCustom, argsTask, argsTaskTeam []interface{}, employ_info_id, employ_custom_id, positionId int64, createPerson string, transferArr []int64) (int64, int64) {
+func SaveCustom(ctx context.Context, argsCustom, argsTask, argsTaskTeam []interface{}, employ_info_id, employ_custom_id, positionId int64, createPerson string, transferArr []int64, entId, entUserId, entDeptId int64) (int64, int64) {
 	customId := int64(-1)
 	taskId := int64(-1)
 	//存库
@@ -175,7 +209,7 @@ func SaveCustom(ctx context.Context, argsCustom, argsTask, argsTaskTeam []interf
 		argsTask = append(argsTask, customId)
 		//任务车存储
 		taskId = TaskAdd(tx, argsTask, argsTaskTeam, transferArr, positionId)
-		ok := EmployUpdate(tx, employ_info_id, employ_custom_id, positionId, "is_create_custom")
+		ok := EmployUpdate(tx, employ_info_id, employ_custom_id, positionId, "is_create_custom", entId, entUserId, entDeptId)
 		//插入台账
 		ok2 := SaveLedger(ctx, positionId, customId, taskId, "创建客户", fmt.Sprintf("%s创建了客户", createPerson), createPerson)
 		if customId > 0 && taskId > 0 && ok && ok2 {
@@ -209,3 +243,12 @@ func SaveLedger(ctx context.Context, positionId, businessId, taskId int64, types
 	}
 	return resp.State
 }
+
+func GetOtherKey(key string) []string {
+	parameters := map[string][]string{
+		"is_create_clue":   []string{"is_create_chance", "is_create_custom"},
+		"is_create_chance": []string{"is_create_clue", "is_create_custom"},
+		"is_create_custom": []string{"is_create_chance", "is_create_clue"},
+	}
+	return parameters[key]
+}

+ 5 - 5
service/sale_chance.go

@@ -25,6 +25,7 @@ type SaleChanceService struct {
 	EntId             int64
 	AppId             string
 	AccountId         int64
+	EntDeptId         int64
 	ChanceName        string  //机会名称
 	Owner             string  //机会所有者
 	Summary           string  //概要信息
@@ -84,7 +85,7 @@ func (this *SaleChanceService) Add(ctx context.Context) (int64, string) {
 		//任务
 		argsTask = append(argsTask, this.EntId, this.ChanceName+"的跟进任务", 2, this.PositionId, 1, nowtime, 1, 0, qu.If(this.NextfollowUpTime == 0, nil, nextFollowTime), this.BusinessType, stageId)
 
-		chanceId, taskId = SaveChange(ctx, args, argsTask, argsTaskTeam, this.EmployInfoId, this.CustomId, this.PositionId, this.BusinessType, this.CreateName, transferArr)
+		chanceId, taskId = SaveChange(ctx, args, argsTask, argsTaskTeam, this.EmployInfoId, this.CustomId, this.PositionId, this.BusinessType, this.CreateName, transferArr, this.EntId, this.EntUserId, this.EntDeptId)
 
 		if chanceId < 0 {
 			return -1, groupId
@@ -97,7 +98,7 @@ func (this *SaleChanceService) Add(ctx context.Context) (int64, string) {
 		//任务团队
 		argsTaskTeam = append(argsTaskTeam, this.PositionId, this.EntUserId, this.CreateName, 1, nowtime)
 		//存库
-		chanceId, taskId = SaveChange(ctx, args, argsTask, argsTaskTeam, this.EmployInfoId, this.CustomId, this.PositionId, this.BusinessType, this.CreateName, []int64{})
+		chanceId, taskId = SaveChange(ctx, args, argsTask, argsTaskTeam, this.EmployInfoId, this.CustomId, this.PositionId, this.BusinessType, this.CreateName, []int64{}, this.EntId, this.EntUserId, this.EntDeptId)
 		if chanceId < 0 {
 			return -1, groupId
 		}
@@ -153,7 +154,7 @@ func SaleChangeAdd(tx *sql.Tx, args []interface{}) int64 {
 }
 
 // Save 存库
-func SaveChange(ctx context.Context, argsChange, argsTask, argsTaskTeam []interface{}, employ_info_id, employ_custom_id, positionId, tplId int64, createName string, transferArr []int64) (int64, int64) {
+func SaveChange(ctx context.Context, argsChange, argsTask, argsTaskTeam []interface{}, employ_info_id, employ_custom_id, positionId, tplId int64, createName string, transferArr []int64, entId, entUserId, entDeptId int64) (int64, int64) {
 	//存库
 	changeId, taskId := int64(-1), int64(-1)
 	cm.CrmMysql.ExecTx("创建机会", func(tx *sql.Tx) bool {
@@ -166,8 +167,7 @@ func SaveChange(ctx context.Context, argsChange, argsTask, argsTaskTeam []interf
 		//操作台帐
 		ok1 := SaveLedger(ctx, positionId, changeId, taskId, "创建销售机会", fmt.Sprintf("%s创建了销售机会", createName), createName)
 		//是否创建销售计划
-		log.Println(employ_info_id, employ_custom_id, "##")
-		ok2 := EmployUpdate(tx, employ_info_id, 0, positionId, "is_create_chance")
+		ok2 := EmployUpdate(tx, employ_info_id, 0, positionId, "is_create_chance", entId, entUserId, entDeptId)
 		//任务执行计划
 		planId := TaskExecutePlanAdd(tx, tplId, taskId)
 		if changeId > 0 && taskId > 0 && ok1 && ok2 && planId > 0 {

+ 5 - 4
service/sale_clue.go

@@ -28,6 +28,7 @@ type SaleClueService struct {
 	EntUserId    int64
 	BaseUserId   int64
 	AccountId    int64
+	EntDeptId    int64
 	ClueName     string
 	CluesSource  string
 	Summary      string
@@ -74,7 +75,7 @@ func (this *SaleClueService) Add(ctx context.Context) (int64, string) {
 		args = append(args, this.PositionId, this.EntId, this.EntUserId, this.ClueName, this.CluesSource, this.Summary, this.EmployInfoId, 0, nowtime, this.CreateName)
 		//任务
 		argsTask = append(argsTask, this.EntId, this.ClueName+"的跟进任务", 1, this.PositionId, 1, nowtime, 1, 0, qu.If(this.FollowUpTime == 0, nil, nextFollowTime), nil, nil)
-		clueId, taskId = Save(ctx, args, argsTask, argsTaskTeam, this.EmployInfoId, 0, this.PositionId, this.CreateName, transferArr)
+		clueId, taskId = Save(ctx, args, argsTask, argsTaskTeam, this.EmployInfoId, 0, this.PositionId, this.CreateName, transferArr, this.EntId, this.EntUserId, this.EntDeptId)
 		if clueId < 0 {
 			return -1, groupId
 		}
@@ -87,7 +88,7 @@ func (this *SaleClueService) Add(ctx context.Context) (int64, string) {
 		//任务团队
 		argsTaskTeam = append(argsTaskTeam, this.PositionId, this.EntUserId, this.CreateName, 1, nowtime)
 		//存库
-		clueId, taskId = Save(ctx, args, argsTask, argsTaskTeam, this.EmployInfoId, 0, this.PositionId, this.CreateName, []int64{})
+		clueId, taskId = Save(ctx, args, argsTask, argsTaskTeam, this.EmployInfoId, 0, this.PositionId, this.CreateName, []int64{}, this.EntId, this.EntUserId, this.EntDeptId)
 		if clueId < 0 {
 			return -1, groupId
 		}
@@ -162,7 +163,7 @@ func TaskAdd(tx *sql.Tx, args, taskTeamArgs []interface{}, transferArr []int64,
 }
 
 //Save 存库
-func Save(ctx context.Context, argsClue, argsTask, argsTaskTeam []interface{}, employ_info_id, employ_custom_id, positionId int64, createName string, transferArr []int64) (int64, int64) {
+func Save(ctx context.Context, argsClue, argsTask, argsTaskTeam []interface{}, employ_info_id, employ_custom_id, positionId int64, createName string, transferArr []int64, entId, entUserId, entDeptId int64) (int64, int64) {
 	clueId, taskId := int64(-1), int64(-1)
 	//存库
 	cm.CrmMysql.ExecTx("创建线索", func(tx *sql.Tx) bool {
@@ -173,7 +174,7 @@ func Save(ctx context.Context, argsClue, argsTask, argsTaskTeam []interface{}, e
 		//任务车存储
 		taskId = TaskAdd(tx, argsTask, argsTaskTeam, transferArr, positionId)
 		//是否创建销售线索
-		ok1 := EmployUpdate(tx, employ_info_id, employ_custom_id, positionId, "is_create_clue")
+		ok1 := EmployUpdate(tx, employ_info_id, employ_custom_id, positionId, "is_create_clue", entId, entUserId, entDeptId)
 		//操作台帐
 		ok2 := SaveLedger(ctx, positionId, clueId, taskId, "创建销售线索", fmt.Sprintf("%s创建了销售线索", createName), createName)
 		if clueId > 0 && taskId > 0 && ok1 && ok2 {