:refactor: 更新登录逻辑,使用用户ID查询机器人并记录首次登录时间
All checks were successful
BuildImage / build-image (push) Successful in 1m54s
All checks were successful
BuildImage / build-image (push) Successful in 1m54s
This commit is contained in:
parent
3be5e65a88
commit
fa8bf764db
@ -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)
|
||||
|
||||
// 添加定时任务
|
||||
|
@ -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"`
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user