|
@@ -2,19 +2,23 @@ package service
|
|
|
|
|
|
import (
|
|
import (
|
|
quitl "app.yhyue.com/moapp/jybase/common"
|
|
quitl "app.yhyue.com/moapp/jybase/common"
|
|
|
|
+ "app.yhyue.com/moapp/jybase/encrypt"
|
|
util "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/entity"
|
|
util "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/entity"
|
|
IC "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/rpc/messagecenter/init"
|
|
IC "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/rpc/messagecenter/init"
|
|
"bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/rpc/messagecenter/messagecenter"
|
|
"bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/rpc/messagecenter/messagecenter"
|
|
"database/sql"
|
|
"database/sql"
|
|
"fmt"
|
|
"fmt"
|
|
"log"
|
|
"log"
|
|
|
|
+ "strings"
|
|
|
|
+ "sync"
|
|
"time"
|
|
"time"
|
|
)
|
|
)
|
|
|
|
|
|
type MessaggeService struct{}
|
|
type MessaggeService struct{}
|
|
|
|
|
|
-//未读消息查询
|
|
|
|
|
|
+// 未读消息查询
|
|
func (b MessaggeService) Count(newUserId, userType, entUserId int64, isClean bool) (count int, last map[string]interface{}, err error) {
|
|
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)
|
|
v := make([]interface{}, 0)
|
|
sqlStr := ""
|
|
sqlStr := ""
|
|
if userType == 1 {
|
|
if userType == 1 {
|
|
@@ -29,7 +33,8 @@ func (b MessaggeService) Count(newUserId, userType, entUserId int64, isClean boo
|
|
sqlStr = fmt.Sprintf("select count(b.id) from %s a "+
|
|
sqlStr = fmt.Sprintf("select count(b.id) from %s a "+
|
|
"LEFT JOIN %s b ON a.id=b.own_id "+
|
|
"LEFT JOIN %s b ON a.id=b.own_id "+
|
|
"where b.type=5 "+
|
|
"where b.type=5 "+
|
|
- "AND a.customer_service_id=%d "+
|
|
|
|
|
|
+ "AND a.customer_service_id=%d "+
|
|
|
|
+ "AND b.iswithdraw = 0 "+
|
|
"AND b.isread=0 "+
|
|
"AND b.isread=0 "+
|
|
"AND own_type = 1 "+
|
|
"AND own_type = 1 "+
|
|
"order by create_time", util.SOCIALIZE_CHAT_SESSION, util.SOCIALIZE_MESSAGE_MAILBOX, entUserId)
|
|
"order by create_time", util.SOCIALIZE_CHAT_SESSION, util.SOCIALIZE_MESSAGE_MAILBOX, entUserId)
|
|
@@ -43,7 +48,8 @@ func (b MessaggeService) Count(newUserId, userType, entUserId int64, isClean boo
|
|
}
|
|
}
|
|
sqlStr = fmt.Sprintf("select count(b.id) from %s b "+
|
|
sqlStr = fmt.Sprintf("select count(b.id) from %s b "+
|
|
"where b.send_user_id != %d "+
|
|
"where b.send_user_id != %d "+
|
|
- "AND b.own_id=%d "+
|
|
|
|
|
|
+ "AND b.own_id=%d "+
|
|
|
|
+ "AND b.iswithdraw = 0 "+
|
|
"AND b.isread=0 "+
|
|
"AND b.isread=0 "+
|
|
"AND own_type = 2 "+
|
|
"AND own_type = 2 "+
|
|
"order by create_time", util.SOCIALIZE_MESSAGE_MAILBOX, newUserId, newUserId)
|
|
"order by create_time", util.SOCIALIZE_MESSAGE_MAILBOX, newUserId, newUserId)
|
|
@@ -57,7 +63,8 @@ func (b MessaggeService) Count(newUserId, userType, entUserId int64, isClean boo
|
|
sqlStr = fmt.Sprintf("SELECT c.* FROM %s b "+
|
|
sqlStr = fmt.Sprintf("SELECT c.* FROM %s b "+
|
|
"LEFT join %s c on b.messag_id=c.id "+
|
|
"LEFT join %s c on b.messag_id=c.id "+
|
|
"WHERE b.send_user_id != %d "+
|
|
"WHERE b.send_user_id != %d "+
|
|
- "AND b.own_id = %d "+
|
|
|
|
|
|
+ "AND b.own_id = %d "+
|
|
|
|
+ "AND b.iswithdraw = 0 "+
|
|
"AND b.isread=0 "+
|
|
"AND b.isread=0 "+
|
|
"AND own_type = 2 "+
|
|
"AND own_type = 2 "+
|
|
"ORDER BY create_time DESC "+
|
|
"ORDER BY create_time DESC "+
|
|
@@ -81,13 +88,15 @@ func (b MessaggeService) Count(newUserId, userType, entUserId int64, isClean boo
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
-//用户列表查询
|
|
|
|
-func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string]interface{}, err error) {
|
|
|
|
|
|
+// 用户列表查询
|
|
|
|
+func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string]interface{}, count int64, err error) {
|
|
sqlStr := ""
|
|
sqlStr := ""
|
|
|
|
+ tm := time.Now()
|
|
if in.UserType == 2 {
|
|
if in.UserType == 2 {
|
|
//用户最后一次信息查询
|
|
//用户最后一次信息查询
|
|
userSql := fmt.Sprintf("SELECT MAX( c.id ) as messageId FROM socialize_message_mailbox c "+
|
|
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.type = 2 "+
|
|
"AND c.own_type = 2 "+
|
|
"AND c.own_type = 2 "+
|
|
"GROUP BY ( CASE WHEN c.send_user_id > c.receive_user_id "+
|
|
"GROUP BY ( CASE WHEN c.send_user_id > c.receive_user_id "+
|
|
@@ -101,6 +110,7 @@ func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string
|
|
customerSql := fmt.Sprintf("SELECT MAX( c.id ) as messageId FROM %s c "+
|
|
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 ) "+
|
|
"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 "+
|
|
"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.type = 4 OR c.type = 5 or c.type=6 or c.type=7 ) "+
|
|
"AND c.own_type = 2 "+
|
|
"AND c.own_type = 2 "+
|
|
"AND d.user_id=c.own_id "+
|
|
"AND d.user_id=c.own_id "+
|
|
@@ -109,14 +119,14 @@ func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string
|
|
customerMessageId := util.Inhandle(data)
|
|
customerMessageId := util.Inhandle(data)
|
|
//用户的列表
|
|
//用户的列表
|
|
sqlStr = fmt.Sprintf("SELECT "+
|
|
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, "+
|
|
"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 "+
|
|
"( SELECT count( h.id ) FROM %s h "+
|
|
"WHERE h.type = 2 "+
|
|
"WHERE h.type = 2 "+
|
|
"AND h.own_id = %d "+
|
|
"AND h.own_id = %d "+
|
|
"AND h.own_type = 2 "+
|
|
"AND h.own_type = 2 "+
|
|
"AND h.send_user_id=b.id "+
|
|
"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 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 "+
|
|
"LEFT JOIN %s e ON e.id = a.messag_id "+
|
|
"WHERE a.id IN ( %s ) AND b.id != %d "+
|
|
"WHERE a.id IN ( %s ) AND b.id != %d "+
|
|
@@ -145,75 +155,167 @@ func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string
|
|
util.SOCIALIZE_TENANT_ROBOT,
|
|
util.SOCIALIZE_TENANT_ROBOT,
|
|
customerMessageId)
|
|
customerMessageId)
|
|
} else {
|
|
} else {
|
|
- phoneSql := ""
|
|
|
|
- if in.Phone != "" {
|
|
|
|
- phoneSql = "AND b.phone like '%" + in.Phone + "%'"
|
|
|
|
|
|
+ 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 "
|
|
}
|
|
}
|
|
- startTimeSql := ""
|
|
|
|
if in.StartTime != "" {
|
|
if in.StartTime != "" {
|
|
- startTimeSql = "AND DATE_FORMAT(c.create_time,'%Y-%m-%d') >= '" + in.StartTime + "' "
|
|
|
|
|
|
+ idSql += " AND DATE_FORMAT(a.update_time,'%Y-%m-%d') >= '" + in.StartTime + "' "
|
|
}
|
|
}
|
|
- endTimeSql := ""
|
|
|
|
if in.EndTime != "" {
|
|
if in.EndTime != "" {
|
|
- endTimeSql = "AND DATE_FORMAT(c.create_time,'%Y-%m-%d') <= '" + in.EndTime + "' "
|
|
|
|
- }
|
|
|
|
- //先获取每个用户最后聊天记录
|
|
|
|
- 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 "+
|
|
|
|
- "WHERE c.own_type = 1 "+
|
|
|
|
- "AND d.customer_service_id = %d "+
|
|
|
|
- "AND ( c.type = 4 OR c.type = 5 or c.type=6 or c.type=7 ) "+
|
|
|
|
- "AND d.customer_service_id !=0 %s %s "+
|
|
|
|
- "GROUP BY ( CASE WHEN c.send_user_type =2 THEN CONCAT( c.send_user_id ) WHEN c.send_user_type =1 THEN CONCAT( c.receive_user_id ) END ) ",
|
|
|
|
- util.SOCIALIZE_MESSAGE_MAILBOX, util.SOCIALIZE_CHAT_SESSION,
|
|
|
|
- in.EntUserId, startTimeSql, endTimeSql)
|
|
|
|
- data = IC.BaseMysql.SelectBySql(userSql)
|
|
|
|
- if data != nil {
|
|
|
|
- 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 )"+
|
|
|
|
- " 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 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 "+
|
|
|
|
- "LEFT JOIN %s e ON e.id = a.messag_id "+
|
|
|
|
- "LEFT JOIN %s f ON a.own_type=1 AND a.own_id=f.id "+
|
|
|
|
- "WHERE a.id IN ( %s) %s ORDER BY a.create_time DESC",
|
|
|
|
- util.SOCIALIZE_MESSAGE_MAILBOX, util.SOCIALIZE_CHAT_SESSION,
|
|
|
|
- in.EntUserId, util.SOCIALIZE_MESSAGE_MAILBOX, util.BASE_USER, util.SOCIALIZE_MESSAGE, util.SOCIALIZE_CHAT_SESSION, customerMessageId, phoneSql)
|
|
|
|
|
|
+ idSql += "AND DATE_FORMAT(a.update_time,'%Y-%m-%d') <= '" + in.EndTime + "' "
|
|
|
|
+ }
|
|
|
|
+ if in.Phone != "" {
|
|
|
|
+ idSql += " 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, ","))
|
|
|
|
+ }
|
|
|
|
+ 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)
|
|
}
|
|
}
|
|
|
|
+ dataSize := []map[string]interface{}{}
|
|
if sqlStr != "" {
|
|
if sqlStr != "" {
|
|
- log.Println(sqlStr)
|
|
|
|
|
|
+ log.Println("查询列表sql:", sqlStr)
|
|
data = IC.BaseMysql.SelectBySql(sqlStr)
|
|
data = IC.BaseMysql.SelectBySql(sqlStr)
|
|
|
|
+ if data != nil && len(*data) > 0 {
|
|
|
|
+ count = quitl.Int64All(len(*data))
|
|
|
|
+ log.Println("查询列表耗时2:", time.Since(tm), count)
|
|
|
|
+ if in.UserType != 2 {
|
|
|
|
+ if in.Page*in.Size >= count {
|
|
|
|
+ dataSize = (*data)[(in.Page-1)*in.Size:]
|
|
|
|
+ } else {
|
|
|
|
+ dataSize = (*data)[(in.Page-1)*in.Size : in.Page*in.Size]
|
|
|
|
+ }
|
|
|
|
+ return &dataSize, count, err
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
-//消息保存
|
|
|
|
|
|
+// 客服会话列表
|
|
|
|
+func (b MessaggeService) ConversationList(in *messagecenter.ConversationReq) (data *[]map[string]interface{}, count int64, err error) {
|
|
|
|
+ sqlStr := ""
|
|
|
|
+ tm := time.Now()
|
|
|
|
+ if in.UserType == 1 && in.FiltrationId != "" {
|
|
|
|
+ var ids []string
|
|
|
|
+ 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)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if sqlStr != "" {
|
|
|
|
+ log.Println("查询列表sql:", sqlStr)
|
|
|
|
+ data = IC.BaseMysql.SelectBySql(sqlStr)
|
|
|
|
+ log.Println("查询耗时2:", time.Since(tm), count)
|
|
|
|
+ }
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// 消息保存
|
|
func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool, errorMsg string, content string, messageId, nowInt int64) {
|
|
func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool, errorMsg string, content string, messageId, nowInt int64) {
|
|
//先插入信息表
|
|
//先插入信息表
|
|
//判断会话标识是否属于本人
|
|
//判断会话标识是否属于本人
|
|
|
|
+ var customer_service_id, userid, entid, message_id int64
|
|
nowForm := time.Now().Local()
|
|
nowForm := time.Now().Local()
|
|
|
|
+ create_time := nowForm.Format(util.Date_Full_Layout)
|
|
if in.ItemType != 2 {
|
|
if in.ItemType != 2 {
|
|
userId := int64(0)
|
|
userId := int64(0)
|
|
sessionId := int64(0)
|
|
sessionId := int64(0)
|
|
switch in.ItemType {
|
|
switch in.ItemType {
|
|
- case 4, 5:
|
|
|
|
|
|
+ case 4, 5, 8:
|
|
if in.OwnType == 1 {
|
|
if in.OwnType == 1 {
|
|
sessionId = in.ReceiveId
|
|
sessionId = in.ReceiveId
|
|
userId = in.NewUserId
|
|
userId = in.NewUserId
|
|
} else {
|
|
} else {
|
|
sessionId = in.SendId
|
|
sessionId = in.SendId
|
|
userId = in.ReceiveId
|
|
userId = in.ReceiveId
|
|
- if in.ItemType == 4 {
|
|
|
|
|
|
+ if in.ItemType == 4 || in.ItemType == 8 {
|
|
userId = in.NewUserId
|
|
userId = in.NewUserId
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -232,7 +334,7 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
|
|
break
|
|
break
|
|
}
|
|
}
|
|
//查找会话信息
|
|
//查找会话信息
|
|
- chatJson := IC.BaseMysql.FindOne(util.SOCIALIZE_CHAT_SESSION, map[string]interface{}{"id": sessionId}, "user_id", "")
|
|
|
|
|
|
+ chatJson := IC.BaseMysql.FindOne(util.SOCIALIZE_CHAT_SESSION, map[string]interface{}{"id": sessionId}, "user_id,ent_id,customer_service_id", "")
|
|
if chatJson == nil {
|
|
if chatJson == nil {
|
|
return false, "会话标识不存在", "", 0, nowForm.Unix()
|
|
return false, "会话标识不存在", "", 0, nowForm.Unix()
|
|
} else {
|
|
} else {
|
|
@@ -240,10 +342,12 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
|
|
return false, "会话标识不属于此用户", "", 0, nowForm.Unix()
|
|
return false, "会话标识不属于此用户", "", 0, nowForm.Unix()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ customer_service_id = quitl.Int64All((*chatJson)["customer_service_id"])
|
|
|
|
+ entid = quitl.Int64All((*chatJson)["ent_id"])
|
|
|
|
+ userid = userId
|
|
}
|
|
}
|
|
fool = IC.BaseMysql.ExecTx("聊天信息保存", func(tx *sql.Tx) bool {
|
|
fool = IC.BaseMysql.ExecTx("聊天信息保存", func(tx *sql.Tx) bool {
|
|
//先插入信息表
|
|
//先插入信息表
|
|
- create_time := nowForm.Format(util.Date_Full_Layout)
|
|
|
|
userType := int64(1)
|
|
userType := int64(1)
|
|
userId := int64(0)
|
|
userId := int64(0)
|
|
message := map[string]interface{}{
|
|
message := map[string]interface{}{
|
|
@@ -264,7 +368,7 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
|
|
}
|
|
}
|
|
ok := IC.BaseMysql.InsertByTx(tx, util.SOCIALIZE_MESSAGE, message)
|
|
ok := IC.BaseMysql.InsertByTx(tx, util.SOCIALIZE_MESSAGE, message)
|
|
receiveOk := int64(0)
|
|
receiveOk := int64(0)
|
|
- messageId = ok
|
|
|
|
|
|
+ messageId, message_id = ok, ok
|
|
data["id"] = ok
|
|
data["id"] = ok
|
|
//在插入邮箱表socialize_message_mailbox
|
|
//在插入邮箱表socialize_message_mailbox
|
|
messageMailBox := map[string]interface{}{
|
|
messageMailBox := map[string]interface{}{
|
|
@@ -319,7 +423,7 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
|
|
receiveOk = IC.BaseMysql.InsertByTx(tx, util.SOCIALIZE_MESSAGE_MAILBOX, messageMailBox)
|
|
receiveOk = IC.BaseMysql.InsertByTx(tx, util.SOCIALIZE_MESSAGE_MAILBOX, messageMailBox)
|
|
return ok > 1 && receiveOk > 1
|
|
return ok > 1 && receiveOk > 1
|
|
}
|
|
}
|
|
- if in.ItemType == 4 || in.ItemType == 5 {
|
|
|
|
|
|
+ if in.ItemType == 4 || in.ItemType == 8 || in.ItemType == 5 {
|
|
//客服或者机器人聊天
|
|
//客服或者机器人聊天
|
|
if in.OwnType == 1 {
|
|
if in.OwnType == 1 {
|
|
// (用户发送)客服接受
|
|
// (用户发送)客服接受
|
|
@@ -340,7 +444,7 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
|
|
messageMailBox["send_user_id"] = in.SendId
|
|
messageMailBox["send_user_id"] = in.SendId
|
|
messageMailBox["receive_user_id"] = in.ReceiveId
|
|
messageMailBox["receive_user_id"] = in.ReceiveId
|
|
userId = in.ReceiveId
|
|
userId = in.ReceiveId
|
|
- if in.ItemType == 4 {
|
|
|
|
|
|
+ if in.ItemType == 4 || in.ItemType == 8 {
|
|
messageMailBox["receive_user_id"] = in.NewUserId
|
|
messageMailBox["receive_user_id"] = in.NewUserId
|
|
userId = in.NewUserId
|
|
userId = in.NewUserId
|
|
messageMailBox["own_id"] = in.NewUserId
|
|
messageMailBox["own_id"] = in.NewUserId
|
|
@@ -372,7 +476,7 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
|
|
"receive_isdel": 0,
|
|
"receive_isdel": 0,
|
|
"iswithdraw": 0,
|
|
"iswithdraw": 0,
|
|
}
|
|
}
|
|
- if in.ItemType == 4 || in.ItemType == 5 {
|
|
|
|
|
|
+ if in.ItemType == 4 || in.ItemType == 8 || in.ItemType == 5 {
|
|
//客服或者机器人聊天
|
|
//客服或者机器人聊天
|
|
if in.OwnType == 1 {
|
|
if in.OwnType == 1 {
|
|
//用户发送(用户接受)
|
|
//用户发送(用户接受)
|
|
@@ -391,7 +495,7 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
|
|
messageMailBox["own_id"] = in.SendId
|
|
messageMailBox["own_id"] = in.SendId
|
|
messageMailBox["send_user_id"] = in.SendId
|
|
messageMailBox["send_user_id"] = in.SendId
|
|
messageMailBox["receive_user_id"] = in.ReceiveId
|
|
messageMailBox["receive_user_id"] = in.ReceiveId
|
|
- if in.ItemType == 4 {
|
|
|
|
|
|
+ if in.ItemType == 4 || in.ItemType == 8 {
|
|
messageMailBox["receive_user_id"] = in.NewUserId
|
|
messageMailBox["receive_user_id"] = in.NewUserId
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -414,10 +518,47 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
|
|
}
|
|
}
|
|
return ok > 1 && receiveOk > 1
|
|
return ok > 1 && receiveOk > 1
|
|
})
|
|
})
|
|
|
|
+ if fool && in.ItemType != 2 && in.ItemType != 3 {
|
|
|
|
+ go UserSynchronousList(customer_service_id, userid, entid, message_id, create_time)
|
|
|
|
+ }
|
|
return fool, "", in.Content, messageId, nowForm.Unix()
|
|
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)
|
|
|
|
+ rwLock.Lock()
|
|
|
|
+ defer rwLock.Unlock()
|
|
|
|
+ if IC.BaseMysql.Count(util.User_message_list, map[string]interface{}{"user_id": userId, "ent_id": entId}) > 0 {
|
|
|
|
+ upData := map[string]interface{}{
|
|
|
|
+ "message_id": messageId,
|
|
|
|
+ "update_time": createTime,
|
|
|
|
+ }
|
|
|
|
+ //判断是否机器人聊天
|
|
|
|
+ if customerServiceId > 0 && IC.BaseMysql.Count(util.User_message_list, map[string]interface{}{"user_id": userId, "ent_id": entId, "customer_service_id": 0}) > 0 {
|
|
|
|
+ //将机器人列表更新成用户
|
|
|
|
+ upData["customer_service_id"] = customerServiceId
|
|
|
|
+ //转人工 机器人聊天类型修改
|
|
|
|
+ upData["type"] = 1
|
|
|
|
+ }
|
|
|
|
+ //已于人工客服联系过 只同步最后消息
|
|
|
|
+ IC.BaseMysql.Update(util.User_message_list, map[string]interface{}{"user_id": userId, "ent_id": entId}, upData)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ //不存在消息列表 创建
|
|
|
|
+ IC.BaseMysql.Insert(util.User_message_list, map[string]interface{}{
|
|
|
|
+ "ent_id": entId,
|
|
|
|
+ "user_id": userId,
|
|
|
|
+ "message_id": messageId,
|
|
|
|
+ "update_time": createTime,
|
|
|
|
+ "customer_service_id": customerServiceId,
|
|
|
|
+ "type": quitl.If(customerServiceId == 0, 0, 1),
|
|
|
|
+ })
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// 历史信息查询
|
|
func (b MessaggeService) FindMessage(in *messagecenter.MessageReq) *[]map[string]interface{} {
|
|
func (b MessaggeService) FindMessage(in *messagecenter.MessageReq) *[]map[string]interface{} {
|
|
sqlStr := ""
|
|
sqlStr := ""
|
|
lastStr := ""
|
|
lastStr := ""
|
|
@@ -435,10 +576,10 @@ func (b MessaggeService) FindMessage(in *messagecenter.MessageReq) *[]map[string
|
|
"LEFT JOIN %s b on a.messag_id=b.id "+
|
|
"LEFT JOIN %s b on a.messag_id=b.id "+
|
|
"LEFT JOIN %s c on c.id=a.send_user_id "+
|
|
"LEFT JOIN %s c on c.id=a.send_user_id "+
|
|
"LEFT JOIN %s d on d.id=a.receive_user_id "+
|
|
"LEFT JOIN %s d on d.id=a.receive_user_id "+
|
|
- "where a.own_id= %d "+
|
|
|
|
|
|
+ "where a.own_id= %d and a.iswithdraw = 0"+
|
|
"AND ((a.send_user_id= %d AND a.receive_user_id= %d) or (a.send_user_id= %d AND a.receive_user_id= %d)) "+
|
|
"AND ((a.send_user_id= %d AND a.receive_user_id= %d) or (a.send_user_id= %d AND a.receive_user_id= %d)) "+
|
|
"AND a.type=2 %s "+
|
|
"AND a.type=2 %s "+
|
|
- "ORDER BY a.create_time desc ,a.id asc "+
|
|
|
|
|
|
+ "ORDER BY a.create_time desc,a.id asc "+
|
|
"limit 0 , %d ",
|
|
"limit 0 , %d ",
|
|
util.SOCIALIZE_MESSAGE_MAILBOX, util.SOCIALIZE_MESSAGE, util.BASE_USER, util.BASE_USER,
|
|
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)
|
|
in.NewUserId, in.NewUserId, in.SendId, in.SendId, in.NewUserId, lastStr, in.PageSize)
|
|
@@ -450,29 +591,30 @@ func (b MessaggeService) FindMessage(in *messagecenter.MessageReq) *[]map[string
|
|
"FROM %s a "+
|
|
"FROM %s a "+
|
|
"LEFT JOIN %s b ON a.messag_id = b.id "+
|
|
"LEFT JOIN %s b ON a.messag_id = b.id "+
|
|
"LEFT JOIN %s c ON a.own_type = 1 AND a.own_id=c.id "+
|
|
"LEFT JOIN %s c ON a.own_type = 1 AND a.own_id=c.id "+
|
|
- "WHERE a.own_type = 1 "+
|
|
|
|
- "AND (a.type = 5 or a.type=4 or a.type=6 or a.type=7) "+
|
|
|
|
|
|
+ "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.ent_id = %d "+
|
|
"AND c.user_id = %d %s "+
|
|
"AND c.user_id = %d %s "+
|
|
- "ORDER BY a.create_time desc ,a.id asc "+
|
|
|
|
|
|
+ "ORDER BY a.create_time desc ,a.id asc "+
|
|
"limit 0 , %d ",
|
|
"limit 0 , %d ",
|
|
util.SOCIALIZE_MESSAGE_MAILBOX, util.SOCIALIZE_MESSAGE, util.SOCIALIZE_CHAT_SESSION,
|
|
util.SOCIALIZE_MESSAGE_MAILBOX, util.SOCIALIZE_MESSAGE, util.SOCIALIZE_CHAT_SESSION,
|
|
in.EntId, in.SendId, lastStr, in.PageSize)
|
|
in.EntId, in.SendId, lastStr, in.PageSize)
|
|
} else {
|
|
} else {
|
|
//用户聊天记录查看
|
|
//用户聊天记录查看
|
|
- 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, d.nickname as robotName, d.headimage as robotImg, c.customer_service_name as setName "+
|
|
|
|
|
|
+ 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 "+
|
|
"FROM %s a "+
|
|
"FROM %s a "+
|
|
"LEFT JOIN %s b ON a.messag_id = b.id "+
|
|
"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 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 d on c.ent_id=d.ent_id "+
|
|
- "WHERE a.own_type = 2 "+
|
|
|
|
|
|
+ "LEFT JOIN %s e on e.messag_id=b.id "+
|
|
|
|
+ "WHERE a.own_type = 2 and a.iswithdraw = 0 "+
|
|
"AND a.own_id = %d "+
|
|
"AND a.own_id = %d "+
|
|
"AND c.ent_id = %d "+
|
|
"AND c.ent_id = %d "+
|
|
"AND c.user_id = %d "+
|
|
"AND c.user_id = %d "+
|
|
- "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 "+
|
|
|
|
|
|
+ "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 "+
|
|
"limit 0 , %d ",
|
|
"limit 0 , %d ",
|
|
- util.SOCIALIZE_MESSAGE_MAILBOX, util.SOCIALIZE_MESSAGE, util.SOCIALIZE_CHAT_SESSION, in.SendId, in.NewUserId, util.SOCIALIZE_TENANT_ROBOT,
|
|
|
|
|
|
+ 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)
|
|
in.NewUserId, in.SendId, in.NewUserId, lastStr, in.PageSize)
|
|
}
|
|
}
|
|
break
|
|
break
|
|
@@ -491,8 +633,8 @@ func (b MessaggeService) FindMessage(in *messagecenter.MessageReq) *[]map[string
|
|
}
|
|
}
|
|
go func() {
|
|
go func() {
|
|
updateMap := map[string]interface{}{}
|
|
updateMap := map[string]interface{}{}
|
|
- //if len(*data) > 0 && data != nil {
|
|
|
|
- if true {
|
|
|
|
|
|
+ if len(*data) > 0 && data != nil {
|
|
|
|
+ //if true {
|
|
//未读信息修改
|
|
//未读信息修改
|
|
switch in.MsgType {
|
|
switch in.MsgType {
|
|
case 2: //点对点聊天
|
|
case 2: //点对点聊天
|
|
@@ -508,14 +650,14 @@ func (b MessaggeService) FindMessage(in *messagecenter.MessageReq) *[]map[string
|
|
sqlStr := ""
|
|
sqlStr := ""
|
|
if in.UserType == 1 {
|
|
if in.UserType == 1 {
|
|
sqlStr = fmt.Sprintf("UPDATE %s a SET a.isread = 1, a.read_time = now( ) "+
|
|
sqlStr = fmt.Sprintf("UPDATE %s a SET a.isread = 1, a.read_time = now( ) "+
|
|
- "WHERE a.own_type = 1 "+
|
|
|
|
|
|
+ "WHERE a.own_type = 1 and a.iswithdraw = 0 "+
|
|
"AND a.type IN ( 4,5,6,7) "+
|
|
"AND a.type IN ( 4,5,6,7) "+
|
|
"AND a.isread = 0 "+
|
|
"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 )",
|
|
"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)
|
|
util.SOCIALIZE_MESSAGE_MAILBOX, util.SOCIALIZE_CHAT_SESSION, in.EntUserId, in.SendId)
|
|
} else {
|
|
} else {
|
|
sqlStr = fmt.Sprintf("UPDATE %s a SET a.isread = 1, a.read_time = now( ) "+
|
|
sqlStr = fmt.Sprintf("UPDATE %s a SET a.isread = 1, a.read_time = now( ) "+
|
|
- "WHERE a.own_type = 2 "+
|
|
|
|
|
|
+ "WHERE a.own_type = 2 and a.iswithdraw = 0 "+
|
|
"AND a.type IN ( 4,5,6,7 ) "+
|
|
"AND a.type IN ( 4,5,6,7 ) "+
|
|
"AND a.isread = 0 "+
|
|
"AND a.isread = 0 "+
|
|
"AND a.own_id =%d ", util.SOCIALIZE_MESSAGE_MAILBOX, in.NewUserId)
|
|
"AND a.own_id =%d ", util.SOCIALIZE_MESSAGE_MAILBOX, in.NewUserId)
|
|
@@ -530,7 +672,7 @@ func (b MessaggeService) FindMessage(in *messagecenter.MessageReq) *[]map[string
|
|
return data
|
|
return data
|
|
}
|
|
}
|
|
|
|
|
|
-//创建会话
|
|
|
|
|
|
+// 创建会话
|
|
func (b MessaggeService) CreateChatSession(in *messagecenter.ChatSessionReq) (fool bool, sessionId int64) {
|
|
func (b MessaggeService) CreateChatSession(in *messagecenter.ChatSessionReq) (fool bool, sessionId int64) {
|
|
fool = IC.BaseMysql.ExecTx("会话新建", func(tx *sql.Tx) bool {
|
|
fool = IC.BaseMysql.ExecTx("会话新建", func(tx *sql.Tx) bool {
|
|
customerserviceName := in.CustomerserviceName
|
|
customerserviceName := in.CustomerserviceName
|
|
@@ -566,7 +708,7 @@ func (b MessaggeService) CreateChatSession(in *messagecenter.ChatSessionReq) (fo
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
-//结束会话
|
|
|
|
|
|
+// 结束会话
|
|
func (b MessaggeService) CloseChatSession(in *messagecenter.CloseSessionReq) bool {
|
|
func (b MessaggeService) CloseChatSession(in *messagecenter.CloseSessionReq) bool {
|
|
fool := IC.BaseMysql.ExecTx("关闭会话", func(tx *sql.Tx) bool {
|
|
fool := IC.BaseMysql.ExecTx("关闭会话", func(tx *sql.Tx) bool {
|
|
updateMap := map[string]interface{}{
|
|
updateMap := map[string]interface{}{
|
|
@@ -578,10 +720,11 @@ func (b MessaggeService) CloseChatSession(in *messagecenter.CloseSessionReq) boo
|
|
return fool
|
|
return fool
|
|
}
|
|
}
|
|
|
|
|
|
-//创建会话并保存信息
|
|
|
|
|
|
+// 创建会话并保存信息
|
|
func (b *MessaggeService) SaveAutoReplyMsg(userType, entId, entUserId, userId int64, content, appId, nowFormat string) (bool, int64) {
|
|
func (b *MessaggeService) SaveAutoReplyMsg(userType, entId, entUserId, userId int64, content, appId, nowFormat string) (bool, int64) {
|
|
|
|
+ var customer_service_id, userid, entid, message_id int64
|
|
messageId := int64(0)
|
|
messageId := int64(0)
|
|
- return IC.BaseMysql.ExecTx("保存自动回复消息", func(tx *sql.Tx) bool {
|
|
|
|
|
|
+ ok1 := IC.BaseMysql.ExecTx("保存自动回复消息", func(tx *sql.Tx) bool {
|
|
entUserName := ""
|
|
entUserName := ""
|
|
if entUserId > 0 {
|
|
if entUserId > 0 {
|
|
list := IC.BaseMysql.SelectBySql(`select ? from socialize_tenant_seat where appid=? AND ent_id=? AND customer_service_id=?`, util.SOCIALIZE_CHAT_SESSION, appId, entId, entUserId)
|
|
list := IC.BaseMysql.SelectBySql(`select ? from socialize_tenant_seat where appid=? AND ent_id=? AND customer_service_id=?`, util.SOCIALIZE_CHAT_SESSION, appId, entId, entUserId)
|
|
@@ -601,11 +744,19 @@ func (b *MessaggeService) SaveAutoReplyMsg(userType, entId, entUserId, userId in
|
|
} else if userType == 2 {
|
|
} else if userType == 2 {
|
|
ok = IC.BaseMysql.InsertBySqlByTx(tx, `insert into socialize_message_mailbox (appid,messag_id,type,send_user_id,send_user_type,receive_user_id,receive_user_type,own_id,own_type,create_time) values (?,?,?,?,?,?,?,?,?,?)`, appId, messageId, 7, sessionId, 1, userId, 2, userId, 2, nowFormat) > 0
|
|
ok = IC.BaseMysql.InsertBySqlByTx(tx, `insert into socialize_message_mailbox (appid,messag_id,type,send_user_id,send_user_type,receive_user_id,receive_user_type,own_id,own_type,create_time) values (?,?,?,?,?,?,?,?,?,?)`, appId, messageId, 7, sessionId, 1, userId, 2, userId, 2, nowFormat) > 0
|
|
}
|
|
}
|
|
|
|
+ message_id = messageId
|
|
return messageId > 0 && sessionId > 0 && ok
|
|
return messageId > 0 && sessionId > 0 && ok
|
|
- }), messageId
|
|
|
|
|
|
+ })
|
|
|
|
+ if ok1 {
|
|
|
|
+ customer_service_id = entUserId
|
|
|
|
+ userid = userId
|
|
|
|
+ entid = entId
|
|
|
|
+ go UserSynchronousList(customer_service_id, userid, entid, message_id, nowFormat)
|
|
|
|
+ }
|
|
|
|
+ return ok1, messageId
|
|
}
|
|
}
|
|
|
|
|
|
-//修改未读状态
|
|
|
|
|
|
+// 修改未读状态
|
|
func (b MessaggeService) UpdateReadById(in *messagecenter.ReadStateReq) bool {
|
|
func (b MessaggeService) UpdateReadById(in *messagecenter.ReadStateReq) bool {
|
|
fool := IC.BaseMysql.ExecTx("已读状态修改", func(tx *sql.Tx) bool {
|
|
fool := IC.BaseMysql.ExecTx("已读状态修改", func(tx *sql.Tx) bool {
|
|
updateMap := map[string]interface{}{
|
|
updateMap := map[string]interface{}{
|
|
@@ -644,3 +795,74 @@ func (b MessaggeService) UpdateReadById(in *messagecenter.ReadStateReq) bool {
|
|
})
|
|
})
|
|
return fool
|
|
return fool
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+// 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失败")
|
|
|
|
+ return false
|
|
|
|
+ }
|
|
|
|
+ createTime, _ := time.Parse(util.Date_Full_Layout, quitl.InterfaceToStr((*msg)["create_time"]))
|
|
|
|
+ if createTime.Unix()+60*2 < time.Now().Unix() {
|
|
|
|
+ log.Println("消息已超过2分钟,撤回失败")
|
|
|
|
+ return false
|
|
|
|
+ }
|
|
|
|
+ nowForm := time.Now().Local()
|
|
|
|
+ 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)
|
|
|
|
+ }
|
|
|
|
+ return m
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// AppraiseMessage 消息评价
|
|
|
|
+func (b MessaggeService) AppraiseMessage(in *messagecenter.AppraiseReq) error {
|
|
|
|
+ messageId := encrypt.SE.Decode4Hex(in.MessageId)
|
|
|
|
+ //查询此条消息是否是当前用户的
|
|
|
|
+ if IC.BaseMysql.Count(util.SOCIALIZE_MESSAGE_MAILBOX, map[string]interface{}{
|
|
|
|
+ "messag_id": messageId,
|
|
|
|
+ "receive_user_id": in.NewUserId,
|
|
|
|
+ "receive_user_type": 2,
|
|
|
|
+ "type": 8,
|
|
|
|
+ }) == 0 {
|
|
|
|
+ return fmt.Errorf("未查询到信息")
|
|
|
|
+ }
|
|
|
|
+ if IC.BaseMysql.Count(util.SOCIALIZE_APPRAISE, map[string]interface{}{
|
|
|
|
+ "appid": in.Appid,
|
|
|
|
+ "messag_id": messageId,
|
|
|
|
+ }) > 0 {
|
|
|
|
+ return fmt.Errorf("请勿重复评价")
|
|
|
|
+ }
|
|
|
|
+ //插入评价
|
|
|
|
+ if IC.BaseMysql.Insert(util.SOCIALIZE_APPRAISE, map[string]interface{}{
|
|
|
|
+ "appid": in.Appid,
|
|
|
|
+ "messag_id": messageId,
|
|
|
|
+ "create_time": time.Now().Local().Format(util.Date_Full_Layout),
|
|
|
|
+ "appraise": in.Appraise,
|
|
|
|
+ }) > 0 {
|
|
|
|
+ return nil
|
|
|
|
+ }
|
|
|
|
+ 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
|
|
|
|
+}
|