Commit 1db367a3 authored by chenweijian's avatar chenweijian

申请加入家族

parent 5bce9bff
......@@ -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"` // 管理员名称
}
......@@ -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
}
......@@ -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
......@@ -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
}
......@@ -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")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment