Parcourir la source

Merge branch 'master' into feature/v1.0.1

lianbingjie il y a 1 an
Parent
commit
643890c7f9
3 fichiers modifiés avec 74 ajouts et 19 suppressions
  1. 14 11
      entity/db.go
  2. 36 0
      service/custom.go
  3. 24 8
      service/sale_chance.go

+ 14 - 11
entity/db.go

@@ -47,15 +47,18 @@ type EsStruct struct {
 }
 
 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"
 )

+ 36 - 0
service/custom.go

@@ -277,6 +277,42 @@ func SaveLedger(ctx context.Context, positionId, businessId, taskId int64, types
 	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`, `current_generation_progress`, `generation`}
+	//当前阶段
+	stageId := int64(0)
+	stageData := cm.CrmMysql.Find(entity.CONFIG_TPL_STAGE, map[string]interface{}{
+		"tpl_id": tpl_id}, "id, order", "", -1, -1)
+	if stageData != nil && len(*stageData) > 0 {
+		var a1 []interface{}
+		for _, m := range *stageData {
+			stageId = gconv.Int64(m["id"])
+			order := gconv.Int(m["order"])
+			a1 = append(a1, args...)
+			if order == 1 {
+				a1 = append(a1, stageId)
+			} else {
+				a1 = append(a1, 0)
+			}
+			a1 = append(a1, 0)
+			a1 = append(a1, stageId)
+			//进度查询
+			matterData := cm.CrmMysql.SelectBySql("select COUNT(1) as ratio from config_stage_matter where stage_id=? and is_must == 1", stageId)
+			if matterData != nil && len(*matterData) > 0 {
+				ratio := gconv.Int64((*matterData)[0]["ratio"])
+				a1 = append(a1, ratio)
+			} else {
+				a1 = append(a1, 0)
+			}
+		}
+		//当前阶段进展
+		_, id := cm.CrmMysql.InsertBatchByTx(tx, entity.SALES_FUNNEL, fields, args)
+		return id
+		/**/
+	}
+	return 0
+}
 func GetOtherKey(key string) []string {
 	parameters := map[string][]string{
 		"is_create_clue":   []string{"is_create_chance", "is_create_custom"},

+ 24 - 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)
 
-		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, transferArr)
 
 		if chanceId < 0 {
 			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)
 		//存库
-		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 {
 			return -1, groupId
 		}
@@ -161,16 +161,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"}
 
 	_, id := cm.CrmMysql.InsertBatchByTx(tx, entity.SALE_CHANCE, fields, args)
+	//
+
 	return id
 }
 
 // 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)
 	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
 
@@ -179,12 +181,26 @@ func SaveChange(ctx context.Context, argsChange, argsTask, argsTaskTeam []interf
 		//传过来的argTask没有来源id,需要append
 		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)
+		//销售漏斗
+		nextFollowTime := time.Unix(this.NextfollowUpTime, 0).Format(date.Date_Full_Layout)
+		argsSalesFunnel := []interface{}{
+			changeId,
+			taskId,
+			this.ChanceName,
+			this.Summary,
+			nextFollowTime,
+			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
 		}
 		log.Println("save change err: ", changeId, taskId, ok1, planId)