超管后台 - 对接删除项目
This commit is contained in:
@@ -36,8 +36,8 @@ Route::group('', function () {
|
||||
Route::group('company', function () {
|
||||
Route::post('create', 'app\superadmin\controller\company\CreateCompanyController@index');
|
||||
Route::post('update', 'app\superadmin\controller\company\UpdateCompanyController@index');
|
||||
Route::post('delete', 'app\superadmin\controller\company\DeleteCompanyController@index');
|
||||
Route::get('list', 'app\superadmin\controller\company\GetCompanyListController@index');
|
||||
Route::get('detail/:id', 'app\superadmin\controller\company\GetCompanyDetailForUpdateController@index');
|
||||
Route::post('delete/:id', 'app\superadmin\controller\company\DeleteCompanyController@index');
|
||||
});
|
||||
})->middleware(['app\superadmin\middleware\AdminAuth']);
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user