Преглед на файлове

fix:新增问答、新增评论后,发送站内消息以及模板消息

Roc преди 2 години
родител
ревизия
3b6ddc3062

+ 91 - 22
logic/yb_community_question/yb_community_question_comment.go

@@ -5,11 +5,16 @@ import (
 	"fmt"
 	"hongze/hongze_yb/global"
 	"hongze/hongze_yb/models/response"
-	"hongze/hongze_yb/models/tables/company_approval_message"
+	"hongze/hongze_yb/models/tables/admin"
+	"hongze/hongze_yb/models/tables/company"
+	"hongze/hongze_yb/models/tables/company_product"
 	"hongze/hongze_yb/models/tables/wx_user"
 	"hongze/hongze_yb/models/tables/yb_comment_anonymous_user"
 	"hongze/hongze_yb/models/tables/yb_community_question_comment"
+	"hongze/hongze_yb/services"
+	"hongze/hongze_yb/services/alarm_msg"
 	"hongze/hongze_yb/services/user"
+	"hongze/hongze_yb/services/wechat"
 	"hongze/hongze_yb/services/wx_app"
 	"hongze/hongze_yb/utils"
 	"strconv"
@@ -64,12 +69,17 @@ func Comment(user user.UserInfo, communityQuestionID uint32, content string, sou
 		}
 	}
 
+	userName := "匿名用户" + strconv.Itoa(int(3333+user.UserID))
+	if user.RealName != `` {
+		userName = user.RealName
+	}
 	//新增留言
 	now := time.Now()
 	ybCommunityQuestionComment = &yb_community_question_comment.YbCommunityQuestionComment{
 		//CommunityQuestionCommentID: 0,
 		CommunityQuestionID: communityQuestionID,
 		UserID:              user.UserID,
+		RealName:            userName,
 		Content:             content,
 		//ReplyCommentID:             0,
 		//IsTop:                      0,
@@ -90,7 +100,8 @@ func Comment(user user.UserInfo, communityQuestionID uint32, content string, sou
 		return
 	}
 
-	// TODO 给管理员发送模板消息
+	// 用户评论完后发送消息给管理员
+	go messageToAdmin(user, ybCommunityQuestionComment)
 	return
 }
 
@@ -379,25 +390,83 @@ func HandleCommentByCommunityQuestionItemList(userId uint64, questionList []*res
 	return
 }
 
-// AddCompanyApprovalMessage 添加系统消息
-func AddCompanyApprovalMessage(createUserId, receiveUserId, companyId, companyApprovalId int, msgType, sourceType, approvalStatus int8, companyName, remark, content, mobile string) (err error) {
-	msgItem := &company_approval_message.CompanyApprovalMessage{
-		//ID:                0,
-		CreateUserID:      createUserId,
-		ReceiveUserID:     receiveUserId,
-		MessageStatus:     0, //消息状态:0未读,1:已读,2:作废
-		Remark:            remark,
-		Content:           content,
-		CompanyID:         companyId,
-		CompanyName:       companyName,
-		CreateTime:        time.Now(),
-		ModifyTime:        time.Now(),
-		CompanyApprovalID: companyApprovalId,
-		ApprovalStatus:    approvalStatus, //审批状态,1:待审批,2:已审批,3:已驳回
-		OperationStatus:   1,              //消息状态:1:待审批,2:已审批
-		MessageType:       msgType,        //1:申请消息,2:审批结果,3:消息通知
-		SourceType:        sourceType,     //消息来源,1:客户,2:合同,3:用印
-	}
-	err = msgItem.Create()
+// messageToAdmin 添加站内消息
+func messageToAdmin(wxUser user.UserInfo, communityQuestionComment *yb_community_question_comment.YbCommunityQuestionComment) {
+	var err error
+
+	defer func() {
+		go alarm_msg.SendAlarmMsg("问答评论完成后发送消息给管理员失败"+time.Now().Format("2006-01-02 15:04:05")+";Err:"+err.Error(), 3)
+	}()
+
+	//因为产品说只要给沛总发送信息,那么没办法咯,只去获取沛总的信息 2022-07-19 11:29:16
+	vWangInfo, err := admin.GetVWangInfo()
+	if err != nil {
+		return
+	}
+	//站内消息
+	go systemMessageToAdmin(*vWangInfo, wxUser, communityQuestionComment)
+	//微信模板消息
+	go wxMessageToAdmin(*vWangInfo, communityQuestionComment)
+
+	return
+}
+
+// systemMessageToAdmin 系统消息消息通知管理员
+func systemMessageToAdmin(adminInfo admin.Admin, wxUser user.UserInfo, communityQuestionComment *yb_community_question_comment.YbCommunityQuestionComment) {
+	var err error
+	defer func() {
+		go alarm_msg.SendAlarmMsg("站内评论信息发送给管理员失败"+time.Now().Format("2006-01-02 15:04:05")+";Err:"+err.Error(), 3)
+	}()
+	// 接收人的admin_id
+	receiveUserId := int(adminInfo.AdminID)
+
+	var msgType, sourceType, approvalStatus int8
+	msgType = services.CompanyApprovalMessageMessageTypeByApply
+	sourceType = services.CompanyApprovalMessageSourceTypeByQuestionComment
+	approvalStatus = services.CompanyApprovalMessageApprovalStatusByPending
+
+	companyInfo, err := company.GetByCompanyId(wxUser.CompanyID)
+	if err != nil {
+		return
+	}
+
+	productId := 1
+	companyProductInfo, err := company_product.GetByCompany2ProductId(wxUser.CompanyID, int64(productId))
+	if err != nil {
+		return
+	}
+
+	companyName := companyInfo.CompanyName
+	remark := communityQuestionComment.Content
+	content := communityQuestionComment.Content
+
+	messageInfo := services.MessageInfo{
+		CompanyName:          companyInfo.CompanyName,
+		ProductId:            productId,
+		CompanyProductStatus: companyProductInfo.Status,
+		Title:                communityQuestionComment.Content,
+		Content:              communityQuestionComment.Content,
+		UserId:               wxUser.UserID,
+		UserName:             communityQuestionComment.RealName,
+	}
+	//客户添加消息
+	err = services.AddCompanyApprovalMessage(utils.AdminId, receiveUserId, int(wxUser.CompanyID), int(communityQuestionComment.CommunityQuestionCommentID), msgType, sourceType, approvalStatus, companyName, remark, content, messageInfo)
+	return
+}
+
+// wxMessageToAdmin 微信模板消息通知管理员
+func wxMessageToAdmin(adminInfo admin.Admin, communityQuestionComment *yb_community_question_comment.YbCommunityQuestionComment) {
+	var err error
+
+	defer func() {
+		go alarm_msg.SendAlarmMsg("问答评论信息发送微信模板消息给管理员失败"+time.Now().Format("2006-01-02 15:04:05")+";Err:"+err.Error(), 3)
+	}()
+
+	wxUser, err := wx_user.GetByMobile(adminInfo.Mobile)
+	if err != nil {
+		return
+	}
+
+	err = wechat.SendQuestionCommentToAdmin(int(communityQuestionComment.CommunityQuestionCommentID), int(wxUser.UserID), communityQuestionComment.Content)
 	return
 }

+ 6 - 1
models/tables/admin/query.go

@@ -14,4 +14,9 @@ func GetByAdminId(adminId int) (item *Admin, err error) {
 func GetAdminByMobile(mobile string) (item *Admin, err error) {
 	err = global.DEFAULT_MYSQL.Model(Admin{}).Where("mobile = ? AND enabled = 1", mobile).First(&item).Error
 	return
-}
+}
+
+// GetVWangInfo 获取沛总的账户信息
+func GetVWangInfo() (item *Admin, err error) {
+	return GetByAdminId(66)
+}

+ 4 - 1
models/tables/company_approval_message/company_approval_message.go

@@ -20,7 +20,8 @@ type CompanyApprovalMessage struct {
 	ApprovalStatus    int8      `gorm:"column:approval_status;type:tinyint(4);default:0" json:"approvalStatus"`                       // 审批状态:1:待审批,2:已审批,3:已驳回
 	OperationStatus   int8      `gorm:"column:operation_status;type:tinyint(4);default:0" json:"operationStatus"`                     // 1:待审批,2:已审批
 	MessageType       int8      `gorm:"column:message_type;type:tinyint(4);default:0" json:"messageType"`                             // 1:申请消息,2:审批结果,3:文字消息
-	SourceType        int8      `gorm:"index:idx_source_typ;column:source_type;type:tinyint(4);default:1" json:"sourceType"`          // 消息来源类型,1:客户,2:合同,3:用印,4:指标替换
+	SourceType        int8      `gorm:"index:idx_source_typ;column:source_type;type:tinyint(4);default:1" json:"sourceType"`          // 消息来源类型,1:客户,2:合同,3:用印,4:指标替换,5:问答社区,6:问答评论
+	MessageInfo       string    `gorm:"column:message_info;type:text" json:"messageInfo"`                                             // 消息主要内容,json数据
 }
 
 // TableName get sql table name.获取数据库表名
@@ -45,6 +46,7 @@ var CompanyApprovalMessageColumns = struct {
 	OperationStatus   string
 	MessageType       string
 	SourceType        string
+	MessageInfo       string
 }{
 	ID:                "id",
 	CreateUserID:      "create_user_id",
@@ -61,4 +63,5 @@ var CompanyApprovalMessageColumns = struct {
 	OperationStatus:   "operation_status",
 	MessageType:       "message_type",
 	SourceType:        "source_type",
+	MessageInfo:       "message_info",
 }

+ 5 - 2
models/tables/yb_community_question_comment/yb_community_question_comment.go

@@ -9,6 +9,7 @@ type YbCommunityQuestionComment struct {
 	CommunityQuestionCommentID uint64    `gorm:"primaryKey;column:community_question_comment_id;type:bigint(20) unsigned;not null" json:"-"`
 	CommunityQuestionID        uint32    `gorm:"column:community_question_id;type:int(10) unsigned;not null;default:0" json:"communityQuestionId"` // 问答ID
 	UserID                     uint64    `gorm:"column:user_id;type:bigint(20) unsigned;not null;default:0" json:"userId"`                         // 用户id
+	RealName                   string    `gorm:"column:real_name;type:varchar(255);not null;default:''" json:"realName"`                           // 用户当时昵称
 	Content                    string    `gorm:"column:content;type:text" json:"content"`                                                          // 留言内容
 	ReplyCommentID             uint64    `gorm:"column:reply_comment_id;type:bigint(20) unsigned;not null;default:0" json:"replyCommentId"`        // 回复的留言ID
 	IsTop                      int8      `gorm:"column:is_top;type:tinyint(2);not null;default:0" json:"isTop"`                                    // 是否置顶(0-未置顶,1-置顶)
@@ -18,8 +19,8 @@ type YbCommunityQuestionComment struct {
 	Enabled                    int8      `gorm:"column:enabled;type:tinyint(1);not null;default:1" json:"enabled"`                                 // 是否有效, 0-无效留言 1-有效留言
 	IsShowName                 int8      `gorm:"column:is_show_name;type:tinyint(1);not null;default:0" json:"isShowName"`                         // 是否匿名 0-匿名,1-不匿名
 	SourceAgent                int8      `gorm:"column:source_agent;type:tinyint(1);not null;default:1" json:"sourceAgent"`                        // 留言入口来源,1:小程序,2:小程序pc, 4:web pc
-	TopTime                    time.Time `gorm:"column:top_time;type:datetime" json:"topTime"`                                                     // 设置精选的时间
-	HotTime                    time.Time `gorm:"column:hot_time;type:datetime" json:"hotTime"`                                                     // 设置置顶的时间
+	TopTime                    time.Time `gorm:"column:top_time;type:datetime" json:"topTime"`                                                     // 设置置顶的时间
+	HotTime                    time.Time `gorm:"column:hot_time;type:datetime" json:"hotTime"`                                                     // 设置精选的时间
 	ModifyTime                 time.Time `gorm:"column:modify_time;type:datetime;not null;default:CURRENT_TIMESTAMP" json:"modifyTime"`            // 修改时间
 	CreateTime                 time.Time `gorm:"column:create_time;type:datetime;not null;default:CURRENT_TIMESTAMP" json:"createTime"`            // 创建时间
 }
@@ -34,6 +35,7 @@ var YbCommunityQuestionCommentColumns = struct {
 	CommunityQuestionCommentID string
 	CommunityQuestionID        string
 	UserID                     string
+	RealName                   string
 	Content                    string
 	ReplyCommentID             string
 	IsTop                      string
@@ -51,6 +53,7 @@ var YbCommunityQuestionCommentColumns = struct {
 	CommunityQuestionCommentID: "community_question_comment_id",
 	CommunityQuestionID:        "community_question_id",
 	UserID:                     "user_id",
+	RealName:                   "real_name",
 	Content:                    "content",
 	ReplyCommentID:             "reply_comment_id",
 	IsTop:                      "is_top",

+ 98 - 3
services/community/question.go

@@ -5,11 +5,17 @@ import (
 	"fmt"
 	"hongze/hongze_yb/models/request"
 	"hongze/hongze_yb/models/response"
+	"hongze/hongze_yb/models/tables/admin"
+	"hongze/hongze_yb/models/tables/company"
+	"hongze/hongze_yb/models/tables/company_product"
 	"hongze/hongze_yb/models/tables/research_group"
 	"hongze/hongze_yb/models/tables/user_record"
+	"hongze/hongze_yb/models/tables/wx_user"
 	"hongze/hongze_yb/models/tables/yb_community_audio_listen_log"
 	"hongze/hongze_yb/models/tables/yb_community_question"
 	"hongze/hongze_yb/models/tables/yb_community_question_audio"
+	"hongze/hongze_yb/services"
+	"hongze/hongze_yb/services/alarm_msg"
 	"hongze/hongze_yb/services/user"
 	"hongze/hongze_yb/services/wechat"
 	"hongze/hongze_yb/utils"
@@ -121,7 +127,7 @@ func GetQuestionList(pageIndex, pageSize, onlyMine, chartPermissionId, replyStat
 			ReplyTime:               v.ReplyTime.Format(utils.FormatDateTime),
 			//AuthOk:                  authOk,
 			//PermissionInfo:          permissionInfo,
-			AudioList:               audios,
+			AudioList: audios,
 		}
 		if !isResearcher && item.IsRead == 0 && item.UserId == userId {
 			item.IsTop = 1
@@ -187,7 +193,7 @@ func GetQuestionDetail(questionId int, userInfo user.UserInfo) (item *response.C
 		ReplyTime:               detail.ReplyTime.Format(utils.FormatDateTime),
 		//AuthOk:                  authOk,
 		//PermissionInfo:          permissionInfo,
-		AudioList:               audios,
+		AudioList: audios,
 	}
 	errMsg = "获取成功"
 	return
@@ -218,6 +224,9 @@ func CreateQuestion(userId int, mobile, realName, content string) (err error) {
 	if e := item.Create(); e != nil {
 		err = errors.New("新增问题失败 Err:" + e.Error())
 	}
+
+	// 新增问答后,消息通知管理员
+	go messageToAdmin(userId, item)
 	return
 }
 
@@ -417,7 +426,7 @@ func GetResearchGroupTree() (respList []*response.ResearchGroupItem, err error)
 }
 
 // AddAudioListenLog 添加用户点击音频日志
-func AddAudioListenLog(userInfo user.UserInfo, audioId int, sourceAgent int) (err error)  {
+func AddAudioListenLog(userInfo user.UserInfo, audioId int, sourceAgent int) (err error) {
 	//1. 查询音频是否存在
 	audio, err := yb_community_question_audio.GetByAudioId(audioId)
 	if err != nil && err != utils.ErrNoRow {
@@ -445,3 +454,89 @@ func AddAudioListenLog(userInfo user.UserInfo, audioId int, sourceAgent int) (er
 	}
 	return
 }
+
+// messageToAdmin 添加站内消息
+func messageToAdmin(userId int, ybCommunityQuestion *yb_community_question.YbCommunityQuestion) {
+	var err error
+
+	defer func() {
+		go alarm_msg.SendAlarmMsg("问答评论完成后发送消息给管理员失败"+time.Now().Format("2006-01-02 15:04:05")+";Err:"+err.Error(), 3)
+	}()
+
+	//因为产品说只要给沛总发送信息,那么没办法咯,只去获取沛总的信息 2022-07-19 11:29:16
+	vWangInfo, err := admin.GetVWangInfo()
+	if err != nil {
+		return
+	}
+	//站内消息
+	go systemMessageToAdmin(*vWangInfo, userId, ybCommunityQuestion)
+	//微信模板消息
+	go wxMessageToAdmin(*vWangInfo, ybCommunityQuestion)
+
+	return
+}
+
+// systemMessageToAdmin 系统消息消息通知管理员
+func systemMessageToAdmin(adminInfo admin.Admin, userId int, ybCommunityQuestion *yb_community_question.YbCommunityQuestion) {
+	var err error
+	defer func() {
+		go alarm_msg.SendAlarmMsg("站内评论信息发送给管理员失败"+time.Now().Format("2006-01-02 15:04:05")+";Err:"+err.Error(), 3)
+	}()
+	// 接收人的admin_id
+	receiveUserId := int(adminInfo.AdminID)
+
+	//获取评论人信息
+	wxUser, err := wx_user.GetByUserId(userId)
+	if err != nil {
+		return
+	}
+	var msgType, sourceType, approvalStatus int8
+	msgType = services.CompanyApprovalMessageMessageTypeByApply
+	sourceType = services.CompanyApprovalMessageSourceTypeByQuestion
+	approvalStatus = services.CompanyApprovalMessageApprovalStatusByPending
+
+	companyInfo, err := company.GetByCompanyId(wxUser.CompanyID)
+	if err != nil {
+		return
+	}
+
+	productId := 1
+	companyProductInfo, err := company_product.GetByCompany2ProductId(wxUser.CompanyID, int64(productId))
+	if err != nil {
+		return
+	}
+
+	companyName := companyInfo.CompanyName
+	remark := ybCommunityQuestion.QuestionContent
+	content := ybCommunityQuestion.QuestionContent
+
+	messageInfo := services.MessageInfo{
+		CompanyName:          companyInfo.CompanyName,
+		ProductId:            productId,
+		CompanyProductStatus: companyProductInfo.Status,
+		Title:                ybCommunityQuestion.QuestionContent,
+		Content:              ybCommunityQuestion.QuestionContent,
+		UserId:               wxUser.UserID,
+		UserName:             ybCommunityQuestion.RealName,
+	}
+	//客户添加消息
+	err = services.AddCompanyApprovalMessage(utils.AdminId, receiveUserId, int(wxUser.CompanyID), ybCommunityQuestion.CommunityQuestionID, msgType, sourceType, approvalStatus, companyName, remark, content, messageInfo)
+	return
+}
+
+// wxMessageToAdmin 微信模板消息通知管理员
+func wxMessageToAdmin(adminInfo admin.Admin, ybCommunityQuestion *yb_community_question.YbCommunityQuestion) {
+	var err error
+
+	defer func() {
+		go alarm_msg.SendAlarmMsg("问答评论信息发送微信模板消息给管理员失败"+time.Now().Format("2006-01-02 15:04:05")+";Err:"+err.Error(), 3)
+	}()
+
+	wxUser, err := wx_user.GetByMobile(adminInfo.Mobile)
+	if err != nil {
+		return
+	}
+
+	err = wechat.SendQuestionToAdmin(ybCommunityQuestion.CommunityQuestionID, int(wxUser.UserID), ybCommunityQuestion.QuestionContent)
+	return
+}

+ 73 - 0
services/company_approval_message.go

@@ -0,0 +1,73 @@
+package services
+
+import (
+	"encoding/json"
+	"hongze/hongze_yb/models/tables/company_approval_message"
+	"time"
+)
+
+//消息来源类型,1:客户,2:合同,3:用印,4:指标替换,5:问答社区,6:问答评论
+const (
+	CompanyApprovalMessageSourceTypeByCompany         = 1
+	CompanyApprovalMessageSourceTypeByContract        = 2
+	CompanyApprovalMessageSourceTypeBySeal            = 3
+	CompanyApprovalMessageSourceTypeByEdbInfo         = 4
+	CompanyApprovalMessageSourceTypeByQuestion        = 5
+	CompanyApprovalMessageSourceTypeByQuestionComment = 6
+)
+
+// 1:申请消息,2:审批结果,3:消息通知
+const (
+	CompanyApprovalMessageMessageTypeByApply          = 1
+	CompanyApprovalMessageMessageTypeByApprovalResult = 2
+	CompanyApprovalMessageMessageTypeByMessage        = 3
+)
+
+//审批状态,1:待审批,2:已审批,3:已驳回
+const (
+	CompanyApprovalMessageApprovalStatusByPending  = 1
+	CompanyApprovalMessageApprovalStatusByApproved = 2
+	CompanyApprovalMessageApprovalStatusByRejected = 3
+)
+
+// MessageInfo 消息主要内容
+type MessageInfo struct {
+	CompanyName          string `json:"company_name"`
+	ProductId            int    `json:"product_id"`
+	CompanyProductStatus string `json:"company_product_status"`
+	Title                string `json:"title"`
+	Content              string `json:"content"`
+	UserId               uint64 `json:"user_id"`
+	UserName             string `json:"user_name"`
+}
+
+// AddCompanyApprovalMessage 添加系统消息
+// @params createUserId int "消息创建人id"
+// @params receiveUserId int "消息接收人id"
+// @params companyApprovalId int "消息对应的id"
+func AddCompanyApprovalMessage(createUserId, receiveUserId, companyId, companyApprovalId int, msgType, sourceType, approvalStatus int8, companyName, remark, content string, messageInfo MessageInfo) (err error) {
+	messageInfoStr, err := json.Marshal(messageInfo)
+	if err != nil {
+		return
+	}
+	msgItem := &company_approval_message.CompanyApprovalMessage{
+		//ID:                0,
+		CreateUserID:      createUserId,
+		ReceiveUserID:     receiveUserId,
+		MessageStatus:     0, //消息状态:0未读,1:已读,2:作废
+		Remark:            remark,
+		Content:           content,
+		CompanyID:         companyId,
+		CompanyName:       companyName,
+		CreateTime:        time.Now(),
+		ModifyTime:        time.Now(),
+		CompanyApprovalID: companyApprovalId,
+		ApprovalStatus:    approvalStatus,         //审批状态,1:待审批,2:已审批,3:已驳回
+		OperationStatus:   1,                      //消息状态:1:待审批,2:已审批
+		MessageType:       msgType,                //1:申请消息,2:审批结果,3:消息通知
+		SourceType:        sourceType,             //消息来源,1:客户,2:合同,3:用印
+		MessageInfo:       string(messageInfoStr), //消息主要内容,json数据
+	}
+	err = msgItem.Create()
+	return
+}

+ 123 - 1
services/wechat/template_msg.go

@@ -233,4 +233,126 @@ func SendQuestionReplyWxMsg(questionId, userId int, questionTitle string) (err e
 	}
 	err = SendMultiTemplateMsg(sendMap, openIdList, wxAppPath, utils.TEMPLATE_MSG_YB_COMMUNITY_QUESTION)
 	return
-}
+}
+
+// SendQuestionToAdmin 推送研报小程序模板消息-用户提问时,通知到管理员
+func SendQuestionToAdmin(questionId, userId int, questionTitle string) (err error) {
+	if userId == 0 {
+		return
+	}
+	var errMsg string
+	defer func() {
+		if err != nil {
+			alarmMsg := fmt.Sprintf("SendQuestionToAdmin-推送研报小程序模板消息-用户提问时,通知到管理员; QuestionId: %d; Err: %s; Msg: %s", questionId, err.Error(), errMsg)
+			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: userRecord.OpenID,
+		UserId: userId,
+	})
+
+	sendMap := make(map[string]interface{})
+	sendData := make(map[string]interface{})
+
+	first := "您好,有新的提问待分配"
+	keyword1 := questionTitle
+	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-question/detail/index?type=question&id=%d", questionId)
+	if global.CONFIG.Serve.RunMode == "debug" {
+		// 仅测试环境测试用
+		wxAppPath = "pages-approve/seal/list"
+	}
+	if wxAppPath != "" {
+		sendMap["miniprogram"] = map[string]interface{}{"appid": WxMobileCrmAppId, "pagepath": wxAppPath}
+	}
+	err = SendMultiTemplateMsg(sendMap, openIdList, wxAppPath, utils.TEMPLATE_MSG_YB_COMMUNITY_QUESTION)
+	return
+}
+
+// SendQuestionCommentToAdmin 推送研报小程序模板消息-用户评论问答时,通知到管理员
+func SendQuestionCommentToAdmin(commentId, userId int, commentContent string) (err error) {
+	if userId == 0 {
+		return
+	}
+	var errMsg string
+	defer func() {
+		if err != nil {
+			alarmMsg := fmt.Sprintf("SendQuestionCommentToAdmin-推送研报小程序模板消息-用户评论问答时,通知到管理员; CommentId: %d; Err: %s; Msg: %s", commentId, err.Error(), errMsg)
+			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: userRecord.OpenID,
+		UserId: userId,
+	})
+
+	sendMap := make(map[string]interface{})
+	sendData := make(map[string]interface{})
+
+	first := "您好,有新的评论待查看"
+	keyword1 := commentContent
+	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-question/detail/index?type=comment&id=%d", commentId)
+	if global.CONFIG.Serve.RunMode == "debug" {
+		// 仅测试环境测试用
+		wxAppPath = "pages-approve/seal/list"
+	}
+	if wxAppPath != "" {
+		sendMap["miniprogram"] = map[string]interface{}{"appid": WxMobileCrmAppId, "pagepath": wxAppPath}
+	}
+	err = SendMultiTemplateMsg(sendMap, openIdList, wxAppPath, utils.TEMPLATE_MSG_YB_COMMUNITY_QUESTION)
+	return
+}

+ 9 - 0
services/wechat/wechat.go

@@ -26,10 +26,19 @@ var (
 	WxYbAppId                       string // 研报小程序AppID
 	PcWxAppId                       string //pc版AppId
 	PcWxAppSecret                   string //pc版AppSecret
+
+	WxMobileCrmAppId     string //随手办公小程序appid
+	WxMobileCrmId        string //随手办公小程序id
+	WxAppMobileCrmSecret string //随手办公小程序秘钥
 )
 
 func init() {
 	WxYbAppId = "wxb059c872d79b9967"
+
+	WxMobileCrmAppId = `wx67b68e39913e511e`
+	WxMobileCrmId = `wx67b68e39913e511e`
+	WxAppMobileCrmSecret = `660b0375f701a19220bb8a662b41c77c`
+
 	if global.CONFIG.Serve.RunMode == "debug" {
 		WxAppId = "wx9b5d7291e581233a"
 		WxAppSecret = "f4d52e34021eee262dce9682b31f8861"

+ 5 - 0
utils/constants.go

@@ -152,3 +152,8 @@ const (
 	DEFAULT_HONGZE_USER_LOGO = "https://hzstatic.hzinsights.com/static/icon/hzyb/default_avatar.png"      //个人中心默认头像、匿名用户留言默认头像
 	DEFAULT_HONGZE_SYS_LOGO  = "https://hzstatic.hzinsights.com/static/yb_wx/hongze_sys_default_head.png" //弘则官方默认头像
 )
+
+const (
+	AdminId  = 11      //系统操作的用户id
+	RealName = "超级管理员" //系统操作的用户名称
+)