|
@@ -12,16 +12,35 @@ import (
|
|
|
|
|
|
|
|
|
func EtaBusinessExpiredRemind(cont context.Context) (err error) {
|
|
|
+
|
|
|
+ frequencyArr := []int{1, 2, 3, 4, 5}
|
|
|
+ for _, f := range frequencyArr {
|
|
|
+ _ = HandleEtaBusinessExpiredRemind(f)
|
|
|
+ time.Sleep(15 * time.Second)
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func HandleEtaBusinessExpiredRemind(frequency int) (err error) {
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
|
- tips := "ETA商家到期提醒: EtaBusinessExpiredRemind, Err: " + err.Error()
|
|
|
+ tips := fmt.Sprintf("ETA商家到期提醒失败, frequency: %d, Err: %s", frequency, err.Error())
|
|
|
utils.FileLog.Info("%s", tips)
|
|
|
go alarm_msg.SendAlarmMsg(tips, 3)
|
|
|
}
|
|
|
}()
|
|
|
|
|
|
-
|
|
|
- monthLater := time.Now().Local().AddDate(0, 2, 0)
|
|
|
+
|
|
|
+ dayMap := map[int]int{1: 1, 2: 7, 3: 15, 4: 30, 5: 60}
|
|
|
+ days := dayMap[frequency]
|
|
|
+ if days <= 0 {
|
|
|
+ err = fmt.Errorf("提醒频次有误")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ monthLater := time.Now().Local().AddDate(0, 0, days)
|
|
|
expiredTime := monthLater.Format(utils.FormatDate)
|
|
|
businesses := make([]*eta_business.EtaBusiness, 0)
|
|
|
{
|
|
@@ -60,10 +79,8 @@ func EtaBusinessExpiredRemind(cont context.Context) (err error) {
|
|
|
sellerMap[s.AdminId] = s
|
|
|
}
|
|
|
|
|
|
- remindType := 5
|
|
|
- remindRecords := make([]*eta_business.EtaBusinessRemindRecord, 0)
|
|
|
-
|
|
|
|
|
|
+ remindRecords := make([]*eta_business.EtaBusinessRemindRecord, 0)
|
|
|
for k, v := range sellerBusinessMap {
|
|
|
seller := sellerMap[k]
|
|
|
if seller == nil {
|
|
@@ -75,11 +92,11 @@ func EtaBusinessExpiredRemind(cont context.Context) (err error) {
|
|
|
if len(v) == 0 {
|
|
|
continue
|
|
|
}
|
|
|
- uniqueCode := fmt.Sprint(seller.AdminId, time.Now().Format(utils.FormatDateUnSpace), remindType, utils.GetRandString(5))
|
|
|
+ uniqueCode := fmt.Sprint(seller.AdminId, time.Now().Format(utils.FormatDateUnSpace), frequency, utils.GetRandDigit(5))
|
|
|
|
|
|
contentRemark := ""
|
|
|
- contentsEmail := fmt.Sprintf(`<div><p>您有【%d】ETA客户将于60天后到期,请注意查看</p>`, len(v))
|
|
|
- contentsEmail += `<table border='1'><tr><td width='200'>60天后到期客户名称</td><td width='200'>到期日期</td><td width='200'>销售人员</td><td>客户类型</td></tr>`
|
|
|
+ contentsEmail := fmt.Sprintf(`<div><p>您有【%d】ETA客户将于%d天后到期,请注意查看</p>`, len(v), days)
|
|
|
+ contentsEmail += fmt.Sprintf(`<table border='1'><tr><td width='200'>%d天后到期客户名称</td><td width='200'>到期日期</td><td width='200'>销售人员</td><td>客户类型</td></tr>`, days)
|
|
|
for _, bz := range v {
|
|
|
row := fmt.Sprintf(`<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>`, bz.BusinessName, bz.ExpiredTime.Format(utils.FormatDate), bz.SellerName, "ETA")
|
|
|
contentsEmail += row
|
|
@@ -87,7 +104,7 @@ func EtaBusinessExpiredRemind(cont context.Context) (err error) {
|
|
|
|
|
|
|
|
|
remindRecords = append(remindRecords, &eta_business.EtaBusinessRemindRecord{
|
|
|
- Type: remindType,
|
|
|
+ Type: frequency,
|
|
|
SellerId: seller.AdminId,
|
|
|
SellerName: seller.RealName,
|
|
|
EtaBusinessId: bz.EtaBusinessId,
|
|
@@ -101,13 +118,14 @@ func EtaBusinessExpiredRemind(cont context.Context) (err error) {
|
|
|
|
|
|
|
|
|
if seller.Email != "" {
|
|
|
- utils.SendEmailByHongze("到期前60天提醒", contentsEmail, seller.Email, "", "")
|
|
|
+ msg := fmt.Sprintf("到期前%d天提醒", days)
|
|
|
+ utils.SendEmailByHongze(msg, contentsEmail, seller.Email, "", "")
|
|
|
}
|
|
|
|
|
|
|
|
|
if seller.OpenId != "" {
|
|
|
- first := fmt.Sprintf(`您有【%d】 客户将于60天后到期,请注意查看`, len(v))
|
|
|
- keyword1 := fmt.Sprintf(`【%d】ETA到期前60天提醒,点击查看`, len(v))
|
|
|
+ first := fmt.Sprintf(`您有【%d】 客户将于%d天后到期,请注意查看`, len(v), days)
|
|
|
+ keyword1 := fmt.Sprintf(`【%d】ETA到期前%d天提醒,点击查看`, len(v), days)
|
|
|
keyword2 := expiredTime
|
|
|
remark := contentRemark
|
|
|
|