diff --git a/app/friend.go b/app/friend.go index 3b00687..e78bee9 100644 --- a/app/friend.go +++ b/app/friend.go @@ -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, "操作成功") } diff --git a/app/group.go b/app/group.go index 394443f..9b22f93 100644 --- a/app/group.go +++ b/app/group.go @@ -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) } diff --git a/service/group.go b/service/group.go new file mode 100644 index 0000000..2e7ea9d --- /dev/null +++ b/service/group.go @@ -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 +} diff --git a/views/index.html b/views/index.html index 4e925d2..5e84bf4 100644 --- a/views/index.html +++ b/views/index.html @@ -4,8 +4,8 @@
- + | {{ end }} @@ -148,11 +148,16 @@