From 1b380be0e4600c3ac38238251e52b970d934f234 Mon Sep 17 00:00:00 2001 From: hujiebin Date: Fri, 31 Mar 2023 14:59:37 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E8=8E=B7=E5=8F=96=E5=AE=B6=E6=97=8F?= =?UTF-8?q?=E7=94=B3=E8=AF=B7=E4=BA=BA=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/groupPower_m/group_power_apply.go | 14 ++++++++ route/group_power_r/group_power.go | 35 +++++++++++++++++++ route/router.go | 1 + 3 files changed, 50 insertions(+) diff --git a/domain/model/groupPower_m/group_power_apply.go b/domain/model/groupPower_m/group_power_apply.go index 9d09a20..5bed0f2 100644 --- a/domain/model/groupPower_m/group_power_apply.go +++ b/domain/model/groupPower_m/group_power_apply.go @@ -2,6 +2,7 @@ package groupPower_m import ( "git.hilo.cn/hilo-common/domain" + "git.hilo.cn/hilo-common/resource/mysql" "gorm.io/gorm" "hilo-group/common" "hilo-group/myerr" @@ -88,3 +89,16 @@ func DelGroupPowerApplyJoinNoDeal(model *domain.Model, userId uint64) error { } return nil } + +// 获取家族申请人数 +// param: isAccept 0:未审核 1:通过 2:拒绝 +func CountGroupPowerApply(model *domain.Model, groupPowerId mysql.ID, isAccept int) (int64, error) { + var cnt int64 + if err := model.DB().Model(GroupPowerApplyJoin{}). + Where("group_power_id = ?", groupPowerId). + Where("is_accept = ?", isAccept).Count(&cnt).Error; err != nil { + model.Log.Errorf("CountGroupPowerApply fail:%v", err) + return cnt, err + } + return cnt, nil +} diff --git a/route/group_power_r/group_power.go b/route/group_power_r/group_power.go index a018a76..a809c38 100644 --- a/route/group_power_r/group_power.go +++ b/route/group_power_r/group_power.go @@ -1223,6 +1223,41 @@ func GroupPowerApplyList(c *gin.Context) (*mycontext.MyContext, error) { return myContext, nil } +// @Tags 家族 +// @Summary 申请人数 +// @Success 200 {object} int +// @Router /v1/groupPower/apply/count [get] +func GroupPowerApplyCount(c *gin.Context) (*mycontext.MyContext, error) { + myContext := mycontext.CreateMyContext(c.Keys) + userId, err := req.GetUserId(c) + if err != nil { + return myContext, err + } + model := domain.CreateModelContext(myContext) + + // 判断是否加入了家族 + gpU := groupPower_m.GroupPowerUser{UserId: userId} + myGroupPUser, err := gpU.GetGroupPowerUser(model) + if err != nil { + return myContext, err + } + // 操作者是否加入了家族,是否有操作权限 + if myGroupPUser == nil || myGroupPUser.ID == 0 { + return myContext, bizerr.GroupPowerHaveNoJoin + } + if myGroupPUser.Role == 0 || myGroupPUser.Role == groupPower_e.GroupPowerUserRoleUser { + return myContext, bizerr.GroupPowerHaveNoPower + } + // 申请人数 + cnt, err := groupPower_m.CountGroupPowerApply(model, myGroupPUser.GroupPowerId, 0) + if err != nil { + return myContext, err + } + + resp.ResponseOk(c, cnt) + return myContext, nil +} + // @Tags 家族 // @Summary 退出/踢出家族 // @Param type formData int true "1.自己退出,2.踢人" diff --git a/route/router.go b/route/router.go index 19d523c..9dd0d47 100644 --- a/route/router.go +++ b/route/router.go @@ -133,6 +133,7 @@ func InitRouter() *gin.Engine { groupPower.POST("/apply", wrapper(group_power_r.GroupPowerApplyJoin)) groupPower.POST("/apply/pass", wrapper(group_power_r.GroupPowerApplyPass)) groupPower.GET("/apply/list", wrapper(group_power_r.GroupPowerApplyList)) + groupPower.GET("/apply/count", wrapper(group_power_r.GroupPowerApplyCount)) groupPower.POST("/quit", wrapper(group_power_r.GroupPowerQuit)) groupPower.GET("/quit/list", wrapper(group_power_r.GroupPowerQuitList)) groupPower.POST("/admin", wrapper(group_power_r.GroupPowerSetAdmin)) -- 2.22.0