diff --git a/app/admin/controller/auth/Admin.php b/app/admin/controller/auth/Admin.php index 2c49d263..c7fea36c 100644 --- a/app/admin/controller/auth/Admin.php +++ b/app/admin/controller/auth/Admin.php @@ -221,14 +221,17 @@ class Admin extends Backend $this->error(__('Parameter error')); } + $where = []; $dataLimitAdminIds = $this->getDataLimitAdminIds(); if ($dataLimitAdminIds) { - $this->model->where($this->dataLimitField, 'in', $dataLimitAdminIds); + $where[] = [$this->dataLimitField, 'in', $dataLimitAdminIds]; } - $pk = $this->model->getPk(); - $data = $this->model->where($pk, 'in', $ids)->select(); + $pk = $this->model->getPk(); + $where[] = [$pk, 'in', $ids]; + $count = 0; + $data = $this->model->where($where)->select(); $this->model->startTrans(); try { foreach ($data as $v) { diff --git a/app/admin/controller/auth/Rule.php b/app/admin/controller/auth/Rule.php index e697d350..a81433bc 100644 --- a/app/admin/controller/auth/Rule.php +++ b/app/admin/controller/auth/Rule.php @@ -207,35 +207,15 @@ class Rule extends Backend $this->error(__('Parameter error')); } - $dataLimitAdminIds = $this->getDataLimitAdminIds(); - if ($dataLimitAdminIds) { - $this->model->where($this->dataLimitField, 'in', $dataLimitAdminIds); - } - - $pk = $this->model->getPk(); - $data = $this->model->where($pk, 'in', $ids)->select(); + // 子级元素检查 $subData = $this->model->where('pid', 'in', $ids)->column('pid', 'id'); foreach ($subData as $key => $subDatum) { if (!in_array($key, $ids)) { $this->error(__('Please delete the child element first, or use batch deletion')); } } - $count = 0; - $this->model->startTrans(); - try { - foreach ($data as $v) { - $count += $v->delete(); - } - $this->model->commit(); - } catch (Throwable $e) { - $this->model->rollback(); - $this->error($e->getMessage()); - } - if ($count) { - $this->success(__('Deleted successfully')); - } else { - $this->error(__('No rows were deleted')); - } + + parent::del($ids); } /** diff --git a/app/admin/controller/user/Rule.php b/app/admin/controller/user/Rule.php index ebc52f5c..3942ecfd 100644 --- a/app/admin/controller/user/Rule.php +++ b/app/admin/controller/user/Rule.php @@ -203,35 +203,15 @@ class Rule extends Backend $this->error(__('Parameter error')); } - $dataLimitAdminIds = $this->getDataLimitAdminIds(); - if ($dataLimitAdminIds) { - $this->model->where($this->dataLimitField, 'in', $dataLimitAdminIds); - } - - $pk = $this->model->getPk(); - $data = $this->model->where($pk, 'in', $ids)->select(); + // 子级元素检查 $subData = $this->model->where('pid', 'in', $ids)->column('pid', 'id'); foreach ($subData as $key => $subDatum) { if (!in_array($key, $ids)) { $this->error(__('Please delete the child element first, or use batch deletion')); } } - $count = 0; - $this->model->startTrans(); - try { - foreach ($data as $v) { - $count += $v->delete(); - } - $this->model->commit(); - } catch (Throwable $e) { - $this->model->rollback(); - $this->error($e->getMessage()); - } - if ($count) { - $this->success(__('Deleted successfully')); - } else { - $this->error(__('No rows were deleted')); - } + + parent::del($ids); } /**