From fa8bf764dba9d4cdce73a2508aba92ccd62f7b30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AF=BB=E6=AC=A2?= Date: Mon, 28 Apr 2025 11:51:28 +0800 Subject: [PATCH] =?UTF-8?q?:refactor:=20=E6=9B=B4=E6=96=B0=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E9=80=BB=E8=BE=91=EF=BC=8C=E4=BD=BF=E7=94=A8=E7=94=A8?= =?UTF-8?q?=E6=88=B7ID=E6=9F=A5=E8=AF=A2=E6=9C=BA=E5=99=A8=E4=BA=BA?= =?UTF-8?q?=E5=B9=B6=E8=AE=B0=E5=BD=95=E9=A6=96=E6=AC=A1=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/handler/api_login.go | 5 ++++- internal/model/robot.go | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) 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"` }