2025-03-27 16:27:41 +08:00

36 lines
1.0 KiB
Go

package model
// ContactType 表示联系人类型的枚举
type ContactType string
const (
ContactTypeFriend ContactType = "friend"
ContactTypeGroup ContactType = "group"
)
// Contact 表示微信联系人,包括好友和群组
type Contact struct {
BaseModel
RobotID uint `gorm:"column:robot_id;index" json:"robot_id"`
WechatID string `gorm:"column:wechat_id;index" json:"wechat_id"`
Nickname string `gorm:"column:nickname" json:"nickname"`
Avatar string `gorm:"column:avatar" json:"avatar"`
Type ContactType `gorm:"column:type" json:"type"`
Remark string `gorm:"column:remark" json:"remark"`
// 关联
Robot Robot `gorm:"foreignKey:RobotID" json:"-"`
GroupMembers []GroupMember `gorm:"foreignKey:GroupID" json:"-"`
Messages []Message `gorm:"foreignKey:ContactID" json:"-"`
}
// TableName 指定表名
func (Contact) TableName() string {
return "contacts"
}
// IsGroup 判断联系人是否为群组
func (c *Contact) IsGroup() bool {
return c.Type == ContactTypeGroup
}