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

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

View File

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

View File

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