diff --git a/app/admin/common.php b/app/admin/common.php index 82e0063..ad0193b 100644 --- a/app/admin/common.php +++ b/app/admin/common.php @@ -7,7 +7,7 @@ if (!function_exists('un_camelize')) { * @param string $separator * @return string */ - function un_camelize($camelCaps, $separator = '_'): string + function un_camelize($camelCaps, string $separator = '_'): string { return strtolower(preg_replace('/([a-z])([A-Z])/', "$1" . $separator . "$2", $camelCaps)); } @@ -108,7 +108,7 @@ if (!function_exists('get_dir')) { * @return mixed * @date 2021-02-17 21:27 */ - function get_dir($dir): mixed + function get_dir($dir) { $dirArray[] = NULL; if (($handle = opendir($dir))) { diff --git a/app/admin/controller/Admin.php b/app/admin/controller/Admin.php index cc7a144..e9ed2b3 100644 --- a/app/admin/controller/Admin.php +++ b/app/admin/controller/Admin.php @@ -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(); @@ -44,7 +45,7 @@ class Admin extends AuthController * @throws DbException * @throws ModelNotFoundException */ - public function lst(Request $request) + public function lst(Request $request): Response { $where = Util::postMore([ ['username', ''], @@ -66,6 +67,7 @@ class Admin extends AuthController * @throws DbException * @throws FormBuilderException * @throws ModelNotFoundException + * @throws \Exception */ public function add(): string { @@ -86,7 +88,7 @@ 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"); } @@ -99,19 +101,20 @@ class Admin extends AuthController * @throws DbException * @throws FormBuilderException * @throws ModelNotFoundException + * @throws \Exception */ - public function edit($id = ""): string + public function edit(string $id = ""): string { if (!$id) return app("json")->fail("账号id不能为空"); - $ainfo = aModel::find($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) { @@ -119,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"); } @@ -132,7 +135,7 @@ class Admin extends AuthController * @param string $id * @return mixed */ - public function save(string $id = ""): mixed + public function save(string $id = "") { $data = Util::postMore([ ['username', ''], @@ -203,14 +206,14 @@ class Admin extends AuthController * @param Request $request * @return mixed */ - public function changePwd(Request $request): mixed + public function changePwd(Request $request) { $data = Util::postMore([ ['oldpwd', ''], ['newpwd', ''] ],$request); if ($data['oldpwd'] == '' || $data['newpwd'] == '') return app("json")->fail("参数有误,新旧密码为空!"); - $adminInfo = aModel::find($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("密码不正确!"); } @@ -220,7 +223,7 @@ class Admin extends AuthController * @return string * @throws \Exception */ - public function profile() + public function profile(): string { $this->assign("info", aModel::find($this->adminId)); return $this->fetch(); @@ -231,7 +234,7 @@ class Admin extends AuthController * @param Request $request * @return mixed */ - public function changProfile(Request $request): mixed + public function changProfile(Request $request): Response { $data = Util::postMore([ ['nickname', ''], diff --git a/app/admin/controller/AdminAuth.php b/app/admin/controller/AdminAuth.php index a52b9e8..689bc31 100644 --- a/app/admin/controller/AdminAuth.php +++ b/app/admin/controller/AdminAuth.php @@ -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,12 +33,12 @@ class AdminAuth extends AuthController /** * 权限列表 * @param Request $request - * @return array + * @return Response * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException */ - public function lst(Request $request): array + public function lst(Request $request): Response { $where = Util::postMore([ ['name', ''], @@ -53,7 +57,7 @@ class AdminAuth extends AuthController * @throws ModelNotFoundException * @throws Exception */ - public function add(int $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"); } @@ -81,7 +85,7 @@ class AdminAuth extends AuthController * @throws ModelNotFoundException * @throws Exception */ - public function edit($id = 0): string + public function edit(int $id = 0): string { if (!$id) return app("json")->fail("权限id不能为空"); $info = (new \app\admin\model\AdminAuth)->find($id); @@ -97,17 +101,17 @@ class AdminAuth extends AuthController $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()); + $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', ''], @@ -144,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', '']]); diff --git a/app/admin/controller/AdminLog.php b/app/admin/controller/AdminLog.php index cc7e893..bbaf86b 100644 --- a/app/admin/controller/AdminLog.php +++ b/app/admin/controller/AdminLog.php @@ -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): array + public function lst(Request $request): Response { $where = Util::postMore([ ['name', ''], diff --git a/app/admin/controller/AdminNotify.php b/app/admin/controller/AdminNotify.php index 0324c6b..b84e299 100644 --- a/app/admin/controller/AdminNotify.php +++ b/app/admin/controller/AdminNotify.php @@ -18,7 +18,7 @@ class AdminNotify extends AuthController * @return mixed * @throws Exception */ - public function index() + public function index() : string { $where = Util::postMore([ ['title', ''], diff --git a/app/admin/controller/AdminRole.php b/app/admin/controller/AdminRole.php index 7a73ac9..a67a751 100644 --- a/app/admin/controller/AdminRole.php +++ b/app/admin/controller/AdminRole.php @@ -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): array + public function lst(Request $request): Response { return app("json")->layui(rModel::systemPage()); } @@ -50,7 +51,7 @@ class AdminRole extends AuthController $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"); } @@ -75,7 +76,7 @@ class AdminRole extends AuthController $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"); } diff --git a/app/admin/controller/Advert.php b/app/admin/controller/Advert.php index 73fce1e..e8348d0 100644 --- a/app/admin/controller/Advert.php +++ b/app/admin/controller/Advert.php @@ -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', ''], @@ -62,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"); } @@ -83,7 +87,7 @@ class Advert extends AuthController $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"); } @@ -93,7 +97,7 @@ class Advert extends AuthController * @param string $id * @return mixed */ - public function save($id = ""): mixed + public function save($id = "") { $data = Util::postMore([ ['title', ''], @@ -124,7 +128,7 @@ class Advert extends AuthController * @author 木子的忧伤 * @date 2021-02-16 23:12 */ - public function field($id): mixed + public function field($id) { if (!$id) return app("json")->fail("参数有误,Id为空!"); $where = Util::postMore([['field', ''], ['value', '']]); @@ -172,7 +176,7 @@ class Advert extends AuthController * @author 木子的忧伤 * @date 2021-02-15 23:26 */ - public function infoList(Request $request): mixed + public function infoList(Request $request) { $where = Util::postMore([ ['id', ''], @@ -208,7 +212,7 @@ 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"); } @@ -241,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"); } @@ -251,7 +255,7 @@ class Advert extends AuthController * @param string $id * @return mixed */ - public function saveAdvert($id = ""): mixed + public function saveAdvert($id = "") { $data = Util::postMore([ ['id', ''], diff --git a/app/admin/controller/Article.php b/app/admin/controller/Article.php index 8a327a6..6149523 100644 --- a/app/admin/controller/Article.php +++ b/app/admin/controller/Article.php @@ -23,7 +23,7 @@ class Article extends AuthController /** * 构造方法 初始化一些参数 */ - public function initialize() + public function initialize(): void { parent::initialize(); //修正因为修改model名称和原来不能对应导致的model功能异常 @@ -35,7 +35,7 @@ class Article extends AuthController * @return string * @throws \Exception */ - public function index() + public function index(): string { return $this->fetch(); } @@ -125,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' => '', @@ -177,7 +178,7 @@ class Article extends AuthController * @return string * @throws \Exception */ - public function comment() + public function comment(): string { return $this->fetch(); } @@ -192,7 +193,7 @@ class Article extends AuthController * @author 木子的忧伤 * @date 2021-11-03 23:28 */ - public function commentList(Request $request): mixed + public function commentList(Request $request) { $where = Util::postMore([ ['document_id', ''], @@ -216,7 +217,7 @@ class Article extends AuthController * @author 木子的忧伤 * @date 2021-02-16 23:12 */ - public function commentField($id): mixed + public function commentField($id) { if (!$id) return app("json")->fail("参数有误,Id为空!"); $where = Util::postMore([['field', ''], ['value', '']]); diff --git a/app/admin/controller/AuthController.php b/app/admin/controller/AuthController.php index accc957..4e093c9 100644 --- a/app/admin/controller/AuthController.php +++ b/app/admin/controller/AuthController.php @@ -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; } diff --git a/app/admin/controller/Category.php b/app/admin/controller/Category.php index 86a9b62..3f4ff67 100644 --- a/app/admin/controller/Category.php +++ b/app/admin/controller/Category.php @@ -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): array + 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() { @@ -103,7 +103,7 @@ class Category extends AuthController * @throws DbException * @throws ModelNotFoundException */ - public function add($pid = ''): string + public function add(string $pid = ''): string { $templatePath = system_config('web_template'); $themeInfoFile = public_path('template' . DIRECTORY_SEPARATOR . $templatePath) . 'info.json'; @@ -132,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'; diff --git a/app/admin/controller/Databases.php b/app/admin/controller/Databases.php index 6673d54..553a1df 100644 --- a/app/admin/controller/Databases.php +++ b/app/admin/controller/Databases.php @@ -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; /* * 数据库备份还原控制器 @@ -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'], diff --git a/app/admin/controller/File.php b/app/admin/controller/File.php index 3ffbc09..38529e4 100644 --- a/app/admin/controller/File.php +++ b/app/admin/controller/File.php @@ -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) diff --git a/app/admin/controller/FriendLink.php b/app/admin/controller/FriendLink.php index bf268e5..e8eaf51 100644 --- a/app/admin/controller/FriendLink.php +++ b/app/admin/controller/FriendLink.php @@ -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"); } @@ -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', ''], diff --git a/app/admin/controller/Icon.php b/app/admin/controller/Icon.php index 6d1806a..a92bb2b 100644 --- a/app/admin/controller/Icon.php +++ b/app/admin/controller/Icon.php @@ -9,7 +9,10 @@ namespace app\admin\controller; */ class Icon extends AuthController { - public function index() + /** + * @throws \Exception + */ + public function index(): string { return $this->fetch(); } diff --git a/app/admin/controller/Image.php b/app/admin/controller/Image.php index 086fa16..511f948 100644 --- a/app/admin/controller/Image.php +++ b/app/admin/controller/Image.php @@ -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,7 +125,8 @@ class Image extends AuthController /** * 删除目录 * @param $id - * @return + * @return mixed + * @throws DbException */ public function delCategory($id) { @@ -149,7 +158,7 @@ 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::find($id); diff --git a/app/admin/controller/Index.php b/app/admin/controller/Index.php index 1175718..92bed9e 100644 --- a/app/admin/controller/Index.php +++ b/app/admin/controller/Index.php @@ -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()); diff --git a/app/admin/controller/Invitation.php b/app/admin/controller/Invitation.php index 0369741..c404ced 100644 --- a/app/admin/controller/Invitation.php +++ b/app/admin/controller/Invitation.php @@ -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; diff --git a/app/admin/controller/Login.php b/app/admin/controller/Login.php index 20b8a64..4b6ca87 100644 --- a/app/admin/controller/Login.php +++ b/app/admin/controller/Login.php @@ -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(); diff --git a/app/admin/controller/Message.php b/app/admin/controller/Message.php index de88551..7d08476 100644 --- a/app/admin/controller/Message.php +++ b/app/admin/controller/Message.php @@ -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', ''], diff --git a/app/admin/controller/Nav.php b/app/admin/controller/Nav.php index 049ceae..94aeca5 100644 --- a/app/admin/controller/Nav.php +++ b/app/admin/controller/Nav.php @@ -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::find($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"); } diff --git a/app/admin/controller/Page.php b/app/admin/controller/Page.php index 53f613c..0a40195 100644 --- a/app/admin/controller/Page.php +++ b/app/admin/controller/Page.php @@ -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 */ diff --git a/app/admin/controller/SystemBasic.php b/app/admin/controller/SystemBasic.php index 983f5ed..a3ff0c9 100644 --- a/app/admin/controller/SystemBasic.php +++ b/app/admin/controller/SystemBasic.php @@ -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 = '无法打开页面') diff --git a/app/admin/controller/SystemConfig.php b/app/admin/controller/SystemConfig.php index af8bbcf..4b90ccf 100644 --- a/app/admin/controller/SystemConfig.php +++ b/app/admin/controller/SystemConfig.php @@ -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,7 +101,7 @@ 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::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::find($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) { diff --git a/app/admin/controller/SystemConfigTab.php b/app/admin/controller/SystemConfigTab.php index d90fd84..67ce87a 100644 --- a/app/admin/controller/SystemConfigTab.php +++ b/app/admin/controller/SystemConfigTab.php @@ -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,25 +54,29 @@ 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::find($id); @@ -74,7 +85,7 @@ class SystemConfigTab extends AuthController $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', ''], diff --git a/app/admin/controller/TemplateTrait.php b/app/admin/controller/TemplateTrait.php index 5861dd2..5e19a73 100644 --- a/app/admin/controller/TemplateTrait.php +++ b/app/admin/controller/TemplateTrait.php @@ -11,7 +11,10 @@ use app\Request; */ trait TemplateTrait { - public function index() + /** + * @throws \Exception + */ + public function index(): string { return $this->fetch(); } diff --git a/app/admin/controller/Theme.php b/app/admin/controller/Theme.php index fa314f6..a434831 100644 --- a/app/admin/controller/Theme.php +++ b/app/admin/controller/Theme.php @@ -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("操作失败"); } } \ No newline at end of file diff --git a/app/admin/controller/User.php b/app/admin/controller/User.php index 65b0fc2..89f4f92 100644 --- a/app/admin/controller/User.php +++ b/app/admin/controller/User.php @@ -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::find($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::find($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]); } diff --git a/app/admin/extend/FormBuilder.php b/app/admin/extend/FormBuilder.php index 9b89a64..8303558 100644 --- a/app/admin/extend/FormBuilder.php +++ b/app/admin/extend/FormBuilder.php @@ -17,10 +17,10 @@ class FormBuilder * 生成表单 * @param $rule * @param $url - * @return string|IviewForm + * @return IviewForm * @throws FormBuilderException */ - public static function make_post_form($rule, $url): string|IviewForm + public static function make_post_form($rule, $url): IviewForm { $form = new IviewForm($url); $form->setMethod('POST'); diff --git a/app/admin/model/Admin.php b/app/admin/model/Admin.php index e32b2f6..1972779 100644 --- a/app/admin/model/Admin.php +++ b/app/admin/model/Admin.php @@ -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); diff --git a/app/admin/model/AdminAuth.php b/app/admin/model/AdminAuth.php index f226b51..da9d3ad 100644 --- a/app/admin/model/AdminAuth.php +++ b/app/admin/model/AdminAuth.php @@ -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,7 +161,7 @@ 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' => cross($num) . $v['name']]; @@ -218,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) ?: []; } @@ -230,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") ?: '未知操作'; } diff --git a/app/admin/model/AdminNotify.php b/app/admin/model/AdminNotify.php index 76ef019..f829842 100644 --- a/app/admin/model/AdminNotify.php +++ b/app/admin/model/AdminNotify.php @@ -42,9 +42,13 @@ class AdminNotify extends BaseModel * @param array $data * @return int|string */ - public static function addLog(array $data): int|string + public static function addLog(array $data): bool { - return self::create($data); + if (self::create($data)){ + return true; + }else{ + return false; + } } /** diff --git a/app/admin/model/AdminRole.php b/app/admin/model/AdminRole.php index 8a76b10..3f921ee 100644 --- a/app/admin/model/AdminRole.php +++ b/app/admin/model/AdminRole.php @@ -128,7 +128,7 @@ class AdminRole extends BaseModel * @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); diff --git a/app/admin/subscribes/AdminSubscribe.php b/app/admin/subscribes/AdminSubscribe.php index b6e60dc..4b6207c 100644 --- a/app/admin/subscribes/AdminSubscribe.php +++ b/app/admin/subscribes/AdminSubscribe.php @@ -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); diff --git a/app/admin/view/admin_log/index.html b/app/admin/view/admin_log/index.html index 11e3349..ae8971a 100644 --- a/app/admin/view/admin_log/index.html +++ b/app/admin/view/admin_log/index.html @@ -67,7 +67,7 @@