diff --git a/internal/handler/api_login.go b/internal/handler/api_login.go index fa77e9c..85d2225 100644 --- a/internal/handler/api_login.go +++ b/internal/handler/api_login.go @@ -37,7 +37,7 @@ func CheckQRCodeStatus(c *fiber.Ctx) error { // 获取机器人实例 db := model.GetDB() var robot model.Robot - if err = db.First(&robot, id).Error; err != nil { + if err = db.Where("user_id = ?", c.Locals("userId")).First(&robot, id).Error; err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { return c.JSON(fiber.Map{ "success": false, @@ -92,6 +92,9 @@ func CheckQRCodeStatus(c *fiber.Ctx) error { robot.Status = model.RobotStatusOnline now := time.Now() robot.LastLoginAt = &now + if robot.FirstLoginAt == nil { + robot.FirstLoginAt = &now // 只有在为空的时候才记录首次登录时间 + } db.Save(&robot) // 添加定时任务 diff --git a/internal/model/robot.go b/internal/model/robot.go index 12a18c4..d1ad895 100644 --- a/internal/model/robot.go +++ b/internal/model/robot.go @@ -29,6 +29,7 @@ type Robot struct { Nickname string `gorm:"column:nickname" json:"nickname"` Avatar string `gorm:"column:avatar" json:"avatar"` Status RobotStatus `gorm:"column:status;default:'offline'" json:"status"` + FirstLoginAt *time.Time `gorm:"column:first_login_at" json:"first_login_at"` // 首次登录时间 LastLoginAt *time.Time `gorm:"column:last_login_at" json:"last_login_at"` ErrorMessage string `gorm:"column:error_message" json:"error_message"` }