(bookId, memberId, roleId int)
| 57 | } |
| 58 | |
| 59 | func (m *Relationship) UpdateRoleId(bookId, memberId, roleId int) (*Relationship, error) { |
| 60 | o := orm.NewOrm() |
| 61 | book := NewBook() |
| 62 | book.BookId = bookId |
| 63 | |
| 64 | if err := o.Read(book); err != nil { |
| 65 | logs.Error("UpdateRoleId => ", err) |
| 66 | return m, errors.New("书籍不存在") |
| 67 | } |
| 68 | err := o.QueryTable(m.TableNameWithPrefix()).Filter("member_id", memberId).Filter("book_id", bookId).One(m) |
| 69 | if err == orm.ErrNoRows { |
| 70 | m.BookId = bookId |
| 71 | m.MemberId = memberId |
| 72 | m.RoleId = roleId |
| 73 | } else if err != nil { |
| 74 | return m, err |
| 75 | } else if m.RoleId == conf.BookFounder { |
| 76 | return m, errors.New("不能变更创始人的权限") |
| 77 | } |
| 78 | m.RoleId = roleId |
| 79 | |
| 80 | if m.RelationshipId > 0 { |
| 81 | _, err = o.Update(m) |
| 82 | } else { |
| 83 | _, err = o.Insert(m) |
| 84 | } |
| 85 | |
| 86 | return m, err |
| 87 | |
| 88 | } |
| 89 | |
| 90 | func (m *Relationship) FindForRoleId(bookId, memberId int) (int, error) { |
| 91 | o := orm.NewOrm() |
no test coverage detected