瀏覽代碼

fix:用户列表名称支持模糊查询&消息撤回修改

duxin 2 年之前
父節點
當前提交
4f6b619f96
共有 1 個文件被更改,包括 16 次插入31 次删除
  1. 16 31
      service/message_mail_box.go

+ 16 - 31
service/message_mail_box.go

@@ -81,12 +81,10 @@ func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string
 	tm := time.Now()
 	if in.UserType == 2 {
 		var (
-			allSql, nameSql string
-			sqlArr          []string
+			allSql string
+			sqlArr []string
 		)
-		if in.NameSearch != "" {
-			nameSql = " WHERE a.name  like '%" + in.NameSearch + "%"
-		}
+
 		//一对一
 		oneSql := fmt.Sprintf(`(SELECT
 							a.your_position_id AS id,
@@ -119,7 +117,7 @@ func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string
 							"" as phone
 						FROM
 							socialize_summary a
-							INNER JOIN socialize_tenant_robot b ON ( a.user_id = %d AND a.ent_id = b.ent_id )
+							INNER JOIN socialize_tenant_robot b ON ( a.user_id = %d AND a.ent_id = b.ent_id)
 							LEFT JOIN socialize_message c ON ( a.message_id = c.id ) 
 						) `, in.NewUserId)
 		//群列表
@@ -151,8 +149,8 @@ func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string
 		sqlStr = fmt.Sprintf(`SELECT * FROM
 					(
 						%s
-					) a %s
-				a.ORDER BY a.timestamp DESC`, allSql, nameSql)
+					) a 
+				a.ORDER BY a.timestamp DESC`, allSql)
 	} else {
 		var timeSql, phoneSql, filtrationSql string
 		if in.StartTime != "" {
@@ -256,18 +254,21 @@ func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string
 				} else {
 					dataSize = (*data)[(in.Page-1)*in.Size : in.Page*in.Size]
 				}
-				return &dataSize, count, err
 			} else {
 				phoneMap, _, _ := EntPerson(in.EntId, false)
 				for _, v := range *data {
 					if name, ok := phoneMap[quitl.InterfaceToStr(v["phone"])]; ok && quitl.IntAll(v["userType"]) == 1 {
 						v["name"] = name
 					}
+					if in.NameSearch != "" && !strings.Contains(quitl.InterfaceToStr(v["name"]), in.NameSearch) {
+						continue
+					}
+					dataSize = append(dataSize, v)
 				}
 			}
 		}
 	}
-	return
+	return &dataSize, count, err
 }
 
 // 客服会话列表
@@ -280,7 +281,7 @@ func (b MessaggeService) ConversationList(in *messagecenter.ConversationReq) (da
 			ids = append(ids, encrypt.SE.Decode4Hex(v))
 		}
 		filtrationSql := fmt.Sprintf(" AND  b.id in (%s)", strings.Join(ids, ","))
-		aiSql := fmt.Sprintf(`SELECT
+		aiSql := fmt.Sprintf(`(SELECT
 		   				a.user_id,
 		   				a.message_id,
 		   				a.timestamp,
@@ -290,9 +291,9 @@ func (b MessaggeService) ConversationList(in *messagecenter.ConversationReq) (da
 	   				FROM
 		   				socialize_summary a
 		   				INNER JOIN base_user b ON  (a.user_id = b.id AND a.ent_id = %d AND a.customer_service_access = 0 
-		   				%s )`, in.EntId, filtrationSql)
+		   				%s ))`, in.EntId, filtrationSql)
 
-		serviceSql := fmt.Sprintf(`SELECT
+		serviceSql := fmt.Sprintf(`(SELECT
 		   				a.user_id,
 		   				c.message_id,
 		   				c.timestamp,
@@ -302,7 +303,7 @@ func (b MessaggeService) ConversationList(in *messagecenter.ConversationReq) (da
 	   				FROM
 		   				socialize_customer_service_user a
 		   				INNER JOIN base_user b ON  ( a.customer_service_id = %d AND a.user_id = b.id %s)
-						INNER JOIN socialize_summary c ON ( a.ent_id = c.ent_id AND a.user_id = c.user_id)`, in.EntUserId, filtrationSql)
+						INNER JOIN socialize_summary c ON ( a.ent_id = c.ent_id AND a.user_id = c.user_id))`, in.EntUserId, filtrationSql)
 		sqlStr = aiSql + " UNION ALL " + serviceSql
 	}
 
@@ -889,7 +890,7 @@ func SynchronousInfo(sender, recipient, conversationType, messageId, userType, e
 	switch conversationType {
 	case 1: //一对一用户聊天
 		if IC.BaseMysql.Count(util.SOCIALIZE_MESSAGE, map[string]interface{}{"id": messageId, "own_id": recipient, "isread": 0}) > 0 {
-			IC.BaseMysql.SelectBySql(fmt.Sprintf("update %s set Value=CASE WHEN Value > 0 and my_position_id = %d and your_position_id = %d THEN Value-1 ELSE 0 END;", util.Socialize_summary, recipient, sender))
+			IC.BaseMysql.SelectBySql(fmt.Sprintf("update %s set unread=CASE WHEN unread > 0 and my_position_id = %d and your_position_id = %d THEN unread-1 ELSE 0 END;", util.Socialize_summary, recipient, sender))
 		}
 	case 2: //用户与客服
 		if IC.BaseMysql.Count(util.SOCIALIZE_MESSAGE, map[string]interface{}{"id": messageId, "own_id": recipient, "isread": 0}) > 0 {
@@ -941,22 +942,6 @@ func (b MessaggeService) AppraiseMessage(in *messagecenter.AppraiseReq) error {
 	return fmt.Errorf("评价消息异常")
 }
 
-// NewEndId 消息撤回 获取对方userid
-func NewEndId(messageId, iType int64) (newUserId, entUserId int64) {
-	data := IC.BaseMysql.FindOne(util.SOCIALIZE_MESSAGE_MAILBOX, map[string]interface{}{"messag_id": messageId, "own_type": iType}, "", "")
-	if data != nil && len(*data) > 0 {
-		if iType == 1 { //客服撤回消息 获取客服id与用户id
-			entUserId = quitl.Int64All((*data)["send_user_id"])
-			newUserId = quitl.Int64All((*data)["receive_user_id"])
-		} else {
-			//用户撤回消息 获取客服id与用户id
-			newUserId = quitl.Int64All((*data)["send_user_id"])
-			entUserId = quitl.Int64All((*data)["receive_user_id"])
-		}
-	}
-	return
-}
-
 // 聊天
 // 包含 1v1 ,群聊,群发
 /*