瀏覽代碼

fix:增加搜索返回内容

zqbao 9 月之前
父節點
當前提交
e38106b556
共有 5 個文件被更改,包括 30 次插入28 次删除
  1. 7 26
      controllers/wechat.go
  2. 3 0
      models/report.go
  3. 1 1
      models/user_template_record.go
  4. 3 0
      services/report.go
  5. 16 1
      services/template_msg.go

+ 7 - 26
controllers/wechat.go

@@ -9,7 +9,6 @@ import (
 	"fmt"
 	"html"
 	"strconv"
-	"time"
 )
 
 type WeChatController struct {
@@ -147,31 +146,13 @@ func (this *WeChatController) SendTemplateMsg() {
 			})
 		}
 	}
-	sendMap := make(map[string]interface{})
-	sendMap["template_id"] = utils.TEMPLATE_ID_BY_PRODUCT
-	// sendMap["first"] = fmt.Sprintf("Hi,最新一期%s已上线,欢迎查看", report.ClassifyNameFirst)
-	// sendMap["keyword1"] = map[string]interface{}{"value": fmt.Sprintf("弘则%s", report.ClassifyNameSecond), "color": "#173177"}
-	// sendMap["keyword2"] = map[string]interface{}{"value": report.ContentSub, "color": "#173177"}
-	sendMap["first"] = "测试first"
-	sendMap["keyword1"] = "测试k1"
-	sendMap["keyword2"] = "测试k2"
-	sendMap["remark"] = time.Now().Format("2006-01-02")
-	// sendMap["keyword3"] = map[string]interface{}{"value": report.PublishTime, "color": "#173177"}
-	// sendMap["keyword4"] = map[string]interface{}{"value": report.Abstract, "color": "#173177"}
-	var WxAppId = `wxb059c872d79b9967`
-	// var WxAppSecret = `1737c73e9f69a21de1a345b8f0800258`
-	var wxAppPath string
-	if utils.RunMode == "debug" {
-		wxAppPath = fmt.Sprintf("pages-question/answerDetail?id=%d", 3800)
-	} else {
-		wxAppPath = fmt.Sprintf("pages-report/reportDetail/index?id=%d", report.Id)
-	}
-	sendMap["miniprogram"] = map[string]string{
-		"appid":    WxAppId,
-		"pagepath": wxAppPath,
-	}
-	alarm_msg.SendAlarmMsg(fmt.Sprintf("发送模板消息,报告id:%d", report.Id), 1)
-	err = services.SendMultiTemplateMsg(sendMap, openIds, 1)
+	sendData := make(map[string]interface{})
+	sendData["first"] = fmt.Sprintf("Hi,最新一期%s已上线,欢迎查看", report.ClassifyNameFirst)
+	sendData["keyword1"] = map[string]interface{}{"value": fmt.Sprintf("弘则%s", report.ClassifyNameSecond), "color": "#173177"}
+	sendData["keyword2"] = map[string]interface{}{"value": report.ContentSub, "color": "#173177"}
+	sendData["keyword3"] = map[string]interface{}{"value": report.PublishTime, "color": "#173177"}
+	sendData["keyword4"] = map[string]interface{}{"value": report.Abstract, "color": "#173177"}
+	err = services.SendMultiTemplateMsg(sendData, openIds, 1, reportId)
 	if err != nil {
 		br.Msg = "发送失败"
 		br.ErrMsg = "发送失败,Err:" + err.Error()

+ 3 - 0
models/report.go

@@ -146,4 +146,7 @@ type ReportCollectListItem struct {
 	PublishTime         time.Time `description:"发布时间"`
 	Title               string    `description:"标题"`
 	ContentSub          string    `description:"内容前两个章节"`
+	Abstract            string    `description:"摘要"`
+	StageStr            string    `description:"期数"`
+	Author              string    `description:"作者"`
 }

+ 1 - 1
models/user_template_record.go

@@ -3,7 +3,7 @@ package models
 import "github.com/beego/beego/v2/client/orm"
 
 type UserTemplateRecord struct {
-	ID         int    `description:"id"`
+	ID         int    `orm:"pk" description:"id"`
 	UserID     int    `description:"用户id"`
 	OpenID     string `description:"用户openid"`
 	SendData   string `description:"发送内容"`

+ 3 - 0
services/report.go

@@ -84,6 +84,9 @@ func SearchReport(keyWord string, pageIndex, pageSize int) (ret *response.Report
 			temp.Title = reportItem.Title
 			temp.ContentSub = reportItem.BodyContent
 			temp.PublishTime, err = time.ParseInLocation(utils.FormatDateTime, reportItem.PublishTime, time.Local)
+			temp.Abstract = reportItem.Abstract
+			temp.Author = reportItem.Author
+			temp.StageStr = reportItem.StageStr
 
 			if len(v.Highlight["Title"]) > 0 {
 				temp.Title = v.Highlight["Title"][0]

+ 16 - 1
services/template_msg.go

@@ -135,15 +135,30 @@ func AddUserTemplateRecord(userId, sendStatus, sendType int, openid, sendData, r
 }
 
 // SendMultiTemplateMsg 推送模板消息至多个用户
-func SendMultiTemplateMsg(sendMap map[string]interface{}, items []*OpenIdList, sendType int) (err error) {
+func SendMultiTemplateMsg(sendData map[string]interface{}, items []*OpenIdList, sendType, reportId int) (err error) {
 	ws := GetWxChat()
 	accessToken, err := ws.GetAccessToken()
 	if err != nil {
 		alarm_msg.SendAlarmMsg("获取微信token失败, Err:"+err.Error(), 1)
 		return
 	}
+
+	var WxAppId = `wxb059c872d79b9967` // 研报小程序appid
+	var wxAppPath string
+	if utils.RunMode == "debug" {
+		wxAppPath = fmt.Sprintf("pages-question/answerDetail?id=%d", 3800)
+	} else {
+		wxAppPath = fmt.Sprintf("pages-report/reportDetail/index?id=%d", reportId)
+	}
+	sendMap := make(map[string]interface{})
 	for _, item := range items {
+		sendMap["template_id"] = utils.TEMPLATE_ID_BY_PRODUCT
+		sendMap["miniprogram"] = map[string]interface{}{
+			"appid":    WxAppId,
+			"pagepath": wxAppPath,
+		}
 		sendMap["touser"] = item.OpenId
+		sendMap["data"] = sendData
 		data, e := json.Marshal(sendMap)
 		if e != nil {
 			err = e