Pārlūkot izejas kodu

Merge branch 'dev/v1.2.7_dx' of moapp/MessageCenter into feature/v1.2.7

duxin 2 gadi atpakaļ
vecāks
revīzija
c887386564

+ 35 - 23
rpc/internal/common/sendMsg.go

@@ -152,14 +152,14 @@ func UserMsgList(this *message.UserMsgListReq) *message.UserMsgList {
 
 	//消息栏目下的最新消息
 	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 {
-		var msgTypes []string
 		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)
 		if query != nil && len(*query) > 0 {
 			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.MsgType = common.Int64All(v["msg_type"])
 			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 {
 				//消息未读数
 				msgType := common.InterfaceToStr(v["msg_type"])
@@ -227,13 +213,39 @@ func UserMsgList(this *message.UserMsgListReq) *message.UserMsgList {
 		}
 	}
 	data.Count = count
-	if !this.IsColumn && this.Read == 0 {
-		unread = count
+	if !this.IsColumn {
+		if this.Read == 0 {
+			unread = count
+			if !this.IsMsgList && !this.IsColumnNewMsg {
+				unread += unreadMsg(this) //仅用于移动端获取所有未读数
+			}
+		}
 	}
 	data.Unread = unread
 	return data
 }
 
+func unreadMsg(this *message.UserMsgListReq) int64 {
+	if this.PositionId <= 0 {
+		return 0
+	}
+	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) {
 	var count int64
 	var data []*message.Messages

+ 6 - 4
rpc/internal/common/sendWxTmplMsg.go

@@ -22,10 +22,12 @@ type WxTmplPush struct {
 
 const CacheDb = "msgCount"
 
-func MessageType() func() map[string]string {
-	rData := entity.Mysql.SelectBySql("SELECT name,switch FROM message_column")
+func MessageType() (func() map[string]string, []map[string]interface{}) {
+	var data []map[string]interface{}
+	rData := entity.Mysql.SelectBySql("SELECT * FROM message_column ORDER BY sequence ASC")
 	switchName := map[string]string{}
-	if rData == nil && len(*rData) == 0 {
+	if rData != nil && len(*rData) > 0 {
+		data = *rData
 		for _, mData := range *rData {
 			if settingKey, messageName := util.ObjToString(mData["switch"]), util.ObjToString(mData["name"]); settingKey == "" && messageName == "" {
 				switchName[settingKey] = messageName
@@ -34,7 +36,7 @@ func MessageType() func() map[string]string {
 	}
 	return func() map[string]string {
 		return switchName
-	}
+	}, data
 }
 
 var AllMsgType func() map[string]string

+ 1 - 1
rpc/internal/logic/usermsglistlogic.go

@@ -32,7 +32,7 @@ func (l *UserMsgListLogic) UserMsgList(in *message.UserMsgListReq) (*message.Use
 	data := new(message.UserMsgListRes)
 	res1 := service.UserMsgList(in)    //具体信息
 	res2 := service.MessageGetLast(in) //最新信息
-	if res2 != nil || res1.Data != nil {
+	if res2 != nil || res1 != nil {
 		var finalData []*message.Messages
 		if res1.Data != nil {
 			for _, v := range res1.Data {

+ 1 - 5
rpc/message.go

@@ -57,11 +57,7 @@ func init() {
 		MaxIdleConns: config.ConfigJson.DataSource.MaxIdleConns,
 	}
 	entity.Mysql.Init()
-	data := entity.Mysql.Find("message_column", map[string]interface{}{"equity": "message_center"}, "", "sequence", -1, -1)
-	if data != nil && len(*data) > 0 {
-		entity.MessageColumn = *data
-	}
-	common.AllMsgType = common.MessageType()
+	common.AllMsgType, entity.MessageColumn = common.MessageType()
 	//初始化basemysql
 	entity.BaseMysql = &mysql.Mysql{
 		Address:      config.ConfigJson.BaseSource.Address,