浏览代码

Merge branch 'yb/new_yb' into debug

hsun 2 年之前
父节点
当前提交
c495f6fe60
共有 4 个文件被更改,包括 116 次插入7 次删除
  1. 19 0
      models/yb/config.go
  2. 39 5
      services/report_push.go
  3. 42 0
      services/wechat.go
  4. 16 2
      services/wx_template_msg.go

+ 19 - 0
models/yb/config.go

@@ -0,0 +1,19 @@
+package yb
+
+import "github.com/beego/beego/v2/client/orm"
+
+type Config struct {
+	ConfigValue     string   `description:"配置值"`
+	ConfigCode      string   `description:"配置编码"`
+}
+
+func (c *Config) TableName() string {
+	return "yb_config"
+}
+// GetConfigByCode 查询配置详情
+func GetConfigByCode(configCode string) (item *Config, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM yb_config  WHERE config_code= ?`
+	err = o.Raw(sql, configCode).QueryRow(&item)
+	return
+}

+ 39 - 5
services/report_push.go

@@ -436,8 +436,14 @@ func SendReportMiniToThs(reportId int) (err error) {
 		return
 	}
 
+	// 获取研报小程序配置
+	ybConf, err := GetYbAppIdInfo()
+	if err != nil {
+		return
+	}
+
 	//小程序跳转地址
-	jumpBaseUrl := utils.WxYbAppId + `/pages-report/reportDetail?reportId=`
+	jumpBaseUrl := ybConf.AppId + `/pages-report/reportDetail?reportId=`
 	jumpUrl := fmt.Sprint(jumpBaseUrl, report.Id)
 	logoUrl := `https://hongze.oss-cn-shanghai.aliyuncs.com/hzyj.png`
 
@@ -512,8 +518,15 @@ func SendYbPriceDrivenToThs(priceDrivenId int) (err error) {
 	if permissionName == "宏观经济" {
 		permissionName = "宏观"
 	}
+
+	// 获取研报小程序配置
+	ybConf, err := GetYbAppIdInfo()
+	if err != nil {
+		return
+	}
+
 	title := fmt.Sprintf("%s价格驱动", permissionName)
-	jumpUrl := fmt.Sprintf(`%s/pages/pricedriven/pricedriven?default_classify_first=%d&default_classify_sub=%d`, utils.WxYbAppId, varietyTag.VarietyClassifyId, varietyTag.VarietyTagId)
+	jumpUrl := fmt.Sprintf(`%s/pages/pricedriven/pricedriven?default_classify_first=%d&default_classify_sub=%d`, ybConf.AppId, varietyTag.VarietyClassifyId, varietyTag.VarietyTagId)
 	logoUrl := `https://hongze.oss-cn-shanghai.aliyuncs.com/hzyj.png`
 	// 推送至同花顺
 	dataType := "2"
@@ -533,9 +546,16 @@ func SendYbCommunityVideoToThs(videoId int) (err error) {
 		err = errors.New("获取视频信息失败, Err:" + e.Error())
 		return
 	}
+
+	// 获取研报小程序配置
+	ybConf, err := GetYbAppIdInfo()
+	if err != nil {
+		return
+	}
+
 	permissionName := "宏观" // 所有客群都推
 	title := video.Title
-	jumpUrl := fmt.Sprint(utils.WxYbAppId+`/pages/video/videoList?videoId=`, videoId)
+	jumpUrl := fmt.Sprint(ybConf.AppId+`/pages/video/videoList?videoId=`, videoId)
 	logoUrl := `https://hongze.oss-cn-shanghai.aliyuncs.com/hzyj.png`
 	// 推送至同花顺
 	dataType := "2"
@@ -579,8 +599,15 @@ func SendYbRoadVideoToThs(videoId int) (err error) {
 	}
 	permissionName = strings.Trim(permissionName, ",")
 	//permissionName := "宏观" //写死宏观,默认所有群都推
+
+	// 获取研报小程序配置
+	ybConf, err := GetYbAppIdInfo()
+	if err != nil {
+		return
+	}
+
 	title := video.Title
-	jumpUrl := fmt.Sprint(utils.WxYbAppId+`/pages/roadShow/video/list?videoId=`, videoId)
+	jumpUrl := fmt.Sprint(ybConf.AppId+`/pages/roadShow/video/list?videoId=`, videoId)
 	logoUrl := `https://hongze.oss-cn-shanghai.aliyuncs.com/hzyj.png`
 	// 推送至同花顺
 	dataType := "2"
@@ -600,9 +627,16 @@ func SendYbVoiceBroadcastToThs(voiceId int) (err error) {
 		err = errors.New("获取语音播报信息失败, Err:" + e.Error())
 		return
 	}
+
+	// 获取研报小程序配置
+	ybConf, err := GetYbAppIdInfo()
+	if err != nil {
+		return
+	}
+
 	permissionName := "宏观" // 所有客群都推
 	title := voice.BroadcastName
-	jumpUrl := fmt.Sprint(utils.WxYbAppId+`/pages-voice/voiceDetail?voiceId=`, voiceId)
+	jumpUrl := fmt.Sprint(ybConf.AppId+`/pages-voice/voiceDetail?voiceId=`, voiceId)
 	logoUrl := `https://hongze.oss-cn-shanghai.aliyuncs.com/hzyj.png`
 	// 推送至同花顺
 	dataType := "2"

+ 42 - 0
services/wechat.go

@@ -0,0 +1,42 @@
+package services
+
+import (
+	"errors"
+	"fmt"
+	"hongze/hongze_task/models/yb"
+)
+
+// YbWxConf 研报小程序AppId配置
+type YbWxConf struct {
+	AppId           string `description:"AppID"`
+	MsgRedirectType int    `description:"公共模板消息跳转类型: 1-研报小程序; 4-备用小程序"`
+}
+
+func init()  {
+	confKey := "use_copy_yb"
+	conf, e := yb.GetConfigByCode(confKey)
+	if e != nil {
+		fmt.Println(e.Error())
+		return
+	}
+	fmt.Println("conf.ConfigValue", conf.ConfigValue)
+}
+
+// 根据研报配置获取研报小程序AppID信息
+func GetYbAppIdInfo() (ybConf *YbWxConf, err error) {
+	confKey := "use_copy_yb"
+	conf, e := yb.GetConfigByCode(confKey)
+	if e != nil {
+		err = errors.New("获取研报小程序配置信息失败, Err: " + e.Error())
+		return
+	}
+	ybConf = &YbWxConf{
+		AppId:           "wxb059c872d79b9967",
+		MsgRedirectType: 1,
+	}
+	if conf.ConfigValue == "true" {
+		ybConf.AppId = "wx9a2a9b49a00513a0"
+		ybConf.MsgRedirectType = 4
+	}
+	return
+}

+ 16 - 2
services/wx_template_msg.go

@@ -178,6 +178,13 @@ func SendWxMsgWithActivityAppointmentRemind(first, keyword1, keyword2, keyword3,
 		return
 	}
 
+	// 获取研报小程序配置
+	ybConf, err := GetYbAppIdInfo()
+	if err != nil {
+		msg = "获取研报小程序配置失败"
+		return
+	}
+
 	sendUrl := "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken
 	sendMap := make(map[string]interface{})
 	sendData := make(map[string]interface{})
@@ -191,7 +198,7 @@ func SendWxMsgWithActivityAppointmentRemind(first, keyword1, keyword2, keyword3,
 	sendData["remark"] = map[string]interface{}{"value": remark, "color": "#173177"}
 
 	if wxAppPath != "" {
-		sendMap["miniprogram"] = map[string]interface{}{"appid": utils.WxYbAppId, "pagepath": wxAppPath}
+		sendMap["miniprogram"] = map[string]interface{}{"appid": ybConf.AppId, "pagepath": wxAppPath}
 	}
 	sendMap["data"] = sendData
 	WxSendTemplateMsg(sendUrl, sendMap, openIdList)
@@ -276,6 +283,13 @@ func SendYbVoiceBroadcastWxMsg(broadcastId int, sectionName, broadcastName strin
 		openIdArr = append(openIdArr, v.OpenId)
 	}
 
+	// 获取研报小程序配置
+	ybConf, err := GetYbAppIdInfo()
+	if err != nil {
+		msg = "获取研报小程序配置失败"
+		return
+	}
+
 	first := "您好,有新的语音播报待查看"
 	keyword1 := fmt.Sprint(sectionName, ":", broadcastName)
 	keyword2 := "待查看"
@@ -287,7 +301,7 @@ func SendYbVoiceBroadcastWxMsg(broadcastId int, sectionName, broadcastName strin
 	sendInfo.Keyword2 = keyword2
 	sendInfo.RedirectUrl = wxAppPath
 	sendInfo.TemplateId = utils.YbCommonTemplateId
-	sendInfo.RedirectTarget = 1
+	sendInfo.RedirectTarget = ybConf.MsgRedirectType
 	sendInfo.Resource = wxAppPath
 	sendInfo.SendType = utils.TEMPLATE_MSG_YB_VOICE_BROADCAST
 	sendInfo.OpenIdArr = openIdArr