package model import "time" // LoginAttempt 登录尝试审计。当前只记录失败尝试(成功登录已由 user_sessions // + users.last_login_at 覆盖),用于风控/审计排查异常登录。由保留期清理任务定期删除旧行。 type LoginAttempt struct { ID uint64 `gorm:"primaryKey;autoIncrement" json:"id"` ShopCode string `gorm:"size:64;index:idx_attempt_user" json:"shop_code"` Username string `gorm:"size:50;index:idx_attempt_user" json:"username"` IP string `gorm:"size:64;index:idx_attempt_ip" json:"ip"` UserAgent string `gorm:"size:512" json:"user_agent"` Success bool `gorm:"default:false" json:"success"` Reason string `gorm:"size:40" json:"reason"` // invalid_shop|invalid_user|bad_password|locked|inactive|platform_not_allowed CreatedAt time.Time `gorm:"autoCreateTime;index:idx_attempt_user;index:idx_attempt_ip" json:"created_at"` } func (LoginAttempt) TableName() string { return "login_attempts" }