Explorar o código

办结时间处理

WH01243 hai 1 ano
pai
achega
a13f3d0509
Modificáronse 1 ficheiros con 158 adicións e 5 borrados
  1. 158 5
      clueSync/jobutil.go

+ 158 - 5
clueSync/jobutil.go

@@ -17,7 +17,7 @@ import (
 // 电销工单生成
 func rderAcceptance() {
 	sql := fmt.Sprintf(`select * from order_acceptance where is_clue=2 and  is_delete=1 order by propose_time  `)
-	//sql := fmt.Sprintf(`select * from order_acceptance where is_clue=2 and  is_delete=1 and  id  = 279  order by propose_time  `)
+	//sql := fmt.Sprintf(`select * from order_acceptance where is_clue=2 and  is_delete=1 and  id  = 333  order by propose_time  `)
 	data := WorkOrder.SelectBySql(sql)
 	if data != nil && len(*data) > 0 {
 		for _, v := range *data {
@@ -196,7 +196,7 @@ func AddOrderWork(acceptanceData map[string]interface{}, userData map[string]int
 		}, map[string]interface{}{
 			"is_clue":   3,
 			"status":    status,
-			"over_time": nowTime,
+			"over_time": common.If(status == 1, nil, nowTime),
 		})
 		//日志添加
 		approvalRecordMap := map[string]interface{}{
@@ -409,9 +409,9 @@ FROM
 	}
 	//按照比例分配选择一部还是三部
 	//一部查询
-	deptCount1 := CalculateProportion(strings.Join(positionIdArr1, ","))
+	deptCount1 := CalculateProportion1(strings.Join(positionIdArr1, ","))
 	//三部查询
-	deptCount3 := CalculateProportion(strings.Join(positionIdArr3, ","))
+	deptCount3 := CalculateProportion1(strings.Join(positionIdArr3, ","))
 	if deptCount1 == 0 {
 		return true, administrators1, allData
 	}
@@ -426,7 +426,7 @@ FROM
 	log.Println("电销信息获取失败", positionId)
 	return false, map[string]interface{}{}, allData
 }
-func CalculateProportion(positionIsStr string) float64 {
+func CalculateProportion1(positionIsStr string) float64 {
 	createtime := time.Time{}
 	now := time.Now()
 	weekday := int(now.Weekday())
@@ -455,6 +455,159 @@ func CalculateProportion(positionIsStr string) float64 {
 	return count
 }
 
+func FindPosition1(positionId int64, trailstatus string) (bool, map[string]interface{}, []map[string]interface{}) {
+	allData := []map[string]interface{}{}
+	//查询两个部门高级管理员
+	//查询两个部门所有人员标识
+	//电销三部
+	userData1 := TiDb.SelectBySql(`SELECT
+	a.position_id,
+	a.name,
+	b.seat_number,
+	b.role_id,
+	a.bi_pcode,
+	a.dept_name
+FROM
+	dwd_d_crm_department_level_succbi a
+	INNER JOIN dwd_f_crm_personnel_management b ON a.resign = 0 and b.resign = 0
+	AND a.dept_name LIKE "%电销部%"
+	AND a.position_id = b.position_id`)
+	userData3 := TiDb.SelectBySql(`SELECT
+	a.position_id,
+	a.name,
+	b.seat_number,
+	b.role_id,
+	a.bi_pcode,
+	a.dept_name
+FROM
+	dwd_d_crm_department_level_succbi a
+	INNER JOIN dwd_f_crm_personnel_management b ON a.resign = 0 and b.resign = 0
+	AND a.resign = 0
+	AND a.dept_name LIKE "%销售三部"
+	AND a.position_id = b.position_id`)
+	if userData3 == nil || len(*userData3) == 0 || userData1 == nil || len(*userData1) == 0 {
+		return false, map[string]interface{}{}, allData
+	}
+	//一部管理员信息
+	administrators1 := map[string]interface{}{}
+	//三部管理员信息
+	administrators3 := map[string]interface{}{}
+	//返回当前人信息
+	administrators := map[string]interface{}{}
+	//电销一部
+	deptNameMap1 := map[string]interface{}{}
+	deptNameMap3 := map[string]interface{}{}
+	proportion1 := float64(0)
+	proportion3 := float64(0)
+	for _, v := range *userData3 {
+		v["type"] = 3
+		id := gconv.Int64(v["position_id"])
+		roleId := gconv.Int64(v["role_id"])
+		if id == positionId {
+			if roleId == 8 {
+				v["orderStatus"] = 2
+			}
+			administrators = v
+		}
+		if roleId == 8 {
+			v["orderStatus"] = 2
+			administrators3 = v
+		} else if roleId == 3 {
+			proportion3 += 0.5
+		} else {
+			proportion3 += 1
+		}
+		deptNameMap3[gconv.String(v["bi_pcode"])] = true
+		allData = append(allData, v)
+	}
+	for _, v := range *userData1 {
+		v["type"] = 1
+		id := gconv.Int64(v["position_id"])
+		roleId := gconv.Int64(v["role_id"])
+		if id == positionId {
+			if roleId == 8 {
+				v["orderStatus"] = 2
+			}
+			administrators = v
+		}
+		if roleId == 8 {
+			v["orderStatus"] = 2
+			administrators1 = v
+		} else if roleId == 3 {
+			proportion1 += 0.5
+		} else {
+			proportion1 += 1
+		}
+		deptNameMap1[gconv.String(v["bi_pcode"])] = true
+		allData = append(allData, v)
+	}
+	if positionId != 0 {
+		if administrators == nil || len(administrators) == 0 {
+			return false, map[string]interface{}{}, allData
+		}
+		positiontype := gconv.Int64(administrators["type"])
+		if trailstatus == "01" || trailstatus == "03" || trailstatus == "04" {
+			switch positiontype {
+			case 1:
+				//找他上级
+				administrators = administrators1
+			case 3:
+				//找他上级
+				administrators = administrators3
+			}
+			return true, administrators, allData
+		} else {
+			return true, administrators, allData
+		}
+	}
+	//按照比例分配选择一部还是三部
+	//一部查询
+	deptCount1 := CalculateProportion(deptNameMap1)
+	//三部查询
+	deptCount3 := CalculateProportion(deptNameMap3)
+	if deptCount1 == 0 {
+		return true, administrators1, allData
+	}
+	if deptCount3 == 0 {
+		return true, administrators3, allData
+	}
+	if deptCount1/deptCount3 > proportion1/proportion3 {
+		return true, administrators3, allData
+	} else {
+		return true, administrators1, allData
+	}
+	log.Println("电销信息获取失败", positionId)
+	return false, map[string]interface{}{}, allData
+}
+
+func CalculateProportion(deptNameMap map[string]interface{}) float64 {
+	deptNameStr := ""
+	for k := range deptNameMap {
+		if deptNameStr == "" {
+			deptNameStr = k
+		} else {
+			deptNameStr = fmt.Sprintf("%s%s", deptNameStr, k)
+		}
+	}
+	if deptNameStr == "" {
+		return float64(0)
+	}
+	count := float64(0)
+	sql := `SELECT
+			sum(1) as  count
+		FROM
+			order_work 
+		WHERE
+			  FIND_IN_SET(current_position_id ,?) 
+			AND is_delete=1
+			and   creator_time>?`
+	data := WorkOrder.SelectBySql(sql, "")
+	if data != nil && len(*data) > 0 {
+		count = gconv.Float64((*data)[0]["count"])
+	}
+	return count
+}
+
 // 未支付订单 30分钟一次
 func orders() {
 	//一个小时未支付进入线索 A