|
@@ -1075,6 +1075,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)
|
|
@@ -1083,10 +1085,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)
|
|
|
}
|
|
@@ -1108,7 +1108,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)
|
|
|
}
|
|
@@ -1161,73 +1161,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
|
|
|
}
|