提交 15985cff 编写于 作者: kanyxmo's avatar kanyxmo

feat: 新增sys_config() 和 sys_group_config() 函数

上级 22267d18
......@@ -32,6 +32,20 @@ class SettingConfigMapper extends AbstractMapper
return $model ? $model->toArray() : [];
}
/**
* 按组的key获取一组配置信息
* @param string $groupKey
* @return array
*/
public function getConfigByGroupKey(string $groupKey): array
{
$prefix = env('DB_PREFIX');
return $this->model::query()->whereRaw(
sprintf('group_id = ( SELECT id FROM %ssetting_config_group WHERE code = ? )', $prefix),
[ $groupKey ]
)->get()->toArray();
}
/**
* 更新配置
* @param string $key
......
......@@ -85,6 +85,16 @@ class SettingConfigService extends AbstractService implements ConfigServiceInter
}
}
/**
* 按组的key获取一组配置信息
* @param string $groupKey
* @return array|null
*/
public function getConfigByGroupKey(string $groupKey): ?array
{
return $this->mapper->getConfigByGroupKey($groupKey);
}
/**
* 清除缓存
* @return bool
......
......@@ -45,4 +45,41 @@ if (! function_exists('make')) {
return \Hyperf\Support\make($name, $parameters);
}
}
if (! function_exists('sys_config')) {
/**
* 获取后台系统配置
*
* @param string $key
* @param null|mixed $default
* @return mixed
* @throws RedisException
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
*/
function sys_config(string $key, mixed $default = null): mixed
{
return container()->get(\App\Setting\Service\SettingConfigService::class)->getConfigByKey($key) ?? $default;
}
}
if (! function_exists('sys_group_config')) {
/**
* 获取后台系统配置
*
* @param string $groupKey
* @param null|mixed $default
* @return mixed
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
*/
function sys_group_config(string $groupKey, mixed $default = []): mixed
{
return container()->get(\App\Setting\Service\SettingConfigService::class)->getConfigByGroupKey($groupKey) ?? $default;
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册