refactor(admin): remove unused 'where' option in system module
- Remove unnecessary 'where' option from various models in system module - Simplify query methods by removing redundant 'where' calls - Affected models: Config, Node, SystemAdmin, SystemMenu, SystemNode
This commit is contained in:
@@ -70,7 +70,7 @@ class Admin extends AdminController
|
||||
try {
|
||||
$save = $this->model->save($post);
|
||||
}catch (\Exception $e) {
|
||||
$this->error('保存失败');
|
||||
$this->error('保存失败' . $e->getMessage());
|
||||
}
|
||||
$save ? $this->success('保存成功') : $this->error('保存失败');
|
||||
}
|
||||
@@ -88,14 +88,11 @@ class Admin extends AdminController
|
||||
$post['auth_ids'] = implode(',', array_keys($authIds));
|
||||
$rule = [];
|
||||
$this->validate($post, $rule);
|
||||
if (isset($row['password'])) {
|
||||
unset($row['password']);
|
||||
}
|
||||
try {
|
||||
$save = $row->save($post);
|
||||
TriggerService::updateMenu($id);
|
||||
}catch (\Exception $e) {
|
||||
$this->error('保存失败');
|
||||
$this->error('保存失败' . $e->getMessage());
|
||||
}
|
||||
$save ? $this->success('保存成功') : $this->error('保存失败');
|
||||
}
|
||||
|
||||
@@ -41,12 +41,12 @@ class Config extends AdminController
|
||||
if ($group == 'upload') {
|
||||
$upload_types = config('admin.upload_types');
|
||||
// 兼容旧版本
|
||||
$this->model->removeOption('where')->where('name', 'upload_allow_type')->update(['value' => implode(',', array_keys($upload_types))]);
|
||||
$this->model->removeOption()->where('name', 'upload_allow_type')->update(['value' => implode(',', array_keys($upload_types))]);
|
||||
}
|
||||
foreach ($post as $key => $val) {
|
||||
if (in_array($key, $notAddFields)) continue;
|
||||
if ($this->model->removeOption('where')->where('name', $key)->count()) {
|
||||
$this->model->removeOption('where')->where('name', $key)->update(['value' => $val,]);
|
||||
if ($this->model->removeOption()->where('name', $key)->count()) {
|
||||
$this->model->removeOption()->where('name', $key)->update(['value' => $val,]);
|
||||
}else {
|
||||
$this->model->create(
|
||||
[
|
||||
@@ -59,7 +59,7 @@ class Config extends AdminController
|
||||
TriggerService::updateMenu();
|
||||
TriggerService::updateSysConfig();
|
||||
}catch (\Exception $e) {
|
||||
$this->error('保存失败' .$e->getMessage());
|
||||
$this->error('保存失败' . $e->getMessage());
|
||||
}
|
||||
$this->success('保存成功');
|
||||
}
|
||||
|
||||
@@ -58,11 +58,11 @@ class Node extends AdminController
|
||||
|
||||
try {
|
||||
if ($force == 1) {
|
||||
$updateNodeList = $model->removeOption('where')->whereIn('node', array_column($nodeList, 'node'))->select();
|
||||
$updateNodeList = $model->removeOption()->whereIn('node', array_column($nodeList, 'node'))->select();
|
||||
$formatNodeList = array_format_key($nodeList, 'node');
|
||||
foreach ($updateNodeList as $vo) {
|
||||
isset($formatNodeList[$vo['node']])
|
||||
&& $model->removeOption('where')->where('id', $vo['id'])->update(
|
||||
&& $model->removeOption()->where('id', $vo['id'])->update(
|
||||
[
|
||||
'title' => $formatNodeList[$vo['node']]['title'],
|
||||
'is_auth' => $formatNodeList[$vo['node']]['is_auth'],
|
||||
@@ -70,7 +70,7 @@ class Node extends AdminController
|
||||
);
|
||||
}
|
||||
}
|
||||
$existNodeList = $model->removeOption('where')->field('node,title,type,is_auth')->select();
|
||||
$existNodeList = $model->removeOption()->field('node,title,type,is_auth')->select();
|
||||
foreach ($nodeList as $key => $vo) {
|
||||
foreach ($existNodeList as $v) {
|
||||
if ($vo['node'] == $v->node) {
|
||||
|
||||
@@ -30,7 +30,7 @@ class SystemAdmin extends TimeModel
|
||||
|
||||
public function getAuthList(): array
|
||||
{
|
||||
return (new SystemAuth())->removeOption('where')->where('status', 1)->column('title', 'id');
|
||||
return (new SystemAuth())->removeOption()->where('status', 1)->column('title', 'id');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,7 +25,7 @@ class SystemMenu extends TimeModel
|
||||
*/
|
||||
public function getPidMenuList(): array
|
||||
{
|
||||
$list = $this->removeOption('where')->field('id,pid,title')->where([
|
||||
$list = $this->removeOption()->field('id,pid,title')->where([
|
||||
['pid', '<>', MenuConstant::HOME_PID],
|
||||
['status', '=', 1],
|
||||
])->select()->toArray();
|
||||
|
||||
@@ -9,7 +9,7 @@ class SystemNode extends TimeModel
|
||||
|
||||
public function getNodeTreeList(): array
|
||||
{
|
||||
$list = $this->removeOption('where')->select()->toArray();
|
||||
$list = $this->removeOption()->select()->toArray();
|
||||
return $this->buildNodeTree($list);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user