编辑删除用户时处理role

pull/30/head
taoshihan1991 4 years ago
parent f0d52f304c
commit 9374049a67

@ -62,6 +62,10 @@ func PostKefuInfo(c *gin.Context){
password=tools.Md5(password)
}
models.UpdateUser(id,name,password,avator,nickname)
roleIdInt,_:=strconv.Atoi(roleId)
uid,_:=strconv.Atoi(id)
models.DeleteRoleByUserId(uid)
models.CreateUserRole(uint(uid),uint(roleIdInt))
}
c.JSON(200, gin.H{
@ -81,6 +85,7 @@ func GetKefuList(c *gin.Context){
func DeleteKefuInfo(c *gin.Context){
kefuId := c.Query("id")
models.DeleteUserById(kefuId)
models.DeleteRoleByUserId(kefuId)
c.JSON(200, gin.H{
"code": 200,
"msg": "删除成功",

@ -20,3 +20,6 @@ func CreateUserRole(userId uint,roleId uint){
}
DB.Create(uRole)
}
func DeleteRoleByUserId(userId interface{}){
DB.Where("user_id = ?", userId).Delete(User_role{})
}

@ -40,7 +40,7 @@ func FindUser(username string)User{
}
func FindUserById(id interface{})User{
var user User
DB.Select("user.*,role.name role_name").Joins("join user_role on user.id=user_role.user_id").Joins("join role on user_role.role_id=role.id").Where("user.id = ?", id).First(&user)
DB.Select("user.*,role.name role_name,role.id role_id").Joins("join user_role on user.id=user_role.user_id").Joins("join role on user_role.role_id=role.id").Where("user.id = ?", id).First(&user)
return user
}
func DeleteUserById(id string){

Loading…
Cancel
Save