Explorar o código

fix: 模板消息推送

hsun %!s(int64=2) %!d(string=hai) anos
pai
achega
082a633d33
Modificáronse 2 ficheiros con 19 adicións e 4 borrados
  1. 1 1
      services/community/question.go
  2. 18 3
      services/wechat/template_msg.go

+ 1 - 1
services/community/question.go

@@ -267,7 +267,7 @@ func ReplyUserQuestion(replierId, questionId int, audios []*request.ReplyReqAudi
 		return
 	}
 	// 推送回复消息给用户
-	go wechat.SendQuestionReplyWxMsg(item.CommunityQuestionID, item.UserID, item.UserOpenid, item.QuestionContent)
+	go wechat.SendQuestionReplyWxMsg(item.CommunityQuestionID, item.UserID, item.QuestionContent)
 	return
 }
 

+ 18 - 3
services/wechat/template_msg.go

@@ -7,6 +7,7 @@ import (
 	"errors"
 	"fmt"
 	"hongze/hongze_yb/global"
+	"hongze/hongze_yb/models/tables/user_record"
 	"hongze/hongze_yb/models/tables/user_template_record"
 	"hongze/hongze_yb/services/alarm_msg"
 	"hongze/hongze_yb/utils"
@@ -174,8 +175,8 @@ func SendMultiTemplateMsg(sendMap map[string]interface{}, items []*OpenIdList, r
 }
 
 // SendQuestionReplyWxMsg 推送研报小程序模板消息-问答社区回复
-func SendQuestionReplyWxMsg(questionId, userId int, openid, questionTitle string) (err error) {
-	if userId == 0 || openid == "" {
+func SendQuestionReplyWxMsg(questionId, userId int, questionTitle string) (err error) {
+	if userId == 0 {
 		return
 	}
 	var errMsg string
@@ -185,10 +186,24 @@ func SendQuestionReplyWxMsg(questionId, userId int, openid, questionTitle string
 			go alarm_msg.SendAlarmMsg(alarmMsg, 3)
 		}
 	}()
+	// 校验用户是否取消关注公众号
+	userRecord, e := user_record.GetByUserId(userId, utils.USER_RECORD_PLATFORM_RDDP)
+	if e != nil {
+		// 用户无公众号信息
+		if e == utils.ErrNoRow {
+			return
+		}
+		err = errors.New("获取用户Record信息失败, Err:" + e.Error())
+		return
+	}
+	// 取消关注则不推送
+	if userRecord.Subscribe == 0 {
+		return
+	}
 
 	openIdList := make([]*OpenIdList, 0)
 	openIdList = append(openIdList, &OpenIdList{
-		OpenId: openid,
+		OpenId: userRecord.OpenID,
 		UserId: userId,
 	})