From 6e9a5538aecfbae33034a04d367c8a7680363f10 Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Thu, 5 Dec 2024 16:06:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A8=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/task/svc/svc_aliyun_sms_record.go | 54 ++++++++++++++++++++++++++- app/task/svc/svc_jpush_record.go | 52 ++++++++++++++++++++++++++ app/task/svc/svc_no_login_send.go | 2 +- app/task/svc/svc_no_sign_send.go | 2 +- go.mod | 2 +- 5 files changed, 108 insertions(+), 4 deletions(-) diff --git a/app/task/svc/svc_aliyun_sms_record.go b/app/task/svc/svc_aliyun_sms_record.go index 7f3ef9b..4847c99 100644 --- a/app/task/svc/svc_aliyun_sms_record.go +++ b/app/task/svc/svc_aliyun_sms_record.go @@ -1,6 +1,7 @@ package svc import ( + "applet/app/db" "applet/app/md" "applet/app/utils" "applet/app/utils/cache" @@ -35,17 +36,68 @@ func AliyunSmsRecord(eg *xorm.Engine) { if v.Target == "0" { //全量用户 commSmsSend(eg, ch, v, p, "") } - if v.Target == "1" { //全量用户 + if v.Target == "1" || v.Target == "4" { //指定用户 MoreSmsSend(eg, ch, v) } if v.Target == "2" { //等级 commSmsSend(eg, ch, v, p, utils.IntToStr(v.Level)) } + if v.Target == "3" { //指定标签 + tagSmsRecordSend(eg, ch, v, p) + } v.IsRun = 1 eg.Where("id=?", v.Id).Cols("is_run").Update(&v) } cache.Del(key) } +func tagSmsRecordSend(eg *xorm.Engine, ch *rabbit.Channel, data model.AliyunSmsRecord, p int) { + sql := ` + SELECT * FROM user_tag_records utr +left join user u on u.id=utr.uid +WHERE %s GROUP BY u.id ORDER BY u.id asc %s +` + tagList := make([]string, 0) + json.Unmarshal([]byte(data.TagId), &tagList) + if len(tagList) == 0 { + return + } + where := "tag_id in(" + strings.Join(tagList, ",") + ")" + limit := " limit " + utils.IntToStr((p-1)*1000) + ",1000" + sql = fmt.Sprintf(sql, where, limit) + userList, _ := db.QueryNativeString(eg, sql) + uids := "" + if len(userList) == 0 { + return + } + for _, v := range userList { + if v["phone"] == "" { + continue + } + if uids == "" { + uids += v["phone"] + } else { + uids += "," + v["phone"] + } + } + if uids == "" { + return + } + arg := md.AliyunSmsRecordFundData{Phone: uids, Title: data.Title, Content: data.Content} + if len(userList) < 1000 { + arg.Id = utils.IntToStr(data.Id) + } + err := ch.PublishV2(md.EggAliyunSmsRecordQueueExchange, arg, md.EggAliyunSmsRecordQueue) + if err != nil { + ch.PublishV2(md.EggAliyunSmsRecordQueueExchange, arg, md.EggAliyunSmsRecordQueue) + } + if len(userList) == 1000 { + p++ + tagSmsRecordSend(eg, ch, data, p) + return + } + return + +} func commSmsSend(eg *xorm.Engine, ch *rabbit.Channel, data model.AliyunSmsRecord, p int, level string) { var userList []model.User diff --git a/app/task/svc/svc_jpush_record.go b/app/task/svc/svc_jpush_record.go index 3bf5862..8341bda 100644 --- a/app/task/svc/svc_jpush_record.go +++ b/app/task/svc/svc_jpush_record.go @@ -1,6 +1,7 @@ package svc import ( + "applet/app/db" "applet/app/md" "applet/app/utils" "applet/app/utils/cache" @@ -45,6 +46,9 @@ func JpushRecord(eg *xorm.Engine) { if v.Target == "2" { //等级 commJpushRecordSend(eg, ch, v, p, utils.IntToStr(v.Level)) } + if v.Target == "3" { //标签 + tagJpushRecordSend(eg, ch, v, p) + } v.IsRun = 1 eg.Where("id=?", v.Id).Cols("is_run").Update(&v) } @@ -90,6 +94,54 @@ func commJpushRecordSend(eg *xorm.Engine, ch *rabbit.Channel, data model.JpushRe } return +} +func tagJpushRecordSend(eg *xorm.Engine, ch *rabbit.Channel, data model.JpushRecord, p int) { + sql := ` + SELECT * FROM user_tag_records utr +left join user u on u.id=utr.uid +WHERE %s GROUP BY u.id ORDER BY u.id asc %s +` + tagList := make([]string, 0) + json.Unmarshal([]byte(data.TagId), &tagList) + if len(tagList) == 0 { + return + } + where := "tag_id in(" + strings.Join(tagList, ",") + ")" + limit := " limit " + utils.IntToStr((p-1)*1000) + ",1000" + sql = fmt.Sprintf(sql, where, limit) + userList, _ := db.QueryNativeString(eg, sql) + uids := "" + if len(userList) == 0 { + return + } + for _, v := range userList { + if v["phone"] == "" { + continue + } + if uids == "" { + uids += v["id"] + } else { + uids += "," + v["id"] + } + } + if uids == "" { + return + } + arg := md.JpushRecordFundData{UserId: uids, Target: data.Target, Platform: data.Platform, Title: data.Title, Content: data.Content} + if len(userList) < 1000 { + arg.Id = utils.IntToStr(data.Id) + } + err := ch.PublishV2(md.EggJpushRecordQueueExchange, arg, md.EggJpushRecordQueue) + if err != nil { + ch.PublishV2(md.EggJpushRecordQueueExchange, arg, md.EggJpushRecordQueue) + } + if len(userList) == 1000 { + p++ + tagJpushRecordSend(eg, ch, data, p) + return + } + return + } func MoreJpushRecordSend(eg *xorm.Engine, ch *rabbit.Channel, data model.JpushRecord) { userList := make([]string, 0) diff --git a/app/task/svc/svc_no_login_send.go b/app/task/svc/svc_no_login_send.go index aaea451..7be91fa 100644 --- a/app/task/svc/svc_no_login_send.go +++ b/app/task/svc/svc_no_login_send.go @@ -56,7 +56,7 @@ WHERE unt.login_time<'%d' and unt.login_notice_time<'%d' and unt.login_time>0 %s data.Content = strings.ReplaceAll(data.Content, "{昵称}", v["nickname"]) data.Content = strings.ReplaceAll(data.Content, "{手机号}", v["phone"]) data.Content = strings.ReplaceAll(data.Content, "{小时}", utils.Int64ToStr(hour)) - extra = "{\"hour\":\"" + utils.Int64ToStr(hour) + "\",\"name\":\"" + v["name"] + "\",\"phone\":\"" + v["phone"] + "\"}" + extra = "{\"hour\":\"" + utils.Int64ToStr(hour) + "\"}" arg := md.JpushRecordFundData{UserId: v["id"], Target: "1", Platform: "all", Title: data.Title, Content: data.Content} err := ch.PublishV2(md.EggJpushRecordQueueExchange, arg, md.EggJpushRecordQueue) if err != nil { diff --git a/app/task/svc/svc_no_sign_send.go b/app/task/svc/svc_no_sign_send.go index c675e2e..e47aff3 100644 --- a/app/task/svc/svc_no_sign_send.go +++ b/app/task/svc/svc_no_sign_send.go @@ -55,7 +55,7 @@ WHERE unt.sign_time<'%d' and unt.sign_notice_time<'%d' and unt.sign_time>0 %s data.Content = strings.ReplaceAll(data.Content, "{昵称}", v["nickname"]) data.Content = strings.ReplaceAll(data.Content, "{手机号}", v["phone"]) data.Content = strings.ReplaceAll(data.Content, "{小时}", utils.Int64ToStr(hour)) - extra = "{\"hour\":\"" + utils.Int64ToStr(hour) + "\",\"name\":\"" + v["name"] + "\",\"phone\":\"" + v["phone"] + "\"}" + extra = "{\"hour\":\"" + utils.Int64ToStr(hour) + "\"}" arg := md.JpushRecordFundData{UserId: v["id"], Target: "1", Platform: "all", Title: data.Title, Content: data.Content} err := ch.PublishV2(md.EggJpushRecordQueueExchange, arg, md.EggJpushRecordQueue) if err != nil { diff --git a/go.mod b/go.mod index e9e276c..90d7d98 100644 --- a/go.mod +++ b/go.mod @@ -32,7 +32,7 @@ require ( ) require ( - code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241205041102-0e106357c399 + code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241205080507-c27ed1ab5226 code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.4-0.20241205061938-91f42710d6cd code.fnuoos.com/go_rely_warehouse/zyos_go_es.git v1.0.1-0.20241118083738-0f22da9ba0be code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5