set user_id=0 at peers, when the user is deleted
This commit is contained in:
@@ -58,6 +58,11 @@ func (ps *PeerService) UuidUnbindUserId(uuid string, userId uint) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EraseUserId 清除用户id, 用于用户删除
|
||||||
|
func (ps *PeerService) EraseUserId(userId uint) error {
|
||||||
|
return global.DB.Model(&model.Peer{}).Where("user_id = ?", userId).Update("user_id", 0).Error
|
||||||
|
}
|
||||||
|
|
||||||
// ListByUserIds 根据用户id取列表
|
// ListByUserIds 根据用户id取列表
|
||||||
func (ps *PeerService) ListByUserIds(userIds []uint, page, pageSize uint) (res *model.PeerList) {
|
func (ps *PeerService) ListByUserIds(userIds []uint, page, pageSize uint) (res *model.PeerList) {
|
||||||
res = &model.PeerList{}
|
res = &model.PeerList{}
|
||||||
|
|||||||
@@ -207,6 +207,11 @@ func (us *UserService) Delete(u *model.User) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
tx.Commit()
|
tx.Commit()
|
||||||
|
// 删除关联的peer
|
||||||
|
if err := AllService.PeerService.EraseUserId(u.Id); err != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
return err
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user