97 lines
2.7 KiB
PHP
97 lines
2.7 KiB
PHP
<?php
|
||
// +------------------------------------------------+
|
||
// |http://www.cjango.com |
|
||
// +------------------------------------------------+
|
||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||
// +------------------------------------------------+
|
||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||
// +------------------------------------------------+
|
||
namespace app\common\model;
|
||
|
||
use think\Cache;
|
||
|
||
class Config extends _Init
|
||
{
|
||
|
||
/**
|
||
* 模型初始化【事件注册】
|
||
*/
|
||
protected static function init()
|
||
{
|
||
self::afterWrite(function () {
|
||
Cache::clear();
|
||
});
|
||
}
|
||
|
||
/**
|
||
* 获取器
|
||
*/
|
||
protected function getTypeTextAttr($value, $data)
|
||
{
|
||
return Config::getValue($data['type'], 'config_type_list');
|
||
}
|
||
protected function getGroupTextAttr($value, $data)
|
||
{
|
||
return Config::getValue($data['group'], 'config_group_list');
|
||
}
|
||
|
||
/**
|
||
* 配置列表,优化输出
|
||
*/
|
||
protected function getValueTextAttr($value, $data)
|
||
{
|
||
return preg_replace('/\r\n/', "<br/>", $data['value']);
|
||
}
|
||
|
||
/**
|
||
* 格式化枚举类型的配置
|
||
*/
|
||
protected function getExtraArrayAttr($value, $data)
|
||
{
|
||
$array = preg_split('/[\r\n]+/', trim($data['extra'], "\r\n"));
|
||
$enum = [];
|
||
if (strpos($data['extra'], ':')) {
|
||
foreach ($array as $val) {
|
||
list($k, $v) = explode(':', $val, 2);
|
||
$enum[$k] = $v;
|
||
}
|
||
} else {
|
||
$enum = $array;
|
||
}
|
||
return $enum;
|
||
}
|
||
|
||
/**
|
||
* 获取配置内容
|
||
* @param string $key
|
||
* @param string $type
|
||
* @return string
|
||
*/
|
||
public static function getValue($key, $type = null)
|
||
{
|
||
if ($key == -1) {
|
||
return '<span style="color:#D2322D;">已删除</span>';
|
||
}
|
||
if (!is_null($type) && is_string($type)) {
|
||
$res = \think\Config::get($type);
|
||
$res = isset($res[$key]) ? $res[$key] : '';
|
||
} elseif (!is_null($type) && is_array($type)) {
|
||
$res = isset($type[$key]) ? $type[$key] : '';
|
||
} else {
|
||
switch ($key) {
|
||
case 0:$res = '<span style="color:#E48600;">禁用</span>';
|
||
break;
|
||
case 1:$res = '<span style="color:#229F24;">正常</span>';
|
||
break;
|
||
case 2:$res = '<span style="color:#39B3D7;">待审核</span>';
|
||
break;
|
||
case 3:$res = '<span style="color:#E48600;">被驳回</span>';
|
||
break;
|
||
default:$res = '';
|
||
break;
|
||
}
|
||
}
|
||
return $res;
|
||
}
|
||
}
|