|
@@ -81,7 +81,7 @@ func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string
|
|
|
"" as groupMember
|
|
|
FROM
|
|
|
socialize_summary a
|
|
|
- INNER JOIN base_position b ON ( a.my_position_id = %d %s AND a.your_position_id = b.id AND a.chat_group_id = 0 )
|
|
|
+ INNER JOIN base_position b ON ( a.my_position_id = %d %s 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 )
|
|
|
ORDER BY a.timestamp DESC LIMIT 0,500
|
|
@@ -124,9 +124,9 @@ func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string
|
|
|
b.groupMember
|
|
|
FROM
|
|
|
socialize_summary a
|
|
|
- INNER JOIN %s b ON ( a.my_position_id = %d AND a.chat_group_id > 0 AND a.chat_group_id = b.id)
|
|
|
+ INNER JOIN %s b ON ( a.my_position_id = %d AND a.chat_group_id = b.id)
|
|
|
LEFT JOIN socialize_message d ON ( a.message_id = d.id )
|
|
|
- ORDER BY c.timestamp DESC LIMIT 0,500
|
|
|
+ ORDER BY a.timestamp DESC LIMIT 0,500
|
|
|
) `, GroupNameSql, in.PositionId)
|
|
|
if oneSql != "" {
|
|
|
sqlArr = append(sqlArr, oneSql)
|
|
@@ -334,52 +334,50 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
|
|
|
var customer_service_id, userid, entid, message_id int64
|
|
|
nowForm := time.Now().Local()
|
|
|
create_time := nowForm.Format(util.Date_Full_Layout)
|
|
|
- if in.ItemType != 2 {
|
|
|
- userId := int64(0)
|
|
|
- sessionId := int64(0)
|
|
|
- switch in.ItemType {
|
|
|
- case 4, 5, 8:
|
|
|
- if in.OwnType == 1 {
|
|
|
- sessionId = in.ReceiveId
|
|
|
- userId = in.NewUserId
|
|
|
- } else {
|
|
|
- sessionId = in.SendId
|
|
|
- userId = in.ReceiveId
|
|
|
- if in.ItemType == 4 || in.ItemType == 8 {
|
|
|
- userId = in.NewUserId
|
|
|
- }
|
|
|
- }
|
|
|
- break
|
|
|
- case 6:
|
|
|
- if in.OwnType == 1 {
|
|
|
- sessionId = in.ReceiveId
|
|
|
- userId = in.NewUserId
|
|
|
- } else if in.OwnType == 2 {
|
|
|
- sessionId = in.SendId
|
|
|
- userId = in.ReceiveId
|
|
|
- } else {
|
|
|
- sessionId = in.ReceiveId
|
|
|
+ userId := int64(0)
|
|
|
+ sessionId := int64(0)
|
|
|
+ switch in.ItemType {
|
|
|
+ case 4, 5, 8:
|
|
|
+ if in.OwnType == 1 {
|
|
|
+ sessionId = in.ReceiveId
|
|
|
+ userId = in.NewUserId
|
|
|
+ } else {
|
|
|
+ sessionId = in.SendId
|
|
|
+ userId = in.ReceiveId
|
|
|
+ if in.ItemType == 4 || in.ItemType == 8 {
|
|
|
userId = in.NewUserId
|
|
|
}
|
|
|
- break
|
|
|
}
|
|
|
- //查找会话信息
|
|
|
- chatJson := IC.BaseMysql.FindOne(util.SOCIALIZE_CHAT_SESSION, map[string]interface{}{"id": sessionId}, "user_id,ent_id,customer_service_id", "")
|
|
|
- if chatJson == nil {
|
|
|
- return false, "会话标识不存在", "", 0, nowForm.Unix()
|
|
|
+ break
|
|
|
+ case 6:
|
|
|
+ if in.OwnType == 1 {
|
|
|
+ sessionId = in.ReceiveId
|
|
|
+ userId = in.NewUserId
|
|
|
+ } else if in.OwnType == 2 {
|
|
|
+ sessionId = in.SendId
|
|
|
+ userId = in.ReceiveId
|
|
|
} else {
|
|
|
- if userId != quitl.Int64All((*chatJson)["user_id"]) {
|
|
|
- return false, "会话标识不属于此用户", "", 0, nowForm.Unix()
|
|
|
- }
|
|
|
+ sessionId = in.ReceiveId
|
|
|
+ userId = in.NewUserId
|
|
|
+ }
|
|
|
+ break
|
|
|
+ }
|
|
|
+ //查找会话信息
|
|
|
+ chatJson := IC.BaseMysql.FindOne(util.SOCIALIZE_CHAT_SESSION, map[string]interface{}{"id": sessionId}, "user_id,ent_id,customer_service_id", "")
|
|
|
+ if chatJson == nil {
|
|
|
+ return false, "会话标识不存在", "", 0, nowForm.Unix()
|
|
|
+ } else {
|
|
|
+ if userId != quitl.Int64All((*chatJson)["user_id"]) {
|
|
|
+ return false, "会话标识不属于此用户", "", 0, nowForm.Unix()
|
|
|
}
|
|
|
- customer_service_id = quitl.Int64All((*chatJson)["customer_service_id"])
|
|
|
- entid = quitl.Int64All((*chatJson)["ent_id"])
|
|
|
- userid = userId
|
|
|
}
|
|
|
+ customer_service_id = quitl.Int64All((*chatJson)["customer_service_id"])
|
|
|
+ entid = quitl.Int64All((*chatJson)["ent_id"])
|
|
|
+ userid = userId
|
|
|
+ userType := int64(1)
|
|
|
+ //客服相关信息保存
|
|
|
fool = IC.BaseMysql.ExecTx("聊天信息保存", func(tx *sql.Tx) bool {
|
|
|
//先插入信息表
|
|
|
- userType := int64(1)
|
|
|
- userId := int64(0)
|
|
|
message := map[string]interface{}{
|
|
|
"appid": in.Appid,
|
|
|
"title": in.Title,
|
|
@@ -482,7 +480,6 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
|
|
|
messageMailBox["read_time"] = nowForm.Format(util.Date_Full_Layout)
|
|
|
}
|
|
|
userType = 2
|
|
|
-
|
|
|
}
|
|
|
} else {
|
|
|
messageMailBox["own_type"] = 2
|
|
@@ -497,9 +494,9 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
|
|
|
receiveOk = IC.BaseMysql.InsertByTx(tx, util.SOCIALIZE_MESSAGE_MAILBOX, messageMailBox)
|
|
|
messageMailBox = map[string]interface{}{
|
|
|
"appid": in.Appid,
|
|
|
- "messag_id": ok,
|
|
|
"type": in.ItemType,
|
|
|
"create_time": nowForm.Format(util.Date_Full_Layout),
|
|
|
+ "messag_id": ok,
|
|
|
"read_time": nowForm.Format(util.Date_Full_Layout),
|
|
|
"isread": 1,
|
|
|
"send_isdel": 0,
|
|
@@ -538,52 +535,67 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
|
|
|
messageMailBox["receive_user_id"] = in.ReceiveId
|
|
|
}
|
|
|
receiveOk = IC.BaseMysql.InsertByTx(tx, util.SOCIALIZE_MESSAGE_MAILBOX, messageMailBox)
|
|
|
- if ok > 1 && receiveOk > 1 {
|
|
|
- pc_a, err := util.GetData(userType, userId)
|
|
|
- count := 1
|
|
|
- if err == nil && pc_a != nil {
|
|
|
- count += pc_a.Count
|
|
|
- }
|
|
|
- util.SetData(userType, userId, map[string]interface{}{"data": data, "count": count}, IC.SurvivalTime)
|
|
|
- }
|
|
|
return ok > 1 && receiveOk > 1
|
|
|
})
|
|
|
- if fool && in.ItemType != 2 && in.ItemType != 3 {
|
|
|
- go UserSynchronousList(customer_service_id, userid, entid, message_id, create_time)
|
|
|
+ if fool {
|
|
|
+ go UserSynchronousList(customer_service_id, userid, entid, message_id, create_time, quitl.Int64All(quitl.If(userType == 1, 2, 1)))
|
|
|
}
|
|
|
return fool, "", in.Content, messageId, nowForm.Unix()
|
|
|
}
|
|
|
|
|
|
// 客服 用户聊天消息列表同步
|
|
|
-func UserSynchronousList(customerServiceId, userId, entId, messageId int64, createTime string) {
|
|
|
+//sendUserType 发送人类型 1客服 2用户
|
|
|
+func UserSynchronousList(customerServiceId, userId, entId, messageId int64, createTime string, sendUserType int64) {
|
|
|
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,
|
|
|
+ /* rwLock.Lock()
|
|
|
+ defer rwLock.Unlock()*/
|
|
|
+ nowForm := time.Now().Local()
|
|
|
+ create_time := nowForm.Format(util.Date_Full_Layout)
|
|
|
+ //查看汇总表
|
|
|
+ log.Println(IC.BaseMysql.Count(util.SOCIALIZE_SUMMARY, map[string]interface{}{"user_id": userId, "ent_id": entId}))
|
|
|
+ if IC.BaseMysql.Count(util.SOCIALIZE_SUMMARY, map[string]interface{}{"user_id": userId, "ent_id": entId}) > 0 {
|
|
|
+ //更新汇总表
|
|
|
+ ok := int64(0)
|
|
|
+ if sendUserType == 1 {
|
|
|
+ ok = IC.BaseMysql.UpdateOrDeleteBySql(fmt.Sprintf("UPDATE socialize_summary SET message_id = %d, unread = unread+1, customer_service_access = %d WHERE user_id = %d and ent_id= %d", messageId, quitl.If(customerServiceId > 0, 0, 1), userId, entId))
|
|
|
+ } else {
|
|
|
+ ok = IC.BaseMysql.UpdateOrDeleteBySql(fmt.Sprintf("UPDATE socialize_summary SET message_id = %d, customer_service_access = %d WHERE user_id = %d and ent_id= %d", messageId, quitl.If(customerServiceId > 0, 0, 1), userId, entId))
|
|
|
}
|
|
|
- //判断是否机器人聊天
|
|
|
- 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
|
|
|
+ if ok > 0 && customerServiceId > 0 {
|
|
|
+ //判断客服用户表是否存在
|
|
|
+ if IC.BaseMysql.Count(util.Socialize_customer_service_user, map[string]interface{}{"user_id": userId, "ent_id": entId, "customer_service_id": customerServiceId}) > 0 {
|
|
|
+ if sendUserType == 2 {
|
|
|
+ IC.BaseMysql.UpdateOrDeleteBySql(fmt.Sprintf("UPDATE socialize_customer_service_user SET unread = unread+1 WHERE user_id = %d and customer_service_id= %d", userId, customerServiceId))
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ IC.BaseMysql.Insert(util.SOCIALIZE_CUSTOMER_SERVICE_USER, map[string]interface{}{
|
|
|
+ "user_id": userId,
|
|
|
+ "ent_id": entId,
|
|
|
+ "customer_service_id": customerServiceId,
|
|
|
+ "unread": quitl.If(sendUserType == 1, 0, 1),
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //新增汇总表
|
|
|
+ ok := IC.BaseMysql.Insert(util.SOCIALIZE_SUMMARY, map[string]interface{}{
|
|
|
+ "user_id": userId,
|
|
|
+ "ent_id": entId,
|
|
|
+ "customer_service_access": quitl.If(customerServiceId > 0, 1, 0),
|
|
|
+ "timestamp": create_time,
|
|
|
+ "unread": quitl.If(sendUserType == 1, 0, 1),
|
|
|
+ "message_id": messageId,
|
|
|
+ })
|
|
|
+ //新增客服用户表
|
|
|
+ if ok > 0 && customerServiceId > 0 {
|
|
|
+ IC.BaseMysql.Insert(util.SOCIALIZE_CUSTOMER_SERVICE_USER, map[string]interface{}{
|
|
|
+ "user_id": userId,
|
|
|
+ "ent_id": entId,
|
|
|
+ "customer_service_id": customerServiceId,
|
|
|
+ "unread": quitl.If(sendUserType == 1, 0, 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),
|
|
|
- })
|
|
|
}
|
|
|
|
|
|
// 历史信息查询
|
|
@@ -820,13 +832,20 @@ func (b *MessaggeService) SaveAutoReplyMsg(userType, entId, entUserId, userId in
|
|
|
sessionId := IC.BaseMysql.InsertBySqlByTx(tx, `insert into socialize_chat_session (appid,type,ent_id,customer_service_id,customer_service_name,user_id,start_time,end_time) values (?,?,?,?,?,?,?,?)`, appId, 1, entId, entUserId, entUserName, userId, nowFormat, nowFormat)
|
|
|
ok := false
|
|
|
if userType == 0 {
|
|
|
+ //客服给用户发送,归属客服已读
|
|
|
ok1 := 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,isread,read_time) values (?,?,?,?,?,?,?,?,?,?,?,?)`, appId, messageId, 7, sessionId, 1, userId, 2, sessionId, 1, nowFormat, 1, nowFormat) > 0
|
|
|
+ //客服给用户发送,归属用户未读
|
|
|
ok2 := 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 = ok1 && ok2
|
|
|
+ userType = 1
|
|
|
} else if userType == 1 {
|
|
|
+ // 客服给用户发送 客服接受已读系统信息
|
|
|
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,isread,read_time) values (?,?,?,?,?,?,?,?,?,?,?,?)`, appId, messageId, 7, sessionId, 1, userId, 2, sessionId, 1, nowFormat, 1, nowFormat) > 0
|
|
|
+ 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
|
|
|
+ userType = 1
|
|
|
}
|
|
|
message_id = messageId
|
|
|
return messageId > 0 && sessionId > 0 && ok
|
|
@@ -835,7 +854,7 @@ func (b *MessaggeService) SaveAutoReplyMsg(userType, entId, entUserId, userId in
|
|
|
customer_service_id = entUserId
|
|
|
userid = userId
|
|
|
entid = entId
|
|
|
- go UserSynchronousList(customer_service_id, userid, entid, message_id, nowFormat)
|
|
|
+ go UserSynchronousList(customer_service_id, userid, entid, message_id, nowFormat, userType)
|
|
|
}
|
|
|
return ok1, messageId
|
|
|
}
|
|
@@ -998,6 +1017,8 @@ func (this *MessaggeService) Chat(in *messagecenter.MessageEntity) (fool bool, e
|
|
|
//发送人自己
|
|
|
if !isWithdrawByOthers {
|
|
|
args = append(args, in.Appid, messageId, in.ItemType, in.SendId, 2, in.SendId, 2, 2, in.SendId, nowTime, v, 1)
|
|
|
+ //最后一次聊天
|
|
|
+ SocializeSummaryAddOrUpdate(tx, v, in.SendId, 0, messageId, isCustomerServiceAccess, nowTime)
|
|
|
}
|
|
|
if !isWithdrawByMyself {
|
|
|
groupUser := GetUserByGroupId(tx, v, in.SendId)
|
|
@@ -1006,10 +1027,8 @@ func (this *MessaggeService) Chat(in *messagecenter.MessageEntity) (fool bool, e
|
|
|
//接收人其他用户
|
|
|
args = append(args, in.Appid, messageId, in.ItemType, in.SendId, 2, vv, 2, 2, vv, nowTime, v, 0)
|
|
|
//最后一次聊天
|
|
|
- SocializeSummaryAddOrUpdate(tx, v, vv, 0, messageId, isCustomerServiceAccess, nowTime)
|
|
|
+ SocializeSummaryAddOrUpdate(tx, v, 0, vv, messageId, isCustomerServiceAccess, nowTime)
|
|
|
}
|
|
|
- //更新未读消息
|
|
|
- GroupUserUnReadUpdate(tx, groupUser)
|
|
|
}
|
|
|
MessageMailBoxAdd(tx, fieids, args)
|
|
|
}
|
|
@@ -1031,7 +1050,7 @@ func (this *MessaggeService) Chat(in *messagecenter.MessageEntity) (fool bool, e
|
|
|
|
|
|
//最后一次聊天
|
|
|
SocializeSummaryAddOrUpdate(tx, 0, in.SendId, v, messageId, isCustomerServiceAccess, nowTime)
|
|
|
- SocializeSummaryAddOrUpdate(tx, 0, v, in.SendId, messageId, isCustomerServiceAccess, nowTime)
|
|
|
+ // SocializeSummaryAddOrUpdate(tx, 0, v, in.SendId, messageId, isCustomerServiceAccess, nowTime)
|
|
|
}
|
|
|
MessageMailBoxAdd(tx, fieids, args)
|
|
|
}
|
|
@@ -1084,73 +1103,103 @@ func GetUserByGroupId(tx *sql.Tx, groupId, sendId int64) []int64 {
|
|
|
}
|
|
|
|
|
|
// 最后一次聊天存储
|
|
|
+//1v1是双方的
|
|
|
+//群聊是发送人和其他人的
|
|
|
func SocializeSummaryAddOrUpdate(tx *sql.Tx, groupId, myPositionId, yourPositionId, messageId int64, isCustomerServiceAccess int, timestamp string) bool {
|
|
|
//判断是否存在
|
|
|
if groupId > 0 {
|
|
|
- if IC.BaseMysql.CountBySql(fmt.Sprintf(`select count(1) from %s where chat_group_id =?`, util.SOCIALIZE_SUMMARY), groupId) > 0 {
|
|
|
- //存在更新
|
|
|
- return IC.BaseMysql.UpdateByTx(tx, util.SOCIALIZE_SUMMARY, map[string]interface{}{
|
|
|
- "chat_group_id": groupId,
|
|
|
- }, map[string]interface{}{
|
|
|
- "message_id": messageId,
|
|
|
- "timestamp": timestamp,
|
|
|
- })
|
|
|
- } else {
|
|
|
- //新增
|
|
|
- return IC.BaseMysql.InsertByTx(tx, util.SOCIALIZE_SUMMARY, map[string]interface{}{
|
|
|
- "chat_group_id": groupId,
|
|
|
- "message_id": messageId,
|
|
|
- "timestamp": timestamp,
|
|
|
- }) > 0
|
|
|
- }
|
|
|
- }
|
|
|
- if yourPositionId > 0 {
|
|
|
- ok_my := true
|
|
|
- ok_your := true
|
|
|
- //发送方
|
|
|
- if IC.BaseMysql.CountBySql(fmt.Sprintf(`select count(1) from %s where my_position_id =? and your_position_id =?`, util.SOCIALIZE_SUMMARY), myPositionId, yourPositionId) > 0 {
|
|
|
- //存在更新
|
|
|
- ok_my = IC.BaseMysql.UpdateByTx(tx, util.SOCIALIZE_SUMMARY, map[string]interface{}{
|
|
|
- "my_position_id": myPositionId,
|
|
|
- "your_position_id": yourPositionId,
|
|
|
- }, map[string]interface{}{
|
|
|
- "message_id": messageId,
|
|
|
- "timestamp": timestamp,
|
|
|
- })
|
|
|
+ isSend := myPositionId != 0
|
|
|
+ if isSend {
|
|
|
+ if IC.BaseMysql.CountBySql(fmt.Sprintf(`select count(1) from %s where chat_group_id =? and my_position_id =?`, util.SOCIALIZE_SUMMARY), groupId, myPositionId) > 0 {
|
|
|
+ //存在更新
|
|
|
+ return IC.BaseMysql.UpdateByTx(tx, util.SOCIALIZE_SUMMARY, map[string]interface{}{
|
|
|
+ "chat_group_id": groupId,
|
|
|
+ "my_position_id": myPositionId,
|
|
|
+ }, map[string]interface{}{
|
|
|
+ "message_id": messageId,
|
|
|
+ "timestamp": timestamp,
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ //新增
|
|
|
+ return IC.BaseMysql.InsertByTx(tx, util.SOCIALIZE_SUMMARY, map[string]interface{}{
|
|
|
+ "chat_group_id": groupId,
|
|
|
+ "my_position_id": myPositionId,
|
|
|
+ "message_id": messageId,
|
|
|
+ "timestamp": timestamp,
|
|
|
+ "unread": 0,
|
|
|
+ }) > 0
|
|
|
+ }
|
|
|
} else {
|
|
|
- //新增
|
|
|
- ok_my = IC.BaseMysql.InsertByTx(tx, util.SOCIALIZE_SUMMARY, map[string]interface{}{
|
|
|
- "my_position_id": myPositionId,
|
|
|
- "your_position_id": yourPositionId,
|
|
|
- "message_id": messageId,
|
|
|
- "timestamp": timestamp,
|
|
|
- "unread": 0,
|
|
|
- "customer_service_access": isCustomerServiceAccess,
|
|
|
- }) > 0
|
|
|
+ if r := IC.BaseMysql.SelectBySql(fmt.Sprintf(`select unread from %s where chat_group_id =? and my_position_id =?`, util.SOCIALIZE_SUMMARY), groupId, yourPositionId); r != nil && len(*r) > 0 {
|
|
|
+ //存在更新
|
|
|
+ return IC.BaseMysql.UpdateByTx(tx, util.SOCIALIZE_SUMMARY, map[string]interface{}{
|
|
|
+ "chat_group_id": groupId,
|
|
|
+ "my_position_id": yourPositionId,
|
|
|
+ }, map[string]interface{}{
|
|
|
+ "message_id": messageId,
|
|
|
+ "timestamp": timestamp,
|
|
|
+ "unread": gconv.Int((*r)[0]["unread"]) + 1,
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ //新增
|
|
|
+ return IC.BaseMysql.InsertByTx(tx, util.SOCIALIZE_SUMMARY, map[string]interface{}{
|
|
|
+ "chat_group_id": groupId,
|
|
|
+ "my_position_id": yourPositionId,
|
|
|
+ "message_id": messageId,
|
|
|
+ "timestamp": timestamp,
|
|
|
+ "unread": 1,
|
|
|
+ }) > 0
|
|
|
+ }
|
|
|
}
|
|
|
- //接收方
|
|
|
- if IC.BaseMysql.CountBySql(fmt.Sprintf(`select count(1) from %s where my_position_id =? and your_position_id =?`, util.SOCIALIZE_SUMMARY), yourPositionId, myPositionId) > 0 {
|
|
|
- //存在更新
|
|
|
- ok_your = IC.BaseMysql.UpdateByTx(tx, util.SOCIALIZE_SUMMARY, map[string]interface{}{
|
|
|
- "my_position_id": yourPositionId,
|
|
|
- "your_position_id": myPositionId,
|
|
|
- }, map[string]interface{}{
|
|
|
- "message_id": messageId,
|
|
|
- "timestamp": timestamp,
|
|
|
- "unread": 1,
|
|
|
- })
|
|
|
- } else {
|
|
|
- //新增
|
|
|
- ok_your = IC.BaseMysql.InsertByTx(tx, util.SOCIALIZE_SUMMARY, map[string]interface{}{
|
|
|
- "my_position_id": yourPositionId,
|
|
|
- "your_position_id": myPositionId,
|
|
|
- "message_id": messageId,
|
|
|
- "timestamp": timestamp,
|
|
|
- "unread": 1,
|
|
|
- "customer_service_access": isCustomerServiceAccess,
|
|
|
- }) > 0
|
|
|
+ } else {
|
|
|
+ if yourPositionId > 0 {
|
|
|
+ ok_my := true
|
|
|
+ ok_your := true
|
|
|
+ //发送方
|
|
|
+ if IC.BaseMysql.CountBySql(fmt.Sprintf(`select count(1) from %s where my_position_id =? and your_position_id =?`, util.SOCIALIZE_SUMMARY), myPositionId, yourPositionId) > 0 {
|
|
|
+ //存在更新
|
|
|
+ ok_my = IC.BaseMysql.UpdateByTx(tx, util.SOCIALIZE_SUMMARY, map[string]interface{}{
|
|
|
+ "my_position_id": myPositionId,
|
|
|
+ "your_position_id": yourPositionId,
|
|
|
+ }, map[string]interface{}{
|
|
|
+ "message_id": messageId,
|
|
|
+ "timestamp": timestamp,
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ //新增
|
|
|
+ ok_my = IC.BaseMysql.InsertByTx(tx, util.SOCIALIZE_SUMMARY, map[string]interface{}{
|
|
|
+ "my_position_id": myPositionId,
|
|
|
+ "your_position_id": yourPositionId,
|
|
|
+ "message_id": messageId,
|
|
|
+ "timestamp": timestamp,
|
|
|
+ "unread": 0,
|
|
|
+ "customer_service_access": isCustomerServiceAccess,
|
|
|
+ }) > 0
|
|
|
+ }
|
|
|
+ //接收方
|
|
|
+ if r := IC.BaseMysql.SelectBySql(fmt.Sprintf(`select id,unread from %s where my_position_id =? and your_position_id =? limit 1`, util.SOCIALIZE_SUMMARY), yourPositionId, myPositionId); r != nil && len(*r) > 0 {
|
|
|
+ //存在更新
|
|
|
+ ok_your = IC.BaseMysql.UpdateByTx(tx, util.SOCIALIZE_SUMMARY, map[string]interface{}{
|
|
|
+ "my_position_id": yourPositionId,
|
|
|
+ "your_position_id": myPositionId,
|
|
|
+ }, map[string]interface{}{
|
|
|
+ "message_id": messageId,
|
|
|
+ "timestamp": timestamp,
|
|
|
+ "unread": gconv.Int((*r)[0]["unread"]) + 1,
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ //新增
|
|
|
+ ok_your = IC.BaseMysql.InsertByTx(tx, util.SOCIALIZE_SUMMARY, map[string]interface{}{
|
|
|
+ "my_position_id": yourPositionId,
|
|
|
+ "your_position_id": myPositionId,
|
|
|
+ "message_id": messageId,
|
|
|
+ "timestamp": timestamp,
|
|
|
+ "unread": 1,
|
|
|
+ "customer_service_access": isCustomerServiceAccess,
|
|
|
+ }) > 0
|
|
|
+ }
|
|
|
+ return ok_my && ok_your
|
|
|
}
|
|
|
- return ok_my && ok_your
|
|
|
}
|
|
|
return true
|
|
|
}
|