feat(tenant): 隔离客服通知文件与后台任务
This commit is contained in:
@@ -92,7 +92,12 @@ func EnsureOrderConversation(tx *gorm.DB, order model.RentalOrder) (*model.ChatC
|
||||
siteID = order.DistributionSiteID
|
||||
}
|
||||
now := time.Now()
|
||||
tenantID := order.BuyerTenantID
|
||||
if tenantID == 0 {
|
||||
tenantID = order.SourceTenantID
|
||||
}
|
||||
conversation := model.ChatConversation{
|
||||
TenantID: tenantID,
|
||||
OrderID: &order.ID,
|
||||
DistributionSiteID: siteID,
|
||||
Type: "order_group",
|
||||
@@ -119,7 +124,7 @@ func EnsureOrderConversation(tx *gorm.DB, order model.RentalOrder) (*model.ChatC
|
||||
JoinedAt: now,
|
||||
},
|
||||
}
|
||||
if supportID := defaultSupportAdminID(tx); supportID > 0 {
|
||||
if supportID := defaultSupportAdminID(tx, tenantID); supportID > 0 {
|
||||
participants = append(participants, model.ChatParticipant{
|
||||
ConversationID: conversation.ID,
|
||||
ParticipantType: "admin",
|
||||
@@ -137,7 +142,11 @@ func EnsureOrderConversation(tx *gorm.DB, order model.RentalOrder) (*model.ChatC
|
||||
// 获取自动话术
|
||||
autoMessage := "订单已支付,群聊已创建。租客、号主和客服可在这里沟通交接与结账问题。"
|
||||
var cfg model.SystemConfig
|
||||
if err := tx.Where("`key` = ?", "chat.auto_welcome_message").First(&cfg).Error; err == nil && cfg.Value != "" {
|
||||
configQuery := tx.Where("`key` = ?", "chat.auto_welcome_message")
|
||||
if tenantID > 0 {
|
||||
configQuery = configQuery.Where("tenant_id = ?", tenantID)
|
||||
}
|
||||
if err := configQuery.First(&cfg).Error; err == nil && cfg.Value != "" {
|
||||
autoMessage = cfg.Value
|
||||
}
|
||||
message := model.ChatMessage{
|
||||
@@ -167,6 +176,7 @@ func (r *Repository) NotifyNewConversation(conversationID uint64) {
|
||||
Type: "conversation_updated",
|
||||
ConversationID: conversationID,
|
||||
}
|
||||
tenantScopedEvent(r.db, event)
|
||||
r.hub.NotifyConversation(conversationID, event)
|
||||
// 新会话(如未分配的平台咨询)需让所有在线客服的列表实时出现。
|
||||
r.hub.NotifyAllAdmins(event)
|
||||
|
||||
Reference in New Issue
Block a user