(bookId, founderId, receiveId int)
| 136 | } |
| 137 | |
| 138 | func (m *Relationship) Transfer(bookId, founderId, receiveId int) error { |
| 139 | o := orm.NewOrm() |
| 140 | |
| 141 | founder := NewRelationship() |
| 142 | |
| 143 | err := o.QueryTable(m.TableNameWithPrefix()).Filter("book_id", bookId).Filter("member_id", founderId).One(founder) |
| 144 | |
| 145 | if err != nil { |
| 146 | return err |
| 147 | } |
| 148 | if founder.RoleId != conf.BookFounder { |
| 149 | return errors.New("转让者不是创始人") |
| 150 | } |
| 151 | receive := NewRelationship() |
| 152 | |
| 153 | err = o.QueryTable(m.TableNameWithPrefix()).Filter("book_id", bookId).Filter("member_id", receiveId).One(receive) |
| 154 | |
| 155 | if err != orm.ErrNoRows && err != nil { |
| 156 | return err |
| 157 | } |
| 158 | o.Begin() |
| 159 | |
| 160 | founder.RoleId = conf.BookAdmin |
| 161 | |
| 162 | receive.MemberId = receiveId |
| 163 | receive.RoleId = conf.BookFounder |
| 164 | receive.BookId = bookId |
| 165 | |
| 166 | if err := founder.Update(); err != nil { |
| 167 | o.Rollback() |
| 168 | return err |
| 169 | } |
| 170 | if receive.RelationshipId > 0 { |
| 171 | if _, err := o.Update(receive); err != nil { |
| 172 | o.Rollback() |
| 173 | return err |
| 174 | } |
| 175 | } else { |
| 176 | if _, err := o.Insert(receive); err != nil { |
| 177 | o.Rollback() |
| 178 | return err |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | return o.Commit() |
| 183 | } |
| 184 | |
| 185 | // HasRelatedBook 查询用户是否有相关联的书籍 |
| 186 | func (m *Relationship) HasRelatedBook(uid int) bool { |
nothing calls this directly
no test coverage detected