|
@@ -4,6 +4,7 @@ import (
|
|
"app.yhyue.com/moapp/jybase/redis"
|
|
"app.yhyue.com/moapp/jybase/redis"
|
|
"fmt"
|
|
"fmt"
|
|
"log"
|
|
"log"
|
|
|
|
+ "math"
|
|
"strings"
|
|
"strings"
|
|
"time"
|
|
"time"
|
|
|
|
|
|
@@ -111,14 +112,14 @@ func WorkDataHandle(company, phone, demand, name, product string, acceptanceData
|
|
} else {
|
|
} else {
|
|
if positionId == 0 {
|
|
if positionId == 0 {
|
|
//线索变更
|
|
//线索变更
|
|
- ok, data, saleData = FindPosition(0, "")
|
|
|
|
|
|
+ ok, data, saleData = FindPosition(0, "", gconv.String(acceptanceData["creator_time"]))
|
|
if !ok {
|
|
if !ok {
|
|
log.Println(positionId, "用户查询失败")
|
|
log.Println(positionId, "用户查询失败")
|
|
return false
|
|
return false
|
|
}
|
|
}
|
|
UpdateClue(*uCount, saleData, "", "", uId, "5", "169", "新增线索", "主动咨询客服留资客户", company, name, gconv.String(data["name"]), phone, "", "", "", "", "", "", gconv.String(data["seat_number"]), "", gconv.Int64(data["position_id"]), "", "", "", []string{}, "", isGroup, isCommerce, true, demand)
|
|
UpdateClue(*uCount, saleData, "", "", uId, "5", "169", "新增线索", "主动咨询客服留资客户", company, name, gconv.String(data["name"]), phone, "", "", "", "", "", "", gconv.String(data["seat_number"]), "", gconv.Int64(data["position_id"]), "", "", "", []string{}, "", isGroup, isCommerce, true, demand)
|
|
} else {
|
|
} else {
|
|
- ok, data, saleData = FindPosition(positionId, trailstatus)
|
|
|
|
|
|
+ ok, data, saleData = FindPosition(positionId, trailstatus, gconv.String(acceptanceData["creator_time"]))
|
|
if !ok {
|
|
if !ok {
|
|
log.Println(positionId, "用户查询失败")
|
|
log.Println(positionId, "用户查询失败")
|
|
return false
|
|
return false
|
|
@@ -133,7 +134,7 @@ func WorkDataHandle(company, phone, demand, name, product string, acceptanceData
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
//新增线索
|
|
//新增线索
|
|
- ok, data, _ = FindPosition(0, "")
|
|
|
|
|
|
+ ok, data, _ = FindPosition(0, "", gconv.String(acceptanceData["creator_time"]))
|
|
if !ok {
|
|
if !ok {
|
|
return false
|
|
return false
|
|
}
|
|
}
|
|
@@ -212,6 +213,9 @@ func AddOrderWork(acceptanceData map[string]interface{}, userData map[string]int
|
|
"is_delete": 1,
|
|
"is_delete": 1,
|
|
"creator_time": nowTime,
|
|
"creator_time": nowTime,
|
|
"handle_time": common.If(gconv.Int64(userData["orderStatus"]) == 0, nowTime, nil),
|
|
"handle_time": common.If(gconv.Int64(userData["orderStatus"]) == 0, nowTime, nil),
|
|
|
|
+ "update_name": common.If(gconv.Int64(userData["orderStatus"]) == 0, userData["name"], nil),
|
|
|
|
+ "update_position_id": common.If(gconv.Int64(userData["orderStatus"]) == 0, userData["position_id"], nil),
|
|
|
|
+ "update_time": common.If(gconv.Int64(userData["orderStatus"]) == 0, nowTime, nil),
|
|
}
|
|
}
|
|
WorkOrder.Insert("approval_record", approvalRecordMap)
|
|
WorkOrder.Insert("approval_record", approvalRecordMap)
|
|
WorkMail(personMap,
|
|
WorkMail(personMap,
|
|
@@ -308,154 +312,38 @@ func FindNumber(moudle string) string {
|
|
}
|
|
}
|
|
|
|
|
|
// 人员查询
|
|
// 人员查询
|
|
-func FindPosition(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
|
|
|
|
-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.ent_id = 25917
|
|
|
|
- AND a.dept_name LIKE "%电销部%"
|
|
|
|
- AND a.position_id = b.position_id`)
|
|
|
|
- userData3 := TiDb.SelectBySql(`SELECT
|
|
|
|
- a.position_id,
|
|
|
|
- a.name,
|
|
|
|
- b.seat_number
|
|
|
|
-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.ent_id = 25917
|
|
|
|
- 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{}{}
|
|
|
|
- //电销一部
|
|
|
|
- positionIdArr1 := []string{}
|
|
|
|
- positionIdArr3 := []string{}
|
|
|
|
- proportion1 := float64(0)
|
|
|
|
- proportion3 := float64(0)
|
|
|
|
- for _, v := range *userData3 {
|
|
|
|
- v["type"] = 3
|
|
|
|
- personName := gconv.String(v["name"])
|
|
|
|
- id := gconv.Int64(v["position_id"])
|
|
|
|
- if id == positionId {
|
|
|
|
- if personName == "孙鹏" {
|
|
|
|
- v["orderStatus"] = 2
|
|
|
|
- }
|
|
|
|
- administrators = v
|
|
|
|
- }
|
|
|
|
- if personName == "孙鹏" {
|
|
|
|
- v["orderStatus"] = 2
|
|
|
|
- administrators3 = v
|
|
|
|
- proportion3 += 0.5
|
|
|
|
- } else {
|
|
|
|
- proportion3 += 1
|
|
|
|
- }
|
|
|
|
- positionIdArr3 = append(positionIdArr3, gconv.String(id))
|
|
|
|
- allData = append(allData, v)
|
|
|
|
- }
|
|
|
|
- for _, v := range *userData1 {
|
|
|
|
- v["type"] = 1
|
|
|
|
- personName := gconv.String(v["name"])
|
|
|
|
- id := gconv.Int64(v["position_id"])
|
|
|
|
- if id == positionId {
|
|
|
|
- if personName == "沈炳毅" {
|
|
|
|
- v["orderStatus"] = 2
|
|
|
|
- }
|
|
|
|
- administrators = v
|
|
|
|
- }
|
|
|
|
- if personName == "沈炳毅" {
|
|
|
|
- v["orderStatus"] = 2
|
|
|
|
- administrators1 = v
|
|
|
|
- proportion1 += 0.5
|
|
|
|
- } else {
|
|
|
|
- proportion1 += 1
|
|
|
|
- }
|
|
|
|
- positionIdArr1 = append(positionIdArr1, gconv.String(id))
|
|
|
|
- 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 := CalculateProportion1(strings.Join(positionIdArr1, ","))
|
|
|
|
- //三部查询
|
|
|
|
- deptCount3 := CalculateProportion1(strings.Join(positionIdArr3, ","))
|
|
|
|
|
|
+func GetAllocation(proportion1, proportion3 float64, deptCount1, deptCount3 int64, administrators1, administrators3 map[string]interface{}, creatorTime string) map[string]interface{} {
|
|
|
|
+ log.Println("分配比例查询", proportion1, proportion3, deptCount1, deptCount3)
|
|
if deptCount1 == 0 {
|
|
if deptCount1 == 0 {
|
|
- return true, administrators1, allData
|
|
|
|
|
|
+ return administrators1
|
|
}
|
|
}
|
|
if deptCount3 == 0 {
|
|
if deptCount3 == 0 {
|
|
- return true, administrators3, allData
|
|
|
|
|
|
+ return administrators3
|
|
}
|
|
}
|
|
- if deptCount1/deptCount3 > proportion1/proportion3 {
|
|
|
|
- return true, administrators3, allData
|
|
|
|
|
|
+ nowAllocationRatio := math.Round(gconv.Float64(deptCount1 / deptCount3))
|
|
|
|
+ if cfg.AllocationRatio == 0 {
|
|
|
|
+ //重新计算
|
|
|
|
+ cfg.AllocationRatio = math.Round(proportion1 / proportion3)
|
|
|
|
+ cfg.AllocationTime = creatorTime
|
|
|
|
+ common.WriteSysConfig(&cfg)
|
|
|
|
+ log.Println("新增计算比例", cfg.AllocationRatio)
|
|
} else {
|
|
} else {
|
|
- return true, administrators1, allData
|
|
|
|
- }
|
|
|
|
- log.Println("电销信息获取失败", positionId)
|
|
|
|
- return false, map[string]interface{}{}, allData
|
|
|
|
-}
|
|
|
|
-func CalculateProportion1(positionIsStr string) float64 {
|
|
|
|
- createtime := time.Time{}
|
|
|
|
- now := time.Now()
|
|
|
|
- weekday := int(now.Weekday())
|
|
|
|
- if weekday == 0 { // 如果是周日,则将其视为本周的最后一天
|
|
|
|
- weekday = 7
|
|
|
|
- }
|
|
|
|
- switch cfg.LoopType {
|
|
|
|
- case 1: //周
|
|
|
|
- createtime = now.AddDate(0, 0, -weekday+1)
|
|
|
|
- case 2: //月
|
|
|
|
- createtime = time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, time.Local)
|
|
|
|
|
|
+ if nowAllocationRatio == cfg.AllocationRatio {
|
|
|
|
+ //重新计算
|
|
|
|
+ cfg.AllocationRatio = math.Round(proportion1 / proportion3)
|
|
|
|
+ cfg.AllocationTime = creatorTime
|
|
|
|
+ common.WriteSysConfig(&cfg)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- 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, positionIsStr, createtime.Format("2006-01-02"))
|
|
|
|
- if data != nil && len(*data) > 0 {
|
|
|
|
- count = gconv.Float64((*data)[0]["count"])
|
|
|
|
|
|
+ if nowAllocationRatio > cfg.AllocationRatio {
|
|
|
|
+ return administrators3
|
|
|
|
+ } else {
|
|
|
|
+ return administrators1
|
|
}
|
|
}
|
|
- return count
|
|
|
|
-}
|
|
|
|
|
|
+ //达到比例也重新计算
|
|
|
|
|
|
-func FindPosition1(positionId int64, trailstatus string) (bool, map[string]interface{}, []map[string]interface{}) {
|
|
|
|
|
|
+}
|
|
|
|
+func FindPosition(positionId int64, trailstatus, creatorTime string) (bool, map[string]interface{}, []map[string]interface{}) {
|
|
allData := []map[string]interface{}{}
|
|
allData := []map[string]interface{}{}
|
|
//查询两个部门高级管理员
|
|
//查询两个部门高级管理员
|
|
//查询两个部门所有人员标识
|
|
//查询两个部门所有人员标识
|
|
@@ -504,9 +392,6 @@ FROM
|
|
id := gconv.Int64(v["position_id"])
|
|
id := gconv.Int64(v["position_id"])
|
|
roleId := gconv.Int64(v["role_id"])
|
|
roleId := gconv.Int64(v["role_id"])
|
|
if id == positionId {
|
|
if id == positionId {
|
|
- if roleId == 8 {
|
|
|
|
- v["orderStatus"] = 2
|
|
|
|
- }
|
|
|
|
administrators = v
|
|
administrators = v
|
|
}
|
|
}
|
|
if roleId == 8 {
|
|
if roleId == 8 {
|
|
@@ -525,9 +410,6 @@ FROM
|
|
id := gconv.Int64(v["position_id"])
|
|
id := gconv.Int64(v["position_id"])
|
|
roleId := gconv.Int64(v["role_id"])
|
|
roleId := gconv.Int64(v["role_id"])
|
|
if id == positionId {
|
|
if id == positionId {
|
|
- if roleId == 8 {
|
|
|
|
- v["orderStatus"] = 2
|
|
|
|
- }
|
|
|
|
administrators = v
|
|
administrators = v
|
|
}
|
|
}
|
|
if roleId == 8 {
|
|
if roleId == 8 {
|
|
@@ -565,45 +447,36 @@ FROM
|
|
deptCount1 := CalculateProportion(deptNameMap1)
|
|
deptCount1 := CalculateProportion(deptNameMap1)
|
|
//三部查询
|
|
//三部查询
|
|
deptCount3 := CalculateProportion(deptNameMap3)
|
|
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
|
|
|
|
- }
|
|
|
|
|
|
+ return true, GetAllocation(proportion1, proportion3, deptCount1, deptCount3, administrators1, administrators3, creatorTime), allData
|
|
log.Println("电销信息获取失败", positionId)
|
|
log.Println("电销信息获取失败", positionId)
|
|
return false, map[string]interface{}{}, allData
|
|
return false, map[string]interface{}{}, allData
|
|
}
|
|
}
|
|
|
|
|
|
-func CalculateProportion(deptNameMap map[string]interface{}) float64 {
|
|
|
|
|
|
+func CalculateProportion(deptNameMap map[string]interface{}) int64 {
|
|
deptNameStr := ""
|
|
deptNameStr := ""
|
|
for k := range deptNameMap {
|
|
for k := range deptNameMap {
|
|
if deptNameStr == "" {
|
|
if deptNameStr == "" {
|
|
deptNameStr = k
|
|
deptNameStr = k
|
|
} else {
|
|
} else {
|
|
- deptNameStr = fmt.Sprintf("%s%s", deptNameStr, k)
|
|
|
|
|
|
+ deptNameStr = fmt.Sprintf("%s,%s", deptNameStr, k)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if deptNameStr == "" {
|
|
if deptNameStr == "" {
|
|
- return float64(0)
|
|
|
|
|
|
+ return int64(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, "")
|
|
|
|
|
|
+ count := int64(0)
|
|
|
|
+ sql := fmt.Sprintf(`SELECT
|
|
|
|
+ sum(1) as count
|
|
|
|
+FROM
|
|
|
|
+ order_work a
|
|
|
|
+ INNER JOIN approval_record b ON a.creator_time > "%s"
|
|
|
|
+ AND FIND_IN_SET( a.department_no , "%s")
|
|
|
|
+ AND a.work_order_no = b.work_order_no
|
|
|
|
+ and (b.new_status!= 1 or b.new_status is null )
|
|
|
|
+ `, cfg.AllocationTime, deptNameStr)
|
|
|
|
+ data := WorkOrder.SelectBySql(sql)
|
|
if data != nil && len(*data) > 0 {
|
|
if data != nil && len(*data) > 0 {
|
|
- count = gconv.Float64((*data)[0]["count"])
|
|
|
|
|
|
+ count = gconv.Int64((*data)[0]["count"])
|
|
}
|
|
}
|
|
return count
|
|
return count
|
|
}
|
|
}
|