更新代码,完善功能

This commit is contained in:
2020-02-18 14:50:57 +08:00
parent 31fd944b9c
commit 8bc0f7534b
36 changed files with 283 additions and 280 deletions

View File

@@ -6,9 +6,11 @@
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\controller\admin;
use app\controller\Admin;
use app\model\Addons as AddonsM;
use app\model\Hooks;
/**
* @title 插件管理
@@ -16,34 +18,19 @@ use app\controller\Admin;
*/
class Addons extends Admin {
protected $addons;
public function _initialize() {
parent::_initialize();
//加入菜单
$this->getAddonsMenu();
$this->addons = model('Addons');
$this->hooks = db('Hooks');
}
/**
* @title 插件列表
*/
public function index($refresh = 0) {
public function index(AddonsM $addons, $refresh = 0) {
if ($refresh) {
$this->addons->refresh();
$addons->refresh();
}
$list = $this->addons->order('id desc')->paginate(25, false, array(
'query' => $this->request->param(),
));
// 记录当前列表页的cookie
Cookie('__forward__', $_SERVER['REQUEST_URI']);
$list = $addons->order('id desc')->paginate($this->request->pageConfig);
$data = array(
$this->data = array(
'list' => $list,
'page' => $list->render(),
);
$this->setMeta("插件管理");
$this->assign($data);
return $this->fetch();
}
@@ -218,22 +205,15 @@ class Addons extends Admin {
* @title 钩子列表
*/
public function hooks() {
$map = array();
$map = [];
$order = "id desc";
$list = model('Hooks')->where($map)->order($order)->paginate(10, false, array(
'query' => $this->request->param(),
));
// 记录当前列表页的cookie
Cookie('__forward__', $_SERVER['REQUEST_URI']);
$list = Hooks::where($map)->order($order)->paginate($this->request->pageConfig);
$data = array(
$this->data = array(
'list' => $list,
'page' => $list->render(),
);
$this->setMeta("钩子管理");
$this->assign($data);
return $this->fetch();
}

View File

@@ -11,7 +11,7 @@ namespace app\controller\admin;
use app\model\Category as CategoryM;
use app\model\Attribute;
use app\model\Module;
use app\model\Model;
use app\controller\Admin;
/**
@@ -28,7 +28,7 @@ class Category extends Admin {
/**
* @title 栏目列表
*/
public function index(CategoryM $category, Attribute $attr, Module $medule) {
public function index(CategoryM $category, Attribute $attr, Model $model) {
$param = $this->request->param();
$map = [];
@@ -42,8 +42,8 @@ class Category extends Admin {
$tree = new \sent\tree\Tree();
$list = $tree->toFormatTree($list->toArray());
}
// $subsql = $attr->where('name', 'category_id')->fetchSql(true)->column('model_id');
// $model_list = $medule->where('id IN ('. $subsql.')')->select();
$subsql = $attr->where('name', 'category_id')->fetchSql(true)->column('model_id');
$model_list = $model->where('id IN ('. $subsql.')')->select();
$this->data = [
'tree' => $list,

View File

@@ -8,7 +8,10 @@
// +----------------------------------------------------------------------
namespace app\controller\admin;
use app\controller\Admin;
use app\model\Channel as ChannelM;
use sent\tree\Tree;
/**
* @title 频道管理
@@ -16,35 +19,27 @@ use app\controller\Admin;
*/
class Channel extends Admin {
public function _initialize() {
parent::_initialize();
}
/**
* @title 频道列表
*/
public function index($type = 0) {
public function index(ChannelM $channel, $type = 0) {
/* 获取频道列表 */
//$map = array('status' => array('gt', -1), 'pid'=>$pid);
$map = array('status' => array('gt', -1));
if ($type) {
$map['type'] = $type;
}
$list = db('Channel')->where($map)->order('sort asc,id asc')->column('*', 'id');
$list = $channel->where($map)->order('sort asc,id asc')->column('*', 'id');
if (!empty($list)) {
$tree = new \com\Tree();
$tree = new Tree();
$list = $tree->toFormatTree($list);
}
config('_sys_get_channel_tree_', true);
$data = array(
$this->data = array(
'tree' => $list,
'type' => $type,
);
$this->assign($data);
$this->setMeta('导航管理');
return $this->fetch();
}

View File

@@ -8,6 +8,8 @@
// +----------------------------------------------------------------------
namespace app\controller\admin;
use app\model\Client as ClientM;
use app\controller\Admin;
/**
@@ -15,71 +17,65 @@ use app\controller\Admin;
*/
class Client extends Admin {
public function _initialize() {
parent::_initialize();
$this->model = model('Client');
}
/**
* @title 客户端列表
*/
public function index() {
$list = $this->model->paginate(25, false, array(
'query' => $this->request->param(),
));
$data = array(
$map = [];
$list = ClientM::where($map)->paginate($this->request->pageConfig);
$this->data = array(
'list' => $list,
'page' => $list->render(),
);
$this->assign($data);
$this->setMeta('客户端列表');
return $this->fetch();
}
/**
* @title 添加客户端
*/
public function add(\think\Request $request) {
public function add() {
if ($this->request->isPost()) {
$data = $request->param();
$result = $this->model->validate(true)->save($data);
$data = $this->request->param();
$result = ClientM::create($data);
if (false !== $result) {
return $this->success('成功添加', url('client/index'));
} else {
return $this->error($this->model->getError());
return $this->error('添加失败!');
}
} else {
$info['appid'] = rand_string(10, 1); //八位数字appid
$info['appsecret'] = rand_string(32); //32位数字加字母秘钥
$data = array(
$this->data = array(
'info' => $info,
);
$this->assign($data);
$this->setMeta('添加客户端');
return $this->fetch('add');
return $this->fetch();
}
}
/**
* @title 编辑客户端
*/
public function edit(\think\Request $request) {
public function edit() {
if ($this->request->isPost()) {
$data = $request->param();
$result = $this->model->validate(true)->save($data, array('id' => $request->param('id')));
$data = $this->request->param();
$result = ClientM::update($data, ['id' => $this->request->param('id')]);
if (false !== $result) {
return $this->success('修改添加', url('client/index'));
} else {
return $this->error($this->model->getError());
}
} else {
$info = $this->model->where('id', $request->param('id'))->find();
$data = array(
$info = $ClientM::where('id', $request->param('id'))->find();
$this->data = array(
'info' => $info,
);
$this->assign($data);
$this->setMeta('编辑客户端');
return $this->fetch('add');
return $this->fetch('admin/client/add');
}
}

View File

@@ -215,18 +215,17 @@ class Config extends Admin {
/**
* @title 主题选择
*/
public function themes() {
$list = $this->model->getThemesList();
$pc = config('pc_themes');
$mobile = config('mobile_themes');
$data = array(
public function themes(ConfigM $config) {
$list = $config->getThemesList();
$pc = config('system_config.pc_themes');
$mobile = config('system_config.mobile_themes');
$this->data = array(
'pc' => $pc,
'mobile' => $mobile,
'list' => $list,
);
$this->assign($data);
$this->setMeta('主题设置');
return $this->fetch();
}

View File

@@ -7,8 +7,9 @@
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\admin\controller;
use app\common\controller\Admin;
namespace app\controller\admin;
use app\controller\Admin;
/**
* @title 数据库管理
@@ -20,54 +21,55 @@ class Database extends Admin {
* @param String $type import-还原export-备份
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/
public function index($type = null) {
public function index() {
$type = $this->request->get('type', 'import');
switch ($type) {
/* 数据还原 */
case 'import':
//列出备份文件列表
$path = config('data_backup_path');
if (!is_dir($path)) {
mkdir($path, 0755, true);
}
$path = realpath($path);
$flag = \FilesystemIterator::KEY_AS_FILENAME;
$glob = new \FilesystemIterator($path, $flag);
$list = array();
foreach ($glob as $name => $file) {
if (preg_match('/^\d{8,8}-\d{6,6}-\d+\.sql(?:\.gz)?$/', $name)) {
$name = sscanf($name, '%4s%2s%2s-%2s%2s%2s-%d');
$date = "{$name[0]}-{$name[1]}-{$name[2]}";
$time = "{$name[3]}:{$name[4]}:{$name[5]}";
$part = $name[6];
if (isset($list["{$date} {$time}"])) {
$info = $list["{$date} {$time}"];
$info['part'] = max($info['part'], $part);
$info['size'] = $info['size'] + $file->getSize();
} else {
$info['part'] = $part;
$info['size'] = $file->getSize();
}
$extension = strtoupper(pathinfo($file->getFilename(), PATHINFO_EXTENSION));
$info['compress'] = ($extension === 'SQL') ? '-' : $extension;
$info['time'] = strtotime("{$date} {$time}");
$list["{$date} {$time}"] = $info;
/* 数据还原 */
case 'import':
//列出备份文件列表
$path = config('data_backup_path');
if (!is_dir($path)) {
mkdir($path, 0755, true);
}
}
$title = '数据还原';
break;
/* 数据备份 */
case 'export':
$Db = \think\Db::connect();
$list = $Db->query('SHOW TABLE STATUS');
$list = array_map('array_change_key_case', $list);
$title = '数据备份';
break;
default:
return $this->error('参数错误!');
$path = realpath($path);
$flag = \FilesystemIterator::KEY_AS_FILENAME;
$glob = new \FilesystemIterator($path, $flag);
$list = array();
foreach ($glob as $name => $file) {
if (preg_match('/^\d{8,8}-\d{6,6}-\d+\.sql(?:\.gz)?$/', $name)) {
$name = sscanf($name, '%4s%2s%2s-%2s%2s%2s-%d');
$date = "{$name[0]}-{$name[1]}-{$name[2]}";
$time = "{$name[3]}:{$name[4]}:{$name[5]}";
$part = $name[6];
if (isset($list["{$date} {$time}"])) {
$info = $list["{$date} {$time}"];
$info['part'] = max($info['part'], $part);
$info['size'] = $info['size'] + $file->getSize();
} else {
$info['part'] = $part;
$info['size'] = $file->getSize();
}
$extension = strtoupper(pathinfo($file->getFilename(), PATHINFO_EXTENSION));
$info['compress'] = ($extension === 'SQL') ? '-' : $extension;
$info['time'] = strtotime("{$date} {$time}");
$list["{$date} {$time}"] = $info;
}
}
$title = '数据还原';
break;
/* 数据备份 */
case 'export':
$Db = \think\Db::connect();
$list = $Db->query('SHOW TABLE STATUS');
$list = array_map('array_change_key_case', $list);
$title = '数据备份';
break;
default:
return $this->error('参数错误!');
}
//渲染模板
$this->setMeta($title);

View File

@@ -58,10 +58,9 @@ class Index extends Admin {
* @title 后台退出
* @return html
*/
public function logout() {
$user = model('Member');
$user->logout();
$this->redirect('admin/index/login');
public function logout(Member $user) {
Session::delete('userInfo');
$this->redirect('/admin/login');
}
/**
@@ -87,12 +86,10 @@ class Index extends Admin {
),
),
);
$data = array(
$this->data = array(
'keyList' => $keylist,
);
$this->assign($data);
$this->setMeta("更新缓存");
return $this->fetch('public/edit');
return $this->fetch('admin/public/edit');
}
}
}

View File

@@ -6,8 +6,9 @@
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\controller\admin;
use app\model\Link as LinkM;
use app\controller\Admin;
/**
@@ -19,20 +20,16 @@ class Link extends Admin {
/**
* @title 链接列表
*/
public function index() {
public function index(LinkM $link) {
$map = array();
$order = "id desc";
$list = db('Link')->where($map)->order($order)->paginate(10, false, array(
'query' => $this->request->param(),
));
$list = $link->where($map)->order($order)->paginate($this->request->pageConfig);
$data = array(
$this->data = array(
'list' => $list,
'page' => $list->render(),
);
$this->assign($data);
$this->setMeta("友情链接");
return $this->fetch();
}

View File

@@ -6,9 +6,10 @@
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\controller\admin;
use app\controller\Admin;
use app\model\Model as ModelM;
/**
* @title 模型管理
@@ -18,7 +19,6 @@ class Model extends Admin {
public function _initialize() {
parent::_initialize();
$this->getContentMenu();
$this->model = model('Model');
}
/**
@@ -26,23 +26,17 @@ class Model extends Admin {
* @author huajie <banhuajie@163.com>
*/
public function index() {
$map = array('status' => array('gt', -1));
$map = [];
$map[] = ['status', '>', '-1'];
$order = "id desc";
$list = $this->model->where($map)->order($order)->paginate(10, false, array(
'query' => $this->request->param(),
));
$list = ModelM::where($map)->order($order)->paginate($this->request->pageConfig);
$data = array(
$this->data = array(
'list' => $list,
'page' => $list->render(),
);
// 记录当前列表页的cookie
Cookie('__forward__', $_SERVER['REQUEST_URI']);
$this->assign($data);
$this->setMeta('模型管理');
return $this->fetch();
}