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" "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 } _ = 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, 0, 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() //}