From af4b4d1b4f6fe558608d40576db4c1d5f259163a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AF=BB=E6=AC=A2?= Date: Wed, 11 Oct 2023 14:46:47 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E6=96=B0=E5=A2=9E=E9=80=80?= =?UTF-8?q?=E7=BE=A4=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entity/friend.go | 15 +++++++++------ tasks/friends.go | 7 ++++++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/entity/friend.go b/entity/friend.go index 7935a75..7d6f04a 100644 --- a/entity/friend.go +++ b/entity/friend.go @@ -1,5 +1,7 @@ package entity +import "time" + // Friend // @description: 好友列表 type Friend struct { @@ -17,12 +19,13 @@ func (Friend) TableName() string { // GroupUser // @description: 群成员 type GroupUser struct { - GroupId string `json:"groupId"` // 群Id - Account string `json:"account"` // 账号 - HeadImage string `json:"headImage"` // 头像 - Nickname string `json:"nickname"` // 昵称 - Wxid string `json:"wxid"` // 微信Id - IsMember bool `json:"isMember" gorm:"type:tinyint(1)"` // 是否群成员 + GroupId string `json:"groupId"` // 群Id + Account string `json:"account"` // 账号 + HeadImage string `json:"headImage"` // 头像 + Nickname string `json:"nickname"` // 昵称 + Wxid string `json:"wxid"` // 微信Id + IsMember bool `json:"isMember" gorm:"type:tinyint(1)"` // 是否群成员 + LeaveTime time.Time `json:"leaveTime"` // 离开时间 } func (GroupUser) TableName() string { diff --git a/tasks/friends.go b/tasks/friends.go index 0e7618d..ca1741d 100644 --- a/tasks/friends.go +++ b/tasks/friends.go @@ -11,6 +11,7 @@ import ( "log" "slices" "strings" + "time" ) // 同步群成员 @@ -115,7 +116,11 @@ func syncGroupUsers(tx *gorm.DB, gid string) { log.Printf(" 群成员数: %d", len(wxIds)) // 修改不在数组的群成员状态为不在 - err = tx.Model(&entity.GroupUser{}).Where("group_id = ?", gid).Where("wxid NOT IN (?)", wxIds).Update("is_member", false).Error + pm := map[string]any{ + "is_member": false, + "leave_time": time.Now().Local(), + } + err = tx.Model(&entity.GroupUser{}).Where("group_id = ?", gid).Where("wxid NOT IN (?)", wxIds).Updates(pm).Error if err != nil { log.Printf("修改群成员状态失败: %s", err.Error()) return