|
@@ -5,7 +5,6 @@ import (
|
|
|
"fmt"
|
|
|
"github.com/gogf/gf/v2/container/gset"
|
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
|
- "github.com/gogf/gf/v2/os/gctx"
|
|
|
"github.com/gogf/gf/v2/os/gtime"
|
|
|
"newuserSend/internal/consts"
|
|
|
"newuserSend/internal/dao"
|
|
@@ -17,28 +16,16 @@ import (
|
|
|
)
|
|
|
|
|
|
var nsm *utility.StationMessage
|
|
|
-var testSet *gset.Set
|
|
|
-var testSwitch bool
|
|
|
-var IndustryMap map[string]interface{}
|
|
|
+var industryUrlMap map[string]interface{}
|
|
|
|
|
|
-func init() {
|
|
|
- ctx := gctx.New()
|
|
|
- phones := g.Cfg().MustGet(ctx, "test.phone").Array()
|
|
|
- testSet = gset.NewFrom(phones, true)
|
|
|
- testSwitch = g.Cfg().MustGet(ctx, "test.switch").Bool()
|
|
|
- industry := []entity.DScopeclassCode{}
|
|
|
- err := dao.DScopeclassCode.Ctx(ctx).Fields("code,name").Where("level=?", 1).Scan(&industry)
|
|
|
- if err != nil {
|
|
|
- panic("初始化行业code信息异常")
|
|
|
- }
|
|
|
- for i := 0; i < len(industry); i++ {
|
|
|
- IndustryMap[industry[i].Code] = industry[i].Name
|
|
|
- }
|
|
|
-}
|
|
|
func Task(ctx context.Context) {
|
|
|
+ phones := g.Cfg().MustGet(ctx, "test.phone").Array()
|
|
|
+ testSet := gset.NewFrom(phones, true)
|
|
|
+ testSwitch := g.Cfg().MustGet(ctx, "test.switch").Bool()
|
|
|
addr := g.Cfg().MustGet(ctx, "siteMsg.addr").String()
|
|
|
action := g.Cfg().MustGet(ctx, "siteMsg.action").String()
|
|
|
callplatform := g.Cfg().MustGet(ctx, "siteMsg.callPlatform").String()
|
|
|
+ industryUrlMap = g.Cfg().MustGet(ctx, "industryUrl").Map()
|
|
|
nsm = utility.NewStationMessage(addr, action, callplatform)
|
|
|
start := time.Now()
|
|
|
defer func() {
|
|
@@ -75,6 +62,10 @@ func Task(ctx context.Context) {
|
|
|
g.Log().Error(ctx, "获取待发送用户失败", sendContent[i].RuleId, err)
|
|
|
break
|
|
|
}
|
|
|
+ // 是否开启测试范围
|
|
|
+ if testSwitch {
|
|
|
+ userList = filterTest(ctx, testSet, userList)
|
|
|
+ }
|
|
|
// 发送消息
|
|
|
sendMsg(ctx, sendContent[i], userList)
|
|
|
g.Log().Infof(ctx, "发送第%v个发送规则:id-%v 内容id:%v 批次:%v-%v\n", i, sendContent[i].RuleId, sendContent[i].Id, j, j+200)
|
|
@@ -98,7 +89,7 @@ func sendMsg(ctx context.Context, content entity.NewUserSendContent, sendUserLis
|
|
|
}
|
|
|
|
|
|
func sms(ctx context.Context, content entity.NewUserSendContent, sendUserList []entity.NewUserSendLog) {
|
|
|
- // todo 处理行业短信模板变量
|
|
|
+ // 处理行业短信模板变量
|
|
|
for i := 0; i < len(sendUserList); i++ {
|
|
|
smsIDIndex := content.SmsId
|
|
|
smsvar := content.SmsVar
|
|
@@ -115,19 +106,13 @@ func sms(ctx context.Context, content entity.NewUserSendContent, sendUserList []
|
|
|
vardata = append(vardata, fmt.Sprint(gtime.Now().Month()))
|
|
|
case consts.SmsVarYear:
|
|
|
vardata = append(vardata, fmt.Sprint(gtime.Now().Year()))
|
|
|
+ case consts.SmsVarIndustry:
|
|
|
+ vardata = append(vardata, sendUserList[i].Industry)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- if testSwitch {
|
|
|
- if testSet.Contains(sendUserList[i].Phone) {
|
|
|
- utility.NewSMSDao(sendUserList[i].Phone, vardata, smsIDIndex).SendMsgBySMS(ctx)
|
|
|
- } else {
|
|
|
- g.Log().Info(ctx, "测试模式已开启-该手机号不在测试范围:", sendUserList[i].Phone)
|
|
|
+ utility.NewSMSDao(sendUserList[i].Phone, vardata, smsIDIndex).SendMsgBySMS(ctx)
|
|
|
|
|
|
- }
|
|
|
- } else {
|
|
|
- utility.NewSMSDao(sendUserList[i].Phone, vardata, content.SmsId).SendMsgBySMS(ctx)
|
|
|
- }
|
|
|
}
|
|
|
//g.Log().Info(ctx, "sms 发送完成:",sendUserList,content.RuleId)
|
|
|
|
|
@@ -141,7 +126,6 @@ func siteMsg(ctx context.Context, content entity.NewUserSendContent, sendUserLis
|
|
|
msgTitle = strings.ReplaceAll(msgTitle, consts.SiteMsgMonth, monthStr)
|
|
|
urls := strings.Split(content.MsgUrl, ",")
|
|
|
var pcUrl, androidUrl, iosUrl, weChatUrl string
|
|
|
- // todo 区分行业跳转地址
|
|
|
if len(urls) > 0 {
|
|
|
if len(urls) != 4 {
|
|
|
pcUrl, androidUrl, iosUrl, weChatUrl = urls[0], urls[0], urls[0], urls[0]
|
|
@@ -153,16 +137,27 @@ func siteMsg(ctx context.Context, content entity.NewUserSendContent, sendUserLis
|
|
|
msgType := g.Cfg().MustGet(ctx, "siteMsg.msgType").Int()
|
|
|
mgoIds := []string{}
|
|
|
for i := 0; i < len(sendUserList); i++ {
|
|
|
+ // todo 处理行业跳转
|
|
|
+ industryPcUrl, industryAndroidUrl, industryIosUrl, industryWeChatUrl := pcUrl, androidUrl, iosUrl, weChatUrl
|
|
|
if sendUserList[i].Industry == "" {
|
|
|
mgoIds = append(mgoIds, sendUserList[i].UserId)
|
|
|
} else {
|
|
|
- // todo 处理行业跳转
|
|
|
- //industryUrl := content.IndustryMsgUrl
|
|
|
- // 有行业的需要单独处理跳转地址
|
|
|
- //newparm := utility.MessageParam{
|
|
|
- // UserIds: sendUserList[i].UserId, Title: msgTitle, Content: msgInfo, Link: pcUrl, AndroidUrl: androidUrl, IosUrl: iosUrl, WeChatUrl: weChatUrl, MsgType: msgType,
|
|
|
- //}
|
|
|
- //nsm.SendStationMessages(ctx, newparm)
|
|
|
+ //有行业的需要单独处理跳转地址
|
|
|
+ urlvar := industryUrlMap[sendUserList[i].Industry]
|
|
|
+ if urlvar != "" {
|
|
|
+ industryUrls := strings.Split(content.IndustryMsgUrl, ",")
|
|
|
+ if len(industryUrls) > 0 {
|
|
|
+ if len(industryUrls) != 4 {
|
|
|
+ industryPcUrl, industryAndroidUrl, industryIosUrl, industryWeChatUrl = industryUrls[0], industryUrls[0], industryUrls[0], industryUrls[0]
|
|
|
+ } else {
|
|
|
+ industryPcUrl, industryAndroidUrl, industryIosUrl, industryWeChatUrl = industryUrls[0], industryUrls[1], industryUrls[2], industryUrls[3]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ newparm := utility.MessageParam{
|
|
|
+ UserIds: sendUserList[i].UserId, Title: msgTitle, Content: msgInfo, Link: industryPcUrl, AndroidUrl: industryAndroidUrl, IosUrl: industryIosUrl, WeChatUrl: industryWeChatUrl, MsgType: msgType,
|
|
|
+ }
|
|
|
+ nsm.SendStationMessages(ctx, newparm)
|
|
|
}
|
|
|
}
|
|
|
parm := utility.MessageParam{
|
|
@@ -182,3 +177,14 @@ func updateState(ctx context.Context, sendUserList []entity.NewUserSendLog) {
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+func filterTest(ctx context.Context, testSet *gset.Set, userList []entity.NewUserSendLog) (newUserList []entity.NewUserSendLog) {
|
|
|
+ for i := 0; i < len(userList); i++ {
|
|
|
+ if testSet != nil && testSet.Contains(userList[i].Phone) {
|
|
|
+ newUserList = append(newUserList, userList[i])
|
|
|
+ } else {
|
|
|
+ g.Log().Info(ctx, "filterTest 不在测试范围内", userList[i])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|