Browse Source

最新消息rpc修改

unknown 3 years ago
parent
commit
ab0fc3f9ee
1 changed files with 7 additions and 8 deletions
  1. 7 8
      service/messageService.go

+ 7 - 8
service/messageService.go

@@ -62,20 +62,19 @@ func (service *MessageService) CountUnread(userId string, appId string) (int64,
 
 // 获取指定用户指定分类最新一条消息
 func (service *MessageService) LastMessage(userId string, appId string, msgType int64, isRead int64) (*message.Messages, error) {
-	sql := "SELECT * FROM message receive_userid=? and isdel=1 and appid=?  and msg_type=?"
-	valueList := []interface{}{userId, appId, msgType}
-	if isRead != -1 {
-		sql = sql + " and isRead=?"
-		valueList = append(valueList, isRead)
-	}
 	query := map[string]interface{}{
 		"receive_userid": userId,
 		"isdel":          1,
 		"appid":          appId,
 		"msg_type":       msgType,
 	}
+	if isRead != -1 {
+		query["isRead"] = isRead
+	}
+	if msgType != -1 {
+		query["msg_type"] = msgType
+	}
 	lastMsg := entity.Mysql.FindOne("message", query, "", "createtime desc")
-
 	if lastMsg != nil && len(*lastMsg) > 0 {
 		_id := util.Int64All((*lastMsg)["id"])
 		id := strconv.FormatInt(_id, 10)
@@ -93,7 +92,7 @@ func (service *MessageService) LastMessage(userId string, appId string, msgType
 			CiteId:        qutil.Int64All((*lastMsg)["cite_id"]),
 			Content:       qutil.ObjToString((*lastMsg)["content"]),
 			IsRead:        qutil.Int64All((*lastMsg)["isRead"]),
-			MsgLogId: qutil.Int64All((*lastMsg)["msg_log_id"]),
+			MsgLogId:      qutil.Int64All((*lastMsg)["msg_log_id"]),
 		}
 		return &msg, nil
 	} else {