diff --git a/backend/internal/modules/chat/admin_list_test.go b/backend/internal/modules/chat/admin_list_test.go index 129ebdb..e0fd371 100644 --- a/backend/internal/modules/chat/admin_list_test.go +++ b/backend/internal/modules/chat/admin_list_test.go @@ -99,8 +99,8 @@ func TestListAdminConversationsUsesPersonalStateAndBatchData(t *testing.T) { if item.UnreadCount != 1 { t.Fatalf("管理员未读数 = %d, want 1", item.UnreadCount) } - if !item.NeedsReply { - t.Fatal("用户消息未回复时应保持待处理") + if item.NeedsReply { + t.Fatal("订单群用户消息不应因未回复停留在待处理") } counts, err := repo.AdminConversationCounts(t.Context(), Principal{Type: "admin", ID: admin.ID}, adminChatFilterMine, adminChatStageAll, "") if err != nil { @@ -109,6 +109,16 @@ func TestListAdminConversationsUsesPersonalStateAndBatchData(t *testing.T) { if counts.Ownership[adminChatFilterMine] != 1 || counts.Stages[adminChatStageAll] != 1 { t.Fatalf("聚合统计异常: ownership=%v stages=%v", counts.Ownership, counts.Stages) } + if err := db.Model(&conversation).Update("type", ConversationTypeGeneralSupport).Error; err != nil { + t.Fatalf("切换咨询会话类型失败: %v", err) + } + result, err = repo.ListConversationsWithFilter(t.Context(), Principal{Type: "admin", ID: admin.ID}, 1, 20, adminChatFilterMine, adminChatStagePending, "") + if err != nil { + t.Fatalf("查询咨询待处理会话失败: %v", err) + } + if result.Total != 1 { + t.Fatalf("咨询未回复待处理数量 = %d, want 1", result.Total) + } adminMessage := model.ChatMessage{ConversationID: conversation.ID, SenderType: "admin", SenderID: admin.ID, SenderRole: "support", ContentType: "text", Content: "客服回复", CreatedAt: now.Add(2 * time.Second)} if err := db.Create(&adminMessage).Error; err != nil { diff --git a/backend/internal/modules/chat/support.go b/backend/internal/modules/chat/support.go index e915142..68fbf09 100644 --- a/backend/internal/modules/chat/support.go +++ b/backend/internal/modules/chat/support.go @@ -239,7 +239,7 @@ func (r *Repository) listAdminConversations(ctx context.Context, principal Princ COALESCE(explicit_lo.handoff_status, listing_lo.handoff_status) AS latest_handoff_status, COALESCE(explicit_lo.refund_status, listing_lo.refund_status) AS latest_refund_status, lm.sender_type AS last_sender_type, lm.sender_id AS last_sender_id, lm.sender_role AS last_sender_role, - CASE WHEN ` + adminNeedsReplyExpression() + ` THEN 1 ELSE 0 END AS needs_reply, + CASE WHEN c.type = 'general_support' AND (` + adminNeedsReplyExpression() + `) THEN 1 ELSE 0 END AS needs_reply, ( SELECT COUNT(1) FROM chat_messages AS cm @@ -415,7 +415,7 @@ func adminChatStageCondition(stage string, principal Principal) (string, []inter latestRefundStatus := "COALESCE(explicit_lo.refund_status, listing_lo.refund_status)" switch stage { case adminChatStagePending: - return adminNeedsReplyExpression(), nil + return "c.type = 'general_support' AND (" + adminNeedsReplyExpression() + ")", nil case adminChatStageUnjoined: return latestID + " IS NULL", nil case adminChatStageHandoff: