Bläddra i källkod

完善问答社区接口

hsun 2 år sedan
förälder
incheckning
91a8e99177

+ 1 - 1
controller/community/question.go

@@ -94,7 +94,7 @@ func QuestionAsk(c *gin.Context) {
 		return
 	}
 	userinfo := user.GetInfoByClaims(c)
-	if err := community.CreateQuestion(int(userinfo.UserID), userinfo.Mobile, userinfo.OpenID, userinfo.RealName, req.QuestionContent); err != nil {
+	if err := community.CreateQuestion(int(userinfo.UserID), userinfo.Mobile, userinfo.RealName, req.QuestionContent); err != nil {
 		response.FailMsg("提交失败", "QuestionAsk ErrMsg:"+err.Error(), c)
 		return
 	}

+ 3 - 3
models/tables/yb_community_question_audio/model.go

@@ -9,14 +9,14 @@ func (item *YbCommunityQuestionAudio) Create() (err error) {
 	return
 }
 
-func GetListByQuestrionIds(ids string) (list []*YbCommunityQuestionAudio, err error) {
-	if ids == "" {
+func GetListByQuestrionIds(idArr []int) (list []*YbCommunityQuestionAudio, err error) {
+	if len(idArr) == 0 {
 		return
 	}
 	err = global.DEFAULT_MYSQL.
 		Model(YbCommunityQuestionAudio{}).
 		Select("community_question_id, audio_url, audio_play_seconds, audio_size, sort").
-		Where("community_question_id IN ?", ids).
+		Where("community_question_id IN ?", idArr).
 		Order("community_question_id ASC, sort ASC").
 		Scan(&list).Error
 	return

+ 17 - 9
services/community/question.go

@@ -5,14 +5,13 @@ import (
 	"fmt"
 	"hongze/hongze_yb/models/request"
 	"hongze/hongze_yb/models/response"
+	"hongze/hongze_yb/models/tables/user_record"
 	"hongze/hongze_yb/models/tables/yb_community_question"
 	"hongze/hongze_yb/models/tables/yb_community_question_audio"
 	"hongze/hongze_yb/services/company"
 	"hongze/hongze_yb/services/user"
 	"hongze/hongze_yb/services/wechat"
 	"hongze/hongze_yb/utils"
-	"strconv"
-	"strings"
 	"time"
 )
 
@@ -21,7 +20,7 @@ func GetQuestionList(pageIndex, pageSize, onlyMine, chartPermissionId, replyStat
 	condition := make(map[string]interface{})
 	condition["is_deleted ="] = 0
 	// 用户身份
-	isAdmin, adminInfo, e := user.GetAdminByUserInfo(userInfo)
+	isAdmin, _, e := user.GetAdminByUserInfo(userInfo)
 	if e != nil {
 		err = errors.New("获取用户身份失败 Err:" + e.Error())
 		return
@@ -36,7 +35,7 @@ func GetQuestionList(pageIndex, pageSize, onlyMine, chartPermissionId, replyStat
 		// 问题列表
 		if onlyMine == 1 {
 			if isAdmin {
-				condition["replier_user_id ="] = adminInfo.AdminID
+				condition["replier_user_id ="] = userInfo.UserID
 			} else {
 				condition["user_id ="] = userInfo.UserID
 			}
@@ -54,17 +53,16 @@ func GetQuestionList(pageIndex, pageSize, onlyMine, chartPermissionId, replyStat
 		err = errors.New("获取问题列表失败 Err:" + e.Error())
 		return
 	}
-	idArr := make([]string, 0)
 	listLen := len(questionList)
 	if listLen == 0 {
 		return
 	}
+	idArr := make([]int, 0)
 	for i := 0; i < listLen; i++ {
-		idArr = append(idArr, strconv.Itoa(questionList[i].CommunityQuestionID))
+		idArr = append(idArr, questionList[i].CommunityQuestionID)
 	}
-	idStr := strings.Join(idArr, ",")
 	// 音频列表
-	audioList, e := yb_community_question_audio.GetListByQuestrionIds(idStr)
+	audioList, e := yb_community_question_audio.GetListByQuestrionIds(idArr)
 	if e != nil {
 		err = errors.New("获取音频列表失败 Err:" + e.Error())
 		return
@@ -168,7 +166,17 @@ func GetQuestionDetail(questionId int, userInfo user.UserInfo) (item *response.C
 }
 
 // CreateQuestion 新增问答
-func CreateQuestion(userId int, mobile, openid, realName, content string) (err error) {
+func CreateQuestion(userId int, mobile, realName, content string) (err error) {
+	// 获取用户公众号openid, 获取不到则置空
+	userRecord, e := user_record.GetByUserId(userId, utils.USER_RECORD_PLATFORM_RDDP)
+	if e != nil && e == utils.ErrNoRow {
+		err = errors.New("获取用户公众号openid失败 Err:" + e.Error())
+		return
+	}
+	openid := ""
+	if userRecord != nil {
+		openid = userRecord.OpenID
+	}
 	item := &yb_community_question.YbCommunityQuestion{
 		UserID:          userId,
 		UserOpenid:      openid,

+ 5 - 1
services/wechat/template_msg.go

@@ -175,6 +175,9 @@ func SendMultiTemplateMsg(sendMap map[string]interface{}, items []*OpenIdList, r
 
 // SendQuestionReplyWxMsg 推送研报小程序模板消息-问答社区回复
 func SendQuestionReplyWxMsg(questionId, userId int, openid, questionTitle string) (err error) {
+	if userId == 0 || openid == "" {
+		return
+	}
 	var errMsg string
 	defer func() {
 		if err != nil {
@@ -208,8 +211,9 @@ func SendQuestionReplyWxMsg(questionId, userId int, openid, questionTitle string
 
 	// TODO:小程序pagepath待定
 	wxAppPath := ""
+	//wxAppPath := fmt.Sprintf("pages-report/reportDetail?reportId=%s", "3800")
 	if wxAppPath != "" {
-		sendMap["miniprogram"] = map[string]interface{}{"appid": WxAppId, "pagepath": wxAppPath}
+		sendMap["miniprogram"] = map[string]interface{}{"appid": WxYbAppId, "pagepath": wxAppPath}
 	}
 	err = SendMultiTemplateMsg(sendMap, openIdList, wxAppPath, utils.TEMPLATE_MSG_YB_COMMUNITY_QUESTION)
 	return

+ 2 - 0
services/wechat/wechat.go

@@ -19,9 +19,11 @@ var (
 	WxAppId                         string
 	WxAppSecret                     string
 	TemplateIdWithCommunityQuestion string // 问答社区回复模板消息ID
+	WxYbAppId                       string // 研报小程序AppID
 )
 
 func initConf() {
+	WxYbAppId = "wxb059c872d79b9967"
 	if global.CONFIG.Serve.RunMode == "debug" {
 		WxAppId = "wx9b5d7291e581233a"
 		WxAppSecret = "f4d52e34021eee262dce9682b31f8861"

+ 10 - 0
utils/constants.go

@@ -136,3 +136,13 @@ const (
 	_
 	TEMPLATE_MSG_YB_COMMUNITY_QUESTION // 研报小程序-问答社区通知
 )
+
+// 微信用户user_record注册平台
+const (
+	USER_RECORD_PLATFORM_RDDP      = iota + 1 // 日度点评公众号
+	USER_RECORD_PLATFORM_BACKSTAGE            // 管理后台
+	USER_RECORD_PLATFORM_PC                   // PC端网站
+	USER_RECORD_PLATFORM_CYGX                 // 查研观向小程序
+	_
+	USER_RECORD_PLATFORM_YB // 研报小程序
+)