|
@@ -3,7 +3,9 @@ package logic
|
|
|
import (
|
|
|
"context"
|
|
|
"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"
|
|
@@ -15,7 +17,24 @@ import (
|
|
|
)
|
|
|
|
|
|
var nsm *utility.StationMessage
|
|
|
+var testSet *gset.Set
|
|
|
+var testSwitch bool
|
|
|
+var IndustryMap 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) {
|
|
|
addr := g.Cfg().MustGet(ctx, "siteMsg.addr").String()
|
|
|
action := g.Cfg().MustGet(ctx, "siteMsg.action").String()
|
|
@@ -79,21 +98,36 @@ func sendMsg(ctx context.Context, content entity.NewUserSendContent, sendUserLis
|
|
|
}
|
|
|
|
|
|
func sms(ctx context.Context, content entity.NewUserSendContent, sendUserList []entity.NewUserSendLog) {
|
|
|
- // 处理短信请求数据
|
|
|
- vardata := []string{}
|
|
|
- if content.SmsVar != "" {
|
|
|
- smsvars := strings.Split(content.SmsVar, ",")
|
|
|
- for i := 0; i < len(smsvars); i++ {
|
|
|
- switch smsvars[i] {
|
|
|
- case consts.SmsVarMonth:
|
|
|
- vardata = append(vardata, fmt.Sprint(gtime.Now().Month()))
|
|
|
- case consts.SmsVarYear:
|
|
|
- vardata = append(vardata, fmt.Sprint(gtime.Now().Year()))
|
|
|
+ // todo 处理行业短信模板变量
|
|
|
+ for i := 0; i < len(sendUserList); i++ {
|
|
|
+ smsIDIndex := content.SmsId
|
|
|
+ smsvar := content.SmsVar
|
|
|
+ if sendUserList[i].Industry != "" {
|
|
|
+ smsIDIndex = content.IndustrySmsId
|
|
|
+ smsvar = content.IndustrySmsVar
|
|
|
+ }
|
|
|
+ vardata := []string{}
|
|
|
+ if smsvar != "" {
|
|
|
+ smsvars := strings.Split(smsvar, ",")
|
|
|
+ for i := 0; i < len(smsvars); i++ {
|
|
|
+ switch smsvars[i] {
|
|
|
+ case consts.SmsVarMonth:
|
|
|
+ vardata = append(vardata, fmt.Sprint(gtime.Now().Month()))
|
|
|
+ case consts.SmsVarYear:
|
|
|
+ vardata = append(vardata, fmt.Sprint(gtime.Now().Year()))
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- for i := 0; i < len(sendUserList); i++ {
|
|
|
- utility.NewSMSDao(sendUserList[i].Phone, vardata, content.SmsId).SendMsgBySMS(ctx)
|
|
|
+ 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)
|
|
|
+
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ utility.NewSMSDao(sendUserList[i].Phone, vardata, content.SmsId).SendMsgBySMS(ctx)
|
|
|
+ }
|
|
|
}
|
|
|
//g.Log().Info(ctx, "sms 发送完成:",sendUserList,content.RuleId)
|
|
|
|
|
@@ -107,6 +141,7 @@ 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]
|
|
@@ -114,15 +149,27 @@ func siteMsg(ctx context.Context, content entity.NewUserSendContent, sendUserLis
|
|
|
pcUrl, androidUrl, iosUrl, weChatUrl = urls[0], urls[1], urls[2], urls[3]
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ msgType := g.Cfg().MustGet(ctx, "siteMsg.msgType").Int()
|
|
|
mgoIds := []string{}
|
|
|
for i := 0; i < len(sendUserList); i++ {
|
|
|
- mgoIds = append(mgoIds, sendUserList[i].UserId)
|
|
|
+ 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)
|
|
|
+ }
|
|
|
}
|
|
|
- msgType := g.Cfg().MustGet(ctx, "siteMsg.msgType").Int()
|
|
|
parm := utility.MessageParam{
|
|
|
UserIds: strings.Join(mgoIds, ","), Title: msgTitle, Content: msgInfo, Link: pcUrl, AndroidUrl: androidUrl, IosUrl: iosUrl, WeChatUrl: weChatUrl, MsgType: msgType,
|
|
|
}
|
|
|
nsm.SendStationMessages(ctx, parm)
|
|
|
+ //
|
|
|
}
|
|
|
func updateState(ctx context.Context, sendUserList []entity.NewUserSendLog) {
|
|
|
ids := []int{}
|