// +---------------------------------------------------------------------- namespace plugin\saiadmin\app\logic\system; use plugin\saiadmin\basic\BaseLogic; use plugin\saiadmin\exception\ApiException; use plugin\saiadmin\app\model\system\SystemConfig; use plugin\saiadmin\app\model\system\SystemConfigGroup; use support\Cache; use plugin\saiadmin\utils\Helper; use support\think\Db; /** * 参数配置逻辑层 */ class SystemConfigLogic extends BaseLogic { /** * 构造函数 */ public function __construct() { $this->model = new SystemConfig(); } /** * 获取配置组 */ public function getGroup($config) { $prefix = 'cfg_'; $data = Cache::get($prefix . $config); if (!is_null($data)) { return $data; } $group = SystemConfigGroup::where('code', $config)->findOrEmpty(); if ($group->isEmpty()) { throw new ApiException('配置组不存在'); } $info = $this->model->where('group_id', $group->id)->select(); Cache::set($prefix . $config, $info->toArray()); return $info; } /** * 获取系统配置 */ public function getSystemConfig($where) { $groupCode = $where['group_code']; $key = $where['key']; $data = Db::connect('db_system')->table('sa_system_config_group')->where('code', $groupCode)->find(); if(empty($data)){ throw new ApiException('配置组不存在'); } $data = Db::connect('db_system')->table('sa_system_config')->where('group_id', $data['id'])->where('key', $key)->find(); if(empty($data)){ throw new ApiException('配置不存在'); } return $data; } }