Browse Source

add user management

master
shenjiachi 6 days ago
parent
commit
44501563a9
4 changed files with 476 additions and 94 deletions
  1. +406
    -82
      app/hdl/member_center/hdl_user_management.go
  2. +64
    -9
      app/md/institutional_management/member_center/md_user_management.go
  3. +4
    -1
      app/router/router.go
  4. +2
    -2
      go.mod

+ 406
- 82
app/hdl/member_center/hdl_user_management.go View File

@@ -5,9 +5,12 @@ import (
"applet/app/e" "applet/app/e"
md "applet/app/md/institutional_management/member_center" md "applet/app/md/institutional_management/member_center"
svc "applet/app/svc/member_center" svc "applet/app/svc/member_center"
"applet/app/utils"
"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/EggPlanet/egg_models.git/src/model"
"fmt"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"strings"
) )


// UserManagementGetUserList // UserManagementGetUserList
@@ -175,7 +178,7 @@ func UserManagementUpdateUserInfo(c *gin.Context) {
// UserManagementGetOneBasic // UserManagementGetOneBasic
// @Summary 制度中心-会员中心-会员明细概况(获取) // @Summary 制度中心-会员中心-会员明细概况(获取)
// @Tags 会员中心 // @Tags 会员中心
// @Description 会员明细概况(更新)
// @Description 会员明细概况(获取)
// @Accept json // @Accept json
// @Produce json // @Produce json
// @param Authorization header string true "验证参数Bearer和token空格拼接" // @param Authorization header string true "验证参数Bearer和token空格拼接"
@@ -183,84 +186,405 @@ func UserManagementUpdateUserInfo(c *gin.Context) {
// @Success 200 {object} md.UserManagementGetOneBasicResp "会员明细概况具体数据" // @Success 200 {object} md.UserManagementGetOneBasicResp "会员明细概况具体数据"
// @Failure 400 {object} md.Response "具体错误" // @Failure 400 {object} md.Response "具体错误"
// @Router /api/memberCenter/userManagement/getOneBasicInfo [get] // @Router /api/memberCenter/userManagement/getOneBasicInfo [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
// }
//
// 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
// }
//
// 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
// }
//
// 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
// }
//
// recordsDb := implement.NewUserTagRecordsDb(db.Db)
// userTagRecord, err := recordsDb.UserTagRecordsGetOneByParams(map[string]interface{}{
// "key": "uid",
// "value": uid,
// })
// if err != nil {
// return
// }
//
// amountDb := implement.NewUserVirtualAmountDb(db.Db)
// amountDb.GetUserVirtualWalletBySession()
//}
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. 查询货币列表
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. 查询父用户信息
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
}

//5. 查询用户标签
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,
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,
},
OtherInfo: md.OtherNode{
LastLoginIp: user.LastLoginIp,
LastLoginAt: user.UpdateAt,
CreateAt: user.CreateAt,
RegisterType: user.RegisterType,
},
}

e.OutSuc(c, resp, nil)
}

// UserManagementGetFans
// @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 "页数"
// @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
default:
level = 3
}
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. 查询累计收益
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"]
}

//5. 查询用户信息
userDb := implement.NewUserDb(db.Db)
users, err := userDb.UserFindByParams(map[string]interface{}{
"key": "uid",
"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,
LevelTotal: levelTotalMap[user.Id],
Amount: walletMap[user.Id],
TotalIncome: incomeMap[user.Id],
RegisterAt: user.CreateAt,
}
}

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 int true "用户 ID"
// @Param limit query int true "每页大小"
// @Param page query int 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")

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
}

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: "管理员操作扣除余额",
3: "蛋蛋能量兑换余额",
4: "余额兑换蛋蛋能量",
}

list := make([]md.BalanceDetailNode, len(*walletFlows))
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,
Paginate: md.Paginate{
Limit: utils.StrToInt(limit),
Page: utils.StrToInt(page),
Total: total,
},
}
e.OutSuc(c, resp, nil)
}

// UserManagementGetVirtualCoinDetail todo 补充s wag 注释
func UserManagementGetVirtualCoinDetail(c *gin.Context) {
page := c.Query("page")
limit := c.Query("limit")
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
}

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)
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)
}

+ 64
- 9
app/md/institutional_management/member_center/md_user_management.go View File

@@ -82,7 +82,7 @@ type UserManagementUpdateUserInfoReq struct {
Avatar string `json:"avatar"` // 头像 Avatar string `json:"avatar"` // 头像
} }


type UserManagementGetOneBasicNode struct {
type BasicInfoNode struct {
Avatar string `json:"avatar"` // 头像 Avatar string `json:"avatar"` // 头像
Sex int `json:"sex"` // 性别 Sex int `json:"sex"` // 性别
Nickname string `json:"nickname"` // 会员名称 Nickname string `json:"nickname"` // 会员名称
@@ -98,22 +98,77 @@ type UserManagementGetOneBasicNode struct {
ParentPhone string `json:"parent_phone"` // 推荐人手机号 ParentPhone string `json:"parent_phone"` // 推荐人手机号
SystemInviteCode string `json:"system_invite_code"` // 系统邀请码 SystemInviteCode string `json:"system_invite_code"` // 系统邀请码
CustomInviteCode string `json:"custom_invite_code"` // 自定义邀请码 CustomInviteCode string `json:"custom_invite_code"` // 自定义邀请码
Level int `json:"level"` // 等级 ID
Level string `json:"level"` // 等级名称
} }


type OtherNode struct { type OtherNode struct {
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.微信授权)
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.微信授权)
} }


type WalletNode struct { type WalletNode struct {
Amount string `json:"amount"` // 用户余额 Amount string `json:"amount"` // 用户余额
} }


type VirtualAmountInfoNode struct {
CoinName string `json:"coin_name"` // 货币类型
Amount string `json:"amount"` // 余额
}

type UserManagementGetOneBasicResp struct { type UserManagementGetOneBasicResp struct {
TagsList []map[string]interface{} `json:"tags_list"` // 标签列表
LevelsList []map[string]interface{} `json:"levels_list"` // 等级列表
CoinsList []map[string]interface{} `json:"coins_list"` // 货币列表
TagsList []map[string]interface{} `json:"tags_list"` // 标签列表
LevelsList []map[string]interface{} `json:"levels_list"` // 等级列表
CoinsList []map[string]interface{} `json:"coins_list"` // 货币列表
VirtualAmountInfo []VirtualAmountInfoNode `json:"virtual_amount_info"` // 虚拟资产钱包数据
BasicInfo BasicInfoNode `json:"basic_info"` // 基本信息
WalletInfo WalletNode `json:"wallet_info"` // 钱包信息
OtherInfo OtherNode `json:"other_info"` // 其他信息
}

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"` // 注册时间
}

type UserManagementGetFansResp struct {
List []FansNode `json:"list"` // 用户数据
Paginate Paginate `json:"paginate"` // 分页信息
}

type BalanceDetailNode struct {
ID int64 `json:"id"` // 记录ID
Uid int64 `json:"uid"` // 用户ID
Nickname string `json:"nickname"` // 用户昵称
Phone string `json:"phone"` // 用户手机号
Amount string `json:"amount"` // 变更余额
AfterAmount string `json:"after_amount"` // 变更后余额
Kind string `json:"kind"` //类型 1:管理员操作增加余额 2:管理员操作扣除余额 3:蛋蛋能量兑换余额 4:余额兑换蛋蛋能量
OrdID string `json:"ord_Id"` // 订单号
CreateAt string `json:"create_at"` // 创建时间
}

type UserManagementGetBalanceDetailResp struct {
List []BalanceDetailNode `json:"list"`
Paginate Paginate `json:"paginate"`
}

type VirtualCoinDetailNode struct {
Uid int64 `json:"uid"` // 用户 ID
Amount string `json:"amount"` // 变更数量
AfterAmount string `json:"after_amount"` // 变更后积分余额
Direction int `json:"direction"` // 类型 1.收入 2.支出
CreateAt string `json:"create_at"` // 创建时间
}

type UserManagementGetVirtualCoinDetailResp struct {
CoinList []map[string]interface{} `json:"coin_list"`
List []VirtualCoinDetailNode `json:"list"`
Paginate Paginate `json:"paginate"`
} }

+ 4
- 1
app/router/router.go View File

@@ -147,8 +147,11 @@ func rMemberCenter(r *gin.RouterGroup) { // 会员中心
rUserManagement := r.Group("/userManagement") rUserManagement := r.Group("/userManagement")
{ {
rUserManagement.POST("/getUserList", member_center.UserManagementGetUserList) rUserManagement.POST("/getUserList", member_center.UserManagementGetUserList)
//rUserManagement.GET("/userData", member_center.UserManagementGetOneBasic)
rUserManagement.GET("/userData", member_center.UserManagementGetOneBasic)
rUserManagement.POST("/updateUserInfo", member_center.UserManagementUpdateUserInfo) rUserManagement.POST("/updateUserInfo", member_center.UserManagementUpdateUserInfo)
rUserManagement.GET("/getFans", member_center.UserManagementGetFans)
rUserManagement.GET("/balanceDetail", member_center.UserManagementGetBalanceDetail)
rUserManagement.GET("/getVirtualCoinDetail", member_center.UserManagementGetVirtualCoinDetail)
} }
} }




+ 2
- 2
go.mod View File

@@ -2,9 +2,9 @@ module applet


go 1.19 go 1.19


// replace code.fnuoos.com/EggPlanet/egg_models.git => E:/company/Egg/egg_models
replace code.fnuoos.com/EggPlanet/egg_models.git => E:/company/Egg/egg_models


// replace code.fnuoos.com/EggPlanet/egg_system_rules.git => E:/company/Egg/egg_system_rules
replace code.fnuoos.com/EggPlanet/egg_system_rules.git => E:/company/Egg/egg_system_rules


require ( require (
github.com/boombuler/barcode v1.0.1 github.com/boombuler/barcode v1.0.1


Loading…
Cancel
Save