|
@@ -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
|
|
|
}
|