45 Commits
v1 ... v2.1

Author SHA1 Message Date
JaguarJack
90990f8782 update:微信模块初始化未安装状态 2020-09-11 07:43:44 +08:00
JaguarJack
40276babfb update:更新安装&新增本地模块安装 2020-09-11 07:42:38 +08:00
JaguarJack
818ffb2ce6 fixed:修复异常code 2020-09-09 11:35:01 +08:00
JaguarJack
763a05fa80 update:优化登录 2020-09-09 10:40:44 +08:00
JaguarJack
8c153cce60 update:转换路径 2020-09-08 19:54:05 +08:00
JaguarJack
93b6f1e2f1 fixed:数据字典分页 2020-09-08 19:36:24 +08:00
JaguarJack
61b9a07d99 update:新增角色标识唯一性 2020-09-08 16:25:36 +08:00
JaguarJack
d75c455bdc update:更新用户部门搜索 2020-09-08 14:36:32 +08:00
JaguarJack
04e2b1ffe5 update:更新项目安装,增加项目domain配置 2020-09-08 14:34:03 +08:00
JaguarJack
14b5b3ce3a update:更新角色初始化数据 2020-09-08 14:31:30 +08:00
JaguarJack
a4e84ffa75 update:更新配置 2020-09-08 14:13:00 +08:00
JaguarJack
bd7f62b9ed add:新增导出用户 2020-09-08 14:12:42 +08:00
JaguarJack
3a2689db18 update:更新部分组件 2020-09-08 14:10:27 +08:00
JaguarJack
3fb55deaaf add:优雅的返回 Json 数据 2020-09-08 10:06:53 +08:00
JaguarJack
b07defb0e9 update 2020-09-07 20:14:03 +08:00
JaguarJack
377b72ae19 update 2020-09-07 19:57:58 +08:00
JaguarJack
dd023caf36 update:readme 2020-09-07 17:37:49 +08:00
JaguarJack
163d1c4bee update:更新部门及以下数据权限 2020-09-07 16:16:25 +08:00
JaguarJack
2c2b7f8723 fixed table 2020-09-07 14:05:36 +08:00
JaguarJack
d533aeaa9e update 2020-09-07 08:29:12 +08:00
JaguarJack
a6cebc3750 update:更新上传获取配置 2020-09-07 07:44:56 +08:00
JaguarJack
214ca68b44 update:wechat 管理 2020-09-06 16:42:29 +08:00
JaguarJack
e712f824f5 update:支持无限级的菜单隐藏 2020-09-06 11:18:12 +08:00
JaguarJack
f301f149fb update:更新获取方法 2020-09-06 10:58:13 +08:00
JaguarJack
96751d6974 update:导出数据 2020-09-05 17:18:31 +08:00
JaguarJack
da9aa45036 update:更新初始化数据 2020-09-05 17:13:50 +08:00
yanwenwu
9ec1285cb9 update:修复导出 2020-09-05 17:12:04 +08:00
JaguarJack
3947ba7386 update数据 2020-09-05 16:34:43 +08:00
JaguarJack
d0a9a41c68 更新到处数据 2020-09-05 16:33:34 +08:00
JaguarJack
7fbee46c73 update 初始化数据 2020-09-05 16:24:00 +08:00
JaguarJack
c8a7d0291c update 2020-09-05 16:01:18 +08:00
JaguarJack
d0044ee019 update 2020-09-04 20:29:38 +08:00
JaguarJack
3466c8ec1f code 更新 2020-09-04 19:28:47 +08:00
JaguarJack
b3be31750a upate 2020-09-04 19:28:30 +08:00
JaguarJack
ca7a3df823 update 2020-09-04 19:01:57 +08:00
JaguarJack
9a5e7010b1 update 2020-09-04 16:21:18 +08:00
JaguarJack
2e67214032 迁移数据 2020-09-04 10:45:18 +08:00
JaguarJack
c5fb6f9409 迁移 2020-09-04 10:09:26 +08:00
JaguarJack
8f73948223 开发者搜索 2020-09-03 19:07:19 +08:00
JaguarJack
2941eeac1e update 2020-09-03 18:55:25 +08:00
JaguarJack
e0007d4150 update:更新搜索 2020-09-02 20:46:30 +08:00
JaguarJack
0e3656c7cc update:更新表结构和模型字段 2020-09-02 11:20:10 +08:00
JaguarJack
44ed0b9788 update:调整部门管理 2020-09-01 07:58:36 +08:00
JaguarJack
1d660ba648 update:更新表结构 2020-08-30 11:31:25 +08:00
JaguarJack
202f7f1dea update:更新表结构 2020-08-30 11:23:10 +08:00
61 changed files with 2074 additions and 1190 deletions

View File

@@ -4,7 +4,10 @@
<p align="center"><code>CatchAdmin</code>是一款基于<a href="http://www.thinkphp.cn/" target="_blank">thinkphp framework</a> <p align="center"><code>CatchAdmin</code>是一款基于<a href="http://www.thinkphp.cn/" target="_blank">thinkphp framework</a>
<a href="https://pro.loacg.com/docs/getting-started">ant degisn pro vue</a>二次开发而成后台管理系统,采用了目前趋势的前后端分离开发模式,后端仅需要提供简洁的 API 数据结构,前端负责呈现数据。目前前端采用数据驱动,大大提高了开发效率。这不仅仅是一个项目,更是后端更新技术栈的一次实践</p> <a href="https://github.com/PanJiaChen/vue-element-admin/">element admin</a>二次开发而成后台管理系统。因为 thinkphp 的简单高效,文档齐全。在看了很多 thinkphp 生态中的后台管理系统,发现没有一款合适的前后端分离系统。遂开发了 CatchAdmin。
完全利用了 thinkphp6 的新版本特性 ServiceProvider将管理系统模块之间的耦合降到了最低限度。每个模块之间都有独立的 controller路由模型数据表`。在开发上尽可能将模块之间的影响降到最低,降低了开发上的难度。基于 CatchAdmin 可以开发 cmsCRMOA 等
等系统。也封装了很多实用的工具,提升开发体验。
</p>
<p align="center"> <p align="center">
<a href="http://doc.catchadmin.com/">文档</a> | <a href="http://doc.catchadmin.com/">文档</a> |
@@ -28,18 +31,56 @@
<img src="https://svg.hamm.cn/badge.svg?key=License&value=Apache-2.0"/> <img src="https://svg.hamm.cn/badge.svg?key=License&value=Apache-2.0"/>
</p > </p >
## 功能
- [x] `用户管理` 后台用户管理
- [x] `部门管理` 配置公司的部门结构,支持树形结构
- [x] `岗位管理` 配置后台用户的职务
- [x] `菜单管理` 配置系统菜单,按钮等等
- [x] `角色管理` 配置用户担当的角色,分配权限
- [x] `数据字典` 管理后台表结构
- [x] `操作日志` 后台用户操作记录
- [x] `登录日志` 后台系统用户的登录记录
- [x] `代码生成` 生成 API 端的 CURD 操作
- [x] `敏感词` 支持敏感词配置
- [x] `附件管理` 可管理上传的文件
- [ ] `微信管理`
## 项目地址 ## 项目地址
- [github 地址](https://github.com/yanwenwu/catch-admin) - [github 地址](https://github.com/yanwenwu/catch-admin)
- [gitee 地址](https://gitee.com/jaguarjack/catchAdmin) - [gitee 地址](https://gitee.com/jaguarjack/catchAdmin)
- [前端 Vue 项目地址](https://github.com/yanwenwu/catch-admin-vue) - [前端 Vue 项目地址](https://github.com/yanwenwu/catch-admin-vue)
- [文档地址](https://github.com/catch-admin/document)[个人精力实在有限,希望可以小伙伴们可以一起维护文档] - [文档地址](https://github.com/catch-admin/document)[个人精力实在有限,希望可以小伙伴们可以一起维护文档]
## 预览 ## 预览
<p align="center"> <table>
<img src="https://cdn.learnku.com/uploads/images/202005/17/18206/0ECPy72zUZ.png!large"> <tr>
</p> <td><img src="https://s1.ax1x.com/2020/09/07/wucNXq.md.png"></td>
<p align="center"> <td><img src="https://s1.ax1x.com/2020/09/07/wucm6I.md.png"></td>
<img src="https://cdn.learnku.com/uploads/images/202005/17/18206/ngzSU0A9SI.png!large"> </tr>
</p> <tr>
<td><img src="https://s1.ax1x.com/2020/09/07/wucZpd.md.png"></td>
<td><img src="https://s1.ax1x.com/2020/09/07/wuce1A.md.png"></td>
</tr>
<tr>
<td><img src="https://s1.ax1x.com/2020/09/07/wucnXt.md.png"></td>
<td><img src="https://s1.ax1x.com/2020/09/07/wucKnP.md.png"></td>
</tr>
<tr>
<td><img src="https://s1.ax1x.com/2020/09/07/wuc3tg.md.png"></td>
<td><img src="https://s1.ax1x.com/2020/09/07/wucM0f.md.png"></td>
</tr>
<tr>
<td><img src="https://s1.ax1x.com/2020/09/07/wucQ78.md.png"></td>
<td><img src="https://s1.ax1x.com/2020/09/07/wuc1AS.md.png"></td>
</tr>
<tr>
<td><img src="https://s1.ax1x.com/2020/09/07/wuc8hQ.md.png"></td>
<td><img src="https://s1.ax1x.com/2020/09/07/wucY1s.md.png"></td>
</tr>
<tr>
<td><img src="https://s1.ax1x.com/2020/09/07/wucJpj.md.png"></td>
<td><img src="https://s1.ax1x.com/2020/09/07/wuctcn.md.png"></td>
</tr>
</table>
## 环境要求 ## 环境要求
- php7.1+ (需以下扩展) - php7.1+ (需以下扩展)
@@ -110,7 +151,7 @@ composer create-project jaguarjack/catchadmin:dev-master
> 排名部分先后 > 排名部分先后
- [top-think/think](https://github.com/top-think/think) - [top-think/think](https://github.com/top-think/think)
- [ant-design-pro-vue](https://github.com/sendya/ant-design-pro-vue) - [element-admin](https://panjiachen.gitee.io/vue-element-admin-site/zh/)
- [thans/tp-jwt-auth](https://packagist.org/packages/thans/tp-jwt-auth) - [thans/tp-jwt-auth](https://packagist.org/packages/thans/tp-jwt-auth)
- [workerman/workerman](https://github.com/walkor/Workerman) - [workerman/workerman](https://github.com/walkor/Workerman)
- [jaguarjack/think-filesystem-cloud](https://github.com/yanwenwu/think-filesystem-cloud) - [jaguarjack/think-filesystem-cloud](https://github.com/yanwenwu/think-filesystem-cloud)

View File

@@ -33,7 +33,7 @@ class Request extends \think\Request
$user = $this->auth->guard($guard ? : config('catch.auth.default.guard'))->user(); $user = $this->auth->guard($guard ? : config('catch.auth.default.guard'))->user();
if ($user->status == Users::DISABLE) { if ($user->status == Users::DISABLE) {
throw new LoginFailedException('该用户已被禁用'); throw new LoginFailedException('该用户已被禁用', Code::USER_FORBIDDEN);
} }
} catch (\Exception $e) { } catch (\Exception $e) {
if ($e instanceof TokenExpiredException) { if ($e instanceof TokenExpiredException) {
@@ -45,7 +45,7 @@ class Request extends \think\Request
if ($e instanceof TokenInvalidException) { if ($e instanceof TokenInvalidException) {
throw new FailedException('token 不合法', Code::LOST_LOGIN); throw new FailedException('token 不合法', Code::LOST_LOGIN);
} }
throw new FailedException('认证失败: '. $e->getMessage(), Code::LOST_LOGIN); throw new FailedException('认证失败: '. $e->getMessage(), $e->getCode());
} }
return $user; return $user;

BIN
catch/.DS_Store vendored Normal file

Binary file not shown.

13
catch/cms/CmsService.php Normal file
View File

@@ -0,0 +1,13 @@
<?php
namespace catchAdmin\cms;
use catcher\ModuleService;
class CmsService extends ModuleService
{
public function loadRouteFrom()
{
// TODO: Implement loadRouteFrom() method.
return __DIR__ . DIRECTORY_SEPARATOR . 'route.php';
}
}

30
catch/cms/model/Hello.php Normal file
View File

@@ -0,0 +1,30 @@
<?php
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
// +----------------------------------------------------------------------
// | Author: JaguarJack [ njphper@gmail.com ]
// +----------------------------------------------------------------------
namespace catchAdmin\cms\model;
use catcher\base\CatchModel as Model;
class Hello extends Model
{
protected $name = 'hello';
protected $field = [
'id', //
'good', //
'creator_id', // 创建人ID
'created_at', // 创建时间
'updated_at', // 更新时间
'deleted_at', // 软删除
];
}

15
catch/cms/module.json Normal file
View File

@@ -0,0 +1,15 @@
{
"name": "内容管理",
"alias": "cms",
"description": "cms,博客,企业站点,内容管理",
"version": "1.0.0",
"keywords": [],
"order": 0,
"services": [
"\\catchAdmin\\cms\\CmsService"
],
"aliases": {},
"files": [],
"requires": [],
"enable": true
}

14
catch/cms/route.php Normal file
View File

@@ -0,0 +1,14 @@
<?php
// you should user `$router`
$router->group(function () use ($router){
});
//hello路由
$router->resource('hello', '\catchAdmin\cms\controller\Hello')->middleware('auth');
//hello路由
$router->resource('hello', '\catchAdmin\cms\controller\Hello')->middleware('auth');

View File

@@ -11,15 +11,13 @@ class LoginLogEvent
{ {
$agent = request()->header('user-agent'); $agent = request()->header('user-agent');
$username = Users::where('email', $params['email'])->value('username');
app(LoginLog::class)->storeBy([ app(LoginLog::class)->storeBy([
'login_name' => $username ? : $params['email'], 'login_name' => $params['login_name'],
'login_ip' => request()->ip(), 'login_ip' => request()->ip(),
'browser' => $this->getBrowser($agent), 'browser' => $this->getBrowser($agent),
'os' => $this->getOs($agent), 'os' => $this->getOs($agent),
'login_at' => time(), 'login_at' => time(),
'status' => $params['success'] ? 1 : 2, 'status' => $params['success'],
]); ]);
} }

View File

@@ -6,6 +6,7 @@ use catchAdmin\permissions\model\Users;
use catcher\base\CatchController; use catcher\base\CatchController;
use catcher\CatchAuth; use catcher\CatchAuth;
use catcher\CatchResponse; use catcher\CatchResponse;
use catcher\Code;
use catcher\exceptions\LoginFailedException; use catcher\exceptions\LoginFailedException;
use thans\jwt\facade\JWTAuth; use thans\jwt\facade\JWTAuth;
@@ -21,29 +22,15 @@ class Index extends CatchController
*/ */
public function login(LoginRequest $request, CatchAuth $auth) public function login(LoginRequest $request, CatchAuth $auth)
{ {
try {
$params = $request->param(); $params = $request->param();
$token = $auth->attempt($params); $token = $auth->attempt($params);
return CatchResponse::success([
$user = $auth->user();
if ($user->status == Users::DISABLE) {
throw new LoginFailedException('该用户已被禁用');
}
// 记录用户登录
$user->last_login_ip = request()->ip();
$user->last_login_time = time();
$user->save();
// 登录事件
$params['success'] = $token;
event('loginLog', $params);
return $token ? CatchResponse::success([
'token' => $token, 'token' => $token,
], '登录成功') : CatchResponse::success('', '登录失败'); ], '登录成功');
} catch (\Exception $exception) {
return CatchResponse::fail('登录失败', $exception->getCode());
}
} }
/** /**

View File

@@ -5,6 +5,7 @@ use catcher\base\CatchController;
use catchAdmin\permissions\model\Department as DepartmentModel; use catchAdmin\permissions\model\Department as DepartmentModel;
use catcher\base\CatchRequest; use catcher\base\CatchRequest;
use catcher\CatchResponse; use catcher\CatchResponse;
use catcher\exceptions\FailedException;
use catcher\Tree; use catcher\Tree;
class Department extends CatchController class Department extends CatchController
@@ -63,6 +64,10 @@ class Department extends CatchController
*/ */
public function delete($id): \think\response\Json public function delete($id): \think\response\Json
{ {
if ($this->department->where('parent_id', $id)->find()) {
throw new FailedException('存在子部门,无法删除');
}
return CatchResponse::success($this->department->deleteBy($id)); return CatchResponse::success($this->department->deleteBy($id));
} }
} }

View File

@@ -9,6 +9,7 @@ use catcher\exceptions\FailedException;
use catcher\library\ParseClass; use catcher\library\ParseClass;
use catcher\Tree; use catcher\Tree;
use catchAdmin\permissions\model\Permissions; use catchAdmin\permissions\model\Permissions;
use think\helper\Str;
use think\response\Json; use think\response\Json;
class Permission extends CatchController class Permission extends CatchController
@@ -66,9 +67,22 @@ class Permission extends CatchController
// 如果是子分类 自动写入父类模块 // 如果是子分类 自动写入父类模块
$parentId = $params['parent_id'] ?? 0; $parentId = $params['parent_id'] ?? 0;
if ($parentId) { // 按钮类型寻找上级
$parent = $this->permissions->findBy($parentId); if ($params['type'] == Permissions::BTN_TYPE && $parentId) {
$params['module'] = $parent->module; $permissionMark = $params['permission_mark'];
// 查找父级
$parentPermission = $this->permissions->findBy($parentId);
// 如果父级是顶级 parent_id = 0
if ($parentPermission->parent_id) {
if (Str::contains($parentPermission->permission_mark, '@')) {
list($controller, $action) = explode('@', $parentPermission->permission_mark);
$permissionMark = $controller . '@' . $permissionMark;
} else {
$permissionMark = $parentPermission->permission_mark .'@'. $permissionMark;
}
}
$params['permission_mark'] = $permissionMark;
$params['module'] = $parentPermission->module;
} }
return CatchResponse::success($this->permissions->storeBy($params)); return CatchResponse::success($this->permissions->storeBy($params));
@@ -85,6 +99,33 @@ class Permission extends CatchController
{ {
$permission = $this->permissions->findBy($id); $permission = $this->permissions->findBy($id);
$params = $request->param();
// 按钮类型
if ($params['type'] == Permissions::BTN_TYPE && $permission->parent_id) {
$parentPermission = $this->permissions->findBy($permission->parent_id);
$permissionMark = $params['permission_mark'];
if ($parentPermission->parent_id) {
if (Str::contains($parentPermission->permission_mark, '@')) {
list($controller, $action) = explode('@', $parentPermission->permission_mark);
$permissionMark = $controller . '@' . $permissionMark;
} else {
$permissionMark = $parentPermission->permission_mark .'@'. $permissionMark;
}
}
$params['permission_mark'] = $permissionMark;
$this->permissions->where('id',$id)->update(array_merge($params, [
'parent_id' => $permission->parent_id,
'level' => $permission->level,
'updated_at' => time()
]));
return CatchResponse::success();
}
$params = array_merge($request->param(), [ $params = array_merge($request->param(), [
'parent_id' => $permission->parent_id, 'parent_id' => $permission->parent_id,
'level' => $permission->level 'level' => $permission->level
@@ -134,17 +175,9 @@ class Permission extends CatchController
*/ */
public function show($id) public function show($id)
{ {
$permission = $this->permissions->findBy($id); $this->permissions->show($id);
$permission->status = $permission->status == Permissions::ENABLE ? Permissions::DISABLE : Permissions::ENABLE; return CatchResponse::success();
if ($permission->save()) {
$this->permissions->where('parent_id', $id)->update([
'status' => $permission->status,
]);
}
return CatchResponse::success($permission->save());
} }
/** /**
@@ -160,14 +193,15 @@ class Permission extends CatchController
public function getMethods($id, ParseClass $parseClass) public function getMethods($id, ParseClass $parseClass)
{ {
$permission = Permissions::where('id', $id)->find(); $permission = Permissions::where('id', $id)->find();
$module = $permission->module; $module = $permission->module;
$controller = explode('@', $permission->permission_mark)[0]; $controller = explode('@', $permission->permission_mark)[0];
try {
$methods = $parseClass->setModule('catch')->setRule($module, $controller)->onlySelfMethods(); $methods = $parseClass->setModule('catch')->setRule($module, $controller)->onlySelfMethods();
return CatchResponse::success($methods); return CatchResponse::success($methods);
}catch (\Exception $e) {
return CatchResponse::success([]);
}
} }
} }

View File

@@ -2,6 +2,7 @@
namespace catchAdmin\permissions\controller; namespace catchAdmin\permissions\controller;
use catchAdmin\permissions\model\Permissions; use catchAdmin\permissions\model\Permissions;
use catchAdmin\permissions\model\Roles;
use catcher\base\CatchRequest as Request; use catcher\base\CatchRequest as Request;
use catcher\base\CatchController; use catcher\base\CatchController;
use catcher\CatchResponse; use catcher\CatchResponse;
@@ -38,14 +39,19 @@ class Role extends CatchController
*/ */
public function save(Request $request) public function save(Request $request)
{ {
$this->role->storeBy($request->param()); $params = $request->param();
$permissions = $request->param('permissions'); if (Roles::where('identify', $params['identify'])->find()) {
throw new FailedException('角色标识 [' . $params['identify'] . ']已存在');
}
$this->role->storeBy($params);
$permissions = $params['permissions'];
if (!empty($permissions)) { if (!empty($permissions)) {
$this->role->attachPermissions(array_unique($permissions)); $this->role->attachPermissions(array_unique($permissions));
} }
if (!empty($request->param('departments'))) { if (!empty($params['permissions'])) {
$this->role->attachDepartments($request->param('departments')); $this->role->attachDepartments($params['permissions']);
} }
// 添加角色 // 添加角色
return CatchResponse::success(); return CatchResponse::success();
@@ -69,6 +75,10 @@ class Role extends CatchController
*/ */
public function update($id, Request $request): Json public function update($id, Request $request): Json
{ {
if (Roles::where('identify', $request->param('identify'))->where('id', '<>', $id)->find()) {
throw new FailedException('角色标识 [' . $request->param('identify') . ']已存在');
}
$this->role->updateBy($id, $request->param()); $this->role->updateBy($id, $request->param());
$role = $this->role->findBy($id); $role = $this->role->findBy($id);

View File

@@ -1,6 +1,7 @@
<?php <?php
namespace catchAdmin\permissions\controller; namespace catchAdmin\permissions\controller;
use catchAdmin\permissions\excel\UserExport;
use catcher\base\CatchRequest as Request; use catcher\base\CatchRequest as Request;
use catchAdmin\permissions\model\Permissions; use catchAdmin\permissions\model\Permissions;
use catchAdmin\permissions\model\Roles; use catchAdmin\permissions\model\Roles;
@@ -11,6 +12,7 @@ use catcher\base\CatchController;
use catcher\CatchAuth; use catcher\CatchAuth;
use catcher\CatchCacheKeys; use catcher\CatchCacheKeys;
use catcher\CatchResponse; use catcher\CatchResponse;
use catcher\library\excel\Excel;
use catcher\Tree; use catcher\Tree;
use catcher\Utils; use catcher\Utils;
use think\facade\Cache; use think\facade\Cache;
@@ -49,7 +51,7 @@ class User extends CatchController
{ {
$user = $auth->user(); $user = $auth->user();
$roles = $user->getRoles(); $roles = $user->getRoles()->column('identify');
$permissionIds = $user->getPermissionsBy($user->id); $permissionIds = $user->getPermissionsBy($user->id);
// 缓存用户权限 // 缓存用户权限
@@ -86,7 +88,9 @@ class User extends CatchController
$this->user->attachRoles($request->param('roles')); $this->user->attachRoles($request->param('roles'));
if ($request->param('jobs')) {
$this->user->attachJobs($request->param('jobs')); $this->user->attachJobs($request->param('jobs'));
}
return CatchResponse::success('', '添加成功'); return CatchResponse::success('', '添加成功');
} }
@@ -225,4 +229,18 @@ class User extends CatchController
'hasRoles' => $roleIds, 'hasRoles' => $roleIds,
]); ]);
} }
/**
* 导出
*
* @time 2020年09月08日
* @param Excel $excel
* @param UserExport $userExport
* @throws \PhpOffice\PhpSpreadsheet\Exception
* @return \think\response\Json
*/
public function export(Excel $excel, UserExport $userExport)
{
return CatchResponse::success($excel->save($userExport, Utils::publicPath('export/users')));
}
} }

View File

@@ -0,0 +1,42 @@
<?php
use think\migration\Migrator;
use think\migration\db\Column;
class UpdateRoles extends Migrator
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
*
* The following commands can be used in this method and Phinx will
* automatically reverse them when rolling back:
*
* createTable
* renameTable
* addColumn
* renameColumn
* addIndex
* addForeignKey
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change()
{
if ($this->hasTable('roles')) {
$table = $this->table('roles');
$table->addColumn('identify', 'string', [
'limit' => 20,
'default' => 1,
'comment' => '角色的标识,用英文表示,用于后台路由权限',
'after' => 'role_name'])
->update();
}
}
}

View File

@@ -0,0 +1,40 @@
<?php
use think\migration\Migrator;
use think\migration\db\Column;
class UpdatePermissions extends Migrator
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
*
* The following commands can be used in this method and Phinx will
* automatically reverse them when rolling back:
*
* createTable
* renameTable
* addColumn
* renameColumn
* addIndex
* addForeignKey
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change()
{
if ($this->hasTable('permissions')) {
$table = $this->table('permissions');
$table->removeColumn('method')
->removeColumn('hide_children_in_menu')
->renameColumn('status', 'hidden')
->update();
}
}
}

View File

@@ -2,7 +2,7 @@
use think\migration\Seeder; use think\migration\Seeder;
class PermissionSeed extends Seeder class PermissionsMenusSeed extends Seeder
{ {
/** /**
* Run Method. * Run Method.
@@ -27,20 +27,18 @@ class PermissionSeed extends Seeder
'parent_id' => 0, 'parent_id' => 0,
'level' => '', 'level' => '',
'route' => '/permissions', 'route' => '/permissions',
'icon' => 'appstore', 'icon' => 'el-icon-cpu',
'module' => 'permissions', 'module' => 'permissions',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get', 'permission_mark' => 'permission',
'permission_mark' => 'permission@index', 'component' => 'layout',
'component' => 'pageView', 'redirect' => '/permissions/users',
'redirect' => '', 'hidden' => 1,
'hide_children_in_menu' => 2,
'keepalive' => 1, 'keepalive' => 1,
'type' => 1, 'type' => 1,
'status' => 1,
'sort' => 100, 'sort' => 100,
'created_at' => 1587461455, 'created_at' => 1587461455,
'updated_at' => 1593044101, 'updated_at' => 1599362429,
'deleted_at' => 0, 'deleted_at' => 0,
'children' => 'children' =>
array ( array (
@@ -51,20 +49,18 @@ class PermissionSeed extends Seeder
'parent_id' => 1, 'parent_id' => 1,
'level' => '1', 'level' => '1',
'route' => '/permissions/users', 'route' => '/permissions/users',
'icon' => 'user', 'icon' => 'el-icon-user',
'module' => 'permissions', 'module' => 'permissions',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get', 'permission_mark' => 'user',
'permission_mark' => 'user@index',
'component' => 'users', 'component' => 'users',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 2, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 1, 'type' => 1,
'status' => 1,
'sort' => 10, 'sort' => 10,
'created_at' => 1587461597, 'created_at' => 1587461597,
'updated_at' => 1592371975, 'updated_at' => 1599362429,
'deleted_at' => 0, 'deleted_at' => 0,
'children' => 'children' =>
array ( array (
@@ -78,17 +74,15 @@ class PermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'permissions', 'module' => 'permissions',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'user@index', 'permission_mark' => 'user@index',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1587461647, 'created_at' => 1587461647,
'updated_at' => 1591316160, 'updated_at' => 1599030266,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
1 => 1 =>
@@ -101,17 +95,15 @@ class PermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'permissions', 'module' => 'permissions',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'user@create', 'permission_mark' => 'user@create',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1587461696, 'created_at' => 1587461696,
'updated_at' => 1587547118, 'updated_at' => 1599030266,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
2 => 2 =>
@@ -124,17 +116,15 @@ class PermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'permissions', 'module' => 'permissions',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'user@save', 'permission_mark' => 'user@save',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1587461721, 'created_at' => 1587461721,
'updated_at' => 1591345475, 'updated_at' => 1599030266,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
3 => 3 =>
@@ -147,17 +137,15 @@ class PermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'permissions', 'module' => 'permissions',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'user@edit', 'permission_mark' => 'user@edit',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1587461742, 'created_at' => 1587461742,
'updated_at' => 1591345504, 'updated_at' => 1599030266,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
4 => 4 =>
@@ -170,17 +158,15 @@ class PermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'permissions', 'module' => 'permissions',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'user@update', 'permission_mark' => 'user@update',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1587461762, 'created_at' => 1587461762,
'updated_at' => 1587547118, 'updated_at' => 1599030266,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
5 => 5 =>
@@ -193,17 +179,15 @@ class PermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'permissions', 'module' => 'permissions',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'user@delete', 'permission_mark' => 'user@delete',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1587461841, 'created_at' => 1587461841,
'updated_at' => 1587547118, 'updated_at' => 1599030266,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
6 => 6 =>
@@ -216,17 +200,15 @@ class PermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'permissions', 'module' => 'permissions',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'user@switchStatus', 'permission_mark' => 'user@switchStatus',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1587461876, 'created_at' => 1587461876,
'updated_at' => 1587547118, 'updated_at' => 1599030266,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
7 => 7 =>
@@ -239,17 +221,15 @@ class PermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'permissions', 'module' => 'permissions',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'user@recover', 'permission_mark' => 'user@recover',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1587461901, 'created_at' => 1587461901,
'updated_at' => 1587547118, 'updated_at' => 1599030266,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
), ),
@@ -261,20 +241,18 @@ class PermissionSeed extends Seeder
'parent_id' => 1, 'parent_id' => 1,
'level' => '1', 'level' => '1',
'route' => '/permissions/roles', 'route' => '/permissions/roles',
'icon' => 'usergroup-add', 'icon' => 'el-icon-s-custom',
'module' => 'permissions', 'module' => 'permissions',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get', 'permission_mark' => 'role',
'permission_mark' => 'role@index',
'component' => 'roles', 'component' => 'roles',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 2, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 1, 'type' => 1,
'status' => 1,
'sort' => 9, 'sort' => 9,
'created_at' => 1587461939, 'created_at' => 1587461939,
'updated_at' => 1592371974, 'updated_at' => 1599362438,
'deleted_at' => 0, 'deleted_at' => 0,
'children' => 'children' =>
array ( array (
@@ -288,17 +266,15 @@ class PermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'permissions', 'module' => 'permissions',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'role@index', 'permission_mark' => 'role@index',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1587461984, 'created_at' => 1587461984,
'updated_at' => 1591341461, 'updated_at' => 1599362438,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
1 => 1 =>
@@ -311,17 +287,15 @@ class PermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'permissions', 'module' => 'permissions',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'role@create', 'permission_mark' => 'role@create',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1587462007, 'created_at' => 1587462007,
'updated_at' => 1587547118, 'updated_at' => 1599362438,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
2 => 2 =>
@@ -334,17 +308,15 @@ class PermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'permissions', 'module' => 'permissions',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'role@save', 'permission_mark' => 'role@save',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1587462021, 'created_at' => 1587462021,
'updated_at' => 1587547118, 'updated_at' => 1599362438,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
3 => 3 =>
@@ -357,17 +329,15 @@ class PermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'permissions', 'module' => 'permissions',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'role@edit', 'permission_mark' => 'role@edit',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1587462040, 'created_at' => 1587462040,
'updated_at' => 1587547118, 'updated_at' => 1599362438,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
4 => 4 =>
@@ -380,17 +350,15 @@ class PermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'permissions', 'module' => 'permissions',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'role@update', 'permission_mark' => 'role@update',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1587462058, 'created_at' => 1587462058,
'updated_at' => 1587547118, 'updated_at' => 1599362438,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
5 => 5 =>
@@ -403,17 +371,15 @@ class PermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'permissions', 'module' => 'permissions',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'role@delete', 'permission_mark' => 'role@delete',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1587462070, 'created_at' => 1587462070,
'updated_at' => 1587547118, 'updated_at' => 1599362438,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
6 => 6 =>
@@ -426,17 +392,15 @@ class PermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'permissions', 'module' => 'permissions',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'role@getPermissions', 'permission_mark' => 'role@getPermissions',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1587462094, 'created_at' => 1587462094,
'updated_at' => 1587547118, 'updated_at' => 1599362438,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
), ),
@@ -448,20 +412,18 @@ class PermissionSeed extends Seeder
'parent_id' => 1, 'parent_id' => 1,
'level' => '1', 'level' => '1',
'route' => '/permissions/rules', 'route' => '/permissions/rules',
'icon' => 'build', 'icon' => 'el-icon-collection-tag',
'module' => 'permissions', 'module' => 'permissions',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get', 'permission_mark' => 'permission',
'permission_mark' => 'permission@index',
'component' => 'rules', 'component' => 'rules',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 2, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 1, 'type' => 1,
'status' => 1,
'sort' => 8, 'sort' => 8,
'created_at' => 1587462147, 'created_at' => 1587462147,
'updated_at' => 1592371979, 'updated_at' => 1599362475,
'deleted_at' => 0, 'deleted_at' => 0,
'children' => 'children' =>
array ( array (
@@ -475,17 +437,15 @@ class PermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'permissions', 'module' => 'permissions',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'permission@index', 'permission_mark' => 'permission@index',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1587462205, 'created_at' => 1587462205,
'updated_at' => 1587547118, 'updated_at' => 1599362475,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
1 => 1 =>
@@ -498,17 +458,15 @@ class PermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'permissions', 'module' => 'permissions',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'permission@create', 'permission_mark' => 'permission@create',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1587462232, 'created_at' => 1587462232,
'updated_at' => 1587547118, 'updated_at' => 1599362475,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
2 => 2 =>
@@ -521,40 +479,36 @@ class PermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'permissions', 'module' => 'permissions',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'permission@save', 'permission_mark' => 'permission@save',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1587462250, 'created_at' => 1587462250,
'updated_at' => 1587547118, 'updated_at' => 1599362475,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
3 => 3 =>
array ( array (
'id' => 23, 'id' => 23,
'permission_name' => '查看', 'permission_name' => '禁用/启用',
'parent_id' => 19, 'parent_id' => 19,
'level' => '1-19', 'level' => '1-19',
'route' => '', 'route' => '',
'icon' => '', 'icon' => '',
'module' => 'permissions', 'module' => 'permissions',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get', 'permission_mark' => 'permission@show',
'permission_mark' => 'permission@edit',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1587462273, 'created_at' => 1587462273,
'updated_at' => 1587547118, 'updated_at' => 1599362475,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
4 => 4 =>
@@ -567,17 +521,15 @@ class PermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'permissions', 'module' => 'permissions',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'permission@update', 'permission_mark' => 'permission@update',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1587462284, 'created_at' => 1587462284,
'updated_at' => 1587547118, 'updated_at' => 1599362475,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
5 => 5 =>
@@ -590,17 +542,36 @@ class PermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'permissions', 'module' => 'permissions',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'permission@delete', 'permission_mark' => 'permission@delete',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1587462296, 'created_at' => 1587462296,
'updated_at' => 1587547118, 'updated_at' => 1599362475,
'deleted_at' => 0,
),
6 =>
array (
'id' => 106,
'permission_name' => '权限方法',
'parent_id' => 19,
'level' => '1-19',
'route' => '',
'icon' => '',
'module' => 'permissions',
'creator_id' => 1,
'permission_mark' => 'permission@getMethods',
'component' => '',
'redirect' => '',
'hidden' => 1,
'keepalive' => 1,
'type' => 2,
'sort' => 1,
'created_at' => 1599221913,
'updated_at' => 1599362475,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
), ),
@@ -612,20 +583,18 @@ class PermissionSeed extends Seeder
'parent_id' => 1, 'parent_id' => 1,
'level' => '1', 'level' => '1',
'route' => '/permissions/departments', 'route' => '/permissions/departments',
'icon' => 'desktop', 'icon' => 'el-icon-monitor',
'module' => 'permissions', 'module' => 'permissions',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'departments', 'permission_mark' => 'departments',
'component' => 'departments', 'component' => 'departments',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 2, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 1, 'type' => 1,
'status' => 1,
'sort' => 7, 'sort' => 7,
'created_at' => 1587462488, 'created_at' => 1587462488,
'updated_at' => 1587547118, 'updated_at' => 1599362429,
'deleted_at' => 0, 'deleted_at' => 0,
'children' => 'children' =>
array ( array (
@@ -639,17 +608,15 @@ class PermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'permissions', 'module' => 'permissions',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'department@index', 'permission_mark' => 'department@index',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1587462529, 'created_at' => 1587462529,
'updated_at' => 1587547118, 'updated_at' => 1599030565,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
1 => 1 =>
@@ -662,17 +629,15 @@ class PermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'permissions', 'module' => 'permissions',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'department@save', 'permission_mark' => 'department@save',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1587462548, 'created_at' => 1587462548,
'updated_at' => 1587547118, 'updated_at' => 1599030565,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
2 => 2 =>
@@ -685,17 +650,15 @@ class PermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'permissions', 'module' => 'permissions',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'department@update', 'permission_mark' => 'department@update',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1587462579, 'created_at' => 1587462579,
'updated_at' => 1587547118, 'updated_at' => 1599030565,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
3 => 3 =>
@@ -708,17 +671,15 @@ class PermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'permissions', 'module' => 'permissions',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'department@delete', 'permission_mark' => 'department@delete',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1587462592, 'created_at' => 1587462592,
'updated_at' => 1587547118, 'updated_at' => 1599030565,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
), ),
@@ -730,20 +691,18 @@ class PermissionSeed extends Seeder
'parent_id' => 1, 'parent_id' => 1,
'level' => '1', 'level' => '1',
'route' => '/permissions/jobs', 'route' => '/permissions/jobs',
'icon' => 'skin', 'icon' => 'el-icon-setting',
'module' => 'permissions', 'module' => 'permissions',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'job', 'permission_mark' => 'job',
'component' => 'jobs', 'component' => 'jobs',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 2, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 1, 'type' => 1,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1587462707, 'created_at' => 1587462707,
'updated_at' => 1587547118, 'updated_at' => 1599362429,
'deleted_at' => 0, 'deleted_at' => 0,
'children' => 'children' =>
array ( array (
@@ -757,17 +716,15 @@ class PermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'permissions', 'module' => 'permissions',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get', 'permission_mark' => 'job@indexs',
'permission_mark' => 'job@index',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 2,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1587462757, 'created_at' => 1587462757,
'updated_at' => 1587547118, 'updated_at' => 1598959522,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
1 => 1 =>
@@ -780,17 +737,15 @@ class PermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'permissions', 'module' => 'permissions',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'job@save', 'permission_mark' => 'job@save',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 2,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1587462774, 'created_at' => 1587462774,
'updated_at' => 1587547118, 'updated_at' => 1598959522,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
2 => 2 =>
@@ -803,17 +758,15 @@ class PermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'permissions', 'module' => 'permissions',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'job@update', 'permission_mark' => 'job@update',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 2,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1587462785, 'created_at' => 1587462785,
'updated_at' => 1587547118, 'updated_at' => 1598959522,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
3 => 3 =>
@@ -826,17 +779,15 @@ class PermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'permissions', 'module' => 'permissions',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'job@delete', 'permission_mark' => 'job@delete',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 2,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1587462794, 'created_at' => 1587462794,
'updated_at' => 1587547118, 'updated_at' => 1598959522,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
4 => 4 =>
@@ -849,17 +800,15 @@ class PermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'permissions', 'module' => 'permissions',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'job@getAll', 'permission_mark' => 'job@getAll',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 2,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1587462818, 'created_at' => 1587462818,
'updated_at' => 1587547118, 'updated_at' => 1598959522,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
), ),

View File

@@ -24,7 +24,9 @@ class RolesSeed extends Seeder
{ {
\catchAdmin\permissions\model\Roles::create([ \catchAdmin\permissions\model\Roles::create([
'role_name' => '超级管理员', 'role_name' => '超级管理员',
'identify' => 'admin',
'description' => 'super user', 'description' => 'super user',
'data_range' => 1,
'creator_id' => 1, 'creator_id' => 1,
]); ]);

View File

@@ -0,0 +1,78 @@
<?php
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
// +----------------------------------------------------------------------
// | Author: JaguarJack [ njphper@gmail.com ]
// +----------------------------------------------------------------------
namespace catchAdmin\permissions\excel;
use catchAdmin\permissions\model\Users;
use catcher\library\excel\ExcelContract;
use PhpOffice\PhpSpreadsheet\Style\Alignment;
class UserExport implements ExcelContract
{
/**
* 设置头部
*
* @time 2020年09月08日
* @return string[]
*/
public function headers(): array
{
// TODO: Implement headers() method.
return [
'id', '用户名', '邮箱', '状态', '创建日期'
];
}
/**
* 处理数据
*
* @time 2020年09月08日
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @return \think\Collection
*/
public function sheets()
{
// TODO: Implement sheets() method.
$users = Users::field(['id', 'username', 'email', 'status', 'created_at'])->select();
foreach ($users as &$user) {
$user->status = $user->status == Users::ENABLE ? '启用' : '停用';
}
return $users;
}
/**
* 设置开始行
*
* @time 2020年09月08日
* @return int
*/
public function setRow()
{
return 2;
}
/**
* 设置标题
*
* @time 2020年09月08日
* @return array
*/
public function setTitle()
{
return [
'A1:G1', '导出用户', Alignment::HORIZONTAL_CENTER
];
}
}

View File

@@ -57,6 +57,11 @@ trait DataRangScopeTrait
$userIds[] = $user->id; $userIds[] = $user->id;
break; break;
case Roles::DEPARTMENT_DOWN_DATA: case Roles::DEPARTMENT_DOWN_DATA:
// 查一下下级部门
$departmentIds = Department::where('parent_id', $user->department_id)->column('id');
$departmentIds[] = $user->department_id;
$userIds = array_merge([$user->id], $this->getUserIdsByDepartmentId($departmentIds));
break;
case Roles::DEPARTMENT_DATA: case Roles::DEPARTMENT_DATA:
$userIds = array_merge($userIds, $this->getUserIdsByDepartmentId([$user->department_id])); $userIds = array_merge($userIds, $this->getUserIdsByDepartmentId([$user->department_id]));
break; break;

View File

@@ -35,9 +35,7 @@ class Department extends CatchModel
*/ */
public function getList(): array public function getList(): array
{ {
return $this->withoutField(['department_name']) return $this->catchSearch()
->addFields(['department_name as title'])
->catchSearch()
->catchOrder() ->catchOrder()
->select()->toArray(); ->select()->toArray();
} }

View File

@@ -19,12 +19,10 @@ class Permissions extends CatchModel
'component', // 组件 'component', // 组件
'redirect', 'redirect',
'keepalive', 'keepalive',
'hide_children_in_menu',
'creator_id', 'creator_id',
'status', 'hidden',
'module', // 模块 'module', // 模块
'route', // 路由 'route', // 路由
'method', // 请求方法
'permission_mark', // 权限标识 'permission_mark', // 权限标识
'type', // 1 菜单 2 按钮 'type', // 1 菜单 2 按钮
'sort', // 排序字段 'sort', // 排序字段
@@ -71,7 +69,7 @@ class Permissions extends CatchModel
return parent::whereIn('id', $permissionIds) return parent::whereIn('id', $permissionIds)
->field(['permission_name as title', 'id', 'parent_id', ->field(['permission_name as title', 'id', 'parent_id',
'route', 'icon', 'component', 'redirect', 'module', 'route', 'icon', 'component', 'redirect', 'module',
'keepalive as keepAlive', 'hide_children_in_menu', 'type', 'permission_mark', 'status' 'keepalive as keepAlive', 'type', 'permission_mark', 'hidden'
]) ])
->catchOrder() ->catchOrder()
->select(); ->select();
@@ -101,4 +99,44 @@ class Permissions extends CatchModel
return true; return true;
} }
public function show($id)
{
$permission = $this->findBy($id);
// 不能使用改属性判断,模型有该属性,使用数组方式
// $permission->hidden
$hidden = $permission['hidden'] == Permissions::ENABLE ? Permissions::DISABLE : Permissions::ENABLE;
$nextLevelIds = $this->getNextLevel([$id]);
$nextLevelIds[] = $id;
return $this->whereIn('id', $nextLevelIds)->update([
'hidden' => $hidden,
'updated_at' => time(),
]);
}
/**
* 获取 level ids
*
* @time 2020年09月06日
* @param array $id
* @param array $ids
* @return array
*/
protected function getNextLevel(array $id, &$ids = [])
{
$_ids = $this->whereIn('parent_id', $id)
->where('type', self::MENU_TYPE)
->column('id');
if (count($_ids)) {
$ids = array_merge($_ids, $this->getNextLevel($_ids, $ids));
}
return $ids;
}
} }

View File

@@ -21,6 +21,7 @@ class Roles extends CatchModel
protected $field = [ protected $field = [
'id', // 'id', //
'role_name', // 角色名 'role_name', // 角色名
'identify', // 身份标识
'parent_id', // 父级ID 'parent_id', // 父级ID
'creator_id', // 创建者 'creator_id', // 创建者
'data_range', // 数据范围 'data_range', // 数据范围

View File

@@ -1,6 +1,8 @@
<?php <?php
namespace catchAdmin\permissions\model\search; namespace catchAdmin\permissions\model\search;
use catchAdmin\permissions\model\Department;
trait UserSearch trait UserSearch
{ {
public function searchUsernameAttr($query, $value, $data) public function searchUsernameAttr($query, $value, $data)
@@ -20,6 +22,8 @@ trait UserSearch
public function searchDepartmentIdAttr($query, $value, $data) public function searchDepartmentIdAttr($query, $value, $data)
{ {
return $query->where($this->aliasField('department_id'), $value); $departmentIds = Department::where('parent_id', $value)->column('id');
$departmentIds[] = $value;
return $query->whereIn($this->aliasField('department_id'), $departmentIds);
} }
} }

View File

@@ -23,4 +23,5 @@ $router->group(function () use ($router){
$router->put('users/recover/<id>', '\catchAdmin\permissions\controller\User@recover'); $router->put('users/recover/<id>', '\catchAdmin\permissions\controller\User@recover');
$router->get('users/get/roles', '\catchAdmin\permissions\controller\User@getRoles'); $router->get('users/get/roles', '\catchAdmin\permissions\controller\User@getRoles');
$router->get('user/info', '\catchAdmin\permissions\controller\User@info'); $router->get('user/info', '\catchAdmin\permissions\controller\User@info');
$router->get('user/export', '\catchAdmin\permissions\controller\User@export');
})->middleware('auth'); })->middleware('auth');

View File

@@ -5,7 +5,7 @@ use catcher\base\CatchController;
use catcher\CatchResponse; use catcher\CatchResponse;
use catchAdmin\system\model\Attachments as AttachmentsModel; use catchAdmin\system\model\Attachments as AttachmentsModel;
use catcher\Utils; use catcher\Utils;
use think\facade\Filesystem; use catcher\facade\FileSystem;
class Attachments extends CatchController class Attachments extends CatchController
{ {
@@ -39,9 +39,17 @@ class Attachments extends CatchController
if ($model->deleteBy($id)) { if ($model->deleteBy($id)) {
foreach ($attachments as $attachment) { foreach ($attachments as $attachment) {
if ($attachment->driver == 'local') {
$localPath = config('filesystem.disks.local.root') . DIRECTORY_SEPARATOR;
$path = $localPath . str_replace('\\','\/', $attachment->path);
if (!FileSystem::exists($path)) {
Filesystem::delete($path);
}
} else {
Filesystem::delete($attachment->path); Filesystem::delete($attachment->path);
} }
} }
}
return CatchResponse::success(); return CatchResponse::success();
} }

View File

@@ -42,7 +42,10 @@ class DataDictionary extends CatchController
$tables = $tables->where('engine', $engine)->values(); $tables = $tables->where('engine', $engine)->values();
} }
return CatchResponse::paginate(Paginator::make($tables->toArray(), $request->get('limit') ?? 10, $request->get('page') ?? 1, $tables->count(), false, [])); $page = $request->get('page', 1);
$limit = $request->get('limit', 10);
return CatchResponse::paginate(Paginator::make(array_slice($tables->toArray(), ($page - 1) * $limit, $limit), $limit, $page, $tables->count(), false, []));
} }
/** /**

View File

@@ -35,7 +35,7 @@ class Developers extends Migrator
->addColumn('mobile', 'string', ['limit' => 30,'null' => false,'default' => '','signed' => false,'comment' => '手机号',]) ->addColumn('mobile', 'string', ['limit' => 30,'null' => false,'default' => '','signed' => false,'comment' => '手机号',])
->addColumn('id_card', 'string', ['limit' => 50,'null' => false,'default' => '','signed' => false,'comment' => '身份证',]) ->addColumn('id_card', 'string', ['limit' => 50,'null' => false,'default' => '','signed' => false,'comment' => '身份证',])
->addColumn('alipay_account', 'string', ['limit' => 100,'null' => false,'default' => '','signed' => false,'comment' => '支付宝账户',]) ->addColumn('alipay_account', 'string', ['limit' => 100,'null' => false,'default' => '','signed' => false,'comment' => '支付宝账户',])
->addColumn('status', 'boolean', ['null' => false,'default' => 1,'signed' => false,'comment' => '1 待认证 1 已认证',]) ->addColumn('status', 'boolean', ['null' => false,'default' => 1,'signed' => false,'comment' => '1 待认证 2 已认证',])
->addColumn('created_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => true,'comment' => '创建时间',]) ->addColumn('created_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => true,'comment' => '创建时间',])
->addColumn('updated_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => true,'comment' => '更新时间',]) ->addColumn('updated_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => true,'comment' => '更新时间',])
->addColumn('deleted_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => true,'comment' => '软删除',]) ->addColumn('deleted_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => true,'comment' => '软删除',])

View File

@@ -18,8 +18,8 @@ class ConfigSeed extends Seeder
[ [
'name' => '基础配置', 'name' => '基础配置',
'pid' => 0, 'pid' => 0,
'component' => 'basis', 'component' => 'basic',
'key' => 'basis', 'key' => 'basic',
], ],
[ [
'name' => '上传配置', 'name' => '上传配置',

View File

@@ -0,0 +1,679 @@
<?php
use think\migration\Seeder;
class SystemMenusSeed extends Seeder
{
/**
* Run Method.
*
* Write your database seeder using this method.
*
* More information on writing seeders is available here:
* http://docs.phinx.org/en/latest/seeding.html
*/
public function run()
{
\catcher\Utils::importTreeData($this->getPermissions(), 'permissions', 'parent_id');
}
protected function getPermissions()
{
return array (
0 =>
array (
'id' => 37,
'permission_name' => '系统管理',
'parent_id' => 0,
'level' => '',
'route' => '/system',
'icon' => 'el-icon-s-tools',
'module' => 'system',
'creator_id' => 1,
'permission_mark' => 'system',
'component' => 'layout',
'redirect' => 'attactments',
'hidden' => 1,
'keepalive' => 2,
'type' => 1,
'sort' => 1,
'created_at' => 1587462349,
'updated_at' => 1599288737,
'deleted_at' => 0,
'children' =>
array (
0 =>
array (
'id' => 38,
'permission_name' => '数据字典',
'parent_id' => 37,
'level' => '37',
'route' => '/system/database',
'icon' => 'el-icon-copy-document',
'module' => 'system',
'creator_id' => 1,
'permission_mark' => 'dataDictionary',
'component' => 'database',
'redirect' => '',
'hidden' => 1,
'keepalive' => 1,
'type' => 1,
'sort' => 8,
'created_at' => 1587463087,
'updated_at' => 1599362678,
'deleted_at' => 0,
'children' =>
array (
0 =>
array (
'id' => 39,
'permission_name' => '查看',
'parent_id' => 38,
'level' => '37-38',
'route' => '',
'icon' => '',
'module' => 'system',
'creator_id' => 1,
'permission_mark' => 'dataDictionary@view',
'component' => '',
'redirect' => '',
'hidden' => 1,
'keepalive' => 1,
'type' => 2,
'sort' => 1,
'created_at' => 1587463113,
'updated_at' => 1599362691,
'deleted_at' => 0,
),
1 =>
array (
'id' => 40,
'permission_name' => '列表',
'parent_id' => 38,
'level' => '37-38',
'route' => '',
'icon' => '',
'module' => 'system',
'creator_id' => 1,
'permission_mark' => 'dataDictionary@tables',
'component' => '',
'redirect' => '',
'hidden' => 1,
'keepalive' => 1,
'type' => 2,
'sort' => 10,
'created_at' => 1587463173,
'updated_at' => 1599362678,
'deleted_at' => 0,
),
2 =>
array (
'id' => 41,
'permission_name' => '优化',
'parent_id' => 38,
'level' => '37-38',
'route' => '',
'icon' => '',
'module' => 'system',
'creator_id' => 1,
'permission_mark' => 'dataDictionary@optimize',
'component' => '',
'redirect' => '',
'hidden' => 1,
'keepalive' => 1,
'type' => 2,
'sort' => 1,
'created_at' => 1587463201,
'updated_at' => 1599362678,
'deleted_at' => 0,
),
3 =>
array (
'id' => 42,
'permission_name' => '备份',
'parent_id' => 38,
'level' => '37-38',
'route' => '',
'icon' => '',
'module' => 'system',
'creator_id' => 1,
'permission_mark' => 'optimize@backup',
'component' => '',
'redirect' => '',
'hidden' => 1,
'keepalive' => 1,
'type' => 2,
'sort' => 1,
'created_at' => 1587463217,
'updated_at' => 1599362678,
'deleted_at' => 0,
),
),
),
1 =>
array (
'id' => 43,
'permission_name' => '附件管理',
'parent_id' => 37,
'level' => '37',
'route' => '/system/attactments',
'icon' => 'el-icon-folder-opened',
'module' => 'system',
'creator_id' => 1,
'permission_mark' => 'attactments',
'component' => 'attachment',
'redirect' => '',
'hidden' => 1,
'keepalive' => 1,
'type' => 1,
'sort' => 10,
'created_at' => 1587463302,
'updated_at' => 1599288737,
'deleted_at' => 0,
'children' =>
array (
0 =>
array (
'id' => 44,
'permission_name' => '列表',
'parent_id' => 43,
'level' => '37-43',
'route' => '',
'icon' => '',
'module' => 'system',
'creator_id' => 1,
'permission_mark' => 'attachments@index',
'component' => '',
'redirect' => '',
'hidden' => 1,
'keepalive' => 1,
'type' => 2,
'sort' => 1,
'created_at' => 1587463335,
'updated_at' => 1599217559,
'deleted_at' => 0,
),
1 =>
array (
'id' => 45,
'permission_name' => '删除',
'parent_id' => 43,
'level' => '37-43',
'route' => '',
'icon' => '',
'module' => 'system',
'creator_id' => 1,
'permission_mark' => 'attachments@delete',
'component' => '',
'redirect' => '',
'hidden' => 1,
'keepalive' => 1,
'type' => 2,
'sort' => 1,
'created_at' => 1587463355,
'updated_at' => 1599217559,
'deleted_at' => 0,
),
2 =>
array (
'id' => 46,
'permission_name' => '上传图片',
'parent_id' => 43,
'level' => '37-43',
'route' => '',
'icon' => '',
'module' => 'system',
'creator_id' => 1,
'permission_mark' => 'upload@image',
'component' => '',
'redirect' => '',
'hidden' => 1,
'keepalive' => 1,
'type' => 2,
'sort' => 1,
'created_at' => 1587466919,
'updated_at' => 1599217559,
'deleted_at' => 0,
),
3 =>
array (
'id' => 47,
'permission_name' => '上传文件',
'parent_id' => 43,
'level' => '37-43',
'route' => '',
'icon' => '',
'module' => 'system',
'creator_id' => 1,
'permission_mark' => 'upload@file',
'component' => '',
'redirect' => '',
'hidden' => 1,
'keepalive' => 1,
'type' => 2,
'sort' => 1,
'created_at' => 1587466939,
'updated_at' => 1599217559,
'deleted_at' => 0,
),
),
),
2 =>
array (
'id' => 48,
'permission_name' => '配置管理',
'parent_id' => 37,
'level' => '37',
'route' => '/system/config',
'icon' => 'el-icon-setting',
'module' => 'system',
'creator_id' => 1,
'permission_mark' => 'config',
'component' => 'config',
'redirect' => '',
'hidden' => 1,
'keepalive' => 1,
'type' => 1,
'sort' => 9,
'created_at' => 1587466991,
'updated_at' => 1599288737,
'deleted_at' => 0,
'children' =>
array (
0 =>
array (
'id' => 49,
'permission_name' => '父级配置',
'parent_id' => 48,
'level' => '37-48',
'route' => '',
'icon' => '',
'module' => 'system',
'creator_id' => 1,
'permission_mark' => 'config@parent',
'component' => '',
'redirect' => '',
'hidden' => 1,
'keepalive' => 1,
'type' => 2,
'sort' => 1,
'created_at' => 1587467036,
'updated_at' => 1591345651,
'deleted_at' => 0,
),
1 =>
array (
'id' => 50,
'permission_name' => '存储',
'parent_id' => 48,
'level' => '37-48',
'route' => '',
'icon' => '',
'module' => 'system',
'creator_id' => 1,
'permission_mark' => 'config@save',
'component' => '',
'redirect' => '',
'hidden' => 1,
'keepalive' => 1,
'type' => 2,
'sort' => 1,
'created_at' => 1587467052,
'updated_at' => 1587547118,
'deleted_at' => 0,
),
2 =>
array (
'id' => 51,
'permission_name' => '获取',
'parent_id' => 48,
'level' => '37-48',
'route' => '',
'icon' => '',
'module' => 'system',
'creator_id' => 1,
'permission_mark' => 'config@read',
'component' => '',
'redirect' => '',
'hidden' => 1,
'keepalive' => 1,
'type' => 2,
'sort' => 1,
'created_at' => 1587467062,
'updated_at' => 1587547118,
'deleted_at' => 0,
),
),
),
3 =>
array (
'id' => 52,
'permission_name' => '登陆日志',
'parent_id' => 37,
'level' => '37',
'route' => '/system/log/operate',
'icon' => 'el-icon-coin',
'module' => 'system',
'creator_id' => 1,
'permission_mark' => 'loginLog',
'component' => 'loginLog',
'redirect' => '',
'hidden' => 1,
'keepalive' => 1,
'type' => 1,
'sort' => 5,
'created_at' => 1587467150,
'updated_at' => 1599288737,
'deleted_at' => 0,
'children' =>
array (
0 =>
array (
'id' => 53,
'permission_name' => '列表',
'parent_id' => 52,
'level' => '37-52',
'route' => '',
'icon' => '',
'module' => 'system',
'creator_id' => 1,
'permission_mark' => 'loginlog@list',
'component' => '',
'redirect' => '',
'hidden' => 1,
'keepalive' => 1,
'type' => 2,
'sort' => 1,
'created_at' => 1587467206,
'updated_at' => 1587547118,
'deleted_at' => 0,
),
1 =>
array (
'id' => 54,
'permission_name' => '清空',
'parent_id' => 52,
'level' => '37-52',
'route' => '',
'icon' => '',
'module' => 'system',
'creator_id' => 1,
'permission_mark' => 'loginlog@empty',
'component' => '',
'redirect' => '',
'hidden' => 1,
'keepalive' => 1,
'type' => 2,
'sort' => 1,
'created_at' => 1587467221,
'updated_at' => 1587547118,
'deleted_at' => 0,
),
),
),
4 =>
array (
'id' => 55,
'permission_name' => '操作日志',
'parent_id' => 37,
'level' => '37',
'route' => '/system/log/login',
'icon' => 'el-icon-house',
'module' => 'system',
'creator_id' => 1,
'permission_mark' => 'operateLog',
'component' => 'operateLog',
'redirect' => '',
'hidden' => 1,
'keepalive' => 1,
'type' => 1,
'sort' => 1,
'created_at' => 1587467180,
'updated_at' => 1599288737,
'deleted_at' => 0,
'children' =>
array (
0 =>
array (
'id' => 56,
'permission_name' => '列表',
'parent_id' => 55,
'level' => '37-55',
'route' => '',
'icon' => '',
'module' => 'system',
'creator_id' => 1,
'permission_mark' => 'operatelog@list',
'component' => '',
'redirect' => '',
'hidden' => 1,
'keepalive' => 1,
'type' => 2,
'sort' => 1,
'created_at' => 1587467246,
'updated_at' => 1587547118,
'deleted_at' => 0,
),
1 =>
array (
'id' => 57,
'permission_name' => '清空',
'parent_id' => 55,
'level' => '37-55',
'route' => '',
'icon' => '',
'module' => 'system',
'creator_id' => 1,
'permission_mark' => 'operatelog@empty',
'component' => '',
'redirect' => '',
'hidden' => 1,
'keepalive' => 1,
'type' => 2,
'sort' => 1,
'created_at' => 1587467266,
'updated_at' => 1587547118,
'deleted_at' => 0,
),
),
),
5 =>
array (
'id' => 58,
'permission_name' => '代码生成',
'parent_id' => 37,
'level' => '37',
'route' => '/system/generate',
'icon' => 'el-icon-scissors',
'module' => 'system',
'creator_id' => 1,
'permission_mark' => 'generate',
'component' => 'generate',
'redirect' => '',
'hidden' => 1,
'keepalive' => 1,
'type' => 1,
'sort' => 1,
'created_at' => 1587717452,
'updated_at' => 1599288737,
'deleted_at' => 0,
'children' =>
array (
0 =>
array (
'id' => 59,
'permission_name' => '生成',
'parent_id' => 58,
'level' => '37-58',
'route' => '',
'icon' => '',
'module' => 'system',
'creator_id' => 1,
'permission_mark' => 'generate@save',
'component' => '',
'redirect' => '',
'hidden' => 1,
'keepalive' => 1,
'type' => 2,
'sort' => 1,
'created_at' => 1588110923,
'updated_at' => 1599217574,
'deleted_at' => 0,
),
1 =>
array (
'id' => 60,
'permission_name' => '预览',
'parent_id' => 58,
'level' => '37-58',
'route' => '',
'icon' => '',
'module' => 'system',
'creator_id' => 1,
'permission_mark' => 'generate@preview',
'component' => '',
'redirect' => '',
'hidden' => 1,
'keepalive' => 1,
'type' => 2,
'sort' => 1,
'created_at' => 1588110962,
'updated_at' => 1599217574,
'deleted_at' => 0,
),
),
),
6 =>
array (
'id' => 68,
'permission_name' => '敏感词库',
'parent_id' => 37,
'level' => '37',
'route' => '/sensitive/word',
'icon' => 'el-icon-folder-delete',
'module' => 'system',
'creator_id' => 1,
'permission_mark' => 'sensitiveWord',
'component' => 'sensitiveWord',
'redirect' => '',
'hidden' => 1,
'keepalive' => 1,
'type' => 1,
'sort' => 1,
'created_at' => 1592375865,
'updated_at' => 1599288737,
'deleted_at' => 0,
'children' =>
array (
0 =>
array (
'id' => 69,
'permission_name' => '列表',
'parent_id' => 68,
'level' => '37-68',
'route' => '',
'icon' => '',
'module' => 'system',
'creator_id' => 1,
'permission_mark' => 'sensitiveWord@index',
'component' => '',
'redirect' => '',
'hidden' => 1,
'keepalive' => 1,
'type' => 2,
'sort' => 1,
'created_at' => 1592382167,
'updated_at' => 1593589434,
'deleted_at' => 0,
),
1 =>
array (
'id' => 70,
'permission_name' => '新增',
'parent_id' => 68,
'level' => '37-68',
'route' => '',
'icon' => '',
'module' => 'system',
'creator_id' => 1,
'permission_mark' => 'sensitiveWord@save',
'component' => '',
'redirect' => '',
'hidden' => 1,
'keepalive' => 1,
'type' => 2,
'sort' => 1,
'created_at' => 1592382179,
'updated_at' => 1593589434,
'deleted_at' => 0,
),
2 =>
array (
'id' => 71,
'permission_name' => '更新',
'parent_id' => 68,
'level' => '37-68',
'route' => '',
'icon' => '',
'module' => 'system',
'creator_id' => 1,
'permission_mark' => 'sensitiveWord@update',
'component' => '',
'redirect' => '',
'hidden' => 1,
'keepalive' => 1,
'type' => 2,
'sort' => 1,
'created_at' => 1592382192,
'updated_at' => 1593589434,
'deleted_at' => 0,
),
3 =>
array (
'id' => 72,
'permission_name' => '删除',
'parent_id' => 68,
'level' => '37-68',
'route' => '',
'icon' => '',
'module' => 'system',
'creator_id' => 1,
'permission_mark' => 'sensitiveWord@delete',
'component' => '',
'redirect' => '',
'hidden' => 1,
'keepalive' => 1,
'type' => 2,
'sort' => 1,
'created_at' => 1592382202,
'updated_at' => 1593589434,
'deleted_at' => 0,
),
),
),
7 =>
array (
'id' => 101,
'permission_name' => '开发者',
'parent_id' => 37,
'level' => '37',
'route' => '/system/develop',
'icon' => 'el-icon-rank',
'module' => 'system',
'creator_id' => 1,
'permission_mark' => 'develop',
'component' => 'develop',
'redirect' => '',
'hidden' => 1,
'keepalive' => 1,
'type' => 1,
'sort' => 1,
'created_at' => 1594626307,
'updated_at' => 1599288737,
'deleted_at' => 0,
),
),
),
);
}
}

View File

@@ -1,621 +0,0 @@
<?php
use think\migration\Seeder;
class SystemPermissionSeed extends Seeder
{
/**
* Run Method.
*
* Write your database seeder using this method.
*
* More information on writing seeders is available here:
* http://docs.phinx.org/en/latest/seeding.html
*/
public function run()
{
\catcher\Utils::importTreeData($this->getPermissions(), 'permissions', 'parent_id');
}
protected function getPermissions()
{
return array(
0 =>
array(
'id' => 37,
'permission_name' => '系统管理',
'parent_id' => 0,
'level' => '',
'route' => '/system',
'icon' => 'bar-chart',
'module' => 'system',
'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'system',
'component' => 'pageView',
'redirect' => '',
'hide_children_in_menu' => 2,
'keepalive' => 2,
'type' => 1,
'status' => 1,
'sort' => 1,
'created_at' => 1587462349,
'updated_at' => 1593044431,
'deleted_at' => 0,
'children' =>
array(
0 =>
array(
'id' => 38,
'permission_name' => '数据字典',
'parent_id' => 37,
'level' => '37',
'route' => '/system/database',
'icon' => 'hdd',
'module' => 'system',
'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'dataDictionary@index',
'component' => 'database',
'redirect' => '',
'hide_children_in_menu' => 2,
'keepalive' => 1,
'type' => 1,
'status' => 1,
'sort' => 8,
'created_at' => 1587463087,
'updated_at' => 1593044431,
'deleted_at' => 0,
'children' =>
array(
0 =>
array(
'id' => 39,
'permission_name' => '查看',
'parent_id' => 38,
'level' => '37-38',
'route' => '',
'icon' => '',
'module' => 'system',
'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'dataDictionary@view',
'component' => '',
'redirect' => '',
'hide_children_in_menu' => 1,
'keepalive' => 1,
'type' => 2,
'status' => 1,
'sort' => 1,
'created_at' => 1587463113,
'updated_at' => 1591343449,
'deleted_at' => 0,
),
1 =>
array(
'id' => 40,
'permission_name' => '列表',
'parent_id' => 38,
'level' => '37-38',
'route' => '',
'icon' => '',
'module' => 'system',
'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'dataDictionary@tables',
'component' => '',
'redirect' => '',
'hide_children_in_menu' => 1,
'keepalive' => 1,
'type' => 2,
'status' => 1,
'sort' => 10,
'created_at' => 1587463173,
'updated_at' => 1587547118,
'deleted_at' => 0,
),
2 =>
array(
'id' => 41,
'permission_name' => '优化',
'parent_id' => 38,
'level' => '37-38',
'route' => '',
'icon' => '',
'module' => 'system',
'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'dataDictionary@optimize',
'component' => '',
'redirect' => '',
'hide_children_in_menu' => 1,
'keepalive' => 1,
'type' => 2,
'status' => 1,
'sort' => 1,
'created_at' => 1587463201,
'updated_at' => 1587547118,
'deleted_at' => 0,
),
3 =>
array(
'id' => 42,
'permission_name' => '备份',
'parent_id' => 38,
'level' => '37-38',
'route' => '',
'icon' => '',
'module' => 'system',
'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'optimize@backup',
'component' => '',
'redirect' => '',
'hide_children_in_menu' => 1,
'keepalive' => 1,
'type' => 2,
'status' => 1,
'sort' => 1,
'created_at' => 1587463217,
'updated_at' => 1587547118,
'deleted_at' => 0,
),
),
),
1 =>
array(
'id' => 43,
'permission_name' => '附件管理',
'parent_id' => 37,
'level' => '37',
'route' => '/attactments',
'icon' => 'folder-open',
'module' => 'system',
'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'attactments',
'component' => 'attachment',
'redirect' => '',
'hide_children_in_menu' => 2,
'keepalive' => 1,
'type' => 1,
'status' => 1,
'sort' => 10,
'created_at' => 1587463302,
'updated_at' => 1593044431,
'deleted_at' => 0,
'children' =>
array(
0 =>
array(
'id' => 44,
'permission_name' => '列表',
'parent_id' => 43,
'level' => '37-43',
'route' => '',
'icon' => '',
'module' => 'system',
'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'attachments@index',
'component' => '',
'redirect' => '',
'hide_children_in_menu' => 1,
'keepalive' => 1,
'type' => 2,
'status' => 1,
'sort' => 1,
'created_at' => 1587463335,
'updated_at' => 1587547118,
'deleted_at' => 0,
),
1 =>
array(
'id' => 45,
'permission_name' => '删除',
'parent_id' => 43,
'level' => '37-43',
'route' => '',
'icon' => '',
'module' => 'system',
'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'attachments@delete',
'component' => '',
'redirect' => '',
'hide_children_in_menu' => 1,
'keepalive' => 1,
'type' => 2,
'status' => 1,
'sort' => 1,
'created_at' => 1587463355,
'updated_at' => 1587547118,
'deleted_at' => 0,
),
2 =>
array(
'id' => 46,
'permission_name' => '上传图片',
'parent_id' => 43,
'level' => '37-43',
'route' => '',
'icon' => '',
'module' => 'system',
'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'upload@image',
'component' => '',
'redirect' => '',
'hide_children_in_menu' => 1,
'keepalive' => 1,
'type' => 2,
'status' => 1,
'sort' => 1,
'created_at' => 1587466919,
'updated_at' => 1587547118,
'deleted_at' => 0,
),
3 =>
array(
'id' => 47,
'permission_name' => '上传文件',
'parent_id' => 43,
'level' => '37-43',
'route' => '',
'icon' => '',
'module' => 'system',
'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'upload@file',
'component' => '',
'redirect' => '',
'hide_children_in_menu' => 1,
'keepalive' => 1,
'type' => 2,
'status' => 1,
'sort' => 1,
'created_at' => 1587466939,
'updated_at' => 1587547118,
'deleted_at' => 0,
),
),
),
2 =>
array(
'id' => 48,
'permission_name' => '配置管理',
'parent_id' => 37,
'level' => '37',
'route' => '/system/config',
'icon' => 'setting',
'module' => 'system',
'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'config',
'component' => 'config',
'redirect' => '',
'hide_children_in_menu' => 2,
'keepalive' => 1,
'type' => 1,
'status' => 1,
'sort' => 9,
'created_at' => 1587466991,
'updated_at' => 1593044431,
'deleted_at' => 0,
'children' =>
array(
0 =>
array(
'id' => 49,
'permission_name' => '父级配置',
'parent_id' => 48,
'level' => '37-48',
'route' => '',
'icon' => '',
'module' => 'system',
'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'config@parent',
'component' => '',
'redirect' => '',
'hide_children_in_menu' => 1,
'keepalive' => 1,
'type' => 2,
'status' => 1,
'sort' => 1,
'created_at' => 1587467036,
'updated_at' => 1591345651,
'deleted_at' => 0,
),
1 =>
array(
'id' => 50,
'permission_name' => '存储',
'parent_id' => 48,
'level' => '37-48',
'route' => '',
'icon' => '',
'module' => 'system',
'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'config@save',
'component' => '',
'redirect' => '',
'hide_children_in_menu' => 1,
'keepalive' => 1,
'type' => 2,
'status' => 1,
'sort' => 1,
'created_at' => 1587467052,
'updated_at' => 1587547118,
'deleted_at' => 0,
),
2 =>
array(
'id' => 51,
'permission_name' => '获取',
'parent_id' => 48,
'level' => '37-48',
'route' => '',
'icon' => '',
'module' => 'system',
'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'config@read',
'component' => '',
'redirect' => '',
'hide_children_in_menu' => 1,
'keepalive' => 1,
'type' => 2,
'status' => 1,
'sort' => 1,
'created_at' => 1587467062,
'updated_at' => 1587547118,
'deleted_at' => 0,
),
),
),
3 =>
array(
'id' => 52,
'permission_name' => '登陆日志',
'parent_id' => 37,
'level' => '37',
'route' => '/system/log/login',
'icon' => 'export',
'module' => 'system',
'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'loginLog',
'component' => 'loginLog',
'redirect' => '',
'hide_children_in_menu' => 2,
'keepalive' => 1,
'type' => 1,
'status' => 1,
'sort' => 5,
'created_at' => 1587467150,
'updated_at' => 1593044431,
'deleted_at' => 0,
'children' =>
array(
0 =>
array(
'id' => 53,
'permission_name' => '列表',
'parent_id' => 52,
'level' => '37-52',
'route' => '',
'icon' => '',
'module' => 'system',
'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'loginlog@list',
'component' => '',
'redirect' => '',
'hide_children_in_menu' => 1,
'keepalive' => 1,
'type' => 2,
'status' => 1,
'sort' => 1,
'created_at' => 1587467206,
'updated_at' => 1587547118,
'deleted_at' => 0,
),
1 =>
array(
'id' => 54,
'permission_name' => '清空',
'parent_id' => 52,
'level' => '37-52',
'route' => '',
'icon' => '',
'module' => 'system',
'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'loginlog@empty',
'component' => '',
'redirect' => '',
'hide_children_in_menu' => 1,
'keepalive' => 1,
'type' => 2,
'status' => 1,
'sort' => 1,
'created_at' => 1587467221,
'updated_at' => 1587547118,
'deleted_at' => 0,
),
),
),
4 =>
array(
'id' => 55,
'permission_name' => '操作日志',
'parent_id' => 37,
'level' => '37',
'route' => '/system/log/operate',
'icon' => 'profile',
'module' => 'system',
'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'operateLog',
'component' => 'operateLog',
'redirect' => '',
'hide_children_in_menu' => 2,
'keepalive' => 1,
'type' => 1,
'status' => 1,
'sort' => 1,
'created_at' => 1587467180,
'updated_at' => 1593044431,
'deleted_at' => 0,
'children' =>
array(
0 =>
array(
'id' => 56,
'permission_name' => '列表',
'parent_id' => 55,
'level' => '37-55',
'route' => '',
'icon' => '',
'module' => 'system',
'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'operatelog@list',
'component' => '',
'redirect' => '',
'hide_children_in_menu' => 1,
'keepalive' => 1,
'type' => 2,
'status' => 1,
'sort' => 1,
'created_at' => 1587467246,
'updated_at' => 1587547118,
'deleted_at' => 0,
),
1 =>
array(
'id' => 57,
'permission_name' => '清空',
'parent_id' => 55,
'level' => '37-55',
'route' => '',
'icon' => '',
'module' => 'system',
'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'operatelog@empty',
'component' => '',
'redirect' => '',
'hide_children_in_menu' => 1,
'keepalive' => 1,
'type' => 2,
'status' => 1,
'sort' => 1,
'created_at' => 1587467266,
'updated_at' => 1587547118,
'deleted_at' => 0,
),
),
),
5 =>
array(
'id' => 58,
'permission_name' => '代码生成',
'parent_id' => 37,
'level' => '37',
'route' => '/generate',
'icon' => 'scissor',
'module' => 'system',
'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'generate',
'component' => 'generate',
'redirect' => '',
'hide_children_in_menu' => 2,
'keepalive' => 1,
'type' => 1,
'status' => 1,
'sort' => 1,
'created_at' => 1587717452,
'updated_at' => 1593044431,
'deleted_at' => 0,
'children' =>
array(
0 =>
array(
'id' => 59,
'permission_name' => '生成',
'parent_id' => 58,
'level' => '37-58',
'route' => '',
'icon' => '',
'module' => 'system',
'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'generate@save',
'component' => '',
'redirect' => '',
'hide_children_in_menu' => 1,
'keepalive' => 1,
'type' => 2,
'status' => 1,
'sort' => 1,
'created_at' => 1588110923,
'updated_at' => 1588110923,
'deleted_at' => 0,
),
1 =>
array(
'id' => 60,
'permission_name' => '预览',
'parent_id' => 58,
'level' => '37-58',
'route' => '',
'icon' => '',
'module' => 'system',
'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'generate@preview',
'component' => '',
'redirect' => '',
'hide_children_in_menu' => 1,
'keepalive' => 1,
'type' => 2,
'status' => 1,
'sort' => 1,
'created_at' => 1588110962,
'updated_at' => 1588110962,
'deleted_at' => 0,
),
),
),
6 =>
array(
'id' => 68,
'permission_name' => '敏感词库',
'parent_id' => 37,
'level' => '37',
'route' => '/sensitive/word',
'icon' => 'sliders',
'module' => 'system',
'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'sensitiveWord',
'component' => 'sensitiveWord',
'redirect' => '',
'hide_children_in_menu' => 2,
'keepalive' => 1,
'type' => 1,
'status' => 1,
'sort' => 1,
'created_at' => 1592375865,
'updated_at' => 1593044431,
'deleted_at' => 0,
),
),
),
);
}
}

View File

@@ -1,12 +1,15 @@
<?php <?php
namespace catchAdmin\system\model; namespace catchAdmin\system\model;
use catchAdmin\system\model\search\AttachmentsSearch;
use catcher\base\CatchModel; use catcher\base\CatchModel;
use think\file\UploadedFile; use think\file\UploadedFile;
use think\Model; use think\Model;
class Attachments extends CatchModel class Attachments extends CatchModel
{ {
use AttachmentsSearch;
protected $name = 'attachments'; protected $name = 'attachments';
protected $field = [ protected $field = [
@@ -27,24 +30,10 @@ class Attachments extends CatchModel
{ {
return $this->order('id', 'desc') return $this->order('id', 'desc')
->catchSearch() ->catchSearch()
->catchOrder()
->paginate(); ->paginate();
} }
public function searchFileExtAttr($query, $value, $data)
{
return $query->where('file_ext', $value);
}
public function searchMimeTypesAttr($query, $value, $data)
{
return $query->where('mime_type', $value);
}
public function searchDriver($query, $value, $data)
{
return $query->where('driver', $value);
}
/** /**
* *
* *

View File

@@ -2,6 +2,7 @@
namespace catchAdmin\system\model; namespace catchAdmin\system\model;
use catcher\base\CatchModel; use catcher\base\CatchModel;
use catcher\exceptions\FailedException;
use thans\jwt\exception\UserNotDefinedException; use thans\jwt\exception\UserNotDefinedException;
use think\Model; use think\Model;
@@ -55,94 +56,47 @@ class Config extends CatchModel
return true; return true;
} }
// 子配置 $parent = $data['parent'] ?? false;
if ($data['pid'] ?? false) { if (!$parent) {
$config = \json_decode($data['config'], true); throw new FailedException('父配置丢失');
$pid = $data['pid']; }
unset($data['pid']); unset($data['parent']);
/**[
'key' => [
'k' => 'v'
],
'k' => 'v' $parentConfig = $this->where('key', $parent)->find();
]*/ $config = [];
foreach ($config as $key => $value) { foreach ($data as $key => $item) {
if (empty($value)) { foreach ($item as $k => $value) {
continue; if ($value) {
$config[$key . '.' .$k] = [
'pid' => $parentConfig['id'],
'key' => $key . '.' . $k,
'value' => $value,
'created_at' => time(),
'updated_at' => time(),
];
} }
// 如果二级配置存在
$secondLevel = $this->isExistConfig($key, $pid);
if ($secondLevel) {
// value 是字符串
if (!is_array($value)) {
if ($value != $secondLevel->value) {
$secondLevel->value = $value;
$secondLevel->save();
} }
} else { }
// 数组
$thirdLevel = []; $this->where('pid', $parentConfig->id)
$this->subConfig($secondLevel->id, ['id', 'key', 'value']) ->select()
->each(function ($item, $key) use (&$thirdLevel){ ->each(function ($item) use (&$config){
$thirdLevel[$item['key']] = $item; if (isset($config[$item['key']])) {
if ($config[$item['key']]['value'] != $item->value) {
$item['value'] = $config[$item['key']]['value'];
$item->save();
}
unset($config[$item['key']]);
}
}); });
if (!empty($value)) { if (count($config)) {
$new = []; return $this->insertAll($config);
foreach ($value as $k => $v) {
if (isset($thirdLevel[$k])) {
if ($v != $thirdLevel[$k]->value) {
$thirdLevel[$k]->value = $v;
$thirdLevel[$k]->save();
}
} else {
$new[] = [
'pid' => $secondLevel->id,
'key' => $k,
'value' => $v,
];
}
}
if (!empty($new)) {
parent::insertAllBy($new);
}
}
}
} else {
if (!is_array($value)) {
parent::createBy([
'pid' => $pid,
'key' => $key,
'value' => $value,
]);
} else {
$id = parent::createBy([
'pid' => $pid,
'key' => $key,
]);
if (!empty($value)) {
$newConfig = [];
foreach ($value as $k => $v) {
$newConfig[] = [
'key' => $k,
'value' => $v,
'pid' => $id,
];
}
parent::insertAllBy($newConfig);
}
}
}
} }
return true; return true;
} }
return parent::storeBy($data);
}
/** /**
* 配置是否存在 * 配置是否存在
* *
@@ -183,28 +137,26 @@ class Config extends CatchModel
* 获取配置 * 获取配置
* *
* @time 2020年04月20日 * @time 2020年04月20日
* @param int $pid * @param string $component
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException * @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
* @return array|mixed * @return array|mixed
*/ */
public function getConfig($pid = 0) public function getConfig(string $component)
{ {
$data = []; $data = [];
$configs = $this->where('pid', $this->where('component', $component)->value('id'))
$configs = $this->where('pid', $pid)
->field('id,`key` as k,value,pid') ->field('id,`key` as k,value,pid')
->select(); ->select();
foreach ($configs as $config) { foreach ($configs as $config) {
if ($config->value !== '') { if (strpos($config['k'], '.') !== false) {
$data[$config->k] = $config->value; list($object, $key) = explode('.', $config['k']);
} else { $data[$object][$key] = $config['value'];
$data[$config->k] = $this->getConfig($config->id);
} }
} }
return empty($data) ? '' : $data; return $data;
} }
} }

View File

@@ -11,10 +11,13 @@
namespace catchAdmin\system\model; namespace catchAdmin\system\model;
use catchAdmin\system\model\search\DeveloperSearch;
use catcher\base\CatchModel as Model; use catcher\base\CatchModel as Model;
class Developers extends Model class Developers extends Model
{ {
use DeveloperSearch;
protected $name = 'developers'; protected $name = 'developers';
protected $field = [ protected $field = [

View File

@@ -0,0 +1,29 @@
<?php
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
// +----------------------------------------------------------------------
// | Author: JaguarJack [ njphper@gmail.com ]
// +----------------------------------------------------------------------
namespace catchAdmin\system\model\search;
trait AttachmentsSearch
{
public function searchFileExtAttr($query, $value, $data)
{
return $query->where('file_ext', $value);
}
public function searchMimeTypesAttr($query, $value, $data)
{
return $query->where('mime_type', $value);
}
public function searchDriverAttr($query, $value, $data)
{
return $query->where('driver', $value);
}
}

View File

@@ -0,0 +1,29 @@
<?php
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
// +----------------------------------------------------------------------
// | Author: JaguarJack [ njphper@gmail.com ]
// +----------------------------------------------------------------------
namespace catchAdmin\system\model\search;
trait DeveloperSearch
{
public function searchUsernameAttr($query, $value, $data)
{
return $query->whereLike('username', $value);
}
public function searchMobileAttr($query, $value, $data)
{
return $query->whereLike('mobile', $value);
}
public function searchStatusAttr($query, $value, $data)
{
return $query->where('driver', $value);
}
}

View File

@@ -10,7 +10,7 @@ class CreateRequest extends CatchRequest
{ {
// TODO: Implement rules() method. // TODO: Implement rules() method.
return [ return [
'word|词汇' => 'sensitive_word|unique:'.SensitiveWord::class.',word', 'word|词汇' => 'unique:'.SensitiveWord::class.',word',
]; ];
} }
} }

View File

@@ -5,8 +5,8 @@ $router->group(function () use ($router) {
$router->delete('loginLog/empty', '\catchAdmin\system\controller\LoginLog@empty'); $router->delete('loginLog/empty', '\catchAdmin\system\controller\LoginLog@empty');
// 操作日志 // 操作日志
$router->get('log/operate', '\catchAdmin\system\controller\OperateLog@list'); $router->get('log/operate', '\catchAdmin\system\controller\OperateLog@list');
$router->delete('operateLog/empty', '\catchAdmin\system\controller\OperateLog@empty'); // $router->delete('empty/log/operate', '\catchAdmin\system\controller\OperateLog@empty');
$router->delete('operateLog/delete', '\catchAdmin\system\controller\OperateLog@delete'); $router->delete('log/operate/<id>', '\catchAdmin\system\controller\OperateLog@delete');
// 数据字典 // 数据字典
$router->get('tables', '\catchAdmin\system\controller\DataDictionary@tables'); $router->get('tables', '\catchAdmin\system\controller\DataDictionary@tables');

View File

@@ -2,7 +2,7 @@
use think\migration\Seeder; use think\migration\Seeder;
class WechatPermissionSeed extends Seeder class WechatMenusSeed extends Seeder
{ {
/** /**
* Run Method. * Run Method.
@@ -30,17 +30,15 @@ class WechatPermissionSeed extends Seeder
'icon' => 'wechat', 'icon' => 'wechat',
'module' => 'wechat', 'module' => 'wechat',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'wechat', 'permission_mark' => 'wechat',
'component' => 'routeView', 'component' => 'layout',
'redirect' => '', 'redirect' => '/wechat/menus',
'hide_children_in_menu' => 2, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 1, 'type' => 1,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1591603025, 'created_at' => 1591603025,
'updated_at' => 1593044101, 'updated_at' => 1599371183,
'deleted_at' => 0, 'deleted_at' => 0,
'children' => 'children' =>
array ( array (
@@ -54,17 +52,15 @@ class WechatPermissionSeed extends Seeder
'icon' => 'table', 'icon' => 'table',
'module' => 'wechat', 'module' => 'wechat',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'menus', 'permission_mark' => 'menus',
'component' => 'menus', 'component' => 'menus',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 2, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 1, 'type' => 1,
'status' => 1, 'sort' => 18,
'sort' => 1,
'created_at' => 1591603088, 'created_at' => 1591603088,
'updated_at' => 1591603427, 'updated_at' => 1599371183,
'deleted_at' => 0, 'deleted_at' => 0,
'children' => 'children' =>
array ( array (
@@ -78,17 +74,15 @@ class WechatPermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'wechat', 'module' => 'wechat',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'menus@index', 'permission_mark' => 'menus@index',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1593304908, 'created_at' => 1593304908,
'updated_at' => 1593304908, 'updated_at' => 1599371167,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
1 => 1 =>
@@ -101,17 +95,15 @@ class WechatPermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'wechat', 'module' => 'wechat',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'menus@save', 'permission_mark' => 'menus@save',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1593304915, 'created_at' => 1593304915,
'updated_at' => 1593304915, 'updated_at' => 1599371167,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
2 => 2 =>
@@ -124,17 +116,15 @@ class WechatPermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'wechat', 'module' => 'wechat',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'menus@update', 'permission_mark' => 'menus@update',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1593304923, 'created_at' => 1593304923,
'updated_at' => 1593304923, 'updated_at' => 1599371167,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
3 => 3 =>
@@ -147,17 +137,15 @@ class WechatPermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'wechat', 'module' => 'wechat',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'menus@delete', 'permission_mark' => 'menus@delete',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1593304929, 'created_at' => 1593304929,
'updated_at' => 1593304929, 'updated_at' => 1599371167,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
4 => 4 =>
@@ -170,17 +158,15 @@ class WechatPermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'wechat', 'module' => 'wechat',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'menus@sync', 'permission_mark' => 'menus@sync',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1593304938, 'created_at' => 1593304938,
'updated_at' => 1593304938, 'updated_at' => 1599371167,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
), ),
@@ -192,20 +178,18 @@ class WechatPermissionSeed extends Seeder
'parent_id' => 66, 'parent_id' => 66,
'level' => '66', 'level' => '66',
'route' => '/wechat/users', 'route' => '/wechat/users',
'icon' => 'team', 'icon' => 'el-icon-s-custom',
'module' => 'wechat', 'module' => 'wechat',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'users', 'permission_mark' => 'users',
'component' => 'pageView', 'component' => 'routerView',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 2, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 1, 'type' => 1,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1592624761, 'created_at' => 1592624761,
'updated_at' => 1592631716, 'updated_at' => 1599371697,
'deleted_at' => 0, 'deleted_at' => 0,
'children' => 'children' =>
array ( array (
@@ -215,21 +199,19 @@ class WechatPermissionSeed extends Seeder
'permission_name' => '微信用户', 'permission_name' => '微信用户',
'parent_id' => 75, 'parent_id' => 75,
'level' => '66-75', 'level' => '66-75',
'route' => '/wechat/users', 'route' => '/wechat/users/user',
'icon' => 'user', 'icon' => 'user',
'module' => 'wechat', 'module' => 'wechat',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'users', 'permission_mark' => 'users',
'component' => 'wechatUsers', 'component' => 'wechatUsers',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 2, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 1, 'type' => 1,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1592624799, 'created_at' => 1592624799,
'updated_at' => 1592624799, 'updated_at' => 1599376002,
'deleted_at' => 0, 'deleted_at' => 0,
'children' => 'children' =>
array ( array (
@@ -243,17 +225,15 @@ class WechatPermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'wechat', 'module' => 'wechat',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'users@index', 'permission_mark' => 'users@index',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1593304869, 'created_at' => 1593304869,
'updated_at' => 1593304869, 'updated_at' => 1599376002,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
1 => 1 =>
@@ -266,17 +246,15 @@ class WechatPermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'wechat', 'module' => 'wechat',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'users@remark', 'permission_mark' => 'users@remark',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1593304876, 'created_at' => 1593304876,
'updated_at' => 1593304876, 'updated_at' => 1599376002,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
2 => 2 =>
@@ -289,17 +267,15 @@ class WechatPermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'wechat', 'module' => 'wechat',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'users@block', 'permission_mark' => 'users@block',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1593304884, 'created_at' => 1593304884,
'updated_at' => 1593304884, 'updated_at' => 1599376002,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
3 => 3 =>
@@ -312,17 +288,15 @@ class WechatPermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'wechat', 'module' => 'wechat',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'users@tag', 'permission_mark' => 'users@tag',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1593304892, 'created_at' => 1593304892,
'updated_at' => 1593304892, 'updated_at' => 1599376002,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
4 => 4 =>
@@ -335,17 +309,15 @@ class WechatPermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'wechat', 'module' => 'wechat',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'users@sync', 'permission_mark' => 'users@sync',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1593304900, 'created_at' => 1593304900,
'updated_at' => 1593304900, 'updated_at' => 1599376002,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
), ),
@@ -356,21 +328,19 @@ class WechatPermissionSeed extends Seeder
'permission_name' => '微信标签', 'permission_name' => '微信标签',
'parent_id' => 75, 'parent_id' => 75,
'level' => '66-75', 'level' => '66-75',
'route' => '/wechat/tags', 'route' => '/wechat/users/tag',
'icon' => 'tags', 'icon' => 'el-icon-paperclip',
'module' => 'wechat', 'module' => 'wechat',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'tags', 'permission_mark' => 'tags',
'component' => 'wechatTags', 'component' => 'wechatTags',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 2, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 1, 'type' => 1,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1592722634, 'created_at' => 1592722634,
'updated_at' => 1593304802, 'updated_at' => 1599376011,
'deleted_at' => 0, 'deleted_at' => 0,
'children' => 'children' =>
array ( array (
@@ -384,17 +354,15 @@ class WechatPermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'wechat', 'module' => 'wechat',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get', 'permission_mark' => 'tags@index',
'permission_mark' => 'wechatTags@index',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1593304575, 'created_at' => 1593304575,
'updated_at' => 1593304575, 'updated_at' => 1599376011,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
1 => 1 =>
@@ -407,17 +375,15 @@ class WechatPermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'wechat', 'module' => 'wechat',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get', 'permission_mark' => 'tags@save',
'permission_mark' => 'wechatTags@save',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1593304592, 'created_at' => 1593304592,
'updated_at' => 1593304592, 'updated_at' => 1599376011,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
2 => 2 =>
@@ -430,17 +396,15 @@ class WechatPermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'wechat', 'module' => 'wechat',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'tags@read', 'permission_mark' => 'tags@read',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1593304830, 'created_at' => 1593304830,
'updated_at' => 1593304830, 'updated_at' => 1599376011,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
3 => 3 =>
@@ -453,17 +417,15 @@ class WechatPermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'wechat', 'module' => 'wechat',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'tags@update', 'permission_mark' => 'tags@update',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1593304837, 'created_at' => 1593304837,
'updated_at' => 1593304837, 'updated_at' => 1599376011,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
4 => 4 =>
@@ -476,17 +438,15 @@ class WechatPermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'wechat', 'module' => 'wechat',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'tags@delete', 'permission_mark' => 'tags@delete',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1593304846, 'created_at' => 1593304846,
'updated_at' => 1593304846, 'updated_at' => 1599376011,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
5 => 5 =>
@@ -499,17 +459,15 @@ class WechatPermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'wechat', 'module' => 'wechat',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'tags@sync', 'permission_mark' => 'tags@sync',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1593304859, 'created_at' => 1593304859,
'updated_at' => 1593304859, 'updated_at' => 1599376011,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
), ),
@@ -523,20 +481,18 @@ class WechatPermissionSeed extends Seeder
'parent_id' => 66, 'parent_id' => 66,
'level' => '66', 'level' => '66',
'route' => '/wechat/graphic', 'route' => '/wechat/graphic',
'icon' => 'gold', 'icon' => 'el-icon-document-add',
'module' => 'wechat', 'module' => 'wechat',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'graphic', 'permission_mark' => 'graphic',
'component' => 'wechatGraphic', 'component' => 'wechatGraphic',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 2, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 1, 'type' => 1,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1593227704, 'created_at' => 1593227704,
'updated_at' => 1593227704, 'updated_at' => 1599371183,
'deleted_at' => 0, 'deleted_at' => 0,
'children' => 'children' =>
array ( array (
@@ -550,17 +506,15 @@ class WechatPermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'wechat', 'module' => 'wechat',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'graphic@save', 'permission_mark' => 'graphic@save',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1593304490, 'created_at' => 1593304490,
'updated_at' => 1593304490, 'updated_at' => 1595978929,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
1 => 1 =>
@@ -573,17 +527,15 @@ class WechatPermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'wechat', 'module' => 'wechat',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'graphic@read', 'permission_mark' => 'graphic@read',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1593304510, 'created_at' => 1593304510,
'updated_at' => 1593304510, 'updated_at' => 1595978929,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
2 => 2 =>
@@ -596,17 +548,15 @@ class WechatPermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'wechat', 'module' => 'wechat',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'graphic@index', 'permission_mark' => 'graphic@index',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 2, 'sort' => 2,
'created_at' => 1593304520, 'created_at' => 1593304520,
'updated_at' => 1593304520, 'updated_at' => 1595978929,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
3 => 3 =>
@@ -619,17 +569,15 @@ class WechatPermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'wechat', 'module' => 'wechat',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'graphic@update', 'permission_mark' => 'graphic@update',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1593304530, 'created_at' => 1593304530,
'updated_at' => 1593304530, 'updated_at' => 1595978929,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
4 => 4 =>
@@ -642,17 +590,123 @@ class WechatPermissionSeed extends Seeder
'icon' => '', 'icon' => '',
'module' => 'wechat', 'module' => 'wechat',
'creator_id' => 1, 'creator_id' => 1,
'method' => 'get',
'permission_mark' => 'graphic@delete', 'permission_mark' => 'graphic@delete',
'component' => '', 'component' => '',
'redirect' => '', 'redirect' => '',
'hide_children_in_menu' => 1, 'hidden' => 1,
'keepalive' => 1, 'keepalive' => 1,
'type' => 2, 'type' => 2,
'status' => 1,
'sort' => 1, 'sort' => 1,
'created_at' => 1593304537, 'created_at' => 1593304537,
'updated_at' => 1593304537, 'updated_at' => 1595978929,
'deleted_at' => 0,
),
),
),
3 =>
array (
'id' => 100,
'permission_name' => '微信回复',
'parent_id' => 66,
'level' => '66',
'route' => '/wechat/reply',
'icon' => 'el-icon-chat-line-round',
'module' => 'wechat',
'creator_id' => 1,
'permission_mark' => 'reply',
'component' => 'wechatReply',
'redirect' => '',
'hidden' => 1,
'keepalive' => 1,
'type' => 1,
'sort' => 1,
'created_at' => 1593323887,
'updated_at' => 1599371183,
'deleted_at' => 0,
'children' =>
array (
0 =>
array (
'id' => 111,
'permission_name' => '列表',
'parent_id' => 100,
'level' => '66-100',
'route' => '',
'icon' => '',
'module' => 'wechat',
'creator_id' => 1,
'permission_mark' => 'reply@index',
'component' => '',
'redirect' => '',
'hidden' => 1,
'keepalive' => 1,
'type' => 2,
'sort' => 1,
'created_at' => 1599292333,
'updated_at' => 1599292373,
'deleted_at' => 0,
),
1 =>
array (
'id' => 112,
'permission_name' => '新增',
'parent_id' => 100,
'level' => '66-100',
'route' => '',
'icon' => '',
'module' => 'wechat',
'creator_id' => 1,
'permission_mark' => 'reply@save',
'component' => '',
'redirect' => '',
'hidden' => 1,
'keepalive' => 1,
'type' => 2,
'sort' => 1,
'created_at' => 1599292344,
'updated_at' => 1599292344,
'deleted_at' => 0,
),
2 =>
array (
'id' => 113,
'permission_name' => '删除',
'parent_id' => 100,
'level' => '66-100',
'route' => '',
'icon' => '',
'module' => 'wechat',
'creator_id' => 1,
'permission_mark' => 'reply@delete',
'component' => '',
'redirect' => '',
'hidden' => 1,
'keepalive' => 1,
'type' => 2,
'sort' => 1,
'created_at' => 1599292351,
'updated_at' => 1599292351,
'deleted_at' => 0,
),
3 =>
array (
'id' => 114,
'permission_name' => '禁用/启用',
'parent_id' => 100,
'level' => '66-100',
'route' => '',
'icon' => '',
'module' => 'wechat',
'creator_id' => 1,
'permission_mark' => 'reply@disOrEnable',
'component' => '',
'redirect' => '',
'hidden' => 1,
'keepalive' => 1,
'type' => 2,
'sort' => 1,
'created_at' => 1599292363,
'updated_at' => 1599292363,
'deleted_at' => 0, 'deleted_at' => 0,
), ),
), ),

View File

@@ -14,5 +14,5 @@
"aliases": "wechat", "aliases": "wechat",
"files": [], "files": [],
"requires": [], "requires": [],
"enable": true "enable": false
} }

View File

@@ -101,7 +101,8 @@ class WechatUsersRepository extends CatchRepository
*/ */
public function tag($id, $data) public function tag($id, $data)
{ {
$tagIds = WechatTags::whereIn('name', Utils::stringToArrayBy($data['tag']))->column('tag_id'); $tagIds = Utils::stringToArrayBy($data['tag']);
// WechatTags::whereIn('name', Utils::stringToArrayBy($data['tag']))->column('tag_id');
$user = $this->findBy($id); $user = $this->findBy($id);
@@ -134,6 +135,10 @@ class WechatUsersRepository extends CatchRepository
$user->hasTags()->saveAll($attachIds); $user->hasTags()->saveAll($attachIds);
} }
WechatUsers::where('id', $id)->update([
'tagid_list' => $data['tag'],
]);
return true; return true;
} }
} }

View File

@@ -31,7 +31,8 @@
}, },
"require-dev": { "require-dev": {
"topthink/think-trace":"^1.0", "topthink/think-trace":"^1.0",
"symfony/var-dumper": "^5.1" "symfony/var-dumper": "^5.1",
"swoole/ide-helper": "^4.5"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {

View File

@@ -10,7 +10,7 @@ return [
'local' => [ 'local' => [
'type' => 'local', 'type' => 'local',
'root' => app()->getRootPath() . 'public'.DIRECTORY_SEPARATOR.'images', 'root' => app()->getRootPath() . 'public'.DIRECTORY_SEPARATOR.'images',
'domain' => env('API_URL'), 'domain' => env('app.domain'),
], ],
'public' => [ 'public' => [
// 磁盘类型 // 磁盘类型

View File

@@ -1,10 +1,12 @@
<?php <?php
namespace catcher; namespace catcher;
use catchAdmin\permissions\model\Users;
use catcher\exceptions\FailedException; use catcher\exceptions\FailedException;
use catcher\exceptions\LoginFailedException; use catcher\exceptions\LoginFailedException;
use thans\jwt\facade\JWTAuth; use thans\jwt\facade\JWTAuth;
use think\facade\Session; use think\facade\Session;
use think\helper\Str;
class CatchAuth class CatchAuth
{ {
@@ -49,22 +51,70 @@ class CatchAuth
*/ */
public function attempt($condition) public function attempt($condition)
{ {
try {
$user = $this->authenticate($condition); $user = $this->authenticate($condition);
if (!$user) { if (!$user) {
throw new LoginFailedException(); throw new LoginFailedException();
} }
if ($user->status == Users::DISABLE) {
if (!password_verify($condition['password'], $user->password)) { throw new LoginFailedException('该用户已被禁用|' . $user->username, Code::USER_FORBIDDEN);
throw new LoginFailedException();
} }
return $this->{$this->getDriver()}($user); if (!password_verify($condition['password'], $user->password)) {
throw new LoginFailedException('登录失败|' . $user->username);
}
$token = $this->{$this->getDriver()}($user);
$this->afterLoginSuccess($user);
// 登录事件
$this->loginEvent($user->username);
return $token;
} catch (\Exception $exception) {
$message = $exception->getMessage();
if (strpos($message, '|') !== false) {
$username = explode('|', $message)[1];
} else {
$username = $condition['email'];
}
$this->loginEvent($username, false);
throw new LoginFailedException('登录失败', $exception->getCode());
}
} }
/** /**
* 用户登录成功后
* *
* @time 2020年01月07 * @time 2020年09月09
* @param $user
* @return void
*/
protected function afterLoginSuccess($user)
{
$user->last_login_ip = request()->ip();
$user->last_login_time = time();
$user->save();
}
/**
* 登录事件
*
* @time 2020年09月09日
* @param $name
* @param bool $success
* @return void
*/
protected function loginEvent($name, $success = true)
{
$params['login_name'] = $name;
$params['success'] = $success ? 1 : 2;
event('loginLog', $params);
}
/**
* user
*
* @time 2020年09月09日
* @return mixed * @return mixed
*/ */
public function user() public function user()

View File

@@ -56,11 +56,6 @@ class CatchExceptionHandle extends Handle
$e = new FailedException($e->getMessage(), 10005, $e); $e = new FailedException($e->getMessage(), 10005, $e);
} }
// 类型错误
if ($e instanceof \TypeError) {
$e = new FailedException($e->getMessage(), 10005, $e);
}
return parent::render($request, $e); return parent::render($request, $e);
} }

View File

@@ -118,8 +118,8 @@ class CatchQuery extends Query
foreach ($params as $field => $value) { foreach ($params as $field => $value) {
$method = 'search' . Str::studly($field) . 'Attr'; $method = 'search' . Str::studly($field) . 'Attr';
if (method_exists($this->model, $method)) { if ($value && method_exists($this->model, $method)) {
$this->model->$method($this, $value ?? null, $params); $this->model->$method($this, $value, $params);
} }
} }

View File

@@ -45,6 +45,11 @@ class CatchUpload
*/ */
protected $path = ''; protected $path = '';
public function __construct()
{
$this->initDriver();
}
/** /**
* upload files * upload files
* *
@@ -77,10 +82,20 @@ class CatchUpload
throw new FailedException('Upload Failed, Try Again!'); throw new FailedException('Upload Failed, Try Again!');
} }
/**
* 本地路径
*
* @time 2020年09月07日
* @param $path
* @return string
*/
protected function getLocalPath($path) protected function getLocalPath($path)
{ {
if ($this->getDriver() === self::LOCAL) { if ($this->getDriver() === self::LOCAL) {
return str_replace(root_path('public'), '', \config('filesystem.disks.local.root')) . DIRECTORY_SEPARATOR .$path;
$path = str_replace(root_path('public'), '', \config('filesystem.disks.local.root')) . DIRECTORY_SEPARATOR .$path;
return str_replace('\\', '/', $path);
} }
return $path; return $path;
@@ -247,9 +262,19 @@ class CatchUpload
$disk = app()->config->get('filesystem.disks'); $disk = app()->config->get('filesystem.disks');
$uploadConfigs = $configModel->getConfig($upload->id); $uploadConfigs = $configModel->getConfig($upload->id);
// 重组
$_config = [];
if (!empty($uploadConfigs)) { if (!empty($uploadConfigs)) {
foreach ($uploadConfigs as $key => $value) {
list($object, $key) = explode('.', $key);
$_config[$object][$key] = $value;
}
}
if (!empty($_config)) {
// 读取上传可配置数据 // 读取上传可配置数据
foreach ($uploadConfigs as $key => &$config) { foreach ($_config as $key => &$config) {
// $disk[$key]['type'] = $key; // $disk[$key]['type'] = $key;
// 腾讯云配置处理 // 腾讯云配置处理
if (strtolower($key) == 'qcloud') { if (strtolower($key) == 'qcloud') {
@@ -258,21 +283,21 @@ class CatchUpload
'secretKey' => $config['secret_key'] ?? '', 'secretKey' => $config['secret_key'] ?? '',
'secretId' => $config['secret_id'] ?? '', 'secretId' => $config['secret_id'] ?? '',
]; ];
$readFromCdn = $config['read_from_cdn'] ?? false; $readFromCdn = $config['read_from_cdn'] ?? 0;
$config['read_from_cdn'] = $readFromCdn ? true : false; $config['read_from_cdn'] = intval($readFromCdn) == 1;
} }
// OSS 配置 // OSS 配置
if (strtolower($key) == 'oss') { if (strtolower($key) == 'oss') {
$isCname = $config['is_cname'] ?? false; $isCname = $config['is_cname'] ?? 0;
$config['is_cname'] = $isCname ? true : false; $config['is_cname'] = intval($isCname) == 1;
} }
} }
// 合并数组 // 合并数组
array_walk($disk, function (&$item, $key) use ($uploadConfigs) { array_walk($disk, function (&$item, $key) use ($_config) {
if (!in_array($key, ['public', 'local'])) { if (!in_array($key, ['public', 'local'])) {
if ($uploadConfigs[$key] ?? false) { if ($_config[$key] ?? false) {
foreach ($uploadConfigs[$key] as $k => $value) { foreach ($_config[$key] as $k => $value) {
$item[$k] = $value; $item[$k] = $value;
} }
} }
@@ -286,6 +311,21 @@ class CatchUpload
} }
} }
/**
* 初始化
*
* @time 2020年09月07日
* @return $this
*/
protected function initDriver()
{
if ($driver = Utils::config('site.upload')) {
$this->driver = $driver;
}
return $this;
}
/** /**
* 获取云存储的域名 * 获取云存储的域名
* *

View File

@@ -11,6 +11,7 @@ class Code
public const FAILED = 10005; // 操作失败 public const FAILED = 10005; // 操作失败
public const LOGIN_EXPIRED = 10006; // 登录失效 public const LOGIN_EXPIRED = 10006; // 登录失效
public const LOGIN_BLACKLIST = 10007; // 黑名单 public const LOGIN_BLACKLIST = 10007; // 黑名单
public const USER_FORBIDDEN = 10008; // 账户被禁
public const WECHAT_RESPONSE_ERROR = 40000; public const WECHAT_RESPONSE_ERROR = 40000;
} }

View File

@@ -1,6 +1,7 @@
<?php <?php
namespace catcher; namespace catcher;
use catchAdmin\system\model\Config;
use think\facade\Db; use think\facade\Db;
use think\helper\Str; use think\helper\Str;
@@ -129,4 +130,28 @@ class Utils
{ {
return request()->user()->id == config('catch.permissions.super_admin_id'); return request()->user()->id == config('catch.permissions.super_admin_id');
} }
/**
* 获取配置
*
* @time 2020年09月07日
* @param $key
* @return mixed
*/
public static function config($key)
{
return Config::where('key', $key)->value('value');
}
/**
* public path
*
* @param string $path
* @time 2020年09月08日
* @return string
*/
public static function publicPath($path = '')
{
return root_path($path ? 'public/'. $path : 'public');
}
} }

View File

@@ -86,7 +86,7 @@ class CatchRequest extends Request
// 设置默认参数 // 设置默认参数
if ($this->needCreatorId) { if ($this->needCreatorId) {
$this->param['creator_id'] = $this->user()->id; $this->param['creator_id'] = $this->user()->id;
$this->post['creator'] = $this->user()->id; $this->post['creator_id'] = $this->user()->id;
} }
return true; return true;

View File

@@ -30,7 +30,8 @@ class ExportDataCommand extends Command
protected function execute(Input $input, Output $output) protected function execute(Input $input, Output $output)
{ {
$table = Utils::tablePrefix() . $input->getArgument('table'); //$table = // Utils::tablePrefix() .
$table = $input->getArgument('table');
$parent = $input->getOption('pid'); $parent = $input->getOption('pid');
$module = $input->getOption('module'); $module = $input->getOption('module');
@@ -39,8 +40,12 @@ class ExportDataCommand extends Command
->where('module', $module) ->where('module', $module)
->select() ->select()
->toArray(); ->toArray();
} else { } else {
$data = Db::name($table)->where('deleted_at', 0)->select()->toArray(); $data = Db::name($table)->where('deleted_at', 0)
->select()
->toArray();
} }
if ($parent) { if ($parent) {
@@ -60,7 +65,11 @@ class ExportDataCommand extends Command
{ {
$stub = file_get_contents(dirname(__DIR__) . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'permissionSeed.stub'); $stub = file_get_contents(dirname(__DIR__) . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'permissionSeed.stub');
file_put_contents(CatchAdmin::moduleSeedsDirectory($module) . 'permissionSeed.php', str_replace('{DATA}', $data, $stub)); $class = ucfirst($module) . 'MenusSeed';
$stub = str_replace('{CLASS}', $class, $stub);
file_put_contents(CatchAdmin::moduleSeedsDirectory($module) . $class .'.php', str_replace('{DATA}', $data, $stub));
} }
} }

View File

@@ -12,6 +12,7 @@ namespace catcher\command\install;
use catchAdmin\permissions\model\Permissions; use catchAdmin\permissions\model\Permissions;
use catcher\CatchAdmin; use catcher\CatchAdmin;
use catcher\library\InstallLocalModule;
use think\console\Command; use think\console\Command;
use think\console\Input; use think\console\Input;
use think\console\input\Argument; use think\console\input\Argument;
@@ -34,10 +35,7 @@ class DisableModuleCommand extends Command
if (empty(CatchAdmin::getModuleInfo(CatchAdmin::directory() .$module))) { if (empty(CatchAdmin::getModuleInfo(CatchAdmin::directory() .$module))) {
$output->error("module [$module] not exist"); $output->error("module [$module] not exist");
} else { } else {
CatchAdmin::disableModule($module); (new InstallLocalModule($module))->disableModule();
Permissions::destroy(function ($query) use ($module){
$query->where('module', trim($module));
});
$output->info("module [$module] disabled"); $output->info("module [$module] disabled");
} }
} }

View File

@@ -12,6 +12,7 @@ namespace catcher\command\install;
use catchAdmin\permissions\model\Permissions; use catchAdmin\permissions\model\Permissions;
use catcher\CatchAdmin; use catcher\CatchAdmin;
use catcher\library\InstallLocalModule;
use think\console\Command; use think\console\Command;
use think\console\Input; use think\console\Input;
use think\console\input\Argument; use think\console\input\Argument;
@@ -33,8 +34,7 @@ class EnableModuleCommand extends Command
if (empty(CatchAdmin::getModuleInfo(CatchAdmin::directory() .$module))) { if (empty(CatchAdmin::getModuleInfo(CatchAdmin::directory() .$module))) {
$output->error("module [$module] not exist"); $output->error("module [$module] not exist");
} else { } else {
CatchAdmin::enableModule($module); (new InstallLocalModule($module))->enableModule();
app(Permissions::class)->restore(['module' => trim($module)]);
$output->info("module [$module] enabled"); $output->info("module [$module] enabled");
} }
} }

View File

@@ -0,0 +1,68 @@
<?php
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
// +----------------------------------------------------------------------
// | Author: JaguarJack [ njphper@gmail.com ]
// +----------------------------------------------------------------------
namespace catcher\command\install;
use catcher\library\InstallLocalModule;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;
class InstallLocalModuleCommand extends Command
{
protected function configure()
{
$this->setName('local:install')
->addArgument('module', Argument::REQUIRED, 'module name')
->setDescription('install catch local module');
}
protected function execute(Input $input, Output $output)
{
$installedModule = $input->getArgument('module');
$install = new InstallLocalModule($installedModule);
if (!$install->localModuleExist()) {
while (true) {
$modules = $install->getLocalModulesInfo(false);
if (!count($modules)) {
$output->error('Input module not found and All local modules had been enabled');exit;
}
$choose = '';
$i = 1;
foreach ($modules as $k => $module) {
$choose .= ($i++) . ':' . ($module['name']) . ($module['enable'] ? '(开启)' : '(未开启)') . PHP_EOL;
}
$answer = $output->ask($input, $choose);
if (isset($modules[$answer-1])) {
$installedModule = $modules[$answer - 1]['name'];
break;
}
}
}
$install = new InstallLocalModule($installedModule);
if (!$install->isModuleEnabled()) {
$output->error($installedModule . ' has been enabled!');
exit;
}
if (!$install->done()) {
$output->error(sprintf('module [%s] has been installed, You can use [php think enable:module $module] to start it.', $installedModule));
}
$output->info(sprintf('module [%s] installed successfully', $installedModule));
}
}

View File

@@ -2,6 +2,7 @@
namespace catcher\command\install; namespace catcher\command\install;
use catcher\CatchAdmin; use catcher\CatchAdmin;
use catcher\library\InstallLocalModule;
use think\console\Command; use think\console\Command;
use think\console\Input; use think\console\Input;
use think\console\input\Option; use think\console\input\Option;
@@ -13,6 +14,8 @@ class InstallProjectCommand extends Command
protected $databaseLink = []; protected $databaseLink = [];
protected $defaultModule = ['permissions', 'system'];
protected function configure() protected function configure()
{ {
$this->setName('catch:install') $this->setName('catch:install')
@@ -111,6 +114,12 @@ class InstallProjectCommand extends Command
return false; return false;
} }
// 设置 app domain
$appDomain = strtolower($this->output->ask($this->input, '👉 first, you should set app domain: '));
if (strpos('http://', $appDomain) === false || strpos('https://', $appDomain) === false) {
$appDomain = 'http://' . $appDomain;
}
$answer = strtolower($this->output->ask($this->input, '🤔️ Did You Need to Set Database information? (Y/N): ')); $answer = strtolower($this->output->ask($this->input, '🤔️ Did You Need to Set Database information? (Y/N): '));
if ($answer === 'y' || $answer === 'yes') { if ($answer === 'y' || $answer === 'yes') {
@@ -142,7 +151,7 @@ class InstallProjectCommand extends Command
$this->databaseLink = [$host, $database, $username, $password, $port, $charset, $prefix]; $this->databaseLink = [$host, $database, $username, $password, $port, $charset, $prefix];
$this->generateEnvFile($host, $database, $username, $password, $port, $charset, $prefix); $this->generateEnvFile($host, $database, $username, $password, $port, $charset, $prefix, $appDomain);
} }
} }
@@ -191,26 +200,27 @@ class InstallProjectCommand extends Command
*/ */
protected function migrateAndSeeds(): void protected function migrateAndSeeds(): void
{ {
foreach (CatchAdmin::getModulesDirectory() as $directory) {
$moduleInfo = CatchAdmin::getModuleInfo($directory);
if (!empty($moduleInfo) && is_dir(CatchAdmin::moduleMigrationsDirectory($moduleInfo['alias']))) {
$output = Console::call('catch-migrate:run', [$moduleInfo['alias']]);
$this->output->info(sprintf('module [%s] migrations %s', $moduleInfo['alias'], $output->fetch()));
$seedOut = Console::call('catch-seed:run', [$moduleInfo['alias']]); foreach ($this->defaultModule as $m) {
$this->output->info(sprintf('module [%s] seeds %s', $moduleInfo['alias'], $seedOut->fetch())); $module = new InstallLocalModule($m);
} $module->installModuleTables();
$module->installModuleSeeds();
$this->output->info('🎉 module [' . $m . '] installed successfully');
} }
} }
/**
* 回滚数据
*
* @time 2020年09月07日
* @return void
*/
protected function migrateRollback() protected function migrateRollback()
{ {
foreach (CatchAdmin::getModulesDirectory() as $directory) { foreach ($this->defaultModule as $m) {
$moduleInfo = CatchAdmin::getModuleInfo($directory); $module = new InstallLocalModule($m);
if (!empty($moduleInfo) && is_dir(CatchAdmin::moduleMigrationsDirectory($moduleInfo['alias']))) { $module->rollbackModuleTable();
$rollbackOut = Console::call('catch-migrate:rollback', [$moduleInfo['alias'], '-f']); $this->output->info('🎉' . $m . ' tables rollback successfully');
// $this->output->info(sprintf('module [%s] [%s] rollback %s', $moduleInfo['alias'], basename($migration), $rollbackOut->fetch()));
}
} }
} }
@@ -251,13 +261,15 @@ class InstallProjectCommand extends Command
* @param $port * @param $port
* @param $charset * @param $charset
* @param $prefix * @param $prefix
* @param $appDomain
* @return void * @return void
*/ */
protected function generateEnvFile($host, $database, $username, $password, $port, $charset, $prefix): void protected function generateEnvFile($host, $database, $username, $password, $port, $charset, $prefix, $appDomain): void
{ {
try { try {
$env = \parse_ini_file(root_path() . '.example.env', true); $env = \parse_ini_file(root_path() . '.example.env', true);
$env['APP']['DOMAIN'] = $appDomain;
$env['DATABASE']['HOSTNAME'] = $host; $env['DATABASE']['HOSTNAME'] = $host;
$env['DATABASE']['DATABASE'] = $database; $env['DATABASE']['DATABASE'] = $database;
$env['DATABASE']['USERNAME'] = $username; $env['DATABASE']['USERNAME'] = $username;

View File

@@ -2,7 +2,7 @@
use think\migration\Seeder; use think\migration\Seeder;
class PermissionSeed extends Seeder class {CLASS} extends Seeder
{ {
/** /**
* Run Method. * Run Method.

View File

@@ -55,7 +55,7 @@ class Generator
// 只有最后成功才写入 route // 只有最后成功才写入 route
(new Route())->controller($controller['controller']) (new Route())->controller($controller['controller'])
->restful($controller['restful']) ->restful($controller['restful'])
->methods((new Controller())->parseOtherMethods($controller['other_function'])) // ->methods((new Controller())->parseOtherMethods($controller['other_function']))
->done(); ->done();
} catch (\Exception $exception) { } catch (\Exception $exception) {
@@ -76,10 +76,10 @@ class Generator
*/ */
public function preview($params) public function preview($params)
{ {
$params = \json_decode($params['data'], true);
$type = $params['type']; $type = $params['type'];
$params = \json_decode($params['data'], true);
[$controller, $model] = $this->parseParams($params); [$controller, $model] = $this->parseParams($params);
switch ($type) { switch ($type) {
@@ -113,7 +113,7 @@ class Generator
'model' => $params['controller']['model'] ?? '', 'model' => $params['controller']['model'] ?? '',
'controller' => $params['controller']['controller'] ?? '', 'controller' => $params['controller']['controller'] ?? '',
'restful' => $params['controller']['restful'], 'restful' => $params['controller']['restful'],
'other_function' => $params['controller']['other_function'], // 'other_function' => $params['controller']['other_function'],
]; ];
$table = $params['controller']['table'] ?? ''; $table = $params['controller']['table'] ?? '';
@@ -124,8 +124,8 @@ class Generator
$model = [ $model = [
'table' => $table, 'table' => $table,
'model' => $params['controller']['model'] ?? '', 'model' => $params['controller']['model'] ?? '',
'sql' => $params['model']['data'], 'sql' => $params['table_fields'],
'extra' => $params['model']['extra'], 'extra' => $params['table_extra'],
]; ];

View File

@@ -92,13 +92,14 @@ class Controller extends Factory
} }
} }
/**
if (!empty($params['other_function'])) { if (!empty($params['other_function'])) {
$others = $this->parseOtherMethods($params['other_function']); $others = $this->parseOtherMethods($params['other_function']);
$this->methods = array_merge($this->methods, $others); $this->methods = array_merge($this->methods, $others);
foreach ($others as $other) { foreach ($others as $other) {
$content .= $template->otherFunction($other[0], $other[1]); $content .= $template->otherFunction($other[0], $other[1]);
} }
} }*/
return $content; return $content;
} }

View File

@@ -0,0 +1,177 @@
<?php
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
// +----------------------------------------------------------------------
// | Author: JaguarJack [ njphper@gmail.com ]
// +----------------------------------------------------------------------
namespace catcher\library;
use catchAdmin\permissions\model\Permissions;
use catcher\CatchAdmin;
use think\facade\Console;
class InstallLocalModule
{
protected $module;
public function __construct($module)
{
$this->module = $module;
}
/**
* 查找
*
* @time 2020年09月10日
* @return bool
*/
public function done()
{
if ($this->findModuleInPermissions()) {
return false;
} else {
$this->installModuleTables();
$this->installModuleSeeds();
$this->enableModule();
return true;
}
}
/**
* 本地模块是否存在
*
* @time 2020年09月10日
* @return bool
*/
public function localModuleExist()
{
return in_array($this->module, array_column(CatchAdmin::getModulesInfo(true), 'value'));
}
/**
* 模块是否开启
*
* @time 2020年09月10日
* @return false|mixed
*/
public function isModuleEnabled()
{
return in_array($this->module, array_column($this->getLocalModulesInfo(false), 'name'));
}
/**
* 获取本地模块信息
*
* @param bool $enabled
* @time 2020年09月10日
* @return array
*/
public function getLocalModulesInfo($enabled = true)
{
$modules = CatchAdmin::getModulesInfo(true);
$info = [];
foreach ($modules as $module) {
$moduleInfo = CatchAdmin::getModuleInfo(CatchAdmin::directory() . $module['value']);
// 获取全部
if ($enabled) {
$info[] = [
'name' => $module['value'],
'title' => $module['title'],
'enable' => $moduleInfo['enable'],
];
} else {
// 获取未开启的
if (!$moduleInfo['enable']) {
$info[] = [
'name' => $module['value'],
'title' => $module['title'],
'enable' => $moduleInfo['enable'],
];
}
}
}
return $info;
}
/**
* 查找模块
*
* @time 2020年09月10日
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @return bool
*/
protected function findModuleInPermissions()
{
return Permissions::where('module', $this->module)->find() ? true : false;
}
/**
* 启用模块
*
* @time 2020年09月10日
* @return void
*/
public function enableModule()
{
CatchAdmin::enableModule($this->module);
app(Permissions::class)->restore(['module' => trim($this->module)]);
}
/**
* 禁用模块
*
* @time 2020年09月10日
* @return void
*/
public function disableModule()
{
CatchAdmin::disableModule($this->module);
Permissions::destroy(function ($query) {
$query->where('module', trim($this->module));
});
}
/**
* 创建模块表
*
* @time 2020年09月10日
* @return void
*/
public function installModuleTables()
{
Console::call('catch-migrate:run', [$this->module]);
}
/**
* 初始化模块数据
*
* @time 2020年09月10日
* @return void
*/
public function installModuleSeeds()
{
Console::call('catch-seed:run', [$this->module]);
}
/**
* 回滚模块表
*
* @time 2020年09月10日
* @return void
*/
public function rollbackModuleTable()
{
Console::call('catch-migrate:rollback', [$this->module, '-f']);
}
}

View File

@@ -2,6 +2,8 @@
namespace catcher\library; namespace catcher\library;
use think\exception\ClassNotFoundException;
class ParseClass class ParseClass
{ {
protected $namespace; protected $namespace;
@@ -74,18 +76,23 @@ class ParseClass
return $methods; return $methods;
} }
/** /**
* 获取 CLASS * 获取class
* *
* @return \ReflectionClass * @time 2020年09月06日
* @throws \ReflectionException * @throws \ReflectionException
* @return \ReflectionClass
*/ */
public function getClass() public function getClass()
{ {
$class = $this->namespace . $this->module . '\\controller\\'. ucfirst($this->controller);
return new \ReflectionClass($this->namespace . $this->module . '\\controller\\'. if (class_exists($class)) {
return new \ReflectionClass($class);
}
ucfirst($this->controller)); throw new ClassNotFoundException($this->controller . ' not found');
} }
/** /**

View File

@@ -3,10 +3,12 @@ namespace catcher\library\excel;
use catcher\CatchUpload; use catcher\CatchUpload;
use catcher\exceptions\FailedException; use catcher\exceptions\FailedException;
use catcher\Utils;
use PhpOffice\PhpSpreadsheet\Exception; use PhpOffice\PhpSpreadsheet\Exception;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
use think\file\UploadedFile; use think\file\UploadedFile;
use think\helper\Str;
class Excel class Excel
{ {
@@ -21,35 +23,54 @@ class Excel
protected $spreadsheet = null; protected $spreadsheet = null;
protected $extension = 'xlsx';
/** /**
* save * save
* *
* @time 2020年05月25日 * @time 2020年05月25日
* @param ExcelContract $excel * @param ExcelContract $excel
* @param $path * @param $path
* @param null $disk * @param string $disk
* @return bool * @return mixed
* @throws Exception * @throws Exception
*/ */
public function save(ExcelContract $excel, $path, $disk = null) public function save(ExcelContract $excel, $path, $disk = 'local')
{ {
$this->excel = $excel; $this->excel = $excel;
$this->init(); $this->init();
Factory::make(pathinfo($path, PATHINFO_EXTENSION)) !is_dir($path) && mkdir($path, 0777, true);
->setSpreadsheet($this->spreadsheet)
->save($path);
if (!file_exists($path)) { $file = $path . date('YmdHis').Str::random(6) . '.' .$this->extension;
throw new FailedException($path . ' generate failed'); Factory::make($this->extension)
->setSpreadsheet($this->spreadsheet)
->save($file);
if (!file_exists($file)) {
throw new FailedException($file . ' generate failed');
} }
if ($disk) { if ($disk) {
$path = $this->upload($disk, $path); $file = $this->upload($disk, $file);
} }
return $path; return ['url' => $file];
}
/**
* set extension
*
* @time 2020年09月08日
* @param $extension
* @return $this
*/
public function setExtension($extension)
{
$this->extension = $extension;
return $this;
} }
/** /**
@@ -219,11 +240,27 @@ class Excel
*/ */
protected function upload($disk, $path) protected function upload($disk, $path)
{ {
if ($disk == 'local') {
return $this->local($path);
}
$upload = new CatchUpload; $upload = new CatchUpload;
return ($disk ? $upload->setDriver($disk) : $upload)->upload($this->uploadedFile($path)); return ($disk ? $upload->setDriver($disk) : $upload)->upload($this->uploadedFile($path));
} }
/**
* 返回本地下载地址
*
* @param $path
* @time 2020年09月08日
* @return mixed
*/
protected function local($path)
{
return \config('filesystem.disks.local')['domain'] . '/' .
str_replace('\\', '/', str_replace(Utils::publicPath(), '', $path));
}
/** /**
* get uploaded file * get uploaded file

View File

@@ -1,4 +1,14 @@
<?php <?php
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
// +----------------------------------------------------------------------
// | Author: JaguarJack [ njphper@gmail.com ]
// +----------------------------------------------------------------------
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | CatchAdmin [Just Like ] // | CatchAdmin [Just Like ]
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------