UNIACID ]; if ($name) { $where['name'] = $name; } else { // 系统配置特殊处理:循环校验文件里的配置 if ($type === 'config_system') { $configFilePath = APP_PATH . 'common/model/fill/data/config_system.php'; $config = require($configFilePath); foreach ($config as $item) { if (!empty($item['name'])) { self::check('config_system', $item['name']); } } Cache::set($cacheKey, true, 3600); return true; } } $where = array_merge($where, self::getCondition($type)); $data = Db::name($type)->where($where)->find(); if (!$data) { self::set($type, $name); Cache::set($cacheKey, true, 3600); return true; } Cache::set($cacheKey, true, 3600); return true; } /** * 根据分组检查并初始化配置 * @param string $group 分组名称 * @return bool */ public static function checkByGroup($group): bool { $configFilePath = APP_PATH . 'common/model/fill/data/config_system.php'; $config = require($configFilePath); $toInsert = []; foreach ($config as $item) { if (isset($item['group']) && $item['group'] == $group) { $exists = Db::name('config_system') ->where(['uniacid' => UNIACID, 'name' => $item['name']]) ->find(); if (!$exists) { $item['uniacid'] = UNIACID; $toInsert[] = $item; } } } if (!empty($toInsert)) { self::name('config_system')->insertAll($toInsert); } return true; } /** * 获取系统配置的默认配置 * @param $configName 配置名称 * @param $fieldValue 某个配置项的名称 * @return void */ public static function getSystemDefaultConfig($configName,$fieldName=''){ $configFilePath = APP_PATH . 'common/model/fill/data/config_system.php'; $config = require($configFilePath); $systemConfig = []; foreach ($config as $item){ if($item['name'] == $configName){ $item['value'] = json_decode($item['value'],true); $systemConfig = $item; break; } } if(!$systemConfig){ return []; } if(!$fieldName){ return $systemConfig['value']; } foreach ($systemConfig['value'] as $item){ if($item['name'] == $fieldName){ return $item; } } return []; } /** * 设置配置 * @param $type 配置类型 * @param $name 配置名称 * @return void */ public static function set($type,$name=null){ $configFilePath = APP_PATH . 'common/model/fill/data/'.$type.'.php'; $config = require($configFilePath); if($name){ $temp = null; foreach ($config as &$item){ if($item['name'] == $name){ $item['uniacid'] = UNIACID; $temp = $item; break; } } if(!$temp){ return false; } $data = [$temp]; }else{ foreach ($config as &$item){ $item['uniacid'] = UNIACID; } $data = $config; } self::name($type)->insertAll($data); } /** * 导出默认配置 * @return void */ public static function export($key = ''){ if(!$key){ foreach (self::$configList as $name){ $where = []; $where = array_merge($where,self::getCondition($name)); $data = Db::name($name)->where($where)->field(['id','uniacid'],true)->select(); if($data){ file_put_contents( APP_PATH . 'common/model/fill/data/'.$name.'.php', 'where($where)->field(['id','uniacid'],true)->select(); if($data){ file_put_contents( APP_PATH . 'common/model/fill/data/'.$name.'.php', '1]; break; case "page_navigation": $where = ['default_navigation'=>1]; break; } return $where; } }