BatchDisablePlanAction.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace App\Module\Cleanup\AdminControllers\Actions;
  3. use Dcat\Admin\Grid\BatchAction;
  4. use Dcat\Admin\Actions\Response;
  5. use Illuminate\Http\Request;
  6. /**
  7. * 批量禁用计划Action
  8. *
  9. * 用于批量禁用清理计划
  10. */
  11. class BatchDisablePlanAction extends BatchAction
  12. {
  13. /**
  14. * 按钮标题
  15. */
  16. protected $title = '批量禁用';
  17. /**
  18. * 处理请求
  19. */
  20. public function handle(Request $request)
  21. {
  22. try {
  23. // 获取选中的ID
  24. $ids = $this->getKey();
  25. if (empty($ids)) {
  26. return $this->response()->error('请选择要禁用的计划');
  27. }
  28. // 批量更新
  29. $count = $this->getModel()::whereIn('id', $ids)->update(['is_enabled' => 0]);
  30. return $this->response()
  31. ->success("成功禁用 {$count} 个计划")
  32. ->refresh();
  33. } catch (\Exception $e) {
  34. return $this->response()
  35. ->error('批量禁用失败:' . $e->getMessage());
  36. }
  37. }
  38. /**
  39. * 确认对话框
  40. */
  41. public function confirm()
  42. {
  43. return [
  44. '确认批量禁用?',
  45. '此操作将禁用选中的所有清理计划。'
  46. ];
  47. }
  48. }