mirror of https://github.com/1099438829/apeblog
优化系统的书写规范
This commit is contained in:
parent
362ea75c7a
commit
2b524af313
|
|
@ -30,7 +30,7 @@ if (!function_exists('auth_is_exit')) {
|
|||
|
||||
if (!function_exists('remove_cache')) {
|
||||
/**
|
||||
* 判断授权信息是否存在
|
||||
* 删除缓存
|
||||
* @return bool
|
||||
* @throws \Psr\SimpleCache\InvalidArgumentException
|
||||
*/
|
||||
|
|
@ -145,10 +145,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) {
|
||||
|
||||
|
|
@ -161,3 +161,71 @@ if (!function_exists('get_theme_list')) {
|
|||
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", " ", " "], '', htmlspecialchars_decode($str))));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 截取中文指定字节
|
||||
* @param string $str
|
||||
* @param int $utf8len
|
||||
* @param string $charset
|
||||
* @param string $file
|
||||
* @return string
|
||||
*/
|
||||
|
||||
if (!function_exists('substr_utf8')) {
|
||||
function substr_utf8($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
|
||||
*/
|
||||
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 . " ";
|
||||
}
|
||||
}
|
||||
|
|
@ -39,7 +39,7 @@ class Admin extends AuthController
|
|||
/**
|
||||
* 账号列表
|
||||
* @param Request $request
|
||||
* @return
|
||||
* @return mixed
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
|
|
@ -65,7 +65,7 @@ class Admin extends AuthController
|
|||
* @return string
|
||||
* @throws FormBuilderException
|
||||
*/
|
||||
public function add(Request $request)
|
||||
public function add(Request $request): string
|
||||
{
|
||||
$form = array();
|
||||
$form[] = Elm::input('username', '登录账号')->col(10);
|
||||
|
|
@ -91,13 +91,17 @@ class Admin extends AuthController
|
|||
|
||||
/**
|
||||
* 修改账号
|
||||
* @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);
|
||||
$ainfo = aModel::find($id);
|
||||
if (!$ainfo) return app("json")->fail("没有该账号");
|
||||
$form = array();
|
||||
$form[] = Elm::input('username', '登录账号', $ainfo['username'])->col(10);
|
||||
|
|
@ -126,7 +130,7 @@ class Admin extends AuthController
|
|||
* @param string $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function save($id = "")
|
||||
public function save(string $id = ""): mixed
|
||||
{
|
||||
$data = Util::postMore([
|
||||
['username', ''],
|
||||
|
|
@ -163,7 +167,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();
|
||||
|
|
@ -188,7 +192,7 @@ class Admin extends AuthController
|
|||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function pwd(Request $request)
|
||||
public function pwd(Request $request): string
|
||||
{
|
||||
return $this->fetch();
|
||||
}
|
||||
|
|
@ -198,14 +202,14 @@ class Admin extends AuthController
|
|||
* @param Request $request
|
||||
* @return mixed
|
||||
*/
|
||||
public function changePwd(Request $request)
|
||||
public function changePwd(Request $request): mixed
|
||||
{
|
||||
$data = Util::postMore([
|
||||
['oldpwd', ''],
|
||||
['newpwd', '']
|
||||
]);
|
||||
if ($data['oldpwd'] == '' || $data['newpwd'] == '') return app("json")->fail("参数有误,新旧密码为空!");
|
||||
$adminInfo = aModel::get($this->adminId);
|
||||
$adminInfo = aModel::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("密码不正确!");
|
||||
}
|
||||
|
|
@ -217,7 +221,7 @@ class Admin extends AuthController
|
|||
*/
|
||||
public function profile()
|
||||
{
|
||||
$this->assign("info", aModel::get($this->adminId));
|
||||
$this->assign("info", aModel::find($this->adminId));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,12 +34,12 @@ class AdminAuth extends AuthController
|
|||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function lst(Request $request)
|
||||
public function lst(Request $request): array
|
||||
{
|
||||
$where = Util::postMore([
|
||||
['name', ''],
|
||||
['status', '']
|
||||
]);
|
||||
],$request);
|
||||
return app("json")->layui(aModel::systemPage($where));
|
||||
}
|
||||
|
||||
|
|
@ -53,7 +53,7 @@ class AdminAuth 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);
|
||||
|
|
@ -79,23 +79,24 @@ class AdminAuth extends AuthController
|
|||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function edit($id = 0)
|
||||
public function edit($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[] = 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('save', ['id' => $id])->build());
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch("public/form-builder");
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class AdminLog extends AuthController
|
|||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function lst(Request $request)
|
||||
public function lst(Request $request): array
|
||||
{
|
||||
$where = Util::postMore([
|
||||
['name', ''],
|
||||
|
|
@ -46,18 +46,17 @@ class AdminLog extends AuthController
|
|||
['end_time', ''],
|
||||
['page', 1],
|
||||
['limit', 20],
|
||||
]);
|
||||
],$request);
|
||||
return app("json")->layui(lModel::systemPage($where));
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空日志
|
||||
* @param Request $request
|
||||
* @throws Exception
|
||||
*/
|
||||
public function empty(Request $request)
|
||||
public function empty()
|
||||
{
|
||||
$res = lModel::where("1=1")->delete();
|
||||
$res = (new \app\admin\model\AdminLog)->where("1=1")->delete();
|
||||
return $res ? app("json")->success("操作成功", 'code') : app("json")->fail("操作失败");
|
||||
}
|
||||
}
|
||||
|
|
@ -28,7 +28,7 @@ class AdminRole extends AuthController
|
|||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function lst(Request $request)
|
||||
public function lst(Request $request): array
|
||||
{
|
||||
return app("json")->layui(rModel::systemPage());
|
||||
}
|
||||
|
|
@ -47,7 +47,7 @@ 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());
|
||||
|
|
@ -67,12 +67,12 @@ 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());
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ 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);
|
||||
|
|
@ -93,7 +93,7 @@ class Advert extends AuthController
|
|||
* @param string $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function save($id = "")
|
||||
public function save($id = ""): mixed
|
||||
{
|
||||
$data = Util::postMore([
|
||||
['title', ''],
|
||||
|
|
@ -124,7 +124,7 @@ class Advert extends AuthController
|
|||
* @author 木子的忧伤
|
||||
* @date 2021-02-16 23:12
|
||||
*/
|
||||
public function field($id)
|
||||
public function field($id): mixed
|
||||
{
|
||||
if (!$id) return app("json")->fail("参数有误,Id为空!");
|
||||
$where = Util::postMore([['field', ''], ['value', '']]);
|
||||
|
|
@ -145,7 +145,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);
|
||||
}
|
||||
|
||||
|
|
@ -156,7 +156,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();
|
||||
|
|
@ -172,7 +172,7 @@ class Advert extends AuthController
|
|||
* @author 木子的忧伤
|
||||
* @date 2021-02-15 23:26
|
||||
*/
|
||||
public function infoList(Request $request)
|
||||
public function infoList(Request $request): mixed
|
||||
{
|
||||
$where = Util::postMore([
|
||||
['id', ''],
|
||||
|
|
@ -182,7 +182,7 @@ class Advert extends AuthController
|
|||
['status', ''],
|
||||
['page', 1],
|
||||
['limit', 20],
|
||||
]);
|
||||
],$request);
|
||||
return app("json")->layui(tModel::systemPage($where));
|
||||
}
|
||||
|
||||
|
|
@ -192,7 +192,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);
|
||||
|
|
@ -215,13 +215,17 @@ class Advert extends AuthController
|
|||
|
||||
/**
|
||||
* 修改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);
|
||||
|
|
@ -247,7 +251,7 @@ class Advert extends AuthController
|
|||
* @param string $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function saveAdvert($id = "")
|
||||
public function saveAdvert($id = ""): mixed
|
||||
{
|
||||
$data = Util::postMore([
|
||||
['id', ''],
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -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
|
||||
*/
|
||||
|
|
@ -181,6 +184,7 @@ class Article extends AuthController
|
|||
|
||||
/**
|
||||
* 文章评论列表
|
||||
* @param Request $request
|
||||
* @return mixed
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
|
|
@ -188,7 +192,7 @@ class Article extends AuthController
|
|||
* @author 木子的忧伤
|
||||
* @date 2021-11-03 23:28
|
||||
*/
|
||||
public function commentList()
|
||||
public function commentList(Request $request): mixed
|
||||
{
|
||||
$where = Util::postMore([
|
||||
['document_id', ''],
|
||||
|
|
@ -199,7 +203,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));
|
||||
}
|
||||
|
|
@ -212,7 +216,7 @@ class Article extends AuthController
|
|||
* @author 木子的忧伤
|
||||
* @date 2021-02-16 23:12
|
||||
*/
|
||||
public function commentField($id)
|
||||
public function commentField($id): mixed
|
||||
{
|
||||
if (!$id) return app("json")->fail("参数有误,Id为空!");
|
||||
$where = Util::postMore([['field', ''], ['value', '']]);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ class Category extends AuthController
|
|||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function lst(Request $request)
|
||||
public function lst(Request $request): array
|
||||
{
|
||||
$where = Util::postMore([
|
||||
['name', ''],
|
||||
|
|
@ -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($pid = ''): 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);
|
||||
|
|
|
|||
|
|
@ -26,7 +26,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';
|
||||
|
|
|
|||
|
|
@ -83,7 +83,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);
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ class Image extends AuthController
|
|||
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("删除失败");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -152,7 +152,7 @@ class Image extends AuthController
|
|||
public function editImage($id)
|
||||
{
|
||||
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 +179,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 +192,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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ class Nav extends AuthController
|
|||
public function edit($id = 0)
|
||||
{
|
||||
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::select('pid', '上级导航', $ainfo['pid'])->options(aModel::returnOptions())->col(10);
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ class SystemConfig extends AuthController
|
|||
*/
|
||||
public function index($tab_id = 0)
|
||||
{
|
||||
$this->assign("tab", tModel::get($tab_id));
|
||||
$this->assign("tab", tModel::find($tab_id));
|
||||
return $this->fetch("list");
|
||||
}
|
||||
|
||||
|
|
@ -137,7 +137,7 @@ class SystemConfig extends AuthController
|
|||
public function edit($id = '')
|
||||
{
|
||||
if (!$id) return app("json")->fail("项目id不能为空");
|
||||
$info = cModel::get($id);
|
||||
$info = cModel::find($id);
|
||||
if (!$info) return app("json")->fail("没有该项目");
|
||||
$form = array();
|
||||
$form[] = Elm::hidden('tab_id', $info['tab_id'])->col(10);
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ class SystemConfigTab extends AuthController
|
|||
public function edit($id = '')
|
||||
{
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ class User 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('username', '登录账号', $ainfo['username'])->col(10);
|
||||
|
|
@ -135,7 +135,7 @@ class User extends AuthController
|
|||
$data['create_user'] = $this->adminId;
|
||||
$res = aModel::create($data);
|
||||
} else {
|
||||
$ainfo = aModel::get($id);
|
||||
$ainfo = aModel::find($id);
|
||||
if ($ainfo['password'] != $data['password']) $data['password'] = md5(md5($data['password']));
|
||||
$data['update_user'] = $this->adminId;
|
||||
$res = aModel::update($data, ['id' => $id]);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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,25 +121,11 @@ 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
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -152,15 +153,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 +173,13 @@ if (!function_exists('get_rand_str')) {
|
|||
* @author 木子的忧伤
|
||||
* @date 2022-04-11 18:26
|
||||
*/
|
||||
function get_rand_str($length){
|
||||
function get_rand_str($length)
|
||||
{
|
||||
//字符组合
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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)) {
|
||||
|
|
|
|||
|
|
@ -29,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
|
||||
|
|
@ -104,17 +44,6 @@ trait ModelTrait
|
|||
return 0 < $model->where($map)->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除一条数据
|
||||
* @param $id
|
||||
* @return bool $type 返回成功失败
|
||||
*/
|
||||
public static function del($id)
|
||||
{
|
||||
return false !== self::destroy($id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 分页
|
||||
* @param null $model 模型
|
||||
|
|
@ -159,185 +88,4 @@ trait ModelTrait
|
|||
$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", " ", " "], '', 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 . " ";
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
@ -64,8 +64,13 @@ class Article extends Base
|
|||
$template = Data::DOCUMENT_CATEGORY . '/' . ($dc['template'] ?: 'index.html');
|
||||
$templateFile = config('view.view_path') . $template;
|
||||
if (!is_file($templateFile)) {
|
||||
//配置的模版文件不存在则走默认模版
|
||||
$template = Data::DOCUMENT_CATEGORY . '/' . 'index.html';
|
||||
$templateFile = config('view.view_path') . $template;
|
||||
if (!is_file($templateFile)){
|
||||
$this->error('模板文件不存在!');
|
||||
}
|
||||
}
|
||||
Log::info('列表页模板路径:' . $templateFile);
|
||||
//文章兼容字段
|
||||
$dc['category_id'] = $dc['id'];
|
||||
|
|
@ -95,6 +100,7 @@ class Article extends Base
|
|||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
* @throws \Exception
|
||||
* @author 木子的忧伤
|
||||
* @date 2021-10-29 0:17
|
||||
*/
|
||||
|
|
@ -119,11 +125,17 @@ 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)) {
|
||||
//配置的模版文件不存在则走默认模版
|
||||
$template = Data::DOCUMENT_CATEGORY . '/' . 'detail.html';
|
||||
$templateFile = config('view.view_path') . $template;
|
||||
if (!is_file($templateFile)){
|
||||
$this->error('模板文件不存在!');
|
||||
}
|
||||
}
|
||||
$article['category_title'] = $dc['title'];
|
||||
//判断SEO 为空则取系统
|
||||
$article['keywords'] = $article['keywords'] ?: web_config('keywords');
|
||||
|
|
@ -197,9 +209,7 @@ class Article extends Base
|
|||
/**
|
||||
* 文章标签页面
|
||||
* @return string
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
* @throws ModelNotFoundException|\Exception
|
||||
* @author 木子的忧伤
|
||||
* @date 2021-10-29 0:19
|
||||
*/
|
||||
|
|
@ -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('模板文件不存在!');
|
||||
}
|
||||
|
|
@ -264,7 +274,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('模板文件不存在!');
|
||||
}
|
||||
|
|
@ -301,7 +311,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('模板文件不存在!');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,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
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
//获取该文章
|
||||
|
|
|
|||
|
|
@ -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('参数错误');
|
||||
|
|
|
|||
|
|
@ -49,11 +49,16 @@ class Page extends Base
|
|||
$article['position'] = '<a href="/">首页</a><span>></span>';
|
||||
//更新浏览次数
|
||||
$documentModel->where('id', $article['id'])->inc('view')->update();
|
||||
$template = Data::DOCUMENT_TYPE_PAGE . '/' . ($article['theme'] ?: 'index.html');
|
||||
$template = Data::DOCUMENT_TYPE_PAGE . '/' . ($article['template'] ?: 'index.html');
|
||||
$templateFile = config('view.view_path') . $template;
|
||||
if (!is_file($templateFile)) {
|
||||
//配置的模版文件不存在则走默认模版
|
||||
$template = Data::DOCUMENT_TYPE_PAGE . '/' . 'index.html';
|
||||
$templateFile = config('view.view_path') . $template;
|
||||
if (!is_file($templateFile)){
|
||||
$this->error('模板文件不存在!');
|
||||
}
|
||||
}
|
||||
$article['category_title'] = "单页";
|
||||
//判断SEO 为空则取系统
|
||||
$article['keywords'] = $article['keywords'] ?: web_config('keywords');
|
||||
|
|
@ -83,7 +88,7 @@ class Page extends Base
|
|||
* @author 木子的忧伤
|
||||
* @date 2021-10-17 19:13
|
||||
*/
|
||||
public function create_comment(Request $request)
|
||||
public function create_comment(Request $request): mixed
|
||||
{
|
||||
$data = Util::postMore([
|
||||
['document_id', ''],
|
||||
|
|
@ -92,7 +97,7 @@ class Page extends Base
|
|||
['url', ''],
|
||||
['email', ''],
|
||||
['content', ''],
|
||||
]);
|
||||
],$request);
|
||||
if (!web_config('comment_close')){
|
||||
$this->error('非法操作,请检查后重试', null);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ class User extends Base
|
|||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function verify()
|
||||
public function verify(): mixed
|
||||
{
|
||||
$data = Util::postMore(['username', 'password', 'captcha'], null, true);
|
||||
try {
|
||||
|
|
@ -72,7 +72,7 @@ class User extends Base
|
|||
* @return string
|
||||
* @throws Exception
|
||||
*/
|
||||
public function register()
|
||||
public function register(): string
|
||||
{
|
||||
return $this->fetch();
|
||||
}
|
||||
|
|
@ -84,7 +84,7 @@ class User extends Base
|
|||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function register_verify()
|
||||
public function register_verify(): mixed
|
||||
{
|
||||
$data = Util::postMore(['username', 'email', 'password', 'captcha'], null, true);
|
||||
try {
|
||||
|
|
@ -109,7 +109,7 @@ class User extends Base
|
|||
* @return string
|
||||
* @throws Exception
|
||||
*/
|
||||
public function forget()
|
||||
public function forget(): string
|
||||
{
|
||||
return $this->fetch();
|
||||
}
|
||||
|
|
@ -143,9 +143,13 @@ class User extends Base
|
|||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function logout()
|
||||
public function logout(): mixed
|
||||
{
|
||||
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();
|
||||
|
|
|
|||
Loading…
Reference in New Issue