网页管理基本功能完成

This commit is contained in:
李寻欢 2023-11-30 23:12:38 +08:00
parent 699f10e854
commit 2af0719f51
7 changed files with 157 additions and 47 deletions

View File

@ -2,6 +2,9 @@ package app
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"go-wechat/client"
"go-wechat/entity"
"gorm.io/gorm"
"log" "log"
"net/http" "net/http"
) )
@ -24,6 +27,15 @@ func ChangeEnableAiStatus(ctx *gin.Context) {
} }
log.Printf("待修改的微信Id%s", p.WxId) log.Printf("待修改的微信Id%s", p.WxId)
err := client.MySQL.Model(&entity.Friend{}).
Where("wxid = ?", p.WxId).
Update("`enable_ai`", gorm.Expr(" !`enable_ai`")).Error
if err != nil {
log.Printf("修改是否开启AI失败%s", err)
ctx.String(http.StatusInternalServerError, "操作失败: %s", err)
return
}
ctx.String(http.StatusOK, "操作成功") ctx.String(http.StatusOK, "操作成功")
} }
@ -38,6 +50,15 @@ func ChangeEnableGroupRankStatus(ctx *gin.Context) {
} }
log.Printf("待修改的群Id%s", p.WxId) log.Printf("待修改的群Id%s", p.WxId)
err := client.MySQL.Model(&entity.Friend{}).
Where("wxid = ?", p.WxId).
Update("`enable_chat_rank`", gorm.Expr(" !`enable_chat_rank`")).Error
if err != nil {
log.Printf("修改开启水群排行榜失败:%s", err)
ctx.String(http.StatusInternalServerError, "操作失败: %s", err)
return
}
ctx.String(http.StatusOK, "操作成功") ctx.String(http.StatusOK, "操作成功")
} }
@ -52,5 +73,15 @@ func ChangeSkipGroupRankStatus(ctx *gin.Context) {
} }
log.Printf("待修改的群Id%s -> %s", p.WxId, p.UserId) log.Printf("待修改的群Id%s -> %s", p.WxId, p.UserId)
err := client.MySQL.Model(&entity.GroupUser{}).
Where("group_id = ?", p.WxId).
Where("wxid = ?", p.UserId).
Update("`skip_chat_rank`", gorm.Expr(" !`skip_chat_rank`")).Error
if err != nil {
log.Printf("修改跳过水群排行榜失败:%s", err)
ctx.String(http.StatusInternalServerError, "操作失败: %s", err)
return
}
ctx.String(http.StatusOK, "操作成功") ctx.String(http.StatusOK, "操作成功")
} }

View File

@ -2,8 +2,7 @@ package app
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"go-wechat/client" "go-wechat/service"
"go-wechat/entity"
"net/http" "net/http"
) )
@ -21,11 +20,11 @@ func GetGroupUsers(ctx *gin.Context) {
return return
} }
// 查询数据 // 查询数据
var users []entity.GroupUser records, err := service.GetGroupUsersByGroupId(p.GroupId)
if err := client.MySQL.Where("group_id = ?", p.GroupId).Find(&users).Error; err != nil { if err != nil {
ctx.String(http.StatusInternalServerError, "查询数据失败") ctx.String(http.StatusInternalServerError, "查询失败: %s", err.Error())
return return
} }
// 暂时先就这样写着,跑通了再改 // 暂时先就这样写着,跑通了再改
ctx.JSON(http.StatusOK, users) ctx.JSON(http.StatusOK, records)
} }

25
service/group.go Normal file
View File

@ -0,0 +1,25 @@
package service
import (
"go-wechat/client"
"go-wechat/vo"
)
// GetGroupUsersByGroupId
// @description: 根据群Id取出群成员列表
// @param groupId
// @return records
// @return err
func GetGroupUsersByGroupId(groupId string) (records []vo.GroupUserItem, err error) {
err = client.MySQL.
Table("t_group_user AS tgu").
Joins("LEFT JOIN t_message AS tm ON tm.from_user = tgu.group_id AND tm.group_user = tgu.wxid").
//Select("tgu.wxid", "tgu.nickname", "tgu.head_image", "tgu.is_member", "tgu.leave_time",
// "tgu.skip_chat_rank", "MAX(tm.create_at) AS last_active_time").
Select("tgu.*", "MAX(tm.create_at) AS last_active_time").
Where("tgu.group_id = ?", groupId).
Group("tgu.group_id, tgu.wxid").
Order("tgu.wxid ASC").
Find(&records).Error
return
}

View File

@ -4,8 +4,8 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>水群助手</title> <title>水群助手</title>
<link href="https://cdn.jsdelivr.net/npm/daisyui@4.4.14/dist/full.min.css" rel="stylesheet" type="text/css" /> <!-- <link href="https://cdn.jsdelivr.net/npm/daisyui@4.4.14/dist/full.min.css" rel="stylesheet" type="text/css" />-->
<link href="assets/css/daisyui-4.4.14-full.min.css" rel="stylesheet" type="text/css" />
<link href="assets/css/index.css" rel="stylesheet" type="text/css" /> <link href="assets/css/index.css" rel="stylesheet" type="text/css" />
<script src="https://cdn.tailwindcss.com"></script> <script src="https://cdn.tailwindcss.com"></script>
@ -24,7 +24,7 @@
{{ end }} {{ end }}
<div role="tablist" class="tabs tabs-bordered"> <div role="tablist" class="tabs tabs-bordered">
<input type="radio" name="friend_tab" role="tab" class="tab" aria-label="好友列表" /> <input type="radio" name="friend_tab" role="tab" class="tab" aria-label="好友列表" checked />
<div role="tabpanel" class="tab-content p-6"> <div role="tabpanel" class="tab-content p-6">
<!-- 循环好友列表 --> <!-- 循环好友列表 -->
<table class="table table-zebra"> <table class="table table-zebra">
@ -77,7 +77,7 @@
</table> </table>
</div> </div>
<input type="radio" name="friend_tab" role="tab" class="tab" aria-label="群列表" checked/> <input type="radio" name="friend_tab" role="tab" class="tab" aria-label="群列表" />
<div role="tabpanel" class="tab-content p-6"> <div role="tabpanel" class="tab-content p-6">
<!-- 循环群列表 --> <!-- 循环群列表 -->
<table class="table table-zebra"> <table class="table table-zebra">
@ -135,7 +135,7 @@
</label> </label>
</td> </td>
<td> <td>
<button class="btn btn-link" onclick="getGroupUsers({{.Wxid}})">查看群成员</button> <button class="btn btn-link" onclick="getGroupUsers({{.Wxid}}, {{.Nickname}})">查看群成员</button>
</td> </td>
</tr> </tr>
{{ end }} {{ end }}
@ -148,11 +148,16 @@
</div> </div>
<dialog id="groupUserModal" class="modal"> <dialog id="groupUserModal" class="modal">
<div class="modal-box w-11/12 max-w-5xl"> <div class="modal-box w-11/12 max-w-7xl">
<form method="dialog"> <!-- <form method="dialog">-->
<button class="btn btn-sm btn-circle btn-ghost absolute right-2 top-2"></button> <!-- <button class="btn btn-sm btn-circle btn-ghost absolute right-2 top-2">✕</button>-->
</form> <!-- </form>-->
<h3 class="font-bold text-lg">我是群名称</h3> <h3 class="font-bold text-lg" id="groupUserModalName">我是群名称</h3>
<!-- 加载动画 -->
<div class="divider divider-warning">成员列表</div>
<!-- 好友列表 -->
<table class="table table-zebra"> <table class="table table-zebra">
<!-- head --> <!-- head -->
<thead> <thead>
@ -165,19 +170,10 @@
<th>是否跳过水群排行榜</th> <th>是否跳过水群排行榜</th>
</tr> </tr>
</thead> </thead>
<tbody id="groupUsers"> <tbody id="groupUsers"></tbody>
<tr>
<td>25984982106634049@openim</td>
<td>成员</td>
<td>true</td>
<td>2023-11-30 16:49:42</td>
<td>2023-11-30 16:49:42</td>
<td>
<input type="checkbox" class="toggle toggle-success" onclick="changeUserGroupRankSkipStatus()" />
</td>
</tr>
</tbody>
</table> </table>
</div> </div>
</dialog> </dialog>
</body> </body>

File diff suppressed because one or more lines are too long

View File

@ -2,7 +2,7 @@ console.log("打开首页")
// 改变AI开启状态 // 改变AI开启状态
function changeAiEnableStatus(wxId) { function changeAiEnableStatus(wxId) {
console.log("修改AI开启状态: ", wxId) // console.log("修改AI开启状态: ", wxId)
axios({ axios({
method: 'put', method: 'put',
@ -14,12 +14,13 @@ function changeAiEnableStatus(wxId) {
console.log(`返回结果: ${JSON.stringify(response)}`); console.log(`返回结果: ${JSON.stringify(response)}`);
}).catch(function (error) { }).catch(function (error) {
console.log(`错误信息: ${error}`); console.log(`错误信息: ${error}`);
alert("修改失败")
}) })
} }
// 修改水群排行榜状态 // 修改水群排行榜状态
function changeGroupRankEnableStatus(wxId) { function changeGroupRankEnableStatus(wxId) {
console.log("修改水群排行榜开启状态: ", wxId) // console.log("修改水群排行榜开启状态: ", wxId)
axios({ axios({
method: 'put', method: 'put',
url: '/api/grouprank/status', url: '/api/grouprank/status',
@ -30,6 +31,7 @@ function changeGroupRankEnableStatus(wxId) {
console.log(`返回结果: ${JSON.stringify(response)}`); console.log(`返回结果: ${JSON.stringify(response)}`);
}).catch(function (error) { }).catch(function (error) {
console.log(`错误信息: ${error}`); console.log(`错误信息: ${error}`);
alert("修改失败")
}) })
} }
@ -40,35 +42,44 @@ function changeUserGroupRankSkipStatus(groupId, userId) {
method: 'put', method: 'put',
url: '/api/grouprank/skip', url: '/api/grouprank/skip',
data: { data: {
wxId: wxId, wxId: groupId,
userId: userId userId: userId
} }
}).then(function (response) { }).then(function (response) {
console.log(`返回结果: ${JSON.stringify(response)}`); console.log(`返回结果: ${JSON.stringify(response)}`);
}).catch(function (error) { }).catch(function (error) {
console.log(`错误信息: ${error}`); console.log(`错误信息: ${error}`);
alert("修改失败")
}) })
} }
// 获取群成员列表 // 获取群成员列表
function getGroupUsers(groupId) { function getGroupUsers(groupId, groupName) {
// 获取表格的tbody部分以便稍后向其中添加行
var tbody = document.getElementById("groupUsers");
tbody.innerHTML = ""
// 打开模态框 // 打开模态框
const modal = document.getElementById("groupUserModal"); const modal = document.getElementById("groupUserModal");
modal.showModal() modal.showModal()
// 设置群名称
const groupNameTag = document.getElementById("groupUserModalName");
groupNameTag.innerHTML = '<span class="loading loading-dots loading-lg"></span>'
// 显示加载框
// const loading = document.getElementById("groupUserDataLoading");
// loading.style.display = "block"
axios.get('/api/group/users', { axios.get('/api/group/users', {
params: { params: {
groupId: groupId groupId: groupId
} }
}).then(function (response) { }).then(function (response) {
console.log(`返回结果: ${JSON.stringify(response)}`); // console.log(`返回结果: ${JSON.stringify(response)}`);
// 渲染群成员列表 // 渲染群成员列表
const groupUsers = response.data const groupUsers = response.data
// 循环渲染数据
// const groupUserList = document.getElementById("groupUsers")
// 获取表格的tbody部分以便稍后向其中添加行
var tbody = document.getElementById("groupUsers");
for (let i = 0; i < groupUsers.length; i++) { for (let i = 0; i < groupUsers.length; i++) {
const groupUser = groupUsers[i] const groupUser = groupUsers[i]
@ -76,29 +87,44 @@ function getGroupUsers(groupId) {
// 微信Id // 微信Id
var wxId = row.insertCell(0); var wxId = row.insertCell(0);
wxId.innerHTML = data[i].wxId; wxId.innerHTML = groupUser.wxid;
// 昵称 // 昵称
var nickname = row.insertCell(1); var nickname = row.insertCell(1);
nickname.innerHTML = data[i].wxId; nickname.innerHTML = groupUser.nickname;
// 是否群成员 // 是否群成员
var isMember = row.insertCell(2); var isMember = row.insertCell(2);
isMember.innerHTML = data[i].wxId; if (groupUser.isMember) {
isMember.innerHTML = '<div class="badge badge-info gap-2">是</div>';
} else {
isMember.innerHTML = '<div class="badge badge-error gap-2">否</div>';
}
// 最后活跃时间 // 最后活跃时间
var wxId = row.insertCell(3); var lastActiveTime = row.insertCell(3);
wxId.innerHTML = data[i].wxId; lastActiveTime.innerHTML = groupUser.lastActiveTime;
// 退群时间 // 退群时间
var wxId = row.insertCell(4); var leaveTime = row.insertCell(4);
wxId.innerHTML = data[i].wxId; leaveTime.innerHTML = groupUser.leaveTime;
// 是否跳过水群排行榜 // 是否跳过水群排行榜
var wxId = row.insertCell(5); var skipChatRank = row.insertCell(5);
wxId.innerHTML = data[i].wxId; let skipChatRankHtml = `<input type="checkbox" class="toggle toggle-error" ${groupUser.skipChatRank ? 'checked' : ''} onclick="changeUserGroupRankSkipStatus(\'${groupId}\', \'${groupUser.wxid}\')" />`
skipChatRank.innerHTML = skipChatRankHtml;
// if (groupUser.skipChatRank) {
//
// } else {
// skipChatRank.innerHTML = '<input type="checkbox" class="toggle toggle-error" />';
// }
} }
}).catch(function (error) { }).catch(function (error) {
console.log(`错误信息: ${error}`); console.log(`错误信息: ${error}`);
}).finally(function () {
// 隐藏加载框
// loading.style.display = "none"
groupNameTag.innerHTML = groupName
}) })
} }

View File

@ -17,3 +17,16 @@ type FriendItem struct {
IsOk bool // 是否还在通讯库(群聊是要还在群里也算) IsOk bool // 是否还在通讯库(群聊是要还在群里也算)
LastActiveTime types.DateTime // 最后活跃时间 LastActiveTime types.DateTime // 最后活跃时间
} }
// GroupUserItem
// @description: 群成员列表数据
type GroupUserItem struct {
Wxid string `json:"wxid"` // 微信Id
Account string `json:"account"` // 账号
HeadImage string `json:"headImage"` // 头像
Nickname string `json:"nickname"` // 昵称
IsMember bool `json:"isMember" ` // 是否群成员
LastActiveTime types.DateTime `json:"lastActiveTime"` // 最后活跃时间
LeaveTime types.DateTime `json:"leaveTime"` // 离开时间
SkipChatRank bool `json:"skipChatRank" ` // 是否跳过聊天排行
}