功能更新

This commit is contained in:
2020-03-30 21:16:28 +08:00
parent b16e4ab920
commit f31f3b99fa
23 changed files with 464 additions and 230 deletions

View File

@@ -6,9 +6,10 @@
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\controller\admin;
use app\model\Attribute as AttributeModel;
/**
* @title 字段管理
* @description 字段管理
@@ -16,32 +17,32 @@ namespace app\controller\admin;
class Attribute extends Base {
//保存的Model句柄
protected $model;
protected $attr;
// protected $model;
// protected $attr;
//初始化
public function _initialize() {
parent::_initialize();
public function initialize() {
parent::initialize();
$this->getContentMenu();
$this->model = model('Attribute');
//遍历属性列表
foreach (get_attribute_type() as $key => $value) {
$this->attr[$key] = $value[0];
}
$this->validate_rule = array(
0 => '请选择',
'regex' => '正则验证',
'function' => '函数验证',
'unique' => '唯一验证',
'length' => '长度验证',
'in' => '验证在范围内',
'notin' => '验证不在范围内',
'between' => '区间验证',
'notbetween' => '不在区间验证',
);
$this->auto_type = array(0 => '请选择', 'function' => '函数', 'field' => '字段', 'string' => '字符串');
$this->the_time = array(0 => '请选择', '3' => '始 终', '1' => '新 增', '2' => '编 辑');
$this->field = $this->getField();
// $this->model = model('Attribute');
// //遍历属性列表
// foreach (get_attribute_type() as $key => $value) {
// $this->attr[$key] = $value[0];
// }
// $this->validate_rule = array(
// 0 => '请选择',
// 'regex' => '正则验证',
// 'function' => '函数验证',
// 'unique' => '唯一验证',
// 'length' => '长度验证',
// 'in' => '验证在范围内',
// 'notin' => '验证不在范围内',
// 'between' => '区间验证',
// 'notbetween' => '不在区间验证',
// );
// $this->auto_type = array(0 => '请选择', 'function' => '函数', 'field' => '字段', 'string' => '字符串');
// $this->the_time = array(0 => '请选择', '3' => '始 终', '1' => '新 增', '2' => '编 辑');
// $this->field = $this->getField();
}
/**
@@ -52,17 +53,13 @@ class Attribute extends Base {
if (!$model_id) {
return $this->error('非法操作!');
}
$list = model('Attribute')->where('model_id', $model_id)->order('id desc')->paginate(25, false, array(
'query' => $this->request->param(),
));
$list = AttributeModel::where('model_id', $model_id)->order('id desc')->paginate($this->request->pageConfig);
$data = array(
$this->data = array(
'list' => $list,
'model_id' => $model_id,
'page' => $list->render(),
);
$this->assign($data);
$this->setMeta('字段管理');
return $this->fetch();
}

View File

@@ -9,9 +9,12 @@
namespace app\controller\admin;
use app\model\Menu;
use app\model\Model;
use app\model\AuthGroup;
use think\facade\View;
use \app\model\Form;
use \app\controller\Base as BaseC;
use think\facade\Route;
class Base extends BaseC {
@@ -190,28 +193,26 @@ class Base extends BaseC {
}
protected function getContentMenu() {
$model = \think\facade\Loader::model('Model');
$list = array();
$map = array(
'status' => array('gt', 0),
);
$list = $model::where($map)->field("name,id,title,icon,'' as 'style'")->select();
$list = [];
$menu = [];
$map[] = ['status', '>', 0];
$list = Model::where($map)->field("name,id,title,icon,'' as 'style'")->select();
//判断是否有模型权限
$models = AuthGroup::getAuthModels(session('user_auth.uid'));
$models = AuthGroup::getAuthModels(session('userInfo.uid'));
foreach ($list as $key => $value) {
if (IS_ROOT || in_array($value['id'], $models)) {
if ('/admin/content/index' == $this->request->path() && input('model_id') == $value['id']) {
if ('/admin/content/index' == $this->request->url() && input('model_id') == $value['id']) {
$value['style'] = "active";
}
$value['url'] = "/admin/content/index?model_id=" . $value['id'];
$value['url'] = "/admin/".$value['name']."/index";
$value['title'] = $value['title'] . "管理";
$value['icon'] = $value['icon'] ? $value['icon'] : 'file';
$menu[] = $value;
}
}
if (!empty($menu)) {
$this->assign('extend_menu', array('内容管理' => $menu));
View::assign('extend_menu', array('内容管理' => $menu));
}
}

View File

@@ -19,8 +19,8 @@ use app\model\Model;
*/
class Category extends Base {
public function _initialize() {
parent::_initialize();
public function initialize() {
parent::initialize();
$this->getContentMenu();
}

View File

@@ -69,7 +69,7 @@ class Config extends Base {
ConfigM::update(['value' => $value], ['name' => $key]);
}
//清除db_config_data缓存
cache('system_config_data', null);
Cache::pull('system_config_data');
return $this->success("更新成功!");
} else {
$list = $config->where(array('status' => 1, 'group' => $id))->field('id,name,title,extra,value,remark,type')->order('sort')->select();
@@ -91,7 +91,7 @@ class Config extends Base {
if ($data) {
$result = ConfigM::create($data);
if (false !== $result) {
Cache::pull('db_config_data');
Cache::pull('system_config_data');
return $this->success('新增成功', url('/admin/config/index'));
} else {
return $this->error('新增失败');
@@ -115,8 +115,7 @@ class Config extends Base {
if ($data) {
$result = ConfigM::update($data, array('id' => $data['id']));
if (false !== $result) {
Cache::pull('db_config_data');
//记录行为
Cache::pull('system_config_data');
return $this->success('更新成功', Cookie('__forward__'));
} else {
return $this->error('更新失败!');
@@ -148,7 +147,7 @@ class Config extends Base {
$Config->where($map)->setField('value', $value);
}
}
cache('db_config_data', null);
Cache::pull('system_config_data');
return $this->success('保存成功!');
}
@@ -165,9 +164,7 @@ class Config extends Base {
$map = array('id' => array('in', $id));
if (db('Config')->where($map)->delete()) {
cache('DB_CONFIG_DATA', null);
//记录行为
action_log('update_config', 'config', $id, session('user_auth.uid'));
Cache::pull('system_config_data');
return $this->success('删除成功');
} else {
return $this->error('删除失败!');
@@ -213,9 +210,9 @@ class Config extends Base {
* @title 主题选择
*/
public function themes(ConfigM $config) {
$list = $config->getThemesList();
$pc = config('system_config.pc_themes');
$mobile = config('system_config.mobile_themes');
$list = $config->getThemesList($this->request);
$pc = config('config.pc_themes');
$mobile = config('config.mobile_themes');
$this->data = array(
'pc' => $pc,
@@ -231,9 +228,9 @@ class Config extends Base {
* @return json
*/
public function setthemes($name, $id) {
$result = db('Config')->where('name', $name . '_themes')->setField('value', $id);
$result = ConfigM::where('name', $name . '_themes')->setField('value', $id);
if (false !== $result) {
\think\Cache::clear();
Cache::pull('system_config_data');
return $this->success('设置成功!');
} else {
return $this->error('设置失败!');

View File

@@ -13,22 +13,10 @@ namespace app\controller\admin;
* @title 内容管理
*/
class Content extends Base {
public function _initialize() {
parent::_initialize();
public function initialize() {
parent::initialize();
$this->getContentMenu();
$this->model_id = $model_id = $this->request->param('model_id');
$list = db('Model')->column('*', 'id');
if (empty($list[$model_id])) {
return $this->error("无此模型!");
} else {
$this->modelInfo = $list[$model_id];
$this->model = M($this->modelInfo['name']);
}
$this->assign('model_id', $model_id);
$this->assign('model_list', $list);
}
/**

View File

@@ -26,7 +26,7 @@ class Database extends Base {
/* 数据还原 */
case 'import':
//列出备份文件列表
$path = \think\facade\Cache::get('system_config_data.data_backup_path');
$path = $this->app->getRuntimePath() . DIRECTORY_SEPARATOR . 'backup';
if (!is_dir($path)) {
mkdir($path, 0755, true);
}
@@ -83,7 +83,7 @@ class Database extends Base {
*/
public function optimize($tables = null) {
if ($tables) {
$Db = \think\Db::connect();
$Db = \think\facade\Db::connect();
if (is_array($tables)) {
$tables = implode('`,`', $tables);
$list = $Db->query("OPTIMIZE TABLE `{$tables}`");
@@ -112,7 +112,7 @@ class Database extends Base {
*/
public function repair($tables = null) {
if ($tables) {
$Db = \think\Db::connect();
$Db = \think\facade\Db::connect();
if (is_array($tables)) {
$tables = implode('`,`', $tables);
$list = $Db->query("REPAIR TABLE `{$tables}`");
@@ -142,7 +142,7 @@ class Database extends Base {
public function del($time = 0) {
if ($time) {
$name = date('Ymd-His', $time) . '-*.sql*';
$path = realpath(config('DATA_BACKUP_PATH')) . DIRECTORY_SEPARATOR . $name;
$path = $this->app->getRuntimePath() . DIRECTORY_SEPARATOR . 'backup' . DIRECTORY_SEPARATOR . $name;
array_map("unlink", glob($path));
if (count(glob($path))) {
return $this->error('备份文件删除失败,请检查权限!');
@@ -163,7 +163,7 @@ class Database extends Base {
public function export($tables = null, $id = null, $start = null) {
if ($this->request->isPost() && !empty($tables) && is_array($tables)) {
//初始化
$path = config('data_backup_path');
$path = $this->app->getRuntimePath() . DIRECTORY_SEPARATOR . 'backup';
if (!is_dir($path)) {
mkdir($path, 0755, true);
}
@@ -236,7 +236,7 @@ class Database extends Base {
//初始化
//获取备份文件信息
$name = date('Ymd-His', $time) . '-*.sql*';
$path = realpath(config('data_backup_path')) . DIRECTORY_SEPARATOR . $name;
$path = $this->app->getRuntimePath() . DIRECTORY_SEPARATOR . 'backup' . DIRECTORY_SEPARATOR . $name;
$files = glob($path);
$list = array();
foreach ($files as $name) {
@@ -257,7 +257,7 @@ class Database extends Base {
} elseif (is_numeric($part) && is_numeric($start)) {
$list = session('backup_list');
$db = new \com\Database($list[$part], array('path' => realpath(config('data_backup_path')) . DIRECTORY_SEPARATOR, 'compress' => $list[$part][2]));
$db = new \com\Database($list[$part], array('path' => $this->app->getRuntimePath() . DIRECTORY_SEPARATOR . 'backup' . DIRECTORY_SEPARATOR, 'compress' => $list[$part][2]));
$start = $db->import($start);

View File

@@ -15,8 +15,8 @@ use app\model\Model as ModelM;
*/
class Model extends Base {
public function _initialize() {
parent::_initialize();
public function initialize() {
parent::initialize();
$this->getContentMenu();
}

View File

@@ -40,19 +40,17 @@ class Seo extends Base {
public function add() {
if ($this->request->isPost()) {
$data = $this->request->post();
$result = $this->seo->save($data);
$result = SeoRule::create($data);
if ($result) {
return $this->success("添加成功!");
} else {
return $this->error("添加失败!");
}
} else {
$data = array(
'keyList' => $this->seo->keyList,
$this->data = array(
'keyList' => SeoRule::$keyList,
);
$this->assign($data);
$this->setMeta("添加规则");
return $this->fetch('public/edit');
return $this->fetch('admin/public/edit');
}
}
@@ -62,22 +60,24 @@ class Seo extends Base {
public function edit($id = null) {
if ($this->request->isPost()) {
$data = $this->request->post();
$result = $this->seo->save($data, array('id' => $data['id']));
$result = SeoRule::update($data, array('id' => $data['id']));
if (false !== $result) {
return $this->success("修改成功!");
} else {
return $this->error("修改失败!");
}
} else {
$id = input('id', '', 'trim,intval');
$info = $this->seo->where(array('id' => $id))->find();
$data = array(
$id = $this->request->param('id', 0);
if (!$id) {
return $this->error("非法操作!");
}
$info = SeoRule::find($id);
$this->data = array(
'info' => $info,
'keyList' => $this->seo->keyList,
'keyList' => SeoRule::$keyList,
);
$this->assign($data);
$this->setMeta("编辑规则");
return $this->fetch('public/edit');
return $this->fetch('admin/public/edit');
}
}
@@ -85,11 +85,20 @@ class Seo extends Base {
* @title 删除SEO
*/
public function del() {
$id = $this->getArrayParam('id');
$id = $this->request->param('id');
if (empty($id)) {
return $this->error("非法操作!");
}
$result = $this->seo->where(array('id' => array('IN', $id)))->delete();
if (is_array($id)) {
$map[] = ['id', 'IN', $id];
}else{
$map[] = ['id', '=', $id];
}
$result = SeoRule::where($map)->delete();
if ($result) {
return $this->success("删除成功!");
} else {
@@ -117,19 +126,19 @@ class Seo extends Base {
*/
public function addrewrite() {
if ($this->request->isPost()) {
$result = model('Rewrite')->change();
$data = $this->request->param();
$result = Rewrite::create($data);
if (false != $result) {
return $this->success("添加成功!", url('admin/seo/rewrite'));
return $this->success("添加成功!", url('/admin/seo/rewrite'));
} else {
return $this->error(model('Rewrite')->getError());
return $this->error('添加失败!');
}
} else {
$data = array(
'keyList' => $this->rewrite->keyList,
$this->data = array(
'keyList' => Rewrite::$keyList,
);
$this->assign($data);
$this->setMeta("添加路由规则");
return $this->fetch('public/edit');
return $this->fetch('admin/public/edit');
}
}
@@ -138,22 +147,22 @@ class Seo extends Base {
*/
public function editrewrite() {
if ($this->request->isPost()) {
$result = model('Rewrite')->change();
$data = $this->request->param();
$result = Rewrite::update($data, ['id' => $data['id']]);
if (false != $result) {
return $this->success("更新成功!", url('admin/seo/rewrite'));
return $this->success("更新成功!", url('/admin/seo/rewrite'));
} else {
return $this->error(model('Rewrite')->getError());
return $this->error('更新失败!');
}
} else {
$id = input('id', '', 'trim,intval');
$info = db('Rewrite')->where(array('id' => $id))->find();
$data = array(
$id = $this->request->param('id');
$info = Rewrite::find($id);
$this->data = array(
'info' => $info,
'keyList' => $this->rewrite->keyList,
'keyList' => Rewrite::$keyList,
);
$this->assign($data);
$this->setMeta("编辑路由规则");
return $this->fetch('public/edit');
return $this->fetch('admin/public/edit');
}
}
@@ -161,11 +170,20 @@ class Seo extends Base {
* @title 删除静态规则
*/
public function delrewrite() {
$id = $this->getArrayParam('id');
$id = $this->request->param('id');
if (empty($id)) {
return $this->error("非法操作!");
}
$result = db('Rewrite')->where(array('id' => array('IN', $id)))->delete();
if (is_array($id)) {
$map[] = ['id', 'IN', $id];
}else{
$map[] = ['id', '=', $id];
}
$result = Rewrite::where($map)->delete();
if ($result) {
return $this->success("删除成功!");
} else {