瀏覽代碼

Merge branch 'feature/v1.0.2' into feature/v1.0.2_wky

# Conflicts:
#	api/messagecenter/internal/logic/messageaddlogic.go
wangkaiyue 2 年之前
父節點
當前提交
f1bc72c355

+ 3 - 1
api/messagecenter/internal/logic/messageaddlogic.go

@@ -34,15 +34,17 @@ var (
 func init() {
 	htmlFilter.AllowStandardURLs()
 	htmlFilter.AllowAttrs("href").OnElements("a")
+	htmlFilter.AllowAttrs("class").OnElements("li")
 	htmlFilter.AllowAttrs("src").OnElements("img")
 }
 
 func (l *MessageAddLogic) MessageAdd(req *types.MessageEntity) (*types.CommonRes, error) {
+
 	resp, err := l.svcCtx.Message.SaveMessage(l.ctx, &messagecenter.MessageEntity{
 		OwnType:   req.OwnType,
 		Title:     req.Title,
 		SendId:    quitl.Int64All(encrypt.SE.Decode4Hex(req.SendId)),
-		Content:   quitl.If(req.OwnType == 1, fsw.Repl(req.Content), htmlFilter.Sanitize(fsw.Repl(req.Content))).(string), //因知识库内容包含标签,改为仅过滤用户输入
+		Content:   htmlFilter.Sanitize(fsw.Repl(req.Content)),
 		Item:      req.Item,
 		Type:      req.Type,
 		Link:      req.Link,

+ 3 - 3
api/messagecenter/internal/types/types.go

@@ -20,9 +20,9 @@ type UserReq struct {
 	EndTime      string `json:"endTime,optional"`
 	NewUserId    int64  `header:"newUserId"`
 	EntUserId    int64  `header:"entUserId,optional"`
-	Page         int64  `header:"page,optional"`
-	Size         int64  `header:"size,optional"`
-	IsArtificial int64  `header:"isArtificial,optional"`
+	Page         int64  `json:"page,optional"`
+	Size         int64  `json:"size,optional"`
+	IsArtificial int64  `json:"isArtificial,optional"`
 }
 
 type MessageEntity struct {

+ 3 - 3
api/messagecenter/messagecenter.api

@@ -16,9 +16,9 @@ type UserReq {
 	EndTime      string `json:"endTime,optional"`
 	NewUserId    int64  `header:"newUserId"`
 	EntUserId    int64  `header:"entUserId,optional"`
-	Page         int64  `header:"page,optional"`
-	Size         int64  `header:"size,optional"`
-	IsArtificial int64  `header:"isArtificial,optional"`
+	Page         int64  `json:"page,optional"`
+	Size         int64  `json:"size,optional"`
+	IsArtificial int64  `json:"isArtificial,optional"`
 }
 type MessageEntity {
 	OwnType   int64  `json:"ownType"`

+ 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
 }

+ 48 - 40
service/message_mail_box.go

@@ -92,7 +92,8 @@ func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string
 	if in.UserType == 2 {
 		//用户最后一次信息查询
 		userSql := fmt.Sprintf("SELECT  MAX( c.id )   as messageId  FROM  socialize_message_mailbox c "+
-			"WHERE  c.own_id = %d   "+
+			"WHERE  c.own_id = %d  "+
+			"AND c.iswithdraw = 0  "+
 			"AND c.type = 2   "+
 			"AND c.own_type = 2 "+
 			"GROUP BY  (  CASE  WHEN c.send_user_id > c.receive_user_id "+
@@ -106,6 +107,7 @@ func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string
 		customerSql := fmt.Sprintf("SELECT   MAX( c.id )   as messageId  FROM   %s c "+
 			"LEFT JOIN %s d ON  IF   ( c.send_user_type = 1, d.id = c.send_user_id, d.id = c.receive_user_id ) "+
 			"WHERE   c.own_id = %d  "+
+			"AND c.iswithdraw = 0 "+
 			"AND ( c.type = 4 OR c.type = 5  or c.type=6 or  c.type=7 ) "+
 			"AND c.own_type = 2 "+
 			"AND   d.user_id=c.own_id "+
@@ -114,14 +116,14 @@ func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string
 		customerMessageId := util.Inhandle(data)
 		//用户的列表
 		sqlStr = fmt.Sprintf("SELECT "+
-			"(  CASE        WHEN SUBSTR( b.nickname, 1, 3 ) = 'JY_' THEN    CONCAT( SUBSTR( b.phone, 1, 3 ), '****', SUBSTR( b.phone, 8, 11 ) )     WHEN b.nickname = '' THEN    CONCAT( SUBSTR( b.phone, 1, 3 ), '****', SUBSTR( b.phone, 8, 11 ) ) ELSE b.nickname    END    )"+
+			"(  CASE        WHEN SUBSTR( b.nickname, 1, 3 ) = 'JY_' THEN    CONCAT( SUBSTR( b.phone, 1, 3 ), '****', SUBSTR( b.phone, 8, 11 ) )     WHEN b.nickname = '' or b.nickname is null THEN    CONCAT( SUBSTR( b.phone, 1, 3 ), '****', SUBSTR( b.phone, 8, 11 ) ) ELSE b.nickname    END    )"+
 			"AS name, b.id, e.title, b.headimg, e.type, e.link, e.content, 2 AS userType, a.create_time, a.type AS itemType, "+
 			"( SELECT  count( h.id )  FROM  %s h  "+
 			"WHERE  h.type = 2  "+
 			"AND h.own_id = %d  "+
 			"AND h.own_type = 2  "+
 			"AND   h.send_user_id=b.id   "+
-			"AND h.isread = 0  ) AS number  FROM  %s a "+
+			"AND h.isread = 0 AND h.iswithdraw = 0  ) AS number  FROM  %s a "+
 			"LEFT JOIN  %s b ON  b.id = a.receive_user_id or  b.id = a.send_user_id  "+
 			"LEFT JOIN  %s e ON e.id = a.messag_id  "+
 			"WHERE a.id IN ( %s )  AND b.id != %d "+
@@ -177,7 +179,8 @@ func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string
 		userSql := fmt.Sprintf("SELECT   MAX( c.id ) as messageId   FROM  %s c   "+
 			"LEFT JOIN %s d ON   c.own_type=1 AND  c.own_id=d.id   "+
 			"LEFT JOIN %s b ON if (c.send_user_type=1 ,c.receive_user_id,c.send_user_id)=b.id  "+
-			"WHERE   c.own_type = 1    "+
+			"WHERE   c.own_type = 1  "+
+			"AND c.iswithdraw = 0 "+
 			"AND (%s)   "+
 			"AND ( c.type = 4 OR c.type = 5 or  c.type=6 or  c.type=7 )   "+
 			"  %s %s %s "+
@@ -199,14 +202,15 @@ func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string
 			customerMessageId := util.Inhandle(&d)
 			//客服的用户列表
 			sqlStr = fmt.Sprintf("SELECT  "+
-				"(  CASE        WHEN SUBSTR( b.nickname, 1, 3 ) = 'JY_' THEN    CONCAT( SUBSTR( b.phone, 1, 3 ), '****', SUBSTR( b.phone, 8, 11 ) )     WHEN b.nickname = '' THEN    CONCAT( SUBSTR( b.phone, 1, 3 ), '****', SUBSTR( b.phone, 8, 11 ) ) ELSE b.nickname    END    )"+
+				"(  CASE        WHEN SUBSTR( b.nickname, 1, 3 ) = 'JY_' THEN    CONCAT( SUBSTR( b.phone, 1, 3 ), '****', SUBSTR( b.phone, 8, 11 ) )     WHEN b.nickname = '' or b.nickname is null THEN    CONCAT( SUBSTR( b.phone, 1, 3 ), '****', SUBSTR( b.phone, 8, 11 ) ) ELSE b.nickname    END    )"+
 				" AS name,  b.id,  e.title,  b.headimg,  e.type,  e.link,  e.content,  a.create_time,  "+
 				"(  SELECT   count( h.id )   FROM   %s h   "+
 				"LEFT JOIN %s i ON h.own_type = 1 AND h.own_id = i.id     "+
 				"WHERE  h.own_type = 1  "+
 				"AND i.ent_id=f.ent_id "+
 				"AND  i.user_id=f.user_id    "+
-				"AND h.isread = 0    "+
+				"AND h.isread = 0  "+
+				"AND h.iswithdraw = 0 "+
 				"AND  i.customer_service_id= %d) AS number "+
 				"FROM  %s a  "+
 				"LEFT JOIN %s b ON if (a.send_user_type=1 ,a.receive_user_id,a.send_user_id)=b.id  "+
@@ -523,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: //点对点聊天
@@ -639,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 撤回消息