WH01243 1 سال پیش
والد
کامیت
daa7559f72
4فایلهای تغییر یافته به همراه165 افزوده شده و 116 حذف شده
  1. 1 0
      clueSync/config.go
  2. 3 2
      clueSync/config.json
  3. 135 114
      clueSync/jobutil.go
  4. 26 0
      clueSync/sendMail.go

+ 1 - 0
clueSync/config.go

@@ -143,6 +143,7 @@ type (
 		NameToMail    map[string]string `json:"nameToMail"`
 		ThawDay       int64             `json:"thawDay"`
 		ProductArr    []string          `json:"productArr"`
+		LoopType      int64             `json:"loopType"`
 	}
 )
 

+ 3 - 2
clueSync/config.json

@@ -22,7 +22,7 @@
   "xlsxNum": "1",
   "countLimit": 1000,
   "regTimes": 7,
-  "redisServer": "192.168.3.206:1712",
+  "redisServer": "bidx=192.168.3.206:1712,newother=192.168.3.149:1712",
   "tiDb": {
     "host": "192.168.3.149",
     "port": 4000,
@@ -138,5 +138,6 @@
     "结构化数据",
     "API接口",
     "广告服务"
-  ]
+  ],
+  "loopType": 1
 }

+ 135 - 114
clueSync/jobutil.go

@@ -16,7 +16,7 @@ import (
 
 // 电销工单生成
 func rderAcceptance() {
-	sql := fmt.Sprintf(`select * from order_acceptance where is_clue=2 order by propose_time  `)
+	sql := fmt.Sprintf(`select * from order_acceptance where is_clue=2 and  is_delete=1 order by propose_time  `)
 	data := WorkOrder.SelectBySql(sql)
 	if data != nil && len(*data) > 0 {
 		for _, v := range *data {
@@ -73,10 +73,11 @@ func WorkDataHandle(company, phone, demand, name, product string, acceptanceData
 	isGroup, isCommerce := GetCompanyType(cluename)
 	uCount, _ := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"uid": uId}, "", ""), true //查当前线索是否已存在
 	if uCount != nil && len(*uCount) > 0 {
+		clueId := gconv.Int64((*uCount)["id"])
 		positionId := gconv.Int64((*uCount)["position_id"])
 		if positionId == 0 {
 			//线索变更
-			ok, data, saleData = FindPosition(positionId, "")
+			ok, data, saleData = FindPosition(positionId, "", false)
 			if !ok {
 				return false
 			}
@@ -85,9 +86,29 @@ func WorkDataHandle(company, phone, demand, name, product string, acceptanceData
 			trailstatusl := gconv.String((*uCount)["trailstatusl"])
 			if trailstatusl == "01" || trailstatusl == "03" || trailstatusl == "04" {
 				//变更销售员
+				ok, data, saleData = FindPosition(positionId, "", false)
+				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 if trailstatusl == "08" {
+				//客成
+				//查找客成人员标识
+				customerMap := TiDb.FindOne("dwd_f_csm_customer_info", map[string]interface{}{
+					"clue_id": clueId,
+				}, "position_id", "")
+				if customerMap != nil && len(*customerMap) > 0 {
+					UpdateClue(*uCount, saleData, "", "", uId, "", "", "", "", company, name, gconv.String((*uCount)["name"]), phone, "", "", "", "", "", "", gconv.String((*uCount)["seat_number"]), "", gconv.Int64((*uCount)["position_id"]), "", "", "", []string{}, "", isGroup, isCommerce, true, demand)
+					data = map[string]interface{}{
+						"type":        "kc",
+						"position_id": (*customerMap)["position_id"],
+						"name":        (*customerMap)["name"],
+					}
+				}
+
 			} else {
 				//线索变更
-				ok, data, saleData = FindPosition(positionId, trailstatusl)
+				ok, data, saleData = FindPosition(positionId, trailstatusl, false)
 				if !ok {
 					return false
 				}
@@ -96,17 +117,17 @@ func WorkDataHandle(company, phone, demand, name, product string, acceptanceData
 		}
 	} else {
 		//新增线索
-		ok, data, _ = FindPosition(0, "")
+		ok, data, _ = FindPosition(0, "", false)
 		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)
+	AddOrderWork(acceptanceData, data, product, phone, company)
 	return true
 }
-func AddOrderWork(acceptanceData map[string]interface{}, userData map[string]interface{}, product string) {
+func AddOrderWork(acceptanceData map[string]interface{}, userData map[string]interface{}, product, phone, company string) bool {
 	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{}
@@ -122,14 +143,14 @@ func AddOrderWork(acceptanceData map[string]interface{}, userData map[string]int
 		"work_order_no":         work_order_no,
 		"acceptance_no":         gconv.String(acceptanceData["acceptance_no"]),
 		"type":                  strings.Join(productArr, ","),
-		"status":                1,
+		"status":                common.If(gconv.Int64(userData["orderStatus"]) == 0, 1, 2),
 		"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_position_id":   gconv.String(acceptanceData["creator_position_id"]),
 		"creator_time":          nowTime,
 		"two_type":              "dx",
 		"department_no":         gconv.String(acceptanceData["department_no"]),
@@ -143,7 +164,83 @@ func AddOrderWork(acceptanceData map[string]interface{}, userData map[string]int
 			"is_clue": 3,
 		})
 		//发送邮件
+		personMap := GetPerson(gconv.String(userData["position_id"]))
+		if personMap == nil || len(personMap) == 0 {
+			return false
+		}
+		WorkMail(personMap,
+			strings.Join(productArr, ","),
+			gconv.Int64(common.If(gconv.Int64(userData["orderStatus"]) == 0, 1, 2)),
+			gconv.String(personMap["name"]),
+			gconv.String(acceptanceData["creator_name"]),
+			nowTime,
+			gconv.String(acceptanceData["acceptance_no"]),
+			phone,
+			company)
+		return true
 	}
+
+	return false
+}
+
+// 本级以及上级管理员查询
+func GetPerson(positionId string) map[string]interface{} {
+	person := map[string]interface{}{}
+	positionArrMap := Base.SelectBySql(fmt.Sprintf(`select  a.phone,b.id,b.ent_id from  
+                         base_user  a  
+                             INNER JOIN   base_position  b     
+                                 on     b.id=%s  and  b.user_id=a.id and   b.type=1`,
+		positionId))
+	if positionArrMap == nil || len(*positionArrMap) == 0 {
+		return map[string]interface{}{}
+	}
+	phone := gconv.String((*positionArrMap)[0]["phone"])
+	entId := gconv.String((*positionArrMap)[0]["ent_id"])
+	entUserArrMap := Mysql.SelectBySql(fmt.Sprintf(`SELECT
+	a.name as  name,a.mail as mail,b.dept_id as  deptId,a.phone
+FROM
+	entniche_user a
+	INNER JOIN entniche_department_user b ON a.ent_id =%s
+	AND a.phone IN %s
+	and  a.id=b.user_id`, entId, fmt.Sprintf("(%s)", phone)))
+	//商机管理员
+	if entUserArrMap == nil || len(*entUserArrMap) == 0 {
+		return map[string]interface{}{}
+	}
+	deptId := gconv.Int64((*entUserArrMap)[0]["deptId"])
+	person = map[string]interface{}{
+		"name":  gconv.String((*entUserArrMap)[0]["name"]),
+		"mail":  gconv.String((*entUserArrMap)[0]["mail"]),
+		"phone": gconv.String((*entUserArrMap)[0]["phone"]),
+	}
+	//本部门管理员查询
+	depthMap := Mysql.SelectBySql(`SELECT
+		c.name as name,c.mail as  mail
+		FROM
+			entniche_department_user a
+			INNER JOIN entniche_user_role b ON a.dept_id = ? 
+			AND a.user_id = b.user_id 
+			AND b.role_id =2
+			INNER JOIN entniche_user c ON a.user_id = c.id`, deptId)
+	if depthMap != nil && len(*depthMap) > 0 {
+		person["deptPersonName"] = gconv.String((*depthMap)[0]["name"])
+		person["deptPersonMail"] = gconv.String((*depthMap)[0]["mail"])
+	}
+	//商机管理员查询
+	superiorDepthMap := Mysql.SelectBySql(`SELECT
+	c.* 
+FROM
+	entniche_department d
+	INNER JOIN entniche_department_user a ON d.id = ? 
+	AND d.pid = a.dept_id
+	INNER JOIN entniche_user_role b ON a.user_id = b.user_id 
+	AND b.role_id = 1
+	INNER JOIN entniche_user c ON a.user_id = c.id`, deptId)
+	if superiorDepthMap != nil && len(*superiorDepthMap) > 0 {
+		person["superiorDepthPersonName"] = gconv.String((*superiorDepthMap)[0]["name"])
+		person["superiorDepthPersonMail"] = gconv.String((*superiorDepthMap)[0]["mail"])
+	}
+	return person
 }
 
 // 编号查询
@@ -160,108 +257,9 @@ func FindNumber(moudle string) string {
 	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{}) {
+func FindPosition(positionId int64, trailstatusl string, full bool) (bool, map[string]interface{}, []map[string]interface{}) {
 	allData := []map[string]interface{}{}
-	full := false
 	//查询是否满了
 	if positionId != 0 {
 		if FindUpperLimit(gconv.String(positionId), "", false) {
@@ -311,10 +309,14 @@ FROM
 		v["type"] = 3
 		personName := gconv.String(v["name"])
 		id := gconv.Int64(v["position_id"])
-		if id == positionId && full {
+		if id == positionId && !full {
+			if personName == "孙鹏" {
+				v["orderStatus"] = 2
+			}
 			administrators = v
 		}
 		if personName == "孙鹏" {
+			v["orderStatus"] = 2
 			administrators3 = v
 			proportion3 += 0.5
 		} else {
@@ -327,10 +329,14 @@ FROM
 		v["type"] = 1
 		personName := gconv.String(v["name"])
 		id := gconv.Int64(v["position_id"])
-		if id == positionId && full {
+		if id == positionId && !full {
+			if personName == "沈炳毅" {
+				v["orderStatus"] = 2
+			}
 			administrators = v
 		}
 		if personName == "沈炳毅" {
+			v["orderStatus"] = 2
 			administrators1 = v
 			proportion1 += 0.5
 		} else {
@@ -340,6 +346,9 @@ FROM
 		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 full {
 			switch positiontype {
@@ -368,9 +377,9 @@ FROM
 	}
 	//按照比例分配选择一部还是三部
 	//一部查询
-	deptCount1 := CalculateProportion(strings.Join(positionIdArr1, ","), "", 1)
+	deptCount1 := CalculateProportion(strings.Join(positionIdArr1, ","))
 	//三部查询
-	deptCount3 := CalculateProportion(strings.Join(positionIdArr3, ","), "", 1)
+	deptCount3 := CalculateProportion(strings.Join(positionIdArr3, ","))
 	if deptCount1 == 0 {
 		return true, administrators1, allData
 	}
@@ -384,7 +393,19 @@ FROM
 	}
 	return false, map[string]interface{}{}, allData
 }
-func CalculateProportion(positionIsStr, createTime string, proportion float64) float64 {
+func CalculateProportion(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)
+	}
 	count := float64(0)
 	sql := `SELECT
 			sum(1) as  count
@@ -394,7 +415,7 @@ func CalculateProportion(positionIsStr, createTime string, proportion float64) f
 			  FIND_IN_SET(current_position_id ,?) 
 			AND is_delete=1
 			and   creator_time>?`
-	data := WorkOrder.SelectBySql(sql, positionIsStr, createTime)
+	data := WorkOrder.SelectBySql(sql, positionIsStr, createtime.Format("2006-01-02"))
 	if data != nil && len(*data) > 0 {
 		count = gconv.Float64((*data)[0]["count"])
 	}

+ 26 - 0
clueSync/sendMail.go

@@ -4,6 +4,7 @@ import (
 	"app.yhyue.com/moapp/jybase/common"
 	"app.yhyue.com/moapp/jybase/mail"
 	"fmt"
+	"github.com/gogf/gf/v2/util/gconv"
 	"log"
 	"strings"
 )
@@ -162,6 +163,29 @@ func WillWarningByPp(posid int64) {
 	sendInfo(toMail, toCc, title, content)
 }
 
+func WorkMail(personMap map[string]interface{}, productStr string, orderStatus int64, personName1, personName2, createTimeStr, acceptance_no, phone, company string) {
+	orderType := fmt.Sprintf(`客户咨询线索(%s)`, productStr)
+	title := fmt.Sprintf("%s通知", orderType)
+	if personName1 == gconv.String(personMap["deptPersonName"]) {
+		personMap["deptPersonMail"] = ""
+	}
+	if personName1 == gconv.String(personMap["superiorDepthPersonName"]) {
+		personMap["superiorDepthPersonMail"] = ""
+	}
+	content := ""
+	if orderStatus == 1 {
+		content = fmt.Sprintf(`%s,您好,“%s”于%s新增了1条"%s”(工单编号:%s)%s%s,请及时前往【剑鱼PC工作台-任务单-工单管理-我负责的】进行工单处理。`, personName1, personName2, createTimeStr, orderType, acceptance_no, gconv.String(common.If(phone == "", "", fmt.Sprintf(`,客户联系方式为:%s`, phone))), gconv.String(common.If(company == "", "", fmt.Sprintf(`,公司名称:%s`, company))))
+	} else if orderStatus == 2 {
+		content = fmt.Sprintf(`%s,您好,“%s”于%s新增了1条"%s”(工单编号:%s)%s%s,请及时前往【电销系统-私海线索】或【客户成功系统-我的个人客户】及时联系客户进行线索跟进。您也可前往【剑鱼PC工作台-任务单-工单管理-我负责的】查看关联工单,系统已自动办结此工单。`, personName1, personName2, createTimeStr, orderType, acceptance_no, gconv.String(common.If(phone == "", "", fmt.Sprintf(`,客户联系方式为:%s`, phone))), gconv.String(common.If(company == "", "", fmt.Sprintf(`,公司名称:%s`, company))))
+	}
+	toMail := gconv.String(personMap["mail"])
+	toCc := fmt.Sprintf("%s%s", gconv.String(common.If(gconv.String(personMap["deptPersonMail"]) == "", "", gconv.String(personMap["deptPersonMail"]))), gconv.String(common.If(gconv.String(personMap["superiorDepthPersonMail"]) == "", "", gconv.String(personMap["superiorDepthPersonMail"]))))
+	log.Println(toMail, toCc, title, content)
+	toMail = "wanghao@topnet.net.cn"
+	toCc = "wanghao@topnet.net.cn"
+	sendInfo(toMail, toCc, title, content)
+}
+
 // @Author jianghan
 // @Description 部门人员私海线索即将达到预警提醒
 // @Date 2024/4/10
@@ -386,6 +410,8 @@ func getCc(posid int64) (to string) {
 				to = getMailAds(common.ObjToString((*m)[0]["mail"]), common.ObjToString((*m)[0]["name"]))
 			}
 		}
+	} else if common.ObjToString((*info)[0]["dept_name"]) == "销售三部" {
+
 	} else {
 		if common.IntAll((*info)[0]["role_id"]) == 1 || common.IntAll((*info)[0]["role_id"]) == 2 {
 			m := TiDb.SelectBySql(topMail, posid)