فهرست منبع

Merge branch 'yb/11.2' into debug

hsun 2 سال پیش
والد
کامیت
e53b2a4bb4
2فایلهای تغییر یافته به همراه42 افزوده شده و 17 حذف شده
  1. 26 11
      controllers/message.go
  2. 16 6
      models/tables/company_approval_message/company_approval_message.go

+ 26 - 11
controllers/message.go

@@ -37,6 +37,7 @@ func (c *MessageCommon) SummaryMessageList() {
 	messageMap := make(map[int]message.SummaryMessage)
 	timeList := make([]int, 0)
 	var err error
+	commentTypes := []int{services.CompanyApprovalMessageSourceTypeByQuestionComment, services.CompanyApprovalMessageSourceTypeByVideoComment, services.CompanyApprovalMessageSourceTypeByRoadVideoComment}
 	for _, sourceType := range sourceTypeList {
 		//最近一条消息
 		tmpMessage := ``
@@ -44,7 +45,7 @@ func (c *MessageCommon) SummaryMessageList() {
 		messageInfo := new(company_approval_message.CompanyApprovalMessageList)
 		// 来源类型为6-评论时, 查询6,7,8最近的一条消息
 		if sourceType == 6 {
-			messageInfo, err = company_approval_message.GetLastMessageBySourceTypes(sysUserId, []int{6, 7, 8})
+			messageInfo, err = company_approval_message.GetLastMessageBySourceTypes(sysUserId, commentTypes)
 		} else {
 			messageInfo, err = company_approval_message.GetLastMessage(sysUserId, sourceType)
 		}
@@ -68,7 +69,7 @@ func (c *MessageCommon) SummaryMessageList() {
 
 				}
 				tmpMessage = fmt.Sprint("待分配提问:", content)
-			case 6,7,8:
+			case 6, 7, 8:
 				content := messageInfo.Content
 				var tmpMessageInfo services.MessageInfo
 				if messageInfo.MessageInfo != `` {
@@ -84,14 +85,26 @@ func (c *MessageCommon) SummaryMessageList() {
 			}
 		}
 
-		notReadTotal, err := company_approval_message.GetNotReadMessageTotal(sysUserId, sourceType)
-		if err != nil {
-			c.FailWithMessage("获取失败", "获取未读消息数失败,Err:"+err.Error())
-			return
+		notReadTotal := 0
+		if sourceType == 6 {
+			cnt, e := company_approval_message.GetCommentNotReadMessageTotal(sysUserId, commentTypes)
+			if e != nil {
+				c.FailWithMessage("获取失败", "获取评论未读消息数失败,Err:"+e.Error())
+				return
+			}
+			notReadTotal = int(cnt)
+		} else {
+			nt, e := company_approval_message.GetNotReadMessageTotal(sysUserId, sourceType)
+			if e != nil {
+				c.FailWithMessage("获取失败", "获取未读消息数失败,Err:"+e.Error())
+				return
+			}
+			notReadTotal = int(nt)
 		}
+
 		companyMessage := message.SummaryMessage{
 			Message:    tmpMessage,
-			Total:      int(notReadTotal),
+			Total:      notReadTotal,
 			SourceType: sourceType,
 		}
 
@@ -171,18 +184,20 @@ func (c *MessageCommon) MessageList() {
 		return
 	}
 	// 消息类型为6-评论时, 查询6-问答评论,7-视频评论,8-路演视频
-	sourceTypeStr := strconv.Itoa(sourceType)
+	typeArr := make([]int, 0)
 	if sourceType == services.CompanyApprovalMessageSourceTypeByQuestionComment {
-		sourceTypeStr = fmt.Sprintf("%d,%d,%d", services.CompanyApprovalMessageSourceTypeByQuestionComment, services.CompanyApprovalMessageSourceTypeByVideoComment, services.CompanyApprovalMessageSourceTypeByRoadVideoComment)
+		typeArr = append(typeArr, services.CompanyApprovalMessageSourceTypeByQuestionComment, services.CompanyApprovalMessageSourceTypeByVideoComment, services.CompanyApprovalMessageSourceTypeByRoadVideoComment)
+	} else {
+		typeArr = append(typeArr, sourceType)
 	}
-	list, err := company_approval_message.GetCompanyApprovalMessageList(sysUserId, startSize, pageSize, sourceTypeStr)
+	list, err := company_approval_message.GetCompanyApprovalMessageList(sysUserId, startSize, pageSize, typeArr)
 	if err != nil {
 		c.FailWithMessage("获取失败", "获取消息列表失败,Err:"+err.Error())
 		return
 	}
 
 	//将所有未读消息标记为已读
-	_ = company_approval_message.ModifyAllCompanyApprovalMessageStatus(sysUserId, sourceType)
+	_ = company_approval_message.ModifyAllCompanyApprovalMessageStatus(sysUserId, typeArr)
 
 	switch sourceType {
 	case 5, 6:

+ 16 - 6
models/tables/company_approval_message/company_approval_message.go

@@ -94,17 +94,17 @@ func GetCompanyApprovalMessageCount(sysUserId, sourceType int) (count int, err e
 }
 
 //消息列表页
-func GetCompanyApprovalMessageList(sysUserId, startSize, pageSize int, sourceType string) (items []*CompanyApprovalMessageList, err error) {
+func GetCompanyApprovalMessageList(sysUserId, startSize, pageSize int, sourceTypes []int) (items []*CompanyApprovalMessageList, err error) {
 	sql := `SELECT
 				a.*, b.real_name
 			FROM
 				company_approval_message AS a
 			INNER JOIN admin AS b ON a.create_user_id = b.admin_id
 			WHERE
-				receive_user_id =? AND message_status != 2 AND a.source_type IN (` + sourceType + `)`
+				receive_user_id =? AND message_status != 2 AND a.source_type IN (` + utils.GetOrmInReplace(len(sourceTypes)) + `)`
 	sql += ` ORDER BY create_time DESC LIMIT ?,? `
 	o := orm.NewOrm()
-	_, err = o.Raw(sql, sysUserId, startSize, pageSize).QueryRows(&items)
+	_, err = o.Raw(sql, sysUserId, sourceTypes, startSize, pageSize).QueryRows(&items)
 	return
 }
 
@@ -145,6 +145,16 @@ func GetNotReadMessageTotal(sysUserId, sourceType int) (total int64, err error)
 	return
 }
 
+// 获取评论未读消息数
+func GetCommentNotReadMessageTotal(sysUserId int, types []int) (total int64, err error) {
+	sql := `SELECT count(*) total FROM company_approval_message AS a
+			INNER JOIN admin AS b ON a.create_user_id=b.admin_id
+			WHERE receive_user_id=? AND a.operation_status=1 AND a.message_status =0 AND source_type IN (` + utils.GetOrmInReplace(len(types)) + `)`
+	o := orm.NewOrm()
+	err = o.Raw(sql, sysUserId, types).QueryRow(&total)
+	return
+}
+
 //申请服务更新请求参数
 type CompanyApprovalMessageReadReq struct {
 	Id int `description:"消息id"`
@@ -159,10 +169,10 @@ func ModifyCompanyApprovalMessageStatus(companyApprovalMessageId int) (err error
 }
 
 //变更当前类型下所有未读消息为消息已读状态
-func ModifyAllCompanyApprovalMessageStatus(receiveUserId, sourceType int) (err error) {
+func ModifyAllCompanyApprovalMessageStatus(receiveUserId int, sourceTypes []int) (err error) {
 	o := orm.NewOrm()
-	sql := `UPDATE company_approval_message SET message_status=1,modify_time=NOW() WHERE receive_user_id = ? and source_type=? and message_status=0`
-	_, err = o.Raw(sql, receiveUserId, sourceType).Exec()
+	sql := `UPDATE company_approval_message SET message_status=1,modify_time=NOW() WHERE receive_user_id = ? and source_type IN (` + utils.GetOrmInReplace(len(sourceTypes)) + `) and message_status=0`
+	_, err = o.Raw(sql, receiveUserId, sourceTypes).Exec()
 	return
 }