Преглед на файлове

fix:已读未读更新逻辑修改

duxin преди 2 години
родител
ревизия
adc7fa5b44
променени са 2 файла, в които са добавени 54 реда и са изтрити 48 реда
  1. 16 14
      rpc/messagecenter/internal/logic/userlistlogic.go
  2. 38 34
      service/message_mail_box.go

+ 16 - 14
rpc/messagecenter/internal/logic/userlistlogic.go

@@ -37,21 +37,23 @@ func (l *UserListLogic) UserList(in *messagecenter.UserReq) (*messagecenter.User
 		return nil, err
 	}
 	var result = []*messagecenter.UserEntity{}
-	for _, v := range *data {
-		tim, _ := time.ParseInLocation(util.Date_Full_Layout, quitl.InterfaceToStr(v["create_time"]), time.Local)
-		userResp := messagecenter.UserEntity{
-			Name:       quitl.ObjToString(v["name"]),
-			Title:      quitl.ObjToString(v["title"]),
-			Type:       quitl.Int64All(v["type"]),
-			Link:       quitl.ObjToString(v["link"]),
-			Content:    quitl.ObjToString(v["content"]),
-			CreateTime: tim.Unix(),
-			UserType:   quitl.Int64All(v["userType"]),
-			Number:     quitl.Int64All(v["number"]),
-			UserId:     encrypt.SE.Encode2Hex(quitl.InterfaceToStr(v["id"])),
-			Headimg:    quitl.ObjToString(v["headimg"]),
+	if data != nil && len(*data) > 0 {
+		for _, v := range *data {
+			tim, _ := time.ParseInLocation(util.Date_Full_Layout, quitl.InterfaceToStr(v["create_time"]), time.Local)
+			userResp := messagecenter.UserEntity{
+				Name:       quitl.ObjToString(v["name"]),
+				Title:      quitl.ObjToString(v["title"]),
+				Type:       quitl.Int64All(v["type"]),
+				Link:       quitl.ObjToString(v["link"]),
+				Content:    quitl.ObjToString(v["content"]),
+				CreateTime: tim.Unix(),
+				UserType:   quitl.Int64All(v["userType"]),
+				Number:     quitl.Int64All(v["number"]),
+				UserId:     encrypt.SE.Encode2Hex(quitl.InterfaceToStr(v["id"])),
+				Headimg:    quitl.ObjToString(v["headimg"]),
+			}
+			result = append(result, &userResp)
 		}
-		result = append(result, &userResp)
 	}
 	return &messagecenter.UserResp{Data: result, Count: count}, nil
 }

+ 38 - 34
service/message_mail_box.go

@@ -527,8 +527,8 @@ func (b MessaggeService) FindMessage(in *messagecenter.MessageReq) *[]map[string
 	}
 	go func() {
 		updateMap := map[string]interface{}{}
-		//if len(*data) > 0 && data != nil {
-		if true {
+		if len(*data) > 0 && data != nil {
+			//if true {
 			//未读信息修改
 			switch in.MsgType {
 			case 2: //点对点聊天
@@ -643,44 +643,48 @@ func (b *MessaggeService) SaveAutoReplyMsg(userType, entId, entUserId, userId in
 
 // 修改未读状态
 func (b MessaggeService) UpdateReadById(in *messagecenter.ReadStateReq) bool {
-	fool := util.Mysql.ExecTx("已读状态修改", func(tx *sql.Tx) bool {
-		updateMap := map[string]interface{}{
-			"messag_id": in.MessageId,
-			"isread":    0,
-		}
-		fool := util.Mysql.Update(util.SOCIALIZE_MESSAGE_MAILBOX, updateMap, map[string]interface{}{"read_time": time.Now().Local().Format(util.Date_Full_Layout), "isread": 1})
-		if fool {
-			//查询此条信息拥有者
-			data := util.Mysql.FindOne(util.SOCIALIZE_MESSAGE_MAILBOX, updateMap, "receive_user_type", "")
-			if data != nil {
-				userType := int64(1)
-				userId := int64(0)
-				if (*data)["receive_user_type"] == 2 {
-					userType = 2
-					userId = in.EntUserId
-				} else {
-					userType = 1
-					userId = in.NewUserId
-				}
-				pc_a, err := util.GetData(userType, userId)
-				if fool {
-					if err == nil && pc_a != nil {
-						if pc_a.Count >= 1 {
-							//id一致
-							if in.MessageId == pc_a.Data["id"] {
-								util.SetData(userType, userId, map[string]interface{}{"data": map[string]interface{}{}, "count": pc_a.Count - 1}, util.SurvivalTime)
-							} else {
-								util.SetData(userType, userId, map[string]interface{}{"data": data, "count": pc_a.Count - 1}, util.SurvivalTime)
+	updateMap := map[string]interface{}{
+		"messag_id": in.MessageId,
+		"isread":    0,
+	}
+	if util.Mysql.Count(util.SOCIALIZE_MESSAGE_MAILBOX, updateMap) > 0 {
+		fool := util.Mysql.ExecTx("已读状态修改", func(tx *sql.Tx) bool {
+
+			fool := util.Mysql.Update(util.SOCIALIZE_MESSAGE_MAILBOX, updateMap, map[string]interface{}{"read_time": time.Now().Local().Format(util.Date_Full_Layout), "isread": 1})
+			if fool {
+				//查询此条信息拥有者
+				data := util.Mysql.FindOne(util.SOCIALIZE_MESSAGE_MAILBOX, updateMap, "receive_user_type", "")
+				if data != nil {
+					userType := int64(1)
+					userId := int64(0)
+					if (*data)["receive_user_type"] == 2 {
+						userType = 2
+						userId = in.EntUserId
+					} else {
+						userType = 1
+						userId = in.NewUserId
+					}
+					pc_a, err := util.GetData(userType, userId)
+					if fool {
+						if err == nil && pc_a != nil {
+							if pc_a.Count >= 1 {
+								//id一致
+								if in.MessageId == pc_a.Data["id"] {
+									util.SetData(userType, userId, map[string]interface{}{"data": map[string]interface{}{}, "count": pc_a.Count - 1}, util.SurvivalTime)
+								} else {
+									util.SetData(userType, userId, map[string]interface{}{"data": data, "count": pc_a.Count - 1}, util.SurvivalTime)
+								}
 							}
 						}
 					}
-				}
 
+				}
 			}
-		}
+			return fool
+		})
 		return fool
-	})
-	return fool
+	}
+	return true
 }
 
 // WithdrawMessage 撤回消息