From 01051ff60662e66e736865e2d7640c5f228d15e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AF=BB=E6=AC=A2?= Date: Fri, 12 Jan 2024 22:20:14 +0800 Subject: [PATCH 1/2] =?UTF-8?q?:new:=20=E7=BD=91=E9=A1=B5=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E6=8E=A7=E5=88=B6=E6=98=AF=E5=90=A6=E6=89=93=E5=BC=80?= =?UTF-8?q?=E6=8C=87=E4=BB=A4=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/friend.go | 23 +++++++++++++++++++++++ router/router.go | 1 + views/index.html | 18 ++++++++++++++++++ views/static/js/index.js | 16 ++++++++++++++++ vo/friend.go | 1 + 5 files changed, 59 insertions(+) diff --git a/app/friend.go b/app/friend.go index 1b597a1..fc4ddc6 100644 --- a/app/friend.go +++ b/app/friend.go @@ -85,6 +85,29 @@ func ChangeEnableWelcomeStatus(ctx *gin.Context) { ctx.String(http.StatusOK, "操作成功") } +// ChangeEnableCommandStatus +// @description: 修改是否开启指令 +// @param ctx +func ChangeEnableCommandStatus(ctx *gin.Context) { + var p changeStatusParam + if err := ctx.ShouldBindJSON(&p); err != nil { + ctx.String(http.StatusBadRequest, "参数错误") + return + } + log.Printf("待修改的群Id:%s", p.WxId) + + err := client.MySQL.Model(&entity.Friend{}). + Where("wxid = ?", p.WxId). + Update("`enable_command`", gorm.Expr(" !`enable_command`")).Error + if err != nil { + log.Printf("修改指令启用状态失败:%s", err) + ctx.String(http.StatusInternalServerError, "操作失败: %s", err) + return + } + + ctx.String(http.StatusOK, "操作成功") +} + // ChangeSkipGroupRankStatus // @description: 修改是否跳过水群排行榜 // @param ctx diff --git a/router/router.go b/router/router.go index 7e9be6f..4ee0598 100644 --- a/router/router.go +++ b/router/router.go @@ -23,6 +23,7 @@ func Init(g *gin.Engine) { api := g.Group("/api") api.PUT("/ai/status", app.ChangeEnableAiStatus) // 修改是否开启AI状态 api.PUT("/welcome/status", app.ChangeEnableWelcomeStatus) // 修改是否开启迎新状态 + api.PUT("/command/status", app.ChangeEnableCommandStatus) // 修改是否开启指令状态 api.PUT("/grouprank/status", app.ChangeEnableGroupRankStatus) // 修改是否开启水群排行榜状态 api.PUT("/grouprank/skip", app.ChangeSkipGroupRankStatus) // 修改是否跳过水群排行榜状态 api.GET("/group/users", app.GetGroupUsers) // 获取群成员列表 diff --git a/views/index.html b/views/index.html index 5c40b6e..b860fbb 100644 --- a/views/index.html +++ b/views/index.html @@ -37,6 +37,7 @@ 最后活跃时间 是否在通讯录 是否启用AI + 是否启用指令 @@ -67,6 +68,14 @@ + + + @@ -91,6 +100,7 @@ 是否启用AI 是否启用水群排行榜 是否启用迎新 + 是否启用l指令 操作 @@ -143,6 +153,14 @@
❌已禁用
+ + + diff --git a/views/static/js/index.js b/views/static/js/index.js index 7d92cb9..804cb08 100644 --- a/views/static/js/index.js +++ b/views/static/js/index.js @@ -51,6 +51,22 @@ function changeWelcomeEnableStatus(wxId) { }) } +// 修改指令权限启用状态 +function changeCommandEnableStatus(wxId) { + axios({ + method: 'put', + url: '/api/command/status', + data: { + wxId: wxId + } + }).then(function (response) { + console.log(`返回结果: ${JSON.stringify(response)}`); + }).catch(function (error) { + console.log(`错误信息: ${error}`); + alert("修改失败") + }) +} + // 修改群成员是否参与排行榜状态 function changeUserGroupRankSkipStatus(groupId, userId) { console.log("修改水群排行榜开启状态: ", groupId, userId) diff --git a/vo/friend.go b/vo/friend.go index dbda938..b916565 100644 --- a/vo/friend.go +++ b/vo/friend.go @@ -15,6 +15,7 @@ type FriendItem struct { EnableAi bool // 是否使用AI EnableChatRank bool // 是否使用聊天排行 EnableWelcome bool // 是否使用迎新 + EnableCommand bool // 是否启用指令 IsOk bool // 是否还在通讯库(群聊是要还在群里也算) LastActiveTime types.DateTime // 最后活跃时间 } -- 2.45.2 From 6a879cbef6b8899051c1bf7099577ff6342705e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AF=BB=E6=AC=A2?= Date: Fri, 12 Jan 2024 22:26:06 +0800 Subject: [PATCH 2/2] =?UTF-8?q?:new:=20=E7=BE=A4=E6=88=90=E5=91=98?= =?UTF-8?q?=E6=96=B0=E5=A2=9E`=E6=98=AF=E5=90=A6=E7=BE=A4=E4=B8=BB`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entity/friend.go | 1 + tasks/friends/friends.go | 2 ++ views/index.html | 3 ++- views/static/js/index.js | 49 +++++++++++----------------------------- vo/friend.go | 1 + 5 files changed, 19 insertions(+), 37 deletions(-) diff --git a/entity/friend.go b/entity/friend.go index 8f8ebd9..626dbe4 100644 --- a/entity/friend.go +++ b/entity/friend.go @@ -31,6 +31,7 @@ type GroupUser struct { HeadImage string `json:"headImage"` // 头像 Nickname string `json:"nickname"` // 昵称 IsMember bool `json:"isMember" gorm:"type:tinyint(1) default 0 not null"` // 是否群成员 + IsAdmin bool `json:"isAdmin" gorm:"type:tinyint(1) default 0 not null"` // 是否群主 JoinTime time.Time `json:"joinTime"` // 加入时间 LeaveTime *time.Time `json:"leaveTime"` // 离开时间 SkipChatRank bool `json:"skipChatRank" gorm:"type:tinyint(1) default 0 not null"` // 是否跳过聊天排行 diff --git a/tasks/friends/friends.go b/tasks/friends/friends.go index 81940df..238a737 100644 --- a/tasks/friends/friends.go +++ b/tasks/friends/friends.go @@ -155,6 +155,7 @@ func syncGroupUsers(tx *gorm.DB, gid string) { Nickname: cp.Nickname, Wxid: cp.Wxid, IsMember: true, + IsAdmin: wxid == baseResp.Data.Admin, JoinTime: time.Now().Local(), }).Error if err != nil { @@ -168,6 +169,7 @@ func syncGroupUsers(tx *gorm.DB, gid string) { "head_image": cp.HeadImage, "nickname": cp.Nickname, "is_member": true, + "is_admin": wxid == baseResp.Data.Admin, "leave_time": nil, } err = tx.Model(&entity.GroupUser{}).Where("group_id = ?", gid).Where("wxid = ?", wxid).Updates(pm).Error diff --git a/views/index.html b/views/index.html index b860fbb..1339217 100644 --- a/views/index.html +++ b/views/index.html @@ -100,7 +100,7 @@ 是否启用AI 是否启用水群排行榜 是否启用迎新 - 是否启用l指令 + 是否启用指令 操作 @@ -201,6 +201,7 @@ 微信Id 昵称 是否群成员 + 是否群主 加群时间 最后活跃时间 退群时间 diff --git a/views/static/js/index.js b/views/static/js/index.js index 804cb08..c01a214 100644 --- a/views/static/js/index.js +++ b/views/static/js/index.js @@ -112,43 +112,20 @@ function getGroupUsers(groupId, groupName) { // 渲染群成员列表 const groupUsers = response.data // 循环渲染数据 - for (let i = 0; i < groupUsers.length; i++) { - const groupUser = groupUsers[i] + groupUsers.forEach((groupUser, i) => { + const { wxid, nickname, isMember, isAdmin, joinTime, lastActiveTime, leaveTime, skipChatRank } = groupUser; - let row = tbody.insertRow(i); // 插入新行 - - // 微信Id - let wxId = row.insertCell(0); - wxId.innerHTML = groupUser.wxid; - - // 昵称 - let nickname = row.insertCell(1); - nickname.innerHTML = groupUser.nickname; - - // 是否群成员 - let isMember = row.insertCell(2); - if (groupUser.isMember) { - isMember.innerHTML = '
'; - } else { - isMember.innerHTML = '
'; - } - - // 加群时间 - let joinTime = row.insertCell(3); - joinTime.innerHTML = groupUser.joinTime; - - // 最后活跃时间 - let lastActiveTime = row.insertCell(4); - lastActiveTime.innerHTML = groupUser.lastActiveTime; - - // 退群时间 - let leaveTime = row.insertCell(5); - leaveTime.innerHTML = groupUser.leaveTime; - - // 是否跳过水群排行榜 - let skipChatRank = row.insertCell(6); - skipChatRank.innerHTML = ``; - } + let row = tbody.insertRow(i); + // Insert data into cells + row.insertCell(0).innerHTML = wxid; + row.insertCell(1).innerHTML = nickname; + row.insertCell(2).innerHTML = `
${isMember ? '是' : '否'}
`; + row.insertCell(3).innerHTML = `
${isAdmin ? '是' : '否'}
`; + row.insertCell(4).innerHTML = joinTime; + row.insertCell(5).innerHTML = lastActiveTime; + row.insertCell(6).innerHTML = leaveTime; + row.insertCell(7).innerHTML = ``; + }); }).catch(function (error) { console.log(`错误信息: ${error}`); }).finally(function () { diff --git a/vo/friend.go b/vo/friend.go index b916565..f8704d2 100644 --- a/vo/friend.go +++ b/vo/friend.go @@ -28,6 +28,7 @@ type GroupUserItem struct { HeadImage string `json:"headImage"` // 头像 Nickname string `json:"nickname"` // 昵称 IsMember bool `json:"isMember" ` // 是否群成员 + IsAdmin bool `json:"isAdmin"` // 是否群主 JoinTime types.DateTime `json:"joinTime"` // 加入时间 LastActiveTime types.DateTime `json:"lastActiveTime"` // 最后活跃时间 LeaveTime types.DateTime `json:"leaveTime"` // 离开时间 -- 2.45.2