|
@@ -152,14 +152,14 @@ func UserMsgList(this *message.UserMsgListReq) *message.UserMsgList {
|
|
|
|
|
|
//消息栏目下的最新消息
|
|
//消息栏目下的最新消息
|
|
var columnData []*message.AllSortData
|
|
var columnData []*message.AllSortData
|
|
|
|
+ var msgTypes []string
|
|
|
|
+ for _, v := range entity.MessageColumn {
|
|
|
|
+ if common.IntAll(v["msg_type"]) > 0 {
|
|
|
|
+ msgTypes = append(msgTypes, fmt.Sprintf(`"%s"`, common.InterfaceToStr(v["msg_type"])))
|
|
|
|
+ }
|
|
|
|
+ }
|
|
if this.IsColumn {
|
|
if this.IsColumn {
|
|
- var msgTypes []string
|
|
|
|
columnUnread := make(map[string]int64)
|
|
columnUnread := make(map[string]int64)
|
|
- for _, v := range entity.MessageColumn {
|
|
|
|
- if common.IntAll(v["msg_type"]) > 0 {
|
|
|
|
- msgTypes = append(msgTypes, fmt.Sprintf(`"%s"`, common.InterfaceToStr(v["msg_type"])))
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
query := entity.Mysql.SelectBySql(fmt.Sprintf("SELECT msg_type,COUNT(CASE WHEN isRead=0 THEN 1 END) as count FROM message where receive_userid=? and isdel=1 and appid=? GROUP BY msg_type ORDER BY FIELD(`msg_type`,%s)", strings.Join(msgTypes, ",")), this.UserId, this.Appid)
|
|
query := entity.Mysql.SelectBySql(fmt.Sprintf("SELECT msg_type,COUNT(CASE WHEN isRead=0 THEN 1 END) as count FROM message where receive_userid=? and isdel=1 and appid=? GROUP BY msg_type ORDER BY FIELD(`msg_type`,%s)", strings.Join(msgTypes, ",")), this.UserId, this.Appid)
|
|
if query != nil && len(*query) > 0 {
|
|
if query != nil && len(*query) > 0 {
|
|
for _, v := range *query {
|
|
for _, v := range *query {
|
|
@@ -172,21 +172,7 @@ func UserMsgList(this *message.UserMsgListReq) *message.UserMsgList {
|
|
column.Img = fmt.Sprintf("/swordfish/msgCenter/%s.png", common.InterfaceToStr(v["img"]))
|
|
column.Img = fmt.Sprintf("/swordfish/msgCenter/%s.png", common.InterfaceToStr(v["img"]))
|
|
column.MsgType = common.Int64All(v["msg_type"])
|
|
column.MsgType = common.Int64All(v["msg_type"])
|
|
if column.Name == "私信" {
|
|
if column.Name == "私信" {
|
|
- querySql := fmt.Sprintf("SELECT b.*,(SELECT SUM( a.unread) FROM %s a "+
|
|
|
|
- "LEFT JOIN %s b ON a.message_id = b.id "+
|
|
|
|
- "WHERE a.unread > 0 "+
|
|
|
|
- "AND ( a.my_position_id = %d OR a.user_id = %d )) AS unread "+
|
|
|
|
- "FROM %s a "+
|
|
|
|
- "LEFT JOIN %s b ON a.message_id = b.id "+
|
|
|
|
- "WHERE a.unread > 0 "+
|
|
|
|
- "AND ( a.my_position_id = %d OR a.user_id = %d ) "+
|
|
|
|
- "ORDER BY a.TIMESTAMP DESC LIMIT 0,1", "socialize_summary", "socialize_message", this.PositionId, this.NewUserId,
|
|
|
|
- "socialize_summary", "socialize_message", this.PositionId, this.NewUserId)
|
|
|
|
- log.Println("查询sql", querySql)
|
|
|
|
- msgUnread := entity.BaseMysql.SelectBySql(querySql)
|
|
|
|
- if msgUnread != nil && len(*msgUnread) > 0 {
|
|
|
|
- column.UnreadMessages = common.Int64All((*msgUnread)[0]["unread"])
|
|
|
|
- }
|
|
|
|
|
|
+ column.UnreadMessages = unreadMsg(this)
|
|
} else {
|
|
} else {
|
|
//消息未读数
|
|
//消息未读数
|
|
msgType := common.InterfaceToStr(v["msg_type"])
|
|
msgType := common.InterfaceToStr(v["msg_type"])
|
|
@@ -230,6 +216,9 @@ func UserMsgList(this *message.UserMsgListReq) *message.UserMsgList {
|
|
if !this.IsColumn {
|
|
if !this.IsColumn {
|
|
if this.Read == 0 {
|
|
if this.Read == 0 {
|
|
unread = count
|
|
unread = count
|
|
|
|
+ if !this.IsMsgList && !this.IsColumnNewMsg {
|
|
|
|
+ unread += unreadMsg(this) //仅用于移动端获取所有未读数
|
|
|
|
+ }
|
|
} else if this.Read == -1 {
|
|
} else if this.Read == -1 {
|
|
unread = entity.Mysql.Count("message", map[string]interface{}{
|
|
unread = entity.Mysql.Count("message", map[string]interface{}{
|
|
"receive_userid": this.UserId,
|
|
"receive_userid": this.UserId,
|
|
@@ -243,6 +232,24 @@ func UserMsgList(this *message.UserMsgListReq) *message.UserMsgList {
|
|
return data
|
|
return data
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func unreadMsg(this *message.UserMsgListReq) int64 {
|
|
|
|
+ querySql := fmt.Sprintf("SELECT b.*,(SELECT SUM( a.unread) FROM %s a "+
|
|
|
|
+ "LEFT JOIN %s b ON a.message_id = b.id "+
|
|
|
|
+ "WHERE a.unread > 0 "+
|
|
|
|
+ "AND ( a.my_position_id = %d OR a.user_id = %d )) AS unread "+
|
|
|
|
+ "FROM %s a "+
|
|
|
|
+ "LEFT JOIN %s b ON a.message_id = b.id "+
|
|
|
|
+ "WHERE a.unread > 0 "+
|
|
|
|
+ "AND ( a.my_position_id = %d OR a.user_id = %d ) "+
|
|
|
|
+ "ORDER BY a.TIMESTAMP DESC LIMIT 0,1", "socialize_summary", "socialize_message", this.PositionId, this.NewUserId,
|
|
|
|
+ "socialize_summary", "socialize_message", this.PositionId, this.NewUserId)
|
|
|
|
+ log.Println("查询sql", querySql)
|
|
|
|
+ msgUnread := entity.BaseMysql.SelectBySql(querySql)
|
|
|
|
+ if msgUnread != nil && len(*msgUnread) > 0 {
|
|
|
|
+ return common.Int64All((*msgUnread)[0]["unread"])
|
|
|
|
+ }
|
|
|
|
+ return 0
|
|
|
|
+}
|
|
func UserUnreadMsgList(this *message.UserUnreadMsgListReq) (int64, []*message.Messages) {
|
|
func UserUnreadMsgList(this *message.UserUnreadMsgListReq) (int64, []*message.Messages) {
|
|
var count int64
|
|
var count int64
|
|
var data []*message.Messages
|
|
var data []*message.Messages
|