support delete account

This commit is contained in:
MaysWind
2020-11-11 23:50:02 +08:00
parent b5a5032bd2
commit e4407c8137
8 changed files with 104 additions and 2 deletions
+24
View File
@@ -121,3 +121,27 @@ func (s *AccountService) CreateAccounts(mainAccount *models.Account, childrenAcc
return nil
})
}
func (s *AccountService) DeleteAccounts(uid int64, ids []int64) error {
if uid <= 0 {
return errs.ErrUserIdInvalid
}
now := time.Now().Unix()
updateModel := &models.Account{
Deleted: true,
UpdatedUnixTime: now,
DeletedUnixTime: now,
}
return s.UserDataDB(uid).DoTransaction(func(sess *xorm.Session) error {
deletedRows, err := sess.Cols("deleted", "deleted_unix_time").In("account_id", ids).Where("uid=? AND deleted=?", uid, false).Update(updateModel)
if deletedRows < 1 {
return errs.ErrAccountNotFound
}
return err
})
}