功能:平台管理员删除商户账号
This commit is contained in:
@@ -316,3 +316,31 @@ func (s *UserService) DeletePlatformAdmin(id, actorUserID uint) error {
|
||||
return tx.Delete(&user).Error
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteMerchantAccount permanently removes a merchant login account and all
|
||||
// of its merchant memberships. Platform administrators must be managed from
|
||||
// the dedicated platform administrator view instead.
|
||||
func (s *UserService) DeleteMerchantAccount(id, actorUserID uint) error {
|
||||
if id == 0 {
|
||||
return errors.New("用户不存在")
|
||||
}
|
||||
if id == actorUserID {
|
||||
return errors.New("不能删除当前登录账号")
|
||||
}
|
||||
return s.db.Transaction(func(tx *gorm.DB) error {
|
||||
var user model.User
|
||||
if err := tx.First(&user, id).Error; err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return errors.New("用户不存在")
|
||||
}
|
||||
return err
|
||||
}
|
||||
if user.Role != model.RoleMerchant {
|
||||
return errors.New("平台管理员请在平台管理员列表中管理")
|
||||
}
|
||||
if err := tx.Where("user_id = ?", user.ID).Delete(&model.MerchantMember{}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return tx.Delete(&user).Error
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user