34 lines
1.6 KiB
Go
34 lines
1.6 KiB
Go
package model
|
||
|
||
// 好友关系状态常量
|
||
const (
|
||
FriendStatusPending = 1 // 待验证(等待对方同意)
|
||
FriendStatusAccepted = 2 // 已通过(互为好友)
|
||
)
|
||
|
||
// Friend 好友关系表:申请方向为 user_id → friend_id,通过后一条记录即代表双向好友
|
||
type Friend struct {
|
||
ID int `gorm:"primaryKey" json:"id"` // 关系ID
|
||
UserID int `gorm:"index" json:"user_id"` // 发起方用户ID(申请人)
|
||
FriendID int `gorm:"index" json:"friend_id"` // 接收方用户ID(被申请人)
|
||
Status int `gorm:"default:1" json:"status"` // 状态:1待验证 2已通过
|
||
CreatedAt int64 `gorm:"autoCreateTime" json:"created_at"` // 申请时间(int 时间戳)
|
||
UpdatedAt int64 `gorm:"autoUpdateTime" json:"updated_at"` // 状态更新时间(int 时间戳)
|
||
}
|
||
|
||
// TableName 指定表名
|
||
func (Friend) TableName() string { return "friends" }
|
||
|
||
// ChatMessage 私聊消息表:仅好友之间可互发
|
||
type ChatMessage struct {
|
||
ID int `gorm:"primaryKey" json:"id"` // 消息ID
|
||
FromID int `gorm:"index" json:"from_id"` // 发送方用户ID
|
||
ToID int `gorm:"index" json:"to_id"` // 接收方用户ID
|
||
Content string `gorm:"size:500" json:"content"` // 消息内容(纯文本)
|
||
IsRead int `gorm:"default:0" json:"is_read"` // 接收方是否已读:0未读 1已读
|
||
CreatedAt int64 `gorm:"autoCreateTime" json:"created_at"` // 发送时间(int 时间戳)
|
||
}
|
||
|
||
// TableName 指定表名
|
||
func (ChatMessage) TableName() string { return "chat_messages" }
|