浏览代码

模版消息

ziwen 2 年之前
父节点
当前提交
9a2a2d77a5
共有 4 个文件被更改,包括 63 次插入0 次删除
  1. 5 0
      controller/voice_broadcast/voice_broadcast.go
  2. 13 0
      models/tables/wx_user/query.go
  3. 44 0
      services/wechat/template_msg.go
  4. 1 0
      utils/constants.go

+ 5 - 0
controller/voice_broadcast/voice_broadcast.go

@@ -12,6 +12,7 @@ import (
 	"hongze/hongze_yb/services"
 	"hongze/hongze_yb/services"
 	"hongze/hongze_yb/services/company"
 	"hongze/hongze_yb/services/company"
 	"hongze/hongze_yb/services/user"
 	"hongze/hongze_yb/services/user"
+	"hongze/hongze_yb/services/wechat"
 	"hongze/hongze_yb/utils"
 	"hongze/hongze_yb/utils"
 	"io/ioutil"
 	"io/ioutil"
 	"os"
 	"os"
@@ -167,6 +168,10 @@ func AddBroadcast(c *gin.Context) {
 	if err != nil {
 	if err != nil {
 		fmt.Println("AddUserViewHistory err", err.Error())
 		fmt.Println("AddUserViewHistory err", err.Error())
 	}
 	}
+
+	// 推送回复消息给用户
+	go wechat.SendVoiceBroadcastWxMsg(voiceBroadcast.BroadcastId, voiceBroadcast.SectionName, voiceBroadcast.BroadcastName)
+
 	response.Ok("发布成功", c)
 	response.Ok("发布成功", c)
 }
 }
 
 

+ 13 - 0
models/tables/wx_user/query.go

@@ -3,6 +3,7 @@ package wx_user
 import (
 import (
 	"errors"
 	"errors"
 	"hongze/hongze_yb/global"
 	"hongze/hongze_yb/global"
+	"hongze/hongze_yb/services/wechat"
 	"hongze/hongze_yb/utils"
 	"hongze/hongze_yb/utils"
 )
 )
 
 
@@ -39,4 +40,16 @@ func GetByUserId(userId int) (wxUser *WxUser, err error) {
 func GetByUserIds(userIds []uint64) (list []*WxUser, err error) {
 func GetByUserIds(userIds []uint64) (list []*WxUser, err error) {
 	err = global.DEFAULT_MYSQL.Model(WxUser{}).Where("user_id in  ? ", userIds).Scan(&list).Error
 	err = global.DEFAULT_MYSQL.Model(WxUser{}).Where("user_id in  ? ", userIds).Scan(&list).Error
 	return
 	return
+}
+
+
+func GetOpenIdList() (items []*wechat.OpenIdList, err error) {
+	sql := `SELECT DISTINCT ur.open_id,wu.user_id FROM wx_user AS wu 
+          INNER JOIN company AS c ON c.company_id = wu.company_id 
+          INNER JOIN company_product AS d ON c.company_id=d.company_id
+		INNER join user_record  as ur on wu.user_id=ur.user_id
+          WHERE ur.open_id != "" AND ur.subscribe=1 and ur.create_platform=1 AND  d.status IN('正式','试用','永续') `
+
+	err = global.DEFAULT_MYSQL.Raw(sql).Scan(&items).Error
+	return
 }
 }

+ 44 - 0
services/wechat/template_msg.go

@@ -9,6 +9,7 @@ import (
 	"hongze/hongze_yb/global"
 	"hongze/hongze_yb/global"
 	"hongze/hongze_yb/models/tables/user_record"
 	"hongze/hongze_yb/models/tables/user_record"
 	"hongze/hongze_yb/models/tables/user_template_record"
 	"hongze/hongze_yb/models/tables/user_template_record"
+	"hongze/hongze_yb/models/tables/wx_user"
 	"hongze/hongze_yb/services/alarm_msg"
 	"hongze/hongze_yb/services/alarm_msg"
 	"hongze/hongze_yb/utils"
 	"hongze/hongze_yb/utils"
 	"io/ioutil"
 	"io/ioutil"
@@ -233,4 +234,47 @@ func SendQuestionReplyWxMsg(questionId, userId int, questionTitle string) (err e
 	}
 	}
 	err = SendMultiTemplateMsg(sendMap, openIdList, wxAppPath, utils.TEMPLATE_MSG_YB_COMMUNITY_QUESTION)
 	err = SendMultiTemplateMsg(sendMap, openIdList, wxAppPath, utils.TEMPLATE_MSG_YB_COMMUNITY_QUESTION)
 	return
 	return
+}
+
+// SendVoiceBroadcastWxMsg 推送研报小程序模板消息-语音播报
+func SendVoiceBroadcastWxMsg(broadcastId int, sectionName, broadcastName string) (err error) {
+	var errMsg string
+	defer func() {
+		if err != nil {
+			alarmMsg := fmt.Sprintf("SendVoiceBroadcastWxMsg-推送语音播报模版消息失败; broadcastId: %d; Err: %s; Msg: %s", broadcastId, err.Error(), errMsg)
+			go alarm_msg.SendAlarmMsg(alarmMsg, 3)
+		}
+	}()
+
+	openIdList, err := wx_user.GetOpenIdList()
+	if err != nil {
+		return
+	}
+
+	sendMap := make(map[string]interface{})
+	sendData := make(map[string]interface{})
+
+	first := "您好,有新的语音播报待查看"
+	keyword1 := sectionName + ":" + broadcastName
+	keyword2 := "待查看"
+	remark := "请点击详情查看"
+
+	sendData["first"] = map[string]interface{}{"value": first, "color": "#173177"}
+	sendData["keyword1"] = map[string]interface{}{"value": keyword1, "color": "#173177"}
+	sendData["keyword2"] = map[string]interface{}{"value": keyword2, "color": "#173177"}
+	sendData["remark"] = map[string]interface{}{"value": remark, "color": "#173177"}
+
+	sendMap["template_id"] = TemplateIdWithCommunityQuestion
+	sendMap["data"] = sendData
+
+	wxAppPath := fmt.Sprintf("pages/voice/voice?voiceId=%d", broadcastId)
+	//if global.CONFIG.Serve.RunMode == "debug" {
+	//	// 仅测试环境测试用
+	//	wxAppPath = "pages/voice/voice?voiceId"
+	//}
+	if wxAppPath != "" {
+		sendMap["miniprogram"] = map[string]interface{}{"appid": WxYbAppId, "pagepath": wxAppPath}
+	}
+	err = SendMultiTemplateMsg(sendMap, openIdList, wxAppPath, utils.TEMPLATE_MSG_YB_VOICE_BROADCAST)
+	return
 }
 }

+ 1 - 0
utils/constants.go

@@ -136,6 +136,7 @@ const (
 	TEMPLATE_MSG_ACTIVITY_APPOINTMENT            //活动预约/报名时间通知
 	TEMPLATE_MSG_ACTIVITY_APPOINTMENT            //活动预约/报名时间通知
 	_
 	_
 	TEMPLATE_MSG_YB_COMMUNITY_QUESTION // 研报小程序-问答社区通知
 	TEMPLATE_MSG_YB_COMMUNITY_QUESTION // 研报小程序-问答社区通知
+	TEMPLATE_MSG_YB_VOICE_BROADCAST // 研报小程序-语音播报
 )
 )
 
 
 // 微信用户user_record注册平台
 // 微信用户user_record注册平台