package member_center import ( "applet/app/db" "applet/app/e" md "applet/app/md/institutional_management/member_center" "applet/app/utils" "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" "code.fnuoos.com/EggPlanet/egg_models.git/src/model" "github.com/gin-gonic/gin" ) // GetLevelList // @Summary 制度中心-会员中心-等级管理(获取) // @Tags 会员中心 // @Description 标签管理(获取) // @Accept json // @Produce json // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Param limit query int true "每页大小" // @Param page query int true "页数" // @Success 200 {object} md.GetLevelListResp "具体数据" // @Failure 400 {object} md.Response "具体错误" // @Router /api/memberCenter/levelManagement/getLevelList [get] func GetLevelList(c *gin.Context) { page := c.DefaultQuery("page", "1") limit := c.DefaultQuery("limit", "10") levelDb := implement.NewUserLevelDb(db.Db) levels, total, err := levelDb.UserLevelAllByAscByPage(utils.StrToInt(page), utils.StrToInt(limit)) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } sql := "SElECT count(distinct id) as total, level FROM `user` GROUP BY level" results, err := db.QueryNativeString(db.Db, sql) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } var countMap = map[int]string{} for _, res := range results { countMap[utils.StrToInt(res["level"])] = res["total"] } list := make([]md.LevelListNode, 0) for i, level := range levels { list[i].LevelWeight = level.LevelWeight list[i].LevelID = level.Id list[i].LevelName = level.LevelName list[i].Count = countMap[level.Id] list[i].CreateAt = level.CreateAt list[i].IsUse = level.IsUse list[i].Memo = level.Memo } resp := md.GetLevelListResp{ List: list, Paginate: md.Paginate{ Limit: utils.StrToInt(limit), Page: utils.StrToInt(page), Total: total, }, } e.OutSuc(c, resp, nil) } // UpdateLevel // @Summary 制度中心-会员中心-等级管理(更新) // @Tags 会员中心 // @Description 等级管理(更新) // @Accept json // @Produce json // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Param req body md.UpdateLevelReq true "需要修改的等级信息" // @Success 200 {int} "成功修改数据条数" // @Failure 400 {object} md.Response "具体错误" // @Router /api/memberCenter/levelManagement/updateLevel [post] func UpdateLevel(c *gin.Context) { var req *md.UpdateLevelReq if err := c.ShouldBindJSON(&req); err != nil { e.OutErr(c, e.ERR_INVALID_ARGS, err.Error()) return } level := &model.UserLevel{ Id: utils.StrToInt(req.LevelID), LevelName: req.LevelName, LevelWeight: req.LevelWeight, IsUse: req.IsUse, Memo: req.Memo, } forceColumns := []string{"level_weight", "is_use"} levelDb := implement.NewUserLevelDb(db.Db) affected, err := levelDb.UserLevelUpdate(req.LevelID, level, forceColumns...) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } e.OutSuc(c, affected, nil) }