Jianghan пре 1 година
родитељ
комит
ce02ee78b4
1 измењених фајлова са 30 додато и 19 уклоњено
  1. 30 19
      service/custom.go

+ 30 - 19
service/custom.go

@@ -272,28 +272,39 @@ func SaveLedger(ctx context.Context, positionId, businessId, taskId int64, types
 
 // 消息漏斗保存
 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`, `status`}
+	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`}
 	//当前阶段
-	//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"])
-		}*/
+	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
+		/**/
 	}
-	args = append(args, stageId)
-	args = append(args, 0)
-	args = append(args, 1)
-	//当前阶段进展
-	_, id := cm.CrmMysql.InsertBatchByTx(tx, entity.SALES_FUNNEL, fields, args)
-	return id
+	return 0
 }
 func GetOtherKey(key string) []string {
 	parameters := map[string][]string{