sendMail.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. package main
  2. import (
  3. "app.yhyue.com/moapp/jybase/common"
  4. "app.yhyue.com/moapp/jybase/mail"
  5. "fmt"
  6. "github.com/gogf/gf/v2/util/gconv"
  7. "log"
  8. "strings"
  9. )
  10. var (
  11. selfMail = `SELECT a.position_id, a.name, c.mail FROM dwd_d_crm_department_level_succbi a LEFT JOIN jianyu.entniche_user c ON a.ent_user_id = c.id WHERE a.position_id = ?`
  12. infoSelf = `SELECT a.name, a.SZ_PID1, a.SZ_PID2, a.dept_name, b.role_id FROM dwd_d_crm_department_level_succbi a INNER JOIN dwd_f_crm_personnel_management b ON b.position_id = a.position_id WHERE a.position_id = ? AND a.resign = 0`
  13. topMail = `SELECT a.name, a.ent_user_id, b.mail FROM dwd_d_crm_department_level_succbi a LEFT JOIN jianyu.entniche_user b ON a.ent_user_id = b.id LEFT JOIN dwd_f_crm_personnel_management c ON a.position_id = c.position_id AND c.resign = 0
  14. WHERE a.SZ_PID3 IN (SELECT a.SZ_PID3 FROM dwd_d_crm_department_level_succbi a WHERE a.position_id = ?) AND c.role_id = 3`
  15. topMail3 = `SELECT a.name, a.ent_user_id, b.mail FROM dwd_d_crm_department_level_succbi a LEFT JOIN jianyu.entniche_user b ON a.ent_user_id = b.id LEFT JOIN dwd_f_crm_personnel_management c ON a.position_id = c.position_id
  16. WHERE a.dept_name = '销售三部' AND a.resign = 0 AND c.role_id = 8`
  17. dmInfo = `SELECT b.dept_name FROM dwd_d_crm_department_level_succbi b WHERE b.position_id IN (SELECT a.position_id FROM dwd_f_crm_personnel_management a
  18. WHERE assign_type = 1) GROUP BY b.dept_name`
  19. dmInfoCount = `SELECT b.position_id, COUNT(IF( a.is_transfer != 1, 1, NULL)) as num FROM dwd_f_crm_clue_info a RIGHT JOIN dwd_d_crm_department_level_succbi b ON a.position_id = b.position_id LEFT JOIN dwd_f_crm_personnel_management c ON b.position_id = c.position_id WHERE b.dept_name = ? AND c.resign = 0 AND c.assign_type = 1 GROUP BY a.position_id HAVING num < ?`
  20. dmInfoMail = `SELECT a.name, a.position_id, (b.send_mail >> 2) & 1 AS flag_1, (b.send_mail >> 3) & 1 AS flag_2, c.mail FROM dwd_d_crm_department_level_succbi a INNER JOIN dwd_f_crm_personnel_management b ON a.position_id = b.position_id LEFT JOIN jianyu.entniche_user c ON a.ent_user_id = c.id WHERE a.dept_name = ? AND a.resign = 0 AND b.role_id = ?`
  21. xgFlag = `SELECT a.name, (b.send_mail >> 4) & 1 AS flag FROM dwd_d_crm_department_level_succbi a INNER JOIN dwd_f_crm_personnel_management b ON a.position_id = b.position_id WHERE b.role_id = 5 AND b.resign = 0`
  22. xgMail = `SELECT a.name, c.mail FROM dwd_d_crm_department_level_succbi a INNER JOIN dwd_f_crm_personnel_management b ON a.position_id = b.position_id LEFT JOIN jianyu.entniche_user c ON a.ent_user_id = c.id WHERE b.role_id = 5 AND b.resign = 0`
  23. // 所有参与线索分配人员的邮箱
  24. allMail = `SELECT a.name, c.mail FROM dwd_f_crm_personnel_management a INNER JOIN dwd_d_crm_department_level_succbi b ON a.position_id = b.position_id LEFT JOIN jianyu.entniche_user c ON b.ent_user_id = c.id WHERE a.assign_type = 1 AND a.resign = 0`
  25. // 超管
  26. cgMail = `SELECT a.name, c.mail FROM dwd_d_crm_department_level_succbi a INNER JOIN dwd_f_crm_personnel_management b ON a.position_id = b.position_id LEFT JOIN jianyu.entniche_user c ON a.ent_user_id = c.id WHERE b.role_id = 4 AND b.resign = 0`
  27. )
  28. // @Author jianghan
  29. // @Description 个人预警/上限
  30. // @Date 2024/4/11
  31. func WarningPerl() {
  32. sql := `SELECT count(*) FROM dwd_f_crm_clue_info where position_id = ? and is_transfer != 1`
  33. sql1 := `UPDATE dwd_f_crm_personnel_management SET send_mail = (%s) where position_id = ?`
  34. pp := TiDb.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 resign = 0`)
  35. if pp != nil && len(*pp) > 0 {
  36. for _, m := range *pp {
  37. sendFlag1 := common.IntAll(m["flag_1"]) //预警邮件发送
  38. sendFlag2 := common.IntAll(m["flag_2"]) //上限邮件发送
  39. posid := common.Int64All(m["position_id"])
  40. count := TiDb.CountBySql(sql, posid)
  41. if count >= db.AllocationCap && sendFlag2 == 0 {
  42. ExceedLimitByPp(posid) // 发上限邮件
  43. _, _ = TiDb.ExecBySql(fmt.Sprintf(sql1, "send_mail | (1 << 1)"), posid)
  44. } else if count >= db.WarningValue && sendFlag1 == 0 && sendFlag2 == 0 {
  45. WillWarningByPp(posid) // 发预警邮件
  46. _, _ = TiDb.ExecBySql(fmt.Sprintf(sql1, "send_mail | (1 << 0)"), posid)
  47. } else if sendFlag1 == 1 && count < db.WarningValue { // 已发邮件
  48. _, _ = TiDb.ExecBySql(fmt.Sprintf(sql1, "send_mail & ~(1 << 0)"), posid)
  49. } else if sendFlag2 == 1 && count < db.AllocationCap { // 已发邮件
  50. _, _ = TiDb.ExecBySql(fmt.Sprintf(sql1, "send_mail & ~(1 << 1)"), posid)
  51. }
  52. }
  53. }
  54. }
  55. // @Author jianghan
  56. // @Description 部门预警/上限 所有人
  57. // @Date 2024/5/9
  58. func WarningDm() {
  59. sql1 := `UPDATE dwd_f_crm_personnel_management SET send_mail = (%s) where position_id = ? `
  60. dm := TiDb.SelectBySql(dmInfo)
  61. send := true // 所有人
  62. for _, m := range *dm {
  63. d1 := common.ObjToString(m["dept_name"])
  64. send1, send2 := true, true // 预警,上限 发送标记
  65. info := TiDb.SelectBySql(dmInfoCount, d1, db.WarningValue)
  66. if info != nil && len(*info) > 0 {
  67. send = false
  68. send1 = false
  69. }
  70. info1 := TiDb.SelectBySql(dmInfoCount, d1, db.AllocationCap)
  71. if info1 != nil && len(*info1) > 0 {
  72. send2 = false
  73. }
  74. //for _, m1 := range *info {
  75. // count := common.IntAll(m1["num"])
  76. // if count < WarningSize {
  77. // send1 = false
  78. // }
  79. // if count < LimitSize {
  80. // send2 = false
  81. // }
  82. //}
  83. var info2 *[]map[string]interface{}
  84. if d1 == "销售三部" {
  85. info2 = TiDb.SelectBySql(dmInfoMail, d1, 8)
  86. } else {
  87. info2 = TiDb.SelectBySql(dmInfoMail, d1, 3)
  88. }
  89. if info2 == nil || len(*info2) == 0 {
  90. log.Println("未查询到部门领导邮箱", d1)
  91. continue
  92. }
  93. sendFlag1 := common.IntAll((*info2)[0]["flag_1"]) //预警邮件发送
  94. sendFlag2 := common.IntAll((*info2)[0]["flag_2"]) //上限邮件发送
  95. to := getMailAds(common.ObjToString((*info2)[0]["mail"]), common.ObjToString((*info2)[0]["name"]))
  96. posid := common.Int64All((*info2)[0]["position_id"])
  97. var toCc []string // 销管
  98. for _, m2 := range *TiDb.SelectBySql(xgMail) {
  99. if m3 := getMailAds(common.ObjToString(m2["mail"]), common.ObjToString(m2["name"])); m3 != "" {
  100. toCc = append(toCc, m3)
  101. }
  102. }
  103. if d1 != "销售三部" {
  104. toCc = append(toCc, getMailAds("shenbingyi@topnet.net.cn", "沈炳毅"))
  105. }
  106. if send2 && sendFlag2 == 0 { // 上限
  107. ExceedLimitByDm(d1, to, toCc)
  108. _, _ = TiDb.ExecBySql(fmt.Sprintf(sql1, "send_mail | (1 << 3)"), posid) // 倒数第四位修改成1
  109. sendFlag2 = 1
  110. } else {
  111. if !send2 && sendFlag2 == 1 {
  112. _, _ = TiDb.ExecBySql(fmt.Sprintf(sql1, "send_mail & ~(1 << 3)"), posid) // 倒数第四位修改成0
  113. }
  114. }
  115. if send1 && sendFlag1 == 0 && sendFlag2 == 0 { // 预警
  116. WillWarningByDm(d1, to, toCc)
  117. _, _ = TiDb.ExecBySql(fmt.Sprintf(sql1, "send_mail | (1 << 2)"), posid) // 倒数第三位修改成1
  118. } else {
  119. if !send1 && sendFlag1 == 1 {
  120. _, _ = TiDb.ExecBySql(fmt.Sprintf(sql1, "send_mail & ~(1 << 2)"), posid) // 倒数第三位修改成0
  121. }
  122. }
  123. }
  124. sql := `UPDATE dwd_f_crm_personnel_management SET send_mail = (%s) where position_id IN (SELECT a.position_id FROM dwd_f_crm_personnel_management a WHERE a.role_id = 5 AND a.resign = 0)`
  125. if send {
  126. info3 := TiDb.SelectBySql(xgFlag)
  127. if info3 != nil && len(*info3) > 0 {
  128. sendFlag := common.IntAll((*info3)[0]["flag"])
  129. if sendFlag == 0 {
  130. WillWarningByAll()
  131. TiDb.ExecBySql(fmt.Sprintf(sql, "send_mail | (1 << 4)"))
  132. }
  133. }
  134. } else {
  135. info3 := TiDb.SelectBySql(xgFlag)
  136. if info3 != nil && len(*info3) > 0 {
  137. sendFlag := common.IntAll((*info3)[0]["flag"])
  138. if sendFlag == 1 {
  139. TiDb.ExecBySql(fmt.Sprintf(sql, "send_mail & ~(1 << 4)")) // 修改销管 发送邮件标志 0
  140. }
  141. }
  142. }
  143. }
  144. // @Author jianghan
  145. // @Description 个人私海线索即将达到预警提醒
  146. // @Date 2024/4/10
  147. func WillWarningByPp(posid int64) {
  148. title := "您的私海线索即将达到上限通知"
  149. content := "您的私海线索已超过%d条(含成交客户),即将达到私海线索上限%d条(含成交客户),请及时将无需跟进的线索退回公海,以避免无法接收新线索。"
  150. toMail := ""
  151. toCc := ""
  152. info := TiDb.SelectBySql(selfMail, posid)
  153. if info != nil && len(*info) > 0 {
  154. toMail = getMailAds(common.ObjToString((*info)[0]["mail"]), common.ObjToString((*info)[0]["name"]))
  155. }
  156. if toMail == "" {
  157. log.Println("未查询到邮箱地址, position id: ", posid)
  158. return
  159. }
  160. toCc = getCc(posid)
  161. content = fmt.Sprintf(content, db.WarningValue, db.AllocationCap)
  162. sendInfo(toMail, toCc, title, content)
  163. }
  164. func WorkMail(personMap map[string]interface{}, productStr string, orderStatus int64, personName1, personName2, createTimeStr, acceptance_no, phone, company string) {
  165. log.Println("邮箱发送", personMap, productStr, orderStatus, personName1, personName2, createTimeStr, acceptance_no, phone, company)
  166. orderType := fmt.Sprintf(`客户咨询线索(%s)`, productStr)
  167. title := fmt.Sprintf("%s通知", orderType)
  168. if personName1 == gconv.String(personMap["deptPersonName"]) {
  169. personMap["deptPersonMail"] = ""
  170. }
  171. if personName1 == gconv.String(personMap["superiorDepthPersonName"]) {
  172. personMap["superiorDepthPersonMail"] = ""
  173. }
  174. content := ""
  175. if orderStatus == 1 {
  176. 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))))
  177. } else if orderStatus == 2 {
  178. 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))))
  179. }
  180. toMail := gconv.String(personMap["mail"])
  181. mailArr := []string{}
  182. if gconv.String(common.If(gconv.String(personMap["deptPersonMail"]) == "", "", gconv.String(personMap["deptPersonMail"]))) != "" {
  183. mailArr = append(mailArr, gconv.String(common.If(gconv.String(personMap["deptPersonMail"]) == "", "", gconv.String(personMap["deptPersonMail"]))))
  184. }
  185. if gconv.String(common.If(gconv.String(personMap["superiorDepthPersonMail"]) == "", "", gconv.String(personMap["superiorDepthPersonMail"]))) != "" {
  186. mailArr = append(mailArr, gconv.String(common.If(gconv.String(personMap["superiorDepthPersonMail"]) == "", "", gconv.String(personMap["superiorDepthPersonMail"]))))
  187. }
  188. toCc := strings.Join(mailArr, ",")
  189. log.Println(toMail, toCc, title, content)
  190. /*toMail = "wanghao@topnet.net.cn"
  191. toCc = "wanghao@topnet.net.cn"*/
  192. sendInfo(toMail, toCc, title, content)
  193. }
  194. // @Author jianghan
  195. // @Description 部门人员私海线索即将达到预警提醒
  196. // @Date 2024/4/10
  197. func WillWarningByDm(dname, to string, toCc []string) {
  198. title := "“%s”私海线索即将达到上限通知"
  199. content := "“%s”的所有参与线索分配的电销人员,私海线索都已达到%d条(含成交客户),即将达到私海线索上限%d条(含成交客户),请及时通知电销人员将无需跟进的线索退回公海,以避免无法接收新线索。"
  200. title = fmt.Sprintf(title, dname)
  201. content = fmt.Sprintf(content, dname, db.WarningValue, db.AllocationCap)
  202. sendInfo(to, strings.Join(toCc, ","), title, content)
  203. }
  204. // @Author jianghan
  205. // @Description 所有人私海线索即将达到预警提醒
  206. // @Date 2024/4/10
  207. func WillWarningByAll() {
  208. title := "所有电销人员私海线索即将达到上限通知"
  209. content := "所有参与线上线索自动分配的电销人员,私海线索都已达到%d条,请及时提醒销售部门将无需跟进的销售线索退回公海"
  210. var to []string // 销管
  211. for _, m2 := range *TiDb.SelectBySql(xgMail) {
  212. if m3 := getMailAds(common.ObjToString(m2["mail"]), common.ObjToString(m2["name"])); m3 != "" {
  213. to = append(to, m3)
  214. }
  215. }
  216. content = fmt.Sprintf(content, db.WarningValue)
  217. sendInfo(strings.Join(to, ","), "", title, content)
  218. }
  219. // @Author jianghan
  220. // @Description 个人私海线索达到上限提醒
  221. // @Date 2024/4/10
  222. func ExceedLimitByPp(posid int64) {
  223. title := "您的私海线索已达上限通知"
  224. content := "您的私海线索已达到私海线索上限%d条(含成交客户),当前无法接收新线索,请及时将无需跟进的线索退回公海"
  225. toMail := ""
  226. toCc := ""
  227. content = fmt.Sprintf(content, db.AllocationCap)
  228. info := TiDb.SelectBySql(selfMail, posid)
  229. if info != nil && len(*info) > 0 {
  230. toMail = getMailAds(common.ObjToString((*info)[0]["mail"]), common.ObjToString((*info)[0]["name"]))
  231. }
  232. if toMail == "" {
  233. log.Println("未查询到邮箱地址, position id: ", posid)
  234. return
  235. }
  236. toCc = getCc(posid)
  237. sendInfo(toMail, toCc, title, content)
  238. }
  239. // @Author jianghan
  240. // @Description 部门所有人私海线索达到上限提醒
  241. // @Date 2024/4/10
  242. func ExceedLimitByDm(dname, to string, toCc []string) {
  243. title := "“%s”私海线索已达到上限通知"
  244. content := "“%s”的所有参与线索分配的电销人员,私海线索都已达到私海线索上限%d条(含成交客户),当前无法接收新线索,请及时通知电销人员将无需跟进的线索退回公海"
  245. title = fmt.Sprintf(title, dname)
  246. content = fmt.Sprintf(content, dname, db.AllocationCap)
  247. sendInfo(to, strings.Join(toCc, ","), title, content)
  248. }
  249. // @Author jianghan
  250. // @Description 自动释放私海线索通知
  251. // @Date 2024/4/10
  252. func AutoReleaseNots() {
  253. title := "自动释放私海线索通知"
  254. content := "所有参与线上线索自动分配的电销人员,私海线索都已达到%d条,为避免线上产生的新线索无法分配,系统已自动将线索状态为“商机线索(已建联,包含已拨打未接通)”、“潜在客户”、“沉睡客户”的线索退回公海,如有异议请联系销管处理;"
  255. var to []string
  256. for _, m := range *TiDb.SelectBySql(allMail) {
  257. if m1 := getMailAds(common.ObjToString(m["mail"]), common.ObjToString(m["name"])); m1 != "" {
  258. to = append(to, m1)
  259. }
  260. }
  261. var toCc []string // 销管+高级电销经理+超管
  262. for _, m2 := range *TiDb.SelectBySql(xgMail) {
  263. if m3 := getMailAds(common.ObjToString(m2["mail"]), common.ObjToString(m2["name"])); m3 != "" {
  264. toCc = append(toCc, m3)
  265. }
  266. }
  267. for _, m2 := range *TiDb.SelectBySql(cgMail) {
  268. if m3 := getMailAds(common.ObjToString(m2["mail"]), common.ObjToString(m2["name"])); m3 != "" {
  269. toCc = append(toCc, m3)
  270. }
  271. }
  272. toCc = append(toCc, getMailAds("shenbingyi@topnet.net.cn", "沈炳毅"))
  273. sendInfo(strings.Join(to, ","), strings.Join(toCc, ","), title, fmt.Sprintf(content, db.AllocationCap))
  274. }
  275. // @Author jianghan
  276. // @Description 线上线索无法分配通知
  277. // @Date 2024/4/10
  278. func CantBeAssignedNots() {
  279. title := "【紧急】线上线索无法分配通知"
  280. content := "所有参与线上线索自动分配的电销人员,私海线索都已达到%d条,且私海已无“潜在客户”、“沉睡客户”、“商机线索(已建联)”可释放,当前线上线索无法分配,请尽快处理!"
  281. var to []string
  282. for _, m := range *TiDb.SelectBySql(allMail) {
  283. if m1 := getMailAds(common.ObjToString(m["mail"]), common.ObjToString(m["name"])); m1 != "" {
  284. to = append(to, m1)
  285. }
  286. }
  287. var toCc []string // 销管+高级电销经理+超管
  288. for _, m2 := range *TiDb.SelectBySql(xgMail) {
  289. if m3 := getMailAds(common.ObjToString(m2["mail"]), common.ObjToString(m2["name"])); m3 != "" {
  290. toCc = append(toCc, m3)
  291. }
  292. }
  293. for _, m2 := range *TiDb.SelectBySql(cgMail) {
  294. if m3 := getMailAds(common.ObjToString(m2["mail"]), common.ObjToString(m2["name"])); m3 != "" {
  295. toCc = append(toCc, m3)
  296. }
  297. }
  298. toCc = append(toCc, getMailAds("shenbingyi@topnet.net.cn", "沈炳毅"))
  299. sendInfo(strings.Join(to, ","), strings.Join(toCc, ","), title, fmt.Sprintf(content, db.AllocationCap))
  300. }
  301. // @Author jianghan
  302. // @Description 客成移交线索失败提醒
  303. // @Date 2024/4/10
  304. func HandOverFail(posid int64, ent string) {
  305. title := "客成线索移交失败通知"
  306. content := "您的私海线索已超过%d条(含成交客户),已达到私海线索上限%d条(含成交客户),导致“%s”无法从客成到期自动移交至私海,请及时将无需跟进的线索退回公海,超过%d个工作日不处理,该线索将自动退回至公海"
  307. toMail := ""
  308. toCc := ""
  309. info := TiDb.SelectBySql(selfMail, posid)
  310. content = fmt.Sprintf(content, db.AllocationCap, db.AllocationCap, ent, db.ThawDay)
  311. if info != nil && len(*info) > 0 {
  312. toMail = getMailAds(common.ObjToString((*info)[0]["mail"]), common.ObjToString((*info)[0]["name"]))
  313. }
  314. if toMail == "" {
  315. log.Println("未查询到邮箱地址, position id: ", posid)
  316. return
  317. }
  318. toCc = getCc(posid)
  319. sendInfo(toMail, toCc, title, content)
  320. }
  321. // @Author jianghan
  322. // @Description 订单用户创建线索失败提醒
  323. // @Date 2024/4/10
  324. func OrderCreateFail(posid int64, bname string) {
  325. title := "订单用户创建线索失败通知"
  326. content := "您的私海线索已超过%d条(含成交客户),已达到私海线索上限%d条(含成交客户),导致订单系统的用户“%s”无法进入您的私海,请及时将无需跟进的线索退回公海,超过%d个工作日不处理,该线索将自动进入至公海。"
  327. toMail := ""
  328. toCc := ""
  329. content = fmt.Sprintf(content, db.AllocationCap, db.AllocationCap, bname, db.ThawDay)
  330. info := TiDb.SelectBySql(selfMail, posid)
  331. if info != nil && len(*info) > 0 {
  332. toMail = getMailAds(common.ObjToString((*info)[0]["mail"]), common.ObjToString((*info)[0]["name"]))
  333. }
  334. if toMail == "" {
  335. log.Println("未查询到邮箱地址, position id: ", posid)
  336. return
  337. }
  338. toCc = getCc(posid)
  339. sendInfo(toMail, toCc, title, content)
  340. }
  341. // @Author jianghan
  342. // @Description 非集团公司线索分配失败
  343. // @Date 2024/5/11
  344. func AssFail(posid int64, ent, iname string) {
  345. title := "您跟进的非集团公司线上线索分配失败"
  346. content := "您的私海线索已达到私海线索上限%d条(含成交客户),导致您正在跟进的非集团公司“%s”产生的新线索“%s”无法进入您的私海,请及时将无需跟进的线索退回公海,退回后联系您的电销经理将此线索再划转至您的私海。"
  347. toMail := ""
  348. toCc := ""
  349. content = fmt.Sprintf(content, db.AllocationCap, ent, iname)
  350. info := TiDb.SelectBySql(selfMail, posid)
  351. if info != nil && len(*info) > 0 {
  352. toMail = getMailAds(common.ObjToString((*info)[0]["mail"]), common.ObjToString((*info)[0]["name"]))
  353. }
  354. if toMail == "" {
  355. log.Println("未查询到邮箱地址, position id: ", posid)
  356. return
  357. }
  358. toCc = getCc(posid)
  359. sendInfo(toMail, toCc, title, content)
  360. }
  361. // @Author jianghan
  362. // @Description 发邮件
  363. // @Date 2024/5/8
  364. func sendInfo(to, cs, title, content string) {
  365. if to == "" {
  366. log.Println("send mail fail", title, to)
  367. return
  368. }
  369. log.Println("发送标题", title)
  370. log.Println("发送人:", to)
  371. log.Println("抄送:", cs)
  372. gmail := &mail.GmailAuth{
  373. SmtpHost: db.Mail.SmtpHost,
  374. SmtpPort: db.Mail.SmtpPort,
  375. User: db.Mail.User,
  376. Pwd: db.Mail.Pwd,
  377. }
  378. status := mail.GSendMail_dx("剑鱼标讯", to, cs, "", title, content, "", "", gmail)
  379. if status {
  380. log.Println("send mail success", title, to)
  381. }
  382. }
  383. // @Author jianghan
  384. // @Description 获取抄送人员邮箱
  385. //
  386. // 销售三部 (SZ_PID1=5432)、销售一部(分组)
  387. //
  388. // @Date 2024/5/8
  389. func getCc(posid int64) (to string) {
  390. info := TiDb.SelectBySql(infoSelf, posid)
  391. if info == nil && len(*info) == 0 {
  392. log.Println("未查询到个人信息, positionId: ", posid)
  393. return
  394. }
  395. if common.ObjToString((*info)[0]["dept_name"]) == "销售三部" {
  396. if common.IntAll((*info)[0]["role_id"]) == 1 || common.IntAll((*info)[0]["role_id"]) == 2 {
  397. m := TiDb.SelectBySql(topMail3)
  398. if m != nil && len(*m) > 0 {
  399. to = getMailAds(common.ObjToString((*m)[0]["mail"]), common.ObjToString((*m)[0]["name"]))
  400. }
  401. }
  402. } else if common.ObjToString((*info)[0]["dept_name"]) == "销售三部" {
  403. } else {
  404. if common.IntAll((*info)[0]["role_id"]) == 1 || common.IntAll((*info)[0]["role_id"]) == 2 {
  405. m := TiDb.SelectBySql(topMail, posid)
  406. if m != nil && len(*m) > 0 {
  407. to = getMailAds(common.ObjToString((*m)[0]["mail"]), common.ObjToString((*m)[0]["name"]))
  408. }
  409. //to = getMailAds("shenbingyi@topnet.net.cn", "沈炳毅")
  410. } else if common.IntAll((*info)[0]["role_id"]) == 3 {
  411. to = getMailAds("shenbingyi@topnet.net.cn", "沈炳毅")
  412. }
  413. }
  414. return
  415. }
  416. // @Author jianghan
  417. // @Description 获取配置文件邮箱地址
  418. // @Date 2024/5/13
  419. func getMailAds(mail, name string) string {
  420. log.Println("getMailAds", name, mail)
  421. if db.NameToMail != nil && len(db.NameToMail) > 0 {
  422. return db.NameToMail[name]
  423. } else {
  424. return mail
  425. }
  426. }