|
@@ -5,6 +5,7 @@ import (
|
|
|
"app.yhyue.com/moapp/jybase/mail"
|
|
|
"fmt"
|
|
|
"log"
|
|
|
+ "strings"
|
|
|
)
|
|
|
|
|
|
var (
|
|
@@ -19,7 +20,13 @@ var (
|
|
|
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`
|
|
|
+ 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 HAVING num < ?`
|
|
|
+ dmInfoMail = `SELECT a.*, c.mail, (b.send_mail >> 2) & 1 AS flag_1, (b.send_mail >> 3) & 1 AS flag_2 FROM jianyu_subjectdb_test.dwd_d_crm_department_level_succbi a INNER JOIN jianyu_subjectdb_test.dwd_f_crm_personnel_management b ON a.position_id = b.position_id INNER JOIN jianyu.entniche_user c ON c.id = a.ent_user_id WHERE a.dept_name = ? AND a.resign = 0 AND b.role_id = 3`
|
|
|
+ xgMail = `SELECT c.mail 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 INNER JOIN jianyu.entniche_user c ON c.id = a.ent_user_id WHERE b.role_id = 5 AND b.resign = 0`
|
|
|
+ // 所有参与线索分配人员的邮箱
|
|
|
+ allMail = `SELECT c.mail 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 INNER JOIN jianyu.entniche_user c ON c.id = a.ent_user_id WHERE b.assign_type = 1 AND b.resign = 0`
|
|
|
+ // 超管
|
|
|
+ cgMail = `SELECT c.mail 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 INNER JOIN jianyu.entniche_user c ON c.id = a.ent_user_id WHERE b.role_id = 4 AND b.resign = 0`
|
|
|
)
|
|
|
|
|
|
// @Author jianghan
|
|
@@ -27,51 +34,91 @@ var (
|
|
|
// @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`)
|
|
|
+ sql1 := `UPDATE dwd_f_crm_personnel_management SET send_mail = (?) where position_id = ?`
|
|
|
+ pp := Mysql.SelectBySql(`SELECT name, position_id, send_mail & 1 AS flag_1, (send_mail >> 1) & 1 AS flag_2 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"])
|
|
|
+ sendFlag1 := common.IntAll(m["flag_1"]) //预警邮件发送
|
|
|
+ sendFlag2 := common.IntAll(m["flag_2"]) //上限邮件发送
|
|
|
posid := common.Int64All(m["position_id"])
|
|
|
count := Mysql.CountBySql(sql, posid)
|
|
|
- if count >= int64(WarningSize) && sendFlag == 0 {
|
|
|
+ if count >= int64(WarningSize) && sendFlag1 == 0 {
|
|
|
WillWarningByPp(posid) // 发预警邮件
|
|
|
- _, _ = Mysql.ExecBySql(sql1, posid, 0)
|
|
|
- } else if count >= int64(LimitSize) && sendFlag == 0 {
|
|
|
+ _, _ = Mysql.ExecBySql(sql1, "send_mail | (1 << 0)", posid)
|
|
|
+ } else if count >= int64(LimitSize) && sendFlag2 == 0 {
|
|
|
ExceedLimitByPp(posid) // 发上限邮件
|
|
|
- _, _ = Mysql.ExecBySql(sql1, posid, 0)
|
|
|
- } else if sendFlag == 1 { // 已发邮件
|
|
|
- if count < int64(WarningSize) {
|
|
|
- _, _ = Mysql.ExecBySql(sql1, posid, 0)
|
|
|
- }
|
|
|
+ _, _ = Mysql.ExecBySql(sql1, "send_mail | (1 << 1)", posid)
|
|
|
+ } else if sendFlag1 == 1 && count < int64(WarningSize) { // 已发邮件
|
|
|
+ _, _ = Mysql.ExecBySql(sql1, "send_mail & ~(1 << 0)", posid)
|
|
|
+ } else if sendFlag2 == 1 && count < int64(LimitSize) { // 已发邮件
|
|
|
+ _, _ = Mysql.ExecBySql(sql1, "send_mail & ~(1 << 1)", posid)
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// @Author jianghan
|
|
|
-// @Description 部门预警/上限
|
|
|
+// @Description 部门预警/上限 所有人
|
|
|
// @Date 2024/5/9
|
|
|
func WarningDm() {
|
|
|
+ sql1 := `UPDATE dwd_f_crm_personnel_management SET send_mail = (?) where position_id = ?`
|
|
|
dm := Mysql.SelectBySql(dmInfo)
|
|
|
+ send := true // 所有人
|
|
|
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
|
|
|
+ info := Mysql.SelectBySql(dmInfoCount, d1, WarningSize)
|
|
|
+ if info != nil && len(*info) > 0 {
|
|
|
+ send1 = false
|
|
|
+ }
|
|
|
+ info1 := Mysql.SelectBySql(dmInfoCount, d1, LimitSize)
|
|
|
+ if info1 != nil && len(*info1) > 0 {
|
|
|
+ send2 = false
|
|
|
+ }
|
|
|
+ //for _, m1 := range *info {
|
|
|
+ // count := common.IntAll(m1["num"])
|
|
|
+ // if count < WarningSize {
|
|
|
+ // send1 = false
|
|
|
+ // }
|
|
|
+ // if count < LimitSize {
|
|
|
+ // send2 = false
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+ info2 := Mysql.SelectBySql(dmInfoMail, d1)
|
|
|
+ sendFlag1 := common.IntAll((*info2)[0]["flag_1"]) //预警邮件发送
|
|
|
+ sendFlag2 := common.IntAll((*info2)[0]["flag_2"]) //上限邮件发送
|
|
|
+ to := common.ObjToString((*info2)[0]["mail"])
|
|
|
+ posid := common.ObjToString((*info2)[0]["position_id"])
|
|
|
+ var toCc []string // 销管
|
|
|
+ for _, m2 := range *Mysql.SelectBySql(xgMail) {
|
|
|
+ if m3 := common.ObjToString(m2["mail"]); m3 != "" {
|
|
|
+ toCc = append(toCc, m3)
|
|
|
}
|
|
|
- if count < LimitSize {
|
|
|
- send2 = false
|
|
|
+ }
|
|
|
+ if d1 != "销售三部" {
|
|
|
+ toCc = append(toCc, "shenbingyi@topnet.net.cn")
|
|
|
+ }
|
|
|
+ if send1 && sendFlag1 == 0 { // 预警
|
|
|
+ WillWarningByDm(d1, to, toCc)
|
|
|
+ _, _ = Mysql.ExecBySql(sql1, "send_mail | (1 << 2)", posid) // 倒数第三位修改成0
|
|
|
+ } else {
|
|
|
+ send = false // 所有人
|
|
|
+ if sendFlag1 == 1 {
|
|
|
+ _, _ = Mysql.ExecBySql(sql1, "send_mail & ~(1 << 2)", posid) // 倒数第三位修改成1
|
|
|
}
|
|
|
}
|
|
|
- if send1 {
|
|
|
-
|
|
|
+ if send2 && sendFlag2 == 0 { // 上限
|
|
|
+ ExceedLimitByDm(d1, to, toCc)
|
|
|
+ _, _ = Mysql.ExecBySql(sql1, "send_mail | (1 << 3)", posid) // 倒数第四位修改成0
|
|
|
+ } else {
|
|
|
+ if sendFlag2 == 1 {
|
|
|
+ _, _ = Mysql.ExecBySql(sql1, "send_mail & ~(1 << 3)", posid) // 倒数第四位修改成1
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ if send {
|
|
|
+ WillWarningByAll()
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// @Author jianghan
|
|
@@ -99,18 +146,12 @@ func WillWarningByPp(posid int64) {
|
|
|
// @Author jianghan
|
|
|
// @Description 部门人员私海线索即将达到预警提醒
|
|
|
// @Date 2024/4/10
|
|
|
-func WillWarningByDm() {
|
|
|
+func WillWarningByDm(dname, to string, toCc []string) {
|
|
|
title := "“%s”私海线索即将达到上限通知"
|
|
|
content := "“%s”的所有参与线索分配的电销人员,私海线索都已达到%d条(不包含成交客户),即将达到私海线索上限%d条(不包含成交客户),请及时通知电销人员将无需跟进的线索退回公海,以避免无法接收新线索。"
|
|
|
-
|
|
|
- toMail := ""
|
|
|
- toCc := ""
|
|
|
- title = fmt.Sprintf(title, "")
|
|
|
- content = fmt.Sprintf(content, "", WarningSize, LimitSize)
|
|
|
-
|
|
|
- // todo
|
|
|
-
|
|
|
- sendInfo(toMail, toCc, title, content)
|
|
|
+ title = fmt.Sprintf(title, dname)
|
|
|
+ content = fmt.Sprintf(content, dname, WarningSize, LimitSize)
|
|
|
+ sendInfo(to, strings.Join(toCc, ","), title, content)
|
|
|
}
|
|
|
|
|
|
// @Author jianghan
|
|
@@ -119,11 +160,14 @@ func WillWarningByDm() {
|
|
|
func WillWarningByAll() {
|
|
|
title := "所有电销人员私海线索即将达到上限通知"
|
|
|
content := "所有参与线上线索自动分配的电销人员,私海线索都已达到%d条,请及时提醒销售部门将无需跟进的销售线索退回公海"
|
|
|
-
|
|
|
- toMail := ""
|
|
|
- toCc := ""
|
|
|
+ var to []string // 销管
|
|
|
+ for _, m2 := range *Mysql.SelectBySql(xgMail) {
|
|
|
+ if m3 := common.ObjToString(m2["mail"]); m3 != "" {
|
|
|
+ to = append(to, m3)
|
|
|
+ }
|
|
|
+ }
|
|
|
content = fmt.Sprintf(content, WarningSize)
|
|
|
- sendInfo(toMail, toCc, title, content)
|
|
|
+ sendInfo(strings.Join(to, ","), "", title, content)
|
|
|
}
|
|
|
|
|
|
// @Author jianghan
|
|
@@ -151,15 +195,12 @@ func ExceedLimitByPp(posid int64) {
|
|
|
// @Author jianghan
|
|
|
// @Description 部门所有人私海线索达到上限提醒
|
|
|
// @Date 2024/4/10
|
|
|
-func ExceedLimitByDm() {
|
|
|
+func ExceedLimitByDm(dname, to string, toCc []string) {
|
|
|
title := "“%s”私海线索已达到上限通知"
|
|
|
content := "“%s”的所有参与线索分配的电销人员,私海线索都已达到私海线索上限%d条(不包含成交客户),当前无法接收新线索,请及时通知电销人员将无需跟进的线索退回公海"
|
|
|
-
|
|
|
- toMail := ""
|
|
|
- toCc := ""
|
|
|
- title = fmt.Sprintf(title, "")
|
|
|
- content = fmt.Sprintf(content, "", LimitSize)
|
|
|
- sendInfo(toMail, toCc, title, content)
|
|
|
+ title = fmt.Sprintf(title, dname)
|
|
|
+ content = fmt.Sprintf(content, dname, LimitSize)
|
|
|
+ sendInfo(to, strings.Join(toCc, ","), title, content)
|
|
|
}
|
|
|
|
|
|
// @Author jianghan
|
|
@@ -169,19 +210,25 @@ 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",
|
|
|
+ var to []string
|
|
|
+ for _, m := range *Mysql.SelectBySql(allMail) {
|
|
|
+ if m1 := common.ObjToString(m["mail"]); m1 != "" {
|
|
|
+ to = append(to, m1)
|
|
|
+ }
|
|
|
}
|
|
|
- status := mail.GSendMail("剑鱼标讯", toMail, toCc, "", title, content, "", "", gmail)
|
|
|
- if status {
|
|
|
- log.Println("send mail success", title, toMail)
|
|
|
+ var toCc []string // 销管+高级电销经理+超管
|
|
|
+ for _, m2 := range *Mysql.SelectBySql(xgMail) {
|
|
|
+ if m3 := common.ObjToString(m2["mail"]); m3 != "" {
|
|
|
+ toCc = append(toCc, m3)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for _, m2 := range *Mysql.SelectBySql(cgMail) {
|
|
|
+ if m3 := common.ObjToString(m2["mail"]); m3 != "" {
|
|
|
+ toCc = append(toCc, m3)
|
|
|
+ }
|
|
|
}
|
|
|
+ toCc = append(toCc, "shenbingyi@topnet.net.cn")
|
|
|
+ sendInfo(strings.Join(to, ","), strings.Join(toCc, ","), title, fmt.Sprintf(content, LimitSize))
|
|
|
}
|
|
|
|
|
|
// @Author jianghan
|
|
@@ -191,24 +238,31 @@ func CantBeAssignedNots() {
|
|
|
title := "【紧急】线上线索无法分配通知"
|
|
|
content := "所有参与线上线索自动分配的电销人员,私海线索都已达到**条,且私海已无“潜在客户”、“沉睡客户”、“商机线索(已建联)”可释放,当前线上线索无法分配,请尽快处理,可前往【公海线索】查看“待分线索”条数"
|
|
|
|
|
|
- toMail := ""
|
|
|
- toCc := ""
|
|
|
- gmail := &mail.GmailAuth{
|
|
|
- SmtpHost: "smtp.exmail.qq.com",
|
|
|
- SmtpPort: 465,
|
|
|
- User: "public03@topnet.net.cn",
|
|
|
- Pwd: "ue9Rg9Sf4CVtdm5a",
|
|
|
+ var to []string
|
|
|
+ for _, m := range *Mysql.SelectBySql(allMail) {
|
|
|
+ if m1 := common.ObjToString(m["mail"]); m1 != "" {
|
|
|
+ to = append(to, m1)
|
|
|
+ }
|
|
|
}
|
|
|
- status := mail.GSendMail("剑鱼标讯", toMail, toCc, "", title, content, "", "", gmail)
|
|
|
- if status {
|
|
|
- log.Println("send mail success", title, toMail)
|
|
|
+ var toCc []string // 销管+高级电销经理+超管
|
|
|
+ for _, m2 := range *Mysql.SelectBySql(xgMail) {
|
|
|
+ if m3 := common.ObjToString(m2["mail"]); m3 != "" {
|
|
|
+ toCc = append(toCc, m3)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for _, m2 := range *Mysql.SelectBySql(cgMail) {
|
|
|
+ if m3 := common.ObjToString(m2["mail"]); m3 != "" {
|
|
|
+ toCc = append(toCc, m3)
|
|
|
+ }
|
|
|
}
|
|
|
+ toCc = append(toCc, "shenbingyi@topnet.net.cn")
|
|
|
+ sendInfo(strings.Join(to, ","), strings.Join(toCc, ","), title, fmt.Sprintf(content, LimitSize))
|
|
|
}
|
|
|
|
|
|
// @Author jianghan
|
|
|
// @Description 客成移交线索失败提醒
|
|
|
// @Date 2024/4/10
|
|
|
-func HandOverFail() {
|
|
|
+func HandOverFail(posid int64) {
|
|
|
title := "客成线索移交失败通知"
|
|
|
content := "您的私海线索已超过**条(不包含成交客户),已达到私海线索上限**条(不包含成交客户),导致“XXX线索名称(XXX手机号)”无法从客成到期自动移交至私海,请及时将无需跟进的线索退回公海,超过3个工作日(根据配置获取)不处理,该线索将自动退回至公海"
|
|
|
|
|
@@ -220,12 +274,22 @@ func HandOverFail() {
|
|
|
// @Author jianghan
|
|
|
// @Description 订单用户创建线索失败提醒
|
|
|
// @Date 2024/4/10
|
|
|
-func OrderCreateFail() {
|
|
|
+func OrderCreateFail(posid int64, bname string) {
|
|
|
title := "订单用户创建线索失败通知"
|
|
|
- content := "您的私海线索已超过**条(不包含成交客户),已达到私海线索上限**条(不包含成交客户),导致订单系统的用户“XXX公司名称(XXX手机号)”无法进入您的私海,请及时将无需跟进的线索退回公海,超过3个工作日(根据配置获取)不处理,该线索将自动进入至公海。"
|
|
|
+ content := "您的私海线索已超过%d条(不包含成交客户),已达到私海线索上限%d条(不包含成交客户),导致订单系统的用户“%s”无法进入您的私海,请及时将无需跟进的线索退回公海,超过3个工作日(根据配置获取)不处理,该线索将自动进入至公海。"
|
|
|
|
|
|
toMail := ""
|
|
|
toCc := ""
|
|
|
+ content = fmt.Sprintf(content, LimitSize, LimitSize, bname)
|
|
|
+ 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)
|
|
|
}
|
|
|
|
|
@@ -233,6 +297,10 @@ func OrderCreateFail() {
|
|
|
// @Description 发邮件
|
|
|
// @Date 2024/5/8
|
|
|
func sendInfo(to, cs, title, content string) {
|
|
|
+ if to == "" {
|
|
|
+ log.Println("send mail fail", title, to)
|
|
|
+ return
|
|
|
+ }
|
|
|
gmail := &mail.GmailAuth{
|
|
|
SmtpHost: "smtp.exmail.qq.com",
|
|
|
SmtpPort: 465,
|