refactor: 修改配置列表支持区分语言查询

This commit is contained in:
2025-03-26 14:12:46 +08:00
parent 2eeab2af16
commit 43c54b0e4f
2 changed files with 18 additions and 23 deletions

View File

@@ -54,9 +54,6 @@ class SiteConfig
return $item;
})
->toArray();
if (empty($configs)) {
return error('配置项不存在');
}
// 处理附加配置项及联动项
$configs = $this->handleExtra($configs);

View File

@@ -50,31 +50,29 @@ class SysConfig
'size/d' => 10
]);
$configs = SysConfigModel::field([
'id',
'group_id',
'title',
'name',
'type',
'sort'
$configs = SysConfigModel::alias('cfg')
->field([
'cfg.id',
'cfg.title',
'cfg.name',
'cfg.type',
'cfg.sort',
'grp.name' => 'group_name',
'type.name' => 'type_name'
])
->with([
'group' => function($query) {
$query->field(['id', 'name' => 'group_name']);
},
'type' => function($query) {
$query->field(['name' => 'type_name', 'value']);
->join('sys_config_group grp', 'grp.id = cfg.group_id')
->join('sys_config_type type', 'type.value = cfg.type')
->where('grp.language_id', '=', request()->lang_id)
->where(function($query) use($param) {
if (!empty($param['title'])) {
$query->where('cfg.title', 'like', "%{$param['title']}%");
}
])
->withSearch(['title'], ['title' => $param['title']??null])
->order(['sort' => 'asc', 'id' => 'desc'])
})
->order(['cfg.sort' => 'asc', 'cfg.id' => 'desc'])
->paginate([
'list_rows' => $param['size'],
'page' => $param['page']
])
->bindAttr('group', ['group_name'])
->bindAttr('type', ['type_name'])
->hidden(['group_id', 'group', 'type']);
]);
return success('获取成功', $configs);
}