|
- package member_center
-
- import (
- "applet/app/db"
- "applet/app/e"
- md2 "applet/app/md"
- "applet/app/md/member_center"
- svc2 "applet/app/svc"
- svc "applet/app/svc/member_center"
- "applet/app/svc/sys_cfg"
- "applet/app/utils"
- "applet/app/utils/cache"
- "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
- "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
- "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum"
- md3 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md"
- "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit"
- "errors"
- "fmt"
- "github.com/gin-gonic/gin"
- "strings"
- "time"
- )
-
- // UserManagementGetUserList
- // @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/getUserList [post]
- func UserManagementGetUserList(c *gin.Context) {
- var req *md.UserManagementGetUserListReq
- if err := c.ShouldBindJSON(&req); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err.Error())
- return
- }
-
- 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,
- CustomInviteCode: user.CustomInviteCode,
- 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,
- }
- if user.ParentCustomInviteCode != "" {
- list[i].ParentInviteCode = user.ParentCustomInviteCode
- }
- 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)
- }
-
- // UserManagementAddUser
- // @Summary 制度中心-会员中心-用户管理-用户添加
- // @Tags 会员中心
- // @Description 用户添加
- // @Accept json
- // @Produce json
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Param req body md.RegisterReq true "分页信息必填"
- // @Success 200 {string} "具体数据"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/memberCenter/userManagement/addUser [post]
- func UserManagementAddUser(c *gin.Context) {
- var req *md.RegisterReq
- if err := c.ShouldBindJSON(&req); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err.Error())
- return
- }
- now := time.Now()
- userDb := implement.NewUserDb(db.Db)
- user, err := userDb.UserGetOneByParams(map[string]interface{}{
- "key": "phone",
- "value": req.Mobile,
- })
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err)
- return
- }
- if user != nil {
- e.OutErr(c, 400, e.NewErr(400, "该手机号已注册"))
- return
- }
- ip := utils.GetIP(c.Request)
- registerType := 3
- var inviteCode string
- sysCfgDb := sys_cfg.NewSysCfgDb(db.Db)
- sysCfg := sysCfgDb.SysCfgFindWithDb(enum.AppInviteType, enum.AppInviteLength)
- inviteCode = svc.ReturnCode(utils.StrToInt(sysCfg[enum.AppInviteLength]), utils.StrToInt(sysCfg[enum.AppInviteType]), 0)
- parentUid := utils.StrToInt64(req.ParentUid)
- appName := svc2.GetSysCfgStr("app_name")
- req.Nickname = appName + req.Mobile[len(req.Mobile)-4:]
- req.Avatar = svc2.GetSysCfgStr("default_avatar")
- NewUserLevelDb := implement.NewUserLevelDb(db.Db)
- userLevel, _ := NewUserLevelDb.UserLevelInIDescByWeightLowWithOne()
- level := 0
- if userLevel != nil {
- level = userLevel.Id
- }
- user = &model.User{
- Phone: req.Mobile,
- Nickname: req.Nickname,
- Avatar: req.Avatar,
- Password: "",
- Passcode: "",
- Level: level,
- InviteTotal: 0,
- State: int(enum.UserStateForNormal),
- LastLoginIp: ip,
- ParentUid: parentUid,
- SystemInviteCode: inviteCode,
- CustomInviteCode: "",
- Memo: "",
- IsRealName: 0,
- RegisterType: registerType,
- CreateAt: now.Format("2006-01-02 15:04:05"),
- UpdateAt: now.Format("2006-01-02 15:04:05"),
- }
- if req.Password != "" {
- user.Password = utils.Md5(req.Password)
- }
-
- insertAffected, err1 := userDb.UserInsert(user)
- if err1 != nil {
- e.OutErr(c, e.ERR_DB_ORM, err1)
- return
- }
- if insertAffected <= 0 {
- e.OutErr(c, e.ERR_DB_ORM, "新增用户数据失败")
- return
- }
- if parentUid > 0 {
- initLV := 1
- ur := new(model.UserRelate)
- ur.ParentUid = parentUid
- ur.Uid = user.Id
- ur.Level = initLV
- ur.InviteTime = time.Now().Format("2006-01-02 15:04:05")
-
- userRelateDb := implement.NewUserRelateDb(db.Db)
- _, err = userRelateDb.UserRelateInsert(ur)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err)
- return
- }
- // 插入多级关联
- go svc.RoutineMultiRelate(ur.ParentUid, ur.Uid, initLV)
- //TODO::推入mq异步处理
- ch, err := rabbit.Cfg.Pool.GetChannel()
- if err != nil {
- e.OutErr(c, e.ERR_INIT_RABBITMQ, err1.Error())
- return
- }
- defer ch.Release()
- ch.Publish(md3.EggAppExchange, md3.AddPublicPlatoonUserRelationCommissionReq{RecommendUid: utils.Int64ToStr(parentUid), Uid: utils.Int64ToStr(user.Id)}, md3.EggRoutKeyForAddPublicPlatoonUserRelationCommission)
- }
- //TODO::推入mq处理
- ch, err := rabbit.Cfg.Pool.GetChannel()
- if err != nil {
- e.OutErr(c, e.ERR_INIT_RABBITMQ, err1.Error())
- return
- }
- defer ch.Release()
- ch.Publish(md3.EggAppExchange, md3.EggNewUserRegisterData{Uid: user.Id}, md3.EggNewUserRegister)
- svc.UserImeiAdd(c, user.Id)
- admin := svc2.GetUser(c)
- svc2.AddAdminLog(c, admin.AdmId, "用户新增", "用户id:"+utils.Int64ToStr(user.Id)+",用户手机号:"+user.Phone, "")
- e.OutSuc(c, "success", nil)
- return
- }
-
- // UserManagementDelUserAlipay
- // @Summary 制度中心-会员中心-用户管理-删除用户支付宝
- // @Tags 会员中心
- // @Description 用户添加
- // @Accept json
- // @Produce json
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Param req body md.UserReq true "分页信息必填"
- // @Success 200 {string} "具体数据"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/memberCenter/userManagement/delUserAlipay [post]
- func UserManagementDelUserAlipay(c *gin.Context) {
- var req *md.UserReq
- if err := c.ShouldBindJSON(&req); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err.Error())
- return
- }
-
- NewAlipayUserInfoDb := implement.NewAlipayUserInfoDb(db.Db)
- info, _ := NewAlipayUserInfoDb.GetAlipayUserInfo(utils.StrToInt64(req.Id))
- if info == nil {
- e.OutErr(c, 400, e.NewErr(400, "支付宝信息不存在"))
- return
- }
- oldUserName := info.UserName
- oldOpenId := info.OpenId
- db.Db.Where("id=?", info.Id).Delete(&model.AlipayUserInfo{})
- admin := svc2.GetUser(c)
- svc2.AddAdminLog(c, admin.AdmId, "用户解除支付宝", "用户id:"+utils.Int64ToStr(info.Uid)+",原支付宝:"+oldUserName+" "+oldOpenId, utils.SerializeStr(info))
- e.OutSuc(c, "success", nil)
- return
- }
-
- // UserManagementDelUserWechat
- // @Summary 制度中心-会员中心-用户管理-删除用户微信
- // @Tags 会员中心
- // @Description 用户微信
- // @Accept json
- // @Produce json
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Param req body md.UserReq true "分页信息必填"
- // @Success 200 {string} "具体数据"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/memberCenter/userManagement/delUserAlipay [post]
- func UserManagementDelUserWechat(c *gin.Context) {
- var req *md.UserReq
- if err := c.ShouldBindJSON(&req); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err.Error())
- return
- }
-
- NewWxUserInfoDb := implement.NewWxUserInfoDb(db.Db)
- info, _ := NewWxUserInfoDb.GetWxUserInfo(utils.StrToInt64(req.Id))
- if info == nil {
- e.OutErr(c, 400, e.NewErr(400, "微信信息不存在"))
- return
- }
- oldUserName := info.UserName
- oldOpenId := info.OpenId
- db.Db.Where("id=?", info.Id).Delete(&model.WxUserInfo{})
- admin := svc2.GetUser(c)
- svc2.AddAdminLog(c, admin.AdmId, "用户解除微信", "用户id:"+utils.Int64ToStr(info.Uid)+",原微信:"+oldUserName+" "+oldOpenId, utils.SerializeStr(info))
- e.OutSuc(c, "success", nil)
- return
- }
-
- // UserManagementSetCustomInviteCode
- // @Summary 制度中心-会员中心-用户管理-用户自定义邀请码修改
- // @Tags 会员中心
- // @Description 用户自定义邀请码修改
- // @Accept json
- // @Produce json
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Param req body md.InviteCodeReq true "分页信息必填"
- // @Success 200 {string} "具体数据"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/memberCenter/userManagement/setCustomInviteCode [post]
- func UserManagementSetCustomInviteCode(c *gin.Context) {
- var req *md.InviteCodeReq
- if err := c.ShouldBindJSON(&req); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err.Error())
- return
- }
- userDb := implement.NewUserDb(db.Db)
- user, err := userDb.GetUser(utils.StrToInt64(req.Id))
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err)
- return
- }
- if user == nil {
- e.OutErr(c, 400, e.NewErr(400, "账号不存在"))
- return
- }
- if req.CustomInviteCode == "" {
- e.OutErr(c, 400, e.NewErr(400, "请输入邀请码"))
- return
- }
- code := []string{req.CustomInviteCode}
- tmp, _ := userDb.UserFindByInviteCodes(code...)
- if tmp != nil {
- for _, v := range *tmp {
- if v.Id != user.Id {
- e.OutErr(c, 400, e.NewErr(400, "该邀请码已被绑定"))
- return
- }
- }
- }
- customTmp, _ := userDb.UserFindByCustomInviteCodes(code...)
- if customTmp != nil {
- for _, v := range *customTmp {
- if v.Id != user.Id {
- e.OutErr(c, 400, e.NewErr(400, "该邀请码已被绑定"))
- return
- }
- }
- }
- oldCode := user.CustomInviteCode
- user.CustomInviteCode = req.CustomInviteCode
- _, err = db.Db.Where("id=?", user.Id).Cols("custom_invite_code").Update(user)
- if err != nil {
- e.OutErr(c, 400, e.NewErr(400, "修改失败"))
- return
- }
- admin := svc2.GetUser(c)
- svc2.AddAdminLog(c, admin.AdmId, "用户邀请码修改", "用户id:"+utils.Int64ToStr(user.Id)+",原邀请码:"+oldCode+",新邀请码"+user.CustomInviteCode, "")
- e.OutSuc(c, "success", nil)
- return
- }
-
- // UserManagementUpdateUserInfo
- // @Summary 制度中心-会员中心-用户管理-用户信息管理(更新)
- // @Tags 会员中心
- // @Description 用户信息管理(更新)
- // @Accept json
- // @Produce json
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Param req body md.UserManagementUpdateUserInfoReq true "用户ID 必传"
- // @Success 200 {int} "修改数据行数"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/memberCenter/userManagement/updateUserInfo [post]
- func UserManagementUpdateUserInfo(c *gin.Context) {
- var req *md.UserManagementUpdateUserInfoReq
- if err := c.ShouldBindJSON(&req); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err.Error())
- return
- }
- affected, err := svc.UserManagementUpdateUserInfo(c, db.Db, req)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
-
- 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
- }
- ex := strings.Split(req.UID, ",")
- NewUserDb := implement.NewUserDb(db.Db)
- for _, v := range ex {
- user, _ := NewUserDb.GetUser(utils.StrToInt64(v))
- if user == nil {
- e.OutErr(c, 400, e.NewErr(400, "用户不存在"))
- return
- }
- user.State = 4
- user.RecycleParentUid = utils.StrToInt(req.ParentUid)
- db.Db.Where("id=?", user.Id).Cols("state,recycle_parent_uid").Update(user)
- // 清掉token
- cacheKey := fmt.Sprintf("egg_app_jwt_token:%d", user.Id)
- cache.SetEx(cacheKey, "", 1)
- admin := svc2.GetUser(c)
- svc2.AddAdminLog(c, admin.AdmId, "用户回收", "用户id:"+utils.Int64ToStr(user.Id)+",用户手机号:"+user.Phone+" 删除到回收站", "")
- }
-
- e.OutSuc(c, "success", nil)
- }
-
- // UserManagementUserRecycleCancel
- // @Summary 会员中心-用户管理-恢复到会员列表
- // @Tags 会员中心
- // @Description 恢复到会员列表
- // @Accept json
- // @Produce json
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Param req body md.UserManagementUserInfoCancelReq 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)
- ex := strings.Split(req.UID, ",")
- for _, v := range ex {
- user, _ := NewUserDb.GetUser(utils.StrToInt64(v))
- if user == nil {
- e.OutErr(c, 400, e.NewErr(400, "用户不存在"))
- return
- }
- user.State = 1
- user.RecycleParentUid = 0
- db.Db.Where("id=?", user.Id).Cols("state,recycle_parent_uid").Update(user)
- admin := svc2.GetUser(c)
- svc2.AddAdminLog(c, admin.AdmId, "用户恢复", "用户id:"+utils.Int64ToStr(user.Id)+",用户手机号:"+user.Phone+" 恢复到会员列表", "")
- }
- 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)
- ex := strings.Split(req.UID, ",")
- ch, err := rabbit.Cfg.Pool.GetChannel()
- if err == nil {
- defer ch.Release()
- }
-
- for _, v := range ex {
- user, _ := NewUserDb.GetUser(utils.StrToInt64(v))
- 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)
- err = ch.PublishV2(md2.EggUserExchange, md2.CommUserId{
- Uid: utils.Int64ToStr(user.Id),
- ParentUid: utils.IntToStr(user.RecycleParentUid),
- }, md2.EggUserDelete)
- if err != nil {
- ch.PublishV2(md2.EggUserExchange, md2.CommUserId{
- Uid: utils.Int64ToStr(user.Id),
- ParentUid: utils.IntToStr(user.RecycleParentUid),
- }, 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+" 永久删除", "")
- }
- e.OutSuc(c, "success", nil)
- return
- }
-
- // UserManagementGetOneBasic
- // @Summary 制度中心-会员中心-用户管理-会员明细概况(获取)
- // @Tags 会员中心
- // @Description 会员明细概况(获取)
- // @Accept json
- // @Produce json
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Param uid query string true "用户 ID"
- // @Success 200 {object} md.UserManagementGetOneBasicResp "会员明细概况具体数据"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/memberCenter/userManagement/userData [get]
- func UserManagementGetOneBasic(c *gin.Context) {
- uid := c.Query("uid")
- userDb := implement.NewUserDb(db.Db)
- user, err := userDb.UserGetOneByParams(map[string]interface{}{
- "key": "id",
- "value": uid,
- })
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
-
- // 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
- }
-
- //2. 查询标签列表
- 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
- }
-
- //3. 查询父用户信息
- parent, err := userDb.UserGetOneByParams(map[string]interface{}{
- "key": "id",
- "value": user.ParentUid,
- })
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
-
- //4. 查询用户标签
- recordsDb := implement.NewUserTagRecordsDb(db.Db)
- userTagRecords, err := recordsDb.UserTagRecordsFindByParams(map[string]interface{}{
- "key": "uid",
- "value": uid,
- })
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
-
- resp := md.UserManagementGetOneBasicResp{
- TagsList: tagsList,
- LevelsList: levelsList,
- BasicInfo: md.BasicInfoNode{
- Avatar: user.Avatar,
- AvatarUrl: svc2.GetOssUrl(user.Avatar),
- Sex: user.Sex,
- Nickname: user.Nickname,
- LevelId: user.Level,
- Phone: user.Phone,
- UnionId: user.UnionId,
- WechatAccount: user.WechatAccount,
- Password: "",
- State: user.State,
- Memo: user.Memo,
- SystemInviteCode: user.SystemInviteCode,
- CustomInviteCode: user.CustomInviteCode,
- },
- OtherInfo: md.OtherNode{
- LastLoginIp: user.LastLoginIp,
- LastLoginAt: user.UpdateAt,
- CreateAt: user.CreateAt,
- },
- }
- NewAlipayUserInfoDb := implement.NewAlipayUserInfoDb(db.Db)
- info, _ := NewAlipayUserInfoDb.GetAlipayUserInfo(user.Id)
- if info != nil {
- resp.BasicInfo.AlipayUserName = info.UserName
- resp.BasicInfo.AlipayOpenId = info.OpenId
- }
- NewWxUserInfoDb := implement.NewWxUserInfoDb(db.Db)
- wxInfo, _ := NewWxUserInfoDb.GetWxUserInfo(user.Id)
- if wxInfo != nil {
- resp.BasicInfo.WechatUserName = wxInfo.UserName
- resp.BasicInfo.WechatOpenId = wxInfo.OpenId
- }
-
- tagList := make([]md.TagNode, len(*userTagRecords))
- if *userTagRecords != nil {
- for i, records := range *userTagRecords {
- tagList[i].TagID = records.TagId
- tagList[i].TagName = tagsMap[records.TagId]
- }
- }
- resp.BasicInfo.Tag = tagList
- if parent != nil {
- resp.BasicInfo.ParentUid = parent.Id
- resp.BasicInfo.ParentName = parent.Nickname
- resp.BasicInfo.ParentPhone = parent.Phone
- }
- level, ok := levelsMap[user.Level]
- if ok {
- resp.BasicInfo.LevelName = level
- }
-
- e.OutSuc(c, resp, nil)
- }
-
- // UserManagementGetFans
- // @Summary 制度中心-会员中心-用户管理-会员明细粉丝情况(获取)
- // @Tags 会员中心
- // @Description 会员明细粉丝情况(获取)
- // @Accept json
- // @Produce json
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Param uid query string true "用户 ID"
- // @Param type query string true "粉丝类型(0.全部 1.直推 2.二代 3.二代以后)"
- // @Param limit query string true "每页大小"
- // @Param page query string true "页数"
- // @Success 200 {object} md.UserManagementGetFansResp "具体数据"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/memberCenter/userManagement/getFans [get]
- func UserManagementGetFans(c *gin.Context) {
- uid := c.Query("uid")
- fansType := c.Query("type")
- limit := c.Query("limit")
- page := c.Query("page")
-
- //1. 查询符合情况用户 ID
- relateDb := implement.NewUserRelateDb(db.Db)
- var level int
- switch fansType {
- case "0":
- level = 0
- case "1":
- level = 1
- case "2":
- level = 2
- case "3":
- level = 3
- default:
- level = 0
- }
- relates, total, err := relateDb.PageFindUserRelateByParentUidAndLevel(utils.StrToInt64(uid), utils.StrToInt(page), utils.StrToInt(limit), level)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- userIDs := make([]int64, len(*relates))
- for i, relate := range *relates {
- userIDs[i] = relate.Uid
- }
-
- //2. 查询所属代数
- platoonUserRelationDb := implement.NewPublicPlatoonUserRelationDb(db.Db)
- levelTotals, err := platoonUserRelationDb.PublicPlatoonUserRelationFindByParamsByPage(map[string]interface{}{
- "key": "uid",
- "value": userIDs,
- }, utils.StrToInt(page), utils.StrToInt(limit))
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- levelTotalMap := make(map[int64]int)
- for _, levelTotal := range *levelTotals {
- levelTotalMap[levelTotal.Uid] = levelTotal.LevelTotal
- }
-
- //3. 查询可提现余额
- walletDb := implement.NewUserWalletDb(db.Db)
- wallets, err := walletDb.FindUserWalletByParams(map[string]interface{}{
- "key": "uid",
- "value": userIDs,
- })
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- walletMap := make(map[int64]string)
- for _, wallet := range *wallets {
- walletMap[wallet.Uid] = wallet.Amount
- }
-
- //4. 查询累计收益
- var incomeMap = map[int64]string{}
- if len(*relates) > 0 {
- userIDStrs := make([]string, len(*relates))
- for i, id := range userIDs {
- userIDStrs[i] = utils.Int64ToStr(id)
- }
- sql := "SELECT SUM(amount) as total, uid FROM `user_wallet_flow` WHERE uid in (%s) AND direction = 1 Group BY uid"
- results, err := db.QueryNativeString(db.Db, fmt.Sprintf(sql, strings.Join(userIDStrs, ",")))
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- for _, res := range results {
- incomeMap[utils.StrToInt64(res["uid"])] = res["total"]
- }
- }
-
- //5. 查询用户信息
- userDb := implement.NewUserDb(db.Db)
- users, err := userDb.UserFindByParams(map[string]interface{}{
- "key": "id",
- "value": userIDs,
- })
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
-
- list := make([]md.FansNode, len(users))
- for i, user := range users {
- list[i] = md.FansNode{
- ID: user.Id,
- Nickname: user.Nickname,
- Phone: user.Phone,
- RegisterAt: user.CreateAt,
- }
- val, ok := incomeMap[user.Id]
- if ok {
- list[i].TotalIncome = val
- }
- levelTotal, ok := levelTotalMap[user.Id]
- if ok {
- list[i].LevelTotal = levelTotal
- }
- amount, ok := walletMap[user.Id]
- if ok {
- list[i].Amount = amount
- }
-
- }
-
- resp := md.UserManagementGetFansResp{
- List: list,
- Paginate: md.Paginate{
- Limit: utils.StrToInt(limit),
- Page: utils.StrToInt(page),
- Total: total,
- },
- }
-
- e.OutSuc(c, resp, nil)
- }
-
- // UserManagementGetBalanceDetail
- // @Summary 制度中心-会员中心-用户管理-会员明细(余额获取)
- // @Tags 会员中心
- // @Description 会员明细(余额获取)
- // @Accept json
- // @Produce json
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Param uid query string true "用户 ID"
- // @Param limit query string true "每页大小"
- // @Param page query string true "页数"
- // @Success 200 {object} md.UserManagementGetBalanceDetailResp "具体数据"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/memberCenter/userManagement/balanceDetail [get]
- func UserManagementGetBalanceDetail(c *gin.Context) {
- uid := c.Query("uid")
- page := c.DefaultQuery("page", "1")
- limit := c.DefaultQuery("limit", "10")
-
- walletFlowDb := implement.NewUserWalletFlowDb(db.Db)
- walletFlows, total, err := walletFlowDb.UserWalletFlowFindByParams(map[string]interface{}{
- "key": "uid",
- "value": uid,
- }, utils.StrToInt(page), utils.StrToInt(limit))
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
-
- kindMap := map[int]string{
- 1: "管理员操作增加余额",
- 2: "管理员操作扣除余额",
- 3: "蛋蛋能量兑换余额",
- 4: "余额兑换蛋蛋能量",
- }
-
- list := make([]md.BalanceDetailNode, len(*walletFlows))
- for i, flow := range *walletFlows {
- list[i] = md.BalanceDetailNode{
- ID: flow.Id,
- Amount: flow.Amount,
- AfterAmount: flow.AfterAmount,
- Kind: kindMap[flow.Kind],
- CreateAt: flow.CreateAt,
- }
- }
-
- resp := md.UserManagementGetBalanceDetailResp{
- List: list,
- Paginate: md.Paginate{
- Limit: utils.StrToInt(limit),
- Page: utils.StrToInt(page),
- Total: total,
- },
- }
- e.OutSuc(c, resp, nil)
- }
-
- // UserManagementGetVirtualCoinDetail
- // @Summary 制度中心-会员中心-用户管理-会员明细(积分明细获取)
- // @Tags 会员中心
- // @Description 会员明细(积分明细获取)
- // @Accept json
- // @Produce json
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Param uid query string true "用户 ID"
- // @Param coinId query string true "货币 ID"
- // @Param limit query string true "每页大小"
- // @Param page query string true "页数"
- // @Success 200 {object} md.UserManagementGetVirtualCoinDetailResp "具体数据"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/memberCenter/userManagement/getVirtualCoinDetail [get]
- func UserManagementGetVirtualCoinDetail(c *gin.Context) {
- page := c.DefaultQuery("page", "1")
- limit := c.DefaultQuery("limit", "10")
- uid := c.Query("uid")
- coinID := c.Query("coinId")
- coinDb := implement.NewVirtualCoinDb(db.Db)
- coins, err := coinDb.VirtualCoinFindAll()
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- if coins == nil {
- e.OutErr(c, e.ERR_NO_DATA, errors.New("未初始化货币"))
- return
- }
-
- coinsList := make([]map[string]interface{}, len(coins))
- coinsMap := map[int]string{}
- for i, coin := range coins {
- coinsList[i] = map[string]interface{}{
- "coinID": coin.Id,
- "name": coin.Name,
- }
- coinsMap[coin.Id] = coin.Name
- }
-
- // 传入不存在的货币类型时 默认为第一种货币类型
- var reqCoinID int
- _, ok := coinsMap[utils.StrToInt(coinID)]
- if !ok {
- reqCoinID = coinsList[0]["coinID"].(int)
- } else {
- reqCoinID = utils.StrToInt(coinID)
- }
-
- flowDb := implement.NewUserVirtualCoinFlowDb(db.Db)
- flows, total, err := flowDb.UserVirtualCoinFlowFindByCoinAndUser(utils.StrToInt(page), utils.StrToInt(limit), reqCoinID, utils.StrToInt64(uid), "", "", 0, false, 0)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
-
- list := make([]md.VirtualCoinDetailNode, len(flows))
- for i, flow := range flows {
- list[i] = md.VirtualCoinDetailNode{
- Uid: flow.Uid,
- Amount: flow.Amount,
- AfterAmount: flow.AfterAmount,
- Direction: flow.Direction,
- CreateAt: flow.CreateAt,
- }
- }
-
- resp := md.UserManagementGetVirtualCoinDetailResp{
- CoinList: coinsList,
- List: list,
- Paginate: md.Paginate{
- Limit: utils.StrToInt(limit),
- Page: utils.StrToInt(page),
- Total: total,
- },
- }
-
- e.OutSuc(c, resp, nil)
- }
|