user.go 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. VisitorID uint `json:"visitor_id"`
  21. AgentID uint `json:"agent_id"`
  22. Status string `json:"status"`
  23. CreatedAt time.Time `json:"created_at"`
  24. UpdatedAt time.Time `json:"updated_at"`
  25. // 访客信息字段(自动收集)
  26. Website string `json:"website" gorm:"type:varchar(500)"` // 网站(当前页面URL)
  27. Referrer string `json:"referrer" gorm:"type:varchar(500)"` // 来源(referrer)
  28. Browser string `json:"browser" gorm:"type:varchar(100)"` // 浏览器信息
  29. OS string `json:"os" gorm:"type:varchar(100)"` // 操作系统
  30. Language string `json:"language" gorm:"type:varchar(50)"` // 语言
  31. IPAddress string `json:"ip_address" gorm:"type:varchar(50)"` // IP地址
  32. Location string `json:"location" gorm:"type:varchar(200)"` // 位置
  33. // 联系信息字段(客服手动添加)
  34. Email string `json:"email" gorm:"type:varchar(255)"` // 邮箱
  35. Phone string `json:"phone" gorm:"type:varchar(50)"` // 电话
  36. Notes string `json:"notes" gorm:"type:text"` // 备注
  37. // 在线状态
  38. LastSeenAt *time.Time `json:"last_seen_at"` // 最后活跃时间
  39. // AI 客服相关
  40. ChatMode string `json:"chat_mode" gorm:"type:varchar(20);default:'human'"` // 对话模式:human(人工客服)、ai(AI客服)
  41. AIConfigID *uint `json:"ai_config_id"` // AI 配置 ID(访客选择的模型配置)
  42. }
  43. type Message struct {
  44. ID uint `json:"id" gorm:"primarykey"`
  45. ConversationID uint `json:"conversation_id"`
  46. SenderID uint `json:"sender_id"`
  47. SenderIsAgent bool `json:"sender_is_agent"`
  48. Content string `json:"content" gorm:"type:text"`
  49. MessageType string `json:"message_type" gorm:"type:varchar(20);default:'user_message'"` // 消息类型:user_message, system_message
  50. ChatMode string `json:"chat_mode" gorm:"type:varchar(20);default:'human'"` // 消息发送时的对话模式:human(人工客服)、ai(AI客服)
  51. IsRead bool `json:"is_read"`
  52. ReadAt *time.Time `json:"read_at"`
  53. CreatedAt time.Time `json:"created_at"`
  54. // 文件相关字段(可选)
  55. FileURL *string `json:"file_url" gorm:"type:varchar(500)"` // 文件URL(相对路径或完整URL)
  56. FileType *string `json:"file_type" gorm:"type:varchar(50)"` // 文件类型:image, document
  57. FileName *string `json:"file_name" gorm:"type:varchar(255)"` // 原始文件名
  58. FileSize *int64 `json:"file_size"` // 文件大小(字节)
  59. MimeType *string `json:"mime_type" gorm:"type:varchar(100)"` // MIME类型(如 image/jpeg)
  60. }