修复删除用户BUG

This commit is contained in:
Minho 2017-07-10 16:59:49 +08:00
parent 3aa1552c5c
commit 4eb8aeb999
2 changed files with 23 additions and 5 deletions

View File

@ -248,12 +248,15 @@ func (c *ManagerController) DeleteMember() {
c.JsonResult(404,"参数错误") c.JsonResult(404,"参数错误")
} }
_ ,err := models.NewMember().Find(member_id) member ,err := models.NewMember().Find(member_id)
if err != nil { if err != nil {
beego.Error(err) beego.Error(err)
c.JsonResult(500,"用户不存在") c.JsonResult(500,"用户不存在")
} }
if member.Role == conf.MemberSuperRole {
c.JsonResult(500,"不能删除超级管理员")
}
superMember,err := models.NewMember().FindByFieldFirst("role",0) superMember,err := models.NewMember().FindByFieldFirst("role",0)
if err != nil { if err != nil {

View File

@ -390,11 +390,26 @@ func (m *Member) Delete(oldId int,newId int) error {
if err == nil { if err == nil {
for _,relationship := range relationship_list { for _,relationship := range relationship_list {
if o.QueryTable(relationship.TableNameWithPrefix()).Filter("book_id",relationship.BookId).Exist() { //如果存在创始人,则删除
o.Delete(relationship) if relationship.RoleId == 0 {
}else{ rel := NewRelationship()
err = o.QueryTable(relationship.TableNameWithPrefix()).Filter("book_id",relationship.BookId).Filter("member_id",newId).One(rel)
if err == nil {
if _,err := o.Delete(relationship) ; err != nil{
beego.Error(err)
}
relationship.RelationshipId = rel.RelationshipId
}
relationship.MemberId = newId relationship.MemberId = newId
o.Update(relationship) relationship.RoleId = 0
if _,err := o.Update(relationship) ; err != nil{
beego.Error(err)
}
}else{
if _,err := o.Delete(relationship) ; err != nil{
beego.Error(err)
}
} }
} }
} }