Compare commits

...

60 Commits

Author SHA1 Message Date
yumo 213c12910b 忽略主题目录避免提交 2024-02-19 21:24:21 +08:00
yumo 730b767ca4 完善评论和默认跳转 2024-02-19 20:59:53 +08:00
yumo 000c41d475 留言增加验证码判断
page统一页面输出seo
2024-02-19 00:58:07 +08:00
yumo b2cfc6d619 修正评论,评论增加验证码验证判断
修正文章获取评论数问题
修正标签获取文章列表偶发的报错问题
文章详情增加评论数
文章列表页数据获取和详情页数据获取问题修正
2024-02-19 00:20:38 +08:00
yumo b02b2f39a8 更改文章主题等获取机制为直接主题目录对应文件夹获取
修正主题切换不生效的问题
一些细节优化
增加模板用户信息获取函数
2024-02-06 15:51:33 +08:00
yumo d69b4983cb Merge branch 'master' into dev 2024-02-02 11:51:02 +08:00
yumo 871ffd9c4d xx 2024-02-02 11:50:40 +08:00
yumo f490f83c61 更新composer
page页面编辑器统一
2024-02-01 08:35:36 +08:00
yumo ffdb3c7228 Merge branch 'master' into dev 2024-01-17 20:51:28 +08:00
yumo 86a604ed57 xxx 2024-01-17 20:51:00 +08:00
yumo c4dcf4eac5 test push 2024-01-17 20:49:03 +08:00
yumo a353e056be 完善接口数据 2023-12-31 18:15:31 +08:00
yumo cc15e83a70 更新编辑器为wangEditer
主题支持代码高亮和复制
2023-12-31 12:59:27 +08:00
yumo 759fe7fa06 完善ape拓展标签 2023-12-19 16:34:54 +08:00
yumo 16cfdb89b6 添加文档信息和修复主页的bug 2023-12-14 18:30:24 +08:00
yumo e25404ee2f 完善逻辑条正 2023-12-14 16:32:56 +08:00
yumo 1ba8bfcc4f 修复修改轮播广告的bug 2023-12-08 09:43:10 +08:00
yumo 1d35393458 修这个图片筛选 2023-12-07 15:27:56 +08:00
yumo bc41c2430d 更新主题读取和支持page单独访问 2023-12-07 15:19:36 +08:00
yumo 8e185ca1a9 更新compoaser 2023-12-07 14:34:24 +08:00
yumo 54934945cc 完善 php 7.1 ~ 8.2 的兼容性 2023-12-07 14:21:09 +08:00
yumo b8002d2503 完善代码 2023-11-15 20:23:39 +08:00
yumo a96251cab4 优化代码写入规范 2023-11-14 20:08:29 +08:00
yumo 2b524af313 优化系统的书写规范 2023-11-14 11:27:55 +08:00
yumo 362ea75c7a 完善8.2的兼容性 2023-11-14 10:00:49 +08:00
yumo deacf4b4b0 更改母驴规则 2023-11-13 20:11:44 +08:00
yumo 469e711f28 修复8.2的兼容性 2023-11-13 19:59:55 +08:00
yumo 7cb03187a9 修复主题样式 2023-10-22 22:16:38 +08:00
yumo a4d1cc7231 修正上一篇下一篇查询逻辑 2023-10-18 19:56:19 +08:00
yumo a284ab8feb 更新composer包 2023-09-27 17:45:31 +08:00
yumo 903c3a4494 fix api报错 2023-09-27 17:44:06 +08:00
yumo b660d17646 修正 2023-09-09 22:10:25 +08:00
yumo 098c3d972f 完善格式、优化一些验证方法 2023-09-09 22:10:07 +08:00
yumo df52b6c56c 规范化model去除无用的方法 2023-09-08 23:13:42 +08:00
yumo 6baa1003bf 优化代码 2023-08-01 20:03:46 +08:00
yumo fd2b715e0c 更改 帐号 为账号 2023-07-28 14:26:18 +08:00
yumo f74d500055 sitemap的实现 2023-07-24 14:43:08 +08:00
yumo ad077237cd 修正路由错误 2023-07-18 16:50:36 +08:00
yumo a2ad5cb8bd 修正主题url构建 2023-07-17 19:21:35 +08:00
yumo 5e1ab5e0ff 修正生成sitemap 2023-07-17 19:05:31 +08:00
yumo d7df6222fe 修正更新自动时间戳 2023-07-17 18:45:41 +08:00
yumo d7a0de97db 修正生成sitemap 2023-07-17 17:58:36 +08:00
yumo 8226105ac9 更新伪静态 2023-07-17 17:45:59 +08:00
yumo d8e693aa52 更新调整 2023-07-17 17:37:25 +08:00
yumo 042bd8eab4 生成map地图支持别名访问 2023-05-05 14:21:19 +08:00
yumo ccec51ad88 更新vendor
修正生成sitemap
2023-05-05 11:10:57 +08:00
yumo c7deee9ae9 修正生成网站地图 2023-05-03 22:08:39 +08:00
yumo 8c2affa887 主页侧边增加最新文章板块 2023-04-06 09:54:59 +08:00
yumo cc6e85f5e0 注册逻辑 2023-03-27 20:06:21 +08:00
yumo 4f23f09295 完善部分代码 2023-03-21 20:05:29 +08:00
muzi 61967bb957 修正网站关闭和log统计的问题 2023-03-06 00:14:19 +08:00
muzi db94bd17b0 修正主题获取swipe的bug
修正初始化
2023-02-11 16:22:36 +08:00
yumo 57e2893451 修正懒加载 2023-02-07 14:12:57 +08:00
yumo 2a730880f3 修正返回和黑暗模式下面友连颜色不一致的bug 2023-02-06 00:04:13 +08:00
muzi_ys 5e21c27aae 修正报错
增加统计代码支持
2022-11-30 11:41:51 +08:00
muzi_ys 172cfd9f3f 增加邮件类
增加社会化登录
修正tp6.1文件上传问题
2022-11-27 00:12:31 +08:00
muzi_ys e3cf01d01f 更新tp版本,完善文件上传 2022-11-06 00:04:07 +08:00
muzi_ys 79c3c9ec53 去掉配置文件只能设置4页的限制 2022-11-02 00:02:30 +08:00
muzi_ys 3b715806fd 更新vendor和首台首页 2022-08-28 22:21:06 +08:00
muzi_ys ecdf50d355
add default pipeline template yaml 2022-08-08 02:43:33 +00:00
922 changed files with 63999 additions and 12855 deletions

6
.gitignore vendored
View File

@ -5,6 +5,10 @@
/.env
/runtime
/composer.lock
/public/upload/image
/public/storage/*
/public/upload/*
/public/template/*
!/public/template/default
/public/install/install.lock
/.constant

View File

@ -0,0 +1,51 @@
version: '1.0'
name: branch-pipeline
displayName: BranchPipeline
stages:
- stage:
name: compile
displayName: 编译
steps:
- step: build@php
name: build_php
displayName: PHP 构建
# 支持5.0、7.0、7.1、7.2、7.3、7.4、8.0、8.1八个版本
phpVersion: 8.0
# 构建命令
commands:
- php --version
# 非必填字段开启后表示将构建产物暂存但不会上传到制品库中7天后自动清除
artifacts:
# 构建产物名字作为产物的唯一标识可向下传递支持自定义默认为BUILD_ARTIFACT。在下游可以通过${BUILD_ARTIFACT}方式引用来获取构建物地址
- name: BUILD_ARTIFACT
# 构建产物获取路径,是指代码编译完毕之后构建物的所在路径
path:
- ./
- step: publish@general_artifacts
name: publish_general_artifacts
displayName: 上传制品
# 上游构建任务定义的产物名默认BUILD_ARTIFACT
dependArtifact: BUILD_ARTIFACT
# 上传到制品库时的制品命名默认output
artifactName: output
dependsOn: build_php
- stage:
name: release
displayName: 发布
steps:
- step: publish@release_artifacts
name: publish_release_artifacts
displayName: '发布'
# 上游上传制品任务的产出
dependArtifact: output
# 发布制品版本号
version: '1.0.0.0'
# 是否开启版本号自增,默认开启
autoIncrement: true
triggers:
push:
branches:
exclude:
- master
include:
- .*

View File

@ -0,0 +1,49 @@
version: '1.0'
name: master-pipeline
displayName: MasterPipeline
stages:
- stage:
name: compile
displayName: 编译
steps:
- step: build@php
name: build_php
displayName: PHP 构建
# 支持5.0、7.0、7.1、7.2、7.3、7.4、8.0、8.1八个版本
phpVersion: 8.0
# 构建命令
commands:
- php --version
# 非必填字段开启后表示将构建产物暂存但不会上传到制品库中7天后自动清除
artifacts:
# 构建产物名字作为产物的唯一标识可向下传递支持自定义默认为BUILD_ARTIFACT。在下游可以通过${BUILD_ARTIFACT}方式引用来获取构建物地址
- name: BUILD_ARTIFACT
# 构建产物获取路径,是指代码编译完毕之后构建物的所在路径
path:
- ./
- step: publish@general_artifacts
name: publish_general_artifacts
displayName: 上传制品
# 上游构建任务定义的产物名默认BUILD_ARTIFACT
dependArtifact: BUILD_ARTIFACT
# 上传到制品库时的制品命名默认output
artifactName: output
dependsOn: build_php
- stage:
name: release
displayName: 发布
steps:
- step: publish@release_artifacts
name: publish_release_artifacts
displayName: '发布'
# 上游上传制品任务的产出
dependArtifact: output
# 发布制品版本号
version: '1.0.0.0'
# 是否开启版本号自增,默认开启
autoIncrement: true
triggers:
push:
branches:
include:
- master

36
.workflow/pr-pipeline.yml Normal file
View File

@ -0,0 +1,36 @@
version: '1.0'
name: pr-pipeline
displayName: PRPipeline
stages:
- stage:
name: compile
displayName: 编译
steps:
- step: build@php
name: build_php
displayName: PHP 构建
# 支持5.0、7.0、7.1、7.2、7.3、7.4、8.0、8.1八个版本
phpVersion: 8.0
# 构建命令
commands:
- php --version
# 非必填字段开启后表示将构建产物暂存但不会上传到制品库中7天后自动清除
artifacts:
# 构建产物名字作为产物的唯一标识可向下传递支持自定义默认为BUILD_ARTIFACT。在下游可以通过${BUILD_ARTIFACT}方式引用来获取构建物地址
- name: BUILD_ARTIFACT
# 构建产物获取路径,是指代码编译完毕之后构建物的所在路径
path:
- ./
- step: publish@general_artifacts
name: publish_general_artifacts
displayName: 上传制品
# 上游构建任务定义的产物名默认BUILD_ARTIFACT
dependArtifact: BUILD_ARTIFACT
# 上传到制品库时的制品命名默认output
artifactName: output
dependsOn: build_php
triggers:
pr:
branches:
include:
- master

View File

@ -23,56 +23,47 @@ ape_blog源码云博客
/public
/runtime
3. 安装好拓展
4. 配置好域名,在浏览器里打开域名,根据安装向导进行安装
5. 后台登录 http://域名/admin
4. 设置伪静态
5. 配置好域名,在浏览器里打开域名,根据安装向导进行安装
6. 后台登录 http://域名/admin
## 手动安装
## 设置伪静态
1.创建数据库,倒入数据库文件
```ngnixconf
数据库文件目录/public/install/learn.sql
location /admin/ {
index index.php index.html index.htm;
if (!-e $request_filename){
#后台文件更名了需要在这里修改
rewrite ^/admin/(.*)$ /admin.php?s=$1;
}
}
2.修改数据库连接文件
配置文件路径/.env
location /api/ {
index index.php index.html index.htm;
if (!-e $request_filename){
rewrite ^/api/(.*)$ /api.php?s=$1;
}
}
~~~
APP_DEBUG = true
location / {
index index.php index.html index.htm;
#如果请求既不是一个文件,也不是一个目录,则执行一下重写规则
if (!-e $request_filename){
#地址作为将参数rewrite到index.php上。
rewrite ^/(.*)$ /index.php?s=$1 last;
#若是子目录则使用下面这句将subdir改成目录名称即可。
#rewrite ^/subdir/(.*)$ /subdir/index.php?s=$1;
}
}
[APP]
DEFAULT_TIMEZONE = Asia/Shanghai
```
[DATABASE]
TYPE = mysql
HOSTNAME = 127.0.0.1 #数据库连接地址
DATABASE = test #数据库名称
USERNAME = username #数据库登录账号
PASSWORD = password #数据库登录密码
HOSTPORT = 3306 #数据库端口
CHARSET = utf8
DEBUG = true
[LANG]
default_lang = zh-cn
~~~
3.安装php拓展
~~~
redis
~~~
4.创建目录并修改目录权限linux系统777
~~~
mkdir public/upload
mkdir runtime
chmod -R 777 public/storage
chmod -R 777 runtime
~~~
5.后台登录:
http://域名/admin
默认账号admin 密码123456
```apacheconf
RewriteRule '^/admin/(.*)$$' /admin.php?s=$1; [L]
RewriteRule '^/api/(.*)$$' /api.php?s=$1; [L]
RewriteRule '^/(.*)$$' /index.php?s=$1 [L]
```
## 文档
@ -111,3 +102,5 @@ All rights reserved。
## 支持项目
💕 无需捐赠,如果觉得项目不错,或者已经在使用了,希望你可以去 Github 或者 Gitee 帮我们点个 ⭐ Star这将是对我们极大的鼓励与支持。

6
TODO.md Normal file
View File

@ -0,0 +1,6 @@
待完成功能列表
- 完善euapi主题
- 完善获取分类,分类下的数量列表,现在只实现当前分类,没有包含下钻分类
- 完善用户发帖数量等字段
- doc文档上输出
- 文章分类id和别名拆分,直接使用别名

View File

@ -104,7 +104,7 @@ abstract class BaseController
* 操作成功跳转的快捷方法
* @access protected
* @param mixed $msg 提示信息
* @param string $url 跳转的URL地址
* @param string|null $url 跳转的URL地址
* @param mixed $data 返回的数据
* @param integer $wait 跳转等待时间
* @param array $header 发送的Header信息
@ -116,10 +116,12 @@ abstract class BaseController
$url = $_SERVER["HTTP_REFERER"];
} elseif ($url) {
$url = (strpos($url, '://') || 0 === strpos($url, '/')) ? $url : app('route')->buildUrl($url);
}else{
$url = app('route')->buildUrl("/");
}
$result = [
'code' => 1,
'code' => 0,
'msg' => $msg,
'data' => $data,
'url' => $url,
@ -132,7 +134,6 @@ abstract class BaseController
} else if ($type == 'json') {
$response = json($result);
}
throw new HttpResponseException($response);
}
@ -153,22 +154,19 @@ abstract class BaseController
} elseif ($url) {
$url = (strpos($url, '://') || 0 === strpos($url, '/')) ? $url : $this->app->route->buildUrl($url);
}
$result = [
'code' => 0,
'code' => 1,
'msg' => $msg,
'data' => $data,
'url' => $url,
'wait' => $wait,
];
$type = $this->getResponseType();
if ($type == 'html') {
$response = view(config('app.dispatch_success_tmpl'), $result);
} else if ($type == 'json') {
$response = json($result);
}
throw new HttpResponseException($response);
}

View File

@ -1,8 +1,5 @@
<?php
use think\facade\Cache;
if (!function_exists('un_camelize')) {
/**
* 驼峰法转下划线
@ -10,7 +7,7 @@ if (!function_exists('un_camelize')) {
* @param string $separator
* @return string
*/
function un_camelize($camelCaps, $separator = '_')
function un_camelize($camelCaps, string $separator = '_'): string
{
return strtolower(preg_replace('/([a-z])([A-Z])/', "$1" . $separator . "$2", $camelCaps));
}
@ -19,24 +16,25 @@ if (!function_exists('un_camelize')) {
if (!function_exists('auth_is_exit')) {
/**
* 判断授权信息是否存在
* @param int $adminId
* @return bool
* @throws \Psr\SimpleCache\InvalidArgumentException
*/
function auth_is_exit(int $adminId): bool
{
return Cache::store('redis')->has('store_' . $adminId);
return cache('store_' . $adminId);
}
}
if (!function_exists('remove_cache')) {
/**
* 判断授权信息是否存在
* 删除缓存文件
* @param string $path
* @return bool
* @throws \Psr\SimpleCache\InvalidArgumentException
*/
function remove_cache(string $path): bool
{
$res = true;
$res = false;
if (is_dir($path)) {
if ($handle = opendir($path)) {
while (false !== ($item = readdir($handle))) {
@ -56,6 +54,7 @@ if (!function_exists('remove_cache')) {
if (!function_exists('to_int_array')) {
/**
* 字符串数组转int数组
* @param array $str
* @return array
*/
function to_int_array(array $str): array
@ -79,9 +78,10 @@ if (!function_exists('tag_options')) {
}
}
if (!function_exists('type_options')) {
/**
* 获取form标签
* 获取form type类型
* @return array
*/
function type_options(): array
@ -100,6 +100,7 @@ if (!function_exists('type_options')) {
}
}
if (!function_exists('get_dir')) {
/**
* 获取文件目录列表,该方法返回数组
@ -110,7 +111,7 @@ if (!function_exists('get_dir')) {
function get_dir($dir)
{
$dirArray[] = NULL;
if (false != ($handle = opendir($dir))) {
if (($handle = opendir($dir))) {
$i = 0;
while (false !== ($file = readdir($handle))) {
//去掉"“.”、“..”以及带“.xxx”后缀的文件
@ -127,8 +128,15 @@ if (!function_exists('get_dir')) {
}
if (!function_exists('get_tree_list')) {
/*无限分类*/
function get_tree_list(&$list, $pid = 0, $level = 0, $html = '|—')
/**
* 无限分类
* @param $list
* @param $pid
* @param $level
* @param $html
* @return array
*/
function get_tree_list(&$list, $pid = 0, $level = 0, $html = '|—'): array
{
static $tree = array();
foreach ($list as $v) {
@ -144,11 +152,14 @@ if (!function_exists('get_tree_list')) {
}
if (!function_exists('get_theme_list')) {
function get_theme_list($type = ''):array
if (!function_exists('get_template_list')) {
function get_template_list($type = ''): array
{
$themeList = [];
$themeDir = public_path('template') . system_config('web_template') . '/pc/' .$type;
$themeDir = public_path('template') . system_config('web_template') . '/pc/' . $type;
if (!file_exists($themeDir)){
return [];
}
if ($dh = opendir($themeDir)) {
while (($file = readdir($dh)) !== false) {
@ -158,6 +169,55 @@ if (!function_exists('get_theme_list')) {
}
closedir($dh);
}
return $themeList;
return $themeList;
}
}
}
/**
* 获取去除html去除空格去除软回车,软换行,转换过后的字符串
* @param string $str
* @return string
*/
if (!function_exists('html2mb_str')) {
function html2mb_str($str): string
{
return trim(strip_tags(str_replace(["\n", "\t", "\r", " ", "&nbsp;"], '', htmlspecialchars_decode($str))));
}
}
/**
* 获取本季度 time
* @param int|string $time
* @param string $ceil
* @return array
*/
if (!function_exists('get_quarter')) {
function get_quarter($time = '', $ceil = 0): array
{
if ($ceil != 0)
$season = ceil(date('n') / 3) - $ceil;
else
$season = ceil(date('n') / 3);
$firstDay = date('Y-m-01', mktime(0, 0, 0, ($season - 1) * 3 + 1, 1, date('Y')));
$lastDay = date('Y-m-t', mktime(0, 0, 0, $season * 3, 1, date('Y')));
return array($firstDay, $lastDay);
}
}
/**
* 横线
* @param int $num
* @return string
*/
if (!function_exists('cross')) {
function cross(int $num = 0): string
{
$str = "";
if ($num == 1) $str .= "|--";
elseif ($num > 1) for ($i = 0; $i < $num; $i++)
if ($i == 0) $str .= "|--";
else $str .= "--";
return $str . " ";
}
}

View File

@ -4,8 +4,8 @@ namespace app\admin\controller;
use app\admin\extend\FormBuilder as Form;
use app\admin\extend\Util as Util;
use app\common\model\Admin as aModel;
use app\common\model\AdminRole as rModel;
use app\admin\model\Admin as aModel;
use app\admin\model\AdminRole as rModel;
use app\common\model\User as userModel;
use app\Request;
use FormBuilder\Exception\FormBuilderException;
@ -17,6 +17,7 @@ use think\Exception;
use think\facade\Db;
use think\Facade\Log;
use think\facade\Route as Url;
use think\Response;
/**
* 账号管理
@ -30,7 +31,7 @@ class Admin extends AuthController
* @return string
* @throws \Exception
*/
public function index()
public function index(): string
{
$this->assign("auths", rModel::getAuthLst());
return $this->fetch();
@ -39,12 +40,12 @@ class Admin extends AuthController
/**
* 账号列表
* @param Request $request
* @return
* @return mixed
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function lst(Request $request)
public function lst(Request $request): Response
{
$where = Util::postMore([
['username', ''],
@ -55,22 +56,25 @@ class Admin extends AuthController
['status', ''],
['page', 1],
['limit', 20],
]);
],$request);
return app("json")->layui(aModel::systemPage($where));
}
/**
* 添加账号
* @param Request $request
* @return string
* @throws DataNotFoundException
* @throws DbException
* @throws FormBuilderException
* @throws ModelNotFoundException
* @throws \Exception
*/
public function add(Request $request)
public function add(): string
{
$form = array();
$form[] = Elm::input('username', '登录账号')->col(10);
$form[] = Elm::input('nickname', '昵称')->col(10);
$form[] = Elm::frameImage('avatar', '头像', Url::buildUrl('admin/image/index', array('fodder' => 'avatar', 'limit' => 1)))->icon("ios-image")->width('96%')->height('440px')->col(10);
$form[] = Elm::frameImage('avatar', '头像', Url::buildUrl('/admin/image/index', array('fodder' => 'avatar', 'limit' => 1)))->icon("ios-image")->width('96%')->height('440px')->col(10);
$form[] = Elm::password('password', '密码')->col(10);
$form[] = Elm::input('realname', '真实姓名')->col(10);
$form[] = Elm::select('role_id', '角色')->options(function () {
@ -84,28 +88,33 @@ class Admin extends AuthController
$form[] = Elm::input('tel', '电话')->col(10);
$form[] = Elm::email('email', '邮箱')->col(10);
$form[] = Elm::radio('status', '状态', 1)->options([['label' => '启用', 'value' => 1], ['label' => '冻结', 'value' => 0]])->col(10);
$form = Form::make_post_form($form, url('save')->build());
$form = Form::make_post_form($form, url('/admin/admin/save')->build());
$this->assign(compact('form'));
return $this->fetch("public/form-builder");
}
/**
* 修改账号
* @param string $id
* @return string
* @throws DataNotFoundException
* @throws DbException
* @throws FormBuilderException
* @throws ModelNotFoundException
* @throws \Exception
*/
public function edit($id = "")
public function edit(string $id = ""): string
{
if (!$id) return app("json")->fail("账号id不能为空");
$ainfo = aModel::get($id);
if (!$ainfo) return app("json")->fail("没有该账号");
$info = (new \app\admin\model\Admin)->find($id);
if (!$info) return app("json")->fail("没有该账号");
$form = array();
$form[] = Elm::input('username', '登录账号', $ainfo['username'])->col(10);
$form[] = Elm::input('nickname', '昵称', $ainfo['nickname'])->col(10);
$form[] = Elm::frameImage('avatar', '头像', Url::buildUrl('admin/image/index', array('fodder' => 'avatar', 'limit' => 1)), $ainfo['avatar'])->icon("ios-image")->width('96%')->height('440px')->col(10);
$form[] = Elm::password('password', '密码', $ainfo['password'])->col(10);
$form[] = Elm::input('realname', '真实姓名', $ainfo['realname'])->col(10);
$form[] = Elm::select('role_id', '角色', $ainfo['role_id'])->options(function () {
$form[] = Elm::input('username', '登录账号', $info['username'])->col(10);
$form[] = Elm::input('nickname', '昵称', $info['nickname'])->col(10);
$form[] = Elm::frameImage('avatar', '头像', Url::buildUrl('/admin/image/index', array('fodder' => 'avatar', 'limit' => 1)), $info['avatar'])->icon("ios-image")->width('96%')->height('440px')->col(10);
$form[] = Elm::password('password', '密码', $info['password'])->col(10);
$form[] = Elm::input('realname', '真实姓名', $info['realname'])->col(10);
$form[] = Elm::select('role_id', '角色', $info['role_id'])->options(function () {
$list = rModel::getAuthLst();
$menus = [];
foreach ($list as $menu) {
@ -113,10 +122,10 @@ class Admin extends AuthController
}
return $menus;
})->col(10);
$form[] = Elm::input('tel', '电话', $ainfo['tel'])->col(10);
$form[] = Elm::email('email', '邮箱', $ainfo['email'])->col(10);
$form[] = Elm::radio('status', '状态', $ainfo['status'])->options([['label' => '启用', 'value' => 1], ['label' => '冻结', 'value' => 0]])->col(10);
$form = Form::make_post_form($form, url('save', ['id' => $id])->build());
$form[] = Elm::input('tel', '电话', $info['tel'])->col(10);
$form[] = Elm::email('email', '邮箱', $info['email'])->col(10);
$form[] = Elm::radio('status', '状态', $info['status'])->options([['label' => '启用', 'value' => 1], ['label' => '冻结', 'value' => 0]])->col(10);
$form = Form::make_post_form($form, url('/admin/admin/save', ['id' => $id])->build());
$this->assign(compact('form'));
return $this->fetch("public/form-builder");
}
@ -126,7 +135,7 @@ class Admin extends AuthController
* @param string $id
* @return mixed
*/
public function save($id = "")
public function save(string $id = "")
{
$data = Util::postMore([
['username', ''],
@ -158,12 +167,12 @@ class Admin extends AuthController
$data['create_user'] = $this->adminId;
$data['create_time'] = time();
$data['update_time'] = time();
aModel::insert($data);
aModel::create($data);
//添加前台用户
$userId = userModel::addAdminUser($data);
$res = aModel::update(['uid' => $userId], ['id' => $id]);
} else {
$userInfo = aModel::get($id);
$userInfo = aModel::find($id);
if ($userInfo['password'] != $data['password']) $data['password'] = md5(md5($data['password']));
$data['update_user'] = $this->adminId;
$data['update_time'] = time();
@ -184,11 +193,10 @@ class Admin extends AuthController
/**
* 修改密码
* @param Request $request
* @return string
* @throws \Exception
*/
public function pwd(Request $request)
public function pwd(): string
{
return $this->fetch();
}
@ -203,9 +211,9 @@ class Admin extends AuthController
$data = Util::postMore([
['oldpwd', ''],
['newpwd', '']
]);
],$request);
if ($data['oldpwd'] == '' || $data['newpwd'] == '') return app("json")->fail("参数有误,新旧密码为空!");
$adminInfo = aModel::get($this->adminId);
$adminInfo = (new \app\admin\model\Admin)->find($this->adminId);
if ($adminInfo['password'] == md5(md5($data['oldpwd']))) return aModel::update(['password' => md5(md5($data['newpwd']))], ['id' => $this->adminId]) ? app("json")->success("操作成功") : app("json")->fail("操作失败");
return app("json")->fail("密码不正确!");
}
@ -215,9 +223,10 @@ class Admin extends AuthController
* @return string
* @throws \Exception
*/
public function profile()
public function profile(): string
{
$this->assign("info", aModel::get($this->adminId));
$this->assign("info", (new \app\admin\model\Admin)->find($this->adminId));
// dd((new \app\admin\model\Admin)->find($this->adminId));
return $this->fetch();
}
@ -226,7 +235,7 @@ class Admin extends AuthController
* @param Request $request
* @return mixed
*/
public function changProfile(Request $request)
public function changProfile(Request $request): Response
{
$data = Util::postMore([
['nickname', ''],

View File

@ -4,7 +4,7 @@ namespace app\admin\controller;
use app\admin\extend\FormBuilder as Form;
use app\admin\extend\Util as Util;
use app\common\model\AdminAuth as aModel;
use app\admin\model\AdminAuth as aModel;
use app\Request;
use Exception;
use FormBuilder\Exception\FormBuilderException;
@ -13,6 +13,7 @@ use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\facade\Route as Url;
use think\Response;
/**
* 权限管理
@ -21,7 +22,10 @@ use think\facade\Route as Url;
*/
class AdminAuth extends AuthController
{
public function index()
/**
* @throws Exception
*/
public function index(): string
{
return $this->fetch();
}
@ -29,17 +33,17 @@ class AdminAuth extends AuthController
/**
* 权限列表
* @param Request $request
* @return array
* @return Response
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function lst(Request $request)
public function lst(Request $request): Response
{
$where = Util::postMore([
['name', ''],
['status', '']
]);
],$request);
return app("json")->layui(aModel::systemPage($where));
}
@ -53,12 +57,12 @@ class AdminAuth extends AuthController
* @throws ModelNotFoundException
* @throws Exception
*/
public function add($pid = 0)
public function add(int $pid = 0): string
{
$form = array();
$form[] = Elm::select('pid', '上级权限', (int)$pid)->options(aModel::returnOptions())->col(10);
$form[] = Elm::input('name', '权限名称')->col(10);
$form[] = Elm::frameInput('icon', '图标', Url::buildUrl('admin/icon/index', array('fodder' => 'icon')))->icon("ios-ionic")->width('96%')->height('390px')->col(10);
$form[] = Elm::frameInput('icon', '图标', Url::buildUrl('/admin/icon/index', array('fodder' => 'icon')))->icon("ios-ionic")->width('96%')->height('390px')->col(10);
$form[] = Elm::input('module', '模块名')->col(10);
$form[] = Elm::input('controller', '控制器名')->col(10);
$form[] = Elm::input('action', '方法名')->col(10);
@ -66,7 +70,7 @@ class AdminAuth extends AuthController
$form[] = Elm::number('rank', '排序')->col(10);
$form[] = Elm::radio('is_menu', '是否菜单', 1)->options([['label' => '是', 'value' => 1], ['label' => '否', 'value' => 0]])->col(10);
$form[] = Elm::radio('status', '状态', 1)->options([['label' => '启用', 'value' => 1], ['label' => '冻结', 'value' => 0]])->col(10);
$form = Form::make_post_form($form, url('save')->build());
$form = Form::make_post_form($form, url('/admin/admin_auth/save')->build());
$this->assign(compact('form'));
return $this->fetch("public/form-builder");
}
@ -79,34 +83,35 @@ class AdminAuth extends AuthController
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @throws Exception
*/
public function edit($id = 0)
public function edit(int $id = 0): string
{
if (!$id) return app("json")->fail("权限id不能为空");
$ainfo = aModel::get($id);
if (!$ainfo) return app("json")->fail("没有该权限");
$info = (new \app\admin\model\AdminAuth)->find($id);
if (!$info) return app("json")->fail("没有该权限");
$form = array();
$form[] = Elm::select('pid', '上级权限', $ainfo['pid'])->options(aModel::returnOptions())->col(10);
$form[] = Elm::input('name', '权限名称', $ainfo['name'])->col(10);
$form[] = Elm::frameInput('icon', '图标', Url::buildUrl('admin/widget.icon/index', array('fodder' => 'icon')), $ainfo['icon'])->icon("ios-ionic")->width('96%')->height('390px')->col(10);
$form[] = Elm::input('module', '模块名', $ainfo['module'])->col(10);
$form[] = Elm::input('controller', '控制器名', $ainfo['controller'])->col(10);
$form[] = Elm::input('action', '方法名', $ainfo['action'])->col(10);
$form[] = Elm::input('params', '参数', $ainfo['params'])->placeholder("php数组,不懂不要填写")->col(10);
$form[] = Elm::number('rank', '排序', $ainfo['rank'])->col(10);
$form[] = Elm::radio('is_menu', '是否菜单', $ainfo['is_menu'])->options([['label' => '是', 'value' => 1], ['label' => '否', 'value' => 0]])->col(10);
$form[] = Elm::radio('status', '状态', $ainfo['status'])->options([['label' => '启用', 'value' => 1], ['label' => '冻结', 'value' => 0]])->col(10);
$form = Form::make_post_form($form, url('save', ['id' => $id])->build());
$form[] = Elm::select('pid', '上级权限', $info['pid'])->options(aModel::returnOptions())->col(10);
$form[] = Elm::input('name', '权限名称', $info['name'])->col(10);
$form[] = Elm::frameInput('icon', '图标', Url::buildUrl('/admin/widget.icon/index', array('fodder' => 'icon')), $info['icon'])->icon("ios-ionic")->width('96%')->height('390px')->col(10);
$form[] = Elm::input('module', '模块名', $info['module'])->col(10);
$form[] = Elm::input('controller', '控制器名', $info['controller'])->col(10);
$form[] = Elm::input('action', '方法名', $info['action'])->col(10);
$form[] = Elm::input('params', '参数', $info['params'])->placeholder("php数组,不懂不要填写")->col(10);
$form[] = Elm::number('rank', '排序', $info['rank'])->col(10);
$form[] = Elm::radio('is_menu', '是否菜单', $info['is_menu'])->options([['label' => '是', 'value' => 1], ['label' => '否', 'value' => 0]])->col(10);
$form[] = Elm::radio('status', '状态', $info['status'])->options([['label' => '启用', 'value' => 1], ['label' => '冻结', 'value' => 0]])->col(10);
$form = Form::make_post_form($form, url('/admin/admin_auth/save', ['id' => $id])->build());
$this->assign(compact('form'));
return $this->fetch("public/form-builder");
}
/**
* 保存
* @param $id
* @return
* @param string $id
* @return mixed
*/
public function save($id = "")
public function save(string $id = "")
{
$data = Util::postMore([
['name', ''],
@ -129,7 +134,7 @@ class AdminAuth extends AuthController
if ($id == "") {
$data['create_user'] = $this->adminId;
$data['create_time'] = time();
$res = aModel::insert($data);
$res = aModel::create($data);
} else {
$data['update_user'] = $this->adminId;
$data['update_time'] = time();
@ -143,9 +148,9 @@ class AdminAuth extends AuthController
/**
* 修改字段
* @param $id
* @return aModel
* @return Response
*/
public function field($id)
public function field($id): Response
{
if (!$id) return app("json")->fail("参数有误Id为空");
$where = Util::postMore([['field', ''], ['value', '']]);

View File

@ -3,12 +3,14 @@
namespace app\admin\controller;
use app\admin\extend\Util as Util;
use app\common\model\AdminLog as lModel;
use app\admin\model\AdminLog as lModel;
use app\common\model\AdvertInfo;
use app\Request;
use Exception;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\Response;
/**
* 日志
@ -24,7 +26,7 @@ class AdminLog extends AuthController
* @return string
* @throws Exception
*/
public function index()
public function index(): string
{
return $this->fetch();
}
@ -32,12 +34,10 @@ class AdminLog extends AuthController
/**
* 权限列表
* @param Request $request
* @return array
* @throws DataNotFoundException
* @return Response
* @throws DbException
* @throws ModelNotFoundException
*/
public function lst(Request $request)
public function lst(Request $request): Response
{
$where = Util::postMore([
['name', ''],
@ -46,18 +46,17 @@ class AdminLog extends AuthController
['end_time', ''],
['page', 1],
['limit', 20],
]);
],$request);
return app("json")->layui(lModel::systemPage($where));
}
/**
* 清空日志
* @param Request $request
* @throws Exception
*/
public function empty(Request $request)
public function empty()
{
$res = lModel::where("1=1")->delete();
$res = (new \app\admin\model\AdminLog)->where("1=1")->delete();
return $res ? app("json")->success("操作成功", 'code') : app("json")->fail("操作失败");
}
}

View File

@ -3,7 +3,7 @@
namespace app\admin\controller;
use app\admin\extend\Util as Util;
use app\common\model\AdminNotify as nModel;
use app\admin\model\AdminNotify as nModel;
use Exception;
/**
@ -18,14 +18,14 @@ class AdminNotify extends AuthController
* @return mixed
* @throws Exception
*/
public function index()
public function index() : string
{
$where = Util::postMore([
['title', ''],
['start_time', ''],
['end_time', ''],
['is_read', ''],
['aid', $this->adminId],
['uid', $this->adminId],
]);
$this->assign("where", $where);
$this->assign("list", nModel::systemPage($where));

View File

@ -4,18 +4,19 @@ namespace app\admin\controller;
use app\admin\extend\FormBuilder as Form;
use app\admin\extend\Util as Util;
use app\common\model\AdminAuth as aModel;
use app\common\model\AdminRole as rModel;
use app\admin\model\AdminAuth as aModel;
use app\admin\model\AdminRole as rModel;
use app\Request;
use FormBuilder\Exception\FormBuilderException;
use FormBuilder\Factory\Elm;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\Response;
class AdminRole extends AuthController
{
public function index()
public function index(): string
{
return $this->fetch();
}
@ -28,7 +29,7 @@ class AdminRole extends AuthController
* @throws DbException
* @throws ModelNotFoundException
*/
public function lst(Request $request)
public function lst(Request $request): Response
{
return app("json")->layui(rModel::systemPage());
}
@ -47,10 +48,10 @@ class AdminRole extends AuthController
$form = array();
$form[] = Elm::select('pid', '所属上级', (int)$pid)->options(rModel::returnOptions())->filterable(true)->col(18);
$form[] = Elm::input('name', '角色名称')->col(18);
$form[] = Elm::treeChecked('tree_data', '选择权限')->data(aModel::selectAndBuildTree(0, $pid != 0 ? explode(",", rModel::get($pid)['auth']) : ($this->adminId == 1 ? aModel::getIds() : $this->auth)))->col(18);
$form[] = Elm::treeChecked('tree_data', '选择权限')->data(aModel::selectAndBuildTree(0, $pid != 0 ? explode(",", rModel::find($pid)['auth']) : ($this->adminId == 1 ? aModel::getIds() : $this->auth)))->col(18);
$form[] = Elm::number('rank', '排序')->col(18);
$form[] = Elm::radio('status', '状态', 1)->options([['label' => '启用', 'value' => 1], ['label' => '冻结', 'value' => 0]])->col(18);
$form = Form::make_post_form($form, url('save')->build());
$form = Form::make_post_form($form, url('/admin/admin_role/save')->build());
$this->assign(compact('form'));
return $this->fetch("public/form-builder");
}
@ -67,15 +68,15 @@ class AdminRole extends AuthController
public function edit($id = 0)
{
if (!$id) return app("json")->fail("权限id不能为空");
$rinfo = rModel::get($id);
$rinfo = rModel::find($id);
if (!$rinfo) return app("json")->fail("没有该权限");
$form = array();
$form[] = Elm::select('pid', '所属上级', $rinfo['pid'])->options(rModel::returnOptions())->filterable(true)->col(18);
$form[] = Elm::input('name', '角色名称', $rinfo['name'])->col(18);
$form[] = Elm::treeChecked('tree_data', '选择权限', to_int_array(explode(",", $rinfo['tree_data'])))->data(aModel::selectAndBuildTree(0, $rinfo['pid'] == 0 ? aModel::getIds() : explode(",", rModel::get($rinfo['pid'])['auth'])))->col(18);
$form[] = Elm::treeChecked('tree_data', '选择权限', to_int_array(explode(",", $rinfo['tree_data'])))->data(aModel::selectAndBuildTree(0, $rinfo['pid'] == 0 ? aModel::getIds() : explode(",", rModel::find($rinfo['pid'])['auth'])))->col(18);
$form[] = Elm::number('rank', '排序', $rinfo['rank'])->col(18);
$form[] = Elm::radio('status', '状态', $rinfo['status'])->options([['label' => '启用', 'value' => 1], ['label' => '冻结', 'value' => 0]])->col(18);
$form = Form::make_post_form($form, url('save', ['id' => $id])->build());
$form = Form::make_post_form($form, url('/admin/admin_role/save', ['id' => $id])->build());
$this->assign(compact('form'));
return $this->fetch("public/form-builder");
}
@ -103,7 +104,7 @@ class AdminRole extends AuthController
if ($id == "") {
$data['create_user'] = $this->adminId;
$data['create_time'] = time();
$res = rModel::insert($data);
$res = rModel::create($data);
} else {
$data['update_user'] = $this->adminId;
$data['update_time'] = time();

View File

@ -15,6 +15,7 @@ use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\facade\Route as Url;
use think\Response;
/**
* Class Advert
@ -25,7 +26,7 @@ use think\facade\Route as Url;
class Advert extends AuthController
{
public function index()
public function index() : string
{
return $this->fetch();
}
@ -33,9 +34,12 @@ class Advert extends AuthController
/**
* 列表
* @param Request $request
* @return
* @return Response
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function lst(Request $request)
public function lst(Request $request): Response
{
$where = Util::postMore([
['title', ''],
@ -53,6 +57,7 @@ class Advert extends AuthController
* @param Request $request
* @return string
* @throws FormBuilderException
* @throws Exception
*/
public function add(Request $request)
{
@ -61,7 +66,7 @@ class Advert extends AuthController
$form[] = Elm::input('alias', '标识')->col(10);
$form[] = Elm::input('description', '描述')->col(20);
$form[] = Elm::radio('status', '状态', 1)->options([['label' => '禁用', 'value' => 0], ['label' => '启用', 'value' => 1]])->col(24);
$form = Form::make_post_form($form, url('save')->build());
$form = Form::make_post_form($form, url('/admin/advert/save')->build());
$this->assign(compact('form'));
return $this->fetch("public/form-builder");
}
@ -75,14 +80,14 @@ class Advert extends AuthController
public function edit($id = '')
{
if (!$id) return app("json")->fail("项目id不能为空");
$info = aModel::get($id);
$info = (new \app\common\model\Advert)->find($id);
if (!$info) return app("json")->fail("轮播组不存在");
$form = array();
$form[] = Elm::input('title', '轮播组名称', $info['title'])->col(10);
$form[] = Elm::input('alias', '标识', $info['alias'])->col(10);
$form[] = Elm::input('description', '描述', $info['description'])->col(20);
$form[] = Elm::radio('status', '状态', $info['status'])->options([['label' => '禁用', 'value' => 0], ['label' => '启用', 'value' => 1]])->col(24);
$form = Form::make_post_form($form, url('save', ["id" => $id])->build());
$form = Form::make_post_form($form, url('/admin/advert/save', ["id" => $id])->build());
$this->assign(compact('form'));
return $this->fetch("public/form-builder");
}
@ -107,7 +112,7 @@ class Advert extends AuthController
$info = aModel::where("alias",$data['alias'])->find($id);
if ($info) return app("json")->fail("标识已存在,请修改后重试");
$data['create_time'] = time();
$res = aModel::insert($data);
$res = aModel::create($data);
} else {
$data['update_time'] = time();
$res = aModel::update($data, ['id' => $id]);
@ -144,7 +149,7 @@ class Advert extends AuthController
$ids = $request->param("id", 0);
if ($ids == 0) return app("json")->fail("参数有误Id为空");
if (!is_array($ids)) $ids = array_filter(explode(",", $ids));
if (tModel::where("tab_id", "in", $ids)->count() > 0) return app("json")->fail("该配置项下有配置数据,不能删除!");
if ((new \app\common\model\AdvertInfo)->where("tab_id", "in", $ids)->count() > 0) return app("json")->fail("该配置项下有配置数据,不能删除!");
return parent::del($request);
}
@ -155,7 +160,7 @@ class Advert extends AuthController
* @author 木子的忧伤
* @date 2021-02-19 11:53
*/
public function info($id = '')
public function info($id = ''): string
{
if (!$id) return app("json")->fail("参数有误Id为空");
return $this->fetch();
@ -181,7 +186,7 @@ class Advert extends AuthController
['status', ''],
['page', 1],
['limit', 20],
]);
],$request);
return app("json")->layui(tModel::systemPage($where));
}
@ -191,12 +196,12 @@ class Advert extends AuthController
* @return string
* @throws FormBuilderException
*/
public function addAdvert(Request $request)
public function addAdvert(Request $request): string
{
$form = array();
$form[] = Elm::input('title', '广告名称')->col(10);
$form[] = Elm::input('url', '链接地址')->col(10);
$form[] = Elm::frameImage('cover_path', '广告图片', Url::buildUrl('admin/image/index', array('fodder' => 'cover_path', 'limit' => 1)))->icon("ios-image")->width('96%')->height('440px')->col(10);
$form[] = Elm::frameImage('cover_path', '广告图片', Url::buildUrl('/admin/image/index', array('fodder' => 'cover_path', 'limit' => 1)))->icon("ios-image")->width('96%')->height('440px')->col(10);
$form[] = Elm::number('sort', '排序')->col(10);
$form[] = Elm::select('advert_id', '位置')->options(function () {
$options = [];
@ -207,25 +212,29 @@ class Advert extends AuthController
return $options;
})->col(10);
$form[] = Elm::radio('status', '状态', 1)->options([['label' => '启用', 'value' => 1], ['label' => '冻结', 'value' => 0]])->col(10);
$form = Form::make_post_form($form, url('saveAdvert')->build());
$form = Form::make_post_form($form, url('/admin/advert/saveAdvert')->build());
$this->assign(compact('form'));
return $this->fetch("public/form-builder");
}
/**
* 修改banner
* @param string $id
* @return string
* @throws DataNotFoundException
* @throws DbException
* @throws FormBuilderException
* @throws ModelNotFoundException
*/
public function editAdvert($id = "")
public function editAdvert($id = ""): string
{
if (!$id) return app("json")->fail("数据id不能为空");
$info = tModel::get($id);
$info = (new \app\common\model\AdvertInfo)->find($id);
if (!$info) return app("json")->fail("没有该数据");
$form = array();
$form[] = Elm::input('title', '广告名称', $info['title'])->col(10);
$form[] = Elm::input('url', '链接地址', $info['url'])->col(10);
$form[] = Elm::frameImage('cover_path', '广告图片', Url::buildUrl('admin/image/index', array('fodder' => 'cover_path', 'limit' => 1)), $info['cover_path'])->icon("ios-image")->width('96%')->height('440px')->col(10);
$form[] = Elm::frameImage('cover_path', '广告图片', Url::buildUrl('/admin/image/index', array('fodder' => 'cover_path', 'limit' => 1)), $info['cover_path'])->icon("ios-image")->width('96%')->height('440px')->col(10);
$form[] = Elm::number('sort', '排序', $info['sort'])->col(10);
$form[] = Elm::select('advert_id', '位置', $info['advert_id'])->options(function () {
$options = [];
@ -236,7 +245,7 @@ class Advert extends AuthController
return $options;
})->col(10);
$form[] = Elm::radio('status', '状态', $info['status'])->options([['label' => '启用', 'value' => 1], ['label' => '冻结', 'value' => 0]])->col(10);
$form = Form::make_post_form($form, url('saveAdvert', ['id' => $id])->build());
$form = Form::make_post_form($form, url('/admin/advert/saveAdvert', ['id' => $id])->build());
$this->assign(compact('form'));
return $this->fetch("public/form-builder");
}
@ -245,6 +254,9 @@ class Advert extends AuthController
* 保存修改
* @param string $id
* @return mixed
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function saveAdvert($id = "")
{
@ -274,4 +286,18 @@ class Advert extends AuthController
cache(Data::DATA_ADVERT . '_' . $info['alias'], null);//清除缓存
return $res ? app("json")->success("操作成功", 'code') : app("json")->fail("操作失败");
}
/**
* 删除广告
* @param Request $request
* @return mixed
*/
public function delAdvert(Request $request)
{
$where = Util::postMore([
['id', ''],
],$request);
if (empty($where['id'])) return app("json")->fail("参数错误,请刷新后重试");
return (new \app\common\model\AdvertInfo)->where('id',$where['id'])->delete() ? app("json")->success("删除成功") : app("json")->fail("删除失败");
}
}

View File

@ -6,6 +6,7 @@ use app\admin\extend\Util as Util;
use app\common\model\Comment as CommentModel;
use app\common\model\Document;
use app\common\model\DocumentCategory as cModel;
use app\Request;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
@ -22,7 +23,7 @@ class Article extends AuthController
/**
* 构造方法 初始化一些参数
*/
public function initialize()
public function initialize(): void
{
parent::initialize();
//修正因为修改model名称和原来不能对应导致的model功能异常
@ -34,7 +35,7 @@ class Article extends AuthController
* @return string
* @throws \Exception
*/
public function index()
public function index(): string
{
return $this->fetch();
}
@ -64,8 +65,10 @@ class Article extends AuthController
/**
* 保存
* @param string $id
* @return mixed
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @author 木子的忧伤
* @date 2021-02-28 22:43
*/
@ -85,7 +88,7 @@ class Article extends AuthController
['is_recommend', 0],
['is_top', 0],
['is_hot', 0],
['theme', 'detail.html'],
['template', 'detail.html'],
['link_str', ''],
['is_jump', 0],
['cover_path', ''],
@ -122,15 +125,16 @@ class Article extends AuthController
/**
* 新增文章
* @param $category_id
* @param string $category_id
* @return string
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @throws \Exception
* @author 木子的忧伤
* @date 2021-03-10 14:46
*/
public function add($category_id = '')
public function add(string $category_id = '')
{
$where = [
'name' => '',
@ -174,13 +178,14 @@ class Article extends AuthController
* @return string
* @throws \Exception
*/
public function comment()
public function comment(): string
{
return $this->fetch();
}
/**
* 文章评论列表
* @param Request $request
* @return mixed
* @throws DataNotFoundException
* @throws DbException
@ -188,7 +193,7 @@ class Article extends AuthController
* @author 木子的忧伤
* @date 2021-11-03 23:28
*/
public function commentList()
public function commentList(Request $request)
{
$where = Util::postMore([
['document_id', ''],
@ -199,7 +204,7 @@ class Article extends AuthController
['end_time', ''],
['page', 1],
['limit', 20],
]);
],$request);
if ($where['document_id'] == "") return app("json")->fail("参数错误");
return app("json")->layui(CommentModel::systemPage($where));
}

View File

@ -2,8 +2,8 @@
namespace app\admin\controller;
use app\admin\model\AdminAuth;
use app\common\constant\Data;
use app\common\model\AdminAuth;
use think\facade\App;
use think\facade\Lang;
use think\facade\Session;
@ -81,7 +81,7 @@ abstract class AuthController extends SystemBasic
/**
* 初始化
*/
protected function initialize()
protected function initialize(): void
{
parent::initialize();
$this->adminInfo = Session::get(Data::SESSION_KEY_ADMIN_INFO);
@ -117,7 +117,7 @@ abstract class AuthController extends SystemBasic
/**
* 加载语言文件
*/
protected function loadLang()
protected function loadLang(): void
{
Lang::load(App::getRootPath() . 'app/' . $this->module . '/lang/' . Lang::getLangSet() . '/' . $this->controller . '.php');
}
@ -126,7 +126,7 @@ abstract class AuthController extends SystemBasic
* 验证登录
* @return bool
*/
protected static function isActive()
protected static function isActive(): bool
{
return Session::has(Data::SESSION_KEY_ADMIN_ID) && Session::has(Data::SESSION_KEY_ADMIN_INFO);
}
@ -135,7 +135,7 @@ abstract class AuthController extends SystemBasic
* 记录日志
* @return bool
*/
protected function createLog()
protected function createLog(): bool
{
// 不需要登录不能记录日志
if (in_array($this->action, $this->noNeedLogin) || $this->noNeedLogin == ['*'] || $this->noNeedLogin == "*") return true;
@ -154,7 +154,13 @@ abstract class AuthController extends SystemBasic
{
$path = explode(".", $this->request->controller());
$modelPath = "app\\common\\model"; //全部为common
foreach ($path as $v) $modelPath .= "\\" . $v;
foreach ($path as $v) {
if (substr($v,0,5) == "Admin"){
//后台用户相关的需要特殊处理
$modelPath = "app\\admin\\model"; //全部为common
}
$modelPath .= "\\" . $v;
}
if (class_exists($modelPath)) return app($modelPath);
return null;
}

View File

@ -10,6 +10,7 @@ use Exception;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\Response;
/**
* Class Article
@ -26,7 +27,7 @@ class Category extends AuthController
* @author 木子的忧伤
* @date 2021-02-17 11:40
*/
public function index()
public function index(): string
{
return $this->fetch();
}
@ -34,12 +35,12 @@ class Category extends AuthController
/**
* 权限列表
* @param Request $request
* @return array
* @return Response
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function lst(Request $request)
public function lst(Request $request): Response
{
$where = Util::postMore([
['name', ''],
@ -50,8 +51,7 @@ class Category extends AuthController
/**
* 保存
* @param $id
* @return
* @return mixed
*/
public function save()
{
@ -73,7 +73,7 @@ class Category extends AuthController
if ($data['alias'] == "") $data['alias'] = get_rand_str(8);
if ($data['id'] == "") {
$model = new aModel();
$res = $model->insert($data);
$res = $model->create($data);
} else {
$res = aModel::update($data, ['id' => $data['id']]);
}
@ -86,7 +86,7 @@ class Category extends AuthController
* @param $id
* @return aModel
*/
public function field($id)
public function field($id): aModel
{
if (!$id) return app("json")->fail("参数有误Id为空");
$where = Util::postMore([['field', ''], ['value', '']]);
@ -97,19 +97,14 @@ class Category extends AuthController
/**
* 新增页
* @param string $pid
* @return string
* @throws Exception
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function add($pid = '')
public function add(string $pid = ''): string
{
$templatePath = system_config('web_template');
$themeInfoFile = public_path('template' . DIRECTORY_SEPARATOR . $templatePath) . 'info.json';
if (file_exists($themeInfoFile)) {
$themeInfo = json_decode(file_get_contents($themeInfoFile), true);
$themeList = $themeInfo['category_list'];
} else {
$themeList = [];
}
$where = Util::postMore([
'name' => '',
'status' => '',
@ -118,6 +113,10 @@ class Category extends AuthController
$category = get_tree_list($category);
$this->assign("category", $category);
$this->assign("pid", $pid);
$themeList = get_template_list(Data::DOCUMENT_CATEGORY);
if (empty($themeList)){
$this->error("模板文件不存在,请检查主题目录或主题配置");
}
$this->assign("template_list", $themeList);
return $this->fetch();
}
@ -129,25 +128,21 @@ class Category extends AuthController
* @author 木子的忧伤
* @date 2021-02-20 17:00
*/
public function edit(Request $request)
public function edit(Request $request): string
{
$templatePath = system_config('web_template');
$themeInfoFile = public_path('template' . DIRECTORY_SEPARATOR . $templatePath) . 'info.json';
if (file_exists($themeInfoFile)) {
$themeInfo = json_decode(file_get_contents($themeInfoFile), true);
$themeList = $themeInfo['category_list'];
} else {
$themeList = [];
}
$where = Util::postMore([
'name' => '',
'status' => '',
]);
$category = aModel::systemPage($where);
$category = get_tree_list($category);
$info = aModel::get($request->param(['id']));
$info = aModel::find($request->param(['id']));
$this->assign("category", $category);
$this->assign("info", $info);
$themeList = get_template_list(Data::DOCUMENT_CATEGORY);
if (empty($themeList)){
$this->error("模板文件不存在,请检查主题目录或主题配置");
}
$this->assign("template_list", $themeList);
return $this->fetch();
}

View File

@ -1,11 +1,4 @@
<?php
// +----------------------------------------------------------------------
// | HulaCWMS 呼啦企业网站管理系统
// +----------------------------------------------------------------------
// | Copyright (c) 2021 https://www.kaifashu.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: 开发树
// +----------------------------------------------------------------------
namespace app\admin\controller;
@ -18,6 +11,7 @@ use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\facade\Db;
use think\Response;
/*
* 数据库备份还原控制器
@ -33,7 +27,7 @@ class Databases extends AuthController
* @author 木子的忧伤
* @date 2021-10-30 12:45
*/
public function index($type = null)
public function index($type = null): string
{
if (!$type) {
$type = 'export';
@ -64,7 +58,7 @@ class Databases extends AuthController
* @author 木子的忧伤
* @date 2021-10-31 0:12
*/
public function lst(Request $request)
public function lst(Request $request): Response
{
$data = Util::postMore([
['type', 'export'],

View File

@ -2,8 +2,6 @@
namespace app\admin\controller;
use app\admin\extend\storage\QcloudCoService;
use app\admin\extend\Util as Util;
use app\common\model\Attachment;
use think\db\exception\DataNotFoundException;
@ -29,21 +27,20 @@ class File extends AuthController
$storage_type = system_config("storage_type") ?: 1;//默认未本地存储
switch ($storage_type) {
case 1:
$saveName = Filesystem::putFile($fileType, $file);
$filePath = Filesystem::url($saveName);
//获取文件类型
$fileMime = $file->getMime();
//获取文件尺寸
$fileSize = $file->getSize();
$fileName = Filesystem::disk('public')->putFile($fileType, $file);
$filePath = Filesystem::disk('public')->url($fileName);
//转换因为win导致的兼容问题
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$filePath = str_replace(DIRECTORY_SEPARATOR, '/', $filePath);
}
break;
case 2:
$saveName = Filesystem::putFile('image', $file);
$ext = $file->getOriginalExtension();
$key = '/image/' . date('Ymd') . "/" . substr(md5($file->getRealPath()), 0, 5) . date('YmdHis') . rand(0, 9999) . '.' . $ext;
$filePath = QcloudCoService::put($key, $file->getRealPath());
break;
//其余云oss 自行开发
}
return Attachment::addAttachment($this->request->param("cid", 0), $saveName, $filePath, 'image', $file->getMime(), $file->getSize(), $storage_type) ? app("json")->code()->success("上传成功", ['filePath' => $filePath, "name" => $saveName]) : app("json")->fail("上传失败");
return Attachment::addAttachment($this->request->param("cid", 0), $fileName, $filePath, 'image', $fileMime, $fileSize, $storage_type) ? app("json")->code()->success("上传成功", ['filePath' => file_cdn($filePath), "name" => $fileName]) : app("json")->fail("上传失败");
}
/**
@ -73,7 +70,7 @@ class File extends AuthController
/**
* @单文件上传
* @param string $type 类型 files image documents banners
* @param Request $request
* @return mixed
*/
public function upload(Request $request)
@ -93,7 +90,7 @@ class File extends AuthController
break;
case 'document':
$fileSize = 5 * 1024 * 1024;
$fileExt = 'pdf,doc,docx';
$fileExt = 'doc,docx,pdf,xls,xlsx,ppt,pptx,txt,wps';
break;
case 'image':
$fileSize = 5 * 1024 * 1024;
@ -117,13 +114,17 @@ class File extends AuthController
'fileExt' => $fileExt
// 更多规则请看“上传验证”的规则文档地址https://www.kancloud.cn/manual/thinkphp6_0/1037629#_444
]])->check(['file' => $file]);
$saveName = Filesystem::putFile($fileType, $file);
$filePath = Filesystem::url($saveName);
//获取文件类型
$fileMime = $file->getMime();
//获取文件尺寸
$fileSize = $file->getSize();
$fileName = Filesystem::disk('public')->putFile($fileType, $file);
$filePath = Filesystem::disk('public')->url($fileName);
//转换因为win导致的兼容问题
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$filePath = str_replace(DIRECTORY_SEPARATOR, '/', $filePath);
}
return $saveName ? app("json")->code()->success("上传成功", ['filePath' => $filePath, "name" => basename($saveName)]) : app("json")->fail("上传失败");
return Attachment::addAttachment($this->request->param("cid", 0), $fileName, $filePath, $fileType, $fileMime, $fileSize, 1) ? app("json")->code()->success("上传成功", ['filePath' => file_cdn($filePath), "name" => $fileName]) : app("json")->fail("上传失败");
} catch (ValidateException $e) {
return app("json")->fail($e->getMessage());
}

View File

@ -14,6 +14,7 @@ use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\facade\Route as Url;
use think\Response;
/**
* Class Message
@ -28,7 +29,7 @@ class FriendLink extends AuthController
* @return string
* @throws Exception
*/
public function index()
public function index() : string
{
return $this->fetch();
}
@ -43,7 +44,7 @@ class FriendLink extends AuthController
* @author 木子的忧伤
* @date 2021-02-15 23:26
*/
public function lst(Request $request)
public function lst(Request $request): Response
{
$where = Util::postMore([
['title', ''],
@ -66,11 +67,11 @@ class FriendLink extends AuthController
$form = array();
$form[] = Elm::input('title', '网站名称')->col(10);
$form[] = Elm::input('url', '网站地址')->col(10);
$form[] = Elm::frameImage('image', '网站Logo', Url::buildUrl('admin/image/index', array('fodder' => 'image', 'limit' => 1)))->icon("ios-image")->width('96%')->height('440px')->col(10);
$form[] = Elm::frameImage('image', '网站Logo', Url::buildUrl('/admin/image/index', array('fodder' => 'image', 'limit' => 1)))->icon("ios-image")->width('96%')->height('440px')->col(10);
$form[] = Elm::input('sort', '排序')->col(10);
$form[] = Elm::textarea('description', '描述')->col(10);
$form[] = Elm::radio('status', '状态', 1)->options([['label' => '启用', 'value' => 1], ['label' => '冻结', 'value' => 0]])->col(10);
$form = Form::make_post_form($form, url('save')->build());
$form = Form::make_post_form($form, url('/admin/friend_link/save')->build());
$this->assign(compact('form'));
return $this->fetch("public/form-builder");
}
@ -83,16 +84,16 @@ class FriendLink extends AuthController
public function edit($id = "")
{
if (!$id) return app("json")->fail("数据id不能为空");
$ainfo = aModel::get($id);
$ainfo = aModel::find($id);
if (!$ainfo) return app("json")->fail("没有该数据");
$form = array();
$form[] = Elm::input('title', '网站名称', $ainfo['title'])->col(10);
$form[] = Elm::input('url', '网站地址', $ainfo['url'])->col(10);
$form[] = Elm::frameImage('image', '网站Logo', Url::buildUrl('admin/image/index', array('fodder' => 'image', 'limit' => 1)), $ainfo['image'])->icon("ios-image")->width('96%')->height('440px')->col(10);
$form[] = Elm::frameImage('image', '网站Logo', Url::buildUrl('/admin/image/index', array('fodder' => 'image', 'limit' => 1)), $ainfo['image'])->icon("ios-image")->width('96%')->height('440px')->col(10);
$form[] = Elm::input('sort', '排序', $ainfo['sort'])->col(10);
$form[] = Elm::textarea('description', '描述', $ainfo['description'])->col(10);
$form[] = Elm::radio('status', '状态', $ainfo['status'])->options([['label' => '启用', 'value' => 1], ['label' => '冻结', 'value' => 0]])->col(10);
$form = Form::make_post_form($form, url('save', ['id' => $id])->build());
$form = Form::make_post_form($form, url('/admin/friend_link/save', ['id' => $id])->build());
$this->assign(compact('form'));
return $this->fetch("public/form-builder");
}
@ -102,7 +103,7 @@ class FriendLink extends AuthController
* @param string $id
* @return mixed
*/
public function save($id = "")
public function save(string $id = "")
{
$data = Util::postMore([
['id', ''],

View File

@ -9,7 +9,10 @@ namespace app\admin\controller;
*/
class Icon extends AuthController
{
public function index()
/**
* @throws \Exception
*/
public function index(): string
{
return $this->fetch();
}

View File

@ -26,7 +26,10 @@ class Image extends AuthController
*/
private $type = "image";
public function index()
/**
* @throws Exception
*/
public function index() : string
{
return $this->fetch();
}
@ -39,7 +42,7 @@ class Image extends AuthController
*/
public function category()
{
return app("json")->success(AttachmentCategory::buildNodes("image", 0, $this->request->param("title", "")));
return app("json")->success(AttachmentCategory::buildNodes($this->type, 0, $this->request->param("title", "")));
}
/**
@ -48,8 +51,9 @@ class Image extends AuthController
* @param int $pid
* @return string
* @throws FormBuilderException
* @throws Exception
*/
public function addCategory($id = 0, $pid = 0)
public function addCategory($id = 0, $pid = 0): string
{
$form = array();
$form[] = Elm::select('pid', '上级分类', (int)$pid ?: (int)$id)->options(function () {
@ -61,19 +65,23 @@ class Image extends AuthController
})->col(18);
$form[] = Elm::input('name', '分类名称')->col(18);
$form[] = Elm::hidden('type', $this->type)->col(18);
$form = Form::make_post_form($form, url('saveCategory')->build());
$form = Form::make_post_form($form, url('/admin/image/saveCategory')->build());
$this->assign(compact('form'));
return $this->fetch("public/form-builder");
}
/**
* 目录的修改
* @param $id
* @param int $id
* @param int $pid
* @return string
* @throws DataNotFoundException
* @throws DbException
* @throws FormBuilderException
* @throws ModelNotFoundException
* @throws Exception
*/
public function editCategory($id = 0, $pid = 0)
public function editCategory(int $id = 0, int $pid = 0): string
{
if ($id == 0) return app("json")->fail("没有选中分类");
$form = array();
@ -86,7 +94,7 @@ class Image extends AuthController
})->col(18);
$form[] = Elm::input('name', '分类名称', AttachmentCategory::getNameById($id))->col(18);
$form[] = Elm::hidden('type', $this->type)->col(18);
$form = Form::make_post_form($form, Url('saveCategory', ['id' => $id])->build());
$form = Form::make_post_form($form, Url('/admin/image/saveCategory', ['id' => $id])->build());
$this->assign(compact('form'));
return $this->fetch("public/form-builder");
}
@ -96,7 +104,7 @@ class Image extends AuthController
* @param string $id
* @return mixed
*/
public function saveCategory($id = "")
public function saveCategory(string $id = "")
{
$data = Util::postMore([
['pid', 0],
@ -117,14 +125,15 @@ class Image extends AuthController
/**
* 删除目录
* @param $id
* @return
* @return mixed
* @throws DbException
*/
public function delCategory($id)
{
if ($id == 0) return app("json")->fail("未选择分类");
if (Attachment::be($id, "cid")) return app("json")->fail("该分类下有图片不能删除");
if (AttachmentCategory::be($id, "pid")) return app("json")->fail("该分类下有子分类不能删除");
return AttachmentCategory::del($id) ? app("json")->success("删除成功") : app("json")->fail("删除失败");
if (Attachment::isExist($id, "cid")) return app("json")->fail("该分类下有图片不能删除");
if (AttachmentCategory::isExist($id, "pid")) return app("json")->fail("该分类下有子分类不能删除");
return AttachmentCategory::delete($id) ? app("json")->success("删除成功") : app("json")->fail("删除失败");
}
/**
@ -149,10 +158,10 @@ class Image extends AuthController
* @throws DbException
* @throws ModelNotFoundException
*/
public function editImage($id)
public function editImage($id): string
{
if ($id == 0) return app("json")->fail("没有选中图片");
$image = Attachment::get($id);
$image = Attachment::find($id);
$form = array();
$form[] = Elm::select('cid', '选中分类', (int)$image['cid'])->options(AttachmentCategory::returnOptions())->col(18);
$form[] = Elm::hidden('type', $this->type)->col(18);
@ -179,7 +188,7 @@ class Image extends AuthController
public function delImage($id)
{
if ($id == 0) return app("json")->fail("未选择图片");
$image = Attachment::get($id);
$image = Attachment::find($id);
try {
switch ($image['storage']) {
case 1:
@ -192,7 +201,7 @@ class Image extends AuthController
QcloudCoService::del(str_replace(system_config("storage_domain"), "", $image['path']));
break;
}
return Attachment::del($id) ? app("json")->success("删除成功") : app("json")->fail("删除失败");
return Attachment::delete($id) ? app("json")->success("删除成功") : app("json")->fail("删除失败");
} catch (Exception $e) {
return app("json")->fail("删除失败" . $e);
}

View File

@ -2,18 +2,11 @@
namespace app\admin\controller;
use app\common\model\AdminAuth;
use app\common\model\Document;
use app\common\model\Document as DocumentModel;
use app\common\model\DocumentCategory;
use app\common\model\DocumentCategory as DocumentCategoryModel;
use app\common\model\FriendLink;
use app\common\model\MessageForm;
use app\common\model\User;
use app\admin\model\AdminAuth;
use app\admin\model\AdminNotify;
use app\common\model\{Document, FriendLink, MessageForm, User};
use Exception;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\db\exception\{DataNotFoundException, DbException, ModelNotFoundException};
class Index extends AuthController
{
@ -22,17 +15,11 @@ class Index extends AuthController
* @return string
* @throws Exception
*/
public function index()
public function index(): string
{
$this->assign("adminInfo", $this->adminInfo);
$menuList = cache(AdminAuth::getMenuCacheKey($this->adminId));
if ($menuList === null) {
$menuList = AdminAuth::getMenu(0, $this->auth);
cache(AdminAuth::getMenuCacheKey($this->adminId), $menuList, 1 * 60 * 60);
}
$this->assign("menu", $menuList);
$messageList = ['data' => [], 'count' => 0];
$this->assign("message", $messageList);
$this->assign("menu", AdminAuth::getAuthList($this->adminId,$this->auth));
$this->assign("message", AdminNotify::pageList($this->adminId,5));
return $this->fetch();
}
@ -41,16 +28,13 @@ class Index extends AuthController
* @return string
* @throws Exception
*/
public function main()
public function main(): string
{
$documentCount = Document::counts(new Document());
$this->assign("document_count", $documentCount);
$userCount = User::counts(new User());
$this->assign("user_count", $userCount);
$FriendLinkCount = FriendLink::counts(new FriendLink());
$this->assign("friend_link_count", $FriendLinkCount);
$messageFormCount = MessageForm::counts(new MessageForm());
$this->assign("message_form_count", $messageFormCount);
$this->assign("document_count", (new Document)->count());
$this->assign("user_count", (new User())->count());
$this->assign("friend_link_count",(new FriendLink())->count());
$this->assign("message_form_count", (new MessageForm())->count());
$this->assign("article_list", Document::systemPage(["page"=> 0 ,"limit" => 5])['data']);
return $this->fetch();
}
@ -62,88 +46,6 @@ class Index extends AuthController
*/
public function menu()
{
$menuList = cache(AdminAuth::getMenuCacheKey($this->adminId));
if ($menuList === null) {
$menuList = AdminAuth::getMenu(0, $this->auth);
cache(AdminAuth::getMenuCacheKey($this->adminId), $menuList, 1 * 60 * 60);
}
return app("json")->success($menuList);
return app("json")->success(AdminAuth::getAuthList($this->adminId,$this->auth));
}
/**
* 生成sitemap.xml
*/
public function sitemap()
{
//获取协议
$protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ?
"https://" : "http://";
//获取域名
$domain = $protocol . $_SERVER['HTTP_HOST'];
//获取页码
$page = input('page/d');
if (!$page) {
$page = 1;
}
$str = '';
if ($page == 1) {
if (file_exists('sitemap.xml'))
unlink('sitemap.xml');
$str .= '<?xml version="1.0" encoding="utf-8"?>';
$str .= '<urlset>';
//首页
$str .= '<url>';
$str .= '<loc>' . $domain . '</loc>';
$str .= '<lastmod>' . date('Y-m-d', time()) . '</lastmod>';
$str .= '<changefreq>daily</changefreq>';
$str .= '<priority>1.0</priority>';
$str .= '</url>';
}
$pagesize = 100;
//获取文章分类url
$documentCategoryModel = new DocumentCategoryModel();
$categoryInfo = $documentCategoryModel->field('id,title,create_time')
->where('display', 1)->where('status', 1)
->page($page, $pagesize)
->order('id desc')->select();
foreach ($categoryInfo as $v) {
$str .= '<url>';
$str .= '<loc>' . $domain . url('article/lists?id=' . $v['id']) . '</loc>';
$str .= '<lastmod>' . $v['create_time'] . '</lastmod>';
$str .= '<changefreq>always</changefreq>';
$str .= '<priority>0.8</priority>';
$str .= '</url>';
}
//获取详细页分类url
$documentModel = new DocumentModel();
$documentInfo = $documentModel->field('id,create_time')
->where('status', 1)
->page($page, $pagesize)
->order('id desc')->select();
foreach ($documentInfo as $v) {
$str .= '<url>';
$str .= '<loc>' . $domain . url('article/detail?id=' . $v['id']) . $v['id'] . '</loc>';
$str .= '<lastmod>' . $v['create_time'] . '</lastmod>';
$str .= '<changefreq>monthly</changefreq>';
$str .= '<priority>0.6</priority>';
$str .= '</url>';
}
if (count($categoryInfo) < $pagesize && count($documentInfo) < $pagesize) {
$str .= '</urlset>';
if (!(file_put_contents('sitemap.xml', $str, FILE_APPEND | LOCK_EX))) {
$this->error('站点地图更新失败!');
} else {
$this->success('站点地图全部更新完成!', null, 'stop');
}
}
//写入
if (!(file_put_contents('sitemap.xml', $str, FILE_APPEND | LOCK_EX))) {
$this->error('站点地图更新失败!');
} else {
$this->success('站点地图正在生成,请稍后(' . $page . '...', 'sitemap?page=' . ($page + 1));
}
}
}
}

View File

@ -9,6 +9,7 @@ use Exception;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\Response;
/**
* Class Invitation
@ -21,7 +22,7 @@ class Invitation extends AuthController
/**
* 构造方法 初始化一些参数
*/
public function initialize()
public function initialize(): void
{
parent::initialize();
//修正因为修改model名称和原来不能对应导致的model功能异常
@ -35,7 +36,7 @@ class Invitation extends AuthController
* @author 木子的忧伤
* @date 2021-02-16 13:15
*/
public function index()
public function index(): string
{
return $this->fetch();
}
@ -50,7 +51,7 @@ class Invitation extends AuthController
* @author 木子的忧伤
* @date 2021-02-15 23:26
*/
public function lst(Request $request)
public function lst(Request $request): Response
{
$where = Util::postMore([
['code', ''],
@ -70,7 +71,7 @@ class Invitation extends AuthController
* @author 木子的忧伤
* @date 2021-02-20 14:32
*/
public function save($id = "")
public function save(string $id = "")
{
$data = Util::postMore([
['code', ''],
@ -102,21 +103,23 @@ class Invitation extends AuthController
* @author 木子的忧伤
* @date 2021-02-20 14:35
*/
public function addMultiple($id = "")
public function addMultiple(string $id = "")
{
$data = Util::postMore([
['name', ''],
['number', 1],
]);
if ($data['name'] == "") return app("json")->fail("邀请码前缀不能为空");
if ($data['number'] == "") return app("json")->fail("数量不是数字或者小于1");
$count = intval($data['number']);
$res = false;
for ($i = 0; $i < $count; $i++) {
$code['code'] = ($data['name'] . substr(time(), -6) . rand(0, 9999));
$code['status'] = 0;
$code['user'] = $this->adminId;
$check = aModel::where('code')->find();
if ($check == null || $check == false) {
$check = (new \app\common\model\InvitationCode)->where('code')->find();
if (!$check) {
$res = aModel::create($code);
} else {
continue;

View File

@ -4,7 +4,7 @@
namespace app\admin\controller;
use app\admin\extend\Util as Util;
use app\common\model\Admin as adminModel;
use app\admin\model\Admin as adminModel;
use Exception;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
@ -52,7 +52,7 @@ class Login extends AuthController
* @return string
* @throws Exception
*/
public function register()
public function register(): string
{
return $this->fetch();
}
@ -62,7 +62,7 @@ class Login extends AuthController
* @return string
* @throws Exception
*/
public function forget()
public function forget(): string
{
return $this->fetch();
}
@ -81,7 +81,7 @@ class Login extends AuthController
* 验证码
* @return Response
*/
public function captcha()
public function captcha(): Response
{
ob_clean();
return captcha();

View File

@ -9,6 +9,7 @@ use Exception;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\Response;
/**
* Class Message
@ -21,7 +22,7 @@ class Message extends AuthController
/**
* 构造方法 初始化一些参数
*/
public function initialize()
public function initialize(): void
{
parent::initialize();
//修正因为修改model名称和原来不能对应导致的model功能异常
@ -35,7 +36,7 @@ class Message extends AuthController
* @author 木子的忧伤
* @date 2021-02-19 11:53
*/
public function index()
public function index(): string
{
return $this->fetch();
}
@ -50,7 +51,7 @@ class Message extends AuthController
* @author 木子的忧伤
* @date 2021-02-19 11:54
*/
public function lst(Request $request)
public function lst(Request $request): Response
{
$where = Util::postMore([
['author', ''],

View File

@ -13,6 +13,7 @@ use FormBuilder\Factory\Elm;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\Response;
/**
* Class Nav
@ -22,7 +23,10 @@ use think\db\exception\ModelNotFoundException;
*/
class Nav extends AuthController
{
public function index()
/**
* @throws Exception
*/
public function index() : string
{
return $this->fetch();
}
@ -35,7 +39,7 @@ class Nav extends AuthController
* @throws DbException
* @throws ModelNotFoundException
*/
public function lst(Request $request)
public function lst(Request $request): Response
{
$where = Util::postMore([
['title', ''],
@ -54,17 +58,17 @@ class Nav extends AuthController
* @throws ModelNotFoundException
* @throws Exception
*/
public function add($pid = 0)
public function add(int $pid = 0)
{
$form = array();
$form[] = Elm::select('pid', '上级导航', (int)$pid)->options(aModel::returnOptions())->col(10);
$form[] = Elm::input('title', '导航名称')->col(10);
// $form[] = Elm::frameInput('icon', '图标', Url::buildUrl('admin/icon/index', array('fodder' => 'icon')))->icon("ios-ionic")->width('96%')->height('390px')->col(10);
// $form[] = Elm::frameInput('icon', '图标', Url::buildUrl('/admin/icon/index', array('fodder' => 'icon')))->icon("ios-ionic")->width('96%')->height('390px')->col(10);
$form[] = Elm::input('url', '链接地址')->col(10);
$form[] = Elm::input('params', '参数')->placeholder("php数组,不懂不要填写")->col(10);
$form[] = Elm::number('sort', '排序')->col(10);
$form[] = Elm::radio('status', '状态', 1)->options([['label' => '启用', 'value' => 1], ['label' => '冻结', 'value' => 0]])->col(10);
$form = Form::make_post_form($form, url('save')->build());
$form = Form::make_post_form($form, url('/admin/nav/save')->build());
$this->assign(compact('form'));
return $this->fetch("public/form-builder");
}
@ -78,20 +82,20 @@ class Nav extends AuthController
* @throws DbException
* @throws ModelNotFoundException
*/
public function edit($id = 0)
public function edit(int $id = 0)
{
if (!$id) return app("json")->fail("导航id不能为空");
$ainfo = aModel::get($id);
if (!$ainfo) return app("json")->fail("没有该导航");
$info = aModel::find($id);
if (!$info) return app("json")->fail("没有该导航");
$form = array();
$form[] = Elm::select('pid', '上级导航', $ainfo['pid'])->options(aModel::returnOptions())->col(10);
$form[] = Elm::input('title', '导航名称', $ainfo['title'])->col(10);
//$form[] = Elm::frameInput('icon', '图标', Url::buildUrl('admin/widget.icon/index', array('fodder' => 'icon')), $ainfo['icon'])->icon("ios-ionic")->width('96%')->height('390px')->col(10);
$form[] = Elm::input('url', '链接地址', $ainfo['url'])->col(10);
$form[] = Elm::input('params', '参数', $ainfo['params'])->placeholder("php数组,不懂不要填写")->col(10);
$form[] = Elm::number('sort', '排序', $ainfo['sort'])->col(10);
$form[] = Elm::radio('status', '状态', $ainfo['status'])->options([['label' => '启用', 'value' => 1], ['label' => '冻结', 'value' => 0]])->col(10);
$form = Form::make_post_form($form, url('save', ['id' => $id])->build());
$form[] = Elm::select('pid', '上级导航', $info['pid'])->options(aModel::returnOptions())->col(10);
$form[] = Elm::input('title', '导航名称', $info['title'])->col(10);
//$form[] = Elm::frameInput('icon', '图标', Url::buildUrl('/admin/widget.icon/index', array('fodder' => 'icon')), $ainfo['icon'])->icon("ios-ionic")->width('96%')->height('390px')->col(10);
$form[] = Elm::input('url', '链接地址', $info['url'])->col(10);
$form[] = Elm::input('params', '参数', $info['params'])->placeholder("php数组,不懂不要填写")->col(10);
$form[] = Elm::number('sort', '排序', $info['sort'])->col(10);
$form[] = Elm::radio('status', '状态', $info['status'])->options([['label' => '启用', 'value' => 1], ['label' => '冻结', 'value' => 0]])->col(10);
$form = Form::make_post_form($form, url('/admin/nav/save', ['id' => $id])->build());
$this->assign(compact('form'));
return $this->fetch("public/form-builder");
}
@ -117,7 +121,7 @@ class Nav extends AuthController
if ($data['url'] == "") return app("json")->fail("链接不能为空");
if ($id == "") {
$data['create_time'] = time();
$res = aModel::insert($data);
$res = aModel::create($data);
} else {
$data['update_time'] = time();
$res = aModel::update($data, ['id' => $id]);

View File

@ -22,7 +22,7 @@ class Page extends AuthController
/**
* 构造方法 初始化一些参数
*/
public function initialize()
public function initialize(): void
{
parent::initialize();
//修正因为修改model名称和原来不能对应导致的model功能异常
@ -34,7 +34,7 @@ class Page extends AuthController
* @return string
* @throws \Exception
*/
public function index()
public function index(): string
{
return $this->fetch();
}
@ -64,8 +64,10 @@ class Page extends AuthController
/**
* 保存
* @param string $id
* @return mixed
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @author 木子的忧伤
* @date 2021-02-28 22:43
*/
@ -85,7 +87,7 @@ class Page extends AuthController
['is_recommend', 0],
['is_top', 0],
['is_hot', 0],
['theme', ''],
['template', ''],
['link_str', ''],
['cover_path', ''],
['display', 1],
@ -96,7 +98,7 @@ class Page extends AuthController
['uid', $this->adminId],
]);
if ($data['title'] == "") return app("json")->fail("文章名称不能为空");
if ($data['theme'] == "") return app("json")->fail("文章模板不能为空");
if ($data['template'] == "") return app("json")->fail("文章模板不能为空");
if ($data['cover_path'] == "") return app("json")->fail("主图不能为空");
$model = new Document();
$res = $model->updateInfo($data, Data::DOCUMENT_TYPE_PAGE);
@ -124,25 +126,25 @@ class Page extends AuthController
* @return string
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @throws ModelNotFoundException|\Exception
* @author 木子的忧伤
* @date 2021-03-10 14:46
*/
public function add()
public function add(): string
{
// 获取页面模板列表
$this->getThemeList();
$themeList = get_theme_list(Data::DOCUMENT_TYPE_PAGE);
$this->assign("theme_list", $themeList);
$templateList = get_template_list(Data::DOCUMENT_TYPE_PAGE);
if (empty($themeList)){
$this->error("模板文件不存在,请检查主题目录或主题配置");
}
$this->assign("template_list", $templateList);
return $this->fetch();
}
/**
* 编辑页
* @return string|void
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @throws \Exception
*/
public function edit()
{
@ -157,8 +159,11 @@ class Page extends AuthController
$this->error('数据不存在');
}
// 获取页面模板列表
$themeList = get_theme_list(Data::DOCUMENT_TYPE_PAGE);
$this->assign("theme_list", $themeList);
$templateList = get_template_list(Data::DOCUMENT_TYPE_PAGE);
if (empty($themeList)){
$this->error("模板文件不存在,请检查主题目录或主题配置");
}
$this->assign("template_list", $templateList);
$this->assign("info", $info);
return $this->fetch();
}

View File

@ -16,13 +16,13 @@ class SystemBasic extends BaseController
/**
* 操作失败提示框
* @param string $msg 提示信息
* @param string $backUrl 跳转地址
* @param string $title 标题
* @param int $backUrl 跳转地址
* @param string $info
* @param int $duration 持续时间
* @return mixed
* @throws Exception
*/
protected function failedNotice($msg = '操作失败', $backUrl = 0, $info = '', $duration = 3)
protected function failedNotice(string $msg = '操作失败', $backUrl = 0, $info = '', $duration = 3)
{
$type = 'error';
$this->assign(compact('msg', 'backUrl', 'info', 'duration', 'type'));
@ -31,13 +31,13 @@ class SystemBasic extends BaseController
/**
* 失败提示一直持续
* @param $msg
* @param string $msg
* @param int $backUrl
* @param string $title
* @param string $info
* @return mixed
* @throws Exception
*/
protected function failedNoticeLast($msg = '操作失败', $backUrl = 0, $info = '')
protected function failedNoticeLast(string $msg = '操作失败', $backUrl = 0, $info = '')
{
return $this->failedNotice($msg, $backUrl, $info, 0);
}
@ -45,8 +45,8 @@ class SystemBasic extends BaseController
/**
* 操作成功提示框
* @param string $msg 提示信息
* @param string $backUrl 跳转地址
* @param string $title 标题
* @param int $backUrl 跳转地址
* @param string $info
* @param int $duration 持续时间
* @return mixed
* @throws Exception
@ -60,13 +60,13 @@ class SystemBasic extends BaseController
/**
* 成功提示一直持续
* @param $msg
* @param string $msg
* @param int $backUrl
* @param string $title
* @param string $info
* @return mixed
* @throws Exception
*/
protected function successfulNoticeLast($msg = '操作成功', $backUrl = 0, $info = '')
protected function successfulNoticeLast(string $msg = '操作成功', $backUrl = 0, $info = '')
{
return $this->successfulNotice($msg, $backUrl, $info, 0);
}
@ -77,7 +77,7 @@ class SystemBasic extends BaseController
* @param int $url
* @throws Exception
*/
protected function failed($msg = '哎呀…亲…您访问的页面出现错误', $url = 0)
protected function failed(string $msg = '哎呀…亲…您访问的页面出现错误', $url = 0)
{
if ($this->request->isAjax()) {
exit(app("json")->fail($msg, $url)->getContent());
@ -93,7 +93,7 @@ class SystemBasic extends BaseController
* @param int $url
* @throws Exception
*/
protected function successful($msg, $url = 0)
protected function successful(string $msg, $url = 0)
{
if ($this->request->isAjax()) {
exit(app("json")->success($msg, $url)->getContent());
@ -104,7 +104,7 @@ class SystemBasic extends BaseController
}
/**异常抛出
* @param $name
* @param string $msg
* @throws Exception
*/
protected function exception($msg = '无法打开页面')

View File

@ -16,6 +16,7 @@ use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\facade\Cache;
use think\Response;
/**
* 系统配置
@ -32,63 +33,65 @@ class SystemConfig extends AuthController
* @throws DbException
* @throws ModelNotFoundException
*/
public function base($tab_id = 1)
public function base($tab_id = 1): string
{
if ($tab_id < 5) {
$system = cModel::getLstByTabId($tab_id);
//特殊处理主题信息,这里不允许修改主题信息
if ($tab_id == 1) {
foreach ($system as $key => &$form) {
if ($form['form_name'] == 'web_template') {
unset($system[$key]);
}
$system = cModel::getLstByTabId($tab_id);
//特殊处理主题信息,这里不允许修改主题信息
if ($tab_id == 1) {
foreach ($system as $key => &$form) {
if ($form['form_name'] == 'web_template') {
unset($system[$key]);
}
}
$where = [
'status' => 1
];
$tabList = tModel::lst($where);
$this->assign("tab_id", $tab_id);
$this->assign("tab_list", $tabList['data']);
$this->assign("system", $system);
return $this->fetch();
}
$where = [
'status' => 1
];
$tabList = tModel::lst($where);
$this->assign("tab_id", $tab_id);
$this->assign("tab_list", $tabList['data']);
$this->assign("system", $system);
return $this->fetch();
}
/**
* @param Request $request
* @return
* @return string
* @throws InvalidArgumentException
* @throws Exception
*/
public function clearCache(Request $request)
{
if ($request->isPost()) {
$adminPath = config("cache.runtime") . "/admin/";
$adminPath = config("cache.runtime") . "/admin/temp";
$commonPath = config("cache.runtime") . "/cache/";
$indexPath = config("cache.runtime") . "/index/";
$apiPath = config("cache.runtime") . "/api/";
$indexPath = config("cache.runtime") . "/index/temp";
$apiPath = config("cache.runtime") . "/api/temp";
Cache::clear();
if (remove_cache($adminPath) && remove_cache($indexPath) && remove_cache($apiPath) && remove_cache($commonPath)) return app("json")->success("操作成功");
return app("json")->error("操作失败");
remove_cache($adminPath);
remove_cache($indexPath);
remove_cache($apiPath);
remove_cache($commonPath);
return app("json")->success("操作成功");
}
return $this->fetch();
}
/**
* 列表
* @param int $tab_id
* @param Request $request
* @return string
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function lst(Request $request)
public function lst(Request $request): Response
{
$where = Util::postMore([
['page', 1],
['limit', 20],
['tab_id', 0]
]);
],$request);
return app("json")->layui(cModel::lst($where));
}
@ -98,9 +101,9 @@ class SystemConfig extends AuthController
* @return string
* @throws Exception
*/
public function index($tab_id = 0)
public function index(int $tab_id = 0): string
{
$this->assign("tab", tModel::get($tab_id));
$this->assign("tab", tModel::find($tab_id));
return $this->fetch("list");
}
@ -110,7 +113,7 @@ class SystemConfig extends AuthController
* @return string
* @throws FormBuilderException
*/
public function add(Request $request)
public function add(Request $request): string
{
$form = array();
$form[] = Elm::hidden('tab_id', $request->param("tab_id"))->col(10);
@ -125,21 +128,24 @@ class SystemConfig extends AuthController
$form[] = Elm::radio('is_show', '是否显示', 1)->options([['label' => '隐藏', 'value' => 0], ['label' => '显示', 'value' => 1]])->col(10);
$form[] = Elm::radio('upload_type', '上传配置', 0)->options([['label' => '单选', 'value' => 0], ['label' => '多选', 'value' => 1]])->col(10);
$form[] = Elm::radio('status', '状态', 1)->options([['label' => '禁用', 'value' => 0], ['label' => '启用', 'value' => 1]])->col(10);
$form = Form::make_post_form($form, url('save')->build());
$form = Form::make_post_form($form, url('/admin/system_config/save')->build());
$this->assign(compact('form'));
return $this->fetch("public/form-builder");
}
/**
* 修改
* @param Request $request
* @param string $id
* @return string
* @throws DataNotFoundException
* @throws DbException
* @throws FormBuilderException
* @throws ModelNotFoundException
*/
public function edit($id = '')
public function edit(string $id = ''): string
{
if (!$id) return app("json")->fail("项目id不能为空");
$info = cModel::get($id);
$info = (new \app\common\model\SystemConfig)->find($id);
if (!$info) return app("json")->fail("没有该项目");
$form = array();
$form[] = Elm::hidden('tab_id', $info['tab_id'])->col(10);
@ -154,7 +160,7 @@ class SystemConfig extends AuthController
$form[] = Elm::radio('is_show', '是否显示', $info['is_show'])->options([['label' => '隐藏', 'value' => 0], ['label' => '显示', 'value' => 1]])->col(10);
$form[] = Elm::radio('upload_type', '上传配置', $info['upload_type'])->options([['label' => '单选', 'value' => 0], ['label' => '多选', 'value' => 1]])->col(10);
$form[] = Elm::radio('status', '状态', $info['status'])->options([['label' => '禁用', 'value' => 0], ['label' => '启用', 'value' => 1]])->col(10);
$form = Form::make_post_form($form, url('save', ["id" => $id])->build());
$form = Form::make_post_form($form, url('/admin/system_config/save', ["id" => $id])->build());
$this->assign(compact('form'));
return $this->fetch("public/form-builder");
}
@ -164,7 +170,7 @@ class SystemConfig extends AuthController
* @param string $id
* @return mixed
*/
public function save($id = "")
public function save(string $id = "")
{
$data = Util::postMore([
['name', ''],
@ -187,7 +193,7 @@ class SystemConfig extends AuthController
if ($id == "") {
$data['create_user'] = $this->adminId;
$data['create_time'] = time();
$res = cModel::insert($data);
$res = cModel::create($data);
} else {
$data['update_user'] = $this->adminId;
$data['update_time'] = time();
@ -201,7 +207,7 @@ class SystemConfig extends AuthController
/**
* 提交修改
* @param Request $request
* @return
* @return mixed
*/
public function ajaxSave(Request $request)
{

View File

@ -13,6 +13,7 @@ use FormBuilder\Factory\Elm;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\Response;
/**
* 管理员配置
@ -21,7 +22,10 @@ use think\db\exception\ModelNotFoundException;
*/
class SystemConfigTab extends AuthController
{
public function index()
/**
* @throws \Exception
*/
public function index(): string
{
return $this->fetch();
}
@ -29,9 +33,12 @@ class SystemConfigTab extends AuthController
/**
* 列表
* @param Request $request
* @return
* @return Response
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function lst(Request $request)
public function lst(Request $request): Response
{
$where = Util::postMore([
['page', 1],
@ -47,34 +54,38 @@ class SystemConfigTab extends AuthController
* @param Request $request
* @return string
* @throws FormBuilderException
* @throws \Exception
*/
public function add(Request $request)
public function add(Request $request): string
{
$form = array();
$form[] = Elm::input('name', '分类名称')->col(10);
$form[] = Elm::number('rank', '排序', 0)->col(24);
$form[] = Elm::radio('status', '状态', 1)->options([['label' => '禁用', 'value' => 0], ['label' => '启用', 'value' => 1]])->col(24);
$form = Form::make_post_form($form, url('save')->build());
$form = Form::make_post_form($form, url('/admin/system_config_tab/save')->build());
$this->assign(compact('form'));
return $this->fetch("public/form-builder");
}
/**
* 修改
* @param Request $request
* @param string $id
* @return string
* @throws DataNotFoundException
* @throws DbException
* @throws FormBuilderException
* @throws ModelNotFoundException
*/
public function edit($id = '')
public function edit($id = ''): string
{
if (!$id) return app("json")->fail("项目id不能为空");
$info = tModel::get($id);
$info = tModel::find($id);
if (!$info) return app("json")->fail("没有该项目");
$form = array();
$form[] = Elm::input('name', '分类名称', $info['name'])->col(10);
$form[] = Elm::number('rank', '排序', $info['rank'])->col(24);
$form[] = Elm::radio('status', '状态', $info['status'])->options([['label' => '禁用', 'value' => 0], ['label' => '启用', 'value' => 1]])->col(24);
$form = Form::make_post_form($form, url('save', ["id" => $id])->build());
$form = Form::make_post_form($form, url('/admin/system_config_tab/save', ["id" => $id])->build());
$this->assign(compact('form'));
return $this->fetch("public/form-builder");
}
@ -84,7 +95,7 @@ class SystemConfigTab extends AuthController
* @param string $id
* @return mixed
*/
public function save($id = "")
public function save(string $id = "")
{
$data = Util::postMore([
['name', ''],
@ -95,7 +106,7 @@ class SystemConfigTab extends AuthController
if ($id == "") {
$data['create_user'] = $this->adminId;
$data['create_time'] = time();
$res = tModel::insert($data);
$res = tModel::create($data);
} else {
$data['update_user'] = $this->adminId;
$data['update_time'] = time();

View File

@ -11,7 +11,10 @@ use app\Request;
*/
trait TemplateTrait
{
public function index()
/**
* @throws \Exception
*/
public function index(): string
{
return $this->fetch();
}

View File

@ -3,6 +3,7 @@
namespace app\admin\controller;
use app\admin\extend\Util as Util;
use app\common\constant\Data;
use app\common\model\SystemConfig as cModel;
use Exception;
@ -21,7 +22,7 @@ class Theme extends AuthController
* @author 木子的忧伤
* @date 2021-02-17 11:40
*/
public function index()
public function index() : string
{
$themeList = [];
// 寻找有多少主题
@ -37,9 +38,9 @@ class Theme extends AuthController
}
$info = json_decode(file_get_contents($themeInfoFile), true);
unset($themeInfoFile);
$info['root_dir'] = $themeDir . "/" . $file . '/';
$info['root_dir'] = $themeDir . "/" . $file ;
$info['dir_name'] = $file;
$info['preview_file'] = file_cdn($themeDir . "/" . $file . '/' . $info['preview_file']);
$info['preview_file'] = file_cdn($themeDir ."/". $file . '/' . $info['preview_file']);
$info['is_default'] = $file == $defaultTheme ? 1 : 0;//检查是不是默认主题
$themeList[] = $info;
}
@ -64,7 +65,7 @@ class Theme extends AuthController
]);
if ($data['value'] == "") return app("json")->fail("主题不能为空");
$res = cModel::update($data, ['form_name' => 'web_template']);
cache(Config::DATA_SYSTEM_CONFIG, null);//清除缓存
cache(Data::DATA_SYSTEM_CONFIG, null);//清除缓存
return $res ? app("json")->success("操作成功", 'code') : app("json")->fail("操作失败");
}
}

View File

@ -13,6 +13,7 @@ use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\facade\Route as Url;
use think\Response;
/**
* 用户管理
@ -28,7 +29,7 @@ class User extends AuthController
* @return string
* @throws Exception
*/
public function index()
public function index(): string
{
return $this->fetch();
}
@ -41,7 +42,7 @@ class User extends AuthController
* @throws DbException
* @throws ModelNotFoundException
*/
public function lst(Request $request)
public function lst(Request $request): Response
{
$where = Util::postMore([
['username', ''],
@ -61,43 +62,48 @@ class User extends AuthController
* @param Request $request
* @return string
* @throws FormBuilderException
* @throws Exception
*/
public function add(Request $request)
public function add(Request $request): string
{
$form = array();
$form[] = Elm::input('username', '登录账号')->col(10);
$form[] = Elm::input('nickname', '昵称')->col(10);
$form[] = Elm::frameImage('avatar', '头像', Url::buildUrl('admin/image/index', array('fodder' => 'avatar', 'limit' => 1)))->icon("ios-image")->width('96%')->height('440px')->col(10);
$form[] = Elm::frameImage('avatar', '头像', Url::buildUrl('/admin/image/index', array('fodder' => 'avatar', 'limit' => 1)))->icon("ios-image")->width('96%')->height('440px')->col(10);
$form[] = Elm::password('password', '密码')->col(10);
$form[] = Elm::input('tel', '电话')->col(10);
$form[] = Elm::email('email', '邮箱')->col(10);
$form[] = Elm::radio('is_admin', '管理员', 0)->options([['label' => '是', 'value' => 1], ['label' => '否', 'value' => 0]])->col(10);
$form[] = Elm::radio('status', '状态', 1)->options([['label' => '启用', 'value' => 1], ['label' => '冻结', 'value' => 0]])->col(10);
$form = Form::make_post_form($form, url('save')->build());
$form = Form::make_post_form($form, url('/admin/user/save')->build());
$this->assign(compact('form'));
return $this->fetch("public/form-builder");
}
/**
* 修改账号
* @param string $id
* @return string
* @throws DataNotFoundException
* @throws DbException
* @throws FormBuilderException
* @throws ModelNotFoundException
*/
public function edit($id = "")
public function edit($id = ""): string
{
if (!$id) return app("json")->fail("账号id不能为空");
$ainfo = aModel::get($id);
if (!$ainfo) return app("json")->fail("没有该账号");
$info = aModel::find($id);
if (!$info) return app("json")->fail("没有该账号");
$form = array();
$form[] = Elm::input('username', '登录账号', $ainfo['username'])->col(10);
$form[] = Elm::input('nickname', '昵称', $ainfo['nickname'])->col(10);
$form[] = Elm::frameImage('avatar', '头像', Url::buildUrl('admin/image/index', array('fodder' => 'avatar', 'limit' => 1)), $ainfo['avatar'])->icon("ios-image")->width('96%')->height('440px')->col(10);
$form[] = Elm::password('password', '密码', $ainfo['password'])->col(10);
$form[] = Elm::input('tel', '电话', $ainfo['tel'])->col(10);
$form[] = Elm::email('email', '邮箱', $ainfo['email'])->col(10);
$form[] = Elm::radio('is_admin', '管理员', $ainfo['is_admin'])->options([['label' => '是', 'value' => 1], ['label' => '否', 'value' => 0]])->col(10);
$form[] = Elm::radio('status', '状态', $ainfo['status'])->options([['label' => '启用', 'value' => 1], ['label' => '冻结', 'value' => 0]])->col(10);
$form = Form::make_post_form($form, url('save', ['id' => $id])->build());
$form[] = Elm::input('username', '登录账号', $info['username'])->col(10);
$form[] = Elm::input('nickname', '昵称', $info['nickname'])->col(10);
$form[] = Elm::frameImage('avatar', '头像', Url::buildUrl('/admin/image/index', array('fodder' => 'avatar', 'limit' => 1)), $info['avatar'])->icon("ios-image")->width('96%')->height('440px')->col(10);
$form[] = Elm::password('password', '密码', $info['password'])->col(10);
$form[] = Elm::input('tel', '电话', $info['tel'])->col(10);
$form[] = Elm::email('email', '邮箱', $info['email'])->col(10);
$form[] = Elm::radio('is_admin', '管理员', $info['is_admin'])->options([['label' => '是', 'value' => 1], ['label' => '否', 'value' => 0]])->col(10);
$form[] = Elm::radio('status', '状态', $info['status'])->options([['label' => '启用', 'value' => 1], ['label' => '冻结', 'value' => 0]])->col(10);
$form = Form::make_post_form($form, url('/admin/user/save', ['id' => $id])->build());
$this->assign(compact('form'));
return $this->fetch("public/form-builder");
}
@ -106,8 +112,11 @@ class User extends AuthController
* 保存修改
* @param string $id
* @return mixed
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function save($id = "")
public function save(string $id = "")
{
$data = Util::postMore([
['username', ''],
@ -135,8 +144,8 @@ class User extends AuthController
$data['create_user'] = $this->adminId;
$res = aModel::create($data);
} else {
$ainfo = aModel::get($id);
if ($ainfo['password'] != $data['password']) $data['password'] = md5(md5($data['password']));
$info = (new \app\common\model\User)->find($id);
if ($info['password'] != $data['password']) $data['password'] = md5(md5($data['password']));
$data['update_user'] = $this->adminId;
$res = aModel::update($data, ['id' => $id]);
}

View File

@ -17,10 +17,10 @@ class FormBuilder
* 生成表单
* @param $rule
* @param $url
* @return string
* @return IviewForm
* @throws FormBuilderException
*/
public static function make_post_form($rule, $url)
public static function make_post_form($rule, $url): IviewForm
{
$form = new IviewForm($url);
$form->setMethod('POST');

View File

@ -17,19 +17,19 @@ class Util
* @param bool $suffix
* @return array
*/
public static function postMore($params, $request = null, $suffix = false)
public static function postMore($params, $request = null, $suffix = false): array
{
if ($request === null) $request = app('request');
$p = [];
$i = 0;
foreach ($params as $param) {
if (!is_array($param)) {
$p[$suffix == true ? $i++ : $param] = $request->param($param, '', 'trim');
$p[$suffix ? $i++ : $param] = $request->param($param, '', 'trim');
} else {
if (!isset($param[1])) $param[1] = null;
if (!isset($param[2])) $param[2] = 'trim'; //默认去除空
$name = is_array($param[1]) ? $param[0] . '/a' : $param[0];
$p[$suffix == true ? $i++ : (isset($param[3]) ? $param[3] : $param[0])] = $request->param($name, $param[1], $param[2]);
$p[$suffix ? $i++ : ($param[3] ?? $param[0])] = $request->param($name, $param[1], $param[2]);
}
}
return $p;
@ -42,19 +42,19 @@ class Util
* @param bool $suffix
* @return array
*/
public static function getMore($params, $request = null, $suffix = false)
public static function getMore($params, $request = null, $suffix = false): array
{
if ($request === null) $request = app('request');
$p = [];
$i = 0;
foreach ($params as $param) {
if (!is_array($param)) {
$p[$suffix == true ? $i++ : $param] = $request->param($param);
$p[$suffix ? $i++ : $param] = $request->param($param);
} else {
if (!isset($param[1])) $param[1] = null;
if (!isset($param[2])) $param[2] = 'trim'; //默认去除空
$name = is_array($param[1]) ? $param[0] . '/a' : $param[0];
$p[$suffix == true ? $i++ : (isset($param[3]) ? $param[3] : $param[0])] = $request->param($name, $param[1], $param[2]);
$p[$suffix ? $i++ : ($param[3] ?? $param[0])] = $request->param($name, $param[1], $param[2]);
}
}
return $p;

View File

@ -1,9 +1,10 @@
<?php
namespace app\common\model;
namespace app\admin\model;
use app\common\constant\Data;
use app\common\model\BaseModel;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
@ -18,8 +19,8 @@ class Admin extends BaseModel
{
/**
* 登录
* @param $username
* @param $pwd
* @param string $username
* @param string $pwd
* @return bool
* @throws DataNotFoundException
* @throws DbException
@ -27,7 +28,7 @@ class Admin extends BaseModel
*/
public static function login(string $username, string $pwd): bool
{
$info = self::where("username|tel", "=", $username)->find();
$info = (new Admin)->where("username|tel", "=", $username)->find();
if (empty($info)) return self::setErrorInfo("登录账号不存在");
if ($info['password'] != md5(md5($pwd))) return self::setErrorInfo("密码不正确!");
if ($info['status'] != 1) return self::setErrorInfo("账号已被冻结!");
@ -40,7 +41,7 @@ class Admin extends BaseModel
* @param $info
* @return bool
*/
public static function setLoginInfo($info)
public static function setLoginInfo($info): bool
{
unset($info->password);//去除密码字段
$info->role_auth = AdminRole::getAuth($info['role_id'] ?? 0);//提前缓存auth字段避免频繁查询
@ -53,7 +54,7 @@ class Admin extends BaseModel
/**
* 退出登录
*/
public static function clearLoginInfo()
public static function clearLoginInfo(): bool
{
Session::delete(Data::SESSION_KEY_ADMIN_ID);
Session::delete(Data::SESSION_KEY_ADMIN_INFO);
@ -78,7 +79,7 @@ class Admin extends BaseModel
if ($where['tel'] != '') $model = $model->where("tel|mail", "like", "%$where[tel]%");
if ($where['status'] != '') $model = $model->where("status", $where['status']);
if ($where['role_id'] != '') $model = $model->where("role_id", $where['role_id']);
$count = self::counts($model);
$count = self::count();
if ($where['page'] && $where['limit']) $model = $model->page((int)$where['page'], (int)$where['limit']);
$data = $model->select()->each(function ($item) {
unset($item['password']);

View File

@ -1,9 +1,10 @@
<?php
namespace app\common\model;
namespace app\admin\model;
use app\common\model\BaseModel;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
@ -40,6 +41,24 @@ class AdminAuth extends BaseModel
return $authList[$module . '_' . $controller . '_' . $action] ?? -1;
}
/**
* 获取用户权限列表
* @param $admin_id
* @param $auth
* @return array|mixed|object|\think\App
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public static function getAuthList($admin_id,$auth){
$menuList = cache(self::getMenuCacheKey($admin_id));
if ($menuList === null) {
$menuList = self::getMenu(0, $auth);
cache(AdminAuth::getMenuCacheKey($admin_id), $menuList, 1 * 60 * 60);
}
return $menuList;
}
/**
* 获取菜单
* @param int $pid
@ -114,7 +133,7 @@ class AdminAuth extends BaseModel
* @author 木子的忧伤
* @date 2021-06-09 17:24
*/
public static function getMenuCacheKey($adminId)
public static function getMenuCacheKey($adminId): string
{
return 'menu:List:' . $adminId;
}
@ -124,7 +143,7 @@ class AdminAuth extends BaseModel
* @author 木子的忧伤
* @date 2021-06-15 11:11
*/
public static function getAuthCacheKey()
public static function getAuthCacheKey(): string
{
return 'auth:key:list';
}
@ -142,10 +161,10 @@ class AdminAuth extends BaseModel
* @param int $num
* @param bool $clear
*/
public static function myOptions(array $data, &$list, $num = 0, $clear = true)
public static function myOptions(array $data, &$list, $num = 0, bool $clear = true)
{
foreach ($data as $k => $v) {
$list[] = ['value' => $v['id'], 'label' => self::cross($num) . $v['name']];
$list[] = ['value' => $v['id'], 'label' => cross($num) . $v['name']];
if (is_array($v['children']) && !empty($v['children'])) {
self::myOptions($v['children'], $list, $num + 1, false);
}
@ -167,21 +186,6 @@ class AdminAuth extends BaseModel
return $list;
}
/**
* 横线
* @param int $num
* @return string
*/
public static function cross(int $num = 0): string
{
$str = "";
if ($num == 1) $str .= "|--";
elseif ($num > 1) for ($i = 0; $i < $num; $i++)
if ($i == 0) $str .= "|--";
else $str .= "--";
return $str . " ";
}
/**
* 生成treeData
* @param int $pid
@ -214,8 +218,8 @@ class AdminAuth extends BaseModel
*/
public static function getIds(array $ids = []): array
{
if (empty($ids)) return self::where("status", 1)->column("id");
$pids = self::where("id", "in", $ids)->column("pid");
if (empty($ids)) return (new AdminAuth)->where("status", 1)->column("id");
$pids = (new AdminAuth)->where("id", "in", $ids)->column("pid");
return array_merge($ids, $pids) ?: [];
}
@ -226,7 +230,7 @@ class AdminAuth extends BaseModel
* @param string $action
* @return string
*/
public static function getNameByAction(string $module, string $controller, string $action)
public static function getNameByAction(string $module, string $controller, string $action): string
{
return self::where("module", $module)->where("controller", $controller)->where("action", $action)->value("name") ?: '未知操作';
}

View File

@ -1,9 +1,10 @@
<?php
namespace app\common\model;
namespace app\admin\model;
use app\common\model\BaseModel;
use think\db\exception\DbException;
/**
@ -24,7 +25,7 @@ class AdminLog extends BaseModel
*/
public static function saveLog(array $adminInfo, string $module, string $controller, string $action): bool
{
return self::create([
return (bool)self::create([
'admin_id' => $adminInfo['id'],
'admin_name' => $adminInfo['username'],
'module' => $module,
@ -33,7 +34,7 @@ class AdminLog extends BaseModel
'ip' => request()->ip(),
'create_time' => time(),
'user_agent' => substr(request()->server('HTTP_USER_AGENT'), 0, 255),
]) ? true : false;
]);
}
/**
@ -42,7 +43,7 @@ class AdminLog extends BaseModel
* @return array
* @throws DbException
*/
public static function systemPage($where)
public static function systemPage($where): array
{
$model = new self;
$model = $model->order("id desc");
@ -50,7 +51,7 @@ class AdminLog extends BaseModel
if ($where['ip'] != '') $model = $model->where('ip', "like", "%$where[ip]%");
if ($where['start_time'] != '') $model = $model->where('create_time', '>', strtotime($where['start_time'] . " 00:00:00"));
if ($where['end_time'] != '') $model = $model->where('create_time', '<', strtotime($where['end_time'] . " 23:59:59"));
$count = self::counts($model);
$count = self::count();
if (!empty($where['page']) && !empty($where['limit'])) $model = $model->page((int)$where['page'], (int)$where['limit']);
$data = $model->select()->each(function ($item) {
$item['name'] = AdminAuth::getNameByAction($item['module'], $item['controller'], $item['action']);

View File

@ -1,9 +1,10 @@
<?php
namespace app\common\model;
namespace app\admin\model;
use app\common\model\BaseModel;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
@ -30,7 +31,7 @@ class AdminNotify extends BaseModel
}
if ($where['title'] != '') $model = $model->where("title|content", "like", "%$where[title]%");
if ($where['is_read'] != '') $model = $model->where("is_read", $where['is_read']);
if ($where['aid'] != '') $model = $model->where("aid", $where['aid']);
if ($where['uid'] != '') $model = $model->where("uid", $where['uid']);
$model = $model->order("is_read");
$model = $model->order("create_time desc");
return $model->paginate(10)->appends($where);
@ -41,24 +42,29 @@ class AdminNotify extends BaseModel
* @param array $data
* @return int|string
*/
public static function addLog(array $data)
public static function addLog(array $data): bool
{
return self::insert($data);
if (self::create($data)){
return true;
}else{
return false;
}
}
/**
* 后台首页获取通知信息
* @param $uid
* @param int $num
* @return array
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public static function pageList(int $num)
public static function pageList($uid,int $num): array
{
$model = new self;
$model = $model->where("is_read", 0);
$count = self::counts($model);
$model = $model->where("is_read", 0)->where("uid",$uid);
$count = self::count();
$model = $model->order("create_time desc");
$model = $model->page(1, $num);
$data = $model->select();

View File

@ -1,9 +1,10 @@
<?php
namespace app\common\model;
namespace app\admin\model;
use app\common\model\BaseModel;
use FormBuilder\Factory\Elm;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
@ -23,7 +24,7 @@ class AdminRole extends BaseModel
*/
public static function getAuth(int $id): string
{
return self::where("id", $id)->value("auth") ?: '';
return (new AdminRole)->where("id", $id)->value("auth") ?: '';
}
/**
@ -35,7 +36,7 @@ class AdminRole extends BaseModel
*/
public static function getAuthLst(): array
{
$data = self::where("status", 1)->field("id,name")->select();
$data = (new AdminRole)->where("status", 1)->field("id,name")->select();
return $data ? $data->toArray() : [];
}
@ -46,13 +47,12 @@ class AdminRole extends BaseModel
*/
public static function getAuthNameById(int $id): string
{
return self::where("id", $id)->value("name") ?: (string)$id;
return (new AdminRole)->where("id", $id)->value("name") ?: (string)$id;
}
/**
* 角色列表
* @param int $pid
* @param array $auth
* @return array
* @throws DataNotFoundException
* @throws DbException
@ -96,10 +96,10 @@ class AdminRole extends BaseModel
* @param int $num
* @param bool $clear
*/
public static function myOptions(array $data, &$list, $num = 0, $clear = true)
public static function myOptions(array $data, &$list, int $num = 0, bool $clear = true): void
{
foreach ($data as $k => $v) {
$list[] = ['value' => $v['id'], 'label' => self::cross($num) . $v['name']];
foreach ($data as $v) {
$list[] = ['value' => $v['id'], 'label' => cross($num) . $v['name']];
if (is_array($v['children']) && !empty($v['children'])) {
self::myOptions($v['children'], $list, $num + 1, false);
}
@ -121,28 +121,14 @@ class AdminRole extends BaseModel
return $list;
}
/**
* 横线
* @param int $num
* @return string
*/
public static function cross(int $num = 0): string
{
$str = "";
if ($num == 1) $str .= "|--";
elseif ($num > 1) for ($i = 0; $i < $num; $i++)
if ($i == 0) $str .= "|--";
else $str .= "--";
return $str . " ";
}
/**
* 生成单个节点
* @param $id
* @param $title
* @param array $children
* @return array
*/
public static function buildTreeData($id, $title, $children = []): array
public static function buildTreeData($id, $title, array $children = []): array
{
$tree = Elm::TreeData($id, $title);
if (!empty($children)) $tree = $tree->children($children);

View File

@ -3,7 +3,7 @@
namespace app\admin\subscribes;
use app\common\model\AdminLog;
use app\admin\model\AdminLog;
/**
* 操作员日志记录
@ -16,7 +16,7 @@ class AdminSubscribe
* 记录操作日志
* @param $event
*/
public function onAdminLog($event)
public function onAdminLog($event): void
{
list($adminInfo, $module, $controller, $action) = $event;
AdminLog::saveLog($adminInfo, $module, $controller, $action);

View File

@ -97,7 +97,7 @@
<div class="card">
<div class="card-body">
<div class="edit-avatar">
<img src="{$info.avatar}" alt="{$info.name}" class="img-avatar">
<img src="{$info.avatar}" alt="{$info.nickname}" class="img-avatar">
<div class="avatar-divider"></div>
<div class="edit-avatar-content">
<button class="btn btn-default trigger-btn">修改头像</button>
@ -109,7 +109,7 @@
<input type="hidden" class="form-control" name="avatar" id="avatar" value="{$info.avatar}"/>
<div class="form-group">
<label for="name">用户名</label>
<input type="text" class="form-control" name="name" id="name" value="{$info.name}"
<input type="text" class="form-control" name="username" id="username" value="{$info.username}"
disabled="disabled"/>
</div>
<div class="form-group">

View File

@ -67,7 +67,7 @@
<script type="text/javascript">
$('#tb_departments').bootstrapTable({
classes: 'table table-bordered table-hover table-striped',
url: '/admin/admin_log/Lst',
url: '/admin/admin_log/lst',
method: 'post',
dataType: 'json', // 因为本示例中是跨域的调用,所以涉及到ajax都采用jsonp,
uniqueId: 'id',

View File

@ -6,7 +6,7 @@
<!--标签插件-->
<link rel="stylesheet" href="/static/admin/js/jquery-tags-input/jquery.tagsinput.min.css">
<!--富文本输入框-->
<link rel="stylesheet" href="/static/admin/js/summernote/summernote.min.css">
<link href="https://cdn.staticfile.org/wangeditor5/5.1.23/css/style.min.css" rel="stylesheet">
</head>
<body>
<div class="row">
@ -74,8 +74,12 @@
placeholder="请输入标签">
</div>
<div class="form-group col-md-12">
<label for="content">文章内容</label>
<textarea id="content" name="content" data-provide="summernote" data-toolbar="full"></textarea>
<label for="editor-text-area">文章内容</label>
<div style="border: 1px solid #ccc;">
<div id="editor-toolbar" style="border-bottom: 1px solid #ccc;"></div>
<div id="editor-text-area" style="height: 500px"></div>
</div>
<textarea id="content" name="content" style="display: none;"></textarea>
</div>
<div class="form-group col-md-12">
<button type="submit" class="btn btn-primary ajax-post" target-form="add-form">立即提交
@ -155,8 +159,7 @@
<!--select2-->
<script type="text/javascript" src="/static/admin/js/select2.min.js"></script>
<!--富文本输入框-->
<script type="text/javascript" src="/static/admin/js/summernote/summernote.min.js"></script>
<script type="text/javascript" src="/static/admin/js/summernote/lang/summernote-zh-CN.min.js"></script>
<script src="https://cdn.staticfile.org/wangeditor5/5.1.23/index.js"></script>
<!--标签-->
<script src="/static/admin/js/jquery-tags-input/jquery.tagsinput.min.js"></script>
<script>
@ -164,51 +167,36 @@
$('#tag').select2();
});
$(document).ready(function(){
$('[data-provide="summernote"]').each(function() {
var options = {
dialogsInBody: true,
lang: 'zh-CN',
dialogsFade: true,
height:400
};
var config = {};
$.each( $(this).data(), function(key, value){
key = key.replace(/-([a-z])/g, function(x){return x[1].toUpperCase();});
if ( key == 'provide' ) {
return;
var E = window.wangEditor
// 切换语言
var LANG = location.href.indexOf('lang=en') > 0 ? 'en' : 'zh-CN'
E.i18nChangeLanguage(LANG)
window.editor = E.createEditor({
selector: '#editor-text-area',
html: '<p><br></p>',
config: {
placeholder: '请输入...',
MENU_CONF: {
uploadImage: {
fieldName: 'your-fileName',
base64LimitSize: 10 * 1024 * 1024 // 10M 以下插入 base64
}
},
onChange(editor) {
let content = editor.getHtml()
console.log('editor content', content)
// 也可以同步到 <textarea>
$("#content").val(content)
}
config[key] = value;
});
}
})
options = $.extend(options, config);
options.toolbar = [
// [groupName, [list of button]]
['para_style', ['style']],
['style', ['bold', 'italic', 'underline', 'clear']],
['font', ['strikethrough', 'superscript', 'subscript']],
['fontsize', ['fontname', 'fontsize', 'height']],
['color', ['color']],
['para', ['ul', 'ol', 'paragraph', 'hr']],
['table', ['table']],
['insert', ['link', 'picture', 'video']],
['do', ['undo', 'redo']],
['misc', ['fullscreen', 'codeview', 'help']]
];
$(this).summernote(options);
});
window.toolbar = E.createToolbar({
editor,
selector: '#editor-toolbar',
config: {}
})
$(document).on('click', '[data-summernote-edit]', function(){
var target = $(this).data('summernote-edit');
$(target).summernote({focus: true});
});
$(document).on('click', '[data-summernote-save]', function(){
var target = $(this).data('summernote-save');
var markup = $(target).summernote('code');
$(target).summernote('destroy');
alert('修改完成');
});
});
/**

View File

@ -6,7 +6,7 @@
<!--标签插件-->
<link rel="stylesheet" href="/static/admin/js/jquery-tags-input/jquery.tagsinput.min.css">
<!--富文本输入框-->
<link rel="stylesheet" href="/static/admin/js/summernote/summernote.min.css">
<link href="https://cdn.staticfile.org/wangeditor5/5.1.23/css/style.min.css" rel="stylesheet">
</head>
<body>
<div class="row">
@ -93,8 +93,12 @@
placeholder="请输入标签" value="{$info.tags}">
</div>
<div class="form-group col-md-12">
<label for="content">文章内容</label>
<textarea id="content" name="content" data-provide="summernote" data-toolbar="full">{$info.content}</textarea>
<label for="editor-text-area">文章内容</label>
<div style="border: 1px solid #ccc;">
<div id="editor-toolbar" style="border-bottom: 1px solid #ccc;"></div>
<div id="editor-text-area" style="height: 500px"></div>
</div>
<textarea id="content" name="content" style="display: none;">{$info.content}</textarea>
</div>
<div class="form-group col-md-12">
<button type="submit" class="btn btn-primary ajax-post" target-form="add-form">立即提交
@ -175,8 +179,7 @@
<!--select2-->
<script type="text/javascript" src="/static/admin/js/select2.min.js"></script>
<!--富文本输入框-->
<script type="text/javascript" src="/static/admin/js/summernote/summernote.min.js"></script>
<script type="text/javascript" src="/static/admin/js/summernote/lang/summernote-zh-CN.min.js"></script>
<script src="https://cdn.staticfile.org/wangeditor5/5.1.23/index.js"></script>
<!--标签-->
<script src="/static/admin/js/jquery-tags-input/jquery.tagsinput.min.js"></script>
<script>
@ -184,51 +187,37 @@
$('#tag').select2();
});
$(document).ready(function(){
$('[data-provide="summernote"]').each(function() {
var options = {
dialogsInBody: true,
lang: 'zh-CN',
dialogsFade: true,
height:400
};
var config = {};
$.each( $(this).data(), function(key, value){
key = key.replace(/-([a-z])/g, function(x){return x[1].toUpperCase();});
if ( key == 'provide' ) {
return;
var E = window.wangEditor
// 切换语言
var LANG = location.href.indexOf('lang=en') > 0 ? 'en' : 'zh-CN'
E.i18nChangeLanguage(LANG)
//需要判断是否含有html标签
window.editor = E.createEditor({
selector: '#editor-text-area',
html: $('#content').val(), // 从 editor.getHtml() 获取的 html 内容
config: {
placeholder: '请输入...',
MENU_CONF: {
uploadImage: {
fieldName: 'your-fileName',
base64LimitSize: 10 * 1024 * 1024 // 10M 以下插入 base64
}
},
onChange(editor) {
let content = editor.getHtml()
console.log('editor content', content)
// 也可以同步到 <textarea>
$("#content").val(content)
}
config[key] = value;
});
}
})
options = $.extend(options, config);
options.toolbar = [
// [groupName, [list of button]]
['para_style', ['style']],
['style', ['bold', 'italic', 'underline', 'clear']],
['font', ['strikethrough', 'superscript', 'subscript']],
['fontsize', ['fontname', 'fontsize', 'height']],
['color', ['color']],
['para', ['ul', 'ol', 'paragraph', 'hr']],
['table', ['table']],
['insert', ['link', 'picture', 'video']],
['do', ['undo', 'redo']],
['misc', ['fullscreen', 'codeview', 'help']]
];
$(this).summernote(options);
});
window.toolbar = E.createToolbar({
editor,
selector: '#editor-toolbar',
config: {}
})
$(document).on('click', '[data-summernote-edit]', function(){
var target = $(this).data('summernote-edit');
$(target).summernote({focus: true});
});
$(document).on('click', '[data-summernote-save]', function(){
var target = $(this).data('summernote-save');
var markup = $(target).summernote('code');
$(target).summernote('destroy');
alert('修改完成');
});
});
/**

View File

@ -58,7 +58,7 @@
<script type="text/javascript">
$('#tb_departments').bootstrapTable({
classes: 'table table-bordered table-hover table-striped',
url: '/admin/article/Lst',
url: '/admin/article/lst',
method: 'post',
dataType: 'json', // 因为本示例中是跨域的调用,所以涉及到ajax都采用jsonp,
uniqueId: 'id',

View File

@ -41,7 +41,7 @@
<div class="form-group form-controls">
<select name="template" class="form-control">
{volist name="template_list" id="vo"}
<option value="{$vo.template}">{$vo.name}</option>
<option value="{$vo}">{$vo}</option>
{/volist}
</select>
</div>

View File

@ -42,7 +42,7 @@
<div class="form-group form-controls">
<select name="template" class="form-control">
{volist name="template_list" id="vo"}
<option value="{$vo.template}" {notempty name="info.template" }{if $vo.template== $info.template}selected{/if}{/notempty}>{$vo.name}</option>
<option value="{$vo}" {notempty name="info.template" }{if $vo == $info.template}selected{/if}{/notempty}>{$vo}</option>
{/volist}
</select>
</div>

View File

@ -49,7 +49,7 @@
var loadIndex;
$('#tb_departments').bootstrapTable({
classes: 'table table-bordered table-hover table-striped',
url: '/admin/databases/Lst',
url: '/admin/databases/lst',
method: 'post',
dataType: 'json', // 因为本示例中是跨域的调用,所以涉及到ajax都采用jsonp,
uniqueId: 'id',

View File

@ -25,7 +25,7 @@
<script type="text/javascript">
$('#tb_departments').bootstrapTable({
classes: 'table table-bordered table-hover table-striped',
url: '/admin/databases/Lst?type=import',
url: '/admin/databases/lst?type=import',
method: 'post',
dataType: 'json', // 因为本示例中是跨域的调用,所以涉及到ajax都采用jsonp,
uniqueId: 'id',

View File

@ -38,9 +38,10 @@
<aside class="lyear-layout-sidebar">
<!-- logo -->
<div id="logo" class="sidebar-header">
<a href="/admin/index/index.html"><img src="/static/admin/img/logo-sidebar.png"
title="{:system_config('title')}后台管理系统"
alt="{:system_config('title')}后台管理系统"/></a>
<a href="/admin/index/index.html">
<img src="/static/admin/img/logo-sidebar.png" title="{:system_config('title')}后台管理系统"
alt="{:system_config('title')}后台管理系统"/>
</a>
</div>
<div class="lyear-layout-sidebar-scroll">
<nav class="sidebar-main">
@ -96,7 +97,7 @@
<li class="dropdown dropdown-profile">
<a href="javascript:void(0)" data-toggle="dropdown">
<img class="img-avatar img-avatar-48 m-r-10" src="{$adminInfo.avatar}"
alt="{$adminInfo.nickname}" style="width: 32px;height: 32px;"/>
alt="{$adminInfo.nickname}" onerror="this.src='/static/admin/img/avatar.png'" style="width: 32px;height: 32px;"/>
<span>{$adminInfo.nickname} <span class="caret"></span></span>
</a>
<ul class="dropdown-menu dropdown-menu-right">

View File

@ -69,6 +69,40 @@
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-header">
<h4>项目信息</h4>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>#</th>
<th>文章标题</th>
<th>文章分类</th>
<th>发布时间</th>
</tr>
</thead>
<tbody>
{volist name="article_list" id="vo"}
<tr>
<td>{$vo.id}</td>
<td>{$vo.title}</td>
<td>{$vo.category_title}</td>
<td>{$vo.create_time}</td>
</tr>
{/volist}
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript" src="/static/admin/js/jquery.min.js"></script>

View File

@ -64,7 +64,7 @@
<script type="text/javascript">
$('#tb_departments').bootstrapTable({
classes: 'table table-bordered table-hover table-striped',
url: '/admin/invitation/Lst',
url: '/admin/invitation/lst',
method: 'post',
dataType: 'json', // 因为本示例中是跨域的调用,所以涉及到ajax都采用jsonp,
uniqueId: 'id',

View File

@ -74,7 +74,7 @@
<script type="text/javascript">
$('#tb_departments').bootstrapTable({
classes: 'table table-bordered table-hover table-striped',
url: '/admin/message/Lst',
url: '/admin/message/lst',
method: 'post',
dataType: 'json', // 因为本示例中是跨域的调用,所以涉及到ajax都采用jsonp,
uniqueId: 'id',

View File

@ -6,7 +6,7 @@
<!--标签插件-->
<link rel="stylesheet" href="/static/admin/js/jquery-tags-input/jquery.tagsinput.min.css">
<!--富文本输入框-->
<link rel="stylesheet" href="/static/admin/js/summernote/summernote.min.css">
<link href="https://cdn.staticfile.org/wangeditor5/5.1.23/css/style.min.css" rel="stylesheet">
</head>
<body>
<div class="row">
@ -31,9 +31,9 @@
<div class="col-xs-4">
<label>展示模板</label>
<div class="form-group form-controls">
<select name="theme" id="theme" class="form-control">
<select name="template" id="template" class="form-control">
<option value="0">请选择</option>
{volist name="theme_list" id="vo"}
{volist name="template_list" id="vo"}
<option value="{$vo}">{$vo}</option>
{/volist}
</select>
@ -90,9 +90,13 @@
<input class="form-control js-tags-input" type="text" name="tags" data-height="38px"
placeholder="请输入标签">
</div>
<div class="form-group col-md-12">
<label for="content">页面内容</label>
<textarea id="content" name="content" data-provide="summernote" data-toolbar="full"></textarea>
<div class="form-group col-md-12">
<label for="editor-text-area">页面内容</label>
<div style="border: 1px solid #ccc;">
<div id="editor-toolbar" style="border-bottom: 1px solid #ccc;"></div>
<div id="editor-text-area" style="height: 500px"></div>
</div>
<textarea id="content" name="content" style="display: none;"></textarea>
</div>
<div class="form-group col-md-12">
<button type="submit" class="btn btn-primary ajax-post" target-form="add-form">立即提交
@ -107,8 +111,7 @@
<!--select2-->
<script type="text/javascript" src="/static/admin/js/select2.min.js"></script>
<!--富文本输入框-->
<script type="text/javascript" src="/static/admin/js/summernote/summernote.min.js"></script>
<script type="text/javascript" src="/static/admin/js/summernote/lang/summernote-zh-CN.min.js"></script>
<script src="https://cdn.staticfile.org/wangeditor5/5.1.23/index.js"></script>
<!--标签-->
<script src="/static/admin/js/jquery-tags-input/jquery.tagsinput.min.js"></script>
<script>
@ -116,51 +119,36 @@
$('#tag').select2();
});
$(document).ready(function(){
$('[data-provide="summernote"]').each(function() {
var options = {
dialogsInBody: true,
lang: 'zh-CN',
dialogsFade: true,
height:400
};
var config = {};
$.each( $(this).data(), function(key, value){
key = key.replace(/-([a-z])/g, function(x){return x[1].toUpperCase();});
if ( key == 'provide' ) {
return;
var E = window.wangEditor
// 切换语言
var LANG = location.href.indexOf('lang=en') > 0 ? 'en' : 'zh-CN'
E.i18nChangeLanguage(LANG)
window.editor = E.createEditor({
selector: '#editor-text-area',
html: '<p><br></p>',
config: {
placeholder: '请输入...',
MENU_CONF: {
uploadImage: {
fieldName: 'your-fileName',
base64LimitSize: 10 * 1024 * 1024 // 10M 以下插入 base64
}
},
onChange(editor) {
let content = editor.getHtml()
console.log('editor content', content)
// 也可以同步到 <textarea>
$("#content").val(content)
}
config[key] = value;
});
}
})
options = $.extend(options, config);
options.toolbar = [
// [groupName, [list of button]]
['para_style', ['style']],
['style', ['bold', 'italic', 'underline', 'clear']],
['font', ['strikethrough', 'superscript', 'subscript']],
['fontsize', ['fontname', 'fontsize', 'height']],
['color', ['color']],
['para', ['ul', 'ol', 'paragraph', 'hr']],
['table', ['table']],
['insert', ['link', 'picture', 'video']],
['do', ['undo', 'redo']],
['misc', ['fullscreen', 'codeview', 'help']]
];
$(this).summernote(options);
});
window.toolbar = E.createToolbar({
editor,
selector: '#editor-toolbar',
config: {}
})
$(document).on('click', '[data-summernote-edit]', function(){
var target = $(this).data('summernote-edit');
$(target).summernote({focus: true});
});
$(document).on('click', '[data-summernote-save]', function(){
var target = $(this).data('summernote-save');
var markup = $(target).summernote('code');
$(target).summernote('destroy');
alert('修改完成');
});
});
/**

View File

@ -6,7 +6,7 @@
<!--标签插件-->
<link rel="stylesheet" href="/static/admin/js/jquery-tags-input/jquery.tagsinput.min.css">
<!--富文本输入框-->
<link rel="stylesheet" href="/static/admin/js/summernote/summernote.min.css">
<link href="https://cdn.staticfile.org/wangeditor5/5.1.23/css/style.min.css" rel="stylesheet">
</head>
<body>
<div class="row">
@ -32,10 +32,10 @@
<div class="col-xs-4">
<label>展示模板</label>
<div class="form-group form-controls">
<select name="theme" id="theme" class="form-control">
<select name="template" id="template" class="form-control">
<option value="0">请选择</option>
{volist name="theme_list" id="vo"}
<option value="{$vo}" {if $vo == $info.theme}selected{/if}>{$vo}</option>
{volist name="template_list" id="vo"}
<option value="{$vo}" {if $vo == $info.template}selected{/if}>{$vo}</option>
{/volist}
</select>
</div>
@ -106,9 +106,13 @@
<label for="abstract">标签</label>
<input class="form-control js-tags-input" type="text" name="tags" data-height="38px" value="{$info.tags}" placeholder="请输入标签">
</div>
<div class="form-group col-md-12">
<label for="content">页面内容</label>
<textarea id="content" name="content" data-provide="summernote" data-toolbar="full">{$info.content}</textarea>
<div class="form-group col-md-12">
<label for="editor-text-area">页面内容</label>
<div style="border: 1px solid #ccc;">
<div id="editor-toolbar" style="border-bottom: 1px solid #ccc;"></div>
<div id="editor-text-area" style="height: 500px"></div>
</div>
<textarea id="content" name="content" style="display: none;">{$info.content}</textarea>
</div>
<div class="form-group col-md-12">
<button type="submit" class="btn btn-primary ajax-post" target-form="add-form">立即提交
@ -123,8 +127,7 @@
<!--select2-->
<script type="text/javascript" src="/static/admin/js/select2.min.js"></script>
<!--富文本输入框-->
<script type="text/javascript" src="/static/admin/js/summernote/summernote.min.js"></script>
<script type="text/javascript" src="/static/admin/js/summernote/lang/summernote-zh-CN.min.js"></script>
<script src="https://cdn.staticfile.org/wangeditor5/5.1.23/index.js"></script>
<!--标签-->
<script src="/static/admin/js/jquery-tags-input/jquery.tagsinput.min.js"></script>
<script>
@ -132,51 +135,37 @@
$('#tag').select2();
});
$(document).ready(function(){
$('[data-provide="summernote"]').each(function() {
var options = {
dialogsInBody: true,
lang: 'zh-CN',
dialogsFade: true,
height:400
};
var config = {};
$.each( $(this).data(), function(key, value){
key = key.replace(/-([a-z])/g, function(x){return x[1].toUpperCase();});
if ( key == 'provide' ) {
return;
var E = window.wangEditor
// 切换语言
var LANG = location.href.indexOf('lang=en') > 0 ? 'en' : 'zh-CN'
E.i18nChangeLanguage(LANG)
//需要判断是否含有html标签
window.editor = E.createEditor({
selector: '#editor-text-area',
html: $('#content').val(), // 从 editor.getHtml() 获取的 html 内容
config: {
placeholder: '请输入...',
MENU_CONF: {
uploadImage: {
fieldName: 'your-fileName',
base64LimitSize: 10 * 1024 * 1024 // 10M 以下插入 base64
}
},
onChange(editor) {
let content = editor.getHtml()
console.log('editor content', content)
// 也可以同步到 <textarea>
$("#content").val(content)
}
config[key] = value;
});
}
})
options = $.extend(options, config);
options.toolbar = [
// [groupName, [list of button]]
['para_style', ['style']],
['style', ['bold', 'italic', 'underline', 'clear']],
['font', ['strikethrough', 'superscript', 'subscript']],
['fontsize', ['fontname', 'fontsize', 'height']],
['color', ['color']],
['para', ['ul', 'ol', 'paragraph', 'hr']],
['table', ['table']],
['insert', ['link', 'picture', 'video']],
['do', ['undo', 'redo']],
['misc', ['fullscreen', 'codeview', 'help']]
];
$(this).summernote(options);
});
window.toolbar = E.createToolbar({
editor,
selector: '#editor-toolbar',
config: {}
})
$(document).on('click', '[data-summernote-edit]', function(){
var target = $(this).data('summernote-edit');
$(target).summernote({focus: true});
});
$(document).on('click', '[data-summernote-save]', function(){
var target = $(this).data('summernote-save');
var markup = $(target).summernote('code');
$(target).summernote('destroy');
alert('修改完成');
});
});
/**

View File

@ -58,7 +58,7 @@
<script type="text/javascript">
$('#tb_departments').bootstrapTable({
classes: 'table table-bordered table-hover table-striped',
url: '/admin/page/Lst',
url: '/admin/page/lst',
method: 'post',
dataType: 'json', // 因为本示例中是跨域的调用,所以涉及到ajax都采用jsonp,
uniqueId: 'id',

View File

@ -0,0 +1,58 @@
<?php
namespace app\api\controller;
use app\admin\extend\Util;
use app\common\constant\Data;
use app\common\model\Document;
use app\Request;
use think\Exception;
use think\facade\Log;
use think\Response;
class Article extends Base
{
public function list(){
$where = Util::postMore([
['cid',''],
['typeId', ''],
['orderBy', 'sort asc,create_time desc'],
['row', 100],
['void', 'field'],
['model', "article"],
['type', "find"],
['where', ""],
['display',1],
['ids',""],
['page',1],
['limit',20],
]);
$list = tpl_get_article_list($where['cid'], $where['row'], $where['orderby'], $where['model'], $where['type'], $where['where'], $where['display'], $where['ids']);
return app("json")->layui($list);
}
/**
* @param Request $request
* @return mixed
* @throws Exception
*/
public function detail(Request $request)
{
$where = Util::postMore([
['id', ''],
],$request);
if (empty($where['id'])){
return app("json")->fail("参数错误");
}
//获取该文章
$documentModel = new Document();
$article = $documentModel->getFullInfo($where['id'], Data::DOCUMENT_TYPE_ARTICLE);
$article['cover_path'] = file_cdn($article['cover_path']);
if (!$article) {
return app("json")->fail("文章不存在或已删除");
}
return app("json")->success($article,'code');
}
}

View File

@ -0,0 +1,30 @@
<?php
declare (strict_types=1);
namespace app\api\controller;
use app\BaseController;
use app\common\constant\Data;
use app\common\model\PvLog;
use app\common\model\UrlLog;
use think\facade\Session;
/**
* 控制器基础类
*/
class Base extends BaseController
{
/**
* 当前登陆用户信息
* @var
*/
protected $userInfo;
/**
* 当前登陆用户ID
* @var int
*/
protected $userId;
// 初始化
}

View File

@ -1,41 +1,32 @@
<?php
namespace app\index\controller;
namespace app\api\controller;
use app\admin\controller\AuthController;
use app\admin\extend\Util as Util;
use app\common\constant\Data;
use app\common\model\FriendLink as friendLinkModel;
use app\common\model\MessageForm as MessageFormModel;
use app\common\model\Tag as TagModel;
use app\common\validate\MessageForm as MessageformValidate;
use app\Request;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use app\common\model\SystemConfig;
/**
* 应用入口
* Class Index
* @package app\index\controller
*/
class Index extends AuthController
class Index extends Base
{
/**
* 入口跳转链接
*/
public function index()
public function index() : string
{
//判断后台统计配置是否开启 1 开启
if (web_config("web_statistics") == 1) {
//统计url
$this->urlrecord('网站首页');
return app("json")->success("获取成功", 'code');
}
public function config(){
$systemConfig = cache(Data::DATA_SYSTEM_CONFIG);
if (empty($systemConfig)) {
$systemConfig = SystemConfig::getSystemConfigValues();
cache(Data::DATA_SYSTEM_CONFIG, $systemConfig);
}
//清除可能存在的栏目分类树id
cache(Data::CURR_CATEGORY_PATENT_ID, false);
//模板兼容性标签
$this->assign('id', false);
$this->assign('cid', false);
return $this->fetch();
return app("json")->success($systemConfig,"code");
}
}

View File

@ -0,0 +1,90 @@
<?php
namespace app\api\controller;
use app\admin\controller\AuthController;
use app\admin\extend\Util as Util;
use app\admin\model\Admin as adminModel;
use Exception;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\Response;
class Login extends Base
{
/**
* 无需登录使用jwt
* @var array
*/
protected $noNeedLogin = ['login', 'register', 'forget', 'captcha', 'verify'];
/**
* 登录
* @return string
* @throws Exception
*/
public function login()
{
return $this->fetch();
}
/**
* 验证登录
* @return mixed
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function verify()
{
list($username, $password, $captcha) = Util::postMore(['username', 'password', 'captcha'], null, true);
if (empty($username) || empty($password)) return app("json")->fail("账号、密码和验证码不能为空!");
// 验证码验证
if (!captcha_check($captcha)) return app("json")->fail("验证码不正确!");
// 验证登录
if (!adminModel::login($username, $password)) return app("json")->fail(adminModel::getErrorInfo());
return app("json")->success("登录成功!");
}
/**
* 注册
* @return string
* @throws Exception
*/
public function register(): string
{
return $this->fetch();
}
/**
* 忘记密码
* @return string
* @throws Exception
*/
public function forget(): string
{
return $this->fetch();
}
/**
* 退出登陆
* @return mixed
* @throws Exception
*/
public function logout()
{
return adminModel::clearLoginInfo() ? $this->successfulNotice("操作成功", "/admin/login/login") : $this->failedNotice("操作失败", "/admin/index/index");
}
/**
* 验证码
* @return Response
*/
public function captcha(): Response
{
ob_clean();
return captcha();
}
}

View File

@ -0,0 +1,8 @@
<?php
namespace app\api\controller;
class Page extends Base
{
}

View File

@ -0,0 +1,10 @@
<?php
namespace app\api\controller;
class User extends Base
{
public function info(){
}
}

View File

@ -24,17 +24,18 @@ if (!function_exists('param_to_array')) {
}
}
if (!function_exists('get_File_type')) {
if (!function_exists('get_file_type')) {
/**
* 获取文件类型
* @param string $mime
* @return string
*/
function get_File_type(string $mime): string
function get_file_type(string $mime): string
{
if (stristr($mime, 'image')) return 'image';
elseif (stristr($mime, 'video')) return 'video';
elseif (stristr($mime, 'audio')) return 'audio';
else return 'file';
}
}
@ -115,20 +116,22 @@ if (!function_exists('unicode_decode')) {
*
* @return string
*/
function server_url()
{
if (isset($_SERVER['HTTPS']) && ('1' == $_SERVER['HTTPS'] || 'on' == strtolower($_SERVER['HTTPS']))) {
$http = 'https://';
} elseif (isset($_SERVER['SERVER_PORT']) && ('443' == $_SERVER['SERVER_PORT'])) {
$http = 'https://';
} else {
$http = 'http://';
if (!function_exists('file_cdn')) {
function server_url(): string
{
if (isset($_SERVER['HTTPS']) && ('1' == $_SERVER['HTTPS'] || 'on' == strtolower($_SERVER['HTTPS']))) {
$http = 'https://';
} elseif (isset($_SERVER['SERVER_PORT']) && ('443' == $_SERVER['SERVER_PORT'])) {
$http = 'https://';
} else {
$http = 'http://';
}
$host = $_SERVER['HTTP_HOST'];
$res = $http . $host;
return $res;
}
$host = $_SERVER['HTTP_HOST'];
$res = $http . $host;
return $res;
}
if (!function_exists('file_cdn')) {
@ -139,7 +142,7 @@ if (!function_exists('file_cdn')) {
* @author 木子的忧伤
* @date 2021-02-17 23:32
*/
function file_cdn($path)
function file_cdn($path): string
{
if (empty($path)) {
return '';
@ -152,15 +155,15 @@ if (!function_exists('file_cdn')) {
$path = str_replace(public_path(), '', $path);
//转换因为win导致的兼容问题
if(strtoupper(substr(PHP_OS,0,3))==='WIN'){
$path = str_replace( DIRECTORY_SEPARATOR, '/',$path);
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$path = str_replace(DIRECTORY_SEPARATOR, '/', $path);
}
if (!(substr($path, 0, 1) == '/')) {
//统一路径
$path = '/' . $path;
}
return (config("app.cdn_url")?:$server_url = server_url()) . $path;
return (config("app.cdn_url") ?: $server_url = server_url()) . $path;
}
}
@ -172,13 +175,13 @@ if (!function_exists('get_rand_str')) {
* @author 木子的忧伤
* @date 2022-04-11 18:26
*/
function get_rand_str($length){
function get_rand_str($length): string
{
//字符组合
$str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890';
$randStr = str_shuffle($str);//打乱字符串
$randstr= substr($randStr,0,$length);//substr(string,start,length);返回字符串的一部分
$randstr = md5($randstr.time());
$randstr = substr($randstr,5,$length);
return $randstr;
$randStr = substr($randStr, 0, $length);//substr(string,start,length);返回字符串的一部分
$randStr = md5($randStr . time());
return substr($randStr, 5, $length);
}
}

View File

@ -116,7 +116,7 @@ class Json
/**
* layui返回
* @param array|string $msg
* @param array $data
* @param array|null $data
* @return Response
*/
public function layui($msg = '', ?array $data = []): Response

View File

@ -32,7 +32,7 @@ class Advert extends BaseModel
if ($where['start_time'] != '') $model = $model->where("create_time", ">", strtotime($where['start_time'] . " 00:00:00"));
if ($where['end_time'] != '') $model = $model->where("create_time", "<", strtotime($where['end_time'] . " 23:59:59"));
if ($where['status'] != '') $model = $model->where("status", $where['status']);
$count = self::counts($model);
$count = self::count();
if ($where['page'] && $where['limit']) $model = $model->page((int)$where['page'], (int)$where['limit']);
$data = $model->select()->each(function ($item) {
if (!empty($item->pic)) {

View File

@ -33,7 +33,7 @@ class AdvertInfo extends BaseModel
if ($where['start_time'] != '') $model = $model->where("create_time", ">", strtotime($where['start_time'] . " 00:00:00"));
if ($where['end_time'] != '') $model = $model->where("create_time", "<", strtotime($where['end_time'] . " 23:59:59"));
if ($where['status'] != '') $model = $model->where("status", $where['status']);
$count = self::counts($model);
$count = $model->count();
if ($where['page'] && $where['limit']) $model = $model->page((int)$where['page'], (int)$where['limit']);
$data = $model->select()->each(function ($item) {
if (!empty($item->pic)) {

View File

@ -4,6 +4,10 @@
namespace app\common\model;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
/**
* Class attachment
* @package app\admin\model\widget
@ -38,12 +42,15 @@ class Attachment extends BaseModel
* 分页显示
* @param array $where
* @return array
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public static function pagination(array $where)
public static function pagination(array $where): array
{
$model = self::where("type", $where['type']);
$model = (new Attachment)->where("type", $where['type']);
if ($where['cid'] != "") $model = $model->where("cid", $where['cid']);
$count = self::counts($model);
$count = (new Attachment)->count();
$model = $model->order("id desc");
$model = $model->field("id,path");
$data = $model->page((int)$where['page'], (int)$where['limit'])->select();

View File

@ -4,6 +4,7 @@
namespace app\common\model;
use think\db\exception\DbException;
use think\facade\Db;
use think\Model;
@ -16,6 +17,25 @@ class BaseModel extends Model
private static $transaction = 0;
private static $DbInstance = [];
/**
* 错误信息,解决调用无法明确错误的问题
* @var mixed
*/
protected $error;
/**
* 获取错误信息
* @access public
* @return mixed
*/
public function getError()
{
return $this->error;
}
//自动时间戳
protected $autoWriteTimestamp = true;
/**
* 获取错误信息
* @param string $defaultMsg
@ -27,53 +47,18 @@ class BaseModel extends Model
}
/**
* 开启事务
* 查询一条数据是否存在
* @param $map
* @param string $field
* @return bool 是否存在
* @throws DbException
*/
public static function beginTrans()
public static function isExist($map, $field = ''): bool
{
Db::startTrans();
}
/**
* 根据结果提交滚回事务
* @param $res
*/
public static function checkTrans($res)
{
if ($res) {
self::commitTrans();
} else {
self::rollbackTrans();
}
}
/**
* 提交事务
*/
public static function commitTrans()
{
Db::commit();
}
/**
* 设置错误信息
* @param string $errorMsg
* @param bool $rollback
* @return bool
*/
protected static function setErrorInfo($errorMsg = self::DEFAULT_ERROR_MSG, $rollback = false)
{
if ($rollback) self::rollbackTrans();
self::$errorMsg = $errorMsg;
return false;
}
/**
* 关闭事务
*/
public static function rollbackTrans()
{
Db::rollback();
$model = (new self);
if (!is_array($map) && empty($field)) $field = $model->getPk();
$map = !is_array($map) ? [$field => $map] : $map;
return 0 < $model->where($map)->count();
}
}

View File

@ -34,7 +34,7 @@ class Comment extends BaseModel
if (isset($where['tel']) && $where['tel'] !== '') $model->where('tel', "like", "%$where[tel]%");
if (isset($where['start_time']) && $where['start_time'] != '') $model = $model->where("m.created_at", ">", strtotime($where['start_time'] . " 00:00:00"));
if (isset($where['end_time']) && $where['end_time'] != '') $model = $model->where("m.created_at", "<", strtotime($where['end_time'] . " 23:59:59"));
$count = self::counts($model);
$count = self::count();
if ($where['page'] && $where['limit']) $model = $model->page((int)$where['page'], (int)$where['limit']);
$data = $model->select();
if ($data) $data = $data->toArray();

View File

@ -33,12 +33,12 @@ class Document extends BaseModel
{
$model = new self;
$model = $model->where("type", "=", $where['type'] ?? Data::DOCUMENT_TYPE_ARTICLE);
if ($where['title'] != '') $model = $model->where("title", "like", "%$where[title]%");
if ($where['start_time'] != '') $model = $model->where("create_time", ">", strtotime($where['start_time'] . " 00:00:00"));
if ($where['end_time'] != '') $model = $model->where("create_time", "<", strtotime($where['end_time'] . " 23:59:59"));
if ($where['status'] != '') $model = $model->where("status", $where['status']);
if (!empty($where['title'])) $model = $model->where("title", "like", "%$where[title]%");
if (!empty($where['start_time'])) $model = $model->where("create_time", ">", strtotime($where['start_time'] . " 00:00:00"));
if (!empty($where['end_time'])) $model = $model->where("create_time", "<", strtotime($where['end_time'] . " 23:59:59"));
if (!empty($where['status'])) $model = $model->where("status", $where['status']);
$model = $model->order("sort desc")->order("id desc");
$count = self::counts($model);
$count = self::count();
if ($where['page'] && $where['limit']) $model = $model->page((int)$where['page'], (int)$where['limit']);
$categoryList = DocumentCategory::column('title', 'id');
$data = $model->select()->each(function ($item) use ($categoryList) {
@ -51,8 +51,11 @@ class Document extends BaseModel
* 获取文章信息
* @param $id
* @param string $type
* @param string $status
* @param int $status
* @return array
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function getInfo($id, string $type = Data::DOCUMENT_TYPE_ARTICLE, $status = 1): array
{
@ -82,24 +85,15 @@ class Document extends BaseModel
if (!$info) {
return [];
}
$info->comment = (new Comment())->where('document_id', $id)->count();
return $info->toArray();
}
/**
* 更新文件信息
* @param $dat
* @param $data
* @param string $type
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
/**
* 更新文件信息
* @param $dat
* @param string $type
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @return bool
*/
public function updateInfo($data, string $type = Data::DOCUMENT_TYPE_ARTICLE)
{
@ -114,13 +108,14 @@ class Document extends BaseModel
if ($data['is_hot']) $data['is_hot'] = 1;
if ($data['display']) $data['display'] = 1;
if ($data['is_top']) $data['is_top'] = 1;
if ($data['is_jump']) $data['is_jump'] = 1;
if (!empty($data['is_jump'])) $data['is_jump'] = 1;
//判断是否主键冲突
$info = $this->where("alias", $data['alias'])->find();
if ($info && (!empty($data['id']) && $info->id != $data['id'])) {
self::setErrorInfo("别名已存在,请修改后重试");
return false;
}
$model = null;
switch ($type) {
case Data::DOCUMENT_TYPE_ARTICLE:
$contentData = [
@ -164,7 +159,7 @@ class Document extends BaseModel
$tagModel->createTags($data['tags'], $id, $data['uid']);
}
} else {
$ainfo = Document::get($data['id']);
$ainfo = Document::find($data['id']);
if (!$ainfo) return app("json")->fail("数据不存在");
Document::where('id', $data['id'])->update($data);
if (!empty($content)) {
@ -192,4 +187,50 @@ class Document extends BaseModel
}
return $res;
}
/**
* 获取文章信息
* @param $id
* @param string $type
* @param int $status
* @return array
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function getFullInfo($id, string $type = Data::DOCUMENT_TYPE_ARTICLE, $status = 1): array
{
if (empty($id)) {
return [];
}
$model = new Document();
$model = $model->alias('a')
->leftJoin('document_category c', 'c.id = a.category_id')
->leftJoin('user u', 'u.id = a.uid')
->field("a.*,p.content,c.title,c.alias,u.nickname,u.avatar,u.remark")
;
if (is_numeric($id)) {
$model->where("a.id", $id);
} else {
$model->where("a.alias", $id);
}
if ($type !== '') $model->where("a.type", $type);
if ($status !== '') $model->where("a.status", $status);
switch ($type) {
case Data::DOCUMENT_TYPE_ARTICLE:
$model->leftJoin('document_article p', 'a.id = p.id');
break;
case Data::DOCUMENT_TYPE_PAGE:
$model->leftJoin('document_page p', 'a.id = p.id');
break;
case Data::DOCUMENT_TYPE_PRODUCT:
$model->leftJoin('document_product p', 'a.id = p.id');
break;
}
$info = $model->find();
if (!$info) {
return [];
}
return $info->toArray();
}
}

View File

@ -29,7 +29,7 @@ class DocumentProduct extends BaseModel
public static function systemPage($where): array
{
$model = new self;
$count = self::counts($model);
$count = self::count();
if ($where['page'] && $where['limit']) $model = $model->page((int)$where['page'], (int)$where['limit']);
$data = $model->select();
if ($data) $data = $data->toArray();

View File

@ -33,7 +33,7 @@ class FriendLink extends BaseModel
if ($where['start_time'] != '') $model = $model->where("create_time", ">", strtotime($where['start_time'] . " 00:00:00"));
if ($where['end_time'] != '') $model = $model->where("create_time", "<", strtotime($where['end_time'] . " 23:59:59"));
if ($where['status'] != '') $model = $model->where("status", $where['status']);
$count = self::counts($model);
$count = self::count();
if ($where['page'] && $where['limit']) $model = $model->page((int)$where['page'], (int)$where['limit']);
$data = $model->select();
if ($data) $data = $data->toArray();

View File

@ -31,7 +31,7 @@ class InvitationCode extends BaseModel
$model = new self;
$model = $model->order('id', 'desc');
if (isset($where['code']) && $where['code'] !== '') $model->where('code', "like", "%$where[code]%");
$count = self::counts($model);
$count = self::count();
if ($where['page'] && $where['limit']) $model = $model->page((int)$where['page'], (int)$where['limit']);
$data = $model->select();
if ($data) $data = $data->toArray();

View File

@ -0,0 +1,72 @@
<?php
namespace app\common\model;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\Paginator;
/**
* 消息通知
* Class AdminNotify
* @package app\admin\model\admin
*/
class Message extends BaseModel
{
/**
* 系统分页
* @param array $where
* @return Paginator
* @throws DbException
*/
public static function systemPage(array $where)
{
$model = new self;
if ($where['start_time'] != "" && $where['end_time'] != "") {
$model = $model->where("create_time", "between", [strtotime($where['start_time'] . " 00:00:00"), strtotime($where['end_time'] . " 23:59:59")]);
}
if ($where['title'] != '') $model = $model->where("title|content", "like", "%$where[title]%");
if ($where['is_read'] != '') $model = $model->where("is_read", $where['is_read']);
if ($where['uid'] != '') $model = $model->where("aid", $where['aid']);
$model = $model->order("is_read");
$model = $model->order("create_time desc");
return $model->paginate(10)->appends($where);
}
/**
* 添加记录
* @param array $data
* @return int|string
*/
public static function addLog(array $data): bool
{
if (self::create($data)){
return true;
}else{
return false;
}
}
/**
* 后台首页获取通知信息
* @param int $num
* @return array
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public static function pageList(int $num): array
{
$model = new self;
$model = $model->where("is_read", 0);
$count = self::count();
$model = $model->order("create_time desc");
$model = $model->page(1, $num);
$data = $model->select();
if ($data) $data = $data->toArray();
return compact("data", "count");
}
}

View File

@ -34,7 +34,7 @@ class MessageForm extends BaseModel
if (isset($where['tel']) && $where['tel'] !== '') $model->where('tel', "like", "%$where[tel]%");
if (isset($where['start_time']) && $where['start_time'] != '') $model = $model->where("m.created_at", ">", strtotime($where['start_time'] . " 00:00:00"));
if (isset($where['end_time']) && $where['end_time'] != '') $model = $model->where("m.created_at", "<", strtotime($where['end_time'] . " 23:59:59"));
$count = self::counts($model);
$count = self::count();
if ($where['page'] && $where['limit']) $model = $model->page((int)$where['page'], (int)$where['limit']);
$data = $model->select();
if ($data) $data = $data->toArray();

View File

@ -4,387 +4,14 @@
namespace app\common\model;
use think\db\BaseQuery;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\db\Raw;
use think\Model;
trait ModelTrait
{
/**
* 错误信息,解决调用无法明确错误的问题
* @var mixed
*/
protected $error;
/**
* 获取错误信息
* @access public
* @return mixed
*/
public function getError()
{
return $this->error;
}
public static function get($where)
{
if (!is_array($where)) {
return self::find($where);
} else {
return self::where($where)->find();
}
}
public static function all($function)
{
$query = self::newQuery();
$function($query);
return $query->select();
}
/**
* 添加多条数据
* @param $group
* @param bool $replace
* @return mixed
*/
public static function setAll($group, $replace = false)
{
return self::insertAll($group, $replace);
}
/**
* 修改一条数据
* @param $data
* @param $id
* @param $field
* @return bool $type 返回成功失败
*/
public static function edit($data, $id, $field = null)
{
$model = new self;
if (!$field) $field = $model->getPk();
// return false !== $model->update($data,[$field=>$id]);
// return 0 < $model->update($data,[$field=>$id])->result;
$res = $model->update($data, [$field => $id]);
if (isset($res->result))
return 0 < $res->result;
else if (isset($res['data']['result']))
return 0 < $res['data']['result'];
else
return false !== $res;
}
/**
* 查询一条数据是否存在
* @param $map
* @param string $field
* @return bool 是否存在
*/
public static function be($map, $field = '')
{
$model = (new self);
if (!is_array($map) && empty($field)) $field = $model->getPk();
$map = !is_array($map) ? [$field => $map] : $map;
return 0 < $model->where($map)->count();
}
/**
* 删除一条数据
* @param $id
* @return bool $type 返回成功失败
*/
public static function del($id)
{
return false !== self::destroy($id);
}
/**
* 分页
* @param null $model 模型
* @param null $eachFn 处理结果函数
* @param array $params 分页参数
* @param int $limit 分页数
* @return array
*/
public static function page($model = null, $eachFn = null, $params = [], $limit = 20)
{
if (is_numeric($eachFn) && is_numeric($model)) {
return parent::page($model, $eachFn);
}
if (is_numeric($eachFn)) {
$limit = $eachFn;
$eachFn = null;
} else if (is_array($eachFn)) {
$params = $eachFn;
$eachFn = null;
}
if (is_callable($model)) {
$eachFn = $model;
$model = null;
} elseif (is_numeric($model)) {
$limit = $model;
$model = null;
} elseif (is_array($model)) {
$params = $model;
$model = null;
}
if (is_numeric($params)) {
$limit = $params;
$params = [];
}
$paginate = $model === null ? self::paginate($limit, false, ['query' => $params]) : $model->paginate($limit, false, ['query' => $params]);
$list = is_callable($eachFn) ? $paginate->each($eachFn) : $paginate;
$page = $list->render();
$total = $list->total();
return compact('list', 'page', 'total');
}
/**
* 获取分页 生成where 条件和 whereOr 支持多表查询生成条件
* @param object $model 模型对象
* @param array $where 需要检索的数组
* @param array $field where字段名
* @param array $fieldOr whereOr字段名
* @param array $fun 闭包函数
* @param string $like 模糊查找 关键字
* @return array
*/
public static function setWherePage($model = null, $where = [], $field = [], $fieldOr = [], $fun = null, $like = 'LIKE')
{
if (!is_array($where) || !is_array($field)) return false;
if ($model === null) $model = new self();
//处理等于行查询
foreach ($field as $key => $item) {
if (($count = strpos($item, '.')) === false) {
if (isset($where[$item]) && $where[$item] != '') {
$model = $model->where($item, $where[$item]);
}
} else {
$item_l = substr($item, $count + 1);
if (isset($where[$item_l]) && $where[$item_l] != '') {
$model = $model->where($item, $where[$item_l]);
}
}
}
//回收变量
unset($count, $key, $item, $item_l);
//处理模糊查询
if (!empty($fieldOr) && is_array($fieldOr) && isset($fieldOr[0])) {
if (($count = strpos($fieldOr[0], '.')) === false) {
if (isset($where[$fieldOr[0]]) && $where[$fieldOr[0]] != '') {
$model = $model->where(self::get_field($fieldOr), $like, "%" . $where[$fieldOr[0]] . "%");
}
} else {
$item_l = substr($fieldOr[0], $count + 1);
if (isset($where[$item_l]) && $where[$item_l] != '') {
$model = $model->where(self::get_field($fieldOr), $like, "%" . $where[$item_l] . "%");
}
}
}
unset($count, $key, $item, $item_l);
return $model;
}
/**
* 字符串拼接
* @param int|array $id
* @param string $str
* @return string
*/
private static function get_field($id, $str = '|')
{
if (is_array($id)) {
$sql = "";
$i = 0;
foreach ($id as $val) {
$i++;
if ($i < count($id)) {
$sql .= $val . $str;
} else {
$sql .= $val;
}
}
return $sql;
} else {
return $id;
}
}
/**
* 条件切割
* @param string $order
* @param string $file
* @return string
*/
public static function setOrder($order, $file = '-')
{
if (empty($order)) return '';
return str_replace($file, ' ', $order);
}
/**
* 获取时间段之间的model
* @param int|string $time
* @param string $ceil
* @return array
*/
public static function getModelTime($where, $model = null, $prefix = 'add_time', $data = 'data', $field = ' - ')
{
if ($model == null) $model = new self;
if (!isset($where[$data])) return $model;
switch ($where[$data]) {
case 'today':
case 'week':
case 'month':
case 'year':
case 'yesterday':
$model = $model->whereTime($prefix, $where[$data]);
break;
case 'quarter':
list($startTime, $endTime) = self::getMonth();
$model = $model->where($prefix, '>', strtotime($startTime));
$model = $model->where($prefix, '<', strtotime($endTime));
break;
case 'lately7':
$model = $model->where($prefix, 'between', [strtotime("-7 day"), time()]);
break;
case 'lately30':
$model = $model->where($prefix, 'between', [strtotime("-30 day"), time()]);
break;
default:
if (strstr($where[$data], $field) !== false) {
list($startTime, $endTime) = explode($field, $where[$data]);
$model = $model->where($prefix, '>', strtotime($startTime));
$model = $model->where($prefix, '<', strtotime($endTime));
}
break;
}
return $model;
}
/**
* 获取去除html去除空格去除软回车,软换行,转换过后的字符串
* @param string $str
* @return string
*/
public static function HtmlToMbStr($str)
{
return trim(strip_tags(str_replace(["\n", "\t", "\r", " ", "&nbsp;"], '', htmlspecialchars_decode($str))));
}
/**
* 截取中文指定字节
* @param string $str
* @param int $utf8len
* @param string $chaet
* @param string $file
* @return string
*/
public static function getSubstrUTf8($str, $utf8len = 100, $chaet = 'UTF-8', $file = '....')
{
if (mb_strlen($str, $chaet) > $utf8len) {
$str = mb_substr($str, 0, $utf8len, $chaet) . $file;
}
return $str;
}
/**
* 获取本季度 time
* @param int|string $time
* @param string $ceil
* @return array
*/
public static function getMonth($time = '', $ceil = 0)
{
if ($ceil != 0)
$season = ceil(date('n') / 3) - $ceil;
else
$season = ceil(date('n') / 3);
$firstday = date('Y-m-01', mktime(0, 0, 0, ($season - 1) * 3 + 1, 1, date('Y')));
$lastday = date('Y-m-t', mktime(0, 0, 0, $season * 3, 1, date('Y')));
return array($firstday, $lastday);
}
/**
* 高精度 加法
* @param int|string $uid id
* @param string $decField 相加的字段
* @param float|int $dec 加的值
* @param string $keyField id的字段
* @param int $acc 精度
* @return bool
*/
public static function bcInc($key, $incField, $inc, $keyField = null, $acc = 2)
{
if (!is_numeric($inc)) return false;
$model = new self();
if ($keyField === null) $keyField = $model->getPk();
$result = self::where($keyField, $key)->find();
if (!$result) return false;
$new = bcadd($result[$incField], $inc, $acc);
return false !== $model->where($keyField, $key)->update([$incField => $new]);
}
/**
* 高精度 减法
* @param int|string $uid id
* @param string $decField 相减的字段
* @param float|int $dec 减的值
* @param string $keyField id的字段
* @param bool $minus 是否可以为负数
* @param int $acc 精度
* @return bool
*/
public static function bcDec($key, $decField, $dec, $keyField = null, $minus = false, $acc = 2)
{
if (!is_numeric($dec)) return false;
$model = new self();
if ($keyField === null) $keyField = $model->getPk();
$result = self::where($keyField, $key)->find();
if (!$result) return false;
if (!$minus && $result[$decField] < $dec) return false;
$new = bcsub($result[$decField], $dec, $acc);
return false !== $model->where($keyField, $key)->update([$decField => $new]);
}
/**
* @param null $model
* @return Model
*/
protected static function getSelfModel($model = null)
{
return $model == null ? (new self()) : $model;
}
/**
* 数据个数
* @param string|Raw $model
* @return int
*/
public static function counts($model): int
{
return $model->count();
}
/**
* 横线
* @param int $num
* @return string
*/
public static function cross(int $num = 0): string
{
$str = "";
if ($num == 1) $str .= "|--";
elseif ($num > 1) for ($i = 0; $i < $num; $i++)
if ($i == 0) $str .= "|--";
else $str .= "--";
return $str . " ";
}
}

View File

@ -67,7 +67,7 @@ class Nav extends BaseModel
public static function myOptions(array $data, &$list, $num = 0, $clear = true)
{
foreach ($data as $k => $v) {
$list[] = ['value' => $v['id'], 'label' => self::cross($num) . $v['title']];
$list[] = ['value' => $v['id'], 'label' => cross($num) . $v['title']];
if (is_array($v['children']) && !empty($v['children'])) {
self::myOptions($v['children'], $list, $num + 1, false);
}
@ -89,21 +89,6 @@ class Nav extends BaseModel
return $list;
}
/**
* 横线
* @param int $num
* @return string
*/
public static function cross(int $num = 0): string
{
$str = "";
if ($num == 1) $str .= "|--";
elseif ($num > 1) for ($i = 0; $i < $num; $i++)
if ($i == 0) $str .= "|--";
else $str .= "--";
return $str . " ";
}
/**
* 生成单个节点
* @param $id

View File

@ -12,24 +12,20 @@ use app\common\model\UvLog as UvLogModel;
*/
class PvLog extends BaseModel
{
//自动时间戳
protected $autoWriteTimestamp = true;
public function del_data()
{
//获取七天前日期
$dateinfo = date('Y-m-d', strtotime('-7 days'));
$date_info = date('Y-m-d', strtotime('-7 days'));
//转换为时间戳
$shijianchuo = strtotime($dateinfo);
$start_time = strtotime($date_info);
//删除pv
$this->where('create_time', '<', $shijianchuo)->delete();
$this->where('create_time', '<', $start_time)->delete();
//删除url
$urlLogModel = new UrlLogModel();
$urlLogModel->where('create_time', '<', $shijianchuo)->delete();
$urlLogModel->where('create_time', '<', $start_time)->delete();
//删除uv
$uvLogModel = new UvLogModel();
$uvLogModel->where('create_time', '<', $shijianchuo)->delete();
$uvLogModel->where('create_time', '<', $start_time)->delete();
}
public function set_view()
@ -39,15 +35,17 @@ class PvLog extends BaseModel
$hour = date('H');
$pvWhere[] = ['date', '=', $date_data];
$pvWhere[] = ['time', '=', $hour];
$pvLogModel = new self;
$pvInfo = $pvLogModel->where($pvWhere)->field('id')->find();
$pvInfo = $this->where($pvWhere)->field('id')->find();
if ($pvInfo) {
$this->where($pvWhere)->inc('view')->update();
$pvLogModel->where($pvWhere)->inc('view')->update();
} else {
$pvData['view'] = 1;
$pvData['date'] = $date_data;
$pvData['time'] = $hour;
$this->save($pvData);
$pvLogModel = new self;
$pvLogModel->view = 1;
$pvLogModel->date = $date_data;
$pvLogModel->time = $hour;
$pvLogModel->save();
}
//uv表
$uvLogModel = new UvLogModel();
@ -61,12 +59,11 @@ class PvLog extends BaseModel
$uvInfo = $uvLogModel->where($uvWhere)->field('id')->find();
//不存在 添加数据
if (!$uvInfo) {
$uvData['ip'] = $ipData;
$uvData['time'] = $hour;
$uvData['date'] = $date_data;
$uvLogModel->save($uvData);
$uvInfo = new UvLogModel();
$uvInfo->ip = $ipData;
$uvInfo->time = $hour;
$uvInfo->date = $date_data;
$uvInfo->save();
}
}
}

View File

@ -17,7 +17,7 @@ class SystemConfig extends BaseModel
{
/**
* 列表
* @param int $tab_id
* @param $where
* @return array
* @throws DataNotFoundException
* @throws DbException
@ -27,7 +27,7 @@ class SystemConfig extends BaseModel
{
$model = new self;
if ($where['tab_id']) $model = $model->where('tab_id', $where['tab_id']);
$count = self::counts($model);
$count = (new SystemConfig)->count();
if ($where['page'] && $where['limit']) $model = $model->page((int)$where['page'], (int)$where['limit']);
$data = $model->select();
if ($data) $data = $data->toArray();

View File

@ -20,12 +20,12 @@ class SystemConfigTab extends BaseModel
* @author 木子的忧伤
* @date 2022-02-28 9:19
*/
public static function lst($where)
public static function lst($where): array
{
$model = new self;
if ($where['status'] != "") $model = $model->where("status", $where['status']);
if (!empty($where['name'])) $model = $model->where("name", "like", "%$where[name]%");
$count = self::counts($model);
$count = self::count();
if (isset($where['page']) && isset($where['limit'])) $model = $model->page((int)$where['page'], (int)$where['limit']);
$data = $model->select();
if ($data) $data = $data->toArray();

View File

@ -17,6 +17,8 @@ use think\db\exception\ModelNotFoundException;
*/
class Tag extends BaseModel
{
protected static $cache_key = 'index:tagList';
/**
* 列表
* @param $where
@ -34,7 +36,7 @@ class Tag extends BaseModel
if ($where['document_id'] != '') $model = $model->where("document_id", $where['document_id']);
if ($where['start_time'] != '') $model = $model->where("create_time", ">", strtotime($where['start_time'] . " 00:00:00"));
if ($where['end_time'] != '') $model = $model->where("create_time", "<", strtotime($where['end_time'] . " 23:59:59"));
$count = self::counts($model);
$count = self::count();
if ($where['page'] && $where['limit']) $model = $model->page((int)$where['page'], (int)$where['limit']);
$data = $model->select();
if ($data) $data = $data->toArray();
@ -66,9 +68,16 @@ class Tag extends BaseModel
'user_id' => $user_id,
];
}
$this->clearCache();
return $this->saveAll($saveAll);
}
/**
* 清除缓存
*/
public function clearCache(){
cache()->delete(self::$cache_key);
}
/**
* 列表
@ -82,8 +91,7 @@ class Tag extends BaseModel
*/
public static function getList($where): array
{
$list = cache('index:tagList');
$list = false;
$list = cache(self::$cache_key);
if ($list) {
return json_decode($list, true);
} else {
@ -93,10 +101,10 @@ class Tag extends BaseModel
if ($where['page'] && $where['limit']) $model = $model->page((int)$where['page'], (int)$where['limit']);
$list = $model->select()->each(function (&$tag) {
$tag->text = $tag['name'];
$tag->href = url("/index/article/tag?t=" . $tag['name'])->build();
$tag->href = url('/article/tag',["t"=>$tag["name"]],'html')->build();
})->toArray();
if ($list) {
cache('index:tagList', json_encode($list), 24 * 60 * 60);
cache(self::$cache_key, json_encode($list), 24 * 60 * 60);
}
}
return $list;

View File

@ -8,10 +8,6 @@ namespace app\common\model;
*/
class UrlLog extends BaseModel
{
//自动时间戳
protected $autoWriteTimestamp = true;
//更新url_log
public function set_url($title, $url)
{
@ -24,11 +20,12 @@ class UrlLog extends BaseModel
if ($url_data) {
$this->where($urlWhere)->inc('pv')->update();
} else {
$dataUrl['url'] = $url;
$dataUrl['pv'] = 1;
$dataUrl['title'] = $title;
$dataUrl['date'] = $date_data;
$this->insertGetId($dataUrl);
$model = new self();
$model->url = $url;
$model->pv = 1;
$model->title = $title;
$model->date = $date_data;
$model->save();
}
}

View File

@ -7,7 +7,10 @@ use app\common\constant\Data;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\facade\Request;
use think\facade\Session;
use mailer\Mailer;
use think\Model;
/**
* 用户管理
@ -68,12 +71,23 @@ class User extends BaseModel
if (!$res) {
return self::setErrorInfo("账号注册失败,请稍后再试");
} else {
//开始发送激活邮件,激活邮件处理
//生成密码重置key 设置有效时间 过期无效
$key = md5($info->email . rand(1000, 99999));
cache($key, $res, 24 * 60 * 60); //缓存1天过后则失效根据用户id设置用户激活
$host = Request::domain();
//TODO 这里暂时未完成 设计是 支持模板来配置这里的任务 后台可以编辑模板这样子
$content = "您已经成功在蓝米云注册会员,请点击以下链接完成账号激活:{$host}/forget?action=rested&key={$key}&id=20
请在24小时内完成激活24小时后链接地址失效如果通过点击以上链接无法访问请将上面的地址复制到您使用的浏览器地址中进入如果您并没有访问过蓝米云官网或没有进行上述操作请忽略这封邮件此账号将不会绑定您的邮箱。感谢您的访问祝您使用愉快";
$mailer = new Mailer();
$mailer->from(system_config('title'))
->to($info->email)
->subject(system_config('title') . '注册激活邮件')
->text($content)
->send();
}
return false;
}
/**
* 设置登录信息
* @param $info
@ -168,10 +182,64 @@ class User extends BaseModel
if ($where['tel'] != '') $model = $model->where("tel|email", "like", "%$where[tel]%");
if ($where['status'] != '') $model = $model->where("status", $where['status']);
if ($where['is_admin'] != '') $model = $model->where("is_admin", $where['is_admin']);
$count = self::counts($model);
$count = self::count();
if ($where['page'] && $where['limit']) $model = $model->page((int)$where['page'], (int)$where['limit']);
$data = $model->select();
$data = $data ? $data->toArray() : [];
return compact("data", "count");
}
/**
* 密码重置
* @param string $userid
* @param $password
* @return bool|void
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public static function resetPassword($key, $password)
{
$username = cache($key); //缓存1天过后则失效
if (empty($username)){
return self::setErrorInfo("链接已失效或者用户不存在");
}
$info = self::where('username|email', '=', $username)->find();
if (!$info) return self::setErrorInfo("用户不存在");
$info['password'] = md5(md5($password));
$info['status'] = 2;
$info['remark'] = '重置密码成功!';
$info['update_time'] = time();
$info['create_time'] = time();
$info['is_admin'] = Data::USER_IS_ADMIN_NO;
$info['update_time'] = time();
$info['is_admin'] = Data::USER_IS_ADMIN_NO;
}
/**
* 丢失密码
* @param $username
* @return bool
* @author 木子的忧伤
* @date 2022-01-03 3:48
*/
public static function lostPassword($username)
{
$info = self::where('username|email', '=', $username)->find();
if ($info) return self::setErrorInfo("账号或邮箱不存在,请检查后重试");
//生成密码重置key 设置有效时间 过期无效
$key = md5($info->email . rand(1000, 99999));
cache($key, $username, 24 * 60 * 60); //缓存1天过后则失效
$host = Request::domain();
//发送邮件
$content = "您好您在本网站进行重置密码操作请点击如下链接进入重置密码页面。【本链接24小时内容有效如果不是您的操作请忽略】
{$host}/forget?action=rested&key={$key}&id=20";
$mailer = new Mailer();
$mailer->from(system_config('title'))
->to($info->email)
->subject(system_config('title') . '重置密码验证')
->text($content)
->send();
return true;
}
}

View File

@ -8,8 +8,4 @@ namespace app\common\model;
*/
class UvLog extends BaseModel
{
//自动时间戳
protected $autoWriteTimestamp = true;
}

View File

@ -36,7 +36,7 @@ class Layer extends Paginator
* @param string $text
* @return string
*/
protected function getPreviousButton($text = "上一页")
protected function getPreviousButton($text = "上一页"): string
{
if ($this->currentPage() <= 1) {
@ -56,7 +56,7 @@ class Layer extends Paginator
* @param string $text
* @return string
*/
protected function getDisabledTextWrapper($text)
protected function getDisabledTextWrapper($text): string
{
return '<a class="layui-laypage-prev layui-disabled">' . $text . '</a>';
}
@ -83,7 +83,7 @@ class Layer extends Paginator
* @param string $text
* @return string
*/
protected function getActivePageWrapper($text)
protected function getActivePageWrapper($text): string
{
return '<span class="layui-laypage-curr"><em class="layui-laypage-em"></em><em>' . $text . '</em></span>';
}
@ -95,7 +95,7 @@ class Layer extends Paginator
* @param int $page
* @return string
*/
protected function getAvailablePageWrapper($url, $page)
protected function getAvailablePageWrapper($url, $page): string
{
return '<a href="' . htmlentities($url) . '">' . $page . '</a>';
}
@ -105,7 +105,7 @@ class Layer extends Paginator
* @param string $text
* @return string
*/
protected function getNextButton($text = '下一页')
protected function getNextButton($text = '下一页'): string
{
if (!$this->hasMore) {
return $this->getDisabledTextWrapper($text);
@ -120,7 +120,7 @@ class Layer extends Paginator
* 页码按钮
* @return string
*/
protected function getLinks()
protected function getLinks(): string
{
if ($this->simple)
return '';
@ -173,7 +173,7 @@ class Layer extends Paginator
* @param array $urls
* @return string
*/
protected function getUrlLinks(array $urls)
protected function getUrlLinks(array $urls): string
{
$html = '';
@ -189,7 +189,7 @@ class Layer extends Paginator
*
* @return string
*/
protected function getDots()
protected function getDots(): string
{
return $this->getDisabledTextWrapper('...');
}

View File

@ -22,9 +22,10 @@ class Ape extends TagLib
'article' => ['attr' => 'id,void,model', 'close' => 1],
'comment' => ['attr' => 'typeId,void,type,pageSize,orderBy', 'close' => 1],
'relevant' => ['attr' => 'id,model,void,row', 'close' => 1],
'tags' => ['attr' => 'tags,void', 'close' => 1],
'tags' => ['attr' => 'tags,void,row', 'close' => 1],
'archive' => ['attr' => 'type,format,void', 'close' => 1],
'nav' => ['attr' => 'type,typeId,row,void,where,orderBy,display', 'close' => 1],
'table' => ['attr' => 'name,where,orderby,row,pagesize,void', 'close' => 1]
];
/**
@ -129,7 +130,7 @@ class Ape extends TagLib
* @param $content
* @return string
*/
public function tagList($tag, $content): string
public function tagList($tag, $content)
{
$orderBy = $tag['orderBy'] ?? 'sort desc,create_time desc';
$pageSize = $tag['pageSize'] ?? 15;
@ -141,7 +142,7 @@ class Ape extends TagLib
$display = $tag['display'] ?? 1;
$display = $display == 1 ? 1 : 0;
$parse = '<?php ';
$parse .= '$__FUN__ =' . "tpl_get_list(\"$orderBy\",$pageSize,\"$typeId\",\"$type\",\"$model\",\"$where\",$display);";
$parse .= '$__FUN__ =' . "tpl_get_list(\"$type\",\"$typeId\",\"$where\",\"$model\",\"$orderBy\",$pageSize,$display);";
$parse .= '$__LIST__ = $__FUN__["lists"];$pager = $__FUN__["model"]->render();';
$parse .= ' ?>';
$parse .= '{volist name="__LIST__" id="' . $void . '" key="i"}';
@ -160,10 +161,10 @@ class Ape extends TagLib
$get = $tag['get'] ?? 'pre';
$cid = $tag['cid'] ?? '$cid';
$void = $tag['void'] ?? 'field';
$none = $tag['none'] ?? '没有了';
$type = $tag['type'] ?? 'article';
$parse = '<?php ';
$parse .= '$__LIST__ =[];array_push($__LIST__,' . "tpl_get_prenext(\"$get\",$cid,\"$none\"));";
$parse .= '$__LIST__ =[];array_push($__LIST__,' . "tpl_get_prenext(\"$get\",$cid,\"$type\"));";
$parse .= ' ?>';
$parse .= '{volist name="__LIST__" id="' . $void . '"}';
$parse .= $content;
@ -193,6 +194,24 @@ class Ape extends TagLib
return $parse;
}
/**
* 执行SQL
*/
public function tagSql($tag,$content)
{
if(!isset($tag['sql'])){
return '';
}
$sql=$tag['sql'];
$parse = '<?php ';
$parse .= '$__LIST__ ='."db()->query(\"$sql\");";
$parse .= ' ?>';
$parse .= '{volist name="__LIST__" id="field"}';
$parse .= $content;
$parse .= '{/volist}';
return $parse;
}
/**
* tagAdvert 广告
* @param $tag
@ -246,14 +265,12 @@ class Ape extends TagLib
*/
public function tagTags($tag, $content)
{
if (!isset($tag['tags'])) {
return false;
}
$tags = $tag['tags'];
$row = $tag['row'] ?? 10;
$tags = $tag['tags']??"";
$void = $tag['void'] ?? 'field';
$parse = '<?php ';
$parse .= '$__LIST__ =' . "tpl_get_tags_list($tags);";
$parse .= '$__LIST__ =' . "tpl_get_tags_list(\"$tags\",$row);";
$parse .= ' ?>';
$parse .= '{volist name="$__LIST__" id="' . $void . '"}';
$parse .= $content;
@ -371,4 +388,35 @@ class Ape extends TagLib
$parse .= '{/volist}';
return $parse;
}
/**
* 表数据读取
*/
public function tagTable($tag, $content)
{
$name = isset($tag['name']) ? $tag['name'] : false;
if (!$name) {
return '';
}
$orderby = isset($tag['orderby']) ? $tag['orderby'] : '';
$pagesize = isset($tag['pagesize']) ? $tag['pagesize'] : '';
$void = isset($tag['void']) ? $tag['void'] : 'field';
$where = isset($tag['where']) ? $tag['where'] : '';
$row = isset($tag['row']) ? $tag['row'] : '100';
$parse = '<?php ';
$parse .= '$__FUN__ =' . "tpl_get_table_list(\"$orderby\",\"$pagesize\",\"$name\",\"$where\",$row);";
if ($pagesize) {
$parse .= '$__LIST__ =$__FUN__["lists"];$pager = $__FUN__["model"]->render();';
} else {
$parse .= '$__LIST__ =$__FUN__;';
}
$parse .= ' ?>';
$parse .= '{volist name="__LIST__" id="' . $void . '"}';
$parse .= $content;
$parse .= '{/volist}';
return $parse;
}
}

View File

@ -1,29 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | HulaCWMS 呼啦企业网站管理系统
// +----------------------------------------------------------------------
// | Copyright (c) 2021 https://www.kaifashu.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: 开发树
// +----------------------------------------------------------------------
namespace app\common\validate;
use think\Validate;
/**
* 后台菜单验证器
*/
class MessageForm extends Validate
{
protected $rule = [
'content' => 'require',
'tel' => 'number|max:11',
];
protected $message = [
'content.require' => '请输入留言内容!',
'tel.number' => '手机号必须是数字!',
'tel.max' => '手机号不得超过11位',
];
}

View File

@ -8,6 +8,7 @@ use app\common\model\Advert;
use app\common\model\FriendLink;
use app\common\model\Tag;
use app\common\model\Nav;
use app\common\model\Tag as TagModel;
use think\App;
use think\Collection;
use think\db\exception\DataNotFoundException;
@ -23,7 +24,7 @@ use think\facade\Db;
* @param $len
* @return string
*/
function cn_substr($str, $len)
function cn_substr($str, $len): string
{
return mb_substr($str, 0, $len, 'utf-8');
}
@ -31,7 +32,7 @@ function cn_substr($str, $len)
/**
* 过滤html标签
*/
function html2text($str)
function html2text($str): string
{
return strip_tags($str);
}
@ -43,20 +44,56 @@ function get_document_category_list()
{
//缓存文章菜单
$documentCategory = cache(Data::DATA_DOCUMENT_CATEGORY_LIST);
if ($documentCategory === null) {
$documentCategoryList = DocumentCategory::where('status', 1)->order('sort asc')->select()->toArray();
//转换让id作为数组的键
$documentCategory = [];
foreach ($documentCategoryList as $item) {
if (is_null($documentCategory)) {
$documentCategory = DocumentCategory::where('status', 1)->order('sort asc')->select()->toArray();
$documentList = Document::where('display', 1)
->where('status', 1)
->where("category_id","in",array_column($documentCategory,"id"))
->group("category_id")
->column('count(*) as count', 'category_id');
//TODO 需要实现包含下级分类所有数据的逻辑 使用下面两个函数实现,暂未完成
///转换让id作为数组的键
$tempList = [];
foreach ($documentCategory as $item) {
//根据栏目类型生成栏目url
$item['url'] = make_category_url($item);
$documentCategory[$item['id']] = $item;
$item['dc_count'] = $documentList[$item['id']] ?? 0;
$tempList[$item['id']] = $item;
}
$documentCategory = $tempList;
unset($item,$tempList,$documentList);
cache(Data::DATA_DOCUMENT_CATEGORY_LIST, $documentCategory);
}
return $documentCategory;
}
// 构建树形结构的函数
function buildTree($list, $pid = 0) {
$tree = [];
foreach ($list as $item) {
if ($item['pid'] == $pid) {
$children = buildTree($list, $item['id']);
if ($children) {
$item['children'] = $children;
}
$item['count'] += array_sum(array_column($children,"count"));
$tree[] = $item;
}
}
return $tree;
}
// 生成映射数据的函数
function generateMap($tree, &$map = []) {
foreach ($tree as $item) {
$map[$item['id']] = $item;
if (isset($item['children'])) {
generateMap($item['children'], $map);
}
}
return $map;
}
/**
* 获取一个文章分类
*/
@ -73,7 +110,7 @@ function get_document_category($x, $field = false)
if ($field) {
return $documentCategoryList[$x][$field];
} else {
$documentCategoryList[$x]['child'] = implode(",",array_column(getSubs($documentCategoryList,$x),"id"));
$documentCategoryList[$x]['child'] = implode(",", array_column(getSubs($documentCategoryList, $x), "id"));
return $documentCategoryList[$x];
}
}
@ -105,6 +142,28 @@ function get_document_category_by_name($name, $field = false)
}
}
/**
* 获取一个文章分类
*/
function get_document_category_by($x, $field = false)
{
if (!$x) {
throw new Exception('请指定要获取的栏目分类id');
}
//获取缓存的文章菜单
$documentCategoryList = get_document_category_list();
if (!isset($documentCategoryList[$x])) {
return false;
}
if ($field) {
return $documentCategoryList[$x][$field];
} else {
$documentCategoryList[$x]['child'] = implode(",", array_column(getSubs($documentCategoryList, $x), "id"));
return $documentCategoryList[$x];
}
}
/**
* 模板-获取文章分类
* @param $type
@ -124,7 +183,7 @@ function tpl_get_channel($type, $typeId, $row = 100, $where = '', $orderby = '')
{
switch ($type) {
case "all":
//获取顶级分类
//获取所有
return get_document_category_all();
break;
case 'top':
@ -249,13 +308,14 @@ function get_document_category_by_parent($pid, $row)
/*
* 获取所有子集元素
*/
function getSubs($categorys,$catId=0,$level=1){
$subs=array();
foreach($categorys as $item){
if($item['pid']==$catId){
$item['level']=$level;
$subs[]=$item;
$subs=array_merge($subs,getSubs($categorys,$item['id'],$level+1));
function getSubs($categorys, $catId = 0, $level = 1)
{
$subs = array();
foreach ($categorys as $item) {
if ($item['pid'] == $catId) {
$item['level'] = $level;
$subs[] = $item;
$subs = array_merge($subs, getSubs($categorys, $item['id'], $level + 1));
}
}
return $subs;
@ -264,7 +324,7 @@ function getSubs($categorys,$catId=0,$level=1){
/**
* @return array
*/
function get_document_category_all()
function get_document_category_all(): array
{
$documentCategoryList = get_document_category_list();
$tempArr = array();
@ -284,28 +344,34 @@ function get_document_category_all()
* $get=上一篇|下一篇
* $cid=栏目分类id
*/
function tpl_get_prenext($get, $cid = false, $none)
function tpl_get_prenext($get, $cid = "",$type ="article")
{
//文档id
$id = input('id');
$id = request()->param('id');
if (!$get) {
$get = 'next';
}
$document = Document::where('display', 1)->where('status', 1);
$document = Document::where('display', 1)->where('status', 1)->where('type',$type);
$document = $get == 'pre' ? $document->where("id", '<', $id) : $document->where("id", '>', $id);
$document_tmp = clone $document;
//如果表明在同一分类下查询
if ($cid) {
$document = $document->where("category_id", $cid);
}
$document = $document->field('id,title')->order($get == 'pre' ? 'id desc' : 'id asc')->find();
if ($document) {
$document['url'] = url('article/detail?id=' . $document['id'])->build();
$document['url'] = make_detail_url($document);
} else {
$document['id'] = false;
$document['url'] = 'javascript:void(0)';
$document['title'] = $none;
//如果执行的cid没有数据则重新请求
$document = $document_tmp->orderRaw('rand()')->find();
if ($document) {
$document['url'] = make_detail_url($document);
}else{
$document['id'] = false;
$document['url'] = 'javascript:void(0)';
$document['title'] = "暂无";
}
}
return $document;
}
@ -317,7 +383,7 @@ function tpl_get_prenext($get, $cid = false, $none)
* @param $cid int 栏目分类id
* @param $type string 读取数据的方式son:'获取栏目下文章以及所有子孙分类文章',self:'获取栏目下文章',search:'获取关键字搜索的文章',where:'根据自定义条件获取文章where语句'
* @param string $table 文章内容扩展表名默认article
* @param bool|array $where 自定义条件
* @param bool|array $where 自定义条件
* @param int $display
* @return array
* @throws Exception
@ -325,7 +391,7 @@ function tpl_get_prenext($get, $cid = false, $none)
* @throws DbException
* @throws ModelNotFoundException
*/
function tpl_get_list($orderBy, int $pageSize, $cid, $type, $table = 'article', $where, int $display = 1)
function tpl_get_list($type, $cid, $where, string $table = 'article', string $orderBy = '', int $pageSize = 10, int $display = 1)
{
$documentListModel = (new Document())
->alias('a')
@ -359,8 +425,8 @@ function tpl_get_list($orderBy, int $pageSize, $cid, $type, $table = 'article',
break;
case 'search':
//获取关键字搜索的文章
$kw = input('kw'); //搜索关键词
$tid = input('cid');//文章分类Id
$kw = request()->param('kw'); //搜索关键词
$tid = request()->param('cid');//文章分类Id
if ($kw) {
$documentListModel = $documentListModel->where('a.title', 'like', "%$kw%");
}
@ -374,7 +440,7 @@ function tpl_get_list($orderBy, int $pageSize, $cid, $type, $table = 'article',
break;
case 'tag':
//读取指定tag的文章
$tag = substr(input('t'), 0, strpos(input('t'), '.')); //搜索关键词
$tag = request()->param('t'); //标签
$tagModel = new Tag();
$tagList = $tagModel->where('name', $tag)->select()->toArray();
$documentListModel = $documentListModel->where('a.id', 'in', array_column($tagList, 'document_id'));
@ -385,17 +451,25 @@ function tpl_get_list($orderBy, int $pageSize, $cid, $type, $table = 'article',
$query = request()->query();
if ($query) {
$documentListModel = $documentListModel->paginate([
'list_rows'=> $pageSize,
'list_rows' => $pageSize,
'var_page' => 'page',
'query' => get_route_query()
]);
} else {
$documentListModel = $documentListModel->paginate($pageSize);
}
//获取评论数 跟在文章后面
if (!empty($item)){
$commentModel = (new Comment())->field('document_id as id,count(*) as comment')
->where("document_id","in" ,array_column($documentListModel->toArray(),'id'))
->group('id')
->select();
}
$lists = [];
foreach ($documentListModel as $key => $item) {
//生成文章url
$item['url'] = make_detail_url($item);
$item['comment'] = $commentModel[$item['id']]['comment'] ?? 0;
$lists[$key] = $item;
}
$re = [
@ -424,7 +498,8 @@ function get_route_query()
*/
function make_category_url($item)
{
return url('article/detail', ['id'=>$item['alias']?:$item['id']])->build();
// return url('/article/lists', ['id' => $item['alias'] ?: $item['id']])->build();
return url('/article/lists', ['id' => $item['id']])->build();
}
/**
@ -439,7 +514,7 @@ function make_detail_url($item)
if ($item['link_str'] && $item['is_jump']) {
return $item['link_str'];
} else {
return url($item['type'].'/detail', ['id'=>$item['alias']?:$item['id']])->build();
return url($item['type'] . '/detail', ['id' => $item['alias'] ?: $item['id']])->build();
}
}
@ -519,10 +594,18 @@ function tpl_get_article_list($cid, $row, $orderby, $table = 'article', $type =
}
$documentListModel = $documentListModel->order($orderby)->select();
//获取评论数 跟在文章后面
if (!empty($item)){
$commentModel = (new Comment())->field('document_id as id,count(*) as comment')
->where("document_id","in" ,array_column($documentListModel->toArray(),'id'))
->group('id')
->select();
}
$lists = [];
foreach ($documentListModel as $key => $item) {
//生成文章url
$item['url'] = make_detail_url($item);
$item['comment'] = $commentModel[$item['id']]['comment'] ?? 0;
$lists[$key] = $item;
}
return $lists;
@ -580,31 +663,31 @@ function tpl_get_advert($type, int $row = 5)
$advertList = cache(Data::DATA_ADVERT . '_' . $type);
if ($advertList === null) {
$advertList = (new Advert())->alias("a")
->leftJoin("advert_info i",'a.id = i.advert_id')
->leftJoin("advert_info i", 'a.id = i.advert_id')
->field("i.*")
->where('a.alias', $type)
->where('a.status', 1)
->where('i.status', 1)
->order('sort desc')
->select()
->toArray();
->toArray();
//处理文件cdn信息
foreach ($advertList as $key => &$item) {
if (empty($item['cover_path'])){
if (empty($item['cover_path'])) {
unset($advertList[$key]);
}
$item['cover_path'] = file_cdn($item['cover_path']);
}
unset($item);
if (!empty($advertList)){
if (!empty($advertList)) {
cache(Data::DATA_ADVERT . '_' . $type, $advertList);
}
}
//如果获取行数为空则取默认值
if (!$row){
if (!$row) {
$row = 5;
}
return !empty($advertList)?array_slice($advertList,0,$row):$advertList;
return !empty($advertList) ? array_slice($advertList, 0, $row) : $advertList;
}
/**
@ -616,17 +699,15 @@ function tpl_get_advert($type, int $row = 5)
* @author 木子的忧伤
* @date 2022-06-01 10:06
*/
function tpl_get_archive_list($type,$format){
function tpl_get_archive_list($type, $format)
{
$list = cache(Data::DATA_ARCHIVE . '_' . $type);
$list = null;
if ($list === null) {
switch ($type){
switch ($type) {
case "month":
$dateFormat = "LEFT(create_date,7)";
break;
case "day":
$dateFormat = "create_date";
break;
case "year":
$dateFormat = "LEFT(create_date,4)";
break;
@ -636,7 +717,7 @@ function tpl_get_archive_list($type,$format){
}
$list = (new Document())->group($dateFormat)->column("count(*) as count,create_date");
foreach ($list as $key => &$item) {
$item['create_date'] = date($format,strtotime($item['create_date']));
$item['create_date'] = date($format, strtotime($item['create_date']));
}
cache(Data::DATA_ADVERT . '_' . $type, $list);
}
@ -670,19 +751,18 @@ if (!function_exists('web_config')) {
* @date 2021-11-12 0:34
*/
if (!function_exists('tpl_get_tags_list')) {
function tpl_get_tags_list($tags)
function tpl_get_tags_list($tag ='', $limit = 10)
{
if (!$tags) {
return false;
$where =[
'name'=> $tag,
'page'=> 1,
'limit'=> $limit
];
try {
return TagModel::getList($where);
} catch (DbException $e) {
return [];
}
$tagArr = explode(',', $tags);
$tagTemp = [];
foreach ($tagArr as $item) {
$data['title'] = $item;
$data['url'] = url('article/tag?t=' . urlencode($item));
array_push($tagTemp, $data);
}
return $tagTemp;
}
}
@ -697,7 +777,7 @@ if (!function_exists('tpl_get_tags_list')) {
*/
function tpl_get_position($dc, $positionList = array())
{
array_push($positionList, $dc);
$positionList[] = $dc;
if ($dc['pid'] == 0) {
$htmlStr = '<a href="/">首页</a>';
$positionListCount = count($positionList);
@ -718,7 +798,7 @@ function get_comment_children($parentIds)
return $list;
}
foreach ($list as &$item) {
$item['reply_url'] = url('article/create_comment?pid=' . $item['id'])->build();
$item['reply_url'] = url('/article/create_comment', ["pid" => $item['id']])->build();
}
unset($item);
return array_merge($list, get_comment_children(array_column($list, 'id')));
@ -760,7 +840,7 @@ function tpl_get_comment_list($id, $type, $pageSize, $orderBy)
}
$lists = [];
foreach ($commentModel as $key => $item) {
$item['reply_url'] = url('article/create_comment?pid=' . $item['id'])->build();
$item['reply_url'] = url('/article/create_comment', ["id" => $item['id']])->build();
$lists[$key] = $item;
}
return [
@ -808,11 +888,9 @@ function get_comment_count($documentId, $type = 'top')
*/
function tpl_get_relevant_list($documentId, $row, $table = 'article')
{
$count = Document::where('type', $table)
->where('status', 1)->count(); //获取总记录数
$count = Document::where('type', $table)->where('status', 1)->count(); //获取总记录数
$id = (new Document())->getPK();
$min = Document::where('type', $table)
->where('status', 1)->min($id); //统计某个字段最小数据
$min = Document::where('type', $table)->where('status', 1)->min($id); //统计某个字段最小数据
if ($count < $row) {
$row = $count;
}
@ -829,8 +907,8 @@ function tpl_get_relevant_list($documentId, $row, $table = 'article')
} else {
$i--;
}
$i++;
}
$i++;
}
$relevantList = Document::where('type', $table)
->where('status', 1)
@ -849,7 +927,7 @@ function tpl_get_relevant_list($documentId, $row, $table = 'article')
//获取顶级栏目名
function GetTopTypename($id = false)
{
$id = $id ? $id : input('id');
$id = $id ?: request()->param('id');
$dc = get_document_category($id);
if ((int)$dc['pid'] === 0) {
return $dc['title'];
@ -861,7 +939,7 @@ function GetTopTypename($id = false)
//获取顶级id
function GetToptypeId($id = false)
{
$id = $id ? $id : input('id');
$id = $id ?: request()->param('id');
$dc = get_document_category($id);
if ((int)$dc['pid'] === 0) {
return $dc['id'];
@ -873,7 +951,7 @@ function GetToptypeId($id = false)
//获取顶级栏目图片
function GetTopTypeimg($id = false)
{
$id = $id ? $id : input('id');
$id = $id ?: request()->param('id');
$dc = get_document_category($id);
if ((int)$dc['pid'] === 0) {
return $dc['icon'];
@ -884,7 +962,7 @@ function GetTopTypeimg($id = false)
//获取顶级栏目描述
function GetTopDescription($id = false)
{
$id = $id ? $id : input('id');
$id = $id ?: request()->param('id');
$dc = get_document_category($id);
if ((int)$dc['pid'] === 0) {
return $dc['description'];
@ -896,7 +974,7 @@ function GetTopDescription($id = false)
//获取顶级英文名称
function GetTopTypenameen($id = false)
{
$id = $id ? $id : input('id');
$id = $id ?: request()->param('id');
$dc = get_document_category($id);
if ((int)$dc['pid'] === 0) {
return $dc['name'];
@ -913,14 +991,13 @@ function GetTopTypenameen($id = false)
*/
function is_active_nav($currCid = false, $cid = false)
{
if (request()->action() == 'search') {
if (in_array(request()->action(),['search','tag','about']) ) {
return false;
}
//首页
if (!$currCid && !$cid) {
return true;
}
//一般在首页中要比对的栏目id会为false
if ($cid == false) {
return false;
@ -1015,7 +1092,7 @@ function file_load_face($path)
}
function comment_face($incoming_comment,$path)
function comment_face($incoming_comment, $path)
{
$pattern = '/\[f=(.*?)\]/';
$isMatched = preg_match_all($pattern, $incoming_comment, $match);
@ -1023,7 +1100,7 @@ function comment_face($incoming_comment,$path)
return $incoming_comment;
}
foreach ($match[1] as $facename) {
if (file_exists( public_path() . $path . $facename . '.gif')) {
if (file_exists(public_path() . $path . $facename . '.gif')) {
$incoming_comment = str_replace("[f={$facename}]", '<img src="' . $path . $facename . '.gif" width="24">', $incoming_comment);
}
}
@ -1157,7 +1234,7 @@ function tpl_get_nav($type, $typeId, $row = 100, $where = '', $orderby = '')
function get_nav($x, $field = false)
{
if (!$x) {
throw new Exception('请指定要获取的栏目导航id');
return false;
}
//获取缓存的文章菜单
$list = get_nav_list();
@ -1171,6 +1248,21 @@ function get_nav($x, $field = false)
}
}
function tpl_get_admin($id,$field=""){
$info = cache("admin_{$id}");
if (is_null($info)){
try {
//TODO 这里考虑是否会泄露用户信息问题,并且是否会影响性能,后续需要完善发帖数量等等
$info = \app\common\model\User::where('id', $id)->field('nickname,avatar,email,ip,remark')->find();
} catch (DbException $e) {
return "";
}
cache("admin_{$id}", $info, 1*60*60);
}
return $info[$field] ?? '';
}
/**
* 获取导航列表
*/
@ -1190,7 +1282,7 @@ function get_nav_list()
return $navList;
}
function get_nav_all()
function get_nav_all(): array
{
$list = get_nav_list();
$tempArr = array();
@ -1209,7 +1301,7 @@ function get_nav_all()
* $pid=父级id
* $row=获取多少数目
*/
function get_nav_by_parent($pid, $row)
function get_nav_by_parent($pid, $row): array
{
$list = get_nav_list();
$x = 1;

View File

@ -5,9 +5,10 @@
//第一步判断选择的模板
$theme = system_config('web_template');
//检查主题目录是否存在,不存在则更新为默认目录
if (file_exists(public_path("template/{$theme}"))) {
if (!file_exists(public_path("template/{$theme}"))) {
$theme = 'default';
}
//检查是否切换模板
if (is_mobile() == "wap" && file_exists(public_path("template/{$theme}/mobile"))) {
$mode = "mobile";

View File

@ -7,11 +7,13 @@ use app\common\constant\Data;
use app\common\model\Comment as commentModel;
use app\common\model\Document;
use app\common\model\DocumentCategory;
use app\index\validate\Comment;
use app\Request;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\Exception;
use think\exception\ValidateException;
use think\facade\Log;
/**
@ -31,7 +33,7 @@ class Article extends Base
* @author 木子的忧伤
* @date 2021-10-29 0:17
*/
public function lists()
public function lists(): string
{
$dc = false;
//栏目分类id
@ -56,13 +58,18 @@ class Article extends Base
//判断后台统计配置是否开启 1 开启
if (web_config("web_statistics") == 1) {
//统计url
$this->urlrecord($dc['title']);
$this->urlRecord($dc['title']);
}
//读取列表页模板
$template = Data::DOCUMENT_CATEGORY . '/' . ($dc['template'] ?: 'list_default.html');
$template = Data::DOCUMENT_CATEGORY . '/' . ($dc['template'] ?: 'index.html');
$templateFile = config('view.view_path') . $template;
if (!is_file($templateFile)) {
$this->error('模板文件不存在!');
//配置的模版文件不存在则走默认模版
$template = Data::DOCUMENT_CATEGORY . '/' . 'index.html';
$templateFile = config('view.view_path') . $template;
if (!is_file($templateFile)){
$this->error('模板文件不存在!');
}
}
Log::info('列表页模板路径:' . $templateFile);
//文章兼容字段
@ -70,8 +77,8 @@ class Article extends Base
//判断seo标题是否存在
$dc['meta_title'] = $dc['meta_title'] ?: $dc['title'];
//判断SEO 为空则取系统
$article['keywords'] = $dc['keywords'] ?: web_config('keywords');
$article['description'] = $dc['description'] ?: web_config('description');
$dc['keywords'] = $dc['keywords'] ?: web_config('keywords');
$dc['description'] = $dc['description'] ?: web_config('description');
//添加当前页面的位置信息
$dc['position'] = tpl_get_position($dc);
//输出文章分类
@ -93,10 +100,11 @@ class Article extends Base
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @throws \Exception
* @author 木子的忧伤
* @date 2021-10-29 0:17
*/
public function detail()
public function detail(): string
{
$id = input('id');
if (!$id) {
@ -117,13 +125,20 @@ class Article extends Base
$article['position'] = tpl_get_position($dc);
//更新浏览次数
$documentModel->where('id', $article['id'])->inc('view')->update();
$template = Data::DOCUMENT_TYPE_ARTICLE . '/' . ($article['theme'] ?: 'detail.html');
//读取模板文件
$template = Data::DOCUMENT_TYPE_ARTICLE . '/' . ($article['template'] ?: 'detail.html');
$templateFile = config('view.view_path') . $template;
if (!is_file($templateFile)) {
$this->error('模板文件不存在!');
//配置的模版文件不存在则走默认模版
$template = Data::DOCUMENT_CATEGORY . '/' . 'detail.html';
$templateFile = config('view.view_path') . $template;
if (!is_file($templateFile)){
$this->error('模板文件不存在!');
}
}
$article['category_title'] = $dc['title'];
//判断SEO 为空则取系统
$article['meta_title'] = $article['title'];
$article['keywords'] = $article['keywords'] ?: web_config('keywords');
$article['description'] = $article['description'] ?: web_config('description');
//输出文章内容
@ -138,7 +153,7 @@ class Article extends Base
//判断后台统计配置是否开启 1 开启
if (web_config("web_statistics") == 1) {
//统计url
$this->urlrecord($article['title']);
$this->urlRecord($article['title']);
}
Log::info('详情页模板路径:' . $templateFile);
//去除后缀
@ -156,6 +171,7 @@ class Article extends Base
public function create_comment(Request $request)
{
$data = Util::postMore([
['captcha',''],
['document_id', ''],
['pid', ''],
['author', ''],
@ -163,18 +179,26 @@ class Article extends Base
['email', ''],
['content', ''],
]);
if (!web_config('comment_close')) {
if (!web_config('comment_close')){
$this->error('非法操作,请检查后重试', null);
}
if (web_config('comment_visitor')) {
if ($data['author'] == "") $this->error("昵称不能为空");
if ($data['email'] == "") $this->error("邮箱不能为空");
if ($data['url'] == "") $this->error("url不能为空");
} else {
$data['author'] = $this->userInfo['nickname'] ?: $this->userInfo['username'];
$data['email'] = $this->userInfo['email'] ?: '';
if (web_config('comment_visitor')){
try {
validate(Comment::class)->check($data);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
$this->error($e->getError(), null);
}
}elseif(web_config('is_register')){
$data['author'] = $this->userInfo['nickname']?:$this->userInfo['username'];
$data['email'] = $this->userInfo['email']?:'';
$data['url'] = '';
}
//开始判断留言是否显示验证码,显示则需要判断验证码
if ($data['captcha'] != "" && !captcha_check($data['captcha'])){
// 验证码验证
$this->error('验证码不正确', null);
}
if ($data['document_id'] == "") $this->error("文章id不能为空");
if ($data['content'] == "") $this->error("内容能为空");
$data['status'] = web_config('comment_review') ? 0 : 1;
@ -192,13 +216,11 @@ class Article extends Base
/**
* 文章标签页面
* @return string
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @throws \Exception
* @author 木子的忧伤
* @date 2021-10-29 0:19
*/
public function tag()
public function tag(): string
{
$tag = input('t');
if (!trim($tag)) {
@ -221,7 +243,7 @@ class Article extends Base
//模板兼容性标签
$this->assign('id', false);
$this->assign('cid', false);
$templateFile = config('view.view_path') . 'article/tag.html';
$templateFile = config('view.view_path') . Data::DOCUMENT_TYPE_ARTICLE . DIRECTORY_SEPARATOR.'tag.html';
if (!is_file($templateFile)) {
$this->error('模板文件不存在!');
}
@ -231,13 +253,11 @@ class Article extends Base
/**
* 搜索页面
* @return string
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @throws \Exception
* @author 木子的忧伤
* @date 2021-10-29 0:18
*/
public function search()
public function search(): string
{
$kw = input('kw');
if (!trim($kw)) {
@ -259,7 +279,7 @@ class Article extends Base
//模板兼容性标签
$this->assign('id', false);
$this->assign('cid', false);
$templateFile = config('view.view_path') . 'article/search.html';
$templateFile = config('view.view_path') . Data::DOCUMENT_TYPE_ARTICLE . DIRECTORY_SEPARATOR.'search.html';
if (!is_file($templateFile)) {
$this->error('模板文件不存在!');
}
@ -269,7 +289,7 @@ class Article extends Base
/**
* 用户首页
* @return string
* @throws Exception
* @throws \Exception
* @author 木子的忧伤
* @date 2022-01-24 1:23
*/
@ -296,7 +316,7 @@ class Article extends Base
//模板兼容性标签
$this->assign('id', false);
$this->assign('cid', false);
$templateFile = config('view.view_path') . 'article/user.html';
$templateFile = config('view.view_path') . Data::DOCUMENT_TYPE_ARTICLE . DIRECTORY_SEPARATOR.'user.html';
if (!is_file($templateFile)) {
$this->error('模板文件不存在!');
}

View File

@ -30,17 +30,14 @@ class Base extends BaseController
protected function initialize()
{
parent::initialize();
$this->userInfo = Session::get(Data::SESSION_KEY_USER_INFO);
$this->userId = Session::get(Data::SESSION_KEY_USER_ID);
if ($this->userId){
if (!empty($this->userId)){
//模板兼容性标签
$this->assign('user_info', $this->userInfo);
$this->assign('user_info', Session::get(Data::SESSION_KEY_USER_INFO));
$this->assign('user_id', $this->userId);
}
//判断是否关闭站点。
if (web_config('web_close')) {
if (web_config('web_close')==1) {
$this->error('网站暂时关闭!', '', 'stop');
}
//判断后台统计配置是否开启 1 开启
@ -71,7 +68,7 @@ class Base extends BaseController
* @author 木子的忧伤
* @date 2021-05-09 23:44
*/
protected function urlrecord($title)
protected function urlRecord($title): void
{
$urlLogModel = new UrlLog();
//获取url

View File

@ -5,10 +5,13 @@ namespace app\index\controller;
use app\admin\extend\Util as Util;
use app\common\constant\Data;
use app\common\model\Document;
use app\common\model\Document as DocumentModel;
use app\common\model\DocumentCategory as DocumentCategoryModel;
use app\common\model\FriendLink as friendLinkModel;
use app\common\model\MessageForm as MessageFormModel;
use app\common\model\Tag as TagModel;
use app\common\validate\MessageForm as MessageformValidate;
use app\index\validate\Msg as MsgValidate;
use app\index\validate\FriendLink as FriendLinkValidate;
use app\Request;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
@ -24,13 +27,14 @@ class Index extends Base
{
/**
* 入口跳转链接
* @throws \Exception
*/
public function index()
public function index(): string
{
//判断后台统计配置是否开启 1 开启
if (web_config("web_statistics") == 1) {
//统计url
$this->urlrecord('网站首页');
$this->urlRecord('网站首页');
}
//清除可能存在的栏目分类树id
cache(Data::CURR_CATEGORY_PATENT_ID, false);
@ -47,10 +51,11 @@ class Index extends Base
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @throws \Exception
* @author 木子的忧伤
* @date 2021-10-17 1:03
*/
public function applylink(Request $request)
public function applyLink(Request $request): string
{
if (request()->isPost()) {
$data = Util::postMore([
@ -61,8 +66,10 @@ class Index extends Base
['description', ''],
]);
if ($data['title'] == "") $this->error("链接名称不能为空");
if ($data['url'] == "") $this->error("链接地址不能为空");
$friendLinkValidate = new FriendLinkValidate();
if (!$friendLinkValidate->check($data)) {
$this->error($friendLinkValidate->getError());
}
//判断下用户是否存在
$info = friendLinkModel::where('url', $data['url'])->find();
if ($info) {
@ -89,24 +96,28 @@ class Index extends Base
* 留言页面
* @param Request $request
* @return string
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @throws \Exception
* @author 木子的忧伤
* @date 2021-10-17 1:03
*/
public function msg(Request $request)
public function msg(Request $request): string
{
if (request()->isPost()) {
$data = Util::postMore([
['captcha',''],
['author', ''],
['tel', ''],
['email', ''],
['content', ''],
]);
//开始判断留言是否显示验证码,显示则需要判断验证码
if ($data['captcha'] != "" && !captcha_check($data['captcha'])){
// 验证码验证
$this->error('验证码不正确', null);
}
$data['create_time'] = time();
$data['reply_content'] = '';
$messageFormValidate = new MessageFormValidate();
$messageFormValidate = new MsgValidate();
if (!$messageFormValidate->check($data)) {
$this->error($messageFormValidate->getError());
}
@ -129,10 +140,12 @@ class Index extends Base
/**
* 关于页面
* @param Request $request
* @return string
* @throws \Exception
* @author 木子的忧伤
* @date 2022-06-21 23:48
*/
public function about(Request $request)
public function about(Request $request): string
{
$id = "about";
//获取该文章
@ -146,13 +159,19 @@ class Index extends Base
$article['position'] = '<a href="/">首页</a><span>&gt;</span>';
//更新浏览次数
$documentModel->where('id', $article['id'])->inc('view')->update();
$template = Data::DOCUMENT_TYPE_PAGE . '/' . ($article['theme'] ?: 'detail.html');
$template = Data::DOCUMENT_TYPE_PAGE . '/' . ($article['template'] ?: 'index.html');
$templateFile = config('view.view_path') . $template;
if (!is_file($templateFile)) {
$this->error('模板文件不存在!');
//配置的模版文件不存在则走默认模版
$template = Data::DOCUMENT_TYPE_PAGE . '/' . 'index.html';
$templateFile = config('view.view_path') . $template;
if (!is_file($templateFile)){
$this->error('模板文件不存在!');
}
}
$article['category_title'] = "单页";
//判断SEO 为空则取系统
$article['meta_title'] = $article['title'];
$article['keywords'] = $article['keywords'] ?: web_config('keywords');
$article['description'] = $article['description'] ?: web_config('description');
//输出文章内容
@ -165,7 +184,7 @@ class Index extends Base
//判断后台统计配置是否开启 1 开启
if (web_config("web_statistics") == 1) {
//统计url
$this->urlrecord($article['title']);
$this->urlRecord($article['title']);
}
Log::info('详情页模板路径:' . $templateFile);
//去除后缀
@ -188,4 +207,78 @@ class Index extends Base
]);
return app("json")->layui(TagModel::getList($where));
}
/**
* 生成sitemap.xml
* @return \think\Response
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function sitemap(): \think\Response
{
//获取域名
$domain = request()->domain();
$cache_key = "sitemap.xml";
//先获取缓存是否存在
if ($content = cache($cache_key)){
return response($content)->header(['Content-Type'=>'application/xml']);
}
// 通过输出缓冲区内容生成XML
$str = '<?xml version="1.0" encoding="UTF-8"?>';
$str.= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">';
//首页
$str .= '<url>';
$str .= '<loc>' . $domain . '</loc>';
$str .= '<lastmod>' . date("Y-m-d\TH:i:s+00:00",time()). '</lastmod>';
$str .= '<changefreq>daily</changefreq>';
$str .= '<priority>1.0</priority>';
$str .= '</url>';
//获取文章分类url
$documentCategoryModel = new DocumentCategoryModel();
$categoryInfo = $documentCategoryModel->field('id,alias,title,create_time')
->where('status', 1)
->order('id desc')->select();
foreach ($categoryInfo as $v) {
$str .= '<url>';
$str .= '<loc>' . url('index/article/lists',["id"=>$v['id']],".html",$domain) . '</loc>';
$str .= '<lastmod>' . date("Y-m-d\TH:i:s+00:00",strtotime($v['create_time'])) . '</lastmod>';
$str .= '<changefreq>always</changefreq>';
$str .= '<priority>0.8</priority>';
$str .= '</url>';
}
//获取文章URL
$documentModel = new DocumentModel();
$documentInfo = $documentModel->field('id,alias,create_time')
->where('display', 1)
->order('id desc')->select();
foreach ($documentInfo as $v) {
$str .= '<url>';
$str .= '<loc>' . url('/article/detail',["id"=>$v["alias"]?:$v['id']],".html",$domain) . '</loc>';
$str .= '<lastmod>'.date("Y-m-d\TH:i:s+00:00",strtotime($v['create_time'])) .'</lastmod>';
$str .= '<changefreq>monthly</changefreq>';
$str .= '<priority>0.6</priority>';
$str .= '</url>';
}
//获取文章标签页url
$documentModel = new TagModel();
$documentInfo = $documentModel->field('name,create_time')
->group('name')
->order('name desc')->select();
foreach ($documentInfo as $v) {
$str .= '<url>';
$str .= '<loc>' . url('/article/tag',["t"=>$v["name"]],".html",$domain) . '</loc>';
$str .= '<lastmod>'.date("Y-m-d\TH:i:s+00:00",strtotime($v['create_time'])) .'</lastmod>';
$str .= '<changefreq>monthly</changefreq>';
$str .= '<priority>0.6</priority>';
$str .= '</url>';
}
$str .= '</urlset>';
cache($cache_key,$str,24*60*60);//每日更新
// 将内容输出到浏览器
return response($str)->header(['Content-Type'=>'application/xml']);
}
}

View File

@ -0,0 +1,59 @@
<?php
namespace app\index\controller;
use app\BaseController;
class Oauth extends BaseController
{
//登录地址
public function login($type = null): void
{
if ($type == null) {
$this->error('参数错误');
}
// 获取对象实例
$sns = \liliuwei\social\Oauth::getInstance($type);
//跳转到授权页面
$this->redirect($sns->getRequestCodeURL());
//前端登录demo
// <a href="{:url('Oauth/login',['type'=>'qq'])}">QQ登录</a>
// <a href="{:url('Oauth/login',['type'=>'sina'])}">新浪微博登录</a>
// <a href="{:url('Oauth/login',['type'=>'weixin'])}">微信登录</a>
// <a href="{:url('Oauth/login',['type'=>'baidu'])}">百度登录</a>
// <a href="{:url('Oauth/login',['type'=>'gitee'])}">gitee登录</a>
// <a href="{:url('Oauth/login',['type'=>'github'])}">github登录</a>
// <a href="{:url('Oauth/login',['type'=>'oschaina'])}">oschaina登录</a>
// <a href="{:url('Oauth/login',['type'=>'google'])}">google登录</a>
// <a href="{:url('Oauth/login',['type'=>'facebook'])}">facebook登录</a>
// <a href="{:url('Oauth/login',['type'=>'taobao'])}">淘宝登录</a>
// <a href="{:url('Oauth/login',['type'=>'douyin'])}">抖音登录</a>
// <a href="{:url('Oauth/login',['type'=>'xiaomi'])}">小米登录</a>
// <a href="{:url('Oauth/login',['type'=>'dingtalk'])}">钉钉登录</a>
}
//授权回调地址
public function callback($type = null, $code = null): void
{
if ($type == null || $code == null) {
$this->error('参数错误');
}
$sns = \liliuwei\social\Oauth::getInstance($type);
// 获取TOKEN
$token = $sns->getAccessToken($code);
//获取当前第三方登录用户信息
if (is_array($token)) {
$user_info = \liliuwei\social\GetInfo::getInstance($type, $token);
dump($user_info);// 获取第三方用户资料
$sns->openid();//统一使用$sns->openid()获取openid
//$sns->unionid();//QQ和微信、淘宝可以获取unionid
dump($sns->openid());
//TODO
echo '登录成功!!';
echo '正在持续开发中,敬请期待!!';
} else {
echo "获取第三方用户的基本信息失败";
}
}
}

View File

@ -6,11 +6,13 @@ use app\admin\extend\Util as Util;
use app\common\constant\Data;
use app\common\model\Comment as commentModel;
use app\common\model\Document;
use app\index\validate\Comment;
use app\Request;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\Exception;
use think\exception\ValidateException;
use think\facade\Log;
/**
@ -30,7 +32,7 @@ class Page extends Base
* @author 木子的忧伤
* @date 2021-10-29 0:17
*/
public function detail()
public function index() : string
{
$id = input('id');
if (!$id) {
@ -47,13 +49,19 @@ class Page extends Base
$article['position'] = '<a href="/">首页</a><span>&gt;</span>';
//更新浏览次数
$documentModel->where('id', $article['id'])->inc('view')->update();
$template = Data::DOCUMENT_TYPE_PAGE . '/' . ($article['theme'] ?: 'detail.html');
$template = Data::DOCUMENT_TYPE_PAGE . '/' . ($article['template'] ?: 'index.html');
$templateFile = config('view.view_path') . $template;
if (!is_file($templateFile)) {
$this->error('模板文件不存在!');
//配置的模版文件不存在则走默认模版
$template = Data::DOCUMENT_TYPE_PAGE . '/' . 'index.html';
$templateFile = config('view.view_path') . $template;
if (!is_file($templateFile)){
$this->error('模板文件不存在!');
}
}
$article['category_title'] = "单页";
//判断SEO 为空则取系统
$article['meta_title'] = $article['title'];
$article['keywords'] = $article['keywords'] ?: web_config('keywords');
$article['description'] = $article['description'] ?: web_config('description');
//输出文章内容
@ -66,7 +74,7 @@ class Page extends Base
//判断后台统计配置是否开启 1 开启
if (web_config("web_statistics") == 1) {
//统计url
$this->urlrecord($article['title']);
$this->urlRecord($article['title']);
}
Log::info('详情页模板路径:' . $templateFile);
//去除后缀
@ -90,15 +98,18 @@ class Page extends Base
['url', ''],
['email', ''],
['content', ''],
]);
],$request);
if (!web_config('comment_close')){
$this->error('非法操作,请检查后重试', null);
}
if (web_config('comment_visitor')){
if ($data['author'] == "") $this->error("昵称不能为空");
if ($data['email'] == "") $this->error("邮箱不能为空");
if ($data['url'] == "") $this->error("url不能为空");
}else{
try {
validate(Comment::class)->check($data);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
$this->error($e->getError(), null);
}
}elseif(web_config('is_register')){
$data['author'] = $this->userInfo['nickname']?:$this->userInfo['username'];
$data['email'] = $this->userInfo['email']?:'';
$data['url'] = '';

View File

@ -7,15 +7,33 @@
namespace app\index\controller;
use app\admin\extend\Util;
use app\common\model\Document;
use app\common\model\User as userModel;
use app\index\validate\Comment;
use app\index\validate\Login;
use app\index\validate\Register;
use Exception;
use think\App;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\exception\ValidateException;
use think\Response;
class User extends Base
{
/**
* 构造方法 初始化一些参数
*/
public function initialize()
{
parent::initialize();
if (!web_config('is_register')) {
$this->error('登录未启用,请联系管理员!');
}
}
/**
* 登录
* @return string
@ -23,9 +41,6 @@ class User extends Base
*/
public function login()
{
if (!web_config('is_register')){
$this->error('登录未启用,请联系管理员!');
}
return $this->fetch();
}
@ -38,15 +53,17 @@ class User extends Base
*/
public function verify()
{
if (!web_config('is_register')){
return app("json")->fail('非法操作!');
$data = Util::postMore(['username', 'password', 'captcha'], null, true);
try {
validate(Login::class)->check($data);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
$this->error($e->getError(), null);
}
list($username, $password, $captcha) = Util::postMore(['username', 'password', 'captcha'], null, true);
if (empty($username) || empty($password)) return app("json")->fail("账号、密码和验证码不能为空!");
// 验证码验证
if (!captcha_check($captcha)) return app("json")->fail("验证码不正确!");
if (!captcha_check($data['captcha'])) return app("json")->fail("验证码不正确!");
// 验证登录
if (!userModel::login($username, $password)) return app("json")->fail(userModel::getErrorInfo());
if (!userModel::login($data['username'], $data['password'])) return app("json")->fail(userModel::getErrorInfo());
return app("json")->success("登录成功!");
}
@ -55,11 +72,8 @@ class User extends Base
* @return string
* @throws Exception
*/
public function register()
public function register(): string
{
if (!web_config('is_register')){
$this->error('注册未启用,请联系管理员!');
}
return $this->fetch();
}
@ -70,21 +84,23 @@ class User extends Base
* @throws DbException
* @throws ModelNotFoundException
*/
public function registerVerify()
public function register_verify()
{
if (!web_config('is_register')){
return app("json")->fail('非法操作!');
$data = Util::postMore(['username', 'email', 'password', 'captcha'], null, true);
try {
validate(Register::class)->check($data);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
$this->error($e->getError(), null);
}
list($username, $email, $password,$captcha) = Util::postMore(['username','email', 'password', 'captcha'], null, true);
if (empty($username) || empty($email) || empty($password) || empty($captcha)) return app("json")->fail("账号、密码和验证码不能为空!");
// 验证码验证
if (!captcha_check($captcha)) return app("json")->fail("验证码不正确!");
if (!captcha_check($data['captcha'])) return app("json")->fail("验证码不正确!");
// 验证码验证
if (!empty(web_config('register_black_list')) && in_array($username,explode(',',web_config('register_black_list')))){
if (!empty(web_config('register_black_list')) && in_array($data['username'], explode(',', web_config('register_black_list')))) {
return app("json")->fail("账号不合法,请更换后重试");
}
// 验证登录
if (!userModel::register($username,$email, $password)) return app("json")->fail(userModel::getErrorInfo());
if (!userModel::register($data['username'], $data['email'], $data['password'])) return app("json")->fail(userModel::getErrorInfo());
return app("json")->success("注册成功!我们给您邮箱发送了一封激活邮件,请按照邮件提示激活用户");
}
@ -93,11 +109,35 @@ class User extends Base
* @return string
* @throws Exception
*/
public function forget()
public function forget(): string
{
return $this->fetch();
}
/**
* @throws ModelNotFoundException
* @throws DbException
* @throws DataNotFoundException
*/
public function forget_verify()
{
list($action, $username, $key, $password) = Util::postMore(['action', 'username', 'key', 'pwd'], null, true);
//做验证
switch ($action) {
case'rested':
//重置密码
if (!userModel::resetPassword($key, $password)) return app("json")->fail(userModel::getErrorInfo());
return app("json")->success("密码重置成功!");
case 'LastPass':
// 验证码验证
if (!captcha_check($key)) return app("json")->fail("验证码不正确!");
//丢失密码 发送邮件
if (!userModel::lostPassword($username)) return app("json")->fail(userModel::getErrorInfo());
return app("json")->success("发送成功!我们给您邮箱发送了一封激活邮件,请按照邮件提示激活用户");
}
return app("json")->fail("非法访问!");
}
/**
* 退出登陆
* @return mixed
@ -105,7 +145,11 @@ class User extends Base
*/
public function logout()
{
return userModel::clearLoginInfo() ? $this->success("操作成功", "/index/index/index") : $this->error("操作失败", "/index/index/index");
if (userModel::clearLoginInfo()) {
return $this->success("操作成功", "/index/index/index");
} else {
return $this->error("操作失败", "/index/index/index");
}
}
/**
@ -125,7 +169,7 @@ class User extends Base
* 验证码
* @return Response
*/
public function captcha()
public function captcha(): Response
{
ob_clean();
return captcha();

20
app/index/route/app.php Normal file
View File

@ -0,0 +1,20 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
use think\facade\Route;
Route::get('think', function () {
return 'hello,ThinkPHP6!';
});
Route::get('hello/:name', 'index/hello');
Route::rule('/sitemap.xml', 'index/sitemap');
//单页面访问
Route::get('page/:id', 'page/index');

View File

@ -0,0 +1,24 @@
<?php
namespace app\index\validate;
use think\Validate;
class Comment extends Validate
{
protected $rule = [
'document_id' => 'require',
'pid' => 'number',
'author'=> 'require',
'url' => 'require|url',
'email' => 'require|email',
'content' => 'require',
];
protected $message = [
'author.require' => '昵称不能为空',
'email.require' => '邮箱不能为空',
'url.require' => 'url不能为空',
'document_id.require' => '文章id不能为空',
'content.require' => '内容不能为空',
];
}

View File

@ -1,13 +1,6 @@
<?php
// +----------------------------------------------------------------------
// | HulaCWMS 呼啦企业网站管理系统
// +----------------------------------------------------------------------
// | Copyright (c) 2021 https://www.kaifashu.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: 开发树
// +----------------------------------------------------------------------
namespace app\common\validate;
namespace app\index\validate;
use think\Validate;

Some files were not shown because too many files have changed in this diff Show More