🎨 新增vip用户管理接口
This commit is contained in:
@@ -196,3 +196,43 @@ func (a *UserApi) GetLoginLog(context *gin.Context) {
|
||||
PageSize: p.PageSize,
|
||||
}, "获取登录日志成功", context)
|
||||
}
|
||||
|
||||
// RemoveUserVip 移除用户Vip
|
||||
func (a *UserApi) RemoveUserVip(context *gin.Context) {
|
||||
var p common.GetById
|
||||
if err := context.ShouldBind(&p); err != nil {
|
||||
global.GVA_LOG.Error("参数错误,移除用户Vip失败", zap.Error(err))
|
||||
r.FailWithMessage("参数错误,移除用户Vip失败", context)
|
||||
return
|
||||
}
|
||||
|
||||
if err := userService.RemoveUserVip(p.ID); err != nil {
|
||||
global.GVA_LOG.Error("移除用户Vip失败", zap.Error(err))
|
||||
r.FailWithMessage("移除用户Vip失败", context)
|
||||
return
|
||||
}
|
||||
r.OkWithMessage("移除用户Vip成功", context)
|
||||
}
|
||||
|
||||
func (a *UserApi) GetUserVipList(context *gin.Context) {
|
||||
var p request.GetUserListReq
|
||||
if err := context.ShouldBind(&p); err != nil {
|
||||
global.GVA_LOG.Error("参数错误,获取用户会员列表失败", zap.Error(err))
|
||||
r.FailWithMessage("参数错误,获取用户会员列表失败", context)
|
||||
return
|
||||
}
|
||||
|
||||
list, total, err := userService.GetUserVipList(p)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("获取用户会员列表失败", zap.Error(err))
|
||||
r.FailWithMessage("获取用户会员列表失败", context)
|
||||
return
|
||||
}
|
||||
|
||||
r.OkWithDetailed(r.PageResult{
|
||||
List: list,
|
||||
Total: total,
|
||||
Page: p.Page,
|
||||
PageSize: p.PageSize,
|
||||
}, "获取用户会员列表成功", context)
|
||||
}
|
||||
|
@@ -16,7 +16,7 @@ type User struct {
|
||||
InviteCode *string `json:"invite_code" form:"invite_code" gorm:"type:varchar(255) comment '用户专属邀请码'"`
|
||||
Balance float32 `json:"balance" form:"balance" gorm:"type:decimal(10,2);comment:学员余额"`
|
||||
CommenderId int `json:"commender_id" form:"commender_id" gorm:"comment:推荐人ID"`
|
||||
UserLabel int64 `json:"user_label" form:"user_label" gorm:"comment:用户标签 1 普通用户 2 Vip 3 Svip"`
|
||||
UserLabel int64 `json:"user_label" form:"user_label" gorm:"comment:用户标签 1 普通用户 2 Vip 3 Svip 4 到期会员"`
|
||||
UserType int8 `gorm:"column:user_type;default:1;NOT NULL;comment:'用户类型 1 用户 2 讲师'" json:"user_type" form:"user_type" `
|
||||
IsVip int8 `gorm:"column:is_vip;default:0;NOT NULL;comment:'是否是VIP 0 否 1 是'" json:"is_vip" form:"is_vip"`
|
||||
VipExpireTime string `json:"vip_expire_time" form:"vip_expire_time" gorm:"comment:VIP过期时间"`
|
||||
|
@@ -21,5 +21,7 @@ func (s *UserRouter) InitUserRouter(Router *gin.RouterGroup, PublicRouter *gin.R
|
||||
userRouter.GET("/teacherApplyList", userApi.GetTeacherApplyList) // 获取教师申请列表
|
||||
userRouter.PUT("/teacherApply/status", userApi.UpdateTeacherApplyStatus) // 更新教师申请状态
|
||||
userRouter.GET("/login/log", userApi.GetLoginLog) // 获取用户登录日志
|
||||
userRouter.DELETE("/vip", userApi.RemoveUserVip) // 删除用户会员
|
||||
userRouter.GET("/vip/list", userApi.GetUserVipList) // 获取用户会员列表
|
||||
}
|
||||
}
|
||||
|
@@ -272,3 +272,49 @@ func (u *UserService) GetLoginLog(p request.GetUserListReq) (list []user.LoginLo
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (u *UserService) RemoveUserVip(id int) error {
|
||||
var user user.User
|
||||
err := global.GVA_DB.Model(&user).Where("id = ?", id).First(&user).Error
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("查询用户信息失败", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
user.IsVip = 0
|
||||
user.UserLabel = 1
|
||||
user.VipExpireTime = ""
|
||||
|
||||
err = global.GVA_DB.Save(&user).Error
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("移除用户VIP失败", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *UserService) GetUserVipList(p request.GetUserListReq) (list []vo.UserInfo, total int64, err error) {
|
||||
limit := p.PageSize
|
||||
offset := (p.Page - 1) * p.PageSize
|
||||
db := global.GVA_DB.Model(&user.User{}).Where("is_vip = ? and status = 1", 1)
|
||||
|
||||
if p.Name != "" {
|
||||
db = db.Where("nick_name LIKE ?", "%"+p.Name+"%")
|
||||
}
|
||||
|
||||
if p.UserId != 0 {
|
||||
db = db.Where("id = ?", p.UserId)
|
||||
}
|
||||
|
||||
err = db.Count(&total).Error
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("查询用户会员总数失败", zap.Error(err))
|
||||
return nil, 0, err
|
||||
}
|
||||
err = db.Limit(limit).Offset(offset).Order("created_at desc").Find(&list).Error
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("查询用户会员列表失败", zap.Error(err))
|
||||
return nil, 0, err
|
||||
}
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user