|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- package member_center
-
- import (
- "applet/app/db"
- "applet/app/e"
- md "applet/app/md/institutional_management/member_center"
- svc "applet/app/svc/member_center"
- "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
- "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
- "github.com/gin-gonic/gin"
- )
-
- // 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
- }
-
- users, total, err3 := svc.UserManagementGetUsers(db.Db, req)
- if err3 != nil {
- e.OutErr(c, e.ERR_DB_ORM, err3.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
- }
-
- list := make([]md.UserManagementGetUserListNode, len(*users))
- for i, user := range *users {
- list[i] = md.UserManagementGetUserListNode{
- ID: user.Id,
- Tag: tagsMap[user.TagID],
- Avatar: user.Avatar,
- Nickname: user.Nickname,
- Phone: user.Phone,
- IsRealName: user.IsRealName,
- Level: levelsMap[user.Level],
- InviteCode: user.SystemInviteCode,
- ParentID: user.ParentUid,
- ParentInviteCode: user.ParentSystemInviteCode,
- ParentPhone: user.Phone,
- RegisterTime: user.CreateAt,
- Memo: user.Memo,
- }
- }
-
- resp := md.UserManagementGetUserListResp{
- LevelsList: levelsList,
- TagsList: tagsList,
- List: list,
- Paginate: md.Paginate{
- Limit: req.Limit,
- Page: req.Page,
- Total: total,
- },
- }
- e.OutSuc(c, resp, nil)
- }
-
- // 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
- }
-
- userDb := implement.NewUserDb(db.Db)
-
- var affected int64
- var err1 error
- forceColumns := make([]string, 0)
- user := model.User{
- Id: req.UID,
- }
- if req.Memo != "" {
- user.Memo = req.Memo
- forceColumns = append(forceColumns, "memo")
- }
- if req.Disable != false {
- user.State = 2
- forceColumns = append(forceColumns, "state")
- }
- if req.LastLoginIp != "" {
- user.LastLoginIp = req.LastLoginIp
- forceColumns = append(forceColumns, "last_login_ip")
- }
- if req.Avatar != "" {
- user.Avatar = req.Avatar
- forceColumns = append(forceColumns, "avatar")
- }
- if len(forceColumns) > 0 {
- affected, err1 = userDb.UserUpdate(req.UID, &user)
- if err1 != nil {
- e.OutErr(c, e.ERR_DB_ORM, err1.Error())
- return
- }
- }
-
- var err2 error
- if req.Tag != 0 {
- record := model.UserTagRecords{
- TagId: req.Tag,
- }
- recordsDb := implement.NewUserTagRecordsDb(db.Db)
- affected, err2 = recordsDb.UserTagRecordsUpdate(req.UID, &record, "tag_id")
- if err2 != nil {
- e.OutErr(c, e.ERR_DB_ORM, err2.Error())
- return
- }
-
- }
-
- e.OutSuc(c, affected, nil)
- }
-
- // UserManagementGetOneBasic
- // @Summary 制度中心-会员中心-会员明细概况(获取)
- // @Tags 会员中心
- // @Description 会员明细概况(更新)
- // @Accept json
- // @Produce json
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Param uid query int true "用户 ID"
- // @Success 200 {object} md.UserManagementGetOneBasicResp "会员明细概况具体数据"
- // @Failure 400 {object} md.Response "具体错误"
- // @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()
- //}
|