Browse Source

fix:删除评论后,取消站内消息

Roc 2 years ago
parent
commit
171b70bee7

+ 21 - 9
logic/yb_community_question/yb_community_question_comment.go

@@ -11,8 +11,8 @@ import (
 	"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/company_approval_message"
 	"hongze/hongze_yb/services/user"
 	"hongze/hongze_yb/services/wechat"
 	"hongze/hongze_yb/services/wx_app"
@@ -147,6 +147,8 @@ func Delete(user user.UserInfo, communityQuestionCommentID uint64) (err error, e
 		errMsg = `删除留言出错`
 		return
 	}
+
+	go afterDelete(communityQuestionCommentInfo)
 	return
 }
 
@@ -395,7 +397,7 @@ func messageToAdmin(wxUser user.UserInfo, communityQuestionComment *yb_community
 	var err error
 
 	defer func() {
-		go alarm_msg.SendAlarmMsg("问答评论完成后发送消息给管理员失败"+time.Now().Format("2006-01-02 15:04:05")+";Err:"+err.Error(), 3)
+		go alarm_msg.SendAlarmMsg("新增问答评论信息完成后发送消息给管理员失败"+time.Now().Format("2006-01-02 15:04:05")+";Err:"+err.Error(), 3)
 	}()
 
 	//因为产品说只要给沛总发送信息,那么没办法咯,只去获取沛总的信息 2022-07-19 11:29:16
@@ -415,15 +417,15 @@ func messageToAdmin(wxUser user.UserInfo, communityQuestionComment *yb_community
 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)
+		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
+	msgType = company_approval_message.CompanyApprovalMessageMessageTypeByApply
+	sourceType = company_approval_message.CompanyApprovalMessageSourceTypeByQuestionComment
+	approvalStatus = company_approval_message.CompanyApprovalMessageApprovalStatusByPending
 
 	companyInfo, err := company.GetByCompanyId(wxUser.CompanyID)
 	if err != nil {
@@ -440,7 +442,7 @@ func systemMessageToAdmin(adminInfo admin.Admin, wxUser user.UserInfo, community
 	remark := communityQuestionComment.Content
 	content := communityQuestionComment.Content
 
-	messageInfo := services.MessageInfo{
+	messageInfo := company_approval_message.MessageInfo{
 		CompanyName:          companyInfo.CompanyName,
 		ProductId:            productId,
 		CompanyProductStatus: companyProductInfo.Status,
@@ -450,7 +452,7 @@ func systemMessageToAdmin(adminInfo admin.Admin, wxUser user.UserInfo, community
 		UserName:             communityQuestionComment.RealName,
 	}
 	//客户添加消息
-	err = services.AddCompanyApprovalMessage(utils.AdminId, receiveUserId, int(wxUser.CompanyID), int(communityQuestionComment.CommunityQuestionCommentID), msgType, sourceType, approvalStatus, companyName, remark, content, messageInfo)
+	err = company_approval_message.AddCompanyApprovalMessage(utils.AdminId, receiveUserId, int(wxUser.CompanyID), int(communityQuestionComment.CommunityQuestionCommentID), msgType, sourceType, approvalStatus, companyName, remark, content, messageInfo)
 	return
 }
 
@@ -459,7 +461,7 @@ func wxMessageToAdmin(adminInfo admin.Admin, communityQuestionComment *yb_commun
 	var err error
 
 	defer func() {
-		go alarm_msg.SendAlarmMsg("问答评论信息发送微信模板消息给管理员失败"+time.Now().Format("2006-01-02 15:04:05")+";Err:"+err.Error(), 3)
+		go alarm_msg.SendAlarmMsg("新增问答评论信息完成后,微信模板消息发送给管理员失败"+time.Now().Format("2006-01-02 15:04:05")+";Err:"+err.Error(), 3)
 	}()
 
 	wxUser, err := wx_user.GetByMobile(adminInfo.Mobile)
@@ -470,3 +472,13 @@ func wxMessageToAdmin(adminInfo admin.Admin, communityQuestionComment *yb_commun
 	err = wechat.SendQuestionCommentToAdmin(int(communityQuestionComment.CommunityQuestionCommentID), int(wxUser.UserID), communityQuestionComment.Content)
 	return
 }
+
+// 删除评论后的逻辑处理
+func afterDelete(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)
+	}()
+	err = company_approval_message.CancelCompanyApprovalMessage(int(communityQuestionComment.CommunityQuestionCommentID), company_approval_message.CompanyApprovalMessageSourceTypeByQuestionComment)
+	return
+}

+ 5 - 28
models/tables/company_approval_message/update.go

@@ -8,33 +8,10 @@ import "hongze/hongze_yb/global"
 	return
 }*/
 
-// Delete 软删除,隐藏评论
-func Delete(userId uint64, commentId uint64) (err error) {
-	tx := global.DEFAULT_MYSQL.Begin()
-	defer func() {
-		if err != nil {
-			tx.Rollback()
-		} else {
-			tx.Commit()
-		}
-	}()
-	sql1 := ` UPDATE yb_comment
-			SET
-            	enabled = 0,
-				modify_time = NOW(),
-				is_hot = 0,
-				is_top = 0
-			WHERE type = 1 and user_id = ? and comment_id = ?`
-	err = tx.Exec(sql1, userId, commentId).Error
-	if err != nil {
-		return
-	}
-	// 删除相关联的回复
-	sql2 := ` UPDATE yb_comment
-			SET
-            	enabled = 0,
-				modify_time = NOW()
-			WHERE reply_comment_id = ? and type = 2`
-	err = tx.Exec(sql2, commentId).Error
+// Cancel 消息作废
+func Cancel(companyApprovalId int, sourceType int8) (err error) {
+	sql1 := ` UPDATE company_approval_message SET message_status=2,modify_time=NOW() 
+WHERE company_approval_id=? AND source_type=?  AND message_type=1 AND operation_status=1`
+	err = global.DEFAULT_MYSQL.Exec(sql1, companyApprovalId, sourceType).Error
 	return
 }

+ 9 - 9
services/community/question.go

@@ -14,8 +14,8 @@ import (
 	"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/company_approval_message"
 	"hongze/hongze_yb/services/user"
 	"hongze/hongze_yb/services/wechat"
 	"hongze/hongze_yb/utils"
@@ -460,7 +460,7 @@ func messageToAdmin(userId int, ybCommunityQuestion *yb_community_question.YbCom
 	var err error
 
 	defer func() {
-		go alarm_msg.SendAlarmMsg("问答评论完成后发送消息给管理员失败"+time.Now().Format("2006-01-02 15:04:05")+";Err:"+err.Error(), 3)
+		go alarm_msg.SendAlarmMsg("新增社区问答完成后发送消息给管理员失败"+time.Now().Format("2006-01-02 15:04:05")+";Err:"+err.Error(), 3)
 	}()
 
 	//因为产品说只要给沛总发送信息,那么没办法咯,只去获取沛总的信息 2022-07-19 11:29:16
@@ -480,7 +480,7 @@ func messageToAdmin(userId int, ybCommunityQuestion *yb_community_question.YbCom
 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)
+		go alarm_msg.SendAlarmMsg("新增社区问答完成后,站内评论信息发送给管理员失败"+time.Now().Format("2006-01-02 15:04:05")+";Err:"+err.Error(), 3)
 	}()
 	// 接收人的admin_id
 	receiveUserId := int(adminInfo.AdminID)
@@ -491,9 +491,9 @@ func systemMessageToAdmin(adminInfo admin.Admin, userId int, ybCommunityQuestion
 		return
 	}
 	var msgType, sourceType, approvalStatus int8
-	msgType = services.CompanyApprovalMessageMessageTypeByApply
-	sourceType = services.CompanyApprovalMessageSourceTypeByQuestion
-	approvalStatus = services.CompanyApprovalMessageApprovalStatusByPending
+	msgType = company_approval_message.CompanyApprovalMessageMessageTypeByApply
+	sourceType = company_approval_message.CompanyApprovalMessageSourceTypeByQuestion
+	approvalStatus = company_approval_message.CompanyApprovalMessageApprovalStatusByPending
 
 	companyInfo, err := company.GetByCompanyId(wxUser.CompanyID)
 	if err != nil {
@@ -510,7 +510,7 @@ func systemMessageToAdmin(adminInfo admin.Admin, userId int, ybCommunityQuestion
 	remark := ybCommunityQuestion.QuestionContent
 	content := ybCommunityQuestion.QuestionContent
 
-	messageInfo := services.MessageInfo{
+	messageInfo := company_approval_message.MessageInfo{
 		CompanyName:          companyInfo.CompanyName,
 		ProductId:            productId,
 		CompanyProductStatus: companyProductInfo.Status,
@@ -520,7 +520,7 @@ func systemMessageToAdmin(adminInfo admin.Admin, userId int, ybCommunityQuestion
 		UserName:             ybCommunityQuestion.RealName,
 	}
 	//客户添加消息
-	err = services.AddCompanyApprovalMessage(utils.AdminId, receiveUserId, int(wxUser.CompanyID), ybCommunityQuestion.CommunityQuestionID, msgType, sourceType, approvalStatus, companyName, remark, content, messageInfo)
+	err = company_approval_message.AddCompanyApprovalMessage(utils.AdminId, receiveUserId, int(wxUser.CompanyID), ybCommunityQuestion.CommunityQuestionID, msgType, sourceType, approvalStatus, companyName, remark, content, messageInfo)
 	return
 }
 
@@ -529,7 +529,7 @@ func wxMessageToAdmin(adminInfo admin.Admin, ybCommunityQuestion *yb_community_q
 	var err error
 
 	defer func() {
-		go alarm_msg.SendAlarmMsg("问答评论信息发送微信模板消息给管理员失败"+time.Now().Format("2006-01-02 15:04:05")+";Err:"+err.Error(), 3)
+		go alarm_msg.SendAlarmMsg("新增社区问答完成后,微信模板消息发送给管理员失败"+time.Now().Format("2006-01-02 15:04:05")+";Err:"+err.Error(), 3)
 	}()
 
 	wxUser, err := wx_user.GetByMobile(adminInfo.Mobile)

+ 7 - 1
services/company_approval_message/company_approval_message.go

@@ -1,4 +1,4 @@
-package services
+package company_approval_message
 
 import (
 	"encoding/json"
@@ -71,3 +71,9 @@ func AddCompanyApprovalMessage(createUserId, receiveUserId, companyId, companyAp
 	err = msgItem.Create()
 	return
 }
+
+// CancelCompanyApprovalMessage 消息作废
+func CancelCompanyApprovalMessage(companyApprovalId int, sourceType int8) (err error) {
+	err = company_approval_message.Cancel(companyApprovalId, sourceType)
+	return
+}