Skip to content

Commit

Permalink
修复删除用户BUG
Browse files Browse the repository at this point in the history
  • Loading branch information
lifei6671 committed Jul 10, 2017
1 parent 3aa1552 commit 4eb8aeb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
5 changes: 4 additions & 1 deletion controllers/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,15 @@ func (c *ManagerController) DeleteMember() {
c.JsonResult(404,"参数错误")
}

_ ,err := models.NewMember().Find(member_id)
member ,err := models.NewMember().Find(member_id)

if err != nil {
beego.Error(err)
c.JsonResult(500,"用户不存在")
}
if member.Role == conf.MemberSuperRole {
c.JsonResult(500,"不能删除超级管理员")
}
superMember,err := models.NewMember().FindByFieldFirst("role",0)

if err != nil {
Expand Down
23 changes: 19 additions & 4 deletions models/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +390,26 @@ func (m *Member) Delete(oldId int,newId int) error {

if err == nil {
for _,relationship := range relationship_list {
if o.QueryTable(relationship.TableNameWithPrefix()).Filter("book_id",relationship.BookId).Exist() {
o.Delete(relationship)
}else{
//如果存在创始人,则删除
if relationship.RoleId == 0 {
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
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)
}
}
}
}
Expand Down

0 comments on commit 4eb8aeb

Please sign in to comment.