32], [['OPTIONS', 'VALUE'], 'string', 'max' => 4000], [['CONFIG_NAME'], 'unique'], ]; } /** * @inheritdoc */ public function attributeLabels() { return [ 'CONFIG_NAME' => '配置参数名', 'TITLE' => '标题', 'UNIT' => '单位', 'INPUT_TYPE' => '表单类型', 'OPTIONS' => '参数配置的选项', 'VALUE' => '配置值', 'TYPE' => '类型', 'SORT' => '排序', 'CREATED_AT' => '创建时间', 'UPDATED_AT' => '更新时间', ]; } /** * 从缓存获取配置信息 * @return array|mixed|\yii\db\ActiveRecord[] */ public static function getFromCache(){ $config = Yii::$app->cache->get(Cache::SYSTEM_CONFIG_KEY); if(!$config){ // 获取配置 $config = Config::find()->where('1=1')->indexBy('CONFIG_NAME')->asArray()->all(); Yii::$app->cache->set('sysConfig', $config); } return $config; } /** * 更新到缓存 * @return array|\yii\db\ActiveRecord[] */ public static function updateToCache(){ // 获取配置 $config = Config::find()->where('1=1')->indexBy('CONFIG_NAME')->asArray()->all(); Yii::$app->cache->set(Cache::SYSTEM_CONFIG_KEY, $config); return $config; } /** * 操作日志记录条件 * @return array */ public function attrLabelsWithLogType(){ return [ 'TITLE' => '标题', 'VALUE' => '配置值', ]; } /** * 按类型获取配置 * @param $type * @return array */ public static function getConfigByType($type) { $configs = Config::find()->where('TYPE=:TYPE', [':TYPE' => $type])->orderBy('SORT ASC')->indexBy('CONFIG_NAME')->asArray()->all(); $data = []; foreach ($configs as $value) { $data[$value['CONFIG_NAME']]['label'] = $value['TITLE']; switch ($value['INPUT_TYPE']) { case 2: $options = json_decode($value['OPTIONS'],true); $arr = explode(",", $value['VALUE']); if($type=='other'){ $colArr = array_column($options, 'value','label'); $result=array_flip($colArr); $str = ''; foreach ($arr as $v) { $str .= $result[$v] . ','; } }else { $str = ''; foreach ($arr as $v) { $str .= $options[$v - 1]['label'] . ','; } } $data[$value['CONFIG_NAME']]['value'] = $str; break; case 3: $options = json_decode($value['OPTIONS'],true); if( $value["VALUE"] ) { $arr = explode(",", $value['VALUE']); $str = ''; foreach ($arr as $v) { foreach ($options as $option) { if( $option['value'] === $v ) { $str .= $option['label'] . ','; break; } } } $data[$value['CONFIG_NAME']]['value'] = $str; }else { $data[$value['CONFIG_NAME']]['value'] = ''; } break; case 8: $data[$value['CONFIG_NAME']]['value'] = $value['VALUE'] == 1 ? '是' : '否'; break; case 10: $data[$value['CONFIG_NAME']]['value'] = $value['VALUE']; break; default: $data[$value['CONFIG_NAME']]['value'] = $value['VALUE']; } } return $data; } }