From c11464788f7ed333b5562891c659b9dc8d98f0f3 Mon Sep 17 00:00:00 2001 From: shenjiachi Date: Tue, 19 Nov 2024 15:51:44 +0800 Subject: [PATCH] update --- app/hdl/member_center/hdl_user_management.go | 285 +++++++++--------- .../member_center/md_user_management.go | 62 ++-- 2 files changed, 171 insertions(+), 176 deletions(-) diff --git a/app/hdl/member_center/hdl_user_management.go b/app/hdl/member_center/hdl_user_management.go index 859f808..0ba3525 100644 --- a/app/hdl/member_center/hdl_user_management.go +++ b/app/hdl/member_center/hdl_user_management.go @@ -8,13 +8,14 @@ import ( "applet/app/utils" "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" "code.fnuoos.com/EggPlanet/egg_models.git/src/model" + "errors" "fmt" "github.com/gin-gonic/gin" "strings" ) // UserManagementGetUserList -// @Summary 制度中心-会员中心-用户信息管理(获取) +// @Summary 制度中心-会员中心-用户管理-用户信息管理(获取) // @Tags 会员中心 // @Description 用户信息管理(获取) // @Accept json @@ -85,7 +86,7 @@ func UserManagementGetUserList(c *gin.Context) { Nickname: user.Nickname, Phone: user.Phone, IsRealName: user.IsRealName, - Level: levelsMap[user.Level], + LevelName: levelsMap[user.Level], InviteCode: user.SystemInviteCode, ParentID: user.ParentUid, ParentInviteCode: user.ParentSystemInviteCode, @@ -109,7 +110,7 @@ func UserManagementGetUserList(c *gin.Context) { } // UserManagementUpdateUserInfo -// @Summary 制度中心-会员中心-用户信息管理(更新) +// @Summary 制度中心-会员中心-用户管理-用户信息管理(更新) // @Tags 会员中心 // @Description 用户信息管理(更新) // @Accept json @@ -125,67 +126,92 @@ func UserManagementUpdateUserInfo(c *gin.Context) { e.OutErr(c, e.ERR_INVALID_ARGS, err.Error()) return } - + session := db.Db.NewSession() + defer session.Close() + session.Begin() userDb := implement.NewUserDb(db.Db) - var affected int64 var err1 error forceColumns := make([]string, 0) user := model.User{ - Id: req.UID, + Id: req.UID, + Phone: req.Phone, + UnionId: req.UnionId, + Nickname: req.Nickname, + Avatar: req.Avatar, + LastLoginIp: req.LastLoginIp, + Memo: req.Memo, } - if req.Memo != "" { - user.Memo = req.Memo - forceColumns = append(forceColumns, "memo") + if req.Level != "" { + user.Level = utils.StrToInt(req.Level) } - if req.Disable != false { - user.State = 2 - forceColumns = append(forceColumns, "state") + if req.State != "" { + user.State = utils.StrToInt(req.State) } - if req.LastLoginIp != "" { - user.LastLoginIp = req.LastLoginIp - forceColumns = append(forceColumns, "last_login_ip") + if req.Sex != "" { + user.Sex = utils.StrToInt(req.Sex) } - if req.Avatar != "" { - user.Avatar = req.Avatar - forceColumns = append(forceColumns, "avatar") + if req.ParentUid != "" { + user.ParentUid = utils.StrToInt64(req.ParentUid) + } else { + user.ParentUid = 0 } - if len(forceColumns) > 0 { - affected, err1 = userDb.UserUpdate(req.UID, &user) - if err1 != nil { - e.OutErr(c, e.ERR_DB_ORM, err1.Error()) - return - } + + forceColumns = []string{"sex", "parent_uid"} + affected, err1 = userDb.UserUpdateBySession(session, req.UID, &user, forceColumns...) + if err1 != nil { + session.Rollback() + e.OutErr(c, e.ERR_DB_ORM, err1.Error()) + return + } + + relateDb := implement.NewUserRelateDb(db.Db) + relateForceColumns := []string{"sex", "parent_uid"} + relate := &model.UserRelate{ + ParentUid: user.ParentUid, + } + affected, err1 = relateDb.UpdateUserRelateBySession(session, req.UID, relate, relateForceColumns...) + if err1 != nil { + session.Rollback() + e.OutErr(c, e.ERR_DB_ORM, err1.Error()) + return } var err2 error - if req.Tag != 0 { + if req.Tag != "" { record := model.UserTagRecords{ - TagId: req.Tag, + TagId: utils.StrToInt(req.Tag), } recordsDb := implement.NewUserTagRecordsDb(db.Db) - affected, err2 = recordsDb.UserTagRecordsUpdate(req.UID, &record, "tag_id") + affected, err2 = recordsDb.UserTagRecordsUpdateBySession(session, req.UID, &record, "tag_id") if err2 != nil { + session.Rollback() e.OutErr(c, e.ERR_DB_ORM, err2.Error()) return } } + err3 := session.Commit() + if err3 != nil { + session.Rollback() + e.OutErr(c, e.ERR_DB_ORM, err3.Error()) + return + } e.OutSuc(c, affected, nil) } // UserManagementGetOneBasic -// @Summary 制度中心-会员中心-会员明细概况(获取) +// @Summary 制度中心-会员中心-用户管理-会员明细概况(获取) // @Tags 会员中心 // @Description 会员明细概况(获取) // @Accept json // @Produce json // @param Authorization header string true "验证参数Bearer和token空格拼接" -// @Param uid query int true "用户 ID" +// @Param uid query string true "用户 ID" // @Success 200 {object} md.UserManagementGetOneBasicResp "会员明细概况具体数据" // @Failure 400 {object} md.Response "具体错误" -// @Router /api/memberCenter/userManagement/getOneBasicInfo [get] +// @Router /api/memberCenter/userManagement/userData [get] func UserManagementGetOneBasic(c *gin.Context) { uid := c.Query("uid") userDb := implement.NewUserDb(db.Db) @@ -232,24 +258,7 @@ func UserManagementGetOneBasic(c *gin.Context) { tagsMap[tag.Id] = tag.TagName } - //3. 查询货币列表 - coinDb := implement.NewVirtualCoinDb(db.Db) - coins, err3 := coinDb.VirtualCoinFindAll() - if err3 != nil { - e.OutErr(c, e.ERR_DB_ORM, err3.Error()) - return - } - coinsList := make([]map[string]interface{}, 0) - coinsMap := make(map[int]string) - for _, coin := range coins { - coinsList = append(coinsList, map[string]interface{}{ - "id": coin.Id, - "name": coin.Name, - }) - coinsMap[coin.Id] = coin.Name - } - - //4. 查询父用户信息 + //3. 查询父用户信息 parent, err := userDb.UserGetOneByParams(map[string]interface{}{ "key": "id", "value": user.ParentUid, @@ -259,87 +268,60 @@ func UserManagementGetOneBasic(c *gin.Context) { return } - //5. 查询用户标签 + //4. 查询用户标签 recordsDb := implement.NewUserTagRecordsDb(db.Db) userTagRecord, err := recordsDb.UserTagRecordsGetOneByParams(map[string]interface{}{ "key": "uid", "value": uid, }) - if err != nil { - return - } - - //6. 查询用户虚拟钱包 - amountDb := implement.NewUserVirtualAmountDb(db.Db) - virtualWallets, err := amountDb.GetUserVirtualAllWallets(utils.AnyToInt64(uid)) - if err != nil { - e.OutErr(c, e.ERR_DB_ORM, err.Error()) - return - } - virtualAmountList := make([]md.VirtualAmountInfoNode, 0) - for _, virtualWallet := range *virtualWallets { - virtualAmountList = append(virtualAmountList, md.VirtualAmountInfoNode{ - CoinName: coinsMap[virtualWallet.CoinId], - Amount: virtualWallet.Amount, - }) - } - - //7. 查询用户钱包余额 - userWalletDb := implement.NewUserWalletDb(db.Db) - wallet, err := userWalletDb.GetUserVirtualWallet(utils.StrToInt64(uid)) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } resp := md.UserManagementGetOneBasicResp{ - TagsList: tagsList, - LevelsList: levelsList, - CoinsList: coinsList, - VirtualAmountInfo: virtualAmountList, + TagsList: tagsList, + LevelsList: levelsList, BasicInfo: md.BasicInfoNode{ - Avatar: user.Avatar, - Sex: user.Sex, - Nickname: user.Nickname, - TagID: userTagRecord.TagId, - Phone: user.Phone, - UnionId: user.UnionId, - Password: user.Password, - Passcode: user.Passcode, - State: user.State, - Memo: user.Memo, - ParentUid: parent.Id, - ParentName: parent.Nickname, - ParentPhone: parent.Phone, - SystemInviteCode: user.SystemInviteCode, - CustomInviteCode: user.CustomInviteCode, - Level: levelsMap[user.Level], - }, - WalletInfo: md.WalletNode{ - Amount: wallet.Amount, + Avatar: user.Avatar, + Sex: user.Sex, + Nickname: user.Nickname, + LevelName: levelsMap[user.Level], + Phone: user.Phone, + UnionId: user.UnionId, + Password: user.Password, + State: user.State, + Memo: user.Memo, }, OtherInfo: md.OtherNode{ - LastLoginIp: user.LastLoginIp, - LastLoginAt: user.UpdateAt, - CreateAt: user.CreateAt, - RegisterType: user.RegisterType, + LastLoginIp: user.LastLoginIp, + LastLoginAt: user.UpdateAt, + CreateAt: user.CreateAt, }, } + if userTagRecord != nil { + resp.BasicInfo.TagName = tagsMap[userTagRecord.TagId] + } + if parent != nil { + resp.BasicInfo.ParentUid = parent.Id + resp.BasicInfo.ParentName = parent.Nickname + resp.BasicInfo.ParentPhone = parent.Phone + } e.OutSuc(c, resp, nil) } // UserManagementGetFans -// @Summary 制度中心-会员中心-会员明细粉丝情况(获取) +// @Summary 制度中心-会员中心-用户管理-会员明细粉丝情况(获取) // @Tags 会员中心 // @Description 会员明细粉丝情况(获取) // @Accept json // @Produce json // @param Authorization header string true "验证参数Bearer和token空格拼接" -// @Param uid query int true "用户 ID" -// @Param type query int true "粉丝类型(1.全部 2.直推 3.二代 4.二代以后)" -// @Param limit query int true "每页大小" -// @Param page query int true "页数" +// @Param uid query string true "用户 ID" +// @Param type query string true "粉丝类型(1.全部 2.直推 3.二代 4.二代以后)" +// @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] @@ -387,7 +369,7 @@ func UserManagementGetFans(c *gin.Context) { levelTotalMap[levelTotal.Uid] = levelTotal.LevelTotal } - //3. 查询可体现余额 + //3. 查询可提现余额 walletDb := implement.NewUserWalletDb(db.Db) wallets, err := walletDb.FindUserWalletByParams(map[string]interface{}{ "key": uid, @@ -403,19 +385,21 @@ func UserManagementGetFans(c *gin.Context) { } //4. 查询累计收益 - userIDStrs := make([]string, len(*relates)) - for i, id := range userIDs { - userIDStrs[i] = utils.Int64ToStr(id) - } - sql := "SELECT SUM(amount) as total, uid FORM `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 - } var incomeMap = map[int64]string{} - for _, res := range results { - incomeMap[utils.StrToInt64(res["uid"])] = res["total"] + 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. 查询用户信息 @@ -432,13 +416,16 @@ func UserManagementGetFans(c *gin.Context) { list := make([]md.FansNode, len(users)) for i, user := range users { list[i] = md.FansNode{ - ID: user.Id, - Nickname: user.Nickname, - Phone: user.Phone, - LevelTotal: levelTotalMap[user.Id], - Amount: walletMap[user.Id], - TotalIncome: incomeMap[user.Id], - RegisterAt: user.CreateAt, + ID: user.Id, + Nickname: user.Nickname, + Phone: user.Phone, + LevelTotal: levelTotalMap[user.Id], + Amount: walletMap[user.Id], + RegisterAt: user.CreateAt, + } + val, ok := incomeMap[user.Id] + if ok { + list[i].TotalIncome = val } } @@ -455,22 +442,22 @@ func UserManagementGetFans(c *gin.Context) { } // UserManagementGetBalanceDetail -// @Summary 制度中心-会员中心-会员明细余额(获取) +// @Summary 制度中心-会员中心-用户管理-会员明细(余额获取) // @Tags 会员中心 -// @Description 会员明细余额(获取) +// @Description 会员明细(余额获取) // @Accept json // @Produce json // @param Authorization header string true "验证参数Bearer和token空格拼接" -// @Param uid query int true "用户 ID" -// @Param limit query int true "每页大小" -// @Param page query int true "页数" +// @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.Query("page") - limit := c.Query("limit") + page := c.DefaultQuery("page", "1") + limit := c.DefaultQuery("limit", "10") walletFlowDb := implement.NewUserWalletFlowDb(db.Db) walletFlows, total, err := walletFlowDb.UserWalletFlowFindByParams(map[string]interface{}{ @@ -482,16 +469,6 @@ func UserManagementGetBalanceDetail(c *gin.Context) { return } - userDb := implement.NewUserDb(db.Db) - user, err := userDb.UserGetOneByParams(map[string]interface{}{ - "key": "uid", - "value": uid, - }) - if err != nil { - e.OutErr(c, e.ERR_DB_ORM, err.Error()) - return - } - kindMap := map[int]string{ 1: "管理员操作增加余额", 2: "管理员操作扣除余额", @@ -503,17 +480,12 @@ func UserManagementGetBalanceDetail(c *gin.Context) { for i, flow := range *walletFlows { list[i] = md.BalanceDetailNode{ ID: flow.Id, - Uid: user.Id, - Nickname: user.Nickname, - Phone: user.Phone, Amount: flow.Amount, AfterAmount: flow.AfterAmount, Kind: kindMap[flow.Kind], - OrdID: flow.OrdId, CreateAt: flow.CreateAt, } } - // todo增加总数、支出总数 resp := md.UserManagementGetBalanceDetailResp{ List: list, @@ -526,10 +498,23 @@ func UserManagementGetBalanceDetail(c *gin.Context) { e.OutSuc(c, resp, nil) } -// UserManagementGetVirtualCoinDetail todo 补充s wag 注释 +// 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.Query("page") - limit := c.Query("limit") + page := c.DefaultQuery("page", "1") + limit := c.DefaultQuery("limit", "10") uid := c.Query("uid") coinID := c.Query("coinId") coinDb := implement.NewVirtualCoinDb(db.Db) @@ -538,6 +523,10 @@ func UserManagementGetVirtualCoinDetail(c *gin.Context) { 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{} diff --git a/app/md/institutional_management/member_center/md_user_management.go b/app/md/institutional_management/member_center/md_user_management.go index ff0e445..eb19165 100644 --- a/app/md/institutional_management/member_center/md_user_management.go +++ b/app/md/institutional_management/member_center/md_user_management.go @@ -2,7 +2,6 @@ package md import ( "code.fnuoos.com/EggPlanet/egg_models.git/src/model" - "time" ) type UserManagementGetUserListReq struct { @@ -37,19 +36,19 @@ type Paginate struct { } type UserManagementGetUserListNode struct { - ID int64 `json:"id"` // 会员 ID - Tag string `json:"tag_name"` // 会员标签 - Avatar string `json:"avatar"` // 头像 - Nickname string `json:"nickname"` // 昵称 - Phone string `json:"phone"` // 手机号 - IsRealName int `json:"is_real_name"` // 是否实名 0.未实名,1.已实名 - Level string `json:"level_name"` // 会员等级 - InviteCode string `json:"invite_code" example:"会员邀请码"` - ParentID int64 `json:"parent_id"` // 推荐人 ID - ParentInviteCode string `json:"parent_invite_code" example:"推荐人邀请码"` - ParentPhone string `json:"parent_phone" example:"推荐人手机号"` - RegisterTime time.Time `json:"register_time"` // 注册时间 - Memo string `json:"memo"` // 备注 + ID int64 `json:"id"` // 会员 ID + Tag string `json:"tag_name"` // 会员标签 + Avatar string `json:"avatar"` // 头像 + Nickname string `json:"nickname"` // 昵称 + Phone string `json:"phone"` // 手机号 + IsRealName int `json:"is_real_name"` // 是否实名 0.未实名,1.已实名 + LevelName string `json:"level_name"` // 会员等级 + InviteCode string `json:"invite_code" example:"会员邀请码"` + ParentID int64 `json:"parent_id"` // 推荐人 ID + ParentInviteCode string `json:"parent_invite_code" example:"推荐人邀请码"` + ParentPhone string `json:"parent_phone" example:"推荐人手机号"` + RegisterTime string `json:"register_time"` // 注册时间 + Memo string `json:"memo"` // 备注 model.User } @@ -77,16 +76,23 @@ type UserManagementUpdateUserInfoReq struct { UID int64 `json:"uid,required"` Memo string `json:"memo" example:"备注"` Disable bool `json:"disable"` // 是否禁用用户 - Tag int `json:"tag"` // 用户标签 ID + Tag string `json:"tag"` // 用户标签 ID LastLoginIp string `json:"last_login_ip"` // 用户最后登录 IP Avatar string `json:"avatar"` // 头像 + Phone string `json:"phone"` // 手机号 + UnionId string `json:"union_id"` // 微信号 + Nickname string `json:"nickname"` // 用户昵称 + Level string `json:"level"` // 用户等级 ID + State string `json:"state"` // 用户状态 1正常,2冻结 + Sex string `json:"sex"` // 用户性别 性别(0:未知 1:男 2:女) + ParentUid string `json:"parent_uid"` // 用户父级 ID } type BasicInfoNode struct { Avatar string `json:"avatar"` // 头像 Sex int `json:"sex"` // 性别 Nickname string `json:"nickname"` // 会员名称 - TagID int `json:"tag_id"` // 标签 ID + TagName string `json:"tag_name"` // 标签名称 Phone string `json:"phone"` // 手机号 UnionId string `json:"union_id"` // 微信号 Password string `json:"password"` // 登录密码 @@ -98,14 +104,14 @@ type BasicInfoNode struct { ParentPhone string `json:"parent_phone"` // 推荐人手机号 SystemInviteCode string `json:"system_invite_code"` // 系统邀请码 CustomInviteCode string `json:"custom_invite_code"` // 自定义邀请码 - Level string `json:"level"` // 等级名称 + LevelName string `json:"level_name"` // 等级名称 } type OtherNode struct { - LastLoginIp string `json:"last_login_ip" ` // 最后登录 IP - LastLoginAt time.Time `json:"last_login_at" ` // 最近登录时间 - CreateAt time.Time `json:"create_at" ` // 注册时间 - RegisterType int `json:"register_at" ` // 注册类型(0.未知, 1.免验证码手机号注册,2.微信授权) + LastLoginIp string `json:"last_login_ip" ` // 最后登录 IP + LastLoginAt string `json:"last_login_at" ` // 最近登录时间 + CreateAt string `json:"create_at" ` // 注册时间 + RegisterType int `json:"register_at" ` // 注册类型(0.未知, 1.免验证码手机号注册,2.微信授权) } type WalletNode struct { @@ -128,13 +134,13 @@ type UserManagementGetOneBasicResp struct { } type FansNode struct { - ID int64 `json:"id"` // 用户ID - Nickname string `json:"nickname" example:"用户昵称"` - Phone string `json:"phone" example:"手机号"` - LevelTotal int `json:"level_total"` // 所属代数 - Amount string `json:"amount"` // 可提现余额 - TotalIncome string `json:"total_income"` // 累计收益 - RegisterAt time.Time `json:"register_at"` // 注册时间 + ID int64 `json:"id"` // 用户ID + Nickname string `json:"nickname" example:"用户昵称"` + Phone string `json:"phone" example:"手机号"` + LevelTotal int `json:"level_total"` // 所属代数 + Amount string `json:"amount"` // 可提现余额 + TotalIncome string `json:"total_income"` // 累计收益 + RegisterAt string `json:"register_at"` // 注册时间 } type UserManagementGetFansResp struct {