Browse Source

销售漏斗数据提交

WH01243 1 year ago
parent
commit
44cdb6d5ee
3 changed files with 65 additions and 25 deletions
  1. 14 11
      entity/db.go
  2. 28 6
      service/custom.go
  3. 23 8
      service/sale_chance.go

+ 14 - 11
entity/db.go

@@ -47,15 +47,18 @@ type EsStruct struct {
 }
 }
 
 
 const (
 const (
-	TASK              = "task"              //任务表
-	FOLLOW_RECORD     = "follow_record"     //跟进记录表
-	SALE_CHANCE       = "sale_chance"       //销售机会
-	CUSTOM            = "custom"            //客户表
-	EMPLOY_INFO       = "employ_info"       //商业资讯收录表
-	EMPLOY_CUSTOM     = "employ_custom"     //候选客户收录表
-	SALE_CLUE         = "sale_clue"         //销售线索
-	EMPLOY_SUMMARY    = "employ_summary"    //收录汇总表
-	TASK_EXECUTE_PLAN = "task_execute_plan" //任务执行计划
-	TASK_TRANSFER     = "task_transfer"     //转办记录表
-	TASK_TEAM         = "task_team"         //任务团队
+	TASK                = "task"              //任务表
+	FOLLOW_RECORD       = "follow_record"     //跟进记录表
+	SALE_CHANCE         = "sale_chance"       //销售机会
+	CUSTOM              = "custom"            //客户表
+	EMPLOY_INFO         = "employ_info"       //商业资讯收录表
+	EMPLOY_CUSTOM       = "employ_custom"     //候选客户收录表
+	SALE_CLUE           = "sale_clue"         //销售线索
+	EMPLOY_SUMMARY      = "employ_summary"    //收录汇总表
+	TASK_EXECUTE_PLAN   = "task_execute_plan" //任务执行计划
+	TASK_TRANSFER       = "task_transfer"     //转办记录表
+	TASK_TEAM           = "task_team"         //任务团队
+	CONFIG_TPL_STAGE    = "config_tpl_stage"
+	CONFIG_STAGE_MATTER = "config_stage_matter"
+	SALES_FUNNEL        = "sales_funnel"
 )
 )

+ 28 - 6
service/custom.go

@@ -17,7 +17,7 @@ import (
 	"github.com/gogf/gf/v2/util/gconv"
 	"github.com/gogf/gf/v2/util/gconv"
 )
 )
 
 
-//客户相关
+// 客户相关
 type CustomService struct {
 type CustomService struct {
 	BaseUserId           int64
 	BaseUserId           int64
 	PositionId           int64
 	PositionId           int64
@@ -47,7 +47,7 @@ type CustomService struct {
 	CreateName           string  //创建人
 	CreateName           string  //创建人
 }
 }
 
 
-//Add 创建客户
+// Add 创建客户
 func (this *CustomService) Add(ctx context.Context) (int64, string) {
 func (this *CustomService) Add(ctx context.Context) (int64, string) {
 	nowtime := time.Now().Format(date.Date_Full_Layout)
 	nowtime := time.Now().Format(date.Date_Full_Layout)
 	nextFollowTime := time.Unix(this.NextfollowUpTime, 0).Format(date.Date_Full_Layout)
 	nextFollowTime := time.Unix(this.NextfollowUpTime, 0).Format(date.Date_Full_Layout)
@@ -141,15 +141,14 @@ func (this *CustomService) Add(ctx context.Context) (int64, string) {
 	return 1, groupId
 	return 1, groupId
 }
 }
 
 
-//
 func SaleCustomAdd(tx *sql.Tx, args []interface{}) int64 {
 func SaleCustomAdd(tx *sql.Tx, args []interface{}) int64 {
 	fields := []string{"position_id", "ent_id", "ent_user_id", "employ_info_id", "employ_custom_id", "type", "full_name", "sort_name", "summary", "level", "industry", "subdivision_industry", "province", "city", "county", "address", "phone", "remark", "create_person", "create_time"}
 	fields := []string{"position_id", "ent_id", "ent_user_id", "employ_info_id", "employ_custom_id", "type", "full_name", "sort_name", "summary", "level", "industry", "subdivision_industry", "province", "city", "county", "address", "phone", "remark", "create_person", "create_time"}
 	_, id := cm.CrmMysql.InsertBatchByTx(tx, entity.CUSTOM, fields, args)
 	_, id := cm.CrmMysql.InsertBatchByTx(tx, entity.CUSTOM, fields, args)
 	return id
 	return id
 }
 }
 
 
-//EmployUpdate 是否创建线索/机会/客户修改
-//return employ_info_id,employ_custom_id
+// EmployUpdate 是否创建线索/机会/客户修改
+// return employ_info_id,employ_custom_id
 func EmployUpdate(tx *sql.Tx, employ_info_id, employ_custom_id, positionId int64, key string, entId, entUserId, entDeptId int64) (int64, int64) {
 func EmployUpdate(tx *sql.Tx, employ_info_id, employ_custom_id, positionId int64, key string, entId, entUserId, entDeptId int64) (int64, int64) {
 	tablename := ""
 	tablename := ""
 	id := int64(0)
 	id := int64(0)
@@ -248,7 +247,7 @@ func SaveCustom(ctx context.Context, argsCustom, argsTask, argsTaskTeam []interf
 	return customId, taskId
 	return customId, taskId
 }
 }
 
 
-//SaveLedger 操作台帐相关
+// SaveLedger 操作台帐相关
 func SaveLedger(ctx context.Context, positionId, businessId, taskId int64, types, content, createPerson string) bool {
 func SaveLedger(ctx context.Context, positionId, businessId, taskId int64, types, content, createPerson string) bool {
 	//操作台账
 	//操作台账
 	resp, err := cm.BaseCenterRpc.LedgerAdd(ctx, &baseC.LedgerAddReq{
 	resp, err := cm.BaseCenterRpc.LedgerAdd(ctx, &baseC.LedgerAddReq{
@@ -271,6 +270,29 @@ func SaveLedger(ctx context.Context, positionId, businessId, taskId int64, types
 	return resp.State
 	return resp.State
 }
 }
 
 
+// 消息漏斗保存
+func saveSalesFunnel(tx *sql.Tx, args []interface{}, tpl_id int64) int64 {
+	fields := []string{`chance_id`, `task_id`, `chance_name`, `outline`, `next_follow_time`, `expected_transaction_amount`, `business_type`, `ent_id`, `employ_info_id`, `current_generation_progress`, `current_generation`}
+	//当前阶段
+	ratio := int64(0)
+	stageId := int64(0)
+	stageData := cm.CrmMysql.FindOne(entity.CONFIG_TPL_STAGE, map[string]interface{}{
+		"tpl_id": tpl_id,
+		"order":  1,
+	}, "id", "")if stageData != nil {
+		stageId = gconv.Int64((*stageData)["id"])
+		//进度查询
+		matterData := cm.CrmMysql.SelectBySql("select SUM(ratio)  as ratio   from  config_stage_matter where stage_id=?", stageId)
+		if matterData != nil && len(*matterData) > 0 {
+			ratio = gconv.Int64((*matterData)[0]["ratio"])
+		}
+	}
+	args = append(args, stageId)
+	args = append(args, ratio)
+	//当前阶段进展
+	_, id := cm.CrmMysql.InsertBatchByTx(tx, entity.SALES_FUNNEL, fields, args)
+	return id
+}
 func GetOtherKey(key string) []string {
 func GetOtherKey(key string) []string {
 	parameters := map[string][]string{
 	parameters := map[string][]string{
 		"is_create_clue":   []string{"is_create_chance", "is_create_custom"},
 		"is_create_clue":   []string{"is_create_chance", "is_create_custom"},

+ 23 - 8
service/sale_chance.go

@@ -86,7 +86,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)
 		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, this.EntId, this.EntUserId, this.EntDeptId)
+		chanceId, taskId = this.SaveChange(ctx, args, argsTask, argsTaskTeam, []int64{})
 
 
 		if chanceId < 0 {
 		if chanceId < 0 {
 			return -1, groupId
 			return -1, groupId
@@ -99,7 +99,7 @@ func (this *SaleChanceService) Add(ctx context.Context) (int64, string) {
 		//任务团队
 		//任务团队
 		argsTaskTeam = append(argsTaskTeam, this.PositionId, this.EntUserId, this.CreateName, 1, nowtime)
 		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{}, this.EntId, this.EntUserId, this.EntDeptId)
+		chanceId, taskId = this.SaveChange(ctx, args, argsTask, argsTaskTeam, []int64{})
 		if chanceId < 0 {
 		if chanceId < 0 {
 			return -1, groupId
 			return -1, groupId
 		}
 		}
@@ -151,16 +151,18 @@ func SaleChangeAdd(tx *sql.Tx, args []interface{}) int64 {
 	fields := []string{"position_id", "ent_id", "ent_user_id", "employ_info_id", "custom_id", "tpl_id", "name", "summary", "classify", "expect_deal_time", "expect_deal_amount", "remark", "create_time", "create_person", "source"}
 	fields := []string{"position_id", "ent_id", "ent_user_id", "employ_info_id", "custom_id", "tpl_id", "name", "summary", "classify", "expect_deal_time", "expect_deal_amount", "remark", "create_time", "create_person", "source"}
 
 
 	_, id := cm.CrmMysql.InsertBatchByTx(tx, entity.SALE_CHANCE, fields, args)
 	_, id := cm.CrmMysql.InsertBatchByTx(tx, entity.SALE_CHANCE, fields, args)
+	//
+
 	return id
 	return id
 }
 }
 
 
 // Save 存库
 // Save 存库
-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) {
+func (this *SaleChanceService) SaveChange(ctx context.Context, argsChange, argsTask, argsTaskTeam []interface{}, transferArr []int64) (int64, int64) {
 	//存库
 	//存库
 	changeId, taskId := int64(-1), int64(-1)
 	changeId, taskId := int64(-1), int64(-1)
 	cm.CrmMysql.ExecTx("创建机会", func(tx *sql.Tx) bool {
 	cm.CrmMysql.ExecTx("创建机会", func(tx *sql.Tx) bool {
 		//
 		//
-		employ_info_id_new, _ := EmployUpdate(tx, employ_info_id, 0, positionId, "is_create_chance", entId, entUserId, entDeptId)
+		employ_info_id_new, _ := EmployUpdate(tx, this.EmployInfoId, 0, this.PositionId, "is_create_chance", this.EntId, this.EntUserId, this.EntDeptId)
 
 
 		argsChange[3] = employ_info_id_new
 		argsChange[3] = employ_info_id_new
 
 
@@ -169,12 +171,25 @@ func SaveChange(ctx context.Context, argsChange, argsTask, argsTaskTeam []interf
 		//传过来的argTask没有来源id,需要append
 		//传过来的argTask没有来源id,需要append
 		argsTask = append(argsTask, changeId)
 		argsTask = append(argsTask, changeId)
 		//任务车存储
 		//任务车存储
-		taskId = TaskAdd(tx, argsTask, argsTaskTeam, transferArr, positionId)
+		taskId = TaskAdd(tx, argsTask, argsTaskTeam, transferArr, this.PositionId)
 		//操作台帐
 		//操作台帐
-		ok1 := SaveLedger(ctx, positionId, changeId, taskId, "创建销售机会", fmt.Sprintf("%s创建了销售机会", createName), createName)
+		ok1 := SaveLedger(ctx, this.PositionId, changeId, taskId, "创建销售机会", fmt.Sprintf("%s创建了销售机会", this.CreateName), this.CreateName)
 		//任务执行计划
 		//任务执行计划
-		planId := TaskExecutePlanAdd(tx, tplId, taskId)
-		if changeId > 0 && taskId > 0 && ok1 && planId > 0 {
+		planId := TaskExecutePlanAdd(tx, this.BusinessType, taskId)
+		//销售漏斗
+		argsSalesFunnel := []interface{}{
+			changeId,
+			taskId,
+			fmt.Sprintf("%s创建了销售机会", this.CreateName),
+			this.Summary,
+			this.NextfollowUpTime,
+			this.ExpectedMoney,
+			this.BusinessType,
+			this.EntId,
+			this.EmployInfoId,
+		}
+		SalesFunnel := saveSalesFunnel(tx, argsSalesFunnel, this.BusinessType)
+		if changeId > 0 && taskId > 0 && ok1 && planId > 0 && SalesFunnel > 0 {
 			return true
 			return true
 		}
 		}
 		log.Println("save change err: ", changeId, taskId, ok1, planId)
 		log.Println("save change err: ", changeId, taskId, ok1, planId)