mirror of
https://github.com/mindoc-org/mindoc.git
synced 2026-02-27 17:03:57 +08:00
完善功能
This commit is contained in:
@@ -90,6 +90,14 @@ func (m *Relationship) FindForRoleId(book_id ,member_id int) (int,error) {
|
||||
return relationship.RoleId,nil
|
||||
}
|
||||
|
||||
func (m *Relationship) FindByBookIdAndMemberId(book_id ,member_id int) (*Relationship,error) {
|
||||
o := orm.NewOrm()
|
||||
|
||||
err := o.QueryTable(m.TableNameWithPrefix()).Filter("book_id",book_id).Filter("member_id",member_id).One(m)
|
||||
|
||||
return m,err
|
||||
}
|
||||
|
||||
func (m *Relationship) Insert() error {
|
||||
o := orm.NewOrm()
|
||||
|
||||
@@ -127,6 +135,46 @@ func (m *Relationship) DeleteByBookIdAndMemberId(book_id,member_id int) error {
|
||||
|
||||
}
|
||||
|
||||
func (m *Relationship) Transfer(book_id,founder_id,receive_id int) error {
|
||||
o := orm.NewOrm()
|
||||
|
||||
founder := NewRelationship()
|
||||
|
||||
err := o.QueryTable(m.TableNameWithPrefix()).Filter("book_id",book_id).Filter("member_id",founder_id).One(founder)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if founder.RoleId != conf.BookFounder {
|
||||
return errors.New("转让者不是创始人")
|
||||
}
|
||||
receive := NewRelationship()
|
||||
|
||||
err = o.QueryTable(m.TableNameWithPrefix()).Filter("book_id",book_id).Filter("member_id",receive_id).One(receive)
|
||||
|
||||
if err != orm.ErrNoRows && err != nil {
|
||||
return err
|
||||
}
|
||||
o.Begin()
|
||||
|
||||
founder.RoleId = conf.BookAdmin
|
||||
|
||||
receive.MemberId = receive_id
|
||||
receive.RoleId = conf.BookFounder
|
||||
receive.BookId = book_id
|
||||
|
||||
if err := founder.Update();err != nil {
|
||||
o.Rollback()
|
||||
return err
|
||||
}
|
||||
if _,err := o.InsertOrUpdate(receive);err != nil {
|
||||
o.Rollback()
|
||||
return err
|
||||
}
|
||||
return o.Commit()
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user