超管后台 - 对接删除项目

This commit is contained in:
柳清爽
2025-04-21 11:46:54 +08:00
parent cc05564328
commit fef6e0fd84
3 changed files with 89 additions and 11 deletions

View File

@@ -61,16 +61,14 @@ class DeleteCompanyController extends BaseController
* @param int $companId
* @throws \Exception
*/
protected function deleteUser(int $companId): void
protected function deleteUsers(int $companId): void
{
$user = UserModel::where('companyId', $companId)->find();
$users = UserModel::where('companyId', $companId)->select();
if (!$user) {
throw new \Exception('用户不存在', 404);
}
if (!$user->delete()) {
throw new \Exception('用户删除失败', 400);
foreach ($users as $user) {
if (!$user->delete()) {
throw new \Exception($user->username . ' 用户删除失败', 400);
}
}
}
@@ -87,7 +85,7 @@ class DeleteCompanyController extends BaseController
$this->deleteCompany($companId);
// 2. 删除用户
$this->deleteUser($companId);
$this->deleteUsers($companId);
return $this;
}