完善项目描述

This commit is contained in:
hdm 2021-07-26 17:41:59 +08:00
parent dcd1734132
commit 2731fee4df
62 changed files with 1120 additions and 685 deletions

View File

@ -30,3 +30,8 @@ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. POSSIBILITY OF SUCH DAMAGE.
勾股CMS遵循Apache2开源协议发布并提供免费使用。
版权所有Copyright © 2021 by gouguCMS (https://www.gougucms.com)
All rights reserved。

View File

@ -1,17 +1,23 @@
# 勾股CMS # 勾股CMS
## 链接 [![勾股CMS](https://img.shields.io/badge/license-Apache%202-blue.svg)](https://gitee.com/gougucms/gougucms/)
[![勾股CMS](https://img.shields.io/badge/GouguCMS-1.0.0-brightgreen.svg)](https://gitee.com/gougucms/gougucms/)
[![star](https://gitee.com/gougucms/gougucms/badge/star.svg?theme=dark)](https://gitee.com/gougucms/gougucms/stargazers)
[![fork](https://gitee.com/gougucms/gougucms/badge/fork.svg?theme=dark)](https://gitee.com/gougucms/gougucms/members)
### 链接
- 勾股CMShttps://www.gougucms.com - 勾股CMShttps://www.gougucms.com
- giteehttps://gitee.com/gougucms/gougucms.git - giteehttps://gitee.com/gougucms/gougucms.git
## 相关链接 ### 相关链接
- [开源项目系列之勾股CMS](https://www.gougucms.com) - [开源项目系列之勾股CMS](https://www.gougucms.com)
- [开源项目系列之勾股博客](https://blog.gougucms.com) - [开源项目系列之勾股博客](https://blog.gougucms.com)
### 介绍 ### 介绍
1. 勾股CMS是一套基于ThinkPHP6 + Layui + MySql打造的轻量级、高性能极速后台开发框架。 - 勾股CMS是一套基于ThinkPHP6 + Layui + MySql打造的轻量级、高性能极速后台开发框架。
2. 系统后台各管理模块,一目了然,操作简单;通用型的后台权限管理框架,前后台用户的操作记录覆盖跟踪,紧随潮流、极低门槛、开箱即用。 - 系统后台各管理模块,一目了然,操作简单;通用型的后台权限管理框架,前后台用户的操作记录覆盖跟踪,紧随潮流、极低门槛、开箱即用。
3. 系统易于功能扩展,代码维护,方便二次开发,帮助开发者简单高效降低二次开发的成本,满足专注业务深度开发的需求。 - 系统易于功能扩展,代码维护,方便二次开发,帮助开发者简单高效降低二次开发的成本,满足专注业务深度开发的需求。
- 可去前台版权,真正意义的永久免费,可商用的后台系统。
### 目录结构 ### 目录结构
@ -77,14 +83,16 @@ www 系统部署目录(或者子目录)
### 安装教程 ### 安装教程
1. 勾股CMS推荐你使用阿里云和腾讯云服务器 一、勾股CMS推荐你使用阿里云和腾讯云服务器
阿里云服务器官方长期折扣优惠地址: (https://www.aliyun.com/activity/daily/bestoffer?userCode=dmrcx154) 阿里云服务器官方长期折扣优惠地址: (https://www.aliyun.com/activity/daily/bestoffer?userCode=dmrcx154)
腾讯云服务器官方长期折扣优惠地址: (https://curl.qcloud.com/PPEgI0oV) 腾讯云服务器官方长期折扣优惠地址: (https://curl.qcloud.com/PPEgI0oV)
2. 服务器运行环境要求
二、服务器运行环境要求。
~~~
PHP >= 7.1 PHP >= 7.1
Mysql >= 5.5.0 (需支持innodb引擎) Mysql >= 5.5.0 (需支持innodb引擎)
Apache 或 Nginx Apache 或 Nginx
@ -92,41 +100,56 @@ www 系统部署目录(或者子目录)
MBstring PHP Extension MBstring PHP Extension
CURL PHP Extension CURL PHP Extension
Composer (用于管理第三方扩展包) Composer (用于管理第三方扩展包)
~~~
3. 完整包安装 三、系统安装
前往官网下载页面 (https://www.gougucms.com/) 下载完整包解压到你的项目目录 **方式一:完整包安装**
添加站点并绑定域名到项目中的public目录为运行目录
访问 http://www.yoursite.com/install/index 进行安装
4. 命令行安装 第一步:前往官网下载页面 (https://www.gougucms.com) 下载完整包解压到你的项目目录
强烈建议使用命令行安装因为采用命令行安装的方式可以和勾股CMS随时保持更新同步。使用命令行安装请提前准备好Git、Composer、Linux下勾股CMS的安装请使用以下命令进行安装。 第二步添加虚拟主机并绑定到项目的public目录
克隆勾股CMS到你本地 第三步:访问 http://www.yoursite.com/install/index 进行安装
**方式二:命令行安装(推荐)**
推荐使用命令行安装因为采用命令行安装的方式可以和勾股CMS随时保持更新同步。使用命令行安装请提前准备好Git、Composer。
Linux下勾股CMS的安装请使用以下命令进行安装。
第一步克隆勾股CMS到你本地
git clone https://gitee.com/gougucms/gougucms.git git clone https://gitee.com/gougucms/gougucms.git
进入目录 第二步:进入目录
cd gougucms cd gougucms
下载PHP依赖包composer的版本最好是2.0.8版本否则可能下载PHP依赖包失败composer降级composer self-update 2.0.8 第三步下载PHP依赖包
composer install composer install
注意composer的版本最好是2.0.8版本否则可能下载PHP依赖包失败composer降级composer self-update 2.0.8
第四步添加虚拟主机并绑定到项目的public目录
添加虚拟主机并绑定到项目的public目录 第五步:访问 http://www.yoursite.com/install/index 进行安装
访问 http://www.yoursite.com/install/index 进行安装
### 常见问题 ### 常见问题
1. 安装失败可能存在php配置文件禁止了putenv 和 proc_open函数。解决方法查找php.ini文件位置打开php.ini搜索 disable_functions 项看是否禁用了putenv 和 proc_open函数。如果在禁用列表里移除putenv proc_open然后退出重启php即可。 1. 安装失败可能存在php配置文件禁止了putenv 和 proc_open函数。解决方法查找php.ini文件位置打开php.ini搜索 disable_functions 项看是否禁用了putenv 和 proc_open函数。如果在禁用列表里移除putenv proc_open然后退出重启php即可。
2. 如果安装后打开页面提示404错误请检查服务器伪静态配置宝塔伪静态请配置使用thinkphp规则
3. 如果提示当前权限不足无法写入配置文件config/database.php请检查database.php是否可读还有可能是当前安装程序无法访问父目录请检查PHP的open_basedir配置 2. 如果安装后打开页面提示404错误请检查服务器伪静态配置如果是宝塔面板网站伪静态请配置使用thinkphp规则。
4. 如果composer install失败请尝试在命令行进行切换配置到国内源命令如下composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
5. 如果composer install失败请尝试composer降级composer self-update 2.0.8 3. 如果提示当前权限不足无法写入配置文件config/database.php请检查database.php是否可读还有可能是当前安装程序无法访问父目录请检查PHP的open_basedir配置。
6. 访问 http://www.yoursite.com/install/index请注意查看伪静态请配置是否设置了thinkphp规则
7. 遇到问题请到QQ群24641076 反馈 4. 如果composer install失败请尝试在命令行进行切换配置到国内源命令如下composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/。
5. 如果composer install失败请尝试composer降级composer self-update 2.0.8。
6. 访问 http://www.yoursite.com/install/index 请注意查看伪静态请配置是否设置了thinkphp规则。
7. 遇到问题请到QQ群24641076 反馈。
### 截图预览 ### 截图预览
![输入图片说明](https://images.gitee.com/uploads/images/2021/0225/002705_51fd21e2_8633021.png "p1.png") ![输入图片说明](https://images.gitee.com/uploads/images/2021/0225/002705_51fd21e2_8633021.png "p1.png")

View File

@ -1,10 +1,17 @@
<?php <?php
declare(strict_types = 1); /**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
declare (strict_types = 1);
namespace app\admin; namespace app\admin;
use think\App;
use think\exception\HttpResponseException; use think\exception\HttpResponseException;
use think\facade\Request; use think\facade\Request;
use think\App;
/** /**
* 控制器基础类 * 控制器基础类
@ -42,7 +49,7 @@ abstract class BaseController
*/ */
public function __construct(App $app) public function __construct(App $app)
{ {
$this->app = $app; $this->app = $app;
$this->request = $this->app->request; $this->request = $this->app->request;
// 控制器初始化 // 控制器初始化
@ -55,11 +62,11 @@ abstract class BaseController
$this->param = $this->request->param(); $this->param = $this->request->param();
} }
// //
// 以下为新增,为了使用旧版的 success error redirect 跳转 start // 以下为新增,为了使用旧版的 success error redirect 跳转 start
// //
/** /**
* 操作成功跳转的快捷方法 * 操作成功跳转的快捷方法
* @access protected * @access protected
* @param mixed $msg 提示信息 * @param mixed $msg 提示信息
@ -79,14 +86,14 @@ abstract class BaseController
$result = [ $result = [
'code' => 1, 'code' => 1,
'msg' => $msg, 'msg' => $msg,
'data' => $data, 'data' => $data,
'url' => $url, 'url' => $url,
'wait' => $wait, 'wait' => $wait,
]; ];
$type = $this->getResponseType(); $type = $this->getResponseType();
if ($type == 'html'){ if ($type == 'html') {
$response = view($this->app->config->get('app.dispatch_success_tmpl'), $result); $response = view($this->app->config->get('app.dispatch_success_tmpl'), $result);
} else if ($type == 'json') { } else if ($type == 'json') {
$response = json($result); $response = json($result);
@ -114,14 +121,14 @@ abstract class BaseController
$result = [ $result = [
'code' => 0, 'code' => 0,
'msg' => $msg, 'msg' => $msg,
'data' => $data, 'data' => $data,
'url' => $url, 'url' => $url,
'wait' => $wait, 'wait' => $wait,
]; ];
$type = $this->getResponseType(); $type = $this->getResponseType();
if ($type == 'html'){ if ($type == 'html') {
$response = view($this->app->config->get('app.dispatch_error_tmpl'), $result); $response = view($this->app->config->get('app.dispatch_error_tmpl'), $result);
} else if ($type == 'json') { } else if ($type == 'json') {
$response = json($result); $response = json($result);
@ -143,7 +150,7 @@ abstract class BaseController
$response = Response::create($url, 'redirect'); $response = Response::create($url, 'redirect');
if (is_integer($params)) { if (is_integer($params)) {
$code = $params; $code = $params;
$params = []; $params = [];
} }
@ -161,8 +168,8 @@ abstract class BaseController
{ {
return $this->request->isJson() || $this->request->isAjax() ? 'json' : 'html'; return $this->request->isJson() || $this->request->isAjax() ? 'json' : 'html';
} }
// //
// 以上为新增,为了使用旧版的 success error redirect 跳转 end // 以上为新增,为了使用旧版的 success error redirect 跳转 end
// //
} }

View File

@ -1,4 +1,10 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
declare (strict_types = 1); declare (strict_types = 1);
namespace app\admin\controller; namespace app\admin\controller;
@ -32,10 +38,9 @@ class Admin extends BaseController
$item->last_login_time = empty($item->last_login_time) ? '-' : date('Y-m-d H:i', $item->last_login_time); $item->last_login_time = empty($item->last_login_time) ? '-' : date('Y-m-d H:i', $item->last_login_time);
}); });
return table_assign(1, '', $admin); return table_assign(1, '', $admin);
} } else {
else{
return view(); return view();
} }
} }
//添加 //添加
@ -254,9 +259,8 @@ class Admin extends BaseController
$content->offsetSet($k, $data); $content->offsetSet($k, $data);
} }
return table_assign(1, '', $content); return table_assign(1, '', $content);
} } else {
else{
return view(); return view();
} }
} }
} }

View File

@ -1,4 +1,10 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
declare (strict_types = 1); declare (strict_types = 1);
namespace app\admin\controller; namespace app\admin\controller;
@ -117,7 +123,7 @@ class Api extends BaseController
$keyword = get_keywords(); $keyword = get_keywords();
return to_assign(1, '', $keyword); return to_assign(1, '', $keyword);
} }
//获取话题 //获取话题
public function get_topics_cate() public function get_topics_cate()
{ {
@ -208,15 +214,16 @@ class Api extends BaseController
} }
// 测试邮件发送 // 测试邮件发送
public function email_test(){ public function email_test()
{
$sender = get_params('email'); $sender = get_params('email');
//检查是否邮箱格式 //检查是否邮箱格式
if (!is_email($sender)) { if (!is_email($sender)) {
return to_assign(0, '测试邮箱码格式有误'); return to_assign(0, '测试邮箱码格式有误');
} }
$email_config = \think\facade\Db::name('config') $email_config = \think\facade\Db::name('config')
->where('name', 'email') ->where('name', 'email')
->find(); ->find();
$config = unserialize($email_config['content']); $config = unserialize($email_config['content']);
$content = $config['template']; $content = $config['template'];
//所有项目必须填写 //所有项目必须填写
@ -224,7 +231,7 @@ class Api extends BaseController
return to_assign(0, '请完善邮件配置信息!'); return to_assign(0, '请完善邮件配置信息!');
} }
$send = send_email($sender, '测试邮件',$content); $send = send_email($sender, '测试邮件', $content);
if ($send) { if ($send) {
return to_assign(1, '邮件发送成功!'); return to_assign(1, '邮件发送成功!');
} else { } else {
@ -240,7 +247,7 @@ class Api extends BaseController
->order('id desc') ->order('id desc')
->limit(10) ->limit(10)
->select()->toArray(); ->select()->toArray();
$res['data']=$content; $res['data'] = $content;
return table_assign(1, '', $res); return table_assign(1, '', $res);
} }
@ -252,10 +259,10 @@ class Api extends BaseController
->order('id desc') ->order('id desc')
->limit(10) ->limit(10)
->select()->toArray(); ->select()->toArray();
foreach($list as $key=>$val){ foreach ($list as $key => $val) {
$list[$key]['last_login_time']=date('Y-m-d :h:m:s',$val['last_login_time']); $list[$key]['last_login_time'] = date('Y-m-d :h:m:s', $val['last_login_time']);
} }
$res['data']=$list; $res['data'] = $list;
return table_assign(1, '', $res); return table_assign(1, '', $res);
} }
@ -270,26 +277,26 @@ class Api extends BaseController
->order('a.id desc') ->order('a.id desc')
->limit(10) ->limit(10)
->select()->toArray(); ->select()->toArray();
foreach($list as $key=>$val){ foreach ($list as $key => $val) {
$list[$key]['create_time']=date('Y-m-d :H:i',$val['create_time']); $list[$key]['create_time'] = date('Y-m-d :H:i', $val['create_time']);
} }
$res['data']=$list; $res['data'] = $list;
return table_assign(1, '', $res); return table_assign(1, '', $res);
} }
//系统操作日志 //系统操作日志
public function log_list() public function log_list()
{ {
return view('admin/log_list'); return view('admin/log_list');
} }
//获取系统操作日志 //获取系统操作日志
public function get_log_list() public function get_log_list()
{ {
$param=get_params(); $param = get_params();
$log = new AdminLog(); $log = new AdminLog();
$content = $log->get_log_list($param); $content = $log->get_log_list($param);
return table_assign(1,'',$content); return table_assign(1, '', $content);
} }
} }

View File

@ -1,4 +1,10 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
declare (strict_types = 1); declare (strict_types = 1);
namespace app\admin\controller; namespace app\admin\controller;

View File

@ -1,4 +1,10 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
declare (strict_types = 1); declare (strict_types = 1);
namespace app\admin\controller; namespace app\admin\controller;
@ -17,15 +23,14 @@ class Conf extends BaseController
$param = get_params(); $param = get_params();
$where = array(); $where = array();
$where[] = ['status', '>=', 0]; $where[] = ['status', '>=', 0];
$rows = empty($param['limit']) ? get_config(app.page_size) : $param['limit']; $rows = empty($param['limit']) ? get_config(app . page_size) : $param['limit'];
$content = Db::name('config') $content = Db::name('Config')
->where($where) ->where($where)
->paginate($rows, false, ['query' => $param]); ->paginate($rows, false, ['query' => $param]);
return table_assign(1, '', $content); return table_assign(1, '', $content);
} } else {
else{
return view(); return view();
} }
} }
//添加 //添加
@ -33,7 +38,7 @@ class Conf extends BaseController
{ {
$id = empty(get_params('id')) ? 0 : get_params('id'); $id = empty(get_params('id')) ? 0 : get_params('id');
if ($id > 0) { if ($id > 0) {
$config = Db::name('config')->where(['id' => $id])->find(); $config = Db::name('Config')->where(['id' => $id])->find();
View::assign('config', $config); View::assign('config', $config);
} }
View::assign('id', $id); View::assign('id', $id);
@ -54,12 +59,18 @@ class Conf extends BaseController
if (!empty($param['id']) && $param['id'] > 0) { if (!empty($param['id']) && $param['id'] > 0) {
$param['update_time'] = time(); $param['update_time'] = time();
$res = Db::name('config')->strict(false)->field(true)->update($param); $res = Db::name('config')->strict(false)->field(true)->update($param);
if($res) add_log('edit',$param['id'],$param); if ($res) {
add_log('edit', $param['id'], $param);
}
return to_assign(); return to_assign();
} else { } else {
$param['create_time'] = time(); $param['create_time'] = time();
$insertId = Db::name('config')->strict(false)->field(true)->insertGetId($param); $insertId = Db::name('Config')->strict(false)->field(true)->insertGetId($param);
if($insertId) add_log('add',$insertId,$param); if ($insertId) {
add_log('add', $insertId, $param);
}
return to_assign(); return to_assign();
} }
} }
@ -71,8 +82,8 @@ class Conf extends BaseController
$data['status'] = '-1'; $data['status'] = '-1';
$data['id'] = $id; $data['id'] = $id;
$data['update_time'] = time(); $data['update_time'] = time();
if (Db::name('config')->update($data) !== false) { if (Db::name('Config')->update($data) !== false) {
add_log('delete',$id,$data); add_log('delete', $id, $data);
return to_assign(1, "删除成功"); return to_assign(1, "删除成功");
} else { } else {
return to_assign(0, "删除失败"); return to_assign(0, "删除失败");
@ -83,12 +94,12 @@ class Conf extends BaseController
public function edit() public function edit()
{ {
$id = empty(get_params('id')) ? 0 : get_params('id'); $id = empty(get_params('id')) ? 0 : get_params('id');
$conf = Db::name('config')->where('id',$id)->find(); $conf = Db::name('Config')->where('id', $id)->find();
$config=[]; $config = [];
if($conf['content']){ if ($conf['content']) {
$config = unserialize($conf['content']); $config = unserialize($conf['content']);
} }
return view($conf['name'], ['id'=>$id,'config' => $config]); return view($conf['name'], ['id' => $id, 'config' => $config]);
} }
//提交添加 //提交添加
public function conf_submit() public function conf_submit()
@ -98,10 +109,12 @@ class Conf extends BaseController
$data['content'] = serialize($param); $data['content'] = serialize($param);
$data['update_time'] = time(); $data['update_time'] = time();
$data['id'] = $param['id']; $data['id'] = $param['id'];
$res = Db::name('config')->strict(false)->field(true)->update($data); $res = Db::name('Config')->strict(false)->field(true)->update($data);
$conf = Db::name('config')->where('id',$param['id'])->find(); $conf = Db::name('Config')->where('id', $param['id'])->find();
clear_cache('system_config' . $conf['name']); clear_cache('system_config' . $conf['name']);
if($res) add_log('edit',$param['id'],$param); if ($res) {
add_log('edit', $param['id'], $param);
}
return to_assign(); return to_assign();
} }
} }

View File

@ -1,4 +1,10 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
declare (strict_types = 1); declare (strict_types = 1);
namespace app\admin\controller; namespace app\admin\controller;
@ -11,13 +17,14 @@ use think\facade\View;
class Database extends BaseController class Database extends BaseController
{ {
protected $db = '', $datadir; protected $db = '', $datadir;
function initialize(){ public function initialize()
{
parent::initialize(); parent::initialize();
$this->config=array( $this->config = array(
'path' => './backup/', // 数据库备份路径 'path' => './backup/', // 数据库备份路径
'part' => 20971520, // 数据库备份卷大小 'part' => 20971520, // 数据库备份卷大小
'compress' => 0, // 数据库备份文件是否启用压缩 0不压缩 1 压缩 'compress' => 0, // 数据库备份文件是否启用压缩 0不压缩 1 压缩
'level' => 9 // 数据库备份文件压缩级别 1普通 4 一般 9最高 'level' => 9, // 数据库备份文件压缩级别 1普通 4 一般 9最高
); );
$this->db = new Backup($this->config); $this->db = new Backup($this->config);
} }
@ -36,9 +43,9 @@ class Database extends BaseController
$list[$k]['data_length'] = format_bytes($v['data_length']); $list[$k]['data_length'] = format_bytes($v['data_length']);
} }
// 提示信息 // 提示信息
$dataTips = '数据库中共有<strong> ' . count($list) . '</strong> 张表,共计 <strong>' . format_bytes($total) .'</strong>大小。'; $dataTips = '数据库中共有<strong> ' . count($list) . '</strong> 张表,共计 <strong>' . format_bytes($total) . '</strong>大小。';
$data['data']=$list; $data['data'] = $list;
return table_assign(1, $dataTips,$data); return table_assign(1, $dataTips, $data);
} }
return view(); return view();
} }
@ -60,12 +67,13 @@ class Database extends BaseController
} }
// 优化 // 优化
public function optimize() { public function optimize()
{
$tables = get_params('id'); $tables = get_params('id');
if (empty($tables)) { if (empty($tables)) {
return to_assign(1,'请选择要优化的表!'); return to_assign(1, '请选择要优化的表!');
} }
$tables = explode(',',$tables); $tables = explode(',', $tables);
if ($this->db->optimize($tables)) { if ($this->db->optimize($tables)) {
add_log('edit'); add_log('edit');
return to_assign(1, '数据表优化成功!'); return to_assign(1, '数据表优化成功!');
@ -75,12 +83,13 @@ class Database extends BaseController
} }
// 修复 // 修复
public function repair() { public function repair()
{
$tables = get_params('id'); $tables = get_params('id');
if (empty($tables)) { if (empty($tables)) {
return to_assign(0,'请选择要修复的表!'); return to_assign(0, '请选择要修复的表!');
} }
$tables = explode(',',$tables); $tables = explode(',', $tables);
if ($this->db->repair($tables)) { if ($this->db->repair($tables)) {
add_log('edit'); add_log('edit');
return to_assign(1, '数据表修复成功!'); return to_assign(1, '数据表修复成功!');
@ -89,24 +98,22 @@ class Database extends BaseController
} }
} }
// ===========================
// 还原列表 // 还原列表
public function backuplist() public function backuplist()
{ {
// 数据信息 // 数据信息
$list = $this->db->fileList(); $list = $this->db->fileList();
$listNew = []; $listNew = [];
$indx=0; $indx = 0;
foreach ($list as $k => $v) { foreach ($list as $k => $v) {
$listNew[$indx]['time'] = $k; $listNew[$indx]['time'] = $k;
$listNew[$indx]['data'][] = $v; $listNew[$indx]['data'][] = $v;
$indx++; $indx++;
// $listNew[$k]['list'] = $list[$k]; // $listNew[$k]['list'] = $list[$k];
} }
$list = $listNew; $list = $listNew;
array_multisort(array_column($list, 'time'), SORT_DESC, $list); array_multisort(array_column($list, 'time'), SORT_DESC, $list);
return view('',['list' => $list]); return view('', ['list' => $list]);
} }
// 执行还原数据库操作 // 执行还原数据库操作
@ -115,7 +122,7 @@ class Database extends BaseController
$list = $this->db->getFile('timeverif', $id); $list = $this->db->getFile('timeverif', $id);
$this->db->setFile($list)->import(1); $this->db->setFile($list)->import(1);
add_log('save'); add_log('save');
return to_assign(1,'还原成功!'); return to_assign(1, '还原成功!');
} }
// 下载 // 下载
@ -123,31 +130,31 @@ class Database extends BaseController
{ {
$file_name = $name; //得到文件名 $file_name = $name; //得到文件名
header("Content-type:text/html;charset=utf-8"); header("Content-type:text/html;charset=utf-8");
$file_name = iconv("utf-8","gb2312",$file_name); // 转换编码 $file_name = iconv("utf-8", "gb2312", $file_name); // 转换编码
$file_sub_path = $this->config['path']; //确保文件在这个路径下面,换成你文件所在的路径 $file_sub_path = $this->config['path']; //确保文件在这个路径下面,换成你文件所在的路径
$file_path = $file_sub_path . $file_name; $file_path = $file_sub_path . $file_name;
# 将反斜杠 替换成正斜杠 # 将反斜杠 替换成正斜杠
$file_path = str_replace('\\','/',$file_path); $file_path = str_replace('\\', '/', $file_path);
if(!file_exists($file_path)){ if (!file_exists($file_path)) {
$this->error($file_path);exit; //如果提示这个错误,很可能你的路径不对,可以打印$file_sub_path查看 $this->error($file_path);exit; //如果提示这个错误,很可能你的路径不对,可以打印$file_sub_path查看
} }
$fp = fopen($file_path,"r"); // 以可读的方式打开这个文件 $fp = fopen($file_path, "r"); // 以可读的方式打开这个文件
# 如果出现图片无法打开,可以在这个位置添加函数 # 如果出现图片无法打开,可以在这个位置添加函数
ob_clean(); # 清空擦掉,输出缓冲区。 ob_clean(); # 清空擦掉,输出缓冲区。
$file_size = filesize($file_path); $file_size = filesize($file_path);
//下载文件需要用到的头 //下载文件需要用到的头
Header("Content-type: application/octet-stream"); Header("Content-type: application/octet-stream");
Header("Accept-Ranges: bytes"); Header("Accept-Ranges: bytes");
Header("Accept-Length:".$file_size); Header("Accept-Length:" . $file_size);
Header("Content-Disposition: attachment; filename = ". $file_name); Header("Content-Disposition: attachment; filename = " . $file_name);
$buffer = 1024000; $buffer = 1024000;
$file_count = 0; $file_count = 0;
while(!feof($fp) && $file_count<$file_size){ while (!feof($fp) && $file_count < $file_size) {
$file_con = fread($fp,$buffer); $file_con = fread($fp, $buffer);
$file_count += $buffer; $file_count += $buffer;
echo $file_con; echo $file_con;
} }
fclose($fp); //关闭这个打开的文件 fclose($fp); //关闭这个打开的文件
} }
// 删除sql文件 // 删除sql文件
@ -160,15 +167,15 @@ class Database extends BaseController
$this->db->delFile($v); $this->db->delFile($v);
} }
add_log('delete'); add_log('delete');
return to_assign(1,"删除成功!"); return to_assign(1, "删除成功!");
} }
if ($this->db->delFile($id)) { if ($this->db->delFile($id)) {
add_log('delete'); add_log('delete');
return to_assign(1,"删除成功!"); return to_assign(1, "删除成功!");
} else { } else {
return to_assign(0, "备份文件删除失败,请检查文件权限!"); return to_assign(0, "备份文件删除失败,请检查文件权限!");
} }
} }
} }
} }

View File

@ -1,4 +1,10 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
declare (strict_types = 1); declare (strict_types = 1);
namespace app\admin\controller; namespace app\admin\controller;
@ -18,12 +24,12 @@ class Index extends BaseController
public function main() public function main()
{ {
$adminCount=Db::name('admin')->where('status','1')->count(); $adminCount = Db::name('Admin')->where('status', '1')->count();
$userCount=Db::name('user')->where('status','1')->count(); $userCount = Db::name('User')->where('status', '1')->count();
$articleCount=Db::name('article')->where('status','1')->count(); $articleCount = Db::name('Article')->where('status', '1')->count();
$install=false; $install = false;
if (file_exists(CMS_ROOT . 'app/install')) { if (file_exists(CMS_ROOT . 'app/install')) {
$install=true; $install = true;
} }
View::assign('adminCount', $adminCount); View::assign('adminCount', $adminCount);
View::assign('userCount', $userCount); View::assign('userCount', $userCount);
@ -36,5 +42,5 @@ class Index extends BaseController
{ {
echo '错误'; echo '错误';
} }
} }

View File

@ -1,4 +1,10 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
declare (strict_types = 1); declare (strict_types = 1);
namespace app\admin\controller; namespace app\admin\controller;
@ -17,7 +23,7 @@ class Keywords extends BaseController
$param = get_params(); $param = get_params();
$where = array(); $where = array();
if (!empty($param['keywords'])) { if (!empty($param['keywords'])) {
$where[] = ['title','like', '%' . $param['keywords'] . '%']; $where[] = ['title', 'like', '%' . $param['keywords'] . '%'];
} }
$where[] = ['status', '>=', 0]; $where[] = ['status', '>=', 0];
$rows = empty($param['limit']) ? get_config(app . page_size) : $param['limit']; $rows = empty($param['limit']) ? get_config(app . page_size) : $param['limit'];
@ -26,10 +32,9 @@ class Keywords extends BaseController
->where($where) ->where($where)
->paginate($rows, false, ['query' => $param]); ->paginate($rows, false, ['query' => $param]);
return table_assign(1, '', $content); return table_assign(1, '', $content);
} } else {
else{
return view(); return view();
} }
} }
//添加 //添加
@ -58,7 +63,10 @@ class Keywords extends BaseController
} }
$param['update_time'] = time(); $param['update_time'] = time();
$res = Db::name('Keywords')->strict(false)->field(true)->update($param); $res = Db::name('Keywords')->strict(false)->field(true)->update($param);
if($res) add_log('edit',$param['id'],$param); if ($res) {
add_log('edit', $param['id'], $param);
}
return to_assign(); return to_assign();
} else { } else {
try { try {
@ -69,7 +77,10 @@ class Keywords extends BaseController
} }
$param['create_time'] = time(); $param['create_time'] = time();
$insertId = Db::name('Keywords')->strict(false)->field(true)->insertGetId($param); $insertId = Db::name('Keywords')->strict(false)->field(true)->insertGetId($param);
if($insertId) add_log('add',$insertId,$param); if ($insertId) {
add_log('add', $insertId, $param);
}
return to_assign(); return to_assign();
} }
} }
@ -82,7 +93,7 @@ class Keywords extends BaseController
$data['id'] = $id; $data['id'] = $id;
$data['update_time'] = time(); $data['update_time'] = time();
if (Db::name('Keywords')->update($data) !== false) { if (Db::name('Keywords')->update($data) !== false) {
add_log('delete',$id,$data); add_log('delete', $id, $data);
return to_assign(1, "删除成功"); return to_assign(1, "删除成功");
} else { } else {
return to_assign(0, "删除失败"); return to_assign(0, "删除失败");

View File

@ -1,4 +1,10 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
declare (strict_types = 1); declare (strict_types = 1);
namespace app\admin\controller; namespace app\admin\controller;
@ -31,7 +37,7 @@ class Login
return to_assign(0, $e->getError()); return to_assign(0, $e->getError());
} }
$admin = Db::name('admin')->where(['username' => $param['username']])->find(); $admin = Db::name('Admin')->where(['username' => $param['username']])->find();
if (empty($admin)) { if (empty($admin)) {
return to_assign(0, '用户名或密码错误'); return to_assign(0, '用户名或密码错误');
} }
@ -53,8 +59,8 @@ class Login
$token = make_token(); $token = make_token();
set_cache($token, $admin, 7200); set_cache($token, $admin, 7200);
$admin['token'] = $token; $admin['token'] = $token;
add_log('login',$admin['id'],$data); add_log('login', $admin['id'], $data);
return to_assign(1, '登录成功', ['uid'=>$admin['id']]); return to_assign(1, '登录成功', ['uid' => $admin['id']]);
} }
//退出登录 //退出登录

View File

@ -1,4 +1,9 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
declare (strict_types = 1); declare (strict_types = 1);
@ -17,10 +22,9 @@ class Menu extends BaseController
if (request()->isAjax()) { if (request()->isAjax()) {
$menu = Db::name('AdminMenu')->order('sort asc')->select(); $menu = Db::name('AdminMenu')->order('sort asc')->select();
return to_assign(0, '', $menu); return to_assign(0, '', $menu);
} } else {
else{
return view(); return view();
} }
} }
//添加菜单页面 //添加菜单页面

View File

@ -1,4 +1,9 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
declare (strict_types = 1); declare (strict_types = 1);
@ -27,10 +32,9 @@ class Nav extends BaseController
->order('create_time asc') ->order('create_time asc')
->paginate($rows, false, ['query' => $param]); ->paginate($rows, false, ['query' => $param]);
return table_assign(1, '', $nav); return table_assign(1, '', $nav);
} } else {
else{
return view(); return view();
} }
} }
//添加 //添加
@ -38,7 +42,7 @@ class Nav extends BaseController
{ {
$id = empty(get_params('id')) ? 0 : get_params('id'); $id = empty(get_params('id')) ? 0 : get_params('id');
if ($id > 0) { if ($id > 0) {
$nav = Db::name('nav')->where(['id' => $id])->find(); $nav = Db::name('Nav')->where(['id' => $id])->find();
View::assign('nav', $nav); View::assign('nav', $nav);
} }
View::assign('id', $id); View::assign('id', $id);
@ -63,7 +67,7 @@ class Nav extends BaseController
->update($param); ->update($param);
// 删除导航缓存 // 删除导航缓存
clear_cache('homeNav'); clear_cache('homeNav');
add_log('edit',$param['id'], $param); add_log('edit', $param['id'], $param);
return to_assign(); return to_assign();
} else { } else {
try { try {
@ -75,7 +79,7 @@ class Nav extends BaseController
$nid = NavList::strict(false)->field(true)->insertGetId($param); $nid = NavList::strict(false)->field(true)->insertGetId($param);
// 删除导航缓存 // 删除导航缓存
clear_cache('homeNav'); clear_cache('homeNav');
add_log('add',$nid, $param); add_log('add', $nid, $param);
return to_assign(); return to_assign();
} }
} }
@ -95,7 +99,7 @@ class Nav extends BaseController
return to_assign(1, '删除成功'); return to_assign(1, '删除成功');
// 删除导航缓存 // 删除导航缓存
clear_cache('homeNav'); clear_cache('homeNav');
add_log('delete',$id, []); add_log('delete', $id, []);
} else { } else {
return to_assign(0, '删除失败'); return to_assign(0, '删除失败');
} }
@ -108,16 +112,15 @@ class Nav extends BaseController
if (request()->isAjax()) { if (request()->isAjax()) {
$id = $param['id']; $id = $param['id'];
$navInfoList = Db::name('NavInfo') $navInfoList = Db::name('NavInfo')
->where(['nav_id' => $id]) ->where(['nav_id' => $id])
->order('sort asc') ->order('sort asc')
->select(); ->select();
return to_assign(0, '', $navInfoList); return to_assign(0, '', $navInfoList);
} } else {
else{
return view('', [ return view('', [
'nav_id' => $param['id'], 'nav_id' => $param['id'],
]); ]);
} }
} }
@ -152,7 +155,7 @@ class Nav extends BaseController
NavInfo::strict(false)->field(true)->update($param); NavInfo::strict(false)->field(true)->update($param);
// 删除导航缓存 // 删除导航缓存
clear_cache('homeNav'); clear_cache('homeNav');
add_log('edit',$param['id'], $param); add_log('edit', $param['id'], $param);
return to_assign(); return to_assign();
} else { } else {
try { try {

View File

@ -1,4 +1,10 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
declare (strict_types = 1); declare (strict_types = 1);
namespace app\admin\controller; namespace app\admin\controller;
@ -18,17 +24,16 @@ class Role extends BaseController
$param = get_params(); $param = get_params();
$where = array(); $where = array();
if (!empty($param['keywords'])) { if (!empty($param['keywords'])) {
$where[] = ['id|title|desc','like', '%' . $param['keywords'] . '%']; $where[] = ['id|title|desc', 'like', '%' . $param['keywords'] . '%'];
} }
$rows = empty($param['limit']) ? get_config(app.page_size) : $param['limit']; $rows = empty($param['limit']) ? get_config(app . page_size) : $param['limit'];
$group = AdminGroup::where($where) $group = AdminGroup::where($where)
->order('create_time asc') ->order('create_time asc')
->paginate($rows, false, ['query' => $param]); ->paginate($rows, false, ['query' => $param]);
return table_assign(1, '', $group); return table_assign(1, '', $group);
} } else {
else{
return view(); return view();
} }
} }
//添加&编辑 //添加&编辑
@ -36,7 +41,7 @@ class Role extends BaseController
{ {
$id = empty(get_params('id')) ? 0 : get_params('id'); $id = empty(get_params('id')) ? 0 : get_params('id');
if ($id > 0) { if ($id > 0) {
$role = Db::name('admin_group')->where(['id' => $id])->find(); $role = Db::name('AdminGroup')->where(['id' => $id])->find();
View::assign('role', $role); View::assign('role', $role);
} }
View::assign('id', $id); View::assign('id', $id);
@ -62,14 +67,14 @@ class Role extends BaseController
} }
/* /*
if (!empty($param['rules'])) { if (!empty($param['rules'])) {
$param['rules'] = implode(',', $param['rules']); $param['rules'] = implode(',', $param['rules']);
} }
if (!empty($param['menus'])) { if (!empty($param['menus'])) {
$param['menus'] = implode(',', $param['menus']); $param['menus'] = implode(',', $param['menus']);
} }
*/ */
Db::name('admin_group')->where(['id' => $param['id']])->strict(false)->field(true)->update($param); Db::name('AdminGroup')->where(['id' => $param['id']])->strict(false)->field(true)->update($param);
add_log('edit',$param['id'],$param); add_log('edit', $param['id'], $param);
} else { } else {
try { try {
validate(GroupCheck::class)->scene('add')->check($param); validate(GroupCheck::class)->scene('add')->check($param);
@ -79,14 +84,14 @@ class Role extends BaseController
} }
/* /*
if (!empty($param['rules'])) { if (!empty($param['rules'])) {
$param['rules'] = implode(',', $param['rules']); $param['rules'] = implode(',', $param['rules']);
} }
if (!empty($param['menus'])) { if (!empty($param['menus'])) {
$param['menus'] = implode(',', $param['menus']); $param['menus'] = implode(',', $param['menus']);
} }
*/ */
$gid = Db::name('admin_group')->strict(false)->field(true)->insertGetId($param); $gid = Db::name('AdminGroup')->strict(false)->field(true)->insertGetId($param);
add_log('add',$gid,$param); add_log('add', $gid, $param);
} }
//清除菜单\权限缓存 //清除菜单\权限缓存
clear_cache('adminMenu'); clear_cache('adminMenu');
@ -103,7 +108,7 @@ class Role extends BaseController
return to_assign(0, "该组是系统所有者,无法删除"); return to_assign(0, "该组是系统所有者,无法删除");
} }
if (Db::name('AdminGroup')->delete($id) !== false) { if (Db::name('AdminGroup')->delete($id) !== false) {
add_log('delete',$id,[]); add_log('delete', $id, []);
return to_assign(1, "删除角色成功"); return to_assign(1, "删除角色成功");
} else { } else {
return to_assign(0, "删除失败"); return to_assign(0, "删除失败");

View File

@ -1,4 +1,10 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
declare (strict_types = 1); declare (strict_types = 1);
namespace app\admin\controller; namespace app\admin\controller;
@ -16,8 +22,7 @@ class Rule extends BaseController
if (request()->isAjax()) { if (request()->isAjax()) {
$rule = Db::name('adminRule')->order('create_time asc')->select(); $rule = Db::name('adminRule')->order('create_time asc')->select();
return to_assign(0, '', $rule); return to_assign(0, '', $rule);
} } else {
else{
return view(); return view();
} }
} }

View File

@ -1,4 +1,10 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
declare (strict_types = 1); declare (strict_types = 1);
namespace app\admin\controller; namespace app\admin\controller;
@ -15,18 +21,17 @@ class Search extends BaseController
$param = get_params(); $param = get_params();
$where = array(); $where = array();
if (!empty($param['keywords'])) { if (!empty($param['keywords'])) {
$where[] = ['title','like', '%' . $param['keywords'] . '%']; $where[] = ['title', 'like', '%' . $param['keywords'] . '%'];
} }
$rows = empty($param['limit']) ? get_config(app . page_size) : $param['limit']; $rows = empty($param['limit']) ? get_config(app . page_size) : $param['limit'];
$content = Db::name('SearchKeywords') $content = Db::name('SearchKeywords')
->order('id desc') ->order('id desc')
->where($where) ->where($where)
->paginate($rows, false, ['query' => $param]); ->paginate($rows, false, ['query' => $param]);
return table_assign(1, '', $content); return table_assign(1, '', $content);
} } else {
else{
return view(); return view();
} }
} }
//删除 //删除

View File

@ -1,4 +1,10 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
declare (strict_types = 1); declare (strict_types = 1);
namespace app\admin\controller; namespace app\admin\controller;
@ -22,16 +28,15 @@ class Sitemap extends BaseController
if (!empty($param['keywords'])) { if (!empty($param['keywords'])) {
$where[] = ['id|name', 'like', '%' . $param['keywords'] . '%']; $where[] = ['id|name', 'like', '%' . $param['keywords'] . '%'];
} }
$where[] = ['status','=',1]; $where[] = ['status', '=', 1];
$rows = empty($param['limit']) ? get_config(app . page_size) : $param['limit']; $rows = empty($param['limit']) ? get_config(app . page_size) : $param['limit'];
$SitemapCate = SitemapCate::where($where) $SitemapCate = SitemapCate::where($where)
->order('sort desc, id desc') ->order('sort desc, id desc')
->paginate($rows, false, ['query' => $param]); ->paginate($rows, false, ['query' => $param]);
return table_assign(1, '', $SitemapCate); return table_assign(1, '', $SitemapCate);
} } else {
else{
return view(); return view();
} }
} }
//添加 //添加
@ -60,7 +65,10 @@ class Sitemap extends BaseController
} }
$param['update_time'] = time(); $param['update_time'] = time();
$res = SitemapCate::where('id', $param['id'])->strict(false)->field(true)->update($param); $res = SitemapCate::where('id', $param['id'])->strict(false)->field(true)->update($param);
if($res) add_log('edit', $param['id'], $param); if ($res) {
add_log('edit', $param['id'], $param);
}
// 删除菜单缓存 // 删除菜单缓存
clear_cache('homeSitemap'); clear_cache('homeSitemap');
return to_assign(); return to_assign();
@ -73,7 +81,10 @@ class Sitemap extends BaseController
} }
$param['create_time'] = time(); $param['create_time'] = time();
$sid = SitemapCate::strict(false)->field(true)->insertGetId($param); $sid = SitemapCate::strict(false)->field(true)->insertGetId($param);
if($sid) add_log('add', $sid, $param); if ($sid) {
add_log('add', $sid, $param);
}
// 删除菜单缓存 // 删除菜单缓存
clear_cache('homeSitemap'); clear_cache('homeSitemap');
return to_assign(); return to_assign();
@ -85,8 +96,8 @@ class Sitemap extends BaseController
public function delete() public function delete()
{ {
$id = get_params("id"); $id = get_params("id");
$where[] = ['sitemap_cate_id','=',$id]; $where[] = ['sitemap_cate_id', '=', $id];
$where[] = ['status','>=',0]; $where[] = ['status', '>=', 0];
$count = Db::name('Sitemap')->where($where)->count(); $count = Db::name('Sitemap')->where($where)->count();
if ($count > 0) { if ($count > 0) {
return to_assign(0, '该分类下还有数据,无法删除'); return to_assign(0, '该分类下还有数据,无法删除');
@ -106,21 +117,20 @@ class Sitemap extends BaseController
public function sitemap_info() public function sitemap_info()
{ {
$param = get_params(); $param = get_params();
if (request()->isAjax()) { if (request()->isAjax()) {
$where = array(); $where = array();
$where[] = ['sitemap_cate_id','=',$param['id']]; $where[] = ['sitemap_cate_id', '=', $param['id']];
$where[] = ['status','>=',0]; $where[] = ['status', '>=', 0];
$rows = empty($param['limit']) ? get_config(app . page_size) : $param['limit']; $rows = empty($param['limit']) ? get_config(app . page_size) : $param['limit'];
$sitemap = SitemapInfo::where($where) $sitemap = SitemapInfo::where($where)
->order('sort desc, id desc') ->order('sort desc, id desc')
->paginate($rows, false, ['query' => $param]); ->paginate($rows, false, ['query' => $param]);
return table_assign(1, '', $sitemap); return table_assign(1, '', $sitemap);
} } else {
else{
return view('', [ return view('', [
'sitemap_cate_id' => $param['id'], 'sitemap_cate_id' => $param['id'],
]); ]);
} }
} }
//添加网站地图 //添加网站地图
@ -152,7 +162,10 @@ class Sitemap extends BaseController
$param['update_time'] = time(); $param['update_time'] = time();
$param['name'] = htmlspecialchars($param['name']); $param['name'] = htmlspecialchars($param['name']);
$res = SitemapInfo::where(['id' => $param['id']])->strict(false)->field(true)->update($param); $res = SitemapInfo::where(['id' => $param['id']])->strict(false)->field(true)->update($param);
if($res) add_log('edit',$param['id'],$param); if ($res) {
add_log('edit', $param['id'], $param);
}
// 删除导航缓存 // 删除导航缓存
clear_cache('homeSitemap'); clear_cache('homeSitemap');
return to_assign(); return to_assign();
@ -166,7 +179,10 @@ class Sitemap extends BaseController
$param['name'] = htmlspecialchars($param['name']); $param['name'] = htmlspecialchars($param['name']);
$param['create_time'] = time(); $param['create_time'] = time();
$sid = SitemapInfo::strict(false)->field(true)->insertGetId($param); $sid = SitemapInfo::strict(false)->field(true)->insertGetId($param);
if($sid) add_log('add', $sid, $param); if ($sid) {
add_log('add', $sid, $param);
}
// 删除导航缓存 // 删除导航缓存
clear_cache('homeSitemap'); clear_cache('homeSitemap');
return to_assign(); return to_assign();

View File

@ -1,4 +1,10 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
declare (strict_types = 1); declare (strict_types = 1);
namespace app\admin\controller; namespace app\admin\controller;
@ -21,15 +27,14 @@ class Slide extends BaseController
if (!empty($param['keywords'])) { if (!empty($param['keywords'])) {
$where[] = ['id|name|title|desc', 'like', '%' . $param['keywords'] . '%']; $where[] = ['id|name|title|desc', 'like', '%' . $param['keywords'] . '%'];
} }
$rows = empty($param['limit']) ? get_config(app . page_size) : $param['limit']; $rows = empty($param['limit']) ? get_config(app . page_size) : $param['limit'];
$slide = SlideList::where($where) $slide = SlideList::where($where)
->order('create_time asc') ->order('create_time asc')
->paginate($rows, false, ['query' => $param]); ->paginate($rows, false, ['query' => $param]);
return table_assign(1, '', $slide); return table_assign(1, '', $slide);
} } else {
else{
return view(); return view();
} }
} }
//添加 //添加
@ -37,7 +42,7 @@ class Slide extends BaseController
{ {
$id = empty(get_params('id')) ? 0 : get_params('id'); $id = empty(get_params('id')) ? 0 : get_params('id');
if ($id > 0) { if ($id > 0) {
$slide = Db::name('slide')->where(['id' => $id])->find(); $slide = Db::name('Slide')->where(['id' => $id])->find();
View::assign('slide', $slide); View::assign('slide', $slide);
} }
View::assign('id', $id); View::assign('id', $id);
@ -58,7 +63,10 @@ class Slide extends BaseController
} }
$param['update_time'] = time(); $param['update_time'] = time();
$res = SlideList::where('id', $param['id'])->strict(false)->field(true)->update($param); $res = SlideList::where('id', $param['id'])->strict(false)->field(true)->update($param);
if($res) add_log('edit', $param['id'], $param); if ($res) {
add_log('edit', $param['id'], $param);
}
clear_cache('homeSlide'); clear_cache('homeSlide');
return to_assign(); return to_assign();
} else { } else {
@ -70,7 +78,10 @@ class Slide extends BaseController
} }
$param['create_time'] = time(); $param['create_time'] = time();
$sid = SlideList::strict(false)->field(true)->insertGetId($param); $sid = SlideList::strict(false)->field(true)->insertGetId($param);
if($sid) add_log('add', $sid, $param); if ($sid) {
add_log('add', $sid, $param);
}
// 删除banner缓存 // 删除banner缓存
clear_cache('homeSlide'); clear_cache('homeSlide');
return to_assign(); return to_assign();
@ -86,7 +97,7 @@ class Slide extends BaseController
'slide_id' => $id, 'slide_id' => $id,
])->count(); ])->count();
if ($count > 0) { if ($count > 0) {
return to_assign(0, '该组下还有幻灯片,无法删除'); return to_assign(0, '该组下还有Banner,无法删除');
} }
if (Db::name('Slide')->delete($id) !== false) { if (Db::name('Slide')->delete($id) !== false) {
add_log('delete', $id); add_log('delete', $id);
@ -103,21 +114,20 @@ class Slide extends BaseController
$param = get_params(); $param = get_params();
if (request()->isAjax()) { if (request()->isAjax()) {
$where = array(); $where = array();
$where[] = ['s.slide_id','=',$param['id']]; $where[] = ['s.slide_id', '=', $param['id']];
$rows = empty($param['limit']) ? get_config(app . page_size) : $param['limit']; $rows = empty($param['limit']) ? get_config(app . page_size) : $param['limit'];
$slideInfoList = SlideInfo::where($where) $slideInfoList = SlideInfo::where($where)
->alias('s') ->alias('s')
->join('file f', 's.img=f.id', 'LEFT') ->join('File f', 's.img=f.id', 'LEFT')
->field('s.*,f.filepath') ->field('s.*,f.filepath')
->order('s.sort desc, s.id desc') ->order('s.sort desc, s.id desc')
->paginate($rows, false, ['query' => $param]); ->paginate($rows, false, ['query' => $param]);
return table_assign(1, '', $slideInfoList); return table_assign(1, '', $slideInfoList);
} } else {
else{
return view('', [ return view('', [
'slide_id' => $param['id'], 'slide_id' => $param['id'],
]); ]);
} }
} }
//幻灯片列表 //幻灯片列表
@ -125,12 +135,12 @@ class Slide extends BaseController
{ {
$param = get_params(); $param = get_params();
$where = array(); $where = array();
$where[] = ['s.slide_id','=',$param['id']]; $where[] = ['s.slide_id', '=', $param['id']];
$rows = empty($param['limit']) ? get_config(app . page_size) : $param['limit']; $rows = empty($param['limit']) ? get_config(app . page_size) : $param['limit'];
$slideInfoList = SlideInfo::where($where) $slideInfoList = SlideInfo::where($where)
->alias('s') ->alias('s')
->join('file f', 's.img=f.id', 'LEFT') ->join('File f', 's.img=f.id', 'LEFT')
->field('s.*,f.filepath') ->field('s.*,f.filepath')
->order('s.sort desc, s.id desc') ->order('s.sort desc, s.id desc')
->paginate($rows, false, ['query' => $param]); ->paginate($rows, false, ['query' => $param]);
return table_assign(1, '', $slideInfoList); return table_assign(1, '', $slideInfoList);
@ -165,7 +175,10 @@ class Slide extends BaseController
} }
$param['update_time'] = time(); $param['update_time'] = time();
$res = SlideInfo::where(['id' => $param['id']])->strict(false)->field(true)->update($param); $res = SlideInfo::where(['id' => $param['id']])->strict(false)->field(true)->update($param);
if($res) add_log('edit',$param['id'],$param); if ($res) {
add_log('edit', $param['id'], $param);
}
// 删除缓存 // 删除缓存
clear_cache('homeSlide'); clear_cache('homeSlide');
return to_assign(); return to_assign();
@ -178,7 +191,10 @@ class Slide extends BaseController
} }
$param['create_time'] = time(); $param['create_time'] = time();
$sid = SlideInfo::strict(false)->field(true)->insertGetId($param); $sid = SlideInfo::strict(false)->field(true)->insertGetId($param);
if($sid) add_log('add', $sid, $param); if ($sid) {
add_log('add', $sid, $param);
}
// 删除缓存 // 删除缓存
clear_cache('homeSlide'); clear_cache('homeSlide');
return to_assign(); return to_assign();
@ -192,7 +208,7 @@ class Slide extends BaseController
if (Db::name('SlideInfo')->delete($id) !== false) { if (Db::name('SlideInfo')->delete($id) !== false) {
add_log('delete', $id); add_log('delete', $id);
clear_cache('homeSlide'); clear_cache('homeSlide');
return to_assign(1, "删除成功"); return to_assign(1, "删除成功");
} else { } else {
return to_assign(0, "删除失败"); return to_assign(0, "删除失败");
} }

View File

@ -1,4 +1,10 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
declare (strict_types = 1); declare (strict_types = 1);
namespace app\admin\controller; namespace app\admin\controller;
@ -16,13 +22,13 @@ class User extends BaseController
$param = get_params(); $param = get_params();
$where = array(); $where = array();
if (!empty($param['keywords'])) { if (!empty($param['keywords'])) {
$where[] = ['nickname|truename|mobile|province|city','like', '%' . $param['keywords'] . '%']; $where[] = ['nickname|truename|mobile|province|city', 'like', '%' . $param['keywords'] . '%'];
} }
//按时间检索 //按时间检索
$start_time = isset($param['start_time']) ? strtotime(urldecode($param['start_time'])) : 0; $start_time = isset($param['start_time']) ? strtotime(urldecode($param['start_time'])) : 0;
$end_time = isset($param['end_time']) ? strtotime(urldecode($param['end_time'])) : 0; $end_time = isset($param['end_time']) ? strtotime(urldecode($param['end_time'])) : 0;
if ($start_time > 0 && $end_time > 0) { if ($start_time > 0 && $end_time > 0) {
if ($start_time === $end_time) { if ($start_time === $end_time) {
$where['register_time'] = array('eq', $start_time); $where['register_time'] = array('eq', $start_time);
@ -34,7 +40,7 @@ class User extends BaseController
} elseif ($start_time == 0 && $end_time > 0) { } elseif ($start_time == 0 && $end_time > 0) {
$where['register_time'] = array('elt', $end_time); $where['register_time'] = array('elt', $end_time);
} }
$rows = empty($param['limit']) ? get_config(app . page_size) : $param['limit']; $rows = empty($param['limit']) ? get_config(app . page_size) : $param['limit'];
$content = UserList::where($where) $content = UserList::where($where)
->order('id desc') ->order('id desc')
@ -43,17 +49,16 @@ class User extends BaseController
$item->register_time = empty($item->register_time) ? '-' : date('Y-m-d H:i', $item->register_time); $item->register_time = empty($item->register_time) ? '-' : date('Y-m-d H:i', $item->register_time);
}); });
return table_assign(1, '', $content); return table_assign(1, '', $content);
} } else {
else{
return view(); return view();
} }
} }
//编辑 //编辑
public function edit() public function edit()
{ {
$id = empty(get_params('id')) ? 0 : get_params('id'); $id = empty(get_params('id')) ? 0 : get_params('id');
$user = Db::name('user')->where(['id' => $id])->find(); $user = Db::name('User')->where(['id' => $id])->find();
View::assign('user', $user); View::assign('user', $user);
return view(); return view();
} }
@ -64,13 +69,13 @@ class User extends BaseController
if (request()->isAjax()) { if (request()->isAjax()) {
$param = get_params(); $param = get_params();
if (!empty($param['id']) && $param['id'] > 0) { if (!empty($param['id']) && $param['id'] > 0) {
$res = Db::name('user')->where(['id' => $param['id']])->strict(false)->field(true)->update($param); $res = Db::name('User')->where(['id' => $param['id']])->strict(false)->field(true)->update($param);
if($res){ if ($res) {
add_log('edit', $param['id'], $param); add_log('edit', $param['id'], $param);
return to_assign(); return to_assign();
}else{ } else {
return to_assign(0, '提交失败:' . $e->getMessage()); return to_assign(0, '提交失败:' . $e->getMessage());
} }
} }
} }
} }
@ -79,7 +84,7 @@ class User extends BaseController
public function view() public function view()
{ {
$id = empty(get_params('id')) ? 0 : get_params('id'); $id = empty(get_params('id')) ? 0 : get_params('id');
$user = Db::name('user')->where(['id' => $id])->find(); $user = Db::name('User')->where(['id' => $id])->find();
add_log('view', get_params('id')); add_log('view', get_params('id'));
View::assign('user', $user); View::assign('user', $user);
return view(); return view();
@ -90,7 +95,7 @@ class User extends BaseController
$id = get_params("id"); $id = get_params("id");
$data['status'] = get_params("status"); $data['status'] = get_params("status");
$data['id'] = $id; $data['id'] = $id;
if (Db::name('user')->update($data) !== false) { if (Db::name('User')->update($data) !== false) {
add_log('edit', $id); add_log('edit', $id);
return to_assign(1, "操作成功"); return to_assign(1, "操作成功");
} else { } else {
@ -98,21 +103,22 @@ class User extends BaseController
} }
} }
//日志
public function log() public function log()
{ {
if (request()->isAjax()) { if (request()->isAjax()) {
$param = get_params(); $param = get_params();
$where = array(); $where = array();
if (!empty($param['keywords'])) { if (!empty($param['keywords'])) {
$where[] = ['nickname|title','like', '%' . $param['keywords'] . '%']; $where[] = ['nickname|title', 'like', '%' . $param['keywords'] . '%'];
} }
$rows = empty($param['limit']) ? get_config(app . page_size) : $param['limit']; $rows = empty($param['limit']) ? get_config(app . page_size) : $param['limit'];
$content = DB::name('user_log') $content = DB::name('UserLog')
->field("id,uid,nickname,title,content,ip,param,FROM_UNIXTIME(create_time,'%Y-%m-%d %H:%i:%s') create_time") ->field("id,uid,nickname,title,content,ip,param,FROM_UNIXTIME(create_time,'%Y-%m-%d %H:%i:%s') create_time")
->order('create_time desc') ->order('create_time desc')
->where($where) ->where($where)
->paginate($rows, false, ['query' => $param]); ->paginate($rows, false, ['query' => $param]);
$content->toArray(); $content->toArray();
foreach ($content as $k => $v) { foreach ($content as $k => $v) {
$data = $v; $data = $v;
@ -128,47 +134,46 @@ class User extends BaseController
$content->offsetSet($k, $data); $content->offsetSet($k, $data);
} }
return table_assign(1, '', $content); return table_assign(1, '', $content);
} } else {
else{
return view(); return view();
} }
} }
//记录
public function record() public function record()
{ {
if (request()->isAjax()) { if (request()->isAjax()) {
$param = get_params(); $param = get_params();
$where = array(); $where = array();
if (!empty($param['keywords'])) { if (!empty($param['keywords'])) {
$where[] = ['nickname|title','like', '%' . $param['keywords'] . '%']; $where[] = ['nickname|title', 'like', '%' . $param['keywords'] . '%'];
} }
$rows = empty($param['limit']) ? get_config(app . page_size) : $param['limit']; $rows = empty($param['limit']) ? get_config(app . page_size) : $param['limit'];
$content = DB::name('user_log') $content = DB::name('UserLog')
->field("id,uid,nickname,title,content,ip,param,create_time") ->field("id,uid,nickname,title,content,ip,param,create_time")
->order('create_time desc') ->order('create_time desc')
->where($where) ->where($where)
->paginate($rows, false, ['query' => $param]); ->paginate($rows, false, ['query' => $param]);
$content->toArray(); $content->toArray();
foreach ($content as $k => $v) { foreach ($content as $k => $v) {
$data = $v; $data = $v;
$param_array = json_decode($v['param'], true); $param_array = json_decode($v['param'], true);
$name = ''; $name = '';
if (!empty($param_array['name'])) { if (!empty($param_array['name'])) {
$name = ''. $param_array['name']; $name = '' . $param_array['name'];
} }
if (!empty($param_array['title'])) { if (!empty($param_array['title'])) {
$name = ''. $param_array['title']; $name = '' . $param_array['title'];
} }
$data['content'] = $v['content'] . $name; $data['content'] = $v['content'] . $name;
$data['times'] = time_trans($v['create_time']); $data['times'] = time_trans($v['create_time']);
$content->offsetSet($k, $data); $content->offsetSet($k, $data);
} }
return table_assign(1, '', $content); return table_assign(1, '', $content);
} } else {
else{
return view(); return view();
} }
} }
} }

View File

@ -1,4 +1,10 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
declare (strict_types = 1); declare (strict_types = 1);
namespace app\admin\middleware; namespace app\admin\middleware;
@ -16,30 +22,28 @@ class Auth
$pathInfo = str_replace('.' . $request->ext(), '', $request->pathInfo()); $pathInfo = str_replace('.' . $request->ext(), '', $request->pathInfo());
$action = explode('/', $pathInfo)[0]; $action = explode('/', $pathInfo)[0];
//var_dump($pathInfo);exit; //var_dump($pathInfo);exit;
if($pathInfo == '' || $action == '' ){ if ($pathInfo == '' || $action == '') {
redirect('/admin/index/index.html')->send(); redirect('/admin/index/index.html')->send();
exit; exit;
} }
//验证用户登录 //验证用户登录
if ($action !== 'login') { if ($action !== 'login') {
$session_admin = get_config('app.session_admin'); $session_admin = get_config('app.session_admin');
if (!Session::has($session_admin)) { if (!Session::has($session_admin)) {
if($request->isAjax()){ if ($request->isAjax()) {
return to_assign(404, '请先登录'); return to_assign(404, '请先登录');
} } else {
else{ redirect('/admin/login/index.html')->send();
redirect('/admin/login/index.html')->send(); exit;
exit; }
}
} }
// 验证用户访问权限 // 验证用户访问权限
if ($action !== 'index' && $action !== 'api') { if ($action !== 'index' && $action !== 'api') {
if (!$this->checkAuth($controller, $pathInfo, $action, Session::get($session_admin)['id'])) { if (!$this->checkAuth($controller, $pathInfo, $action, Session::get($session_admin)['id'])) {
if($request->isAjax()){ if ($request->isAjax()) {
return to_assign(202, '你没有权限,请联系超级管理员!'); return to_assign(202, '你没有权限,请联系超级管理员!');
} } else {
else{
echo '<div style="text-align:center;color:red;margin-top:20%;">您没有权限,请联系超级管理员</div>';exit; echo '<div style="text-align:center;color:red;margin-top:20%;">您没有权限,请联系超级管理员</div>';exit;
} }
} }
@ -59,49 +63,48 @@ class Auth
protected function checkAuth($controller, $pathInfo, $action, $uid) protected function checkAuth($controller, $pathInfo, $action, $uid)
{ {
//Cache::delete('RulesSrc' . $uid); //Cache::delete('RulesSrc' . $uid);
if (!Cache::get('RulesSrc' . $uid) || !Cache::get('RulesSrc0')) { if (!Cache::get('RulesSrc' . $uid) || !Cache::get('RulesSrc0')) {
//用户所在权限组及所拥有的权限 //用户所在权限组及所拥有的权限
// 执行查询 // 执行查询
$user_groups = Db::name('admin_group_access') $user_groups = Db::name('AdminGroupAccess')
->alias('a') ->alias('a')
->join("admin_group g", "a.group_id=g.id", 'LEFT') ->join("AdminGroup g", "a.group_id=g.id", 'LEFT')
->where("a.uid='{$uid}' and g.status='1'") ->where("a.uid='{$uid}' and g.status='1'")
->select() ->select()
->toArray(); ->toArray();
$groups = $user_groups ?: []; $groups = $user_groups ?: [];
$ids = []; //保存用户所属用户组设置的所有权限规则id $ids = []; //保存用户所属用户组设置的所有权限规则id
foreach ($groups as $g) { foreach ($groups as $g) {
$ids = array_merge($ids, explode(',', trim($g['rules'], ','))); $ids = array_merge($ids, explode(',', trim($g['rules'], ',')));
} }
$ids = array_unique($ids); $ids = array_unique($ids);
//读取所有权限规则 //读取所有权限规则
$rules_all = Db::name('admin_rule')->field('src')->select(); $rules_all = Db::name('AdminRule')->field('src')->select();
//读取用户组所有权限规则 //读取用户组所有权限规则
$rules = Db::name('admin_rule')->where('id', 'in', $ids)->field('src')->select(); $rules = Db::name('AdminRule')->where('id', 'in', $ids)->field('src')->select();
//循环规则,判断结果。 //循环规则,判断结果。
$auth_list_all = []; $auth_list_all = [];
$auth_list = []; $auth_list = [];
foreach ($rules_all as $rule_all) { foreach ($rules_all as $rule_all) {
$auth_list_all[] = strtolower($rule_all['src']); $auth_list_all[] = strtolower($rule_all['src']);
} }
foreach ($rules as $rule) { foreach ($rules as $rule) {
$auth_list[] = strtolower($rule['src']); $auth_list[] = strtolower($rule['src']);
} }
//规则列表结果保存到Cache //规则列表结果保存到Cache
Cache::tag('adminRules')->set('RulesSrc0', $auth_list_all, 36000); Cache::tag('adminRules')->set('RulesSrc0', $auth_list_all, 36000);
Cache::tag('adminRules')->set('RulesSrc' . $uid, $auth_list, 36000); Cache::tag('adminRules')->set('RulesSrc' . $uid, $auth_list, 36000);
} else { } else {
$auth_list_all = Cache::get('RulesSrc0'); $auth_list_all = Cache::get('RulesSrc0');
$auth_list = Cache::get('RulesSrc' . $uid); $auth_list = Cache::get('RulesSrc' . $uid);
} }
$pathUrl = $controller . '/' . $pathInfo; $pathUrl = $controller . '/' . $pathInfo;
if (!in_array($pathUrl , $auth_list) && !in_array($pathUrl, $auth_list_all)) { if (!in_array($pathUrl, $auth_list) && !in_array($pathUrl, $auth_list_all)) {
return false; return false;
} } else {
else{ return true;
return true; }
}
} }
} }

View File

@ -1,4 +1,10 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
declare (strict_types = 1); declare (strict_types = 1);
namespace app\admin\middleware; namespace app\admin\middleware;

View File

@ -1,7 +1,15 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
namespace app\admin\model; namespace app\admin\model;
use think\Model; use think\Model;
class Admin extends Model class Admin extends Model
{ {
} }

View File

@ -1,7 +1,15 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
namespace app\admin\model; namespace app\admin\model;
use think\Model; use think\Model;
class AdminGroup extends Model class AdminGroup extends Model
{ {
} }

View File

@ -1,4 +1,10 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
declare (strict_types = 1); declare (strict_types = 1);
namespace app\admin\model; namespace app\admin\model;
@ -20,7 +26,7 @@ class AdminLog extends Model
} }
$where['status'] = 1; $where['status'] = 1;
$rows = empty($param['limit']) ? get_config('app.pages') : $param['limit']; $rows = empty($param['limit']) ? get_config('app.pages') : $param['limit'];
$content = \think\facade\Db::name('admin_log') $content = \think\facade\Db::name('AdminLog')
->field("id,uid,nickname,type,title,module,controller,function,param,content,create_time") ->field("id,uid,nickname,type,title,module,controller,function,param,content,create_time")
->order('create_time desc') ->order('create_time desc')
->where($where) ->where($where)
@ -32,10 +38,10 @@ class AdminLog extends Model
$param_array = json_decode($v['param'], true); $param_array = json_decode($v['param'], true);
$name = ''; $name = '';
if (!empty($param_array['name'])) { if (!empty($param_array['name'])) {
$name = ''. $param_array['name']; $name = '' . $param_array['name'];
} }
if (!empty($param_array['title'])) { if (!empty($param_array['title'])) {
$name = ''. $param_array['title']; $name = '' . $param_array['title'];
} }
$data['content'] = $v['content'] . $name; $data['content'] = $v['content'] . $name;
$data['times'] = time_trans($v['create_time']); $data['times'] = time_trans($v['create_time']);

View File

@ -1,44 +1,53 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
namespace app\admin\model; namespace app\admin\model;
use think\Model;
use app\admin\model\Keywords; use app\admin\model\Keywords;
use think\Model;
class Article extends Model class Article extends Model
{ {
// 获取文章详情 // 获取文章详情
public function detail($id) public function detail($id)
{ {
$article = \think\facade\Db::name('article')->where(['id' => $id])->find(); $article = \think\facade\Db::name('Article')->where(['id' => $id])->find();
if (empty($article)) { if (empty($article)) {
return $this->error('文章不存在'); return $this->error('文章不存在');
} }
$keywrod_array = \think\facade\Db::name('ArticleKeywords') $keywrod_array = \think\facade\Db::name('ArticleKeywords')
->field('i.aid,i.keywords_id,k.title') ->field('i.aid,i.keywords_id,k.title')
->alias('i') ->alias('i')
->join('keywords k', 'k.id = i.keywords_id', 'LEFT') ->join('keywords k', 'k.id = i.keywords_id', 'LEFT')
->order('i.create_time asc') ->order('i.create_time asc')
->where(array('i.aid' => $id, 'k.status' => 1)) ->where(array('i.aid' => $id, 'k.status' => 1))
->select()->toArray(); ->select()->toArray();
$article['keyword_ids'] = implode(",", array_column($keywrod_array, 'keywords_id')); $article['keyword_ids'] = implode(",", array_column($keywrod_array, 'keywords_id'));
$article['keyword_names'] = implode(',', array_column($keywrod_array, 'title')); $article['keyword_names'] = implode(',', array_column($keywrod_array, 'title'));
return $article; return $article;
} }
//插入关键字 //插入关键字
public function insertKeyword($keywordArray=[],$aid){ public function insertKeyword($keywordArray = [], $aid)
$insert = []; {
$time = time(); $insert = [];
foreach ($keywordArray as $key => $value) { $time = time();
if (!$value) { foreach ($keywordArray as $key => $value) {
continue; if (!$value) {
} continue;
$keywords_id = (new Keywords())->increase($value); }
$insert[] = ['aid' => $aid , $keywords_id = (new Keywords())->increase($value);
'keywords_id' => $keywords_id, $insert[] = ['aid' => $aid,
'create_time' => $time 'keywords_id' => $keywords_id,
]; 'create_time' => $time,
} ];
$res = \think\facade\Db::name('ArticleKeywords')->strict(false)->field(true)->insertAll($insert); }
return $res; $res = \think\facade\Db::name('ArticleKeywords')->strict(false)->field(true)->insertAll($insert);
} return $res;
} }
}

View File

@ -1,7 +1,15 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
namespace app\admin\model; namespace app\admin\model;
use think\Model; use think\Model;
class ArticleCate extends Model class ArticleCate extends Model
{ {
} }

View File

@ -1,18 +1,26 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
namespace app\admin\model; namespace app\admin\model;
use think\Model; use think\Model;
// 关键字模型 // 关键字模型
class Keywords extends Model class Keywords extends Model
{ {
// 关联关键字 // 关联关键字
public function increase($keywords) public function increase($keywords)
{ {
$is_exist = $this->where('title',$keywords)->find(); $is_exist = $this->where('title', $keywords)->find();
if( $is_exist ){ if ($is_exist) {
$res = $is_exist['id']; $res = $is_exist['id'];
}else{ } else {
$res = $this->strict(false)->field(true)->insertGetId(['title' => $keywords,'create_time' => time()]); $res = $this->strict(false)->field(true)->insertGetId(['title' => $keywords, 'create_time' => time()]);
} }
return $res; return $res;
} }
} }

View File

@ -1,7 +1,15 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
namespace app\admin\model; namespace app\admin\model;
use think\Model; use think\Model;
class Nav extends Model class Nav extends Model
{ {
} }

View File

@ -1,7 +1,15 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
namespace app\admin\model; namespace app\admin\model;
use think\Model; use think\Model;
class NavInfo extends Model class NavInfo extends Model
{ {
} }

View File

@ -1,4 +1,9 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
namespace app\admin\model; namespace app\admin\model;

View File

@ -1,11 +1,17 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
namespace app\admin\model; namespace app\admin\model;
use think\Model; use think\Model;
class SitemapCate extends Model class SitemapCate extends Model
{ {
/** /**
* 关联网站地图 * 关联网站地图
* @param [type] $value [description] * @param [type] $value [description]
*/ */
@ -14,4 +20,4 @@ class SitemapCate extends Model
return $this->hasMany('sitemap', 'sitemap_cate_id', 'id')->order('sort desc, id desc'); return $this->hasMany('sitemap', 'sitemap_cate_id', 'id')->order('sort desc, id desc');
} }
} }

View File

@ -1,7 +1,15 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
namespace app\admin\model; namespace app\admin\model;
use think\Model; use think\Model;
class Slide extends Model class Slide extends Model
{ {
} }

View File

@ -1,7 +1,15 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
namespace app\admin\model; namespace app\admin\model;
use think\Model; use think\Model;
class SlideInfo extends Model class SlideInfo extends Model
{ {
} }

View File

@ -1,8 +1,15 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
namespace app\admin\model; namespace app\admin\model;
use think\Model; use think\Model;
class User extends Model class User extends Model
{ {
} }

View File

@ -1,48 +1,55 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
namespace app\admin\validate; namespace app\admin\validate;
use think\Validate; use think\Validate;
class AdminCheck extends Validate class AdminCheck extends Validate
{ {
protected $rule = [ protected $rule = [
'username' => 'require|unique:admin', 'username' => 'require|unique:admin',
'pwd' => 'require|confirm', 'pwd' => 'require|confirm',
'mobile' => 'require', 'mobile' => 'require',
'nickname' => 'require', 'nickname' => 'require',
'group_id' => 'require', 'group_id' => 'require',
'id' => 'require', 'id' => 'require',
'status' => 'require|checkStatus:-1,1', 'status' => 'require|checkStatus:-1,1',
'old_pwd' => 'require|different:pwd', 'old_pwd' => 'require|different:pwd',
]; ];
protected $message = [ protected $message = [
'username.require' => '登录账号不能为空', 'username.require' => '登录账号不能为空',
'pwd.require' => '密码不能为空', 'pwd.require' => '密码不能为空',
'pwd.confirm' => '两次密码不一致', 'pwd.confirm' => '两次密码不一致',
'username.unique' => '同样的登录账号已经存在!', 'username.unique' => '同样的登录账号已经存在!',
'mobile.require' => '手机不能为空', 'mobile.require' => '手机不能为空',
'nickname.require' => '昵称不能为空', 'nickname.require' => '昵称不能为空',
'group_id.require' => '至少要选择一个用户角色', 'group_id.require' => '至少要选择一个用户角色',
'id.require' => '缺少更新条件', 'id.require' => '缺少更新条件',
'status.require' => '状态为必选', 'status.require' => '状态为必选',
'status.checkStatus' => '系统所有者不能被禁用!', 'status.checkStatus' => '系统所有者不能被禁用!',
'old_pwd.require' => '请提供旧密码', 'old_pwd.require' => '请提供旧密码',
'old_pwd.different' => '新密码不能和旧密码一样', 'old_pwd.different' => '新密码不能和旧密码一样',
]; ];
protected $scene = [ protected $scene = [
'add' => ['phone', 'nickname', 'group_id', 'pwd', 'username', 'status'], 'add' => ['phone', 'nickname', 'group_id', 'pwd', 'username', 'status'],
'edit' => ['phone', 'nickname', 'group_id', 'id', 'username.unique', 'status'], 'edit' => ['phone', 'nickname', 'group_id', 'id', 'username.unique', 'status'],
'editPersonal' => ['phone', 'nickname'], 'editPersonal' => ['phone', 'nickname'],
'editpwd' => ['old_pwd', 'pwd'], 'editpwd' => ['old_pwd', 'pwd'],
]; ];
// 自定义验证规则 // 自定义验证规则
protected function checkStatus($value,$rule,$data) protected function checkStatus($value, $rule, $data)
{ {
if($value == -1 and $data['id'] == 1) { if ($value == -1 and $data['id'] == 1) {
return $rule == false; return $rule == false;
} }
return $rule == true; return $rule == true;
} }
} }

View File

@ -1,26 +1,33 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
namespace app\admin\validate; namespace app\admin\validate;
use think\Validate; use think\Validate;
class ArticleCateCheck extends Validate class ArticleCateCheck extends Validate
{ {
protected $rule = [ protected $rule = [
'title' => 'require|unique:article_cate', 'title' => 'require|unique:article_cate',
'pid' => 'require', 'pid' => 'require',
'id' => 'require', 'id' => 'require',
'field' => 'require', 'field' => 'require',
]; ];
protected $message = [ protected $message = [
'title.require' => '名称不能为空', 'title.require' => '名称不能为空',
'pid.require' => '父级分类为必选', 'pid.require' => '父级分类为必选',
'title.unique' => '同样的记录已经存在', 'title.unique' => '同样的记录已经存在',
'id.require' => '缺少更新条件', 'id.require' => '缺少更新条件',
'filed.require' => '缺少要更新的字段名', 'filed.require' => '缺少要更新的字段名',
]; ];
protected $scene = [ protected $scene = [
'add' => ['title', 'pid'], 'add' => ['title', 'pid'],
'edit' => ['id', 'field','title.unique'], 'edit' => ['id', 'field', 'title.unique'],
]; ];
} }

View File

@ -1,27 +1,34 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
namespace app\admin\validate; namespace app\admin\validate;
use think\Validate; use think\Validate;
class ArticleCheck extends Validate class ArticleCheck extends Validate
{ {
protected $rule = [ protected $rule = [
'title' => 'require|unique:article', 'title' => 'require|unique:article',
'content' => 'require', 'content' => 'require',
'id' => 'require', 'id' => 'require',
'article_cate_id' => 'require', 'article_cate_id' => 'require',
'status' => 'require' 'status' => 'require',
]; ];
protected $message = [ protected $message = [
'title.require' => '标题不能为空', 'title.require' => '标题不能为空',
'article_cate_id.require' => '所属分类为必选', 'article_cate_id.require' => '所属分类为必选',
'title.unique' => '同样的记录已经存在!', 'title.unique' => '同样的记录已经存在!',
'id.require' => '缺少更新条件', 'id.require' => '缺少更新条件',
'status.require' => '状态为必选', 'status.require' => '状态为必选',
]; ];
protected $scene = [ protected $scene = [
'add' => ['title', 'thumb', 'article_cate_id', 'content', 'status'], 'add' => ['title', 'thumb', 'article_cate_id', 'content', 'status'],
'edit' => ['title', 'thumb', 'article_cate_id', 'content', 'id', 'status'], 'edit' => ['title', 'thumb', 'article_cate_id', 'content', 'id', 'status'],
]; ];
} }

View File

@ -1,18 +1,25 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
namespace app\admin\validate; namespace app\admin\validate;
use think\Validate; use think\Validate;
class ConfCheck extends Validate class ConfCheck extends Validate
{ {
protected $rule = [ protected $rule = [
'title' => 'require|unique:config', 'title' => 'require|unique:config',
'name' => 'require|unique:config' 'name' => 'require|unique:config',
]; ];
protected $message = [ protected $message = [
'title.require' => '配置名称不能为空', 'title.require' => '配置名称不能为空',
'name.require' => '配置标识不能为空', 'name.require' => '配置标识不能为空',
'title.unique' => '同样的配置名称已经存在', 'title.unique' => '同样的配置名称已经存在',
'name.unique' => '同样的配置标识已经存在' 'name.unique' => '同样的配置标识已经存在',
]; ];
} }

View File

@ -1,34 +1,41 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
namespace app\admin\validate; namespace app\admin\validate;
use think\Validate; use think\Validate;
class GroupCheck extends Validate class GroupCheck extends Validate
{ {
protected $rule = [ protected $rule = [
'title' => 'require|unique:admin_group', 'title' => 'require|unique:admin_group',
'id' => 'require', 'id' => 'require',
'status' => 'require|checkStatus:-1,1' 'status' => 'require|checkStatus:-1,1',
]; ];
protected $message = [ protected $message = [
'title.require' => '名称不能为空', 'title.require' => '名称不能为空',
'title.unique' => '同样的记录已经存在!', 'title.unique' => '同样的记录已经存在!',
'id.require' => '缺少更新条件', 'id.require' => '缺少更新条件',
'status.require' => '状态为必选', 'status.require' => '状态为必选',
'status.checkStatus' => '系统所有者组不能被禁用!', 'status.checkStatus' => '系统所有者组不能被禁用!',
]; ];
protected $scene = [ protected $scene = [
'add' => ['title','status'], 'add' => ['title', 'status'],
'edit' => ['id', 'title', 'status'], 'edit' => ['id', 'title', 'status'],
]; ];
// 自定义验证规则 // 自定义验证规则
protected function checkStatus($value,$rule,$data) protected function checkStatus($value, $rule, $data)
{ {
if($value == -1 and $data['id'] == 1) { if ($value == -1 and $data['id'] == 1) {
return $rule == false; return $rule == false;
} }
return $rule == true; return $rule == true;
} }
} }

View File

@ -1,40 +1,47 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
namespace app\admin\validate; namespace app\admin\validate;
use think\Validate;
use think\facade\Db; use think\facade\Db;
use think\Validate;
class KeywordsCheck extends Validate class KeywordsCheck extends Validate
{ {
protected $rule = [ protected $rule = [
'title' => 'require|checkUnique', 'title' => 'require|checkUnique',
'id' => 'require', 'id' => 'require',
]; ];
protected $message = [ protected $message = [
'title.require' => '关键字名称不能为空', 'title.require' => '关键字名称不能为空',
'title.checkUnique' => '同样的关键字名称已经存在', 'title.checkUnique' => '同样的关键字名称已经存在',
'id.require' => '缺少更新条件', 'id.require' => '缺少更新条件',
]; ];
protected $scene = [ protected $scene = [
'add' => ['title'], 'add' => ['title'],
'edit' => ['id','title'] 'edit' => ['id', 'title'],
]; ];
//自定义验证规则 //自定义验证规则
protected function checkUnique($value,$rule,$data) protected function checkUnique($value, $rule, $data)
{ {
if(isset($data['id'])){ if (isset($data['id'])) {
$unique =Db::name('keywords')->where([['id','<>',$data['id']],['title','=',$value],['status','>=',0]])->value('id'); $unique = Db::name('keywords')->where([['id', '<>', $data['id']], ['title', '=', $value], ['status', '>=', 0]])->value('id');
}else{ } else {
$unique =Db::name('keywords')->where([['title','=',$value],['status','>=',0]])->value('id'); $unique = Db::name('keywords')->where([['title', '=', $value], ['status', '>=', 0]])->value('id');
} }
if($unique) { if ($unique) {
return false; return false;
}else{ } else {
return true; return true;
} }
} }
} }

View File

@ -1,26 +1,33 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
namespace app\admin\validate; namespace app\admin\validate;
use think\Validate; use think\Validate;
class MenuCheck extends Validate class MenuCheck extends Validate
{ {
protected $rule = [ protected $rule = [
'title' => 'require|unique:admin_menu', 'title' => 'require|unique:admin_menu',
'pid' => 'require', 'pid' => 'require',
'id' => 'require', 'id' => 'require',
'field' => 'require', 'field' => 'require',
]; ];
protected $message = [ protected $message = [
'title.require' => '菜单名称不能为空', 'title.require' => '菜单名称不能为空',
'pid.require' => '父级菜单为必选', 'pid.require' => '父级菜单为必选',
'title.unique' => '同样的菜单名称已经存在', 'title.unique' => '同样的菜单名称已经存在',
'id.require' => '缺少更新条件', 'id.require' => '缺少更新条件',
'filed.require' => '缺少要更新的字段名', 'filed.require' => '缺少要更新的字段名',
]; ];
protected $scene = [ protected $scene = [
'add' => ['title', 'pid'], 'add' => ['title', 'pid'],
'edit' => ['id', 'field', 'title.unique'], 'edit' => ['id', 'field', 'title.unique'],
]; ];
} }

View File

@ -1,4 +1,10 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
namespace app\admin\validate; namespace app\admin\validate;
use think\Validate; use think\Validate;
@ -10,7 +16,7 @@ class NavCheck extends Validate
'name' => 'require|unique:nav', 'name' => 'require|unique:nav',
'id' => 'require', 'id' => 'require',
'status' => 'require', 'status' => 'require',
'slide_id' => 'require' 'slide_id' => 'require',
]; ];
protected $message = [ protected $message = [

View File

@ -1,4 +1,10 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
namespace app\admin\validate; namespace app\admin\validate;
use think\Validate; use think\Validate;

View File

@ -1,21 +1,29 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
namespace app\admin\validate; namespace app\admin\validate;
use think\Validate; use think\Validate;
class SitemapCateCheck extends Validate class SitemapCateCheck extends Validate
{ {
protected $rule = [ protected $rule = [
'name' => 'require|unique:sitemap_cate', 'name' => 'require|unique:sitemap_cate',
'id' => 'require', 'id' => 'require',
]; ];
protected $message = [ protected $message = [
'name.require' => '名称不能为空', 'name.require' => '名称不能为空',
'name.unique' => '同样的记录已经存在!', 'name.unique' => '同样的记录已经存在!',
'id.require' => '缺少更新条件', 'id.require' => '缺少更新条件',
]; ];
protected $scene = [ protected $scene = [
'add' => ['name'], 'add' => ['name'],
'edit' => ['id', 'name'], 'edit' => ['id', 'name'],
]; ];
} }

View File

@ -1,31 +1,38 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
namespace app\admin\validate; namespace app\admin\validate;
use think\Validate; use think\Validate;
class SitemapCheck extends Validate class SitemapCheck extends Validate
{ {
protected $rule = [ protected $rule = [
'name' => 'require', 'name' => 'require',
'id' => 'require', 'id' => 'require',
'sitemap_cate_id' => 'require', 'sitemap_cate_id' => 'require',
'pc_img' => 'require', 'pc_img' => 'require',
'pc_src' => 'require', 'pc_src' => 'require',
'mobile_img' => 'require', 'mobile_img' => 'require',
'mobile_src' => 'require', 'mobile_src' => 'require',
]; ];
protected $message = [ protected $message = [
'name.require' => '名称不能为空', 'name.require' => '名称不能为空',
'pc_img.require' => 'pc端图片不能为空', 'pc_img.require' => 'pc端图片不能为空',
'pc_src.require' => 'pc端链接不能为空', 'pc_src.require' => 'pc端链接不能为空',
'mobile_img.require' => '移动端图片不能为空', 'mobile_img.require' => '移动端图片不能为空',
'mobile_src.require' => '移动端链接不能为空', 'mobile_src.require' => '移动端链接不能为空',
'id.require' => '缺少更新条件', 'id.require' => '缺少更新条件',
'sitemap_cate_id.require' => '缺少更新条件', 'sitemap_cate_id.require' => '缺少更新条件',
]; ];
protected $scene = [ protected $scene = [
'add' => ['sitemap_cate_id', 'name', 'pc_src', 'mobile_src'], 'add' => ['sitemap_cate_id', 'name', 'pc_src', 'mobile_src'],
'edit' => ['id', 'name', 'pc_src', 'mobile_src'], 'edit' => ['id', 'name', 'pc_src', 'mobile_src'],
]; ];
} }

View File

@ -1,33 +1,40 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
namespace app\admin\validate; namespace app\admin\validate;
use think\Validate; use think\Validate;
class SlideCheck extends Validate class SlideCheck extends Validate
{ {
protected $rule = [ protected $rule = [
'title' => 'require|unique:slide', 'title' => 'require|unique:slide',
'name' => 'require|unique:slide', 'name' => 'require|unique:slide',
'id' => 'require', 'id' => 'require',
'status' => 'require', 'status' => 'require',
'img' => 'require', 'img' => 'require',
'slide_id' => 'require', 'slide_id' => 'require',
]; ];
protected $message = [ protected $message = [
'title.require' => '标题不能为空', 'title.require' => '标题不能为空',
'name.require' => '标识不能为空', 'name.require' => '标识不能为空',
'title.unique' => '同样的记录已经存在!', 'title.unique' => '同样的记录已经存在!',
'name.unique' => '同样的记录已经存在!', 'name.unique' => '同样的记录已经存在!',
'id.require' => '缺少更新条件', 'id.require' => '缺少更新条件',
'status.require' => '状态为必选', 'status.require' => '状态为必选',
'img.require' => '请上传图片', 'img.require' => '请上传图片',
'slide_id.require' => '缺少换灯组ID', 'slide_id.require' => '缺少换灯组ID',
]; ];
protected $scene = [ protected $scene = [
'add' => ['title', 'name', 'status'], 'add' => ['title', 'name', 'status'],
'edit' => ['id', 'title', 'name', 'status'], 'edit' => ['id', 'title', 'name', 'status'],
'addInfo' => ['title', 'img', 'status', 'slide_id'], 'addInfo' => ['title', 'img', 'status', 'slide_id'],
'editInfo' => ['title', 'img', 'status', 'id'], 'editInfo' => ['title', 'img', 'status', 'id'],
]; ];
} }

View File

@ -1,19 +1,26 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
namespace app\admin\validate; namespace app\admin\validate;
use think\Validate; use think\Validate;
class UserCheck extends Validate class UserCheck extends Validate
{ {
protected $rule = [ protected $rule = [
'username' => 'require', 'username' => 'require',
'password' => 'require', 'password' => 'require',
'captcha' => 'require|captcha', 'captcha' => 'require|captcha',
]; ];
protected $message = [ protected $message = [
'username.require' => '用户名不能为空', 'username.require' => '用户名不能为空',
'password.require' => '密码不能为空', 'password.require' => '密码不能为空',
'captcha.require' => '验证码不能为空', 'captcha.require' => '验证码不能为空',
'captcha.captcha' => '验证码不正确', 'captcha.captcha' => '验证码不正确',
]; ];
} }

View File

@ -1,4 +1,9 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
// 应用公共文件 // 应用公共文件
use think\facade\Cache; use think\facade\Cache;
use think\facade\Config; use think\facade\Config;

View File

@ -1,4 +1,10 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
declare (strict_types = 1); declare (strict_types = 1);
namespace app\home; namespace app\home;
@ -66,7 +72,7 @@ abstract class BaseController
$info = $this->checkLogin(); $info = $this->checkLogin();
if ($info) { if ($info) {
$login_class = 'nav-login nav-logined'; $login_class = 'nav-login nav-logined';
$login_top = '<a class="nav-img" href="/home/user/index"><img src="' . $info['headimgurl'] . '" alt="' . $info['username'] . '" />'.$info['username'].'</a>'; $login_top = '<a class="nav-img" href="/home/user/index"><img src="' . $info['headimgurl'] . '" alt="' . $info['username'] . '" />' . $info['username'] . '</a>';
$params['isLogin'] = 1; $params['isLogin'] = 1;
$params['uid'] = $info['id']; $params['uid'] = $info['id'];
$params['nickname'] = $info['nickname']; $params['nickname'] = $info['nickname'];

View File

@ -1,4 +1,10 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
// 这是home公共文件 // 这是home公共文件
//获取当前登录用户的信息 //获取当前登录用户的信息
function get_login_user($key = "") function get_login_user($key = "")
@ -25,7 +31,7 @@ function get_login_user($key = "")
* @param int $param_id 操作类型 * @param int $param_id 操作类型
* @param array $param 提交的参数 * @param array $param 提交的参数
*/ */
function add_user_log($type, $param_str='', $param_id = 0, $param = []) function add_user_log($type, $param_str = '', $param_id = 0, $param = [])
{ {
$request = request(); $request = request();
switch ($type) { switch ($type) {
@ -47,18 +53,18 @@ function add_user_log($type, $param_str='', $param_id = 0, $param = [])
case 'delete': case 'delete':
$title = '删除'; $title = '删除';
break; break;
case 'join': case 'join':
$title = '报名'; $title = '报名';
break; break;
case 'sign': case 'sign':
$title = '签到'; $title = '签到';
break; break;
case 'play': case 'play':
$title = '播放'; $title = '播放';
break; break;
case 'order': case 'order':
$title = '下单'; $title = '下单';
break; break;
case 'pay': case 'pay':
$title = '支付'; $title = '支付';
break; break;
@ -68,29 +74,28 @@ function add_user_log($type, $param_str='', $param_id = 0, $param = [])
} }
if ($type == 'login') { if ($type == 'login') {
$login_user = \think\facade\Db::name('user')->where(array('id' => $param_id))->find(); $login_user = \think\facade\Db::name('user')->where(array('id' => $param_id))->find();
if($login_user['nickname'] == ''){ if ($login_user['nickname'] == '') {
$login_user['nickname'] = $login_user['name']; $login_user['nickname'] = $login_user['name'];
} }
if($login_user['nickname'] == ''){ if ($login_user['nickname'] == '') {
$login_user['nickname'] = $login_user['username']; $login_user['nickname'] = $login_user['username'];
} }
} else { } else {
$login_user = get_login_user(); $login_user = get_login_user();
if (empty($login_user)) { if (empty($login_user)) {
$login_user=[]; $login_user = [];
$login_user['id'] = 0; $login_user['id'] = 0;
$login_user['nickname'] = '游客'; $login_user['nickname'] = '游客';
} else {
if ($login_user['nickname'] == '') {
$login_user['nickname'] = $login_user['username'];
}
} }
else{
if($login_user['nickname'] == ''){
$login_user['nickname'] = $login_user['username'];
}
}
} }
$content = $login_user['nickname'] . '在' . date('Y-m-d H:i:s') . '执行了' . $title . '操作'; $content = $login_user['nickname'] . '在' . date('Y-m-d H:i:s') . '执行了' . $title . '操作';
if($param_str!=''){ if ($param_str != '') {
$content = $login_user['nickname'] . '在' . date('Y-m-d H:i:s') . $title .'了' . $param_str; $content = $login_user['nickname'] . '在' . date('Y-m-d H:i:s') . $title . '了' . $param_str;
} }
$data = []; $data = [];
$data['uid'] = $login_user['id']; $data['uid'] = $login_user['id'];
$data['nickname'] = $login_user['nickname']; $data['nickname'] = $login_user['nickname'];

View File

@ -1,17 +1,22 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
declare (strict_types = 1); declare (strict_types = 1);
namespace app\home\controller; namespace app\home\controller;
use app\home\BaseController; use app\home\BaseController;
use think\facade\Db;
use think\facade\View; use think\facade\View;
class Index extends BaseController class Index extends BaseController
{ {
public function index() public function index()
{ {
add_user_log('view','首页'); add_user_log('view', '首页');
return View(); return View();
} }

View File

@ -1,4 +1,10 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
declare (strict_types = 1); declare (strict_types = 1);
namespace app\home\controller; namespace app\home\controller;
@ -14,10 +20,10 @@ class Login
//登录 //登录
public function index() public function index()
{ {
if(!empty(get_login_user('id'))){ if (!empty(get_login_user('id'))) {
redirect('/home/user/index')->send(); redirect('/home/user/index')->send();
} }
add_user_log('view','登录页面'); add_user_log('view', '登录页面');
return View(); return View();
} }
//错误页面 //错误页面
@ -36,7 +42,7 @@ class Login
return to_assign(0, $e->getError()); return to_assign(0, $e->getError());
} }
$user = Db::name('user')->where(['username' => $param['username']])->find(); $user = Db::name('User')->where(['username' => $param['username']])->find();
if (empty($user)) { if (empty($user)) {
return to_assign(0, '用户名或密码错误'); return to_assign(0, '用户名或密码错误');
} }
@ -64,7 +70,7 @@ class Login
$token = make_token(); $token = make_token();
set_cache($token, $userInfo, 7200); set_cache($token, $userInfo, 7200);
$userInfo['token'] = $token; $userInfo['token'] = $token;
add_user_log('login','',$user['id']); add_user_log('login', '', $user['id']);
return to_assign(1, '登录成功', $userInfo); return to_assign(1, '登录成功', $userInfo);
} }
@ -97,17 +103,17 @@ class Login
$Avatar->Free(); $Avatar->Free();
return $path; return $path;
} }
//注册 //注册
public function reg() public function reg()
{ {
if(!empty(get_login_user('id'))){ if (!empty(get_login_user('id'))) {
redirect('/home/user/index')->send(); redirect('/home/user/index')->send();
} }
add_user_log('view','注册页面'); add_user_log('view', '注册页面');
return View(); return View();
} }
//提交注册 //提交注册
public function reg_submit() public function reg_submit()
{ {
$param = get_params(); $param = get_params();
@ -118,7 +124,7 @@ class Login
return to_assign(0, $e->getError()); return to_assign(0, $e->getError());
} }
$user = Db::name('user')->where(['username' => $param['username']])->find(); $user = Db::name('User')->where(['username' => $param['username']])->find();
if (!empty($user)) { if (!empty($user)) {
return to_assign(0, '该账户已经存在'); return to_assign(0, '该账户已经存在');
} }
@ -130,7 +136,7 @@ class Login
$char = mb_substr($param['username'], 0, 1, 'utf-8'); $char = mb_substr($param['username'], 0, 1, 'utf-8');
$param['headimgurl'] = $this->to_avatars($char); $param['headimgurl'] = $this->to_avatars($char);
$uid = Db::name('User')->strict(false)->field(true)->insertGetId($param); $uid = Db::name('User')->strict(false)->field(true)->insertGetId($param);
add_user_log('reg','',$uid); add_user_log('reg', '', $uid);
return to_assign(1, '注册成功,请登录', $uid); return to_assign(1, '注册成功,请登录', $uid);
} }

View File

@ -1,4 +1,10 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
declare (strict_types = 1); declare (strict_types = 1);
namespace app\home\controller; namespace app\home\controller;
@ -11,35 +17,34 @@ class User extends BaseController
{ {
public function index() public function index()
{ {
$uid=get_login_user('id'); $uid = get_login_user('id');
$userInfo = Db::name('User')->where(['id' => $uid])->find(); $userInfo = Db::name('User')->where(['id' => $uid])->find();
$userInfo['showname'] = empty($userInfo['nickname']) ? $userInfo['username'] : $userInfo['nickname']; $userInfo['showname'] = empty($userInfo['nickname']) ? $userInfo['username'] : $userInfo['nickname'];
$userInfo['sex'] = ($userInfo['sex'] == 1) ? '男' : '女'; $userInfo['sex'] = ($userInfo['sex'] == 1) ? '男' : '女';
add_user_log('view','个人中心'); add_user_log('view', '个人中心');
View::assign('userInfo', $userInfo); View::assign('userInfo', $userInfo);
return view(); return view();
} }
public function info_edit() public function info_edit()
{ {
$uid=get_login_user('id'); $uid = get_login_user('id');
$userInfo = Db::name('User')->where(['id' => $uid])->find(); $userInfo = Db::name('User')->where(['id' => $uid])->find();
add_user_log('view','个人信息'); add_user_log('view', '个人信息');
View::assign('userInfo', $userInfo); View::assign('userInfo', $userInfo);
return view(); return view();
} }
public function edit_submit() public function edit_submit()
{ {
$param =get_params(); $param = get_params();
$param['birthday'] = strtotime($param['birthday']); $param['birthday'] = strtotime($param['birthday']);
$res = Db::name('User')->where(['id' => $param['id']])->strict(false)->field(true)->update($param); $res = Db::name('User')->where(['id' => $param['id']])->strict(false)->field(true)->update($param);
if($res!== false){ if ($res !== false) {
add_user_log('edit','个人信息',$param['id'],$param); add_user_log('edit', '个人信息', $param['id'], $param);
to_assign(1,'操作成功'); to_assign(1, '操作成功');
} } else {
else{ to_assign(0, '操作失败');
to_assign(0,'操作失败');
} }
} }

View File

@ -1,10 +1,16 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
// 这是系统自动生成的middleware定义文件 // 这是系统自动生成的middleware定义文件
return [ return [
//开启session中间件 //开启session中间件
//'think\middleware\SessionInit', //'think\middleware\SessionInit',
//验证勾股cms是否完成安装 //验证勾股cms是否完成安装
\app\home\middleware\Install::class, \app\home\middleware\Install::class,
//验证操作 //验证操作
\app\home\middleware\Auth::class, \app\home\middleware\Auth::class,
]; ];

View File

@ -1,4 +1,10 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
declare (strict_types = 1); declare (strict_types = 1);
namespace app\home\middleware; namespace app\home\middleware;

View File

@ -1,4 +1,10 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
declare (strict_types = 1); declare (strict_types = 1);
namespace app\home\middleware; namespace app\home\middleware;
@ -8,9 +14,9 @@ class Install
public function handle($request, \Closure $next) public function handle($request, \Closure $next)
{ {
if (!is_installed()) { if (!is_installed()) {
return $request->isAjax()?to_assign(0,'请先完成系统安装引导'):redirect((string)url('/install/index')); return $request->isAjax() ? to_assign(0, '请先完成系统安装引导') : redirect((string) url('/install/index'));
} }
return $next($request); return $next($request);
} }
} }

View File

@ -1,29 +1,36 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
namespace app\home\validate; namespace app\home\validate;
use think\Validate; use think\Validate;
class UserCheck extends Validate class UserCheck extends Validate
{ {
protected $rule = [ protected $rule = [
'username' => 'require', 'username' => 'require',
'password' => 'require', 'password' => 'require',
'pwd' =>'require|min:6|confirm', 'pwd' => 'require|min:6|confirm',
'captcha' => 'require|captcha', 'captcha' => 'require|captcha',
]; ];
protected $message = [ protected $message = [
'username.require' => '账号不能为空', 'username.require' => '账号不能为空',
'password.require' => '密码不能为空', 'password.require' => '密码不能为空',
'pwd.require' => '密码不能为空', 'pwd.require' => '密码不能为空',
'pwd.min' => '密码必须6位以上', 'pwd.min' => '密码必须6位以上',
'pwd.confirm' => '两次密码不一致',//confirm自动相互验证 'pwd.confirm' => '两次密码不一致', //confirm自动相互验证
'captcha.require' => '验证码不能为空', 'captcha.require' => '验证码不能为空',
'captcha.captcha' => '验证码不正确', 'captcha.captcha' => '验证码不正确',
]; ];
protected $scene = [ protected $scene = [
'login' => ['username', 'password','captcha'], 'login' => ['username', 'password', 'captcha'],
'reg' => ['username', 'pwd','captcha'] 'reg' => ['username', 'pwd', 'captcha'],
]; ];
} }

View File

@ -1,4 +1,10 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
declare (strict_types = 1); declare (strict_types = 1);
namespace app\install\controller; namespace app\install\controller;
@ -9,7 +15,8 @@ use think\facade\View;
class Index class Index
{ {
function __construct(){ public function __construct()
{
// 检测是否安装过 // 检测是否安装过
if (is_installed()) { if (is_installed()) {
echo '你已经安装过勾股cms系统!'; echo '你已经安装过勾股cms系统!';
@ -63,60 +70,60 @@ class Index
public function install() public function install()
{ {
$data = get_params(); $data = get_params();
try { try {
validate(InstallCheck::class)->check($data); validate(InstallCheck::class)->check($data);
} catch (ValidateException $e) { } catch (ValidateException $e) {
// 验证失败 输出错误信息 // 验证失败 输出错误信息
return to_assign(0, $e->getError()); return to_assign(0, $e->getError());
} }
// 连接数据库 // 连接数据库
$link = @new mysqli("{$data['DB_HOST']}:{$data['DB_PORT']}", $data['DB_USER'], $data['DB_PWD']); $link = @new mysqli("{$data['DB_HOST']}:{$data['DB_PORT']}", $data['DB_USER'], $data['DB_PWD']);
// 获取错误信息 // 获取错误信息
$error = $link->connect_error; $error = $link->connect_error;
if (!is_null($error)) { if (!is_null($error)) {
// 转义防止和alert中的引号冲突 // 转义防止和alert中的引号冲突
$error = addslashes($error); $error = addslashes($error);
return to_assign(0, '数据库链接失败:' . $error);die; return to_assign(0, '数据库链接失败:' . $error);die;
} }
// 设置字符集 // 设置字符集
$link->query("SET NAMES 'utf8'"); $link->query("SET NAMES 'utf8'");
if ($link->server_info < 5.0) { if ($link->server_info < 5.0) {
return to_assign(0, '请将您的mysql升级到5.0以上');die; return to_assign(0, '请将您的mysql升级到5.0以上');die;
} }
// 创建数据库并选中 // 创建数据库并选中
if (!$link->select_db($data['DB_NAME'])) { if (!$link->select_db($data['DB_NAME'])) {
return to_assign(0, '未找到数据库'.$data['DB_NAME'].',请先自行创建数据库');die; return to_assign(0, '未找到数据库' . $data['DB_NAME'] . ',请先自行创建数据库');die;
} }
$link->select_db($data['DB_NAME']); $link->select_db($data['DB_NAME']);
// 导入sql数据并创建表 // 导入sql数据并创建表
$fqcms_sql = file_get_contents(CMS_ROOT . '/app/install/data/gougucms.sql'); $fqcms_sql = file_get_contents(CMS_ROOT . '/app/install/data/gougucms.sql');
$sql_array = preg_split("/;[\r\n]+/", str_replace("cms_", $data['DB_PREFIX'], $fqcms_sql)); $sql_array = preg_split("/;[\r\n]+/", str_replace("cms_", $data['DB_PREFIX'], $fqcms_sql));
foreach ($sql_array as $k => $v) { foreach ($sql_array as $k => $v) {
if (!empty($v)) { if (!empty($v)) {
$link->query($v); $link->query($v);
}
} }
}
//插入管理员信息 //插入管理员信息
$username = get_params('username'); $username = get_params('username');
$password = get_params('password'); $password = get_params('password');
$nickname = '超级管理员'; $nickname = '超级管理员';
$thumb = '/static/admin/images/icon.png'; $thumb = '/static/admin/images/icon.png';
$salt = set_salt(20); $salt = set_salt(20);
$password = set_password($password, $salt); $password = set_password($password, $salt);
$create_time = time(); $create_time = time();
$update_time = time(); $update_time = time();
$create_admin_sql = "INSERT INTO " . $data['DB_PREFIX'] . "admin " . $create_admin_sql = "INSERT INTO " . $data['DB_PREFIX'] . "admin " .
"(username,pwd, nickname,thumb,salt,create_time,update_time) " "(username,pwd, nickname,thumb,salt,create_time,update_time) "
. "VALUES " . "VALUES "
. "('$username','$password','$nickname','$thumb','$salt','$create_time','$update_time')"; . "('$username','$password','$nickname','$thumb','$salt','$create_time','$update_time')";
if (!$link->query($create_admin_sql)) { if (!$link->query($create_admin_sql)) {
return to_assign(0, '创建管理员信息失败'); return to_assign(0, '创建管理员信息失败');
} }
$link->close(); $link->close();
$db_str = "<?php $db_str = "<?php
return [ return [
// 默认使用的数据库连接配置 // 默认使用的数据库连接配置
'default' => 'mysql', 'default' => 'mysql',
@ -147,8 +154,8 @@ return [
'prefix' => '{$data['DB_PREFIX']}', 'prefix' => '{$data['DB_PREFIX']}',
// 数据库连接参数 // 数据库连接参数
'params' => [], 'params' => [],
// 数据库编码默认采用utf8 // 数据库编码默认采用utf8mb4
'charset' => 'utf8', 'charset' => 'utf8mb4',
// 数据库调试模式 // 数据库调试模式
'debug' => false, 'debug' => false,
// 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器) // 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)
@ -171,13 +178,13 @@ return [
], ],
];"; ];";
// 创建数据库配置文件 // 创建数据库配置文件
if (false == file_put_contents(CMS_ROOT . "config/database.php", $db_str)) { if (false == file_put_contents(CMS_ROOT . "config/database.php", $db_str)) {
return to_assign(0, '创建数据库配置文件失败,请检查目录权限'); return to_assign(0, '创建数据库配置文件失败,请检查目录权限');
} }
if (false == file_put_contents(CMS_ROOT . "config/install.lock", '勾股CMS安装鉴定文件请勿删除此次安装时间为' . date('Y-m-d H:i:s', time()))) { if (false == file_put_contents(CMS_ROOT . "config/install.lock", '勾股CMS安装鉴定文件请勿删除此次安装时间为' . date('Y-m-d H:i:s', time()))) {
return to_assign(0, '创建安装鉴定文件失败,请检查目录权限'); return to_assign(0, '创建安装鉴定文件失败,请检查目录权限');
} }
return to_assign(); return to_assign();
} }
} }

View File

@ -1,6 +1,9 @@
/* /**
Date: 2021-01-08 18:00:00 * @copyright Copyright (c) 2021
*/ * @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
SET FOREIGN_KEY_CHECKS=0; SET FOREIGN_KEY_CHECKS=0;

View File

@ -1,36 +1,43 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
namespace app\install\validate; namespace app\install\validate;
use think\Validate; use think\Validate;
class InstallCheck extends Validate class InstallCheck extends Validate
{ {
protected $rule = [ protected $rule = [
'DB_TYPE' => 'require|eq:mysql', 'DB_TYPE' => 'require|eq:mysql',
'DB_HOST' => 'require', 'DB_HOST' => 'require',
'DB_PORT' => 'require', 'DB_PORT' => 'require',
'DB_USER' => 'require', 'DB_USER' => 'require',
'DB_PWD' => 'require', 'DB_PWD' => 'require',
'DB_NAME' => 'require', 'DB_NAME' => 'require',
'DB_PREFIX' => 'require', 'DB_PREFIX' => 'require',
'username' => 'require', 'username' => 'require',
'password' => 'require|confirm', 'password' => 'require|confirm',
]; ];
protected $message = [ protected $message = [
'DB_TYPE.require' => '数据库类型不能为空', 'DB_TYPE.require' => '数据库类型不能为空',
'DB_TYPE.eq' => '数据库类型固定为mysql', 'DB_TYPE.eq' => '数据库类型固定为mysql',
'DB_HOST.require' => '数据库地址不能为空', 'DB_HOST.require' => '数据库地址不能为空',
'DB_PORT.require' => '数据库端口不能为空', 'DB_PORT.require' => '数据库端口不能为空',
'DB_USER.require' => '数据库用户名不能为空', 'DB_USER.require' => '数据库用户名不能为空',
'DB_PWD.require' => '数据库密码不能为空', 'DB_PWD.require' => '数据库密码不能为空',
'DB_NAME.require' => '数据库名字不能为空', 'DB_NAME.require' => '数据库名字不能为空',
'DB_PREFIX.require' => '表前缀不能为空', 'DB_PREFIX.require' => '表前缀不能为空',
'username.require' => '管理员账户不能为空', 'username.require' => '管理员账户不能为空',
'password.require' => '密码不能为空', 'password.require' => '密码不能为空',
'password.confirm' => '两次密码不一致', 'password.confirm' => '两次密码不一致',
]; ];
protected $scene = [ protected $scene = [
]; ];
} }

View File

@ -1,4 +1,9 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
// 全局中间件定义文件 // 全局中间件定义文件
return [ return [
// 全局请求缓存 // 全局请求缓存
@ -6,5 +11,5 @@ return [
// 多语言加载 // 多语言加载
// \think\middleware\LoadLangPack::class, // \think\middleware\LoadLangPack::class,
// Session初始化 // Session初始化
'think\middleware\SessionInit' 'think\middleware\SessionInit',
]; ];

View File

@ -1,4 +1,10 @@
<?php <?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
// [ 应用入口文件 ] // [ 应用入口文件 ]
namespace think; namespace think;
@ -7,7 +13,7 @@ require __DIR__ . '/../vendor/autoload.php';
// 定义当前版本号 // 定义当前版本号
define('CMS_VERSION','1.0.0'); define('CMS_VERSION','1.0.0');
// 定义Layui版本号 // 定义ThinkPHP版本号
define('TP_VERSION','6.0.5'); define('TP_VERSION','6.0.5');
// 定义Layui版本号 // 定义Layui版本号