user.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package models
  2. import (
  3. "time"
  4. )
  5. type User struct {
  6. ID uint `json:"id" gorm:"primarykey"`
  7. Username string `json:"username" gorm:"unique"`
  8. Password string `json:"password"`
  9. Role string `json:"role"`
  10. AvatarURL string `json:"avatar_url" gorm:"type:varchar(500)"` // 头像URL
  11. Nickname string `json:"nickname" gorm:"type:varchar(100)"` // 昵称
  12. Email string `json:"email" gorm:"type:varchar(255)"` // 邮箱
  13. // AI 对话接收设置
  14. ReceiveAIConversations bool `json:"receive_ai_conversations" gorm:"default:true"` // 是否接收 AI 对话(默认接收)
  15. CreatedAt time.Time `json:"created_at"` // 创建时间
  16. UpdatedAt time.Time `json:"updated_at"` // 更新时间
  17. }
  18. type Conversation struct {
  19. ID uint `json:"id" gorm:"primaryKey"`
  20. ConversationType string `json:"conversation_type" gorm:"type:varchar(20);default:'visitor'"` // visitor(访客对话)、internal(内部/知识库测试)
  21. VisitorID uint `json:"visitor_id"`
  22. AgentID uint `json:"agent_id"`
  23. Status string `json:"status"`
  24. CreatedAt time.Time `json:"created_at"`
  25. UpdatedAt time.Time `json:"updated_at"`
  26. // 访客信息字段(自动收集)
  27. Website string `json:"website" gorm:"type:varchar(500)"` // 网站(当前页面URL)
  28. Referrer string `json:"referrer" gorm:"type:varchar(500)"` // 来源(referrer)
  29. Browser string `json:"browser" gorm:"type:varchar(100)"` // 浏览器信息
  30. OS string `json:"os" gorm:"type:varchar(100)"` // 操作系统
  31. Language string `json:"language" gorm:"type:varchar(50)"` // 语言
  32. IPAddress string `json:"ip_address" gorm:"type:varchar(50)"` // IP地址
  33. Location string `json:"location" gorm:"type:varchar(200)"` // 位置
  34. // 联系信息字段(客服手动添加)
  35. Email string `json:"email" gorm:"type:varchar(255)"` // 邮箱
  36. Phone string `json:"phone" gorm:"type:varchar(50)"` // 电话
  37. Notes string `json:"notes" gorm:"type:text"` // 备注
  38. // 在线状态
  39. LastSeenAt *time.Time `json:"last_seen_at"` // 最后活跃时间
  40. // AI 客服相关
  41. ChatMode string `json:"chat_mode" gorm:"type:varchar(20);default:'human'"` // 对话模式:human(人工客服)、ai(AI客服)
  42. AIConfigID *uint `json:"ai_config_id"` // AI 配置 ID(访客选择的模型配置)
  43. }
  44. type Message struct {
  45. ID uint `json:"id" gorm:"primarykey"`
  46. ConversationID uint `json:"conversation_id"`
  47. SenderID uint `json:"sender_id"`
  48. SenderIsAgent bool `json:"sender_is_agent"`
  49. Content string `json:"content" gorm:"type:text"`
  50. MessageType string `json:"message_type" gorm:"type:varchar(20);default:'user_message'"` // 消息类型:user_message, system_message
  51. ChatMode string `json:"chat_mode" gorm:"type:varchar(20);default:'human'"` // 消息发送时的对话模式:human(人工客服)、ai(AI客服)
  52. IsRead bool `json:"is_read"`
  53. ReadAt *time.Time `json:"read_at"`
  54. CreatedAt time.Time `json:"created_at"`
  55. // 文件相关字段(可选)
  56. FileURL *string `json:"file_url" gorm:"type:varchar(500)"` // 文件URL(相对路径或完整URL)
  57. FileType *string `json:"file_type" gorm:"type:varchar(50)"` // 文件类型:image, document
  58. FileName *string `json:"file_name" gorm:"type:varchar(255)"` // 原始文件名
  59. FileSize *int64 `json:"file_size"` // 文件大小(字节)
  60. MimeType *string `json:"mime_type" gorm:"type:varchar(100)"` // MIME类型(如 image/jpeg)
  61. // AI 回复使用的数据源,用于前端展示「已使用知识库」等,逗号分隔:knowledge_base, llm, web
  62. SourcesUsed string `json:"sources_used" gorm:"type:varchar(100)"`
  63. // IsAIGenerationFailed 为 true 表示本次 AI 消息为生成失败后的兜底文案(用于统计失败率)
  64. IsAIGenerationFailed bool `json:"is_ai_generation_failed" gorm:"default:false"`
  65. }