|
@@ -710,3 +710,233 @@ func SendWxMsgActivitySpecial10(activityInfo *models.CygxActivitySpecialDetail)
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+//SendWxMsgActivitySpecialTwoDays 活动开始前两天08:00,提醒报名客户 \提醒报名客户的对口销售
|
|
|
+func SendWxMsgActivitySpecialTwoDays(cont context.Context) (err error) {
|
|
|
+ var msg string
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err)
|
|
|
+ go utils.SendEmail("发送模版消息失败"+"【"+utils.APPNAME+"】"+time.Now().Format("2006-01-02 15:04:05"), msg+";Err:"+err.Error(), utils.EmailSendToUsers)
|
|
|
+ go utils.SendAlarmMsg(fmt.Sprint(" 活动开始前两天08:00,提醒报名客户、提醒报名客户的对口销售消息发送失败"), 2)
|
|
|
+ utils.FileLog.Info("发送模版消息失败,Err:%s", err.Error())
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ twoDayTime := time.Now().AddDate(0, 0, 2)
|
|
|
+ startTime := twoDayTime.Format(utils.FormatDate) + " 00:00:00"
|
|
|
+ endTime := twoDayTime.Format(utils.FormatDate) + " 23:59:59"
|
|
|
+ var condition string
|
|
|
+ var pars []interface{}
|
|
|
+ condition = ` AND days >0 AND activity_time BETWEEN ? AND ? `
|
|
|
+ pars = append(pars, startTime, endTime)
|
|
|
+ listActivitySpecial, e := models.GetActivitySpecialListAll(condition, pars, 0, 1000)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetSellerByAdminId, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(listActivitySpecial) == 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ var activityIds []int
|
|
|
+
|
|
|
+ for _, v := range listActivitySpecial {
|
|
|
+ activityIds = append(activityIds, v.ActivityId)
|
|
|
+ condition = ` AND is_cancel = 0 AND activity_id = ` + strconv.Itoa(v.ActivityId)
|
|
|
+ pars = make([]interface{}, 0)
|
|
|
+ listSpecialTrip, e := models.GetCygxActivitySpecialTripList(condition, pars)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetCygxActivitySpecialTripList, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(listSpecialTrip) == 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var mobile string
|
|
|
+ var companyIds []int
|
|
|
+ for _, vT := range listSpecialTrip {
|
|
|
+ mobile += "'" + vT.Mobile + "',"
|
|
|
+ companyIds = append(companyIds, vT.CompanyId)
|
|
|
+ }
|
|
|
+ mobile = strings.TrimRight(mobile, ",")
|
|
|
+ openIdList, e := models.GetWxOpenIdByMobileList(mobile)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetSellerByAdminId, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ first := "【" + v.ResearchTheme + "】专项调研将在两天后进行,如不能参加,请及时取消报名"
|
|
|
+ keyword1 := v.ResearchTheme
|
|
|
+ keyword2 := "已报名"
|
|
|
+ keyword3 := v.ActivityTimeTextByDay
|
|
|
+ keyword4 := "线上"
|
|
|
+ if v.SpecialType == 2 {
|
|
|
+ keyword4 = v.City
|
|
|
+ }
|
|
|
+ remark := "点击查看活动详情"
|
|
|
+ SendWxMsgWithFrequency(first, keyword1, keyword2, keyword3, keyword4, remark, openIdList, v.ActivityId)
|
|
|
+
|
|
|
+ //活动开始前两天08:00,提醒报名客户的对口销售
|
|
|
+ companyIdsLen := len(companyIds)
|
|
|
+ if companyIdsLen == 0 {
|
|
|
+ continue
|
|
|
+ } else {
|
|
|
+ pars = make([]interface{}, 0)
|
|
|
+ condition = ` AND p.company_id IN (` + utils.GetOrmInReplace(companyIdsLen) + `) GROUP BY p.company_id `
|
|
|
+ pars = append(pars, companyIds)
|
|
|
+
|
|
|
+ listSeller, e := models.GetAdminOpendidByCompany(condition, pars)
|
|
|
+ if e != nil && e.Error() != utils.ErrNoRow() {
|
|
|
+ err = errors.New("GetAdminOpendidByCompany, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(listSeller) == 0 {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ type SllerData struct {
|
|
|
+ Openid string `description:"Openid"`
|
|
|
+ Keyword string `description:"Keyword "`
|
|
|
+ }
|
|
|
+ mapSller := make(map[string]string)
|
|
|
+ mapSllerOpenid := make(map[string]string)
|
|
|
+ for _, vS := range listSeller {
|
|
|
+ for _, vT := range listSpecialTrip {
|
|
|
+ if vT.CompanyId == vS.CompanyId {
|
|
|
+ mapSller[vS.Mobile] += "【" + vT.RealName + "--" + vT.CompanyName + "】"
|
|
|
+ mapSllerOpenid[vS.Mobile] = vS.OpenId
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for k, vM := range mapSller {
|
|
|
+ first = "【" + v.ResearchTheme + "】专项调研将在两天后进行,请及时提醒您的报名客户"
|
|
|
+ keyword2 = vM
|
|
|
+ openIdList = make([]*models.OpenIdList, 0)
|
|
|
+ openIdList = append(openIdList, &models.OpenIdList{OpenId: mapSllerOpenid[k]})
|
|
|
+ SendWxMsgWithFrequency(first, keyword1, keyword2, keyword3, keyword4, remark, openIdList, v.ActivityId)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+//SendWxMsgActivitySpecialCancel 线下活动前4天08:00报名人数不足7人,线上活动前3天08:00报名人数不足10人,活动自动取消发布,并推送模板消息至报名客户及对口销售
|
|
|
+func SendWxMsgActivitySpecialCancel(cont context.Context) (err error) {
|
|
|
+ var msg string
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err)
|
|
|
+ go utils.SendEmail("发送模版消息失败"+"【"+utils.APPNAME+"】"+time.Now().Format("2006-01-02 15:04:05"), msg+";Err:"+err.Error(), utils.EmailSendToUsers)
|
|
|
+ go utils.SendAlarmMsg(fmt.Sprint(" 活动开始前两天08:00,提醒报名客户、提醒报名客户的对口销售消息发送失败"), 2)
|
|
|
+ utils.FileLog.Info("发送模版消息失败,Err:%s", err.Error())
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ dayTime3 := time.Now().AddDate(0, 0, 3)
|
|
|
+ startTime := dayTime3.Format(utils.FormatDate) + " 00:00:00"
|
|
|
+ endTime := dayTime3.Format(utils.FormatDate) + " 23:59:59"
|
|
|
+
|
|
|
+ dayTime4 := time.Now().AddDate(0, 0, 4)
|
|
|
+ startTime4 := dayTime4.Format(utils.FormatDate) + " 00:00:00"
|
|
|
+ endTime4 := dayTime4.Format(utils.FormatDate) + " 23:59:59"
|
|
|
+ var condition string
|
|
|
+ var pars []interface{}
|
|
|
+ condition = ` AND days >0 AND activity_time BETWEEN ? AND ? AND special_type= 1 `
|
|
|
+ pars = append(pars, startTime, endTime)
|
|
|
+
|
|
|
+ condition += ` OR ( days >0 AND activity_time BETWEEN ? AND ? AND special_type= 2 ) `
|
|
|
+ pars = append(pars, startTime4, endTime4)
|
|
|
+
|
|
|
+ listActivitySpecial, e := models.GetActivitySpecialListAll(condition, pars, 0, 1000)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetSellerByAdminId, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(listActivitySpecial) == 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ var activityIds []int
|
|
|
+
|
|
|
+ for _, v := range listActivitySpecial {
|
|
|
+ activityIds = append(activityIds, v.ActivityId)
|
|
|
+ condition = ` AND is_cancel = 0 AND activity_id = ` + strconv.Itoa(v.ActivityId)
|
|
|
+ pars = make([]interface{}, 0)
|
|
|
+ listSpecialTrip, e := models.GetCygxActivitySpecialTripList(condition, pars)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetCygxActivitySpecialTripList, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if v.SpecialType == 1 {
|
|
|
+ if len(listSpecialTrip) >= 10 {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if v.SpecialType == 2 {
|
|
|
+ if len(listSpecialTrip) >= 7 {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ }
|
|
|
+ e = models.UpdateActivitySpecialPublishStatus(0, v.ActivityId)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("UpdateActivitySpecialPublishStatus,自动取消专项调研日程失败 Err: " + e.Error() + strconv.Itoa(v.ActivityId))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(listSpecialTrip) < 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var mobile string
|
|
|
+ var companyIds []int
|
|
|
+ for _, vT := range listSpecialTrip {
|
|
|
+ mobile += "'" + vT.Mobile + "',"
|
|
|
+ companyIds = append(companyIds, vT.CompanyId)
|
|
|
+ }
|
|
|
+ mobile = strings.TrimRight(mobile, ",")
|
|
|
+ openIdList, e := models.GetWxOpenIdByMobileList(mobile)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetSellerByAdminId, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ first := "【" + v.ResearchTheme + "】专项调研因专家安排变动,本次调研活动延期举办,具体时间另行通知"
|
|
|
+ keyword1 := v.ResearchTheme
|
|
|
+ keyword2 := "已取消"
|
|
|
+ keyword3 := ""
|
|
|
+ keyword4 := ""
|
|
|
+ remark := ""
|
|
|
+
|
|
|
+ openIdArr := make([]string, 0)
|
|
|
+ for _, vOpenid := range openIdList {
|
|
|
+ openIdArr = append(openIdArr, vOpenid.OpenId)
|
|
|
+ }
|
|
|
+ companyIdsLen := len(companyIds)
|
|
|
+ if len(companyIds) > 0 {
|
|
|
+ pars = make([]interface{}, 0)
|
|
|
+ condition = ` AND p.company_id IN (` + utils.GetOrmInReplace(companyIdsLen) + `) GROUP BY p.company_id `
|
|
|
+ pars = append(pars, companyIds)
|
|
|
+ listSeller, e := models.GetAdminOpendidByCompany(condition, pars)
|
|
|
+ if e != nil && e.Error() != utils.ErrNoRow() {
|
|
|
+ err = errors.New("GetAdminOpendidByCompany, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(listSeller) > 0 {
|
|
|
+ for _, vOpenid := range listSeller {
|
|
|
+ openIdArr = append(openIdArr, vOpenid.OpenId)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ redirectUrl := ""
|
|
|
+ sendInfo := new(SendWxTemplate)
|
|
|
+ sendInfo.First = first
|
|
|
+ sendInfo.Keyword1 = keyword1
|
|
|
+ sendInfo.Keyword2 = keyword2
|
|
|
+ sendInfo.Keyword3 = keyword3
|
|
|
+ sendInfo.Keyword4 = keyword4
|
|
|
+ sendInfo.Remark = remark
|
|
|
+ sendInfo.TemplateId = utils.WxMsgTemplateIdArticleUserRemind
|
|
|
+ sendInfo.RedirectUrl = redirectUrl
|
|
|
+ sendInfo.RedirectTarget = 3
|
|
|
+ sendInfo.Resource = strconv.Itoa(v.ActivityId)
|
|
|
+ sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
|
|
|
+ sendInfo.OpenIdArr = openIdArr
|
|
|
+ fmt.Println(sendInfo)
|
|
|
+ err = PublicSendTemplateMsg(sendInfo)
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|