|
@@ -0,0 +1,506 @@
|
|
|
+package yb_community_question
|
|
|
+
|
|
|
+import (
|
|
|
+ "errors"
|
|
|
+ "fmt"
|
|
|
+ "hongze/hongze_yb/global"
|
|
|
+ "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/wx_user"
|
|
|
+ "hongze/hongze_yb/models/tables/yb_comment_anonymous_user"
|
|
|
+ "hongze/hongze_yb/models/tables/yb_community_question"
|
|
|
+ "hongze/hongze_yb/models/tables/yb_community_question_comment"
|
|
|
+ "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"
|
|
|
+ "hongze/hongze_yb/utils"
|
|
|
+ "strconv"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+
|
|
|
+func Comment(user user.UserInfo, communityQuestionID uint32, content string, sourceAgent, isShowName int8) (ybCommunityQuestionComment *yb_community_question_comment.YbCommunityQuestionComment, err error, errMsg string) {
|
|
|
+ errMsg = "发布留言失败"
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ global.LOG.Critical(fmt.Sprintf("yb_community_question Comment: userId=%d, err:%s, errMsg:%s", user.UserID, err.Error(), errMsg))
|
|
|
+ }
|
|
|
+ }()
|
|
|
+
|
|
|
+ if isShowName != 0 && isShowName != 1 {
|
|
|
+ errMsg = "匿名设置出错"
|
|
|
+ err = errors.New(errMsg)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if content == "" {
|
|
|
+ errMsg = "请输入留言内容"
|
|
|
+ err = errors.New(errMsg)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if sourceAgent == 0 {
|
|
|
+ errMsg = "请输入留言来源"
|
|
|
+ err = errors.New(errMsg)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if communityQuestionID <= 0 {
|
|
|
+ errMsg = "请输入问答ID"
|
|
|
+ err = errors.New(errMsg)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if user.RecordInfo.OpenID != "" && user.RecordInfo.CreatePlatform == 6 {
|
|
|
+ checkResult, tErr := wx_app.MsgSecCheck(user.RecordInfo.OpenID, content)
|
|
|
+
|
|
|
+ errMsg = "敏感词过滤失败" + tErr.Error()
|
|
|
+ err = errors.New("敏感词过滤失败")
|
|
|
+ return
|
|
|
+ }*/
|
|
|
+ if tErr == nil {
|
|
|
+ if checkResult.Result != nil {
|
|
|
+ if checkResult.Result.Suggest != "pass" {
|
|
|
+ errMsg = "含有违禁词,不允许发布:" + checkResult.Result.Suggest + ".命中标签:" + strconv.Itoa(checkResult.Result.Label)
|
|
|
+ err = errors.New("含有违禁词,不允许发布。")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ userName := "匿名用户" + strconv.Itoa(int(3333+user.UserID))
|
|
|
+ if user.RealName != `` {
|
|
|
+ userName = user.RealName
|
|
|
+ }
|
|
|
+
|
|
|
+ now := time.Now()
|
|
|
+ ybCommunityQuestionComment = &yb_community_question_comment.YbCommunityQuestionComment{
|
|
|
+
|
|
|
+ CommunityQuestionID: communityQuestionID,
|
|
|
+ UserID: user.UserID,
|
|
|
+ RealName: userName,
|
|
|
+ Content: content,
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ Type: 1,
|
|
|
+ Enabled: 1,
|
|
|
+ IsShowName: isShowName,
|
|
|
+ SourceAgent: sourceAgent,
|
|
|
+
|
|
|
+
|
|
|
+ ModifyTime: now,
|
|
|
+ CreateTime: now,
|
|
|
+ }
|
|
|
+ err = ybCommunityQuestionComment.Create()
|
|
|
+ if err != nil {
|
|
|
+ errMsg = "新增留言失败"
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ go messageToAdmin(user, ybCommunityQuestionComment)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func Delete(user user.UserInfo, communityQuestionCommentID uint64) (err error, errMsg string) {
|
|
|
+ errMsg = `删除留言失败`
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ global.LOG.Critical(fmt.Sprintf("comment Delete: userId=%d, err:%s, errMsg:%s", user.UserID, err.Error(), errMsg))
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ if communityQuestionCommentID <= 0 {
|
|
|
+ errMsg = `请输入留言ID`
|
|
|
+ err = errors.New(errMsg)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ communityQuestionCommentInfo, err := yb_community_question_comment.GetByCommunityQuestionCommentId(communityQuestionCommentID)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = `查询留言出错`
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if communityQuestionCommentInfo.CommunityQuestionCommentID <= 0 {
|
|
|
+ errMsg = `留言不存在`
|
|
|
+ err = errors.New(errMsg)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if communityQuestionCommentInfo.UserID != user.UserID {
|
|
|
+ errMsg = `不允许删除他人的留言`
|
|
|
+ err = errors.New(errMsg)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if communityQuestionCommentInfo.Type != 1 {
|
|
|
+ errMsg = `不允许删除回复`
|
|
|
+ err = errors.New(errMsg)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if communityQuestionCommentInfo.Enabled == 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ err = yb_community_question_comment.Delete(user.UserID, communityQuestionCommentInfo.CommunityQuestionCommentID)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = `删除留言出错`
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ go afterDelete(communityQuestionCommentInfo)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func MyList(userId uint64, communityQuestionID int, page, pageSize int) (list []*response.RespCommunityQuestionCommentItem, hotTotal, myTotal int64, err error, errMsg string) {
|
|
|
+ list, hotTotal, myTotal, err, errMsg = List(userId, communityQuestionID, false, page, pageSize)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func List(userId uint64, communityQuestionID int, hotFlag bool, page, pageSize int) (list []*response.RespCommunityQuestionCommentItem, hotTotal, myTotal int64, err error, errMsg string) {
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ global.LOG.Critical(fmt.Sprintf("comment List: userId=%d, err:%s, errMsg:%s", userId, err.Error(), errMsg))
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ list = make([]*response.RespCommunityQuestionCommentItem, 0)
|
|
|
+
|
|
|
+ if communityQuestionID <= 0 {
|
|
|
+ err = errors.New("请输入问答ID")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ hotTotal, err = yb_community_question_comment.GetHotListTotalByCommunityQuestionID(communityQuestionID)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = `查询精选留言总数出错`
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ myTotal, err = yb_community_question_comment.GetListTotalByUserIdCommunityQuestionID(userId, communityQuestionID)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = `查询我的留言总数出错`
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ var commentList []*yb_community_question_comment.YbCommunityQuestionComment
|
|
|
+
|
|
|
+ if hotFlag {
|
|
|
+ commentList, err = yb_community_question_comment.GetHotListByCommunityQuestionID(communityQuestionID, (page-1)*pageSize, pageSize)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = `查询精选留言列表出错`
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ commentList, err = yb_community_question_comment.GetListByUserIdCommunityQuestionID(userId, communityQuestionID)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = `查询我的留言列表出错`
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var commentIds []uint64
|
|
|
+ var userIds []uint64
|
|
|
+ for _, v := range commentList {
|
|
|
+ commentIds = append(commentIds, v.CommunityQuestionCommentID)
|
|
|
+ userIds = append(userIds, v.UserID)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var userOthers []*wx_user.WxUser
|
|
|
+ if len(userIds) > 0 {
|
|
|
+ userOthers, err = wx_user.GetByUserIds(userIds)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = err.Error()
|
|
|
+ err = errors.New("查询精选留言用户出错")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ usersMap := make(map[uint64]*wx_user.WxUser)
|
|
|
+ for _, v := range userOthers {
|
|
|
+ usersMap[v.UserID] = v
|
|
|
+ }
|
|
|
+ for _, v := range commentList {
|
|
|
+ tmp := &response.RespCommunityQuestionCommentItem{
|
|
|
+ CommunityQuestionCommentID: v.CommunityQuestionCommentID,
|
|
|
+ UserId: v.UserID,
|
|
|
+ Content: v.Content,
|
|
|
+ IsTop: v.IsTop,
|
|
|
+ IsHot: v.IsHot,
|
|
|
+ HotTopTime: v.HotTopTime,
|
|
|
+ IsShowName: v.IsShowName,
|
|
|
+ UserName: "匿名用户" + strconv.Itoa(int(3333+v.UserID)),
|
|
|
+ UserImgUrl: utils.DEFAULT_HONGZE_USER_LOGO,
|
|
|
+ CreateTime: v.CreateTime,
|
|
|
+ ReplyList: nil,
|
|
|
+ }
|
|
|
+ if info, ok := usersMap[v.UserID]; ok && v.IsShowName == 1 {
|
|
|
+ tmp.UserName = info.NickName
|
|
|
+ tmp.UserImgUrl = info.Headimgurl
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ list = append(list, tmp)
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func GetNeedCommentAnonymousUserTips(userId uint64) (ok bool, err error) {
|
|
|
+ ybCommentAnonymousUser, err := yb_comment_anonymous_user.GetByUserId(userId)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if ybCommentAnonymousUser.UserID > 0 {
|
|
|
+ ok = true
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func SetYbCommentAnonymousUserTips(userId uint64) (err error) {
|
|
|
+ ybCommentAnonymousUser, err := yb_comment_anonymous_user.GetByUserId(userId)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if ybCommentAnonymousUser.UserID <= 0 {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ err = yb_comment_anonymous_user.CreateBySql(userId, time.Now())
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func HandleCommentByCommunityQuestionItemList(userId uint64, questionList []*response.CommunityQuestionItem) (err error) {
|
|
|
+ listLen := len(questionList)
|
|
|
+ if listLen == 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ idArr := make([]uint32, 0)
|
|
|
+ idMap := make(map[uint32]int)
|
|
|
+
|
|
|
+ userIds := []uint64{userId}
|
|
|
+
|
|
|
+ for i := 0; i < listLen; i++ {
|
|
|
+ idArr = append(idArr, uint32(questionList[i].CommunityQuestionID))
|
|
|
+ idMap[uint32(questionList[i].CommunityQuestionID)] = 1
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ ybCommunityQuestionCommentMap := make(map[uint32]*yb_community_question_comment.YbCommunityQuestionComment)
|
|
|
+
|
|
|
+
|
|
|
+ hotList, err := yb_community_question_comment.GetLastHotListByCommunityQuestionIds(idArr)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, v := range hotList {
|
|
|
+ ybCommunityQuestionCommentMap[v.CommunityQuestionID] = v
|
|
|
+ delete(idMap, v.CommunityQuestionID)
|
|
|
+
|
|
|
+
|
|
|
+ userIds = append(userIds, v.UserID)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ myIdArr := make([]uint32, 0)
|
|
|
+ for id := range idMap {
|
|
|
+ myIdArr = append(myIdArr, id)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ myList, err := yb_community_question_comment.GetLastMyListByCommunityQuestionIds(userId, myIdArr)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, v := range myList {
|
|
|
+ ybCommunityQuestionCommentMap[v.CommunityQuestionID] = v
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ numCommentMap := make(map[uint32]int)
|
|
|
+ numCommentList, err := yb_community_question_comment.GetNumCommentByCommunityQuestionIds(idArr, userId)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, v := range numCommentList {
|
|
|
+ numCommentMap[v.CommunityQuestionID] = v.Total
|
|
|
+ }
|
|
|
+
|
|
|
+ var userOthers []*wx_user.WxUser
|
|
|
+ if len(userIds) > 0 {
|
|
|
+ userOthers, err = wx_user.GetByUserIds(userIds)
|
|
|
+ if err != nil {
|
|
|
+ err = errors.New("查询精选留言用户出错")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ usersMap := make(map[uint64]*wx_user.WxUser)
|
|
|
+ for _, v := range userOthers {
|
|
|
+ usersMap[v.UserID] = v
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, v := range questionList {
|
|
|
+
|
|
|
+ if tmpTotal, ok := numCommentMap[uint32(v.CommunityQuestionID)]; ok {
|
|
|
+ v.CommentTotal = tmpTotal
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if ybCommunityQuestionCommentInfo, ok := ybCommunityQuestionCommentMap[uint32(v.CommunityQuestionID)]; ok {
|
|
|
+ v.Comment = ybCommunityQuestionCommentInfo.Content
|
|
|
+ v.CommentUserName = "匿名用户" + strconv.Itoa(int(3333+ybCommunityQuestionCommentInfo.UserID))
|
|
|
+ if info, ok := usersMap[ybCommunityQuestionCommentInfo.UserID]; ok && ybCommunityQuestionCommentInfo.IsShowName == 1 {
|
|
|
+ v.CommentUserName = info.NickName
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func messageToAdmin(wxUser user.UserInfo, communityQuestionComment *yb_community_question_comment.YbCommunityQuestionComment) {
|
|
|
+ var err error
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ go alarm_msg.SendAlarmMsg("新增问答评论信息完成后,发送消息给管理员失败"+time.Now().Format("2006-01-02 15:04:05")+";Err:"+err.Error(), 3)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+
|
|
|
+
|
|
|
+ vWangInfo, err := admin.GetVWangInfo()
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ go systemMessageToAdmin(*vWangInfo, wxUser, communityQuestionComment)
|
|
|
+
|
|
|
+ go wxMessageToAdmin(*vWangInfo, communityQuestionComment)
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func systemMessageToAdmin(adminInfo admin.Admin, wxUser user.UserInfo, communityQuestionComment *yb_community_question_comment.YbCommunityQuestionComment) {
|
|
|
+ var err error
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ go alarm_msg.SendAlarmMsg("新增问答评论信息完成后,站内评论信息发送给管理员失败"+time.Now().Format("2006-01-02 15:04:05")+";Err:"+err.Error(), 3)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+
|
|
|
+ receiveUserId := int(adminInfo.AdminID)
|
|
|
+
|
|
|
+ var msgType, sourceType, approvalStatus int8
|
|
|
+ msgType = company_approval_message.CompanyApprovalMessageMessageTypeByApply
|
|
|
+ sourceType = company_approval_message.CompanyApprovalMessageSourceTypeByQuestionComment
|
|
|
+ approvalStatus = company_approval_message.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 := `您有新的问答评论待查阅`
|
|
|
+ content := `您有新的问答评论待查阅`
|
|
|
+
|
|
|
+
|
|
|
+ communityQuestion, err := yb_community_question.GetItemById(int(communityQuestionComment.CommunityQuestionID))
|
|
|
+ if err != nil {
|
|
|
+ err = errors.New("获取评论对应的问答失败,err:" + err.Error())
|
|
|
+ }
|
|
|
+ messageInfo := company_approval_message.MessageInfo{
|
|
|
+ CompanyName: companyInfo.CompanyName,
|
|
|
+ ProductId: productId,
|
|
|
+ CompanyProductStatus: companyProductInfo.Status,
|
|
|
+ Title: communityQuestionComment.Content,
|
|
|
+ Content: communityQuestion.QuestionContent,
|
|
|
+ UserId: wxUser.UserID,
|
|
|
+ UserName: communityQuestionComment.RealName,
|
|
|
+ CreateTime: communityQuestionComment.CreateTime,
|
|
|
+ }
|
|
|
+
|
|
|
+ err = company_approval_message.AddCompanyApprovalMessage(utils.AdminId, receiveUserId, int(wxUser.CompanyID), int(communityQuestionComment.CommunityQuestionCommentID), msgType, sourceType, approvalStatus, companyName, remark, content, messageInfo)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func wxMessageToAdmin(adminInfo admin.Admin, communityQuestionComment *yb_community_question_comment.YbCommunityQuestionComment) {
|
|
|
+ var err error
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ go alarm_msg.SendAlarmMsg("新增问答评论信息完成后,微信模板消息发送给管理员失败"+time.Now().Format("2006-01-02 15:04:05")+";Err:"+err.Error(), 3)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+
|
|
|
+ if global.CONFIG.Serve.RunMode == "debug" {
|
|
|
+ adminInfo.Mobile = `18221983795`
|
|
|
+ }
|
|
|
+ wxUser, err := wx_user.GetByMobile(adminInfo.Mobile)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ 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() {
|
|
|
+ if err != nil {
|
|
|
+ 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
|
|
|
+}
|