|
@@ -1,6 +1,7 @@
|
|
|
package main
|
|
|
|
|
|
import (
|
|
|
+ "app.yhyue.com/moapp/jybase/redis"
|
|
|
"fmt"
|
|
|
"log"
|
|
|
"strings"
|
|
@@ -13,10 +14,10 @@ import (
|
|
|
"app.yhyue.com/moapp/jybase/mongodb"
|
|
|
)
|
|
|
|
|
|
-/*// 电销工单生成
|
|
|
+// 电销工单生成
|
|
|
func rderAcceptance() {
|
|
|
sql := fmt.Sprintf(`select * from order_acceptance where is_clue=2 order by propose_time `)
|
|
|
- data := Mysql.SelectBySql(sql)
|
|
|
+ data := WorkOrder.SelectBySql(sql)
|
|
|
if data != nil && len(*data) > 0 {
|
|
|
for _, v := range *data {
|
|
|
acceptance_no := gconv.String(v["acceptance_no"])
|
|
@@ -27,24 +28,31 @@ func rderAcceptance() {
|
|
|
company := ""
|
|
|
phone := ""
|
|
|
demand := ""
|
|
|
+ name := ""
|
|
|
+ product := ""
|
|
|
for _, v1 := range *childrenArr {
|
|
|
- if gconv.String(v1["file_name"]) == "公司名称" {
|
|
|
- company = gconv.String(v1["file_value"])
|
|
|
+ if gconv.String(v1["field_name"]) == "公司名称" {
|
|
|
+ company = gconv.String(v1["field_value"])
|
|
|
+ }
|
|
|
+ if gconv.String(v1["field_name"]) == "联系方式num" {
|
|
|
+ phone = gconv.String(v1["field_value"])
|
|
|
}
|
|
|
- if gconv.String(v1["file_name"]) == "联系方式" {
|
|
|
- phone = gconv.String(v1["file_value"])
|
|
|
+ if gconv.String(v1["field_name"]) == "客户姓名" {
|
|
|
+ name = gconv.String(v1["field_value"])
|
|
|
}
|
|
|
- if gconv.String(v1["file_name"]) == "客户需求" {
|
|
|
- demand = gconv.String(v1["file_value"])
|
|
|
+ if gconv.String(v1["field_name"]) == "客户需求" {
|
|
|
+ demand = gconv.String(v1["field_value"])
|
|
|
+ }
|
|
|
+ if gconv.String(v1["field_name"]) == "咨询产品" {
|
|
|
+ product = gconv.String(v1["field_value"])
|
|
|
}
|
|
|
}
|
|
|
- WorkDataHandle(company, phone, demand)
|
|
|
+ WorkDataHandle(company, phone, demand, name, product, v)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-}*/
|
|
|
-/*func WorkDataHandle(company, phone, demand string) bool {
|
|
|
- positionId, seatNumber, saleNam := AutoDrawPerson(company, phone, demand)
|
|
|
+}
|
|
|
+func WorkDataHandle(company, phone, demand, name, product string, acceptanceData map[string]interface{}) bool {
|
|
|
uId := ""
|
|
|
query := map[string]interface{}{}
|
|
|
contactsData := TiDb.SelectBySql("select * from dwd_f_userbase_contacts where phone = ? and is_delete = 1", phone)
|
|
@@ -57,26 +65,209 @@ func rderAcceptance() {
|
|
|
if uId == "" {
|
|
|
return false
|
|
|
}
|
|
|
+ cluename := company
|
|
|
+ if cluename == "" {
|
|
|
+ cluename = phone //没有线索名,手机号代替
|
|
|
+ }
|
|
|
+ ok, data, saleData := false, map[string]interface{}{}, []map[string]interface{}{}
|
|
|
+ isGroup, isCommerce := GetCompanyType(cluename)
|
|
|
uCount, _ := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"uid": uId}, "", ""), true //查当前线索是否已存在
|
|
|
if uCount != nil && len(*uCount) > 0 {
|
|
|
positionId := gconv.Int64((*uCount)["position_id"])
|
|
|
if positionId == 0 {
|
|
|
//线索变更
|
|
|
+ ok, data, saleData = FindPosition(positionId, "")
|
|
|
+ if !ok {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ UpdateClue(*uCount, saleData, "", "", uId, "", "", "", "", company, name, gconv.String(data["name"]), phone, "", "", "", "", "", "", gconv.String(data["seat_number"]), "", gconv.Int64(data["position_id"]), "", "", "", []string{}, "", isGroup, isCommerce, true, demand)
|
|
|
} else {
|
|
|
trailstatusl := gconv.String((*uCount)["trailstatusl"])
|
|
|
- if trailstatusl == "" {
|
|
|
+ if trailstatusl == "01" || trailstatusl == "03" || trailstatusl == "04" {
|
|
|
//变更销售员
|
|
|
} else {
|
|
|
//线索变更
|
|
|
+ ok, data, saleData = FindPosition(positionId, trailstatusl)
|
|
|
+ if !ok {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ UpdateClue(*uCount, saleData, "", "", uId, "", "", "", "", company, name, gconv.String(data["name"]), phone, "", "", "", "", "", "", gconv.String(data["seat_number"]), "", gconv.Int64(data["position_id"]), "", "", "", []string{}, "", isGroup, isCommerce, true, demand)
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
//新增线索
|
|
|
-
|
|
|
+ ok, data, _ = FindPosition(0, "")
|
|
|
+ if !ok {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ SaveClue("", "", uId, "", "", "", "", cluename, name, gconv.String(data["name"]), phone, "", "", "", "", "", "", gconv.String(data["seat_number"]), gconv.Int64(data["position_id"]), "", "", "", []string{}, "", isGroup, isCommerce, false, demand)
|
|
|
}
|
|
|
+ //工单生成
|
|
|
+ AddOrderWork(acceptanceData, data, product)
|
|
|
return true
|
|
|
}
|
|
|
-func FindPosition(positionId int64) int64 {
|
|
|
+func AddOrderWork(acceptanceData map[string]interface{}, userData map[string]interface{}, product string) {
|
|
|
+ nowTime := time.Now().Format(date.Date_Full_Layout)
|
|
|
+ work_order_no := fmt.Sprintf("GD%s%s", time.Now().Format(date.Date_Short_Layout), FindNumber("gd"))
|
|
|
+ productArr := []string{}
|
|
|
+ for _, v := range strings.Split(product, ",") {
|
|
|
+ switch ProductMap[v] {
|
|
|
+ case "dk":
|
|
|
+ continue
|
|
|
+ default:
|
|
|
+ productArr = append(productArr, v)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ orderWorkMap := map[string]interface{}{
|
|
|
+ "work_order_no": work_order_no,
|
|
|
+ "acceptance_no": gconv.String(acceptanceData["acceptance_no"]),
|
|
|
+ "type": strings.Join(productArr, ","),
|
|
|
+ "status": 1,
|
|
|
+ "initiator_name": gconv.String(acceptanceData["creator_name"]),
|
|
|
+ "initiator_position_id": gconv.String(acceptanceData["initiator_position_id"]),
|
|
|
+ "current_name": userData["name"],
|
|
|
+ "current_position_id": userData["position_id"],
|
|
|
+ "is_delete": 1,
|
|
|
+ "creator_name": gconv.String(acceptanceData["creator_name"]),
|
|
|
+ "creator_position_id": gconv.String(acceptanceData["gconv.String(acceptanceData[\"department_name\"])"]),
|
|
|
+ "creator_time": nowTime,
|
|
|
+ "two_type": "dx",
|
|
|
+ "department_no": gconv.String(acceptanceData["department_no"]),
|
|
|
+ "department_name": gconv.String(acceptanceData["department_name"]),
|
|
|
+ }
|
|
|
+ ok3 := WorkOrder.Insert("order_work", orderWorkMap)
|
|
|
+ if ok3 > 0 {
|
|
|
+ WorkOrder.Update("order_acceptance", map[string]interface{}{
|
|
|
+ "id": acceptanceData["id"],
|
|
|
+ }, map[string]interface{}{
|
|
|
+ "is_clue": 3,
|
|
|
+ })
|
|
|
+ //发送邮件
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// 编号查询
|
|
|
+func FindNumber(moudle string) string {
|
|
|
+ today := time.Now().Format("2006-01-02")
|
|
|
+ yesterday := time.Now().AddDate(0, 0, -1).Format("2006-01-02")
|
|
|
+ key := fmt.Sprintf("%s_%s", today, moudle)
|
|
|
+ yesterdayKey := fmt.Sprintf("%s_%s", yesterday, moudle)
|
|
|
+ if ok, _ := redis.Exists("newother", yesterdayKey); ok {
|
|
|
+ //删除之前数据
|
|
|
+ redis.Del("newother", yesterdayKey)
|
|
|
+ }
|
|
|
+ count := redis.Incr("newother", key)
|
|
|
+ return fmt.Sprintf("%04d", count)
|
|
|
+}
|
|
|
+
|
|
|
+/*func updateClue(uCount *map[string]interface{}, company, phone, demand, name string, position string, administrators map[string]interface{}) {
|
|
|
+ clueId := gconv.Int64((*uCount)["id"])
|
|
|
+ oldCompany := gconv.String((*uCount)["oldCompany"])
|
|
|
+ oldPhone := gconv.String((*uCount)["oldPhone"])
|
|
|
+ oldDemand := gconv.String((*uCount)["oldDemand"])
|
|
|
+ oldName := gconv.String((*uCount)["oldName"])
|
|
|
+ nowTime := time.Now().Format(date.Date_Full_Layout)
|
|
|
+ old_position := gconv.String((*uCount)["position_id"])
|
|
|
+ updateData := map[string]interface{}{}
|
|
|
+ if company != "" && company != oldCompany {
|
|
|
+ updateData["cluename"] = company
|
|
|
+ TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
+ "clue_id": clueId,
|
|
|
+ "position_id": common.If(position != "", position, "-1"),
|
|
|
+ "change_field": "cluename",
|
|
|
+ "change_type": "基本信息变更",
|
|
|
+ "old_value": oldCompany,
|
|
|
+ "new_value": company,
|
|
|
+ "createtime": nowTime,
|
|
|
+ "BCPCID": common.GetRandom(32),
|
|
|
+ "operator_id": -1,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if phone != "" && phone != oldPhone {
|
|
|
+ updateData["phone"] = phone
|
|
|
+ TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
+ "clue_id": clueId,
|
|
|
+ "position_id": common.If(position != "", position, "-1"),
|
|
|
+ "change_field": "phone",
|
|
|
+ "change_type": "基本信息变更",
|
|
|
+ "old_value": oldPhone,
|
|
|
+ "new_value": phone,
|
|
|
+ "createtime": nowTime,
|
|
|
+ "BCPCID": common.GetRandom(32),
|
|
|
+ "operator_id": -1,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if name != "" && name != oldName {
|
|
|
+ updateData["name"] = name
|
|
|
+ TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
+ "clue_id": clueId,
|
|
|
+ "position_id": common.If(position != "", position, "-1"),
|
|
|
+ "change_field": "name",
|
|
|
+ "change_type": "基本信息变更",
|
|
|
+ "old_value": oldName,
|
|
|
+ "new_value": name,
|
|
|
+ "createtime": nowTime,
|
|
|
+ "BCPCID": common.GetRandom(32),
|
|
|
+ "operator_id": -1,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if demand != "" && demand != oldDemand {
|
|
|
+ updateData["demand"] = demand
|
|
|
+ TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
+ "clue_id": clueId,
|
|
|
+ "position_id": common.If(position != "", position, "-1"),
|
|
|
+ "change_field": "demand",
|
|
|
+ "change_type": "基本信息变更",
|
|
|
+ "old_value": oldDemand,
|
|
|
+ "new_value": demand,
|
|
|
+ "createtime": nowTime,
|
|
|
+ "BCPCID": common.GetRandom(32),
|
|
|
+ "operator_id": -1,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if old_position != position && position != "" {
|
|
|
+ //员工更改
|
|
|
+ updateData["position_id"] = position
|
|
|
+ updateData["seatNumber"] = "seatNumber"
|
|
|
+ TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
+ "clue_id": clueId,
|
|
|
+ "change_field": "position",
|
|
|
+ "position_id": 0,
|
|
|
+ "change_type": "基本信息变更",
|
|
|
+ "old_value": common.If(old_position != "", old_position, "/"),
|
|
|
+ "new_value": common.If(position != "", position, "/"),
|
|
|
+ "createtime": nowTime,
|
|
|
+ "BCPCID": common.GetRandom(32),
|
|
|
+ "operator_id": -1})
|
|
|
+ TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
+ "clue_id": clueId,
|
|
|
+ "change_field": "position",
|
|
|
+ "position_id": 0,
|
|
|
+ "change_type": "基本信息变更",
|
|
|
+ "old_value": common.If(old_position != "", old_position, "/"),
|
|
|
+ "new_value": common.If(position != "", position, "/"),
|
|
|
+ "createtime": nowTime,
|
|
|
+ "BCPCID": common.GetRandom(32),
|
|
|
+ "operator_id": -1})
|
|
|
+ }
|
|
|
+ if updateData != nil {
|
|
|
+ TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{
|
|
|
+ "uid": clueId,
|
|
|
+ },
|
|
|
+ updateData)
|
|
|
+ }
|
|
|
+}
|
|
|
+*/
|
|
|
+// 人员查询
|
|
|
+func FindPosition(positionId int64, trailstatusl string) (bool, map[string]interface{}, []map[string]interface{}) {
|
|
|
+ allData := []map[string]interface{}{}
|
|
|
+ full := false
|
|
|
+ //查询是否满了
|
|
|
+ if positionId != 0 {
|
|
|
+ if FindUpperLimit(gconv.String(positionId), "", false) {
|
|
|
+ full = true
|
|
|
+ }
|
|
|
+ }
|
|
|
//查询两个部门高级管理员
|
|
|
//查询两个部门所有人员标识
|
|
|
//电销三部
|
|
@@ -103,54 +294,113 @@ FROM
|
|
|
AND a.dept_name LIKE "%销售三部"
|
|
|
AND a.position_id = b.position_id`)
|
|
|
if userData3 == nil || len(*userData3) == 0 || userData1 == nil || len(*userData1) == 0 {
|
|
|
- return 0
|
|
|
+ return false, map[string]interface{}{}, allData
|
|
|
}
|
|
|
+ //一部管理员信息
|
|
|
administrators1 := map[string]interface{}{}
|
|
|
+ //三部管理员信息
|
|
|
administrators3 := map[string]interface{}{}
|
|
|
+ //返回当前人信息
|
|
|
administrators := map[string]interface{}{}
|
|
|
//电销一部
|
|
|
- positionIdArr1 := []int64{}
|
|
|
- positionIdArr3 := []int64{}
|
|
|
+ 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 personName == "孙鹏" {
|
|
|
- administrators3 = v
|
|
|
+ if id == positionId && full {
|
|
|
administrators = v
|
|
|
}
|
|
|
- if id == positionId {
|
|
|
- administrators = v
|
|
|
+ if personName == "孙鹏" {
|
|
|
+ administrators3 = v
|
|
|
+ proportion3 += 0.5
|
|
|
+ } else {
|
|
|
+ proportion3 += 1
|
|
|
}
|
|
|
- positionIdArr3 = append(positionIdArr3, id)
|
|
|
+ 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 && full {
|
|
|
+ administrators = v
|
|
|
+ }
|
|
|
if personName == "沈炳毅" {
|
|
|
administrators1 = v
|
|
|
-
|
|
|
+ proportion1 += 0.5
|
|
|
+ } else {
|
|
|
+ proportion1 += 1
|
|
|
}
|
|
|
-
|
|
|
- positionIdArr1 = append(positionIdArr1, id)
|
|
|
+ positionIdArr1 = append(positionIdArr1, gconv.String(id))
|
|
|
+ allData = append(allData, v)
|
|
|
}
|
|
|
if positionId != 0 {
|
|
|
positiontype := gconv.Int64(administrators["type"])
|
|
|
- isBool := false
|
|
|
- if FindUpperLimit(gconv.String(positionId), "", false) {
|
|
|
- if positiontype == 1 {
|
|
|
- administrators1
|
|
|
- } else {
|
|
|
- administrators1
|
|
|
+ if full {
|
|
|
+ switch positiontype {
|
|
|
+ case 1:
|
|
|
+ if trailstatusl == "01" || trailstatusl == "03" || trailstatusl == "04" {
|
|
|
+ //找他上级
|
|
|
+ positionId1 := gconv.String(administrators1["position_id"])
|
|
|
+ administrators = administrators1
|
|
|
+ if FindUpperLimit(positionId1, "", false) {
|
|
|
+ return false, map[string]interface{}{}, allData
|
|
|
+ }
|
|
|
+ }
|
|
|
+ case 3:
|
|
|
+ if trailstatusl == "01" || trailstatusl == "03" || trailstatusl == "04" {
|
|
|
+ //找他上级
|
|
|
+ positionId1 := gconv.String(administrators3["position_id"])
|
|
|
+ administrators = administrators3
|
|
|
+ if FindUpperLimit(positionId1, "", false) {
|
|
|
+ return false, map[string]interface{}{}, allData
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
} else {
|
|
|
-
|
|
|
+ return true, administrators, allData
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ //按照比例分配选择一部还是三部
|
|
|
+ //一部查询
|
|
|
+ deptCount1 := CalculateProportion(strings.Join(positionIdArr1, ","), "", 1)
|
|
|
+ //三部查询
|
|
|
+ deptCount3 := CalculateProportion(strings.Join(positionIdArr3, ","), "", 1)
|
|
|
+ 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 false, map[string]interface{}{}, allData
|
|
|
}
|
|
|
-*/
|
|
|
+func CalculateProportion(positionIsStr, createTime string, proportion float64) float64 {
|
|
|
+ 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)
|
|
|
+ if data != nil && len(*data) > 0 {
|
|
|
+ count = gconv.Float64((*data)[0]["count"])
|
|
|
+ }
|
|
|
+ return count
|
|
|
+}
|
|
|
+
|
|
|
// 未支付订单 30分钟一次
|
|
|
func orders() {
|
|
|
//一个小时未支付进入线索 A
|