后端文件更新
This commit is contained in:
@@ -9,35 +9,35 @@
|
||||
|
||||
namespace app\model;
|
||||
|
||||
use think\Model;
|
||||
use think\facade\Cache;
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 设置模型
|
||||
*/
|
||||
class Config extends Model{
|
||||
|
||||
* 设置模型
|
||||
*/
|
||||
class Config extends Model {
|
||||
|
||||
protected $type = array(
|
||||
'id' => 'integer',
|
||||
'id' => 'integer',
|
||||
);
|
||||
|
||||
protected $auto = array('name', 'update_time', 'status'=>1);
|
||||
protected $auto = array('name', 'update_time', 'status' => 1);
|
||||
protected $insert = array('create_time');
|
||||
|
||||
protected function setNameAttr($value){
|
||||
return strtolower($value);
|
||||
}
|
||||
protected function setNameAttr($value) {
|
||||
return strtolower($value);
|
||||
}
|
||||
|
||||
protected function getTypeTextAttr($value, $data){
|
||||
$config = Cache::get('system_config');
|
||||
$type = $config['config_type_list'];
|
||||
$type_text = explode(',', $type[$data['type']]);
|
||||
return $type_text[0];
|
||||
}
|
||||
protected function getTypeTextAttr($value, $data) {
|
||||
$config = Cache::get('system_config');
|
||||
$type = $config['config_type_list'];
|
||||
$type_text = explode(',', $type[$data['type']]);
|
||||
return $type_text[0];
|
||||
}
|
||||
|
||||
public function lists(){
|
||||
$map = array('status' => 1);
|
||||
$res = $this->where($map)->field('type,name,value')->select();
|
||||
public function lists() {
|
||||
$map = array('status' => 1);
|
||||
$res = $this->where($map)->field('type,name,value')->select();
|
||||
|
||||
$config = array();
|
||||
foreach ($res->toArray() as $value) {
|
||||
@@ -46,54 +46,66 @@ class Config extends Model{
|
||||
return $config;
|
||||
}
|
||||
|
||||
public function updateConfig($data) {
|
||||
if (empty($data['config'])) {
|
||||
$this->error = "无更新";
|
||||
return false;
|
||||
}
|
||||
foreach ($data['config'] as $key => $value) {
|
||||
self::update(['value' => $value], ['name' => $key], ['value']);
|
||||
}
|
||||
Cache::set('system_config', null);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据配置类型解析配置
|
||||
* @param integer $type 配置类型
|
||||
* @param string $value 配置值
|
||||
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
|
||||
*/
|
||||
private function parse($type, $value){
|
||||
private function parse($type, $value) {
|
||||
switch ($type) {
|
||||
case 'textarea': //解析数组
|
||||
case 'textarea': //解析数组
|
||||
$array = preg_split('/[,;\r\n]+/', trim($value, ",;\r\n"));
|
||||
if(strpos($value,':')){
|
||||
$value = array();
|
||||
if (strpos($value, ':')) {
|
||||
$value = array();
|
||||
foreach ($array as $val) {
|
||||
$list = explode(':', $val);
|
||||
if(isset($list[2])){
|
||||
$value[$list[0]] = $list[1].','.$list[2];
|
||||
}else{
|
||||
$value[$list[0]] = $list[1];
|
||||
if (isset($list[2])) {
|
||||
$value[$list[0]] = $list[1] . ',' . $list[2];
|
||||
} else {
|
||||
$value[$list[0]] = $list[1];
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$value = $array;
|
||||
} else {
|
||||
$value = $array;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function getThemesList(){
|
||||
$files = array();
|
||||
$files['pc'] = $this->getList('pc');
|
||||
public function getThemesList() {
|
||||
$files = array();
|
||||
$files['pc'] = $this->getList('pc');
|
||||
$files['mobile'] = $this->getList('mobile');
|
||||
return $files;
|
||||
}
|
||||
|
||||
protected function getList($type){
|
||||
protected function getList($type) {
|
||||
$path = './template/';
|
||||
$file = opendir($path);
|
||||
$file = opendir($path);
|
||||
while (false !== ($filename = readdir($file))) {
|
||||
if (!in_array($filename, array('.', '..'))) {
|
||||
$files = $path . $filename . '/info.php';
|
||||
if (is_file($files)) {
|
||||
$info = include($files);
|
||||
$info = include $files;
|
||||
if (isset($info['type']) && $info['type'] == $type) {
|
||||
$info['id'] = $filename;
|
||||
$info['img'] = '/template/' . $filename . '/' . $info['img'];
|
||||
$list[] = $info;
|
||||
}else{
|
||||
$list[] = $info;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,8 @@ namespace app\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class Content extends Model
|
||||
{
|
||||
class Content extends Model {
|
||||
// 定义默认的表后缀(默认查询中文数据)
|
||||
protected $suffix = '';
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user