diff --git a/cv/group_power_cv/groupPower.go b/cv/group_power_cv/groupPower.go index dc54f16418cc973857dad0390d308cdad4139451..1d1583f525f7b29b05167ed57d5ad4c9bc284142 100644 --- a/cv/group_power_cv/groupPower.go +++ b/cv/group_power_cv/groupPower.go @@ -661,3 +661,10 @@ type FamilyMemberDetail struct { user_cv.CvUserExtend Role groupPower_e.GroupPowerUserRole `json:"role"` } + +type FamilyApplyList struct { + User *user_m.UserTiny `json:"user"` + Time time.Time `json:"time"` + Status int8 `json:"status"` // 0未操作,1已接受,2.已拒绝 + MgrName string `json:"mgrName"` // 管理员名称 +} diff --git a/domain/model/groupPower_m/group_power_apply.go b/domain/model/groupPower_m/group_power_apply.go index 29ea38bd1dc79907ff88a21b6edd1fb0267b7455..1ada06d5c1e194b1c6831b43032816e873c93c10 100644 --- a/domain/model/groupPower_m/group_power_apply.go +++ b/domain/model/groupPower_m/group_power_apply.go @@ -15,6 +15,7 @@ type GroupPowerApplyJoin struct { CreatedTime time.Time `json:"created_time"` UpdatedTime time.Time `json:"updated_time"` IsAccept int8 `json:"is_accept"` + MgrId uint64 `json:"mgr_id"` } func InsertGroupPowerApplyJoin(model *domain.Model, userId, familyId uint64) error { @@ -43,8 +44,8 @@ func GetGroupPowerApplyJoin(model *domain.Model, userId, familyId uint64) (*Grou return res, nil } -func OptGroupPowerApplyJoinById(model *domain.Model, id uint64, optType int) error { - err := model.Db.Exec("update group_power_apply_join set is_accept = ? where id=?", optType, id).Error +func OptGroupPowerApplyJoinById(model *domain.Model, id, mgrId uint64, optType int) error { + err := model.Db.Exec("update group_power_apply_join set is_accept = ?, mgr_id = ? where id=?", optType, mgrId, id).Error if err != nil { return myerr.WrapErr(err) } @@ -58,3 +59,13 @@ func AcceptGroupPowerApplyJoin(model *domain.Model, userId, familyId uint64) err } return nil } + +func OptGroupPowerApplyList(model *domain.Model, familyId uint64, pageSize, pageIndex int) ([]*GroupPowerApplyJoin, error) { + rows := make([]*GroupPowerApplyJoin, 0) + err := model.Db.Model(GroupPowerApplyJoin{}).Where("group_power_id = ?", familyId). + Order("is_accept, created_time desc").Limit(pageSize).Offset(pageIndex - 1).Find(&rows).Error + if err != nil { + return nil, err + } + return rows, nil +} diff --git a/mysql/3.5.0.sql b/mysql/3.5.0.sql index 57294c2ee506362162772bf5d8c672d1024c0050..baa8a18219d6fe1d801aeafb588c2008f4b370bc 100644 --- a/mysql/3.5.0.sql +++ b/mysql/3.5.0.sql @@ -18,7 +18,6 @@ CREATE TABLE `group_power_invite_join` ( KEY `invite_user_id` (`invite_user_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='邀请加入家族'; - CREATE TABLE `group_power_apply_join` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id', `user_id` bigint unsigned NOT NULL COMMENT '申请者id', @@ -26,7 +25,8 @@ CREATE TABLE `group_power_apply_join` ( `created_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `updated_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `is_accept` tinyint NOT NULL DEFAULT '0' COMMENT '是否已经接受', + `mgr_id` bigint unsigned NOT NULL DEFAULT '0' COMMENT '审核的管理员id', PRIMARY KEY (`id`), KEY `group_power_id` (`group_power_id`), KEY `user_id` (`user_id`) USING BTREE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='申请加入家族'; \ No newline at end of file +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='申请加入家族'; \ No newline at end of file diff --git a/route/group_power_r/group_power.go b/route/group_power_r/group_power.go index 2611772e14cddb1679d2cee62673de7c4ff6230e..6a2e8856152ff5d08a969191bb28a2ce99fd89cd 100644 --- a/route/group_power_r/group_power.go +++ b/route/group_power_r/group_power.go @@ -13,6 +13,7 @@ import ( "hilo-group/_const/enum/group_e" "hilo-group/_const/enum/msg_e" "hilo-group/_const/redis_key" + "hilo-group/common" "hilo-group/cv/group_cv" "hilo-group/cv/group_power_cv" "hilo-group/cv/medal_cv" @@ -852,7 +853,7 @@ func GroupPowerMembers(c *gin.Context) (*mycontext.MyContext, error) { // @Summary 申请加入家族 // @Param id formData int true "家族id" // @Success 200 -// @Router /v1/groupPower/applyJoin [post] +// @Router /v1/groupPower/apply [post] func GroupPowerApplyJoin(c *gin.Context) (*mycontext.MyContext, error) { myContext := mycontext.CreateMyContext(c.Keys) userId, err := req.GetUserId(c) @@ -899,7 +900,7 @@ func GroupPowerApplyJoin(c *gin.Context) (*mycontext.MyContext, error) { // @Param userExtId formData string false "用户extId" // @Param type formData int true "1.通过,2.不通过" // @Success 200 -// @Router /v1/groupPower/passApply [post] +// @Router /v1/groupPower/apply/pass [post] func GroupPowerApplyPass(c *gin.Context) (*mycontext.MyContext, error) { myContext := mycontext.CreateMyContext(c.Keys) userId, err := req.GetUserId(c) @@ -940,7 +941,7 @@ func GroupPowerApplyPass(c *gin.Context) (*mycontext.MyContext, error) { if optType == 2 { // 拒绝 // 更改申请表状态 - err = groupPower_m.OptGroupPowerApplyJoinById(model, apply.Id, optType) + err = groupPower_m.OptGroupPowerApplyJoinById(model, apply.Id, userId, optType) if err != nil { return myContext, err } @@ -958,7 +959,7 @@ func GroupPowerApplyPass(c *gin.Context) (*mycontext.MyContext, error) { return err } // 更改申请表状态 - err = groupPower_m.OptGroupPowerApplyJoinById(model, apply.Id, optType) + err = groupPower_m.OptGroupPowerApplyJoinById(model, apply.Id, userId, optType) if err != nil { return err } @@ -971,3 +972,61 @@ func GroupPowerApplyPass(c *gin.Context) (*mycontext.MyContext, error) { resp.ResponseOk(c, nil) return myContext, nil } + +// @Tags 家族 +// @Summary 申请加入列表 +// @Param pageSize query int true "分页大小 默认:10" default(10) +// @Param pageIndex query int true "第几个分页,从1开始 默认:1" default(1) +// @Success 200 +// @Router /v1/groupPower/apply/list [get] +func GroupPowerApplyList(c *gin.Context) (*mycontext.MyContext, error) { + myContext := mycontext.CreateMyContext(c.Keys) + userId, err := req.GetUserId(c) + if err != nil { + return myContext, err + } + pageSize, err := strconv.Atoi(c.Query("pageSize")) + if err != nil { + return myContext, err + } + pageIndex, err := strconv.Atoi(c.Query("pageIndex")) + 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 + } + // 申请列表 + rows, err := groupPower_m.OptGroupPowerApplyList(model, myGroupPUser.GroupPowerId, pageSize, pageIndex) + if err != nil { + return myContext, err + } + + uids := make([]uint64, 0, len(rows)) + for _, v := range rows { + uids = append(uids, v.UserId, v.MgrId) + } + //查找用户信息 + uids = common.UniqueSliceUInt64(uids) + userMap, err := user_c.GetUserTinyMap(domain.CreateModelContext(myContext), uids, true) + + result := make([]*group_power_cv.FamilyApplyList, 0, len(rows)) + for _, v := range rows { + result = append(result, &group_power_cv.FamilyApplyList{User: userMap[v.UserId], Time: v.CreatedTime, Status: v.IsAccept, MgrName: userMap[v.MgrId].Nick}) + } + + resp.ResponseOk(c, result) + return myContext, nil +} diff --git a/route/router.go b/route/router.go index 7a586d67c566ce46ab478f1715e22213c4e396fd..323333888d36bcabb09425e5e24327ab0fc11776 100644 --- a/route/router.go +++ b/route/router.go @@ -129,8 +129,9 @@ func InitRouter() *gin.Engine { groupPower.GET("/info", wrapper(group_power_r.GroupPowerInfo)) groupPower.GET("/rooms", wrapper(group_power_r.GroupPowerRooms)) groupPower.GET("/members", wrapper(group_power_r.GroupPowerMembers)) - groupPower.POST("/applyJoin", wrapper(group_power_r.GroupPowerApplyJoin)) - groupPower.POST("/passApply", wrapper(group_power_r.GroupPowerApplyPass)) + 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)) } charge := v1.Group("/charge")