|
@@ -1,60 +1,47 @@
|
|
|
package service
|
|
|
|
|
|
import (
|
|
|
- quitl "app.yhyue.com/moapp/jybase/common"
|
|
|
- "app.yhyue.com/moapp/jybase/encrypt"
|
|
|
- util "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/entity"
|
|
|
- IC "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/rpc/messagecenter/init"
|
|
|
- "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/rpc/messagecenter/messagecenter"
|
|
|
"database/sql"
|
|
|
"fmt"
|
|
|
"log"
|
|
|
+ "strconv"
|
|
|
"strings"
|
|
|
"sync"
|
|
|
"time"
|
|
|
+
|
|
|
+ quitl "app.yhyue.com/moapp/jybase/common"
|
|
|
+ "app.yhyue.com/moapp/jybase/date"
|
|
|
+ "app.yhyue.com/moapp/jybase/encrypt"
|
|
|
+ util "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/entity"
|
|
|
+ IC "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/rpc/messagecenter/init"
|
|
|
+ "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/rpc/messagecenter/messagecenter"
|
|
|
+ "github.com/gogf/gf/v2/util/gconv"
|
|
|
)
|
|
|
|
|
|
type MessaggeService struct{}
|
|
|
|
|
|
+var rwLock = new(sync.RWMutex)
|
|
|
+
|
|
|
// 未读消息查询
|
|
|
func (b MessaggeService) Count(newUserId, userType, entUserId int64, isClean bool) (count int, last map[string]interface{}, err error) {
|
|
|
log.Printf("用户id:%d,userType:%d,entUserId:%d,isClean:%v", newUserId, userType, entUserId, isClean)
|
|
|
v := make([]interface{}, 0)
|
|
|
sqlStr := ""
|
|
|
- if userType == 1 {
|
|
|
- //查询缓存里边是否有数据
|
|
|
- pc_a, err := util.GetData(userType, entUserId)
|
|
|
- if err == nil && pc_a != nil {
|
|
|
- // 缓存有值
|
|
|
- if !isClean {
|
|
|
- return pc_a.Count, pc_a.Data, err
|
|
|
- }
|
|
|
- }
|
|
|
- sqlStr = fmt.Sprintf("select count(b.id) from %s a "+
|
|
|
- "LEFT JOIN %s b ON a.id=b.own_id "+
|
|
|
- "where b.type=5 "+
|
|
|
- "AND a.customer_service_id=%d "+
|
|
|
- "AND b.iswithdraw = 0 "+
|
|
|
- "AND b.isread=0 "+
|
|
|
- "AND own_type = 1 "+
|
|
|
- "order by create_time", util.SOCIALIZE_CHAT_SESSION, util.SOCIALIZE_MESSAGE_MAILBOX, entUserId)
|
|
|
|
|
|
- } else {
|
|
|
- pc_a, err := util.GetData(userType, newUserId)
|
|
|
- if err == nil && pc_a != nil {
|
|
|
- if !isClean {
|
|
|
- return pc_a.Count, pc_a.Data, err
|
|
|
- }
|
|
|
+ pc_a, err := util.GetData(userType, newUserId)
|
|
|
+ if err == nil && pc_a != nil {
|
|
|
+ if !isClean {
|
|
|
+ return pc_a.Count, pc_a.Data, err
|
|
|
}
|
|
|
- sqlStr = fmt.Sprintf("select count(b.id) from %s b "+
|
|
|
- "where b.send_user_id != %d "+
|
|
|
- "AND b.own_id=%d "+
|
|
|
- "AND b.iswithdraw = 0 "+
|
|
|
- "AND b.isread=0 "+
|
|
|
- "AND own_type = 2 "+
|
|
|
- "order by create_time", util.SOCIALIZE_MESSAGE_MAILBOX, newUserId, newUserId)
|
|
|
-
|
|
|
}
|
|
|
+ sqlStr = fmt.Sprintf("select count(b.id) from %s b "+
|
|
|
+ "where b.send_user_id != %d "+
|
|
|
+ "AND b.own_id=%d "+
|
|
|
+ "AND b.iswithdraw = 0 "+
|
|
|
+ "AND b.isread=0 "+
|
|
|
+ "AND own_type = 2 "+
|
|
|
+ "order by create_time", util.SOCIALIZE_MESSAGE_MAILBOX, newUserId, newUserId)
|
|
|
+
|
|
|
log.Println(sqlStr, v)
|
|
|
rs := IC.BaseMysql.CountBySql(sqlStr, v...)
|
|
|
log.Println(rs)
|
|
@@ -85,7 +72,7 @@ func (b MessaggeService) Count(newUserId, userType, entUserId int64, isClean boo
|
|
|
util.SetData(userType, newUserId, map[string]interface{}{"data": map[string]interface{}{}, "count": count}, IC.SurvivalTime)
|
|
|
}
|
|
|
}
|
|
|
- return
|
|
|
+ return positionStr
|
|
|
}
|
|
|
|
|
|
// 用户列表查询
|
|
@@ -93,133 +80,166 @@ func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string
|
|
|
sqlStr := ""
|
|
|
tm := time.Now()
|
|
|
if in.UserType == 2 {
|
|
|
- //用户最后一次信息查询
|
|
|
- userSql := fmt.Sprintf("SELECT MAX( c.id ) as messageId FROM socialize_message_mailbox c "+
|
|
|
- "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 "+
|
|
|
- "THEN CONCAT( c.send_user_id, c.receive_user_id ) "+
|
|
|
- "WHEN c.send_user_id < c.receive_user_id "+
|
|
|
- "THEN CONCAT( c.receive_user_id, c.send_user_id ) END ) ", in.NewUserId,
|
|
|
+ var (
|
|
|
+ allSql string
|
|
|
+ sqlArr []string
|
|
|
)
|
|
|
- data = IC.BaseMysql.SelectBySql(userSql)
|
|
|
- userMessageId := util.Inhandle(data)
|
|
|
- //客服最后一次信息查询
|
|
|
- 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 "+
|
|
|
- "GROUP BY d.ent_id ", util.SOCIALIZE_MESSAGE_MAILBOX, util.SOCIALIZE_CHAT_SESSION, in.NewUserId)
|
|
|
- data = IC.BaseMysql.SelectBySql(customerSql)
|
|
|
- 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 = '' 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 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 "+
|
|
|
- "UNION ALL "+
|
|
|
- "SELECT f.nickname AS name, b.ent_id AS id, e.title,f.headimage AS headimg, e.type, e.link, e.content, 1 AS userType, a.create_time, a.type AS itemType, "+
|
|
|
- "( SELECT count( h.id ) FROM %s h WHERE ( h.type = 4 OR h.type = 5 ) AND h.own_id = %d AND h.own_type = 2 AND h.send_user_type = 1 AND h.receive_user_id = %d AND h.isread = 0 ) AS number "+
|
|
|
- "FROM %s a "+
|
|
|
- "LEFT JOIN %s b ON IF ( a.send_user_type = 1, a.send_user_id, a.receive_user_id ) = b.id "+
|
|
|
- "LEFT JOIN %s e ON e.id = a.messag_id "+
|
|
|
- "LEFT join %s f on f.ent_id=b.ent_id "+
|
|
|
- "WHERE a.id IN ( %s ) "+
|
|
|
- "ORDER BY create_time DESC",
|
|
|
- util.SOCIALIZE_MESSAGE_MAILBOX,
|
|
|
- in.NewUserId,
|
|
|
- util.SOCIALIZE_MESSAGE_MAILBOX,
|
|
|
- util.BASE_USER,
|
|
|
- util.SOCIALIZE_MESSAGE,
|
|
|
- userMessageId,
|
|
|
- in.NewUserId,
|
|
|
- util.SOCIALIZE_MESSAGE_MAILBOX,
|
|
|
- in.NewUserId,
|
|
|
- in.NewUserId,
|
|
|
- util.SOCIALIZE_MESSAGE_MAILBOX,
|
|
|
- util.SOCIALIZE_CHAT_SESSION,
|
|
|
- util.SOCIALIZE_MESSAGE,
|
|
|
- util.SOCIALIZE_TENANT_ROBOT,
|
|
|
- customerMessageId)
|
|
|
- } else {
|
|
|
- idSql := fmt.Sprintf(" (a.customer_service_id = %d OR a.customer_service_id = 0) ", in.EntUserId)
|
|
|
- if in.IsArtificial == 1 {
|
|
|
- idSql = fmt.Sprintf(" a.customer_service_id = %d ", in.EntUserId)
|
|
|
- } else if in.IsArtificial == 2 {
|
|
|
- idSql = " a.customer_service_id = 0 "
|
|
|
+
|
|
|
+ //一对一
|
|
|
+ oneSql := fmt.Sprintf(`(SELECT
|
|
|
+ a.your_position_id AS id,
|
|
|
+ 1 AS userType,
|
|
|
+ c.nickname AS name,
|
|
|
+ c.headimg,
|
|
|
+ d.content,
|
|
|
+ d.type
|
|
|
+ d.create_time,
|
|
|
+ a.unread as number,
|
|
|
+ a.timestamp,
|
|
|
+ c.phone
|
|
|
+ FROM
|
|
|
+ socialize_summary a
|
|
|
+ INNER JOIN base_position b ON ( a.my_position_id = %d AND a.your_position_id = b.id )
|
|
|
+ INNER JOIN base_user c ON ( b.user_id = c.id )
|
|
|
+ LEFT JOIN socialize_message d ON ( a.message_id = d.id ))`, in.PositionId)
|
|
|
+ //客服列表
|
|
|
+ serviceSql := fmt.Sprintf(` (
|
|
|
+ SELECT
|
|
|
+ a.ent_id AS id,
|
|
|
+ 2 AS userType,
|
|
|
+ b.nickname AS name,
|
|
|
+ b.headimage as headimg,
|
|
|
+ c.content,
|
|
|
+ c.type,
|
|
|
+ c.create_time,
|
|
|
+ a.unread as number,
|
|
|
+ a.timestamp,
|
|
|
+ "" as phone
|
|
|
+ FROM
|
|
|
+ socialize_summary a
|
|
|
+ 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)
|
|
|
+ //群列表
|
|
|
+ groupSql := fmt.Sprintf(` (
|
|
|
+ SELECT
|
|
|
+ b.id,
|
|
|
+ 3 AS userType,
|
|
|
+ b.name,
|
|
|
+ '' AS headimg,
|
|
|
+ d.content,
|
|
|
+ d.type,
|
|
|
+ d.create_time,
|
|
|
+ a.unread as number,
|
|
|
+ c.timestamp,
|
|
|
+ "" as phone
|
|
|
+ FROM
|
|
|
+ socialize_chat_group_person a
|
|
|
+ INNER JOIN socialize_chat_group b ON ( a.position_id = %d AND a.chat_group_id = b.id AND b.isdismiss = 0)
|
|
|
+ INNER JOIN socialize_summary c ON ( b.id = c.chat_group_id )
|
|
|
+ LEFT JOIN socialize_message d ON ( c.message_id = d.id )
|
|
|
+ ) `, in.PositionId)
|
|
|
+ switch in.QueryType {
|
|
|
+ case 1: //分享列表
|
|
|
+ allSql = strings.Join(append(sqlArr, oneSql, groupSql), " UNION ALL ")
|
|
|
+ case 2: //历史会话列表
|
|
|
+ allSql = strings.Join(append(sqlArr, oneSql, groupSql, serviceSql), " UNION ALL ")
|
|
|
}
|
|
|
+
|
|
|
+ sqlStr = fmt.Sprintf(`SELECT * FROM
|
|
|
+ (
|
|
|
+ %s
|
|
|
+ ) a
|
|
|
+ a.ORDER BY a.timestamp DESC`, allSql)
|
|
|
+ } else {
|
|
|
+ var timeSql, phoneSql, filtrationSql string
|
|
|
if in.StartTime != "" {
|
|
|
- idSql += " AND DATE_FORMAT(a.update_time,'%Y-%m-%d') >= '" + in.StartTime + "' "
|
|
|
+ timeSql += fmt.Sprintf(" AND a.timestamp > %s", in.StartTime)
|
|
|
}
|
|
|
if in.EndTime != "" {
|
|
|
- idSql += "AND DATE_FORMAT(a.update_time,'%Y-%m-%d') <= '" + in.EndTime + "' "
|
|
|
+ timeSql += fmt.Sprintf(" AND a.timestamp < %s", in.EndTime)
|
|
|
}
|
|
|
if in.Phone != "" {
|
|
|
- idSql += " AND b.phone like '%" + in.Phone + "%'"
|
|
|
+ phoneSql = " AND b.phone like '%" + in.Phone + "%"
|
|
|
}
|
|
|
if in.FiltrationId != "" {
|
|
|
var ids []string
|
|
|
for _, v := range strings.Split(in.FiltrationId, ",") {
|
|
|
ids = append(ids, encrypt.SE.Decode4Hex(v))
|
|
|
}
|
|
|
- idSql += fmt.Sprintf(" AND b.id not in (%s)", strings.Join(ids, ","))
|
|
|
+ filtrationSql += fmt.Sprintf(" AND b.id not in (%s)", strings.Join(ids, ","))
|
|
|
+ }
|
|
|
+ aiSql := fmt.Sprintf(`(SELECT
|
|
|
+ a.user_id,
|
|
|
+ a.message_id,
|
|
|
+ a.timestamp,
|
|
|
+ b.nickname,
|
|
|
+ 0 as unread,
|
|
|
+ b.headimg,
|
|
|
+ "" as phone,
|
|
|
+ 0 as userType
|
|
|
+ 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 %s %s)`, in.EntId, timeSql, phoneSql, filtrationSql)
|
|
|
+
|
|
|
+ serviceSql := fmt.Sprintf(`(SELECT
|
|
|
+ a.user_id,
|
|
|
+ c.message_id,
|
|
|
+ c.timestamp,
|
|
|
+ b.nickname,
|
|
|
+ a.unread,
|
|
|
+ b.headimg,
|
|
|
+ "" as phone,
|
|
|
+ 0 as userType
|
|
|
+ FROM
|
|
|
+ socialize_customer_service_user a
|
|
|
+ INNER JOIN base_user b ON ( a.customer_service_id = %d AND a.user_id = b.id %s %s)
|
|
|
+ INNER JOIN socialize_summary c ON ( a.ent_id = c.ent_id AND a.user_id = c.user_id %s))`, in.EntUserId, filtrationSql, phoneSql,
|
|
|
+ strings.ReplaceAll(timeSql, "a.", "c."))
|
|
|
+ var restrictionSql string
|
|
|
+ switch in.IsArtificial {
|
|
|
+ case 1:
|
|
|
+ restrictionSql = serviceSql
|
|
|
+ case 2:
|
|
|
+ restrictionSql = aiSql
|
|
|
+ default:
|
|
|
+ restrictionSql = aiSql + " UNION ALL " + serviceSql
|
|
|
}
|
|
|
+
|
|
|
if in.Page <= 0 {
|
|
|
in.Page = 1
|
|
|
}
|
|
|
if in.Size <= 0 || in.Size > 100 {
|
|
|
in.Size = 50
|
|
|
}
|
|
|
- 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 = ''
|
|
|
- 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.update_time as create_time,
|
|
|
- (
|
|
|
- SELECT
|
|
|
- count( h.id )
|
|
|
- FROM
|
|
|
- %s h
|
|
|
- LEFT JOIN %s i ON h.own_id = i.id
|
|
|
- WHERE
|
|
|
- h.own_type = 1
|
|
|
- AND i.ent_id = a.ent_id
|
|
|
- AND i.user_id = a.user_id
|
|
|
- AND h.isread = 0
|
|
|
- AND h.iswithdraw = 0
|
|
|
- AND i.customer_service_id = %d
|
|
|
- ) AS number
|
|
|
- FROM
|
|
|
- %s a
|
|
|
- INNER JOIN %s b ON a.ent_id = %d and %s
|
|
|
- AND a.user_id = b.id
|
|
|
- LEFT JOIN %s e ON e.id = a.message_id
|
|
|
- ORDER BY
|
|
|
- a.update_time DESC`, util.SOCIALIZE_MESSAGE_MAILBOX, util.SOCIALIZE_CHAT_SESSION, in.EntUserId, util.User_message_list, util.BASE_USER, in.EntId, idSql, util.SOCIALIZE_MESSAGE)
|
|
|
+ sqlStr = fmt.Sprintf(`SELECT
|
|
|
+ (
|
|
|
+ CASE
|
|
|
+ WHEN SUBSTR( a.nickname, 1, 3 ) = 'JY_' THEN
|
|
|
+ CONCAT( SUBSTR( a.phone, 1, 3 ), '****', SUBSTR( a.phone, 8, 11 ) )
|
|
|
+ WHEN a.nickname = ''
|
|
|
+ OR a.nickname IS NULL THEN
|
|
|
+ CONCAT( SUBSTR( a.phone, 1, 3 ), '****', SUBSTR( a.phone, 8, 11 ) ) ELSE a.nickname
|
|
|
+ END
|
|
|
+ ) AS name,
|
|
|
+ c.content,
|
|
|
+ c.title,
|
|
|
+ c.type,
|
|
|
+ c.link,
|
|
|
+ c.create_time,
|
|
|
+ a.message_id,
|
|
|
+ a.timestamp,
|
|
|
+ a.unread as number,
|
|
|
+ a.user_id as id,
|
|
|
+ a.headimg,
|
|
|
+ a.phone,
|
|
|
+ a.userType
|
|
|
+ FROM
|
|
|
+ (%s) a
|
|
|
+ LEFT JOIN socialize_message c ON ( a.message_id = c.id )
|
|
|
+ ORDER BY
|
|
|
+ a.timestamp DESC`, restrictionSql)
|
|
|
}
|
|
|
dataSize := []map[string]interface{}{}
|
|
|
if sqlStr != "" {
|
|
@@ -234,11 +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
|
|
|
}
|
|
|
|
|
|
// 客服会话列表
|
|
@@ -250,43 +280,31 @@ func (b MessaggeService) ConversationList(in *messagecenter.ConversationReq) (da
|
|
|
for _, v := range strings.Split(in.FiltrationId, ",") {
|
|
|
ids = append(ids, encrypt.SE.Decode4Hex(v))
|
|
|
}
|
|
|
- idSql := fmt.Sprintf("a.customer_service_id = %d AND b.id in (%s) ", in.EntUserId, strings.Join(ids, ","))
|
|
|
- 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 = ''
|
|
|
- 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.update_time as create_time,
|
|
|
- (
|
|
|
- SELECT
|
|
|
- count( h.id )
|
|
|
- FROM
|
|
|
- %s h
|
|
|
- LEFT JOIN %s i ON h.own_id = i.id
|
|
|
- WHERE
|
|
|
- h.own_type = 1
|
|
|
- AND i.ent_id = a.ent_id
|
|
|
- AND i.user_id = a.user_id
|
|
|
- AND h.isread = 0
|
|
|
- AND h.iswithdraw = 0
|
|
|
- AND i.customer_service_id = %d
|
|
|
- ) AS number
|
|
|
- FROM
|
|
|
- %s a
|
|
|
- INNER JOIN %s b ON %s
|
|
|
- AND a.user_id = b.id
|
|
|
- LEFT JOIN %s e ON e.id = a.message_id`,
|
|
|
- util.SOCIALIZE_MESSAGE_MAILBOX, util.SOCIALIZE_CHAT_SESSION, in.EntUserId, util.User_message_list, util.BASE_USER, idSql, util.SOCIALIZE_MESSAGE)
|
|
|
+ filtrationSql := fmt.Sprintf(" AND b.id in (%s)", strings.Join(ids, ","))
|
|
|
+ aiSql := fmt.Sprintf(`(SELECT
|
|
|
+ a.user_id,
|
|
|
+ a.message_id,
|
|
|
+ a.timestamp,
|
|
|
+ b.nickname,
|
|
|
+ 0 as unread,
|
|
|
+ b.headimg
|
|
|
+ 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)
|
|
|
+
|
|
|
+ serviceSql := fmt.Sprintf(`(SELECT
|
|
|
+ a.user_id,
|
|
|
+ c.message_id,
|
|
|
+ c.timestamp,
|
|
|
+ b.nickname,
|
|
|
+ a.unread,
|
|
|
+ b.headimg
|
|
|
+ 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)
|
|
|
+ sqlStr = aiSql + " UNION ALL " + serviceSql
|
|
|
}
|
|
|
|
|
|
if sqlStr != "" {
|
|
@@ -524,8 +542,6 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
|
|
|
return fool, "", in.Content, messageId, nowForm.Unix()
|
|
|
}
|
|
|
|
|
|
-var rwLock = new(sync.RWMutex)
|
|
|
-
|
|
|
// 客服 用户聊天消息列表同步
|
|
|
func UserSynchronousList(customerServiceId, userId, entId, messageId int64, createTime string) {
|
|
|
log.Printf("同步最后消息参数customerServiceId:%d,userId:%d,entId%d,messageId:%d", customerServiceId, userId, entId, messageId)
|
|
@@ -562,6 +578,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)
|
|
@@ -584,7 +601,22 @@ 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
|
|
|
+ positionStr = GetUserAllPosition(in.NewUserId)
|
|
|
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 "+
|
|
@@ -594,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 "+
|
|
@@ -606,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", "")
|
|
@@ -631,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 {
|
|
@@ -638,35 +679,61 @@ 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)})
|
|
|
+ //更新socialize_summary表未读消息数量
|
|
|
+ updateQuery := map[string]interface{}{
|
|
|
+ "my_position_id": in.NewUserId,
|
|
|
+ "your_position_id": in.SendId,
|
|
|
+ }
|
|
|
+ IC.BaseMysql.Update(util.SOCIALIZE_SUMMARY, updateQuery, map[string]interface{}{"unread": 0})
|
|
|
break
|
|
|
+ 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)
|
|
|
+ IC.BaseMysql.UpdateOrDeleteBySql(sqlStr)
|
|
|
+ //更新socialize_summary表未读消息数量
|
|
|
+ updateQuery := map[string]interface{}{
|
|
|
+ "my_position_id": in.NewUserId,
|
|
|
+ "chat_group_id": in.ChatGroupId,
|
|
|
+ }
|
|
|
+ IC.BaseMysql.Update(util.SOCIALIZE_SUMMARY, updateQuery, map[string]interface{}{"unread": 0})
|
|
|
case 4, 5:
|
|
|
sqlStr := ""
|
|
|
- if in.UserType == 1 {
|
|
|
+ unreadSql := ""
|
|
|
+ if in.UserType == 1 { //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)
|
|
|
- } else {
|
|
|
+ "AND a.own_id IN (SELECT id FROM %s WHERE user_id = %d)",
|
|
|
+ util.SOCIALIZE_MESSAGE_MAILBOX, util.BASE_POSITION, in.UserId)
|
|
|
+ unreadSql = fmt.Sprintf("UPDATE %s SET unread = 0 WHERE user_id = %d", util.Socialize_customer_service_user, in.UserId)
|
|
|
+ } else { //2用户
|
|
|
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)
|
|
|
+ unreadSql = fmt.Sprintf("UPDATE %s SET unread = 0 WHERE user_id = %d", util.SOCIALIZE_SUMMARY, in.UserId)
|
|
|
}
|
|
|
IC.BaseMysql.UpdateOrDeleteBySql(sqlStr)
|
|
|
+ IC.BaseMysql.UpdateOrDeleteBySql(unreadSql)
|
|
|
break
|
|
|
}
|
|
|
//redis缓存处理
|
|
|
- b.Count(in.NewUserId, in.UserType, in.EntUserId, true)
|
|
|
+ //b.Count(in.NewUserId, in.UserType, in.EntUserId, true)
|
|
|
}
|
|
|
}()
|
|
|
return data
|
|
@@ -799,7 +866,6 @@ func (b MessaggeService) UpdateReadById(in *messagecenter.ReadStateReq) bool {
|
|
|
// WithdrawMessage 撤回消息
|
|
|
func (b MessaggeService) WithdrawMessage(in *messagecenter.ReadWithdrawReq) bool {
|
|
|
messageId := encrypt.SE.Decode4Hex(in.MessageId)
|
|
|
- newUserId, entUserId := NewEndId(quitl.Int64All(messageId), in.UserType)
|
|
|
msg := IC.BaseMysql.FindOne(util.SOCIALIZE_MESSAGE, map[string]interface{}{"id": messageId}, "create_time", "")
|
|
|
if msg == nil || len(*msg) <= 0 {
|
|
|
log.Println("查询消息id失败")
|
|
@@ -814,13 +880,42 @@ func (b MessaggeService) WithdrawMessage(in *messagecenter.ReadWithdrawReq) bool
|
|
|
m := IC.BaseMysql.Update(util.SOCIALIZE_MESSAGE_MAILBOX,
|
|
|
map[string]interface{}{"messag_id": messageId}, map[string]interface{}{"iswithdraw": 1, "withdraw_time": nowForm.Format(util.Date_Full_Layout)})
|
|
|
if m {
|
|
|
- //消息撤回 更新对方私信
|
|
|
- in.UserType = quitl.Int64All(quitl.If(in.UserType == 1, 2, 1))
|
|
|
- b.Count(newUserId, in.UserType, entUserId, true)
|
|
|
+ go SynchronousInfo(in.SenderId, in.RecipientId, in.ConversationType, quitl.Int64All(messageId), in.UserType, in.EntId, in.ChatGroupId)
|
|
|
}
|
|
|
return m
|
|
|
}
|
|
|
|
|
|
+// 撤回消息同步信息
|
|
|
+func SynchronousInfo(sender, recipient, conversationType, messageId, userType, entId, chatGroupId int64) {
|
|
|
+ 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 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 {
|
|
|
+ if userType == 2 { //发送人是用户
|
|
|
+ //接收人是会话标识 查询客服id
|
|
|
+ data := IC.BaseMysql.FindOne(util.SOCIALIZE_CHAT_SESSION, map[string]interface{}{"id": recipient}, "", "")
|
|
|
+ if data != nil && len(*data) > 0 {
|
|
|
+ IC.BaseMysql.SelectBySql(fmt.Sprintf("update %s set unread=CASE WHEN unread > 0 and user_id = %d and customer_service_id = %d and entId = %d THEN unread-1 ELSE 0 END;", util.Socialize_customer_service_user, sender, quitl.IntAll((*data)["customer_service_id"]), entId))
|
|
|
+ }
|
|
|
+ } else { //发送人是客服
|
|
|
+ IC.BaseMysql.SelectBySql(fmt.Sprintf("update %s set unread=CASE WHEN unread > 0 and user_id = %d and ent_id = %d THEN unread-1 ELSE 0 END;", util.Socialize_summary, recipient, entId))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ case 3: //一对群
|
|
|
+ data := IC.BaseMysql.Find(util.SOCIALIZE_MESSAGE, map[string]interface{}{"id": messageId, "chat_group_id": chatGroupId, "isread": 0}, "own_id", "", -1, -1)
|
|
|
+ if data != nil && len(*data) > 0 {
|
|
|
+ var ownIds []string
|
|
|
+ for _, v := range *data {
|
|
|
+ ownIds = append(ownIds, quitl.InterfaceToStr(v["own_id"]))
|
|
|
+ }
|
|
|
+ IC.BaseMysql.SelectBySql(fmt.Sprintf("update %s set unread=CASE WHEN unread > 0 and chat_group_id = %d and position_id in (%s) THEN unread-1 ELSE 0 END;", util.SOCIALIZE_CHAT_GROUP_PERSON, chatGroupId, strings.Join(ownIds, ",")))
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
// AppraiseMessage 消息评价
|
|
|
func (b MessaggeService) AppraiseMessage(in *messagecenter.AppraiseReq) error {
|
|
|
messageId := encrypt.SE.Decode4Hex(in.MessageId)
|
|
@@ -851,18 +946,148 @@ 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"])
|
|
|
+// 聊天
|
|
|
+// 包含 1v1 ,群聊,群发
|
|
|
+/*
|
|
|
+入参 appid,title,content,sendid,link,item,messagetype,receiverIds,groupIds
|
|
|
+*/
|
|
|
+func (this *MessaggeService) Chat(in *messagecenter.MessageSaveReq) (fool bool, errorMsg string, content string, messageId, nowInt int64) {
|
|
|
+ now := time.Now()
|
|
|
+ nowTime := now.Format(date.Date_Full_Layout)
|
|
|
+ messageId = int64(0)
|
|
|
+ fool = IC.BaseMysql.ExecTx("消息存储", func(tx *sql.Tx) bool {
|
|
|
+ isGroup := len(in.GroupIds) > 0
|
|
|
+ isOneToOne := len(in.ReceiverIds) > 0
|
|
|
+ createperson := strconv.Itoa(int(in.SendId))
|
|
|
+ messageId = MessageAdd(tx, in.Appid, in.Title, in.Content, createperson, in.Link, in.Item, in.MessageType)
|
|
|
+ //是否客服介入
|
|
|
+ isCustomerServiceAccess := 0
|
|
|
+
|
|
|
+ //群聊
|
|
|
+ if isGroup {
|
|
|
+ fieids := []string{"appid", "messag_id", "type", "send_user_id", "send_user_type", "receive_user_id", "receive_user_type", "own_type", "own_id", "create_time", "chat_group_id", "isread"}
|
|
|
+ for _, v := range in.GroupIds {
|
|
|
+ args := []interface{}{}
|
|
|
+ summaryArgs := []interface{}{}
|
|
|
+ args = append(args, in.Appid, messageId, in.Type, in.SendId, 2, in.SendId, 2, 2, in.SendId, nowTime, v, 1)
|
|
|
+ groupUser := GetUserByGroupId(tx, v, in.SendId)
|
|
|
+ for _, vv := range groupUser {
|
|
|
+ log.Println("获取到群组下员工:", vv)
|
|
|
+ args = append(args, in.Appid, messageId, in.Type, in.SendId, 2, vv, 2, 2, vv, nowTime, v, 0)
|
|
|
+ }
|
|
|
+ summaryArgs = append(summaryArgs, in.SendId, nil, nil, v, messageId, nil, isCustomerServiceAccess, nowTime)
|
|
|
+ MessageMailBoxAdd(tx, fieids, args)
|
|
|
+ //最后一次聊天
|
|
|
+ SocializeSummaryAdd(tx, summaryArgs)
|
|
|
+ //更新未读消息
|
|
|
+ GroupUserUnReadUpdate(tx, groupUser)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //1v1
|
|
|
+ if isOneToOne {
|
|
|
+ fieids := []string{"appid", "messag_id", "type", "send_user_id", "send_user_type", "receive_user_id", "receive_user_type", "own_type", "own_id", "create_time", "isread"}
|
|
|
+ args := []interface{}{}
|
|
|
+ summaryArgs := []interface{}{}
|
|
|
+ args = append(args, in.Appid, messageId, in.Type, in.SendId, 2, in.SendId, 2, 2, in.SendId, nowTime, 1)
|
|
|
+ for _, v := range in.ReceiverIds {
|
|
|
+ args = append(args, in.Appid, messageId, in.Type, in.SendId, 2, v, 2, 2, v, nowTime, 0)
|
|
|
+ //发送方,未读消息应该是0
|
|
|
+ summaryArgs = append(summaryArgs, in.SendId, v, nil, nil, messageId, 0, isCustomerServiceAccess, nowTime)
|
|
|
+ //接收方,未读消息应该是1
|
|
|
+ summaryArgs = append(summaryArgs, v, in.SendId, nil, nil, messageId, 1, isCustomerServiceAccess, nowTime)
|
|
|
+ }
|
|
|
+ MessageMailBoxAdd(tx, fieids, args)
|
|
|
+ //最后一次聊天
|
|
|
+ SocializeSummaryAdd(tx, summaryArgs)
|
|
|
+ }
|
|
|
+ return true
|
|
|
+ })
|
|
|
+
|
|
|
+ return fool, "", in.Content, messageId, now.Unix()
|
|
|
+}
|
|
|
+
|
|
|
+// 消息存储
|
|
|
+func MessageAdd(tx *sql.Tx, appid, title, content, createperson, link string, item, messageType int64) int64 {
|
|
|
+ nowTime := time.Now()
|
|
|
+ message := map[string]interface{}{
|
|
|
+ "appid": appid,
|
|
|
+ "title": title,
|
|
|
+ "content": content,
|
|
|
+ "item": item,
|
|
|
+ "type": messageType,
|
|
|
+ "link": link,
|
|
|
+ "create_time": nowTime.Format(date.Date_Full_Layout),
|
|
|
+ "create_person": createperson, //系统消息时,创建人是群聊id或接收人id
|
|
|
+ }
|
|
|
+ return IC.BaseMysql.InsertByTx(tx, util.SOCIALIZE_MESSAGE, message)
|
|
|
+}
|
|
|
+
|
|
|
+// 消息信息箱存储
|
|
|
+// types 2:点对点 3:群消息
|
|
|
+func MessageMailBoxAdd(tx *sql.Tx, fieids []string, args []interface{}) (int64, int64) {
|
|
|
+ length, lastId := IC.BaseMysql.InsertBatchByTx(tx, util.SOCIALIZE_MESSAGE_MAILBOX, fieids, args)
|
|
|
+ log.Println("MessageMailBoxAdd length:", length, "MessageMailBoxAdd lastId:", lastId)
|
|
|
+ return length, lastId
|
|
|
+}
|
|
|
+
|
|
|
+// 获取除发送人以外的群成员
|
|
|
+func GetUserByGroupId(tx *sql.Tx, groupId, sendId int64) []int64 {
|
|
|
+ arr := []int64{}
|
|
|
+ data := IC.BaseMysql.SelectBySqlByTx(tx, "select position_id from "+util.SOCIALIZE_CHAT_GROUP_PERSON+" where status = 1 and chat_group_id = ? AND position_id != ? ", groupId, sendId)
|
|
|
+ log.Println("~~~~", data)
|
|
|
+ if data == nil || len(*data) <= 0 {
|
|
|
+ return arr
|
|
|
+ }
|
|
|
+ for _, v := range *data {
|
|
|
+ position_id := quitl.Int64All(v["position_id"])
|
|
|
+ if position_id == 0 {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ arr = append(arr, position_id)
|
|
|
+ }
|
|
|
+ return arr
|
|
|
+}
|
|
|
+
|
|
|
+// 最后一次聊天存储
|
|
|
+func SocializeSummaryAdd(tx *sql.Tx, args []interface{}) (int64, int64) {
|
|
|
+ fieids := []string{"my_position_id", "your_position_id", "ent_id", "chat_group_id", "message_id", "unread", "customer_service_access", "timestamp"}
|
|
|
+
|
|
|
+ length, lastId := IC.BaseMysql.InsertBatchByTx(tx, util.SOCIALIZE_SUMMARY, fieids, args)
|
|
|
+
|
|
|
+ log.Println("SocializeSummaryAdd length:", length, "SocializeSummaryAdd lastId:", lastId)
|
|
|
+
|
|
|
+ return length, lastId
|
|
|
+}
|
|
|
+
|
|
|
+// 群组人员未读消息更新
|
|
|
+func GroupUserUnReadUpdate(tx *sql.Tx, ids []int64) bool {
|
|
|
+ whs := []string{}
|
|
|
+ for i := 0; i < len(ids); i++ {
|
|
|
+ whs = append(whs, "?")
|
|
|
+ }
|
|
|
+ wh := strings.Join(whs, ",")
|
|
|
+ interfaces := gconv.Interfaces(ids)
|
|
|
+ count := IC.BaseMysql.UpdateOrDeleteBySql(`UPDATE `+util.SOCIALIZE_CHAT_GROUP_PERSON+` SET unread = unread + 1 WHERE id in (`+wh+`)`, interfaces...)
|
|
|
+ if count > 0 {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ return true
|
|
|
+}
|
|
|
+
|
|
|
+// GetUserAllPosition 用户下所有职位id
|
|
|
+func GetUserAllPosition(positionId int64) (positionStr string) {
|
|
|
+ //查询用户所有的职位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, positionId)
|
|
|
+ positionArr := IC.BaseMysql.SelectBySql(sqlPosition)
|
|
|
+ for k, val := range *positionArr {
|
|
|
+ if k < len(*positionArr)-1 {
|
|
|
+ positionStr += quitl.ObjToString(val["id"]) + ","
|
|
|
} else {
|
|
|
- //用户撤回消息 获取客服id与用户id
|
|
|
- newUserId = quitl.Int64All((*data)["send_user_id"])
|
|
|
- entUserId = quitl.Int64All((*data)["receive_user_id"])
|
|
|
+ positionStr += quitl.ObjToString(val["id"])
|
|
|
}
|
|
|
}
|
|
|
- return
|
|
|
+ return positionStr
|
|
|
}
|