package pubdef import ( "time" ) // 机器人 const ( RobotId_Min = 9000 RobotId_Max = 10000 ) // CrawlerUserId 爬虫观看会话的虚拟用户 ID。 // 不对应任何真实用户;业务侧按 userId<=0 当作未登录,免费内容仍可看。 const CrawlerUserId int64 = -1 func IsCrawlerUser(userId int64) bool { return userId == CrawlerUserId } // 性别 type Gender int32 const ( Gender_male Gender = 0 // 男 Gender_female Gender = 1 // 女 ) // 用户类型(身份) type UserType int32 const ( UserTypeGuest UserType = 0 // 游客用户 UserTypeNormal UserType = 1 // 普通用户(已注册) ) // UserTypeNone 兼容旧命名,等同游客 const UserTypeNone = UserTypeGuest var UserTypeMap = map[UserType]string{ UserTypeGuest: "游客用户", UserTypeNormal: "普通用户", } func (s UserType) String() string { return UserTypeMap[s] } // 用户状态 type UserStatus int32 const ( UserStatusNormal UserStatus = 0 // 正常 UserStatusDisable UserStatus = 1 // 封禁 UserStatusSlient UserStatus = 2 // 禁言 ) var UserStatusMap = map[UserStatus]string{ UserStatusNormal: "正常", UserStatusDisable: "封禁", UserStatusSlient: "禁止登陆", } type LoginType int32 const ( LoginTypeDevice LoginType = 0 + iota // 设备登陆 LoginTypeAccount // 账号登陆 LoginTypeEmail // 邮箱登陆 ) type VipInfo struct { CardId int64 `json:"cardId" bson:"cardId,omitempty"` // 会员卡ID VipType VipType `json:"vipType" bson:"vipType,omitempty"` // VIP类型 0:没卡、1:月卡、2:年卡 VipExpire time.Time `json:"vipExpire" bson:"vipExpire,omitempty"` // 会员过期时间 CardName string `json:"cardName" bson:"cardName,omitempty"` // 会员卡名字 VipExpireInt int64 `json:"vipExpireInt" bson:"-"` // 会员过期时间 VipExpireStr string `json:"vipExpireStr" bson:"-"` // 会员过期时间 IsUpgrade bool `json:"isUpgrade" bson:"-"` // 是否可升级 } func (vi *VipInfo) IsValid() bool { return vi.VipType > VipTypeNone && vi.VipExpire.After(time.Now()) } func (vi *VipInfo) ReSet() { vi.CardId = 0 vi.VipType = VipTypeNone vi.VipExpire = time.Now().AddDate(0, 0, -1) vi.CardName = "" } func (vi *VipInfo) ToJson() VipInfo { if !vi.IsValid() { vi.ReSet() } vi.VipExpireInt = vi.VipExpire.Unix() vi.VipExpireStr = vi.VipExpire.Format(TimeISO) return *vi }