feat(widget): 优化访客在线轨迹、GeoIP与多站点渠道
This commit is contained in:
@@ -28,6 +28,7 @@ type SessionListItem struct {
|
||||
AgentName string `json:"agent_name"`
|
||||
ChannelName string `json:"channel_name"`
|
||||
ChannelType string `json:"channel_type"`
|
||||
ChannelDomain string `json:"channel_domain"`
|
||||
}
|
||||
|
||||
// AgentItem 可转接/筛选坐席项。
|
||||
@@ -60,6 +61,7 @@ func LoadTenantSession(id string, tenantID uint) (*model.Session, error) {
|
||||
if session.TenantID != tenantID {
|
||||
return nil, Forbidden("无权访问其他租户会话")
|
||||
}
|
||||
session.VisitorOnline = VisitorIsOnline(&session, time.Now())
|
||||
return &session, nil
|
||||
}
|
||||
|
||||
@@ -225,6 +227,7 @@ func ListSessions(actor Actor, tenantID uint, f SessionFilter) ([]SessionListIte
|
||||
items := make([]SessionListItem, 0, len(sessions))
|
||||
for _, session := range sessions {
|
||||
item := SessionListItem{Session: session, MessageCount: msgCountMap[session.ID]}
|
||||
item.VisitorOnline = VisitorIsOnline(&session, time.Now())
|
||||
if !actor.SessionAll && session.AgentID != nil && *session.AgentID == actor.UserID {
|
||||
item.UnreadCount = unreadCount(session)
|
||||
}
|
||||
@@ -239,6 +242,7 @@ func ListSessions(actor Actor, tenantID uint, f SessionFilter) ([]SessionListIte
|
||||
if ch, ok := channelMap[session.ChannelID]; ok {
|
||||
item.ChannelName = ch.Name
|
||||
item.ChannelType = ch.Type
|
||||
item.ChannelDomain = ch.SiteDomain
|
||||
}
|
||||
var lastMsg model.Message
|
||||
if err := model.DB.Where("session_id = ?", session.ID).Order("seq desc").First(&lastMsg).Error; err == nil {
|
||||
@@ -529,7 +533,9 @@ func EndSession(session *model.Session, operatorID uint, reason string) error {
|
||||
|
||||
result := model.DB.Model(&model.Session{}).
|
||||
Where("id = ? AND tenant_id = ? AND status <> ?", session.ID, session.TenantID, "ended").
|
||||
Updates(map[string]interface{}{"status": "ended", "end_reason": reason, "ended_at": now})
|
||||
Updates(map[string]interface{}{
|
||||
"status": "ended", "end_reason": reason, "ended_at": now, "visitor_left_at": now,
|
||||
})
|
||||
|
||||
if result.RowsAffected == 0 {
|
||||
return NotFound("会话不存在")
|
||||
@@ -543,6 +549,9 @@ func EndSession(session *model.Session, operatorID uint, reason string) error {
|
||||
})
|
||||
session.Status = "ended"
|
||||
session.EndedAt = &now
|
||||
session.VisitorLeftAt = &now
|
||||
session.VisitorOnline = false
|
||||
_ = CloseCurrentPageView(session, now)
|
||||
BroadcastSessionUpdate(session)
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user