Skip to content

Commit 2455ae6

Browse files
committed
所有接口中增加批量删除
1 parent a433aaa commit 2455ae6

File tree

10 files changed

+85
-23
lines changed

10 files changed

+85
-23
lines changed

app/Controller/Auth/UserController.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use App\Constants\UploadCode;
99
use App\Controller\AbstractController;
1010
use App\Foundation\Annotation\Explanation;
11+
use App\Model\Laboratory\FriendRelation;
1112
use App\Service\Auth\UserService;
1213
use App\Model\Auth\User;
1314
use Donjan\Permission\Models\Role;
@@ -347,9 +348,18 @@ public function update(int $id)
347348
*/
348349
public function destroy(int $id)
349350
{
350-
if (!intval($id)) $this->throwExp(StatusCode::ERR_VALIDATION, '参数错误');
351-
if (!User::destroy($id)) $this->throwExp(StatusCode::ERR_EXCEPTION, '删除失败');
352-
351+
if ($id == 0) {
352+
$idArr = $this->request->input('id') ?? [];
353+
if (empty($idArr) || !is_array($idArr)) $this->throwExp(StatusCode::ERR_VALIDATION, '参数类型不正确');
354+
if (!User::whereIn('id', $idArr)->delete()) $this->throwExp(StatusCode::ERR_EXCEPTION, '删除失败');
355+
356+
//清理聊天好友关系
357+
FriendRelation::query()->whereIn('uid', $idArr)->orWhereIn('friend_id', $idArr)->delete();
358+
}else {
359+
if (!intval($id)) $this->throwExp(StatusCode::ERR_VALIDATION, '参数错误');
360+
if (!User::destroy($id)) $this->throwExp(StatusCode::ERR_EXCEPTION, '删除失败');
361+
FriendRelation::query()->where('uid', $id)->orWhere('friend_id', $id)->delete();
362+
}
353363
return $this->successByMessage('删除用户成功');
354364
}
355365

app/Controller/Blog/AlbumController.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use App\Foundation\Annotation\Explanation;
1010
use App\Model\Blog\PhotoAlbum;
1111
use App\Model\System\DictData;
12+
use App\Model\System\GlobalConfig;
1213
use Hyperf\Di\Annotation\Inject;
1314
use Hyperf\HttpServer\Annotation\Controller;
1415
use Hyperf\HttpServer\Annotation\Middleware;
@@ -212,8 +213,14 @@ public function update(int $id)
212213
*/
213214
public function destroy(int $id)
214215
{
215-
if (!intval($id)) $this->throwExp(StatusCode::ERR_VALIDATION, '参数错误');
216-
if (!PhotoAlbum::destroy($id)) $this->throwExp(StatusCode::ERR_EXCEPTION, '删除失败');
216+
if ($id == 0) {
217+
$idArr = $this->request->input('id') ?? [];
218+
if (empty($idArr) || !is_array($idArr)) $this->throwExp(StatusCode::ERR_VALIDATION, '参数类型不正确');
219+
if (!PhotoAlbum::whereIn('id', $idArr)->delete()) $this->throwExp(StatusCode::ERR_EXCEPTION, '删除失败');
220+
}else {
221+
if (!intval($id)) $this->throwExp(StatusCode::ERR_VALIDATION, '参数错误');
222+
if (!PhotoAlbum::destroy($id)) $this->throwExp(StatusCode::ERR_EXCEPTION, '删除失败');
223+
}
217224

218225
return $this->successByMessage('删除相册成功');
219226
}

app/Controller/Blog/PhotoController.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,14 @@ public function store()
108108
*/
109109
public function destroy(int $id)
110110
{
111-
if (!intval($id)) $this->throwExp(StatusCode::ERR_VALIDATION, '参数错误');
112-
if (!Photo::destroy($id)) $this->throwExp(StatusCode::ERR_EXCEPTION, '删除失败');
111+
if ($id == 0) {
112+
$idArr = $this->request->input('id') ?? [];
113+
if (empty($idArr) || !is_array($idArr)) $this->throwExp(StatusCode::ERR_VALIDATION, '参数类型不正确');
114+
if (!Photo::whereIn('id', $idArr)->delete()) $this->throwExp(StatusCode::ERR_EXCEPTION, '删除失败');
115+
}else {
116+
if (!intval($id)) $this->throwExp(StatusCode::ERR_VALIDATION, '参数错误');
117+
if (!Photo::destroy($id)) $this->throwExp(StatusCode::ERR_EXCEPTION, '删除失败');
118+
}
113119

114120
return $this->successByMessage('删除图片成功');
115121
}

app/Controller/Setting/TimedTaskController.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use App\Controller\AbstractController;
99
use App\Foundation\Annotation\Explanation;
1010
use App\Foundation\Utils\Cron;
11+
use App\Model\Auth\User;
12+
use App\Model\Laboratory\FriendRelation;
1113
use App\Model\Setting\TimedTask;
1214
use Hyperf\Di\Annotation\Inject;
1315
use Hyperf\HttpServer\Annotation\Controller;
@@ -222,8 +224,14 @@ public function update(int $id)
222224
*/
223225
public function destroy(int $id)
224226
{
225-
if (!intval($id)) $this->throwExp(StatusCode::ERR_VALIDATION, '参数错误');
226-
if (!TimedTask::destroy($id)) $this->throwExp(StatusCode::ERR_EXCEPTION, '删除失败');
227+
if ($id == 0) {
228+
$idArr = $this->request->input('id') ?? [];
229+
if (empty($idArr) || !is_array($idArr)) $this->throwExp(StatusCode::ERR_VALIDATION, '参数类型不正确');
230+
if (!TimedTask::whereIn('id', $idArr)->delete()) $this->throwExp(StatusCode::ERR_EXCEPTION, '删除失败');
231+
}else {
232+
if (!intval($id)) $this->throwExp(StatusCode::ERR_VALIDATION, '参数错误');
233+
if (!TimedTask::destroy($id)) $this->throwExp(StatusCode::ERR_EXCEPTION, '删除失败');
234+
}
227235

228236
return $this->successByMessage('删除定时任务成功');
229237
}

app/Controller/System/AdviceController.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,14 @@ public function reply(int $id)
217217
*/
218218
public function destroy(int $id)
219219
{
220-
if (!intval($id)) $this->throwExp(StatusCode::ERR_VALIDATION, '参数错误');
221-
if (!Advice::destroy($id)) $this->throwExp(StatusCode::ERR_EXCEPTION, '删除失败');
220+
if ($id == 0) {
221+
$idArr = $this->request->input('id') ?? [];
222+
if (empty($idArr) || !is_array($idArr)) $this->throwExp(StatusCode::ERR_VALIDATION, '参数类型不正确');
223+
if (!Advice::whereIn('id', $idArr)->delete()) $this->throwExp(StatusCode::ERR_EXCEPTION, '删除失败');
224+
}else {
225+
if (!intval($id)) $this->throwExp(StatusCode::ERR_VALIDATION, '参数错误');
226+
if (!Advice::destroy($id)) $this->throwExp(StatusCode::ERR_EXCEPTION, '删除失败');
227+
}
222228

223229
return $this->successByMessage('删除系统建议成功');
224230
}

app/Controller/System/DictDataController.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use App\Controller\AbstractController;
99
use App\Foundation\Annotation\Explanation;
1010
use App\Model\System\DictData;
11+
use App\Model\System\DictType;
1112
use Hyperf\Di\Annotation\Inject;
1213
use Hyperf\HttpServer\Annotation\Controller;
1314
use Hyperf\HttpServer\Annotation\Middleware;
@@ -207,10 +208,16 @@ public function update(int $id)
207208
*/
208209
public function destroy(int $id)
209210
{
210-
if (!intval($id)) $this->throwExp(StatusCode::ERR_VALIDATION, '参数错误');
211-
if (!DictData::destroy($id)) $this->throwExp(StatusCode::ERR_EXCEPTION, '删除失败');
211+
if ($id == 0) {
212+
$idArr = $this->request->input('id') ?? [];
213+
if (empty($idArr) || !is_array($idArr)) $this->throwExp(StatusCode::ERR_VALIDATION, '参数类型不正确');
214+
if (!DictData::whereIn('dict_code', $idArr)->delete()) $this->throwExp(StatusCode::ERR_EXCEPTION, '删除失败');
215+
}else {
216+
if (!intval($id)) $this->throwExp(StatusCode::ERR_VALIDATION, '参数错误');
217+
if (!DictData::destroy($id)) $this->throwExp(StatusCode::ERR_EXCEPTION, '删除失败');
218+
}
212219

213-
return $this->successByMessage('删除字典数据成功');
220+
return $this->successByMessage('删除定时任务成功');
214221
}
215222

216223
}

app/Controller/System/DictTypeController.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,16 @@ public function update(int $id)
177177
*/
178178
public function destroy(int $id)
179179
{
180-
if (!intval($id)) $this->throwExp(StatusCode::ERR_VALIDATION, '参数错误');
181-
if (!DictType::destroy($id)) $this->throwExp(StatusCode::ERR_EXCEPTION, '删除失败');
182-
183-
return $this->successByMessage('删除字典类型成功');
180+
if ($id == 0) {
181+
$idArr = $this->request->input('id') ?? [];
182+
if (empty($idArr) || !is_array($idArr)) $this->throwExp(StatusCode::ERR_VALIDATION, '参数类型不正确');
183+
if (!DictType::whereIn('dict_id', $idArr)->delete()) $this->throwExp(StatusCode::ERR_EXCEPTION, '删除失败');
184+
}else {
185+
if (!intval($id)) $this->throwExp(StatusCode::ERR_VALIDATION, '参数错误');
186+
if (!DictType::destroy($id)) $this->throwExp(StatusCode::ERR_EXCEPTION, '删除失败');
187+
}
188+
189+
return $this->successByMessage('删除定时任务成功');
184190
}
185191

186192
}

app/Controller/System/GlobalConfigController.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,14 @@ public function update(int $id)
188188
*/
189189
public function destroy(int $id)
190190
{
191-
if (!intval($id)) $this->throwExp(StatusCode::ERR_VALIDATION, '参数错误');
192-
if (!GlobalConfig::destroy($id)) $this->throwExp(StatusCode::ERR_EXCEPTION, '删除失败');
191+
if ($id == 0) {
192+
$idArr = $this->request->input('id') ?? [];
193+
if (empty($idArr) || !is_array($idArr)) $this->throwExp(StatusCode::ERR_VALIDATION, '参数类型不正确');
194+
if (!GlobalConfig::whereIn('id', $idArr)->delete()) $this->throwExp(StatusCode::ERR_EXCEPTION, '删除失败');
195+
}else {
196+
if (!intval($id)) $this->throwExp(StatusCode::ERR_VALIDATION, '参数错误');
197+
if (!GlobalConfig::destroy($id)) $this->throwExp(StatusCode::ERR_EXCEPTION, '删除失败');
198+
}
193199

194200
return $this->successByMessage('删除全局参数成功');
195201
}

app/Controller/System/NoticeController.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,14 @@ public function update(int $id)
188188
*/
189189
public function destroy(int $id)
190190
{
191-
if (!intval($id)) $this->throwExp(StatusCode::ERR_VALIDATION, '参数错误');
192-
if (!Notice::destroy($id)) $this->throwExp(StatusCode::ERR_EXCEPTION, '删除失败');
191+
if ($id == 0) {
192+
$idArr = $this->request->input('id') ?? [];
193+
if (empty($idArr) || !is_array($idArr)) $this->throwExp(StatusCode::ERR_VALIDATION, '参数类型不正确');
194+
if (!Notice::whereIn('id', $idArr)->delete()) $this->throwExp(StatusCode::ERR_EXCEPTION, '删除失败');
195+
}else {
196+
if (!intval($id)) $this->throwExp(StatusCode::ERR_VALIDATION, '参数错误');
197+
if (!Notice::destroy($id)) $this->throwExp(StatusCode::ERR_EXCEPTION, '删除失败');
198+
}
193199

194200
return $this->successByMessage('删除系统通知成功');
195201
}

config/autoload/permissionData.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@
10121012
"display_name" => "系统日志",
10131013
"display_desc" => "系统的框架日志以及错误日志",
10141014
"url" => "/setting/log_module/system_log/list",
1015-
"component" => "setting/log+module/systemLog",
1015+
"component" => "setting/log_module/systemLog",
10161016
"guard_name" => "web",
10171017
"icon" => "logs",
10181018
"type" => "2",

0 commit comments

Comments
 (0)