|
@@ -566,6 +566,7 @@ func UserSynchronousList(customerServiceId, userId, entId, messageId int64, crea
|
|
|
func (b MessaggeService) FindMessage(in *messagecenter.MessageReq) *[]map[string]interface{} {
|
|
|
sqlStr := ""
|
|
|
lastStr := ""
|
|
|
+ positionStr := ""
|
|
|
if in.LastId > 0 {
|
|
|
if in.Sort == "asc" {
|
|
|
lastStr = fmt.Sprintf("AND a.messag_id > %d ", in.LastId)
|
|
@@ -588,7 +589,34 @@ func (b MessaggeService) FindMessage(in *messagecenter.MessageReq) *[]map[string
|
|
|
util.SOCIALIZE_MESSAGE_MAILBOX, util.SOCIALIZE_MESSAGE, util.BASE_USER, util.BASE_USER,
|
|
|
in.NewUserId, in.NewUserId, in.SendId, in.SendId, in.NewUserId, lastStr, in.PageSize)
|
|
|
break
|
|
|
+ case 3: //群聊天
|
|
|
+
|
|
|
+ sqlStr = fmt.Sprintf("SELECT a.messag_id AS messageId,b.*,"+
|
|
|
+ "IF ( a.own_id = a.send_user_id, 1, 2 ) AS fool,"+
|
|
|
+ "IF ( a.own_id = a.send_user_id, 0, a.send_user_id ) AS send_position_id,"+
|
|
|
+ "a.send_user_type,a.type AS itemType FROM %s a "+
|
|
|
+ "LEFT JOIN %s b ON a.messag_id = b.id "+
|
|
|
+ "WHERE a.own_type = 1 AND a.own_id = %d "+
|
|
|
+ "AND chat_group_id = %d AND a.type IN ( 3, 6 ) "+
|
|
|
+ "ORDER BY a.create_time desc,a.id DESC "+
|
|
|
+ "LIMIT 0, %d",
|
|
|
+ util.SOCIALIZE_MESSAGE_MAILBOX, util.SOCIALIZE_MESSAGE, in.SendId,
|
|
|
+ in.ChatGroupId, in.PageSize)
|
|
|
case 4, 5, 6, 7: //客服聊天
|
|
|
+ //查询用户所有的职位id
|
|
|
+ sqlPosition := fmt.Sprintf("SELECT b.id FROM %s a LEFT JOIN %s b ON a.id = b.user_id "+
|
|
|
+ "WHERE a.phone = (SELECT a.phone FROM %s a LEFT JOIN %s b ON a.id = b.user_id "+
|
|
|
+ "WHERE b.id = %d)",
|
|
|
+ util.BASE_USER, util.BASE_POSITION, util.BASE_USER, util.BASE_POSITION, in.NewUserId)
|
|
|
+ positionArr := IC.BaseMysql.SelectBySql(sqlPosition)
|
|
|
+ for k, val := range *positionArr {
|
|
|
+ if k < len(*positionArr)-1 {
|
|
|
+ positionStr += quitl.ObjToString(val["id"]) + ","
|
|
|
+ } else {
|
|
|
+ positionStr += quitl.ObjToString(val["id"])
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
if in.UserType == 1 {
|
|
|
//客服聊天记录查看
|
|
|
sqlStr = fmt.Sprintf("SELECT a.messag_id as messageId,b.*, IF ( a.own_id = a.send_user_id, 1, 2 ) AS fool, a.send_user_type, a.type AS itemType, '' AS robotName, '' AS robotImg, c.customer_service_name AS setName , c.user_id "+
|
|
@@ -598,11 +626,11 @@ func (b MessaggeService) FindMessage(in *messagecenter.MessageReq) *[]map[string
|
|
|
"WHERE a.own_type = 1 and a.iswithdraw = 0 "+
|
|
|
"AND (a.type = 5 or a.type=4 or a.type=6 or a.type=7 or a.type=8 ) "+
|
|
|
"AND c.ent_id = %d "+
|
|
|
- "AND c.user_id = %d %s "+
|
|
|
- "ORDER BY a.create_time desc ,a.id asc "+
|
|
|
+ "AND c.user_id in (%s) %s "+
|
|
|
+ "ORDER BY a.create_time desc ,a.id asc "+
|
|
|
"limit 0 , %d ",
|
|
|
util.SOCIALIZE_MESSAGE_MAILBOX, util.SOCIALIZE_MESSAGE, util.SOCIALIZE_CHAT_SESSION,
|
|
|
- in.EntId, in.SendId, lastStr, in.PageSize)
|
|
|
+ in.EntId, positionStr, lastStr, in.PageSize)
|
|
|
} else {
|
|
|
//用户聊天记录查看
|
|
|
sqlStr = fmt.Sprintf("SELECT a.messag_id as messageId,e.appraise as appraise, b.*, IF ( a.own_id = a.send_user_id, 1, 2 ) AS fool , a.send_user_type, a.type as itemType, d.nickname as robotName, d.headimage as robotImg, c.customer_service_name as setName "+
|
|
@@ -610,21 +638,21 @@ func (b MessaggeService) FindMessage(in *messagecenter.MessageReq) *[]map[string
|
|
|
"LEFT JOIN %s b ON a.messag_id = b.id "+
|
|
|
"LEFT JOIN %s c ON IF ( a.send_user_type = 1, a.send_user_id, a.receive_user_id ) = c.id AND c.ent_id = %d AND c.user_id = %d "+
|
|
|
"LEFT JOIN %s d on c.ent_id=d.ent_id "+
|
|
|
- "LEFT JOIN %s e on e.messag_id=b.id "+
|
|
|
- "WHERE a.own_type = 2 and a.iswithdraw = 0 "+
|
|
|
- "AND a.own_id = %d "+
|
|
|
+ "WHERE a.own_type = 2 "+
|
|
|
+ "AND a.own_id in (%s) "+
|
|
|
"AND c.ent_id = %d "+
|
|
|
- "AND c.user_id = %d "+
|
|
|
- "AND ( a.type = 4 OR a.type = 5 or a.type=6 or a.type=7 or a.type=8) %s "+
|
|
|
- "ORDER BY a.create_time desc,a.id asc "+
|
|
|
+ "AND c.user_id in (%s) "+
|
|
|
+ "AND ( a.type = 4 OR a.type = 5 or a.type=6 or a.type=7) %s "+
|
|
|
+ "ORDER BY a.create_time desc ,a.id asc "+
|
|
|
"limit 0 , %d ",
|
|
|
- util.SOCIALIZE_MESSAGE_MAILBOX, util.SOCIALIZE_MESSAGE, util.SOCIALIZE_CHAT_SESSION, in.SendId, in.NewUserId, util.SOCIALIZE_TENANT_ROBOT, util.SOCIALIZE_APPRAISE,
|
|
|
- in.NewUserId, in.SendId, in.NewUserId, lastStr, in.PageSize)
|
|
|
+ util.SOCIALIZE_MESSAGE_MAILBOX, util.SOCIALIZE_MESSAGE, util.SOCIALIZE_CHAT_SESSION, in.SendId, in.NewUserId, util.SOCIALIZE_TENANT_ROBOT,
|
|
|
+ positionStr, in.SendId, positionStr, lastStr, in.PageSize)
|
|
|
}
|
|
|
break
|
|
|
}
|
|
|
log.Println(sqlStr)
|
|
|
data := IC.BaseMysql.SelectBySql(sqlStr)
|
|
|
+ //查询非自己发送消息得发送人名字
|
|
|
//自己头像处理
|
|
|
if in.UserType == 2 {
|
|
|
userData := IC.BaseMysql.FindOne(util.BASE_USER, map[string]interface{}{"id": in.NewUserId}, "headimg", "")
|
|
@@ -635,6 +663,15 @@ func (b MessaggeService) FindMessage(in *messagecenter.MessageReq) *[]map[string
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+ if in.MsgType == 3 && data != nil && len(*data) > 0 {
|
|
|
+ _, _, positionData := EntPerson(in.EntId, true)
|
|
|
+ for _, v := range *data {
|
|
|
+ positionId := quitl.IntAll(v["send_user_id"])
|
|
|
+ if positionId != 0 {
|
|
|
+ v["userName"] = positionData[positionId]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
go func() {
|
|
|
updateMap := map[string]interface{}{}
|
|
|
if len(*data) > 0 && data != nil {
|
|
@@ -643,34 +680,42 @@ func (b MessaggeService) FindMessage(in *messagecenter.MessageReq) *[]map[string
|
|
|
switch in.MsgType {
|
|
|
case 2: //点对点聊天
|
|
|
updateMap = map[string]interface{}{
|
|
|
- "own_type": 2,
|
|
|
- "own_id": in.NewUserId,
|
|
|
- "type": 2,
|
|
|
- "isread": 0,
|
|
|
+ "own_type": 2,
|
|
|
+ "own_id": in.NewUserId,
|
|
|
+ "send_user_id": in.SendId,
|
|
|
+ "type": 2,
|
|
|
+ "isread": 0,
|
|
|
}
|
|
|
IC.BaseMysql.Update(util.SOCIALIZE_MESSAGE_MAILBOX, updateMap, map[string]interface{}{"isread": 1, "read_time": time.Now().Local().Format(util.Date_Full_Layout)})
|
|
|
break
|
|
|
- case 4, 5:
|
|
|
+ case 3: //群聊天
|
|
|
+ sqlStr = fmt.Sprintf("UPDATE %s a SET a.isread = 1, a.read_time = now( ) "+
|
|
|
+ "WHERE a.own_type = 1 "+
|
|
|
+ "AND a.type IN (3,6) "+
|
|
|
+ "AND a.isread = 0 "+
|
|
|
+ "AND a.own_id = %d AND a.chat_group_id = %d",
|
|
|
+ util.SOCIALIZE_MESSAGE_MAILBOX, in.SendId, in.ChatGroupId)
|
|
|
+ case 4, 5: //UserType 2用户1客服
|
|
|
sqlStr := ""
|
|
|
if in.UserType == 1 {
|
|
|
sqlStr = fmt.Sprintf("UPDATE %s a SET a.isread = 1, a.read_time = now( ) "+
|
|
|
"WHERE a.own_type = 1 and a.iswithdraw = 0 "+
|
|
|
"AND a.type IN ( 4,5,6,7) "+
|
|
|
"AND a.isread = 0 "+
|
|
|
- "AND a.own_id IN ( SELECT b.id FROM %s b WHERE b.customer_service_id=%d AND b.user_id=%d )",
|
|
|
- util.SOCIALIZE_MESSAGE_MAILBOX, util.SOCIALIZE_CHAT_SESSION, in.EntUserId, in.SendId)
|
|
|
+ "AND a.own_id IN ( SELECT b.id FROM %s b WHERE b.customer_service_id=%d AND b.user_id in (%s) )",
|
|
|
+ util.SOCIALIZE_MESSAGE_MAILBOX, util.SOCIALIZE_CHAT_SESSION, in.EntUserId, positionStr)
|
|
|
} else {
|
|
|
sqlStr = fmt.Sprintf("UPDATE %s a SET a.isread = 1, a.read_time = now( ) "+
|
|
|
"WHERE a.own_type = 2 and a.iswithdraw = 0 "+
|
|
|
"AND a.type IN ( 4,5,6,7 ) "+
|
|
|
"AND a.isread = 0 "+
|
|
|
- "AND a.own_id =%d ", util.SOCIALIZE_MESSAGE_MAILBOX, in.NewUserId)
|
|
|
+ "AND a.own_id in (%s) ", util.SOCIALIZE_MESSAGE_MAILBOX, positionStr)
|
|
|
}
|
|
|
IC.BaseMysql.UpdateOrDeleteBySql(sqlStr)
|
|
|
break
|
|
|
}
|
|
|
//redis缓存处理
|
|
|
- b.Count(in.NewUserId, in.UserType, in.EntUserId, true)
|
|
|
+ //b.Count(in.NewUserId, in.UserType, in.EntUserId, true)
|
|
|
}
|
|
|
}()
|
|
|
return data
|