|
@@ -3,15 +3,20 @@ package member_center |
|
|
import ( |
|
|
import ( |
|
|
"applet/app/db" |
|
|
"applet/app/db" |
|
|
"applet/app/e" |
|
|
"applet/app/e" |
|
|
|
|
|
md2 "applet/app/md" |
|
|
"applet/app/md/member_center" |
|
|
"applet/app/md/member_center" |
|
|
svc2 "applet/app/svc" |
|
|
svc2 "applet/app/svc" |
|
|
svc "applet/app/svc/member_center" |
|
|
svc "applet/app/svc/member_center" |
|
|
"applet/app/utils" |
|
|
"applet/app/utils" |
|
|
|
|
|
"applet/app/utils/cache" |
|
|
"code.fnuoos.com/EggPlanet/egg_models.git/src/implement" |
|
|
"code.fnuoos.com/EggPlanet/egg_models.git/src/implement" |
|
|
|
|
|
"code.fnuoos.com/EggPlanet/egg_models.git/src/model" |
|
|
|
|
|
"code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" |
|
|
"errors" |
|
|
"errors" |
|
|
"fmt" |
|
|
"fmt" |
|
|
"github.com/gin-gonic/gin" |
|
|
"github.com/gin-gonic/gin" |
|
|
"strings" |
|
|
"strings" |
|
|
|
|
|
"time" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
// UserManagementGetUserList |
|
|
// UserManagementGetUserList |
|
@@ -180,6 +185,261 @@ func UserManagementUpdateUserInfo(c *gin.Context) { |
|
|
e.OutSuc(c, affected, nil) |
|
|
e.OutSuc(c, affected, nil) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// UserManagementGetUserRecycleList |
|
|
|
|
|
// @Summary 会员中心-用户管理-回收站列表 |
|
|
|
|
|
// @Tags 会员中心 |
|
|
|
|
|
// @Description 回收站列表 |
|
|
|
|
|
// @Accept json |
|
|
|
|
|
// @Produce json |
|
|
|
|
|
// @param Authorization header string true "验证参数Bearer和token空格拼接" |
|
|
|
|
|
// @Param req body md.UserManagementGetUserListReq true "分页信息必填" |
|
|
|
|
|
// @Success 200 {object} md.UserManagementGetUserListResp "具体数据" |
|
|
|
|
|
// @Failure 400 {object} md.Response "具体错误" |
|
|
|
|
|
// @Router /api/memberCenter/userManagement/userRecycleList [post] |
|
|
|
|
|
func UserManagementGetUserRecycleList(c *gin.Context) { |
|
|
|
|
|
var req *md.UserManagementGetUserListReq |
|
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil { |
|
|
|
|
|
e.OutErr(c, e.ERR_INVALID_ARGS, err.Error()) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
req.IsRecycle = "1" |
|
|
|
|
|
levelDb := implement.NewUserLevelDb(db.Db) |
|
|
|
|
|
levels, err1 := levelDb.UserLevelAllByAsc() |
|
|
|
|
|
if err1 != nil { |
|
|
|
|
|
e.OutErr(c, e.ERR_DB_ORM, err1.Error()) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
levelsList := make([]map[string]interface{}, 0) |
|
|
|
|
|
levelsMap := make(map[int]string) |
|
|
|
|
|
for _, level := range levels { |
|
|
|
|
|
levelsList = append(levelsList, map[string]interface{}{ |
|
|
|
|
|
"id": level.Id, |
|
|
|
|
|
"name": level.LevelName, |
|
|
|
|
|
}) |
|
|
|
|
|
levelsMap[level.Id] = level.LevelName |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
tagDb := implement.NewUserTagDb(db.Db) |
|
|
|
|
|
tags, err2 := tagDb.UserTagAllByAsc() |
|
|
|
|
|
if err2 != nil { |
|
|
|
|
|
e.OutErr(c, e.ERR_DB_ORM, err2.Error()) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
tagsList := make([]map[string]interface{}, 0) |
|
|
|
|
|
tagsMap := make(map[int]string) |
|
|
|
|
|
for _, tag := range tags { |
|
|
|
|
|
tagsList = append(tagsList, map[string]interface{}{ |
|
|
|
|
|
"id": tag.Id, |
|
|
|
|
|
"name": tag.TagName, |
|
|
|
|
|
}) |
|
|
|
|
|
tagsMap[tag.Id] = tag.TagName |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
stateList := []map[string]interface{}{ |
|
|
|
|
|
{ |
|
|
|
|
|
"name": "正常", |
|
|
|
|
|
"value": "1", |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
"name": "冻结", |
|
|
|
|
|
"value": "2", |
|
|
|
|
|
}, |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
users, total, err3 := svc.UserManagementGetUsers(req) |
|
|
|
|
|
if err3 != nil { |
|
|
|
|
|
e.OutErr(c, e.ERR_DB_ORM, err3.Error()) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
userIDs := make([]int64, len(users)) |
|
|
|
|
|
for i, user := range users { |
|
|
|
|
|
userIDs[i] = user.Id |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
recordsDb := implement.NewUserTagRecordsDb(db.Db) |
|
|
|
|
|
records, err := recordsDb.UserTagRecordsFindByParams(map[string]interface{}{ |
|
|
|
|
|
"key": "uid", |
|
|
|
|
|
"value": userIDs, |
|
|
|
|
|
}) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
e.OutErr(c, e.ERR_DB_ORM, err.Error()) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var levelCounts []md.LevelCount |
|
|
|
|
|
err4 := db.Db.Table("user").Select("level, Count(*) AS count").GroupBy("level").Find(&levelCounts) |
|
|
|
|
|
if err4 != nil { |
|
|
|
|
|
e.OutErr(c, e.ERR_DB_ORM, err4.Error()) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
userMap := make(map[int64]int, len(users)) |
|
|
|
|
|
list := make([]md.UserManagementGetUserListNode, len(users)) |
|
|
|
|
|
for i, user := range users { |
|
|
|
|
|
list[i] = md.UserManagementGetUserListNode{ |
|
|
|
|
|
ID: user.Id, |
|
|
|
|
|
Sex: user.Sex, |
|
|
|
|
|
Avatar: svc2.GetOssUrl(user.Avatar), |
|
|
|
|
|
Nickname: user.Nickname, |
|
|
|
|
|
Phone: user.Phone, |
|
|
|
|
|
IsRealName: user.IsRealName, |
|
|
|
|
|
InviteCode: user.SystemInviteCode, |
|
|
|
|
|
ParentID: user.ParentUid, |
|
|
|
|
|
ParentInviteCode: user.ParentSystemInviteCode, |
|
|
|
|
|
ParentPhone: user.ParentPhone, |
|
|
|
|
|
RegisterTime: user.CreateAt, |
|
|
|
|
|
Memo: user.Memo, |
|
|
|
|
|
Wechat: user.UnionId, |
|
|
|
|
|
RegisterType: user.RegisterType, |
|
|
|
|
|
State: user.State, |
|
|
|
|
|
LastLoginAt: user.UpdateAt, |
|
|
|
|
|
} |
|
|
|
|
|
var tempTagList []md.TagNode |
|
|
|
|
|
list[i].Tag = tempTagList |
|
|
|
|
|
userMap[user.Id] = i |
|
|
|
|
|
level, ok := levelsMap[user.Level] |
|
|
|
|
|
if ok { |
|
|
|
|
|
list[i].LevelName = level |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for _, record := range *records { |
|
|
|
|
|
tempTagNode := md.TagNode{ |
|
|
|
|
|
TagID: record.TagId, |
|
|
|
|
|
TagName: tagsMap[record.TagId], |
|
|
|
|
|
} |
|
|
|
|
|
list[userMap[record.Uid]].Tag = append(list[userMap[record.Uid]].Tag, tempTagNode) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
resp := md.UserManagementGetUserListResp{ |
|
|
|
|
|
LevelsList: levelsList, |
|
|
|
|
|
TagsList: tagsList, |
|
|
|
|
|
StateList: stateList, |
|
|
|
|
|
List: list, |
|
|
|
|
|
Paginate: md.Paginate{ |
|
|
|
|
|
Limit: req.Limit, |
|
|
|
|
|
Page: req.Page, |
|
|
|
|
|
Total: total, |
|
|
|
|
|
}, |
|
|
|
|
|
} |
|
|
|
|
|
e.OutSuc(c, resp, nil) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// UserManagementUserRecycle |
|
|
|
|
|
// @Summary 会员中心-用户管理-删除到回收站 |
|
|
|
|
|
// @Tags 会员中心 |
|
|
|
|
|
// @Description 删除到回收站 |
|
|
|
|
|
// @Accept json |
|
|
|
|
|
// @Produce json |
|
|
|
|
|
// @param Authorization header string true "验证参数Bearer和token空格拼接" |
|
|
|
|
|
// @Param req body md.UserManagementUserInfoReq true "用户ID 必传" |
|
|
|
|
|
// @Success 200 {int} "修改数据行数" |
|
|
|
|
|
// @Failure 400 {object} md.Response "具体错误" |
|
|
|
|
|
// @Router /api/memberCenter/userManagement/userRecycle [post] |
|
|
|
|
|
func UserManagementUserRecycle(c *gin.Context) { |
|
|
|
|
|
var req *md.UserManagementUserInfoReq |
|
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil { |
|
|
|
|
|
e.OutErr(c, e.ERR_INVALID_ARGS, err.Error()) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
NewUserDb := implement.NewUserDb(db.Db) |
|
|
|
|
|
user, _ := NewUserDb.GetUser(utils.StrToInt64(req.UID)) |
|
|
|
|
|
if user == nil { |
|
|
|
|
|
e.OutErr(c, 400, e.NewErr(400, "用户不存在")) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
user.State = 4 |
|
|
|
|
|
db.Db.Where("id=?", user.Id).Cols("state").Update(user) |
|
|
|
|
|
admin := svc2.GetUser(c) |
|
|
|
|
|
svc2.AddAdminLog(c, admin.AdmId, "用户回收", "用户id:"+utils.Int64ToStr(user.Id)+",用户手机号:"+user.Phone+" 删除到回收站", utils.SerializeStr(user)) |
|
|
|
|
|
e.OutSuc(c, "success", nil) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// UserManagementUserRecycleCancel |
|
|
|
|
|
// @Summary 会员中心-用户管理-恢复到会员列表 |
|
|
|
|
|
// @Tags 会员中心 |
|
|
|
|
|
// @Description 恢复到会员列表 |
|
|
|
|
|
// @Accept json |
|
|
|
|
|
// @Produce json |
|
|
|
|
|
// @param Authorization header string true "验证参数Bearer和token空格拼接" |
|
|
|
|
|
// @Param req body md.UserManagementUserInfoReq true "用户ID 必传" |
|
|
|
|
|
// @Success 200 {int} "修改数据行数" |
|
|
|
|
|
// @Failure 400 {object} md.Response "具体错误" |
|
|
|
|
|
// @Router /api/memberCenter/userManagement/userRecycleCancel [post] |
|
|
|
|
|
func UserManagementUserRecycleCancel(c *gin.Context) { |
|
|
|
|
|
var req *md.UserManagementUserInfoReq |
|
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil { |
|
|
|
|
|
e.OutErr(c, e.ERR_INVALID_ARGS, err.Error()) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
NewUserDb := implement.NewUserDb(db.Db) |
|
|
|
|
|
user, _ := NewUserDb.GetUser(utils.StrToInt64(req.UID)) |
|
|
|
|
|
if user == nil { |
|
|
|
|
|
e.OutErr(c, 400, e.NewErr(400, "用户不存在")) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
user.State = 1 |
|
|
|
|
|
db.Db.Where("id=?", user.Id).Cols("state").Update(user) |
|
|
|
|
|
admin := svc2.GetUser(c) |
|
|
|
|
|
svc2.AddAdminLog(c, admin.AdmId, "用户恢复", "用户id:"+utils.Int64ToStr(user.Id)+",用户手机号:"+user.Phone+" 恢复到会员列表", utils.SerializeStr(user)) |
|
|
|
|
|
e.OutSuc(c, "success", nil) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// UserManagementUserDelete |
|
|
|
|
|
// @Summary 会员中心-用户管理-永久删除 |
|
|
|
|
|
// @Tags 会员中心 |
|
|
|
|
|
// @Description 删除到回收站 |
|
|
|
|
|
// @Accept json |
|
|
|
|
|
// @Produce json |
|
|
|
|
|
// @param Authorization header string true "验证参数Bearer和token空格拼接" |
|
|
|
|
|
// @Param req body md.UserManagementUserInfoReq true "用户ID 必传" |
|
|
|
|
|
// @Success 200 {int} "修改数据行数" |
|
|
|
|
|
// @Failure 400 {object} md.Response "具体错误" |
|
|
|
|
|
// @Router /api/memberCenter/userManagement/userDelete [post] |
|
|
|
|
|
func UserManagementUserDelete(c *gin.Context) { |
|
|
|
|
|
var req *md.UserManagementUserInfoReq |
|
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil { |
|
|
|
|
|
e.OutErr(c, e.ERR_INVALID_ARGS, err.Error()) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
NewUserDb := implement.NewUserDb(db.Db) |
|
|
|
|
|
user, _ := NewUserDb.GetUser(utils.StrToInt64(req.UID)) |
|
|
|
|
|
if user == nil { |
|
|
|
|
|
e.OutErr(c, 400, e.NewErr(400, "用户不存在")) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
if user.State != 4 { |
|
|
|
|
|
e.OutErr(c, 400, e.NewErr(400, "不能删除")) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
user.State = 3 |
|
|
|
|
|
db.Db.Where("id=?", user.Id).Cols("state").Update(user) |
|
|
|
|
|
tmp := model.UserDeleteInfo{ |
|
|
|
|
|
Uid: int(user.Id), |
|
|
|
|
|
Phone: user.Phone, |
|
|
|
|
|
CreateAt: time.Now(), |
|
|
|
|
|
} |
|
|
|
|
|
db.Db.Insert(&tmp) |
|
|
|
|
|
ch, err := rabbit.Cfg.Pool.GetChannel() |
|
|
|
|
|
if err == nil { |
|
|
|
|
|
defer ch.Release() |
|
|
|
|
|
err = ch.PublishV2(md2.EggUserExchange, md2.CommUserId{ |
|
|
|
|
|
Uid: utils.Int64ToStr(user.Id), |
|
|
|
|
|
}, md2.EggUserDelete) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
ch.PublishV2(md2.EggUserExchange, md2.CommUserId{ |
|
|
|
|
|
Uid: utils.Int64ToStr(user.Id), |
|
|
|
|
|
}, md2.EggUserDelete) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
// 清掉token |
|
|
|
|
|
cacheKey := fmt.Sprintf("egg_app_jwt_token:%d", user.Id) |
|
|
|
|
|
_, err = cache.SetEx(cacheKey, "", 1) |
|
|
|
|
|
admin := svc2.GetUser(c) |
|
|
|
|
|
svc2.AddAdminLog(c, admin.AdmId, "用户永久删除", "用户id:"+utils.Int64ToStr(user.Id)+",用户手机号:"+user.Phone+" 永久删除", utils.SerializeStr(user)) |
|
|
|
|
|
e.OutSuc(c, "success", nil) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// UserManagementGetOneBasic |
|
|
// UserManagementGetOneBasic |
|
|
// @Summary 制度中心-会员中心-用户管理-会员明细概况(获取) |
|
|
// @Summary 制度中心-会员中心-用户管理-会员明细概况(获取) |
|
|
// @Tags 会员中心 |
|
|
// @Tags 会员中心 |
|
|