|
@@ -16,7 +16,7 @@ import (
|
|
|
)
|
|
|
|
|
|
// GetQuestionList 获取问答列表
|
|
|
-func GetQuestionList(pageIndex, pageSize, onlyMine, chartPermissionId, replyStatus, replierUserId int, userInfo user.UserInfo) (resp []*response.CommunityQuestionItem, err error) {
|
|
|
+func GetQuestionList(pageIndex, pageSize, onlyMine, chartPermissionId, replyStatus int, userInfo user.UserInfo) (resp []*response.CommunityQuestionItem, err error) {
|
|
|
condition := make(map[string]interface{})
|
|
|
condition["is_deleted ="] = 0
|
|
|
// 用户身份
|
|
@@ -25,25 +25,16 @@ func GetQuestionList(pageIndex, pageSize, onlyMine, chartPermissionId, replyStat
|
|
|
err = errors.New("获取用户身份失败 Err:" + e.Error())
|
|
|
return
|
|
|
}
|
|
|
- if replierUserId > 0 {
|
|
|
- condition["replier_user_id ="] = replierUserId
|
|
|
- // 回复列表
|
|
|
- if replyStatus > 0 {
|
|
|
- condition["reply_status ="] = replyStatus
|
|
|
- }
|
|
|
- } else {
|
|
|
- // 问题列表
|
|
|
- if onlyMine == 1 {
|
|
|
- if isAdmin {
|
|
|
- condition["replier_user_id ="] = userInfo.UserID
|
|
|
- } else {
|
|
|
- condition["user_id ="] = userInfo.UserID
|
|
|
- }
|
|
|
+ if onlyMine == 1 {
|
|
|
+ if isAdmin {
|
|
|
+ condition["replier_user_id ="] = userInfo.UserID
|
|
|
} else {
|
|
|
- // 默认只展示已回复的
|
|
|
- condition["reply_status ="] = 3
|
|
|
+ condition["user_id ="] = userInfo.UserID
|
|
|
}
|
|
|
}
|
|
|
+ if replyStatus > 0 {
|
|
|
+ condition["reply_status ="] = replyStatus
|
|
|
+ }
|
|
|
if chartPermissionId > 0 {
|
|
|
condition["chart_permission_id ="] = chartPermissionId
|
|
|
}
|
|
@@ -240,19 +231,30 @@ func ReplyUserQuestion(replierId, questionId int, audios []*request.ReplyReqAudi
|
|
|
}
|
|
|
|
|
|
// ReadQuestionReply 回复已读
|
|
|
-func ReadQuestionReply(userId int, questionId int) (err error) {
|
|
|
+func ReadQuestionReply(questionId int, userInfo user.UserInfo) (err error) {
|
|
|
item, e := yb_community_question.GetItemById(questionId)
|
|
|
if e != nil {
|
|
|
err = errors.New("获取提问信息失败 Err:" + e.Error())
|
|
|
return
|
|
|
}
|
|
|
- if item.IsRead == 1 {
|
|
|
+ if item.IsRead == 1 && item.ReplierIsRead == 1 {
|
|
|
return
|
|
|
}
|
|
|
- if item.UserID == userId {
|
|
|
+ if item.UserID == int(userInfo.UserID) {
|
|
|
+ isAdmin, _, e := user.GetAdminByUserInfo(userInfo)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("获取用户身份失败 Err:" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
updateCols := make([]string, 0)
|
|
|
- updateCols = append(updateCols, "is_read", "modify_time")
|
|
|
- item.IsRead = 1
|
|
|
+ updateCols = append(updateCols, "modify_time")
|
|
|
+ if isAdmin {
|
|
|
+ updateCols = append(updateCols, "replier_is_read")
|
|
|
+ item.ReplierIsRead = 1
|
|
|
+ } else {
|
|
|
+ updateCols = append(updateCols, "is_read")
|
|
|
+ item.IsRead = 1
|
|
|
+ }
|
|
|
item.ModifyTime = time.Now().Local()
|
|
|
if e = item.Update(updateCols); e != nil {
|
|
|
err = errors.New("更新问题已读失败 Err:" + e.Error())
|
|
@@ -261,14 +263,26 @@ func ReadQuestionReply(userId int, questionId int) (err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// GetReplyListTotal 获取问答列表数量统计
|
|
|
-func GetReplyListTotal(replierUserId int) (resp *response.CommunityReplyTotal, err error) {
|
|
|
- countList, e := yb_community_question.GetReplierQuestionCount(replierUserId)
|
|
|
+// GetQuestionListTotal 获取问答列表数量统计
|
|
|
+func GetQuestionListTotal(userInfo user.UserInfo) (resp *response.CommunityQuestionListTotal, err error) {
|
|
|
+ isAdmin, _, e := user.GetAdminByUserInfo(userInfo)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("获取用户身份失败 Err:" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ condition := make(map[string]interface{}, 0)
|
|
|
+ condition["is_deleted ="] = 0
|
|
|
+ if isAdmin {
|
|
|
+ condition["replier_user_id ="] = userInfo.UserID
|
|
|
+ } else {
|
|
|
+ condition["user_id ="] = userInfo.UserID
|
|
|
+ }
|
|
|
+ countList, e := yb_community_question.GetQuestionListCount(condition)
|
|
|
if e != nil {
|
|
|
err = errors.New("获取回复人问题统计失败 Err:" + e.Error())
|
|
|
return
|
|
|
}
|
|
|
- resp = new(response.CommunityReplyTotal)
|
|
|
+ resp = new(response.CommunityQuestionListTotal)
|
|
|
for _, v := range countList {
|
|
|
if v.ReplyStatus == 2 {
|
|
|
resp.Wait = v.Total
|
|
@@ -281,3 +295,27 @@ func GetReplyListTotal(replierUserId int) (resp *response.CommunityReplyTotal, e
|
|
|
resp.Total = resp.Wait + resp.Replied
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+// GetMyQuestionUnread 获取我的未读数
|
|
|
+func GetMyQuestionUnread(userInfo user.UserInfo) (total int, err error) {
|
|
|
+ isAdmin, _, e := user.GetAdminByUserInfo(userInfo)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("获取用户身份失败 Err:" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ condition := make(map[string]interface{}, 0)
|
|
|
+ if isAdmin {
|
|
|
+ condition["replier_user_id ="] = userInfo.UserID
|
|
|
+ condition["replier_is_read ="] = 0
|
|
|
+ } else {
|
|
|
+ condition["user_id ="] = userInfo.UserID
|
|
|
+ condition["is_read ="] = 0
|
|
|
+ }
|
|
|
+ num, e := yb_community_question.GetUnreadNum(condition)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("获取我的未读数失败 Err:" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ total = int(num)
|
|
|
+ return
|
|
|
+}
|