From 92e7c94c625541e50ad352b8a1919502b1d02001 Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Wed, 4 Dec 2024 14:48:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=94=A8=E6=88=B7=E6=9D=83?= =?UTF-8?q?=E9=99=90=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dao/user.go | 4 ++-- proto/user_req.go | 6 +++--- service/userService.go | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dao/user.go b/dao/user.go index 05055c1..23d08cd 100644 --- a/dao/user.go +++ b/dao/user.go @@ -79,8 +79,8 @@ func UpdateUserByID(id int, name, password, email string) { // 管理员修改用户信息 func UpdateUserByID2(id int, req proto.UpdateUserInfoReq) { - user := User{Name: req.Username, Age: req.Age, Role: req.Role, Run: *req.Run, Redis: *req.Redis, Upload: *req.Upload, Avatar: req.Avatar, Gender: req.Gender} - DB.Debug().Model(&User{}).Where("id = ?", id).Updates(user) + user := User{Name: req.Username, Age: req.Age, Role: req.Role, Run: req.Run, Redis: req.Redis, Upload: req.Upload, Avatar: req.Avatar, Gender: req.Gender} + DB.Debug().Model(&User{}).Where("id = ?", id).Updates(user).UpdateColumns([]string{"Name", "Age", "Role", "Run", "Redis", "Upload", "Avatar", "Gender"}) } // 用户修改自己的信息 diff --git a/proto/user_req.go b/proto/user_req.go index e2e8788..be15ea6 100644 --- a/proto/user_req.go +++ b/proto/user_req.go @@ -6,8 +6,8 @@ type UpdateUserInfoReq struct { Age int `json:"age" form:"age"` //年龄 Role string `json:"role" form:"role"` //角色 Gender string `json:"gender" form:"gender"` //性别 - Redis *bool `json:"redis" form:"redis"` //是否刷新redis - Upload *bool `json:"upload" form:"upload"` //是否上传头像 - Run *bool `json:"run" form:"run"` //是否运行 + Redis bool `json:"redis" form:"redis"` //是否刷新redis + Upload bool `json:"upload" form:"upload"` //是否上传头像 + Run bool `json:"run" form:"run"` //是否运行 Avatar string `json:"avatar" form:"avatar"` //头像 } diff --git a/service/userService.go b/service/userService.go index f7f6492..ab3ec8b 100644 --- a/service/userService.go +++ b/service/userService.go @@ -46,7 +46,7 @@ func GetUserByNameLike(name string) []proto.User { func UpdateUser(user_id int, req proto.UpdateUserInfoReq) (int, error) { cur_user := dao.FindUserByID2(user_id) fmt.Println("cur_user:", cur_user, "req:", req) - if user_id == req.ID { + if user_id == req.ID && cur_user.Role != "admin" { dao.UpdateUserByID3(user_id, req) //用户修改自己的信息,不能修改权限信息 return user_id, nil } else if cur_user.Role == "admin" {