mirror of
https://gitee.com/wonderful-code/buildadmin
synced 2024-11-21 22:55:36 +00:00
refactor:优化管理员管理和菜单规则管理的控制器代码
This commit is contained in:
parent
5a8cd3422c
commit
9e784a5d72
@ -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();
|
||||
$where[] = [$pk, 'in', $ids];
|
||||
|
||||
$count = 0;
|
||||
$data = $this->model->where($where)->select();
|
||||
$this->model->startTrans();
|
||||
try {
|
||||
foreach ($data as $v) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user