فهرست منبع

Merge branch 'dev/v1.5.2_wjh' into feature/v1.5.2

* dev/v1.5.2_wjh:
  邮件提醒
Jianghan 1 سال پیش
والد
کامیت
8470f842f4
1فایلهای تغییر یافته به همراه278 افزوده شده و 0 حذف شده
  1. 278 0
      clueSync/sendMail.go

+ 278 - 0
clueSync/sendMail.go

@@ -0,0 +1,278 @@
+package main
+
+import (
+	"app.yhyue.com/moapp/jybase/common"
+	"app.yhyue.com/moapp/jybase/mail"
+	"fmt"
+	"log"
+)
+
+var (
+	WarningSize = 350
+	LimitSize   = 400
+
+	selfMail = `SELECT b.mail FROM jianyu.entniche_user b WHERE b.id IN (SELECT a.ent_user_id FROM jianyu_subjectdb_test.dwd_d_crm_department_level_succbi a WHERE a.position_id = ?)`
+	infoSelf = `SELECT a.name, a.SZ_PID1, a.SZ_PID2, a.dept_name, b.role_id FROM jianyu_subjectdb_test.dwd_d_crm_department_level_succbi a INNER JOIN jianyu_subjectdb_test.dwd_f_crm_personnel_management b ON b.position_id = a.position_id WHERE a.position_id = ? AND a.resign = 0`
+	topMail  = `SELECT d.mail FROM jianyu.entniche_user d WHERE d.id IN (SELECT b.ent_user_id FROM jianyu_subjectdb.dwd_d_crm_department_level_succbi b INNER JOIN jianyu_subjectdb.dwd_f_crm_personnel_management c
+		ON b.position_id  = c.position_id AND c.resign = 0 WHERE b.SZ_PID3 IN (SELECT a.SZ_PID3 FROM jianyu_subjectdb.dwd_d_crm_department_level_succbi a WHERE a.position_id = ?) AND c.role_id = 3)`
+	topMail3 = `SELECT d.mail FROM jianyu.entniche_user d WHERE d.id IN ( SELECT a.ent_user_id FROM Jianyu_subjectdb.dwd_d_crm_department_level_succbi a INNER JOIN jianyu_subjectdb.dwd_f_crm_personnel_management b
+		ON a.position_id = b.position_id WHERE a.dept_name = '销售三部' AND a.resign = 0 AND b.role_id = 3)`
+	dmInfo = `SELECT b.dept_name FROM Jianyu_subjectdb.dwd_d_crm_department_level_succbi b WHERE b.position_id IN (SELECT a.position_id FROM Jianyu_subjectdb.dwd_f_crm_personnel_management a
+		WHERE assign_type = 1) GROUP BY b.dept_name`
+	dmInfoCount = `SELECT COUNT(*) as num FROM Jianyu_subjectdb.dwd_f_crm_clue_info b WHERE b.position_id IN (SELECT a.position_id FROM Jianyu_subjectdb.dwd_d_crm_department_level_succbi a WHERE dept_name = ? AND resign = 0) GROUP BY b.position_id`
+)
+
+// @Author jianghan
+// @Description 个人预警/上限
+// @Date 2024/4/11
+func WarningPerl() {
+	sql := `SELECT count(*) FROM dwd_f_crm_clue_info where position_id = ? and assign_type >= 1 and trailstatus <> '08'`
+	sql1 := `UPDATE dwd_f_crm_personnel_management where position_id = ? SET send_mail = ?`
+	pp := Mysql.SelectBySql(`SELECT name, position_id, send_mail FROM dwd_f_crm_personnel_management WHERE assign_type >= 1`)
+	if pp != nil && len(*pp) > 0 {
+		for _, m := range *pp {
+			sendFlag := common.IntAll(m["send_mail"])
+			posid := common.Int64All(m["position_id"])
+			count := Mysql.CountBySql(sql, posid)
+			if count >= int64(WarningSize) && sendFlag == 0 {
+				WillWarningByPp(posid) // 发预警邮件
+				_, _ = Mysql.ExecBySql(sql1, posid, 0)
+			} else if count >= int64(LimitSize) && sendFlag == 0 {
+				ExceedLimitByPp(posid) // 发上限邮件
+				_, _ = Mysql.ExecBySql(sql1, posid, 0)
+			} else if sendFlag == 1 { // 已发邮件
+				if count < int64(WarningSize) {
+					_, _ = Mysql.ExecBySql(sql1, posid, 0)
+				}
+			}
+
+		}
+	}
+}
+
+// @Author jianghan
+// @Description 部门预警/上限
+// @Date 2024/5/9
+func WarningDm() {
+	dm := Mysql.SelectBySql(dmInfo)
+	for _, m := range *dm {
+		d1 := common.ObjToString(m["dept_name"])
+		info := Mysql.SelectBySql(dmInfoCount, d1)
+		send1, send2 := true, true // 预警,上限 发送标记
+		for _, m1 := range *info {
+			count := common.IntAll(m1["num"])
+			if count < WarningSize {
+				send1 = false
+			}
+			if count < LimitSize {
+				send2 = false
+			}
+		}
+		if send1 {
+
+		}
+	}
+}
+
+// @Author jianghan
+// @Description 个人私海线索即将达到预警提醒
+// @Date 2024/4/10
+func WillWarningByPp(posid int64) {
+	title := "您的私海线索即将达到上限通知"
+	content := "您的私海线索已超过%d条(不包含成交客户),即将达到私海线索上限%d条(不包含成交客户),请及时将无需跟进的线索退回公海,以避免无法接收新线索。"
+	toMail := ""
+	toCc := ""
+
+	info := Mysql.SelectBySql(selfMail, posid)
+	if info != nil && len(*info) > 0 {
+		toMail = common.ObjToString((*info)[0]["mail"])
+	}
+	if toMail == "" {
+		log.Println("未查询到邮箱地址, position id: ", posid)
+		return
+	}
+	toCc = getCc(posid)
+	content = fmt.Sprintf(content, WarningSize, LimitSize)
+	sendInfo(toMail, toCc, title, content)
+}
+
+// @Author jianghan
+// @Description 部门人员私海线索即将达到预警提醒
+// @Date 2024/4/10
+func WillWarningByDm() {
+	title := "“%s”私海线索即将达到上限通知"
+	content := "“%s”的所有参与线索分配的电销人员,私海线索都已达到%d条(不包含成交客户),即将达到私海线索上限%d条(不包含成交客户),请及时通知电销人员将无需跟进的线索退回公海,以避免无法接收新线索。"
+
+	toMail := ""
+	toCc := ""
+	title = fmt.Sprintf(title, "")
+	content = fmt.Sprintf(content, "", WarningSize, LimitSize)
+
+	// todo
+
+	sendInfo(toMail, toCc, title, content)
+}
+
+// @Author jianghan
+// @Description 所有人私海线索即将达到预警提醒
+// @Date 2024/4/10
+func WillWarningByAll() {
+	title := "所有电销人员私海线索即将达到上限通知"
+	content := "所有参与线上线索自动分配的电销人员,私海线索都已达到%d条,请及时提醒销售部门将无需跟进的销售线索退回公海"
+
+	toMail := ""
+	toCc := ""
+	content = fmt.Sprintf(content, WarningSize)
+	sendInfo(toMail, toCc, title, content)
+}
+
+// @Author jianghan
+// @Description 个人私海线索达到上限提醒
+// @Date 2024/4/10
+func ExceedLimitByPp(posid int64) {
+	title := "您的私海线索已达上限通知"
+	content := "您的私海线索已达到私海线索上限%d条(不包含成交客户),当前无法接收新线索,请及时将无需跟进的线索退回公海"
+
+	toMail := ""
+	toCc := ""
+	content = fmt.Sprintf(content, LimitSize)
+	info := Mysql.SelectBySql(selfMail, posid)
+	if info != nil && len(*info) > 0 {
+		toMail = common.ObjToString((*info)[0]["mail"])
+	}
+	if toMail == "" {
+		log.Println("未查询到邮箱地址, position id: ", posid)
+		return
+	}
+	toCc = getCc(posid)
+	sendInfo(toMail, toCc, title, content)
+}
+
+// @Author jianghan
+// @Description  部门所有人私海线索达到上限提醒
+// @Date 2024/4/10
+func ExceedLimitByDm() {
+	title := "“%s”私海线索已达到上限通知"
+	content := "“%s”的所有参与线索分配的电销人员,私海线索都已达到私海线索上限%d条(不包含成交客户),当前无法接收新线索,请及时通知电销人员将无需跟进的线索退回公海"
+
+	toMail := ""
+	toCc := ""
+	title = fmt.Sprintf(title, "")
+	content = fmt.Sprintf(content, "", LimitSize)
+	sendInfo(toMail, toCc, title, content)
+}
+
+// @Author jianghan
+// @Description	自动释放私海线索通知
+// @Date 2024/4/10
+func AutoReleaseNots() {
+	title := "自动释放私海线索通知"
+	content := "所有参与线上线索自动分配的电销人员,私海线索都已达到%d条,为避免线上产生的新线索无法分配,系统已自动将线索状态为“商机线索(已建联,包含已拨打未接通)”、“潜在客户”、“沉睡客户”的线索退回公海,如有异议请联系销管处理;"
+
+	toMail := ""
+	toCc := ""
+	content = fmt.Sprintf(content, "", LimitSize)
+	gmail := &mail.GmailAuth{
+		SmtpHost: "smtp.exmail.qq.com",
+		SmtpPort: 465,
+		User:     "public03@topnet.net.cn",
+		Pwd:      "ue9Rg9Sf4CVtdm5a",
+	}
+	status := mail.GSendMail("剑鱼标讯", toMail, toCc, "", title, content, "", "", gmail)
+	if status {
+		log.Println("send mail success", title, toMail)
+	}
+}
+
+// @Author jianghan
+// @Description  线上线索无法分配通知
+// @Date 2024/4/10
+func CantBeAssignedNots() {
+	title := "【紧急】线上线索无法分配通知"
+	content := "所有参与线上线索自动分配的电销人员,私海线索都已达到**条,且私海已无“潜在客户”、“沉睡客户”、“商机线索(已建联)”可释放,当前线上线索无法分配,请尽快处理,可前往【公海线索】查看“待分线索”条数"
+
+	toMail := ""
+	toCc := ""
+	gmail := &mail.GmailAuth{
+		SmtpHost: "smtp.exmail.qq.com",
+		SmtpPort: 465,
+		User:     "public03@topnet.net.cn",
+		Pwd:      "ue9Rg9Sf4CVtdm5a",
+	}
+	status := mail.GSendMail("剑鱼标讯", toMail, toCc, "", title, content, "", "", gmail)
+	if status {
+		log.Println("send mail success", title, toMail)
+	}
+}
+
+// @Author jianghan
+// @Description  客成移交线索失败提醒
+// @Date 2024/4/10
+func HandOverFail() {
+	title := "客成线索移交失败通知"
+	content := "您的私海线索已超过**条(不包含成交客户),已达到私海线索上限**条(不包含成交客户),导致“XXX线索名称(XXX手机号)”无法从客成到期自动移交至私海,请及时将无需跟进的线索退回公海,超过3个工作日(根据配置获取)不处理,该线索将自动退回至公海"
+
+	toMail := ""
+	toCc := ""
+	sendInfo(toMail, toCc, title, content)
+}
+
+// @Author jianghan
+// @Description 订单用户创建线索失败提醒
+// @Date 2024/4/10
+func OrderCreateFail() {
+	title := "订单用户创建线索失败通知"
+	content := "您的私海线索已超过**条(不包含成交客户),已达到私海线索上限**条(不包含成交客户),导致订单系统的用户“XXX公司名称(XXX手机号)”无法进入您的私海,请及时将无需跟进的线索退回公海,超过3个工作日(根据配置获取)不处理,该线索将自动进入至公海。"
+
+	toMail := ""
+	toCc := ""
+	sendInfo(toMail, toCc, title, content)
+}
+
+// @Author jianghan
+// @Description 发邮件
+// @Date 2024/5/8
+func sendInfo(to, cs, title, content string) {
+	gmail := &mail.GmailAuth{
+		SmtpHost: "smtp.exmail.qq.com",
+		SmtpPort: 465,
+		User:     "public03@topnet.net.cn",
+		Pwd:      "ue9Rg9Sf4CVtdm5a",
+	}
+	status := mail.GSendMail("剑鱼标讯", to, cs, "", title, content, "", "", gmail)
+	if status {
+		log.Println("send mail success", title, to)
+	}
+}
+
+// @Author jianghan
+// @Description 获取抄送人员邮箱
+//
+//	销售三部 (SZ_PID1=5432)、销售一部(分组)
+//
+// @Date 2024/5/8
+func getCc(posid int64) (to string) {
+	info := Mysql.SelectBySql(infoSelf, posid)
+	if info == nil && len(*info) == 0 {
+		log.Println("为查询到个人信息, positionId: ", posid)
+		return
+	}
+	if common.ObjToString((*info)[0]["dept_name"]) == "销售三部" {
+		if common.IntAll((*info)[0]["role_id"]) == 1 {
+			m := Mysql.SelectBySql(topMail3)
+			if m != nil && len(*m) > 0 {
+				to = common.ObjToString((*m)[0]["mail"])
+			}
+		}
+	} else {
+		if common.IntAll((*info)[0]["role_id"]) == 2 {
+			m := Mysql.SelectBySql(topMail, posid)
+			if m != nil && len(*m) > 0 {
+				to = common.ObjToString((*m)[0]["mail"])
+			}
+		} else {
+			to = "shenbingyi@topnet.net.cn"
+		}
+	}
+	return
+}