Compare commits

...

7 Commits

Author SHA1 Message Date
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
73 changed files with 624 additions and 780 deletions

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) {
@ -145,10 +153,10 @@ if (!function_exists('get_tree_list')) {
}
if (!function_exists('get_theme_list')) {
function get_theme_list($type = ''):array
function get_theme_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 ($dh = opendir($themeDir)) {
while (($file = readdir($dh)) !== false) {
@ -158,6 +166,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

@ -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,17 +56,20 @@ 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);
@ -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', ''],
@ -163,7 +172,7 @@ class Admin extends AuthController
$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,9 @@ 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", aModel::find($this->adminId));
return $this->fetch();
}
@ -226,7 +234,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

@ -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,7 +57,7 @@ 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);
@ -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', ''],
@ -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

@ -9,6 +9,7 @@ use Exception;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\Response;
/**
* 日志
@ -24,7 +25,7 @@ class AdminLog extends AuthController
* @return string
* @throws Exception
*/
public function index()
public function index(): string
{
return $this->fetch();
}
@ -32,12 +33,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 +45,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

@ -18,7 +18,7 @@ class AdminNotify extends AuthController
* @return mixed
* @throws Exception
*/
public function index()
public function index() : string
{
$where = Util::postMore([
['title', ''],

View File

@ -12,10 +12,11 @@ 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");
}

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");
}
@ -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,7 +196,7 @@ 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);
@ -207,20 +212,24 @@ 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);
@ -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");
}

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
*/
@ -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

@ -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);
}
@ -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()
{
@ -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,10 +97,13 @@ 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';
@ -129,7 +132,7 @@ 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';
@ -145,7 +148,7 @@ class Category extends AuthController
]);
$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);
$this->assign("template_list", $themeList);

View File

@ -11,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;
/*
* 数据库备份还原控制器
@ -26,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';
@ -57,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

@ -70,7 +70,7 @@ class File extends AuthController
/**
* @单文件上传
* @param string $type 类型 files image documents banners
* @param Request $request
* @return mixed
*/
public function upload(Request $request)

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', ''],
@ -70,7 +71,7 @@ class FriendLink extends AuthController
$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,7 +84,7 @@ 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);
@ -92,7 +93,7 @@ class FriendLink extends AuthController
$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();
}
@ -37,7 +40,7 @@ class Image extends AuthController
* @throws DbException
* @throws ModelNotFoundException
*/
public function category()
public function category(): array
{
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::isExist($id, "cid")) return app("json")->fail("该分类下有图片不能删除");
if (AttachmentCategory::isExist($id, "pid")) return app("json")->fail("该分类下有子分类不能删除");
return AttachmentCategory::del($id) ? app("json")->success("删除成功") : 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

@ -15,7 +15,7 @@ class Index extends AuthController
* @return string
* @throws Exception
*/
public function index()
public function index(): string
{
$this->assign("adminInfo", $this->adminInfo);
$this->assign("menu", AdminAuth::getAuthList($this->adminId,$this->auth));
@ -28,7 +28,7 @@ class Index extends AuthController
* @return string
* @throws Exception
*/
public function main()
public function main(): string
{
$this->assign("document_count", (new Document)->count());
$this->assign("user_count", (new User())->count());

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

@ -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,7 +58,7 @@ 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);
@ -64,7 +68,7 @@ class Nav extends AuthController
$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::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', '链接地址', $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::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");
}

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
*/
@ -124,7 +126,7 @@ class Page extends AuthController
* @return string
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @throws ModelNotFoundException|\Exception
* @author 木子的忧伤
* @date 2021-03-10 14:46
*/

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,7 +33,7 @@ class SystemConfig extends AuthController
* @throws DbException
* @throws ModelNotFoundException
*/
public function base($tab_id = 1)
public function base($tab_id = 1): string
{
$system = cModel::getLstByTabId($tab_id);
//特殊处理主题信息,这里不允许修改主题信息
@ -55,38 +56,42 @@ class SystemConfig extends AuthController
/**
* @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/";
$commonPath = config("cache.runtime") . "/cache/";
$indexPath = config("cache.runtime") . "/index/";
$apiPath = config("cache.runtime") . "/api/";
// $indexPath = config("cache.runtime") . "/index/";
// $apiPath = config("cache.runtime") . "/api/";
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));
}
@ -96,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");
}
@ -108,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);
@ -123,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);
@ -152,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");
}
@ -162,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', ''],
@ -199,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', ''],

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 = [];
// 寻找有多少主题
@ -57,14 +58,14 @@ class Theme extends AuthController
* @author 木子的忧伤
* @date 2021-02-17 11:40
*/
public function change_theme()
public function change_theme(): string
{
$data = Util::postMore([
['value', ''],
]);
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,8 +62,9 @@ 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);
@ -73,31 +75,35 @@ class User extends AuthController
$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

@ -19,8 +19,8 @@ class Admin extends BaseModel
{
/**
* 登录
* @param $username
* @param $pwd
* @param string $username
* @param string $pwd
* @return bool
* @throws DataNotFoundException
* @throws DbException
@ -28,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("账号已被冻结!");
@ -41,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字段避免频繁查询
@ -54,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);

View File

@ -133,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;
}
@ -143,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';
}
@ -161,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);
}
@ -186,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
@ -233,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) ?: [];
}
@ -245,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

@ -25,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,
@ -34,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;
]);
}
/**
@ -43,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");

View File

@ -42,9 +42,13 @@ 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::create($data);
if (self::create($data)){
return true;
}else{
return false;
}
}
/**
@ -55,7 +59,7 @@ class AdminNotify extends BaseModel
* @throws DbException
* @throws ModelNotFoundException
*/
public static function pageList(int $num)
public static function pageList(int $num): array
{
$model = new self;
$model = $model->where("is_read", 0);

View File

@ -24,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") ?: '';
}
/**
@ -36,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() : [];
}
@ -47,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
@ -97,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);
}
@ -122,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

@ -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

@ -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

@ -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

@ -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

@ -97,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

@ -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

@ -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

@ -15,7 +15,7 @@ class Index extends Base
/**
* 入口跳转链接
*/
public function index()
public function index() : string
{
return app("json")->success("获取成功", 'code');
}

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

@ -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::count();
$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

@ -113,6 +113,7 @@ class Document extends BaseModel
self::setErrorInfo("别名已存在,请修改后重试");
return false;
}
$model = null;
switch ($type) {
case Data::DOCUMENT_TYPE_ARTICLE:
$contentData = [
@ -156,7 +157,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)) {

View File

@ -4,6 +4,7 @@
namespace app\common\model;
use think\db\BaseQuery;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
@ -28,66 +29,6 @@ trait ModelTrait
return $this->error;
}
/**
* @throws DataNotFoundException
* @throws ModelNotFoundException
* @throws DbException
*/
public static function get($where)
{
if (!is_array($where)) {
return (new BaseModel)->find($where);
} else {
return (new BaseModel)->where($where)->find();
}
}
/**
* @throws ModelNotFoundException
* @throws DataNotFoundException
* @throws DbException
*/
public static function all($function)
{
$query = (new BaseModel)->newQuery();
$function($query);
return $query->select();
}
/**
* 添加多条数据
* @param $group
* @param bool $replace
* @return int
*/
public static function setAll($group, bool $replace = false)
{
return (new BaseModel)->insertAll($group, $replace);
}
/**
* 修改一条数据
* @param $data
* @param $id
* @param $field
* @return bool $type 返回成功失败
*/
public static function edit($data, $id, $field = null): bool
{
$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
@ -102,241 +43,4 @@ trait ModelTrait
$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 ModelTrait
*/
public static function page($model = null, $eachFn = null, $params = [], $limit = 20): ModelTrait
{
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::getField($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::getField($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 getField($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 $charset
* @param string $file
* @return string
*/
public static function getSubstrUTf8($str, int $utf8len = 100, string $charset = 'UTF-8', string $file = '....'): string
{
if (mb_strlen($str, $charset) > $utf8len) {
$str = mb_substr($str, 0, $utf8len, $charset) . $file;
}
return $str;
}
/**
* 获取本季度 time
* @param int|string $time
* @param string $ceil
* @return array
*/
public static function getMonth($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
*/
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

@ -15,17 +15,17 @@ class PvLog extends BaseModel
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()

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::count();
$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,7 +20,7 @@ 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']);

View File

@ -20,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

@ -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

@ -23,7 +23,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 +31,7 @@ function cn_substr($str, $len)
/**
* 过滤html标签
*/
function html2text($str)
function html2text($str): string
{
return strip_tags($str);
}
@ -286,7 +286,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();
@ -1180,7 +1180,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();
@ -1213,7 +1213,7 @@ function get_nav_list()
return $navList;
}
function get_nav_all()
function get_nav_all(): array
{
$list = get_nav_list();
$tempArr = array();
@ -1232,7 +1232,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

@ -33,7 +33,7 @@ class Article extends Base
* @author 木子的忧伤
* @date 2021-10-29 0:17
*/
public function lists()
public function lists(): string
{
$dc = false;
//栏目分类id
@ -61,10 +61,15 @@ class Article extends Base
$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);
//文章兼容字段
@ -95,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) {
@ -119,10 +125,16 @@ 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');
$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 为空则取系统
@ -197,13 +209,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)) {
@ -226,7 +236,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('模板文件不存在!');
}
@ -236,13 +246,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)) {
@ -264,7 +272,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('模板文件不存在!');
}
@ -274,7 +282,7 @@ class Article extends Base
/**
* 用户首页
* @return string
* @throws Exception
* @throws \Exception
* @author 木子的忧伤
* @date 2022-01-24 1:23
*/
@ -301,7 +309,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,12 +30,10 @@ 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);
}
//判断是否关闭站点。
@ -70,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

@ -27,8 +27,9 @@ class Index extends Base
{
/**
* 入口跳转链接
* @throws \Exception
*/
public function index()
public function index(): string
{
//判断后台统计配置是否开启 1 开启
if (web_config("web_statistics") == 1) {
@ -50,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([
@ -94,13 +96,11 @@ 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([
@ -134,10 +134,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";
//获取该文章

View File

@ -7,7 +7,7 @@ class Oauth extends BaseController
{
//登录地址
public function login($type = null)
public function login($type = null): void
{
if ($type == null) {
$this->error('参数错误');
@ -34,7 +34,7 @@ class Oauth extends BaseController
}
//授权回调地址
public function callback($type = null, $code = null)
public function callback($type = null, $code = null): void
{
if ($type == null || $code == null) {
$this->error('参数错误');

View File

@ -32,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) {
@ -49,10 +49,15 @@ 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 为空则取系统
@ -92,7 +97,7 @@ class Page extends Base
['url', ''],
['email', ''],
['content', ''],
]);
],$request);
if (!web_config('comment_close')){
$this->error('非法操作,请检查后重试', null);
}

View File

@ -72,7 +72,7 @@ class User extends Base
* @return string
* @throws Exception
*/
public function register()
public function register(): string
{
return $this->fetch();
}
@ -109,7 +109,7 @@ class User extends Base
* @return string
* @throws Exception
*/
public function forget()
public function forget(): string
{
return $this->fetch();
}
@ -145,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");
}
}
/**
@ -165,7 +169,7 @@ class User extends Base
* 验证码
* @return Response
*/
public function captcha()
public function captcha(): Response
{
ob_clean();
return captcha();

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

View File

@ -47,7 +47,7 @@ jQuery( function() {
//图片加载失败
$("img").error(function(){
//当图片加载失败时,你要进行的操作
$(this).attr('src','/static/admin/img/logo-ico.png');
$(this).attr('src','/static/admin/img/logo1.png');
});
// 侧边栏导航

View File

@ -124,7 +124,7 @@
<div class="post-item-meta">
<div class="post-item-meta-item">
<span class="post-item-meta-author">
<!-- <img src="{$field['avatar']}" width="24" height="24" alt="头像" class="avatar avatar-24 wp-user-avatar wp-user-avatar-24 photo avatar-default post-item-avatar">-->
<!-- <img src="" width="24" height="24" alt="头像" class="avatar avatar-24 wp-user-avatar wp-user-avatar-24 photo avatar-default post-item-avatar">-->
{$field['author']}
</span>
<span class="post-item-time">{$field['create_time']}</span>

View File

@ -44,7 +44,7 @@
<div class="menu-mobile">
<ul class="menu-mobile-header-list">
{ape:nav type="all"}
<li id="menu-item-{$field.id}" class="menu-item {notempty name="field['child']"}menu-item-has-children{/notempty} {:is_active_nav($cid,$field['id'])?'current-menu-item current_page_item':''} menu-item-{$field['id']}">
<li id="menu-item-{$field.id}" class="menu-item {notempty name="field['child']"}menu-item-has-children {:is_active_nav($cid,$field['pid'])?'current-menu-item current_page_item':''} {else} {:is_active_nav($cid,$field['id'])?'current-menu-item current_page_item':''} {/notempty} menu-item-{$field['id']}">
{notempty name="field['child']"}
<a href="#" aria-current="page">{$field['title']}</a>
{else /}

View File

@ -1365,17 +1365,17 @@
},
{
"name": "symfony/http-foundation",
"version": "v5.4.28",
"version_normalized": "5.4.28.0",
"version": "v5.4.30",
"version_normalized": "5.4.30.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/http-foundation.git",
"reference": "365992c83a836dfe635f1e903ccca43ee03d3dd2"
"reference": "671769f79de0532da1478c60968b42506e185d2e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/http-foundation/zipball/365992c83a836dfe635f1e903ccca43ee03d3dd2",
"reference": "365992c83a836dfe635f1e903ccca43ee03d3dd2",
"url": "https://api.github.com/repos/symfony/http-foundation/zipball/671769f79de0532da1478c60968b42506e185d2e",
"reference": "671769f79de0532da1478c60968b42506e185d2e",
"shasum": "",
"mirrors": [
{
@ -1402,7 +1402,7 @@
"suggest": {
"symfony/mime": "To use the file extension guesser"
},
"time": "2023-08-21T07:23:18+00:00",
"time": "2023-10-28T23:35:12+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
@ -1430,7 +1430,7 @@
"description": "Defines an object-oriented layer for the HTTP specification",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/http-foundation/tree/v5.4.28"
"source": "https://github.com/symfony/http-foundation/tree/v5.4.30"
},
"funding": [
{

View File

@ -3,7 +3,7 @@
'name' => 'topthink/think',
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'reference' => 'a284ab8feb3db76d633b4d2320202e59e209a9a0',
'reference' => '7cb03187a94546bb6ec2c895b331743c8c72fce9',
'type' => 'project',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
@ -194,9 +194,9 @@
),
),
'symfony/http-foundation' => array(
'pretty_version' => 'v5.4.28',
'version' => '5.4.28.0',
'reference' => '365992c83a836dfe635f1e903ccca43ee03d3dd2',
'pretty_version' => 'v5.4.30',
'version' => '5.4.30.0',
'reference' => '671769f79de0532da1478c60968b42506e185d2e',
'type' => 'library',
'install_path' => __DIR__ . '/../symfony/http-foundation',
'aliases' => array(),
@ -295,7 +295,7 @@
'topthink/think' => array(
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'reference' => 'a284ab8feb3db76d633b4d2320202e59e209a9a0',
'reference' => '7cb03187a94546bb6ec2c895b331743c8c72fce9',
'type' => 'project',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),

2
vendor/services.php vendored
View File

@ -1,5 +1,5 @@
<?php
// This file is automatically generated at:2023-10-18 19:05:37
// This file is automatically generated at:2023-11-03 23:08:15
declare (strict_types = 1);
return array (
0 => 'think\\captcha\\CaptchaService',

View File

@ -33,17 +33,21 @@ class HeaderUtils
*
* Example:
*
* HeaderUtils::split("da, en-gb;q=0.8", ",;")
* HeaderUtils::split('da, en-gb;q=0.8', ',;')
* // => ['da'], ['en-gb', 'q=0.8']]
*
* @param string $separators List of characters to split on, ordered by
* precedence, e.g. ",", ";=", or ",;="
* precedence, e.g. ',', ';=', or ',;='
*
* @return array Nested array with as many levels as there are characters in
* $separators
*/
public static function split(string $header, string $separators): array
{
if ('' === $separators) {
throw new \InvalidArgumentException('At least one separator must be specified.');
}
$quotedSeparators = preg_quote($separators, '/');
preg_match_all('
@ -77,8 +81,8 @@ class HeaderUtils
*
* Example:
*
* HeaderUtils::combine([["foo", "abc"], ["bar"]])
* // => ["foo" => "abc", "bar" => true]
* HeaderUtils::combine([['foo', 'abc'], ['bar']])
* // => ['foo' => 'abc', 'bar' => true]
*/
public static function combine(array $parts): array
{
@ -95,13 +99,13 @@ class HeaderUtils
/**
* Joins an associative array into a string for use in an HTTP header.
*
* The key and value of each entry are joined with "=", and all entries
* The key and value of each entry are joined with '=', and all entries
* are joined with the specified separator and an additional space (for
* readability). Values are quoted if necessary.
*
* Example:
*
* HeaderUtils::toString(["foo" => "abc", "bar" => true, "baz" => "a b c"], ",")
* HeaderUtils::toString(['foo' => 'abc', 'bar' => true, 'baz' => 'a b c'], ',')
* // => 'foo=abc, bar, baz="a b c"'
*/
public static function toString(array $assoc, string $separator): string
@ -252,40 +256,37 @@ class HeaderUtils
private static function groupParts(array $matches, string $separators, bool $first = true): array
{
$separator = $separators[0];
$partSeparators = substr($separators, 1);
$separators = substr($separators, 1);
$i = 0;
if ('' === $separators && !$first) {
$parts = [''];
foreach ($matches as $match) {
if (!$i && isset($match['separator'])) {
$i = 1;
$parts[1] = '';
} else {
$parts[$i] .= self::unquote($match[0]);
}
}
return $parts;
}
$parts = [];
$partMatches = [];
$previousMatchWasSeparator = false;
foreach ($matches as $match) {
if (!$first && $previousMatchWasSeparator && isset($match['separator']) && $match['separator'] === $separator) {
$previousMatchWasSeparator = true;
$partMatches[$i][] = $match;
} elseif (isset($match['separator']) && $match['separator'] === $separator) {
$previousMatchWasSeparator = true;
if (($match['separator'] ?? null) === $separator) {
++$i;
} else {
$previousMatchWasSeparator = false;
$partMatches[$i][] = $match;
}
}
$parts = [];
if ($partSeparators) {
foreach ($partMatches as $matches) {
$parts[] = self::groupParts($matches, $partSeparators, false);
}
} else {
foreach ($partMatches as $matches) {
$parts[] = self::unquote($matches[0][0]);
}
if (!$first && 2 < \count($parts)) {
$parts = [
$parts[0],
implode($separator, \array_slice($parts, 1)),
];
}
foreach ($partMatches as $matches) {
$parts[] = '' === $separators ? self::unquote($matches[0][0]) : self::groupParts($matches, $separators, false);
}
return $parts;

View File

@ -94,27 +94,30 @@ class CustomComponent implements CustomComponentInterface, \JsonSerializable, \A
return $this->appendRule + $this->getRule();
}
public function jsonSerialize()
/**
* @return void
*/
public function jsonSerialize(): mixed
{
return $this->build();
}
public function offsetExists($offset)
public function offsetExists($offset):bool
{
return isset($this->props[$offset]);
}
public function offsetGet($offset)
public function offsetGet($offset): mixed
{
return $this->props[$offset];
}
public function offsetSet($offset, $value)
public function offsetSet($offset, $value) : void
{
$this->props[$offset] = $value;
}
public function offsetUnset($offset)
public function offsetUnset($offset): void
{
unset($this->props[$offset]);
}