Initial commit
This commit is contained in:
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
namespace app\controller\admin;
|
||||
|
||||
use app\controller\Base;
|
||||
use think\facade\Request;
|
||||
use think\facade\Validate;
|
||||
use think\facade\Db;
|
||||
|
||||
class Category extends Base
|
||||
{
|
||||
|
||||
public function list()
|
||||
{
|
||||
$params = Request::param();
|
||||
|
||||
$validate = Validate::rule([
|
||||
'page' => 'integer',
|
||||
'limit' => 'integer',
|
||||
]);
|
||||
if (!$validate->check($params)) {
|
||||
return msg('error', $validate->getError());
|
||||
}
|
||||
|
||||
$page = isset($params['page']) ? intval($params['page']) : 1;
|
||||
$limit = isset($params['limit']) ? intval($params['limit']) : 50;
|
||||
|
||||
$select = Db::name('category');
|
||||
if(!empty($params['title'])){
|
||||
$select->where('title', 'like', '%' . $params['title'] . '%');
|
||||
}
|
||||
$total = $select->count();
|
||||
$items = $select->order('weight','desc')->page($page, $limit)->select();
|
||||
|
||||
return msg("ok", "success", ['total'=>$total, 'items'=>$items]);
|
||||
}
|
||||
|
||||
public function get()
|
||||
{
|
||||
$params = Request::param();
|
||||
|
||||
$validate = Validate::rule([
|
||||
'id' => 'require|integer',
|
||||
]);
|
||||
if (!$validate->check($params)) {
|
||||
return msg('error', $validate->getError());
|
||||
}
|
||||
|
||||
$item = Db::name('category')->where('id', $params['id'])->findOrEmpty();
|
||||
|
||||
return msg('ok', 'success', $item);
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
$params = Request::param();
|
||||
|
||||
$validate = Validate::rule([
|
||||
'title|分类标题' => 'require|unique:category',
|
||||
'icon|小图标' => 'require',
|
||||
'weight|权重' => 'require|integer',
|
||||
'enable' => 'integer',
|
||||
]);
|
||||
if (!$validate->check($params)) {
|
||||
return msg('error', $validate->getError());
|
||||
}
|
||||
|
||||
Db::name('category')->cache('categorys')->insert([
|
||||
'title' => trim($params['title']),
|
||||
'icon' => trim($params['icon']),
|
||||
'weight' => $params['weight'],
|
||||
'enable' => $params['enable'],
|
||||
'create_time' => date("Y-m-d H:i:s"),
|
||||
'update_time' => date("Y-m-d H:i:s")
|
||||
]);
|
||||
|
||||
return msg();
|
||||
}
|
||||
|
||||
public function edit()
|
||||
{
|
||||
$params = Request::param();
|
||||
|
||||
$validate = Validate::rule([
|
||||
'id' => 'require',
|
||||
'icon|小图标' => 'require',
|
||||
'title|分类标题' => 'require|unique:category',
|
||||
'weight|权重' => 'require|integer',
|
||||
'enable' => 'integer',
|
||||
]);
|
||||
if (!$validate->check($params)) {
|
||||
return msg('error', $validate->getError());
|
||||
}
|
||||
|
||||
Db::name('category')->cache('categorys')->where('id', $params['id'])->update([
|
||||
'title' => trim($params['title']),
|
||||
'icon' => trim($params['icon']),
|
||||
'weight' => $params['weight'],
|
||||
'enable' => $params['enable'],
|
||||
'update_time' => date("Y-m-d H:i:s")
|
||||
]);
|
||||
|
||||
return msg();
|
||||
}
|
||||
|
||||
public function enable()
|
||||
{
|
||||
$id = input('post.id/d');
|
||||
$enable = input('post.enable/d');
|
||||
|
||||
Db::name('category')->cache('categorys')->where('id', $id)->update([
|
||||
'enable' => $enable,
|
||||
'update_time' => date("Y-m-d H:i:s")
|
||||
]);
|
||||
|
||||
return msg();
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$params = Request::param();
|
||||
|
||||
$validate = Validate::rule([
|
||||
'id' => 'require|integer',
|
||||
]);
|
||||
if (!$validate->check($params)) {
|
||||
return msg('error', $validate->getError());
|
||||
}
|
||||
|
||||
Db::name('category')->cache('categorys')->where('id', $params['id'])->delete();
|
||||
|
||||
return msg();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
|
||||
namespace app\controller\admin;
|
||||
|
||||
use app\controller\Base;
|
||||
use think\facade\Request;
|
||||
use think\facade\Validate;
|
||||
use think\facade\Db;
|
||||
|
||||
class Comment extends Base
|
||||
{
|
||||
|
||||
public function list()
|
||||
{
|
||||
$params = Request::param();
|
||||
|
||||
$validate = Validate::rule([
|
||||
'page' => 'integer',
|
||||
'limit' => 'integer',
|
||||
]);
|
||||
if (!$validate->check($params)) {
|
||||
return msg('error', $validate->getError());
|
||||
}
|
||||
|
||||
$page = intval($params['page']);
|
||||
$limit = intval($params['limit']);
|
||||
|
||||
$select = Db::name('comment');
|
||||
if(!empty($params['uid'])){
|
||||
$select->where('uid', $params['uid']);
|
||||
}
|
||||
if(!empty($params['content'])){
|
||||
$select->where('content', 'like', '%' . $params['content'] . '%');
|
||||
}
|
||||
$total = $select->count();
|
||||
$items = $select->order('id','desc')->page($page, $limit)->select();
|
||||
|
||||
return msg("ok", "success", ['total'=>$total, 'items'=>$items]);
|
||||
}
|
||||
|
||||
public function get()
|
||||
{
|
||||
$params = Request::param();
|
||||
|
||||
$validate = Validate::rule([
|
||||
'id' => 'require|integer',
|
||||
]);
|
||||
if (!$validate->check($params)) {
|
||||
return msg('error', $validate->getError());
|
||||
}
|
||||
|
||||
$item = Db::name('comment')->where('id', $params['id'])->findOrEmpty();
|
||||
|
||||
return msg('ok', 'success', $item);
|
||||
}
|
||||
|
||||
public function edit()
|
||||
{
|
||||
$params = Request::param();
|
||||
|
||||
$validate = Validate::rule([
|
||||
'id' => 'require',
|
||||
'content|留言内容' => 'require',
|
||||
'enable' => 'require|integer',
|
||||
]);
|
||||
if (!$validate->check($params)) {
|
||||
return msg('error', $validate->getError());
|
||||
}
|
||||
|
||||
Db::name('comment')->where('id', $params['id'])->update([
|
||||
'content' => $params['content'],
|
||||
'reply' => $params['reply'],
|
||||
'enable' => $params['enable'],
|
||||
'update_time' => date("Y-m-d H:i:s")
|
||||
]);
|
||||
|
||||
return msg();
|
||||
}
|
||||
|
||||
public function enable()
|
||||
{
|
||||
$id = input('post.id/d');
|
||||
$enable = input('post.enable/d');
|
||||
|
||||
Db::name('comment')->where('id', $id)->update([
|
||||
'enable' => $enable,
|
||||
'update_time' => date("Y-m-d H:i:s")
|
||||
]);
|
||||
|
||||
return msg();
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$params = Request::param();
|
||||
|
||||
$validate = Validate::rule([
|
||||
'id' => 'require|integer',
|
||||
]);
|
||||
if (!$validate->check($params)) {
|
||||
return msg('error', $validate->getError());
|
||||
}
|
||||
|
||||
Db::name('comment')->where('id', $params['id'])->delete();
|
||||
|
||||
return msg();
|
||||
}
|
||||
|
||||
|
||||
public function uploadlog()
|
||||
{
|
||||
$params = Request::param();
|
||||
|
||||
$validate = Validate::rule([
|
||||
'page' => 'integer',
|
||||
'limit' => 'integer',
|
||||
]);
|
||||
if (!$validate->check($params)) {
|
||||
return msg('error', $validate->getError());
|
||||
}
|
||||
|
||||
$page = intval($params['page']);
|
||||
$limit = intval($params['limit']);
|
||||
|
||||
$select = Db::name('uploadlog');
|
||||
if(!empty($params['uid'])){
|
||||
$select->where('uid', $params['uid']);
|
||||
}
|
||||
if(!empty($params['ip'])){
|
||||
$select->where('ip', $params['ip']);
|
||||
}
|
||||
if(!empty($params['fileurl'])){
|
||||
$select->where('fileurl', $params['fileurl']);
|
||||
}
|
||||
$total = $select->count();
|
||||
$items = $select->order('id','desc')->page($page, $limit)->select();
|
||||
|
||||
return msg("ok", "success", ['total'=>$total, 'items'=>$items]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
namespace app\controller\admin;
|
||||
|
||||
use app\controller\Base;
|
||||
use think\facade\Request;
|
||||
use think\facade\Validate;
|
||||
use think\facade\Db;
|
||||
|
||||
class Link extends Base
|
||||
{
|
||||
|
||||
public function list()
|
||||
{
|
||||
$params = Request::param();
|
||||
|
||||
$validate = Validate::rule([
|
||||
'page' => 'integer',
|
||||
'limit' => 'integer',
|
||||
]);
|
||||
if (!$validate->check($params)) {
|
||||
return msg('error', $validate->getError());
|
||||
}
|
||||
|
||||
$page = intval($params['page']);
|
||||
$limit = intval($params['limit']);
|
||||
|
||||
$select = Db::name('link');
|
||||
if(!empty($params['keyword'])){
|
||||
$select->where('name|url', 'like', '%' . $params['keyword'] . '%');
|
||||
}
|
||||
$total = $select->count();
|
||||
$items = $select->order('weight','desc')->page($page, $limit)->select();
|
||||
|
||||
return msg("ok", "success", ['total'=>$total, 'items'=>$items]);
|
||||
}
|
||||
|
||||
public function get()
|
||||
{
|
||||
$params = Request::param();
|
||||
|
||||
$validate = Validate::rule([
|
||||
'id' => 'require|integer',
|
||||
]);
|
||||
if (!$validate->check($params)) {
|
||||
return msg('error', $validate->getError());
|
||||
}
|
||||
|
||||
$item = Db::name('link')->where('id', $params['id'])->findOrEmpty();
|
||||
|
||||
return msg('ok', 'success', $item);
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
$params = Request::param();
|
||||
|
||||
$validate = Validate::rule([
|
||||
'name|名称' => 'require|chsAlphaNum|unique:link',
|
||||
'url|地址' => 'require',
|
||||
'weight|权重' => 'require|integer',
|
||||
'enable' => 'integer',
|
||||
]);
|
||||
if (!$validate->check($params)) {
|
||||
return msg('error', $validate->getError());
|
||||
}
|
||||
|
||||
Db::name('link')->cache('links')->insert([
|
||||
'name' => trim($params['name']),
|
||||
'url' => trim($params['url']),
|
||||
'weight' => $params['weight'],
|
||||
'enable' => $params['enable'],
|
||||
'create_time' => date("Y-m-d H:i:s"),
|
||||
'update_time' => date("Y-m-d H:i:s")
|
||||
]);
|
||||
|
||||
return msg();
|
||||
}
|
||||
|
||||
public function edit()
|
||||
{
|
||||
$params = Request::param();
|
||||
|
||||
$validate = Validate::rule([
|
||||
'id' => 'require',
|
||||
'name|名称' => 'require|chsAlphaNum|unique:link',
|
||||
'url|地址' => 'require',
|
||||
'weight|权重' => 'require|integer',
|
||||
'enable' => 'integer',
|
||||
]);
|
||||
if (!$validate->check($params)) {
|
||||
return msg('error', $validate->getError());
|
||||
}
|
||||
|
||||
Db::name('link')->cache('links')->where('id', $params['id'])->update([
|
||||
'name' => trim($params['name']),
|
||||
'url' => trim($params['url']),
|
||||
'weight' => $params['weight'],
|
||||
'enable' => $params['enable'],
|
||||
'update_time' => date("Y-m-d H:i:s")
|
||||
]);
|
||||
|
||||
return msg();
|
||||
}
|
||||
|
||||
public function enable()
|
||||
{
|
||||
$id = input('post.id/d');
|
||||
$enable = input('post.enable/d');
|
||||
|
||||
Db::name('link')->cache('links')->where('id', $id)->update([
|
||||
'enable' => $enable,
|
||||
'update_time' => date("Y-m-d H:i:s")
|
||||
]);
|
||||
|
||||
return msg();
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$params = Request::param();
|
||||
|
||||
$validate = Validate::rule([
|
||||
'id' => 'require|integer',
|
||||
]);
|
||||
if (!$validate->check($params)) {
|
||||
return msg('error', $validate->getError());
|
||||
}
|
||||
|
||||
Db::name('link')->cache('links')->where('id', $params['id'])->delete();
|
||||
|
||||
return msg();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
namespace app\controller\admin;
|
||||
|
||||
|
||||
use app\BaseController;
|
||||
|
||||
class Menu extends BaseController
|
||||
{
|
||||
public function get(){
|
||||
|
||||
$homeInfo = [
|
||||
'title' => '主页',
|
||||
'href' => 'page/dashboard.html',
|
||||
];
|
||||
$logoInfo = [
|
||||
'title' => '工具网后台',
|
||||
'image' => 'images/logo.png',
|
||||
'href' => './',
|
||||
];
|
||||
$menuInfo = [
|
||||
[
|
||||
"title" => "常规管理",
|
||||
"icon" => "fa fa-address-book",
|
||||
"href" => "",
|
||||
"target" => "_self",
|
||||
"child" => [
|
||||
[
|
||||
"title" => "主页",
|
||||
"icon" => "fa fa-home",
|
||||
"target" => "_self",
|
||||
"href" => "page/dashboard.html",
|
||||
],
|
||||
[
|
||||
"title" => "分类管理",
|
||||
"href" => "page/category.html",
|
||||
"icon" => "fa fa-bookmark-o",
|
||||
"target" => "_self",
|
||||
],
|
||||
[
|
||||
"title" => "插件管理",
|
||||
"href" => "",
|
||||
"icon" => "fa fa-puzzle-piece",
|
||||
"target" => "_self",
|
||||
"child" => [
|
||||
[
|
||||
"title" => "插件列表",
|
||||
"href" => "page/plugin.html",
|
||||
"icon" => "fa fa-list",
|
||||
"target" => "_self"
|
||||
],
|
||||
[
|
||||
"title" => "安装新插件",
|
||||
"href" => "page/plugin/install.html",
|
||||
"icon" => "fa fa-cloud-upload",
|
||||
"target" => "_self"
|
||||
],
|
||||
]
|
||||
],
|
||||
[
|
||||
"title" => "用户管理",
|
||||
"href" => "page/user.html",
|
||||
"icon" => "fa fa-user",
|
||||
"target" => "_self",
|
||||
],
|
||||
[
|
||||
"title" => "留言管理",
|
||||
"href" => "page/comment.html",
|
||||
"icon" => "fa fa-comments",
|
||||
"target" => "_self",
|
||||
],
|
||||
[
|
||||
"title" => "上传记录",
|
||||
"href" => "page/uploadlog.html",
|
||||
"icon" => "fa fa-cloud-upload",
|
||||
"target" => "_self",
|
||||
],
|
||||
[
|
||||
"title" => "友链管理",
|
||||
"href" => "page/link.html",
|
||||
"icon" => "fa fa-link",
|
||||
"target" => "_self",
|
||||
],
|
||||
[
|
||||
"title" => "系统配置",
|
||||
"href" => "",
|
||||
"icon" => "fa fa-cogs",
|
||||
"target" => "_self",
|
||||
"child" => [
|
||||
[
|
||||
"title" => "基本信息配置",
|
||||
"href" => "page/system.html",
|
||||
"icon" => "fa fa-cog",
|
||||
"target" => "_self"
|
||||
],
|
||||
[
|
||||
"title" => "管理员配置",
|
||||
"href" => "page/account.html",
|
||||
"icon" => "fa fa-user",
|
||||
"target" => "_self"
|
||||
],
|
||||
]
|
||||
],
|
||||
/*[
|
||||
"title" => "在线升级",
|
||||
"href" => "page/update.html",
|
||||
"icon" => "fa fa-cloud-upload",
|
||||
"target" => "_self",
|
||||
],*/
|
||||
],
|
||||
]
|
||||
];
|
||||
$systemInit = [
|
||||
'homeInfo' => $homeInfo,
|
||||
'logoInfo' => $logoInfo,
|
||||
'menuInfo' => $menuInfo,
|
||||
];
|
||||
return json($systemInit);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,224 @@
|
||||
<?php
|
||||
|
||||
namespace app\controller\admin;
|
||||
|
||||
|
||||
use app\BaseController;
|
||||
use think\facade\Db;
|
||||
use think\facade\Request;
|
||||
use think\facade\Session;
|
||||
use think\facade\Validate;
|
||||
|
||||
class Plugin extends BaseController
|
||||
{
|
||||
public function list()
|
||||
{
|
||||
$params = Request::param();
|
||||
|
||||
$validate = Validate::rule([
|
||||
'page' => 'integer',
|
||||
'limit' => 'integer',
|
||||
'category_id' => 'integer',
|
||||
'class' => 'is_legal_plugin_class',
|
||||
]);
|
||||
if (!$validate->check($params)) {
|
||||
return msg('error', $validate->getError());
|
||||
}
|
||||
|
||||
$page = isset($params['page']) ? intval($params['page']) : 1;
|
||||
$limit = isset($params['limit']) ? intval($params['limit']) : 50;
|
||||
$orderby = ['id' => 'desc'];
|
||||
|
||||
$select = Db::name('plugin');
|
||||
if(!empty($params['title'])){
|
||||
$select->where('title', 'like', '%' . $params['title'] . '%');
|
||||
}
|
||||
if(!empty($params['alias'])){
|
||||
$select->where('alias', $params['alias']);
|
||||
}
|
||||
if(!empty($params['class'])){
|
||||
$select->where('class', $params['class']);
|
||||
}
|
||||
if(!empty($params['enable'])){
|
||||
$select->where('enable', '1');
|
||||
}
|
||||
if(!empty($params['category_id'])){
|
||||
$select->where('category_id', $params['category_id']);
|
||||
$orderby = ['weight' => 'desc', 'id' => 'desc'];
|
||||
}
|
||||
$total = $select->count();
|
||||
$items = $select->order($orderby)->page($page, $limit)->select();
|
||||
|
||||
return msg("ok", "success", ['total'=>$total, 'items'=>$items]);
|
||||
}
|
||||
|
||||
public function get()
|
||||
{
|
||||
$params = Request::param();
|
||||
|
||||
$validate = Validate::rule([
|
||||
'id' => 'require|integer',
|
||||
]);
|
||||
if (!$validate->check($params)) {
|
||||
return msg('error', $validate->getError());
|
||||
}
|
||||
|
||||
$item = Db::name('plugin')->where('id', $params['id'])->findOrEmpty();
|
||||
|
||||
return msg('ok', 'success', $item);
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
$params = Request::param();
|
||||
|
||||
$validate = Validate::rule([
|
||||
'title|插件标题' => 'require|unique:plugin',
|
||||
'alias|路由别名' => 'require|unique:plugin',
|
||||
'class|插件类名' => 'require|unique:plugin|is_legal_plugin_class',
|
||||
'category_id|分类' => 'require|integer',
|
||||
'level|用户等级限制' => 'integer',
|
||||
'enable' => 'integer',
|
||||
'weight|权重' => 'integer',
|
||||
]);
|
||||
if (!$validate->check($params)) {
|
||||
return msg('error', $validate->getError());
|
||||
}
|
||||
|
||||
Db::name('plugin')->cache('plugins')->insert([
|
||||
'title' => trim($params['title']),
|
||||
'alias' => trim($params['alias']),
|
||||
'class' => trim($params['class']),
|
||||
'keyword' => trim($params['keyword']),
|
||||
'weight' => $params['weight'],
|
||||
'enable' => $params['enable'],
|
||||
'category_id' => $params['category_id'],
|
||||
'level' => $params['level'],
|
||||
'login' => $params['login'],
|
||||
'desc' => $params['desc'],
|
||||
'create_time' => date("Y-m-d H:i:s"),
|
||||
'update_time' => date("Y-m-d H:i:s")
|
||||
]);
|
||||
|
||||
return msg();
|
||||
}
|
||||
|
||||
public function edit()
|
||||
{
|
||||
$params = Request::param();
|
||||
|
||||
$validate = Validate::rule([
|
||||
'id' => 'require',
|
||||
'title|插件标题' => 'require|unique:plugin',
|
||||
'alias|路由别名' => 'unique:plugin',
|
||||
'class|插件类名' => 'unique:plugin|is_legal_plugin_class',
|
||||
'category_id|分类' => 'integer',
|
||||
'level|用户等级限制' => 'integer',
|
||||
'enable' => 'integer',
|
||||
'weight|权重' => 'integer',
|
||||
]);
|
||||
if (!$validate->check($params)) {
|
||||
return msg('error', $validate->getError());
|
||||
}
|
||||
|
||||
if(isset($params['level']) && isset($params['enable'])){
|
||||
Db::name('plugin')->cache('plugins')->where('id', $params['id'])->update([
|
||||
'title' => trim($params['title']),
|
||||
'alias' => trim($params['alias']),
|
||||
'class' => trim($params['class']),
|
||||
'keyword' => trim($params['keyword']),
|
||||
'weight' => $params['weight'],
|
||||
'enable' => $params['enable'],
|
||||
'category_id' => $params['category_id'],
|
||||
'level' => $params['level'],
|
||||
'login' => $params['login'],
|
||||
'desc' => $params['desc'],
|
||||
'update_time' => date("Y-m-d H:i:s")
|
||||
]);
|
||||
}else{
|
||||
Db::name('plugin')->cache('plugins')->where('id', $params['id'])->update([
|
||||
'title' => trim($params['title']),
|
||||
'alias' => trim($params['alias']),
|
||||
'class' => trim($params['class']),
|
||||
'category_id' => $params['category_id'],
|
||||
'desc' => $params['desc'],
|
||||
'update_time' => date("Y-m-d H:i:s")
|
||||
]);
|
||||
}
|
||||
|
||||
return msg();
|
||||
}
|
||||
|
||||
public function enable(){
|
||||
$params = Request::param();
|
||||
|
||||
$validate = Validate::rule([
|
||||
'id' => 'require',
|
||||
'category_id|分类' => 'integer',
|
||||
'enable' => 'integer'
|
||||
]);
|
||||
if (!$validate->check($params)) {
|
||||
return msg('error', $validate->getError());
|
||||
}
|
||||
|
||||
Db::name('plugin')->cache('plugins')->where('id', $params['id'])->update($params);
|
||||
return msg();
|
||||
}
|
||||
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$params = Request::param();
|
||||
|
||||
$validate = Validate::rule([
|
||||
'id' => 'require|integer',
|
||||
]);
|
||||
if (!$validate->check($params)) {
|
||||
return msg('error', $validate->getError());
|
||||
}
|
||||
|
||||
$plugin = Db::name('plugin')->where('id', $params['id'])->find();
|
||||
if(!$plugin) return msg('ok', 'success');
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
$classPath = plugin_path_get() . '/'.$plugin['class'].'/Install.php';
|
||||
if (file_exists($classPath)) {
|
||||
require $classPath;
|
||||
$class = 'plugin\\'.$plugin['class'].'\\Install';
|
||||
if (class_exists($class)) {
|
||||
$uninstall = new $class();
|
||||
$uninstall->UnInstall();
|
||||
}
|
||||
}
|
||||
Db::name('plugin')->cache('plugins')->where('id', $params['id'])->delete();
|
||||
if (!empty($plugin['class'])) {
|
||||
del_tree(plugin_path_get($plugin['class']));
|
||||
}
|
||||
// 提交事务
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return msg('error', $e->getMessage(), $e);
|
||||
}
|
||||
return msg('ok', 'success');
|
||||
}
|
||||
|
||||
public function upload()
|
||||
{
|
||||
$params = Request::file();
|
||||
|
||||
$validate = Validate::rule([
|
||||
'file' => 'require|file',
|
||||
]);
|
||||
if (!$validate->check($params)) {
|
||||
return msg('error', $validate->getError());
|
||||
}
|
||||
$uploadedFile = Request::file('file');
|
||||
$plugin = new \app\lib\Plugin();
|
||||
$zipFilepath = $plugin->getZipFilepath();
|
||||
$uploadedFile->move(dirname($zipFilepath), basename($zipFilepath));
|
||||
return $plugin->install();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
namespace app\controller\admin;
|
||||
|
||||
|
||||
use app\BaseController;
|
||||
use think\facade\Db;
|
||||
use think\facade\Request;
|
||||
use think\facade\Validate;
|
||||
use think\facade\Cache;
|
||||
|
||||
class System extends BaseController
|
||||
{
|
||||
public function analysis(){
|
||||
$data['count1'] = Db::name('plugin')->count();
|
||||
$data['count2'] = Db::name('comment')->count();
|
||||
$data['count3'] = Db::name('user')->count();
|
||||
$data['count4'] = Db::name('user')->whereDay('create_time', date("Y-m-d"))->count();
|
||||
return msg('ok', 'success', $data);
|
||||
}
|
||||
|
||||
public function info()
|
||||
{
|
||||
|
||||
$tmp = 'version()';
|
||||
$mysqlVersion = Db::query("select version()")[0][$tmp];
|
||||
$data = [
|
||||
'framework_version' => app()::VERSION,
|
||||
'php_version' => PHP_VERSION,
|
||||
'mysql_version' => $mysqlVersion,
|
||||
'software' => $_SERVER['SERVER_SOFTWARE'],
|
||||
'os' => php_uname(),
|
||||
'date' => date("Y-m-d H:i:s"),
|
||||
'checkupdate' => '//auth.cccyun.cc/app/tool.php?version='.config('app.version').'&ver='.config('app.ver')
|
||||
];
|
||||
return msg('ok', 'success', $data);
|
||||
|
||||
}
|
||||
|
||||
public function all()
|
||||
{
|
||||
$all = Db::name('config')->select();
|
||||
return msg('ok', 'success', $all);
|
||||
}
|
||||
|
||||
public function get()
|
||||
{
|
||||
$key = Request::param('key');
|
||||
$value = config_get($key);
|
||||
return msg('ok', 'success', $value);
|
||||
}
|
||||
|
||||
public function set()
|
||||
{
|
||||
$params = Request::param();
|
||||
|
||||
foreach ($params as $v) {
|
||||
if (empty($v['key'])) {
|
||||
continue;
|
||||
}
|
||||
config_set($v['key'], $v['value']);
|
||||
}
|
||||
cache('configs', NULL);
|
||||
$all = Db::name('config')->select();
|
||||
return msg('ok', 'success', $all);
|
||||
}
|
||||
|
||||
public function setpwd()
|
||||
{
|
||||
$params = Request::param();
|
||||
if(isset($params['username']))$params['username']=trim($params['username']);
|
||||
if(isset($params['oldpwd']))$params['oldpwd']=trim($params['oldpwd']);
|
||||
if(isset($params['newpwd']))$params['newpwd']=trim($params['newpwd']);
|
||||
if(isset($params['newpwd2']))$params['newpwd2']=trim($params['newpwd2']);
|
||||
|
||||
$validate = Validate::rule([
|
||||
'username|用户名' => 'require|chsAlphaNum',
|
||||
]);
|
||||
if (!$validate->check($params)) {
|
||||
return msg('error', $validate->getError());
|
||||
}
|
||||
|
||||
config_set('admin_username', $params['username']);
|
||||
|
||||
if(!empty($params['oldpwd']) && !empty($params['newpwd']) && !empty($params['newpwd2'])){
|
||||
$oldpwd = config_get('admin_password');
|
||||
if($oldpwd && !password_verify($params['oldpwd'], $oldpwd)){
|
||||
return msg('error', '旧密码不正确');
|
||||
}
|
||||
if($params['newpwd'] != $params['newpwd2']){
|
||||
return msg('error', '两次新密码输入不一致');
|
||||
}
|
||||
config_set('admin_password', password_hash($params['newpwd'], PASSWORD_DEFAULT));
|
||||
}
|
||||
cache('configs', NULL);
|
||||
cookie('admin_token', null);
|
||||
return msg();
|
||||
}
|
||||
|
||||
public function templates()
|
||||
{
|
||||
$glob = glob(app()->getRootPath() . config("view.view_dir_name") . '/index/*');
|
||||
$arr = [];
|
||||
foreach ($glob as $v) {
|
||||
if (is_dir($v)) {
|
||||
array_push($arr, basename($v));
|
||||
}
|
||||
}
|
||||
return msg('ok', 'success', $arr);
|
||||
|
||||
}
|
||||
|
||||
public function clear(){
|
||||
Cache::clear();
|
||||
reset_opcache();
|
||||
return msg();
|
||||
}
|
||||
|
||||
public function iptype(){
|
||||
$result = [
|
||||
['name'=>'0_X_FORWARDED_FOR', 'ip'=>real_ip(0), 'city'=>get_ip_city(real_ip(0))],
|
||||
['name'=>'1_X_REAL_IP', 'ip'=>real_ip(1), 'city'=>get_ip_city(real_ip(1))],
|
||||
['name'=>'2_REMOTE_ADDR', 'ip'=>real_ip(2), 'city'=>get_ip_city(real_ip(2))]
|
||||
];
|
||||
return msg('ok', 'success', $result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\controller\admin;
|
||||
|
||||
|
||||
use app\controller\Base;
|
||||
use app\lib\ExecSQL;
|
||||
use think\facade\Request;
|
||||
|
||||
class Update extends Base
|
||||
{
|
||||
private $RELEASE_API = '';
|
||||
|
||||
public function initialize()
|
||||
{
|
||||
reset_opcache();
|
||||
$this->RELEASE_API = base64_decode('aHR0cHM6Ly90b29sLWNsb3VkLmFvYW9zdGFyLmNvbS9vcGVuL3JlbGVhc2U=');
|
||||
}
|
||||
|
||||
private function get_last_release()
|
||||
{
|
||||
|
||||
$res = get_curl($this->RELEASE_API, 0, Request::domain());
|
||||
$json = json_decode($res);
|
||||
|
||||
if (empty($json) || empty($json->data)) {
|
||||
if (!empty($json->message)) {
|
||||
throw new \Exception($json->message);
|
||||
}
|
||||
throw new \Exception('"连接云中心失败,请检查网络连通性是否正常"');
|
||||
}
|
||||
return $json;
|
||||
}
|
||||
|
||||
public function check()
|
||||
{
|
||||
try {
|
||||
$release = $this->get_last_release();
|
||||
$release->data->current_version = get_version();
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return msg('error', $e->getMessage());
|
||||
|
||||
}
|
||||
return msg('ok', 'success', $release->data);
|
||||
}
|
||||
|
||||
public function update()
|
||||
{
|
||||
try {
|
||||
$release = $this->get_last_release();
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return msg('error', $e->getMessage());
|
||||
|
||||
}
|
||||
$get = get_curl($release->data->download_url);
|
||||
if (empty($get) || str_starts_with($get, 'CURL Error:')) {
|
||||
return msg('error', '下载更新包失败,请检查网络连通性是否正常');
|
||||
}
|
||||
$tmpFilename = app()->getRuntimePath() . '/tmp/' . uniqid() . '.zip';
|
||||
if (!file_exists(dirname($tmpFilename))) {
|
||||
mkdir(dirname($tmpFilename), 0777, true);
|
||||
}
|
||||
if (!file_put_contents($tmpFilename, $get)) {
|
||||
return msg('error', '保存文件失败,请检查是否有写入权限');
|
||||
}
|
||||
$rootPath = app()->getRootPath();
|
||||
if (!unzip($tmpFilename, $rootPath)) {
|
||||
return msg('error', '解压压缩包失败');
|
||||
}
|
||||
return msg('ok', '资源包解压成功', $release->data);
|
||||
}
|
||||
|
||||
public function updateDatabase()
|
||||
{
|
||||
$glob = glob(app()->getRuntimePath() . '/update/sql/*.sql');
|
||||
if (empty($glob)) {
|
||||
return msg('ok', '未发现数据库更新文件');
|
||||
}
|
||||
foreach ($glob as $value) {
|
||||
$result[$value] = [];
|
||||
$basename = basename($value);
|
||||
$lines = file($value);
|
||||
$execSQL = new ExecSQL();
|
||||
$lines = $execSQL->purify($lines);
|
||||
$number = $execSQL->exec($lines);
|
||||
$result[$value] = array_merge($result[$value], $execSQL->getErrors());
|
||||
|
||||
if ($number > 0) {
|
||||
$result[$value][] = "影响的记录数 $number";
|
||||
}
|
||||
$result[$value][] = '创建数据库升级记录成功';
|
||||
end:
|
||||
unlink($value);
|
||||
$result[$value] = "[$basename]:" . implode("\n", $result[$value]);
|
||||
}
|
||||
return msg('ok', "数据库执行结果:\n" . implode("\n", $result));
|
||||
}
|
||||
|
||||
public function updateScript()
|
||||
{
|
||||
$glob = glob(app()->getRuntimePath() . '/update/script/*.php');
|
||||
if (empty($glob)) {
|
||||
return msg('ok', '未发现更新脚本');
|
||||
}
|
||||
foreach ($glob as $value) {
|
||||
$result[$value] = [];
|
||||
$basename = basename($value);
|
||||
try {
|
||||
require $value;
|
||||
$class = 'UpdateScript';
|
||||
if (!class_exists($class)) {
|
||||
throw new \Exception("更新脚本不存在[$class]类");
|
||||
}
|
||||
$instance = new $class();
|
||||
$boot = 'main';
|
||||
if (!method_exists($instance, $boot)) {
|
||||
throw new \Exception("更新脚本不存在[$boot]方法");
|
||||
}
|
||||
$instance->main();
|
||||
$result[$value] = array_merge($result[$value], $instance->getResult());
|
||||
} catch (\Exception $e) {
|
||||
$result[$value][] = $e->getMessage();
|
||||
}
|
||||
$result[$value][] = '创建更新脚本升级记录成功';
|
||||
end:
|
||||
unlink($value);
|
||||
$result[$value] = "[$basename]:" . implode("\n", $result[$value]);
|
||||
}
|
||||
return msg('ok', "更新脚本执行结果:\n" . implode("\n", $result));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
namespace app\controller\admin;
|
||||
|
||||
use app\controller\Base;
|
||||
use think\facade\Request;
|
||||
use think\facade\Validate;
|
||||
use think\facade\Db;
|
||||
|
||||
class User extends Base
|
||||
{
|
||||
|
||||
public function list()
|
||||
{
|
||||
$params = Request::param();
|
||||
|
||||
$validate = Validate::rule([
|
||||
'page' => 'integer',
|
||||
'limit' => 'integer',
|
||||
]);
|
||||
if (!$validate->check($params)) {
|
||||
return msg('error', $validate->getError());
|
||||
}
|
||||
|
||||
$page = intval($params['page']);
|
||||
$limit = intval($params['limit']);
|
||||
|
||||
$select = Db::name('user');
|
||||
if(!empty($params['id'])){
|
||||
$select->where('id|openid', $params['id']);
|
||||
}
|
||||
if(!empty($params['username'])){
|
||||
$select->where('username', 'like', '%' . $params['username'] . '%');
|
||||
}
|
||||
$total = $select->count();
|
||||
$items = $select->order('id','desc')->page($page, $limit)->select();
|
||||
|
||||
return msg("ok", "success", ['total'=>$total, 'items'=>$items]);
|
||||
}
|
||||
|
||||
public function get()
|
||||
{
|
||||
$params = Request::param();
|
||||
|
||||
$validate = Validate::rule([
|
||||
'id' => 'require|integer',
|
||||
]);
|
||||
if (!$validate->check($params)) {
|
||||
return msg('error', $validate->getError());
|
||||
}
|
||||
|
||||
$item = Db::name('user')->where('id', $params['id'])->findOrEmpty();
|
||||
|
||||
return msg('ok', 'success', $item);
|
||||
}
|
||||
|
||||
public function enable(){
|
||||
$params = Request::param();
|
||||
|
||||
$validate = Validate::rule([
|
||||
'id' => 'require',
|
||||
'enable' => 'integer'
|
||||
]);
|
||||
if (!$validate->check($params)) {
|
||||
return msg('error', $validate->getError());
|
||||
}
|
||||
|
||||
Db::name('user')->where('id', $params['id'])->update($params);
|
||||
return msg();
|
||||
}
|
||||
|
||||
public function edit()
|
||||
{
|
||||
$params = Request::param();
|
||||
|
||||
$validate = Validate::rule([
|
||||
'id' => 'require',
|
||||
'level' => 'integer',
|
||||
]);
|
||||
if (!$validate->check($params)) {
|
||||
return msg('error', $validate->getError());
|
||||
}
|
||||
|
||||
Db::name('user')->where('id', $params['id'])->update([
|
||||
'level' => $params['level']
|
||||
]);
|
||||
|
||||
return msg();
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$params = Request::param();
|
||||
|
||||
$validate = Validate::rule([
|
||||
'id' => 'require|integer',
|
||||
]);
|
||||
if (!$validate->check($params)) {
|
||||
return msg('error', $validate->getError());
|
||||
}
|
||||
|
||||
Db::name('user')->where('id', $params['id'])->delete();
|
||||
|
||||
return msg('ok', 'success');
|
||||
}
|
||||
|
||||
public function slogin(){
|
||||
$id = input('get.id/d');
|
||||
$item = Db::name('user')->where('id', $id)->find();
|
||||
if(!$item){
|
||||
return $this->alert('error', '用户不存在');
|
||||
}
|
||||
|
||||
$session = md5($id.$item['password']);
|
||||
$expiretime = time()+30744000;
|
||||
$token = authcode("{$id}\t{$session}\t{$expiretime}", 'ENCODE', config_get('syskey'));
|
||||
cookie('user_token', $token, ['expire' => $expiretime, 'httponly' => true]);
|
||||
|
||||
return redirect("/");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user