1
0
Fork 0

网页管理基本功能完成

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 (
"github.com/gin-gonic/gin"
"go-wechat/client"
"go-wechat/entity"
"gorm.io/gorm"
"log"
"net/http"
)
@ -24,6 +27,15 @@ func ChangeEnableAiStatus(ctx *gin.Context) {
}
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, "操作成功")
}
@ -38,6 +50,15 @@ func ChangeEnableGroupRankStatus(ctx *gin.Context) {
}
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, "操作成功")
}
@ -52,5 +73,15 @@ func ChangeSkipGroupRankStatus(ctx *gin.Context) {
}
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, "操作成功")
}

View File

@ -2,8 +2,7 @@ package app
import (
"github.com/gin-gonic/gin"
"go-wechat/client"
"go-wechat/entity"
"go-wechat/service"
"net/http"
)
@ -21,11 +20,11 @@ func GetGroupUsers(ctx *gin.Context) {
return
}
// 查询数据
var users []entity.GroupUser
if err := client.MySQL.Where("group_id = ?", p.GroupId).Find(&users).Error; err != nil {
ctx.String(http.StatusInternalServerError, "查询数据失败")
records, err := service.GetGroupUsersByGroupId(p.GroupId)
if err != nil {
ctx.String(http.StatusInternalServerError, "查询失败: %s", err.Error())
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">
<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" />
<script src="https://cdn.tailwindcss.com"></script>
@ -24,7 +24,7 @@
{{ end }}
<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">
<!-- 循环好友列表 -->
<table class="table table-zebra">
@ -77,7 +77,7 @@
</table>
</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">
<!-- 循环群列表 -->
<table class="table table-zebra">
@ -135,7 +135,7 @@
</label>
</td>
<td>
<button class="btn btn-link" onclick="getGroupUsers({{.Wxid}})">查看群成员</button>
<button class="btn btn-link" onclick="getGroupUsers({{.Wxid}}, {{.Nickname}})">查看群成员</button>
</td>
</tr>
{{ end }}
@ -148,11 +148,16 @@
</div>
<dialog id="groupUserModal" class="modal">
<div class="modal-box w-11/12 max-w-5xl">
<form method="dialog">
<button class="btn btn-sm btn-circle btn-ghost absolute right-2 top-2"></button>
</form>
<h3 class="font-bold text-lg">我是群名称</h3>
<div class="modal-box w-11/12 max-w-7xl">
<!-- <form method="dialog">-->
<!-- <button class="btn btn-sm btn-circle btn-ghost absolute right-2 top-2">✕</button>-->
<!-- </form>-->
<h3 class="font-bold text-lg" id="groupUserModalName">我是群名称</h3>
<!-- 加载动画 -->
<div class="divider divider-warning">成员列表</div>
<!-- 好友列表 -->
<table class="table table-zebra">
<!-- head -->
<thead>
@ -165,19 +170,10 @@
<th>是否跳过水群排行榜</th>
</tr>
</thead>
<tbody id="groupUsers">
<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>
<tbody id="groupUsers"></tbody>
</table>
</div>
</dialog>
</body>

File diff suppressed because one or more lines are too long

View File

@ -2,7 +2,7 @@ console.log("打开首页")
// 改变AI开启状态
function changeAiEnableStatus(wxId) {
console.log("修改AI开启状态: ", wxId)
// console.log("修改AI开启状态: ", wxId)
axios({
method: 'put',
@ -14,12 +14,13 @@ function changeAiEnableStatus(wxId) {
console.log(`返回结果: ${JSON.stringify(response)}`);
}).catch(function (error) {
console.log(`错误信息: ${error}`);
alert("修改失败")
})
}
// 修改水群排行榜状态
function changeGroupRankEnableStatus(wxId) {
console.log("修改水群排行榜开启状态: ", wxId)
// console.log("修改水群排行榜开启状态: ", wxId)
axios({
method: 'put',
url: '/api/grouprank/status',
@ -30,6 +31,7 @@ function changeGroupRankEnableStatus(wxId) {
console.log(`返回结果: ${JSON.stringify(response)}`);
}).catch(function (error) {
console.log(`错误信息: ${error}`);
alert("修改失败")
})
}
@ -40,35 +42,44 @@ function changeUserGroupRankSkipStatus(groupId, userId) {
method: 'put',
url: '/api/grouprank/skip',
data: {
wxId: wxId,
wxId: groupId,
userId: userId
}
}).then(function (response) {
console.log(`返回结果: ${JSON.stringify(response)}`);
}).catch(function (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");
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', {
params: {
groupId: groupId
}
}).then(function (response) {
console.log(`返回结果: ${JSON.stringify(response)}`);
// console.log(`返回结果: ${JSON.stringify(response)}`);
// 渲染群成员列表
const groupUsers = response.data
// const groupUserList = document.getElementById("groupUsers")
// 获取表格的tbody部分以便稍后向其中添加行
var tbody = document.getElementById("groupUsers");
// 循环渲染数据
for (let i = 0; i < groupUsers.length; i++) {
const groupUser = groupUsers[i]
@ -76,29 +87,44 @@ function getGroupUsers(groupId) {
// 微信Id
var wxId = row.insertCell(0);
wxId.innerHTML = data[i].wxId;
wxId.innerHTML = groupUser.wxid;
// 昵称
var nickname = row.insertCell(1);
nickname.innerHTML = data[i].wxId;
nickname.innerHTML = groupUser.nickname;
// 是否群成员
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);
wxId.innerHTML = data[i].wxId;
var lastActiveTime = row.insertCell(3);
lastActiveTime.innerHTML = groupUser.lastActiveTime;
// 退群时间
var wxId = row.insertCell(4);
wxId.innerHTML = data[i].wxId;
var leaveTime = row.insertCell(4);
leaveTime.innerHTML = groupUser.leaveTime;
// 是否跳过水群排行榜
var wxId = row.insertCell(5);
wxId.innerHTML = data[i].wxId;
var skipChatRank = row.insertCell(5);
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) {
console.log(`错误信息: ${error}`);
}).finally(function () {
// 隐藏加载框
// loading.style.display = "none"
groupNameTag.innerHTML = groupName
})
}

View File

@ -17,3 +17,16 @@ type FriendItem struct {
IsOk bool // 是否还在通讯库(群聊是要还在群里也算)
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" ` // 是否跳过聊天排行
}