Repository: saithink/saiadmin Branch: 6.x Commit: bce3cc48ba27 Files: 232 Total size: 801.9 KB Directory structure: gitextract_4k9f2lks/ ├── LICENSE ├── README.md ├── composer.json └── src/ ├── Install.php ├── orm/ │ ├── eloquent/ │ │ └── app/ │ │ ├── logic/ │ │ │ ├── system/ │ │ │ │ ├── DatabaseLogic.php │ │ │ │ ├── SystemAttachmentLogic.php │ │ │ │ ├── SystemCategoryLogic.php │ │ │ │ ├── SystemConfigGroupLogic.php │ │ │ │ ├── SystemConfigLogic.php │ │ │ │ ├── SystemDeptLogic.php │ │ │ │ ├── SystemDictDataLogic.php │ │ │ │ ├── SystemDictTypeLogic.php │ │ │ │ ├── SystemLoginLogLogic.php │ │ │ │ ├── SystemMailLogic.php │ │ │ │ ├── SystemMenuLogic.php │ │ │ │ ├── SystemOperLogLogic.php │ │ │ │ ├── SystemPostLogic.php │ │ │ │ ├── SystemRoleLogic.php │ │ │ │ └── SystemUserLogic.php │ │ │ └── tool/ │ │ │ ├── CrontabLogLogic.php │ │ │ ├── CrontabLogic.php │ │ │ ├── GenerateColumnsLogic.php │ │ │ └── GenerateTablesLogic.php │ │ └── model/ │ │ ├── system/ │ │ │ ├── SystemAttachment.php │ │ │ ├── SystemCategory.php │ │ │ ├── SystemConfig.php │ │ │ ├── SystemConfigGroup.php │ │ │ ├── SystemDept.php │ │ │ ├── SystemDictData.php │ │ │ ├── SystemDictType.php │ │ │ ├── SystemLoginLog.php │ │ │ ├── SystemMail.php │ │ │ ├── SystemMenu.php │ │ │ ├── SystemOperLog.php │ │ │ ├── SystemPost.php │ │ │ ├── SystemRole.php │ │ │ ├── SystemRoleDept.php │ │ │ ├── SystemRoleMenu.php │ │ │ ├── SystemUser.php │ │ │ ├── SystemUserPost.php │ │ │ └── SystemUserRole.php │ │ └── tool/ │ │ ├── Crontab.php │ │ ├── CrontabLog.php │ │ ├── GenerateColumns.php │ │ └── GenerateTables.php │ └── think/ │ └── app/ │ ├── logic/ │ │ ├── system/ │ │ │ ├── DatabaseLogic.php │ │ │ ├── SystemAttachmentLogic.php │ │ │ ├── SystemCategoryLogic.php │ │ │ ├── SystemConfigGroupLogic.php │ │ │ ├── SystemConfigLogic.php │ │ │ ├── SystemDeptLogic.php │ │ │ ├── SystemDictDataLogic.php │ │ │ ├── SystemDictTypeLogic.php │ │ │ ├── SystemLoginLogLogic.php │ │ │ ├── SystemMailLogic.php │ │ │ ├── SystemMenuLogic.php │ │ │ ├── SystemOperLogLogic.php │ │ │ ├── SystemPostLogic.php │ │ │ ├── SystemRoleLogic.php │ │ │ └── SystemUserLogic.php │ │ └── tool/ │ │ ├── CrontabLogLogic.php │ │ ├── CrontabLogic.php │ │ ├── GenerateColumnsLogic.php │ │ └── GenerateTablesLogic.php │ └── model/ │ ├── system/ │ │ ├── SystemAttachment.php │ │ ├── SystemCategory.php │ │ ├── SystemConfig.php │ │ ├── SystemConfigGroup.php │ │ ├── SystemDept.php │ │ ├── SystemDictData.php │ │ ├── SystemDictType.php │ │ ├── SystemLoginLog.php │ │ ├── SystemMail.php │ │ ├── SystemMenu.php │ │ ├── SystemOperLog.php │ │ ├── SystemPost.php │ │ ├── SystemRole.php │ │ ├── SystemRoleDept.php │ │ ├── SystemRoleMenu.php │ │ ├── SystemUser.php │ │ ├── SystemUserPost.php │ │ └── SystemUserRole.php │ └── tool/ │ ├── Crontab.php │ ├── CrontabLog.php │ ├── GenerateColumns.php │ └── GenerateTables.php └── plugin/ └── saiadmin/ ├── app/ │ ├── cache/ │ │ ├── ConfigCache.php │ │ ├── DictCache.php │ │ ├── ReflectionCache.php │ │ ├── UserAuthCache.php │ │ ├── UserInfoCache.php │ │ └── UserMenuCache.php │ ├── controller/ │ │ ├── InstallController.php │ │ ├── LoginController.php │ │ ├── SystemController.php │ │ ├── system/ │ │ │ ├── DataBaseController.php │ │ │ ├── SystemAttachmentController.php │ │ │ ├── SystemCategoryController.php │ │ │ ├── SystemConfigController.php │ │ │ ├── SystemConfigGroupController.php │ │ │ ├── SystemDeptController.php │ │ │ ├── SystemDictDataController.php │ │ │ ├── SystemDictTypeController.php │ │ │ ├── SystemLogController.php │ │ │ ├── SystemMailController.php │ │ │ ├── SystemMenuController.php │ │ │ ├── SystemPostController.php │ │ │ ├── SystemRoleController.php │ │ │ ├── SystemServerController.php │ │ │ └── SystemUserController.php │ │ └── tool/ │ │ ├── CrontabController.php │ │ └── GenerateTablesController.php │ ├── event/ │ │ └── SystemUser.php │ ├── exception/ │ │ └── Handler.php │ ├── functions.php │ ├── logic/ │ │ ├── system/ │ │ │ ├── DatabaseLogic.php │ │ │ ├── SystemAttachmentLogic.php │ │ │ ├── SystemCategoryLogic.php │ │ │ ├── SystemConfigGroupLogic.php │ │ │ ├── SystemConfigLogic.php │ │ │ ├── SystemDeptLogic.php │ │ │ ├── SystemDictDataLogic.php │ │ │ ├── SystemDictTypeLogic.php │ │ │ ├── SystemLoginLogLogic.php │ │ │ ├── SystemMailLogic.php │ │ │ ├── SystemMenuLogic.php │ │ │ ├── SystemOperLogLogic.php │ │ │ ├── SystemPostLogic.php │ │ │ ├── SystemRoleLogic.php │ │ │ └── SystemUserLogic.php │ │ └── tool/ │ │ ├── CrontabLogLogic.php │ │ ├── CrontabLogic.php │ │ ├── GenerateColumnsLogic.php │ │ └── GenerateTablesLogic.php │ ├── middleware/ │ │ ├── CheckAuth.php │ │ ├── CheckLogin.php │ │ ├── CrossDomain.php │ │ └── SystemLog.php │ ├── model/ │ │ ├── system/ │ │ │ ├── SystemAttachment.php │ │ │ ├── SystemCategory.php │ │ │ ├── SystemConfig.php │ │ │ ├── SystemConfigGroup.php │ │ │ ├── SystemDept.php │ │ │ ├── SystemDictData.php │ │ │ ├── SystemDictType.php │ │ │ ├── SystemLoginLog.php │ │ │ ├── SystemMail.php │ │ │ ├── SystemMenu.php │ │ │ ├── SystemOperLog.php │ │ │ ├── SystemPost.php │ │ │ ├── SystemRole.php │ │ │ ├── SystemRoleDept.php │ │ │ ├── SystemRoleMenu.php │ │ │ ├── SystemUser.php │ │ │ ├── SystemUserPost.php │ │ │ └── SystemUserRole.php │ │ └── tool/ │ │ ├── Crontab.php │ │ ├── CrontabLog.php │ │ ├── GenerateColumns.php │ │ └── GenerateTables.php │ ├── validate/ │ │ ├── system/ │ │ │ ├── SystemCategoryValidate.php │ │ │ ├── SystemConfigGroupValidate.php │ │ │ ├── SystemConfigValidate.php │ │ │ ├── SystemCrontabValidate.php │ │ │ ├── SystemDeptValidate.php │ │ │ ├── SystemDictDataValidate.php │ │ │ ├── SystemDictTypeValidate.php │ │ │ ├── SystemMailValidate.php │ │ │ ├── SystemMenuValidate.php │ │ │ ├── SystemNoticeValidate.php │ │ │ ├── SystemPostValidate.php │ │ │ ├── SystemRoleValidate.php │ │ │ └── SystemUserValidate.php │ │ └── tool/ │ │ ├── CrontabValidate.php │ │ └── GenerateTablesValidate.php │ └── view/ │ └── install/ │ ├── error.html │ └── index.html ├── basic/ │ ├── AbstractLogic.php │ ├── BaseController.php │ ├── BaseValidate.php │ ├── OpenController.php │ ├── contracts/ │ │ ├── LogicInterface.php │ │ └── ModelInterface.php │ ├── eloquent/ │ │ ├── BaseLogic.php │ │ └── BaseModel.php │ └── think/ │ ├── BaseLogic.php │ └── BaseModel.php ├── command/ │ ├── SaiOrm.php │ ├── SaiPlugin.php │ └── SaiUpgrade.php ├── config/ │ ├── app.php │ ├── autoload.php │ ├── container.php │ ├── database.php │ ├── event.php │ ├── exception.php │ ├── log.php │ ├── middleware.php │ ├── process.php │ ├── route.php │ ├── saithink.php │ ├── static.php │ ├── translation.php │ └── view.php ├── db/ │ ├── plugin.sql │ ├── saiadmin-6.0.sql │ └── saiadmin-pure.sql ├── exception/ │ ├── ApiException.php │ └── SystemException.php ├── process/ │ ├── Task.php │ └── Test.php ├── public/ │ └── template/ │ └── template.xlsx ├── service/ │ ├── EmailService.php │ ├── OpenSpoutWriter.php │ ├── Permission.php │ └── storage/ │ ├── ChunkUploadService.php │ └── UploadService.php └── utils/ ├── Arr.php ├── Captcha.php ├── Helper.php ├── ServerMonitor.php └── code/ ├── CodeEngine.php ├── CodeZip.php └── stub/ └── saiadmin/ ├── php/ │ ├── controller.stub │ ├── logic.stub │ ├── model.stub │ └── validate.stub ├── sql/ │ └── sql.stub ├── ts/ │ └── api.stub └── vue/ ├── edit-dialog.stub ├── index.stub └── table-search.stub ================================================ FILE CONTENTS ================================================ ================================================ FILE: LICENSE ================================================ MIT License Copyright (c) 2024 saithink Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================
演示地址: http://v6.saithink.top
演示账号:admin
演示密码:123456
saiadmin交流群(添加我微信备注"saiadmin") |
|
|
这是一封测试邮件,请忽略
"; $template = [ 'code' => $code ]; $config = EmailService::getConfig(); $model = SystemMail::create([ 'gateway' => Arr::getConfigValue($config,'Host'), 'from' => Arr::getConfigValue($config,'From'), 'email' => $email, 'code' => $code, ]); try { $result = EmailService::sendByTemplate($email, $subject, $content, $template); if (!empty($result)) { $model->status = 'failure'; $model->response = $result; $model->save(); return $this->fail('发送失败,请查看日志'); } else { $model->status = 'success'; $model->save(); return $this->success([], '发送成功'); } } catch (\Exception $e) { $model->status = 'failure'; $model->response = $e->getMessage(); $model->save(); return $this->fail($e->getMessage()); } } } ================================================ FILE: src/plugin/saiadmin/app/controller/system/SystemDeptController.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\controller\system; use plugin\saiadmin\app\validate\system\SystemDeptValidate; use plugin\saiadmin\basic\BaseController; use plugin\saiadmin\app\logic\system\SystemDeptLogic; use plugin\saiadmin\service\Permission; use support\Request; use support\Response; /** * 部门控制器 */ class SystemDeptController extends BaseController { /** * 构造 */ public function __construct() { $this->logic = new SystemDeptLogic(); $this->validate = new SystemDeptValidate; parent::__construct(); } /** * 数据列表 * @param Request $request * @return Response */ #[Permission('部门数据列表', 'core:dept:index')] public function index(Request $request) : Response { $where = $request->more([ ['name', ''], ['code', ''], ['status', ''], ]); $data = $this->logic->tree($where); return $this->success($data); } /** * 读取数据 * @param Request $request * @return Response */ #[Permission('部门数据读取', 'core:dept:read')] public function read(Request $request) : Response { $id = $request->input('id', ''); $model = $this->logic->read($id); if ($model) { $data = is_array($model) ? $model : $model->toArray(); return $this->success($data); } else { return $this->fail('未查找到信息'); } } /** * 保存数据 * @param Request $request * @return Response */ #[Permission('部门数据添加', 'core:dept:save')] public function save(Request $request): Response { $data = $request->post(); $this->validate('save', $data); $result = $this->logic->add($data); if ($result) { return $this->success('添加成功'); } else { return $this->fail('添加失败'); } } /** * 更新数据 * @param Request $request * @return Response */ #[Permission('部门数据修改','core:dept:update')] public function update(Request $request): Response { $data = $request->post(); $this->validate('update', $data); $result = $this->logic->edit($data['id'], $data); if ($result) { return $this->success('修改成功'); } else { return $this->fail('修改失败'); } } /** * 删除数据 * @param Request $request * @return Response */ #[Permission('部门数据删除','core:dept:destroy')] public function destroy(Request $request) : Response { $ids = $request->post('ids', ''); if (empty($ids)) { return $this->fail('请选择要删除的数据'); } $result = $this->logic->destroy($ids); if ($result) { return $this->success('删除成功'); } else { return $this->fail('删除失败'); } } /** * 可操作部门 * @param Request $request * @return Response */ public function accessDept(Request $request) : Response { $where = ['status' => 1]; $data = $this->logic->accessDept($where); return $this->success($data); } } ================================================ FILE: src/plugin/saiadmin/app/controller/system/SystemDictDataController.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\controller\system; use plugin\saiadmin\app\cache\DictCache; use plugin\saiadmin\basic\BaseController; use plugin\saiadmin\app\logic\system\SystemDictDataLogic; use plugin\saiadmin\app\validate\system\SystemDictDataValidate; use plugin\saiadmin\service\Permission; use support\Request; use support\Response; /** * 字典数据控制器 */ class SystemDictDataController extends BaseController { /** * 构造 */ public function __construct() { $this->logic = new SystemDictDataLogic(); $this->validate = new SystemDictDataValidate; parent::__construct(); } /** * 数据列表 * @param Request $request * @return Response */ #[Permission('数据字典列表', 'core:dict:index')] public function index(Request $request): Response { $where = $request->more([ ['label', ''], ['value', ''], ['type_id', ''], ['status', ''], ]); $this->logic->setOrderField('sort'); $this->logic->setOrderType('desc'); $query = $this->logic->search($where); $data = $this->logic->getList($query); return $this->success($data); } /** * 保存数据 * @param Request $request * @return Response */ #[Permission('数据字典管理', 'core:dict:edit')] public function save(Request $request): Response { $data = $request->post(); $this->validate('save', $data); $result = $this->logic->add($data); if ($result) { DictCache::clear(); return $this->success('添加成功'); } else { return $this->fail('添加失败'); } } /** * 更新数据 * @param Request $request * @return Response */ #[Permission('数据字典管理', 'core:dict:edit')] public function update(Request $request): Response { $data = $request->post(); $this->validate('update', $data); $result = $this->logic->edit($data['id'], $data); if ($result) { DictCache::clear(); return $this->success('修改成功'); } else { return $this->fail('修改失败'); } } /** * 删除数据 * @param Request $request * @return Response */ #[Permission('数据字典管理', 'core:dict:edit')] public function destroy(Request $request): Response { $ids = $request->post('ids', ''); if (empty($ids)) { return $this->fail('请选择要删除的数据'); } $result = $this->logic->destroy($ids); if ($result) { DictCache::clear(); return $this->success('删除成功'); } else { return $this->fail('删除失败'); } } } ================================================ FILE: src/plugin/saiadmin/app/controller/system/SystemDictTypeController.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\controller\system; use plugin\saiadmin\app\cache\DictCache; use plugin\saiadmin\basic\BaseController; use plugin\saiadmin\app\logic\system\SystemDictTypeLogic; use plugin\saiadmin\app\validate\system\SystemDictTypeValidate; use plugin\saiadmin\service\Permission; use support\Cache; use support\Request; use support\Response; /** * 字典类型控制器 */ class SystemDictTypeController extends BaseController { /** * 构造 */ public function __construct() { $this->logic = new SystemDictTypeLogic(); $this->validate = new SystemDictTypeValidate; parent::__construct(); } /** * 数据列表 * @param Request $request * @return Response */ #[Permission('数据字典列表', 'core:dict:index')] public function index(Request $request) : Response { $where = $request->more([ ['name', ''], ['code', ''], ['status', ''], ]); $query = $this->logic->search($where); $data = $this->logic->getList($query); return $this->success($data); } /** * 保存数据 * @param Request $request * @return Response */ #[Permission('数据字典管理', 'core:dict:edit')] public function save(Request $request): Response { $data = $request->post(); $this->validate('save', $data); $result = $this->logic->add($data); if ($result) { DictCache::clear(); return $this->success('添加成功'); } else { return $this->fail('添加失败'); } } /** * 更新数据 * @param Request $request * @return Response */ #[Permission('数据字典管理', 'core:dict:edit')] public function update(Request $request): Response { $data = $request->post(); $this->validate('update', $data); $result = $this->logic->edit($data['id'], $data); if ($result) { DictCache::clear(); return $this->success('修改成功'); } else { return $this->fail('修改失败'); } } /** * 删除数据 * @param Request $request * @return Response */ #[Permission('数据字典管理', 'core:dict:edit')] public function destroy(Request $request) : Response { $ids = $request->post('ids', ''); if (empty($ids)) { return $this->fail('请选择要删除的数据'); } $result = $this->logic->destroy($ids); if ($result) { DictCache::clear(); return $this->success('删除成功'); } else { return $this->fail('删除失败'); } } } ================================================ FILE: src/plugin/saiadmin/app/controller/system/SystemLogController.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\controller\system; use plugin\saiadmin\basic\BaseController; use plugin\saiadmin\app\logic\system\SystemLoginLogLogic; use plugin\saiadmin\app\logic\system\SystemOperLogLogic; use plugin\saiadmin\service\Permission; use support\Request; use support\Response; /** * 日志控制器 */ class SystemLogController extends BaseController { /** * 登录日志列表 * @param Request $request * @return Response */ #[Permission('登录日志列表', 'core:logs:login')] public function getLoginLogPageList(Request $request) : Response { $where = $request->more([ ['login_time', ''], ['username', ''], ['status', ''], ['ip', ''], ]); $logic = new SystemLoginLogLogic(); $query = $logic->search($where); $data = $logic->getList($query); return $this->success($data); } /** * 删除登录日志 * @param Request $request * @return Response */ #[Permission('登录日志删除', 'core:logs:deleteLogin')] public function deleteLoginLog(Request $request) : Response { $ids = $request->input('ids', ''); $logic = new SystemLoginLogLogic(); if (!empty($ids)) { $logic->destroy($ids); return $this->success('删除成功'); } else { return $this->fail('参数错误,请检查'); } } /** * 操作日志列表 * @param Request $request * @return Response */ #[Permission('操作日志列表', 'core:logs:Oper')] public function getOperLogPageList(Request $request) : Response { $where = $request->more([ ['create_time', ''], ['username', ''], ['service_name', ''], ['router', ''], ['ip', ''], ]); $logic = new SystemOperLogLogic(); $logic->init($this->adminInfo); $query = $logic->search($where); $data = $logic->getList($query); return $this->success($data); } /** * 删除操作日志 * @param Request $request * @return Response */ #[Permission('操作日志删除', 'core:logs:deleteOper')] public function deleteOperLog(Request $request) : Response { $ids = $request->input('ids', ''); $logic = new SystemOperLogLogic(); if (!empty($ids)) { $logic->destroy($ids); return $this->success('删除成功'); } else { return $this->fail('参数错误,请检查'); } } } ================================================ FILE: src/plugin/saiadmin/app/controller/system/SystemMailController.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\controller\system; use plugin\saiadmin\service\Permission; use plugin\saiadmin\basic\BaseController; use plugin\saiadmin\app\logic\system\SystemMailLogic; use plugin\saiadmin\app\validate\system\SystemMailValidate; use support\Request; use support\Response; /** * 邮件记录控制器 */ class SystemMailController extends BaseController { /** * 构造 */ public function __construct() { $this->logic = new SystemMailLogic(); $this->validate = new SystemMailValidate; parent::__construct(); } /** * 数据列表 * @param Request $request * @return Response */ #[Permission('邮件日志列表', 'core:email:index')] public function index(Request $request): Response { $where = $request->more([ ['gateway', ''], ['from', ''], ['code', ''], ['email', ''], ['status', ''], ['create_time', ''], ]); $query = $this->logic->search($where); $data = $this->logic->getList($query); return $this->success($data); } /** * 删除数据 * @param Request $request * @return Response */ #[Permission('邮件日志删除', 'core:email:destroy')] public function destroy(Request $request) : Response { $ids = $request->post('ids', ''); if (empty($ids)) { return $this->fail('请选择要删除的数据'); } $result = $this->logic->destroy($ids); if ($result) { return $this->success('删除成功'); } else { return $this->fail('删除失败'); } } } ================================================ FILE: src/plugin/saiadmin/app/controller/system/SystemMenuController.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\controller\system; use plugin\saiadmin\app\cache\UserMenuCache; use plugin\saiadmin\basic\BaseController; use plugin\saiadmin\app\logic\system\SystemMenuLogic; use plugin\saiadmin\app\validate\system\SystemMenuValidate; use plugin\saiadmin\service\Permission; use support\Request; use support\Response; /** * 菜单控制器 */ class SystemMenuController extends BaseController { /** * 构造 */ public function __construct() { $this->logic = new SystemMenuLogic(); $this->validate = new SystemMenuValidate; parent::__construct(); } /** * 数据列表 * @param Request $request * @return Response */ #[Permission('菜单数据列表', 'core:menu:index')] public function index(Request $request): Response { $where = $request->more([ ['name', ''], ['path', ''], ['menu', ''], ['status', ''], ]); $data = $this->logic->tree($where); return $this->success($data); } /** * 读取数据 * @param Request $request * @return Response */ #[Permission('菜单数据读取', 'core:menu:read')] public function read(Request $request): Response { $id = $request->input('id', ''); $model = $this->logic->read($id); if ($model) { $data = is_array($model) ? $model : $model->toArray(); return $this->success($data); } else { return $this->fail('未查找到信息'); } } /** * 保存数据 * @param Request $request * @return Response */ #[Permission('菜单数据添加', 'core:menu:save')] public function save(Request $request): Response { $data = $request->post(); $this->validate('save', $data); $result = $this->logic->add($data); if ($result) { UserMenuCache::clearMenuCache(); return $this->success('添加成功'); } else { return $this->fail('添加失败'); } } /** * 更新数据 * @param Request $request * @return Response */ #[Permission('菜单数据修改', 'core:menu:update')] public function update(Request $request): Response { $data = $request->post(); $this->validate('update', $data); $result = $this->logic->edit($data['id'], $data); if ($result) { UserMenuCache::clearMenuCache(); return $this->success('修改成功'); } else { return $this->fail('修改失败'); } } /** * 删除数据 * @param Request $request * @return Response */ #[Permission('菜单数据删除', 'core:menu:destroy')] public function destroy(Request $request): Response { $ids = $request->post('ids', ''); if (empty($ids)) { return $this->fail('请选择要删除的数据'); } $result = $this->logic->destroy($ids); if ($result) { UserMenuCache::clearMenuCache(); return $this->success('删除成功'); } else { return $this->fail('删除失败'); } } /** * 可操作菜单 * @param Request $request * @return Response */ public function accessMenu(Request $request): Response { $where = []; if ($this->adminId > 1) { $data = $this->logic->auth(); } else { $data = $this->logic->tree($where); } return $this->success($data); } } ================================================ FILE: src/plugin/saiadmin/app/controller/system/SystemPostController.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\controller\system; use plugin\saiadmin\basic\BaseController; use plugin\saiadmin\app\logic\system\SystemPostLogic; use plugin\saiadmin\app\validate\system\SystemPostValidate; use plugin\saiadmin\service\Permission; use support\Request; use support\Response; /** * 岗位信息控制器 */ class SystemPostController extends BaseController { /** * 构造 */ public function __construct() { $this->logic = new SystemPostLogic(); $this->validate = new SystemPostValidate; parent::__construct(); } /** * 数据列表 * @param Request $request * @return Response */ #[Permission('岗位数据列表', 'core:post:index')] public function index(Request $request): Response { $where = $request->more([ ['name', ''], ['code', ''], ['status', ''], ]); $query = $this->logic->search($where); $data = $this->logic->getList($query); return $this->success($data); } /** * 读取数据 * @param Request $request * @return Response */ #[Permission('岗位数据读取', 'core:post:read')] public function read(Request $request): Response { $id = $request->input('id', ''); $model = $this->logic->read($id); if ($model) { $data = is_array($model) ? $model : $model->toArray(); return $this->success($data); } else { return $this->fail('未查找到信息'); } } /** * 保存数据 * @param Request $request * @return Response */ #[Permission('岗位数据添加', 'core:post:save')] public function save(Request $request): Response { $data = $request->post(); $this->validate('save', $data); $result = $this->logic->add($data); if ($result) { return $this->success('添加成功'); } else { return $this->fail('添加失败'); } } /** * 更新数据 * @param Request $request * @return Response */ #[Permission('岗位数据修改', 'core:post:update')] public function update(Request $request): Response { $data = $request->post(); $this->validate('update', $data); $result = $this->logic->edit($data['id'], $data); if ($result) { return $this->success('修改成功'); } else { return $this->fail('修改失败'); } } /** * 删除数据 * @param Request $request * @return Response */ #[Permission('岗位数据删除', 'core:post:destroy')] public function destroy(Request $request): Response { $ids = $request->post('ids', ''); if (empty($ids)) { return $this->fail('请选择要删除的数据'); } $result = $this->logic->destroy($ids); if ($result) { return $this->success('删除成功'); } else { return $this->fail('删除失败'); } } /** * 导入数据 * @param Request $request * @return Response */ #[Permission('岗位数据导入', 'core:post:import')] public function import(Request $request): Response { $file = current($request->file()); if (!$file || !$file->isValid()) { return $this->fail('未找到上传文件'); } $this->logic->import($file); return $this->success('导入成功'); } /** * 导出数据 * @param Request $request * @return Response */ #[Permission('岗位数据导出', 'core:post:export')] public function export(Request $request): Response { $where = $request->more([ ['name', ''], ['code', ''], ['status', ''], ]); return $this->logic->export($where); } /** * 下载导入模板 * @return Response */ public function downloadTemplate(): Response { $file_name = "template.xlsx"; return downloadFile($file_name); } /** * 可操作岗位 * @param Request $request * @return Response */ public function accessPost(Request $request): Response { $where = ['status' => 1]; $data = $this->logic->accessPost($where); return $this->success($data); } } ================================================ FILE: src/plugin/saiadmin/app/controller/system/SystemRoleController.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\controller\system; use plugin\saiadmin\app\model\system\SystemUserRole; use plugin\saiadmin\basic\BaseController; use plugin\saiadmin\app\cache\UserInfoCache; use plugin\saiadmin\app\model\system\SystemUser; use plugin\saiadmin\app\validate\system\SystemRoleValidate; use plugin\saiadmin\app\logic\system\SystemRoleLogic; use plugin\saiadmin\service\Permission; use support\Request; use support\Response; /** * 角色控制器 */ class SystemRoleController extends BaseController { /** * 构造 */ public function __construct() { $this->logic = new SystemRoleLogic(); $this->validate = new SystemRoleValidate; parent::__construct(); } /** * 数据列表 * @param Request $request * @return Response */ #[Permission('角色数据列表', 'core:role:index')] public function index(Request $request): Response { $where = $request->more([ ['name', ''], ['code', ''], ['status', ''], ]); $query = $this->logic->search($where); $levelArr = array_column($this->adminInfo['roleList'], 'level'); $maxLevel = max($levelArr); $query->where('level', '<', $maxLevel); $data = $this->logic->getList($query); return $this->success($data); } /** * 读取数据 * @param Request $request * @return Response */ #[Permission('角色数据读取', 'core:role:read')] public function read(Request $request): Response { $id = $request->input('id', ''); $model = $this->logic->read($id); if ($model) { $data = is_array($model) ? $model : $model->toArray(); return $this->success($data); } else { return $this->fail('未查找到信息'); } } /** * 保存数据 * @param Request $request * @return Response */ #[Permission('角色数据添加', 'core:role:save')] public function save(Request $request): Response { $data = $request->post(); $this->validate('save', $data); $result = $this->logic->add($data); if ($result) { return $this->success('添加成功'); } else { return $this->fail('添加失败'); } } /** * 更新数据 * @param Request $request * @return Response */ #[Permission('角色数据修改', 'core:role:update')] public function update(Request $request): Response { $data = $request->post(); $this->validate('update', $data); $result = $this->logic->edit($data['id'], $data); if ($result) { return $this->success('修改成功'); } else { return $this->fail('修改失败'); } } /** * 删除数据 * @param Request $request * @return Response */ #[Permission('角色数据删除', 'core:role:destroy')] public function destroy(Request $request): Response { $ids = $request->post('ids', ''); if (empty($ids)) { return $this->fail('请选择要删除的数据'); } $result = $this->logic->destroy($ids); if ($result) { return $this->success('删除成功'); } else { return $this->fail('删除失败'); } } /** * 根据角色获取菜单 * @param Request $request * @return Response */ #[Permission('角色数据列表', 'core:role:index')] public function getMenuByRole(Request $request): Response { $id = $request->get('id'); $data = $this->logic->getMenuByRole($id); return $this->success($data); } /** * 菜单权限 * @param Request $request * @return Response */ #[Permission('角色菜单权限', 'core:role:menu')] public function menuPermission(Request $request): Response { $id = $request->post('id'); $menu_ids = $request->post('menu_ids'); $this->logic->saveMenuPermission($id, $menu_ids); return $this->success('操作成功'); } /** * 可操作角色 * @param Request $request * @return Response */ public function accessRole(Request $request): Response { $where = ['status' => 1]; $data = $this->logic->accessRole($where); return $this->success($data); } } ================================================ FILE: src/plugin/saiadmin/app/controller/system/SystemServerController.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\controller\system; use plugin\saiadmin\service\Permission; use plugin\saiadmin\basic\BaseController; use plugin\saiadmin\utils\ServerMonitor; use support\think\Cache; use support\Request; use support\Response; /** * 邮件记录控制器 */ class SystemServerController extends BaseController { /** * 构造 */ public function __construct() { parent::__construct(); } /** * 数据列表 * @param Request $request * @return Response */ #[Permission('服务监控', 'core:server:monitor')] public function monitor(Request $request): Response { $service = new ServerMonitor(); return $this->success([ 'memory' => $service->getMemoryInfo(), 'disk' => $service->getDiskInfo(), 'phpEnv' => $service->getPhpAndEnvInfo(), ]); } /** * 数据列表 * @param Request $request * @return Response */ #[Permission('缓存信息', 'core:server:cache')] public function cache(Request $request): Response { $menu_cache = config('plugin.saiadmin.saithink.menu_cache', []); $button_cache = config('plugin.saiadmin.saithink.button_cache', []); $config_cache = config('plugin.saiadmin.saithink.config_cache', []); $dict_cache = config('plugin.saiadmin.saithink.dict_cache', []); $reflection_cache = config('plugin.saiadmin.saithink.reflection_cache', []); return $this->success([ 'menu_cache' => $menu_cache, 'button_cache' => $button_cache, 'config_cache' => $config_cache, 'dict_cache' => $dict_cache, 'reflection_cache' => $reflection_cache ]); } /** * 删除数据 * @param Request $request * @return Response */ #[Permission('缓存数据清理', 'core:server:clear')] public function clear(Request $request) : Response { $tag = $request->input('tag', ''); if (empty($tag)) { return $this->fail('请选择要删除的缓存'); } Cache::tag($tag)->clear(); Cache::delete($tag); return $this->success('删除成功'); } } ================================================ FILE: src/plugin/saiadmin/app/controller/system/SystemUserController.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\controller\system; use plugin\saiadmin\app\cache\UserAuthCache; use plugin\saiadmin\app\cache\UserMenuCache; use plugin\saiadmin\basic\BaseController; use plugin\saiadmin\app\cache\UserInfoCache; use plugin\saiadmin\app\logic\system\SystemUserLogic; use plugin\saiadmin\app\validate\system\SystemUserValidate; use plugin\saiadmin\service\Permission; use support\Request; use support\Response; /** * 用户信息控制器 */ class SystemUserController extends BaseController { /** * 构造 */ public function __construct() { $this->logic = new SystemUserLogic(); $this->validate = new SystemUserValidate; parent::__construct(); } /** * 数据列表 * @param Request $request * @return Response */ #[Permission('用户数据列表', 'core:user:index')] public function index(Request $request): Response { $where = $request->more([ ['username', ''], ['phone', ''], ['email', ''], ['status', ''], ['dept_id', ''], ['create_time', ''], ]); $data = $this->logic->indexList($where); return $this->success($data); } /** * 读取数据 * @param Request $request * @return Response */ #[Permission('用户数据读取', 'core:user:read')] public function read(Request $request): Response { $id = $request->input('id', ''); $model = $this->logic->read($id); if ($model) { $data = is_array($model) ? $model : $model->toArray(); return $this->success($data); } else { return $this->fail('未查找到信息'); } } /** * 保存数据 * @param Request $request * @return Response */ #[Permission('用户数据保存', 'core:user:save')] public function save(Request $request): Response { $data = $request->post(); $this->validate('save', $data); $result = $this->logic->add($data); if ($result) { return $this->success('添加成功'); } else { return $this->fail('添加失败'); } } /** * 更新数据 * @param Request $request * @return Response */ #[Permission('用户数据更新', 'core:user:update')] public function update(Request $request): Response { $data = $request->post(); $this->validate('update', $data); $result = $this->logic->edit($data['id'], $data); if ($result) { return $this->success('修改成功'); } else { return $this->fail('修改失败'); } } /** * 删除数据 * @param Request $request * @return Response */ #[Permission('用户数据删除', 'core:user:destroy')] public function destroy(Request $request): Response { $ids = $request->input('ids', ''); if (!empty($ids)) { $this->logic->destroy($ids); return $this->success('操作成功'); } else { return $this->fail('参数错误,请检查'); } } /** * 清理用户缓存 * @param Request $request * @return Response */ #[Permission('清理用户缓存', 'core:user:cache')] public function clearCache(Request $request): Response { $id = $request->post('id', ''); UserInfoCache::clearUserInfo($id); UserAuthCache::clearUserAuth($id); UserMenuCache::clearUserMenu($id); return $this->success('操作成功'); } /** * 修改用户密码 * @param Request $request * @return Response */ #[Permission('修改用户密码', 'core:user:password')] public function initUserPassword(Request $request): Response { $id = $request->post('id', ''); $password = $request->post('password', ''); if ($id == 1) { return $this->fail('超级管理员不允许重置密码'); } $data = ['password' => password_hash($password, PASSWORD_DEFAULT)]; $this->logic->authEdit($id, $data); UserInfoCache::clearUserInfo($id); return $this->success('操作成功'); } /** * 设置用户首页 * @param Request $request * @return Response */ #[Permission('设置用户首页', 'core:user:home')] public function setHomePage(Request $request): Response { $id = $request->post('id', ''); $dashboard = $request->post('dashboard', ''); $data = ['dashboard' => $dashboard]; $this->logic->authEdit($id, $data); UserInfoCache::clearUserInfo($id); return $this->success('操作成功'); } /** * 更新资料 * @param Request $request * @return Response */ #[Permission('用户修改资料')] public function updateInfo(Request $request): Response { $data = $request->post(); unset($data['deptList']); unset($data['postList']); unset($data['roleList']); $result = $this->logic->updateInfo($this->adminId, $data); if ($result) { UserInfoCache::clearUserInfo($this->adminId); return $this->success('操作成功'); } else { return $this->fail('操作失败'); } } /** * 修改密码 * @param Request $request * @return Response */ #[Permission('用户修改密码')] public function modifyPassword(Request $request): Response { $oldPassword = $request->input('oldPassword'); $newPassword = $request->input('newPassword'); $this->logic->modifyPassword($this->adminId, $oldPassword, $newPassword); UserInfoCache::clearUserInfo($this->adminId); return $this->success('修改成功'); } } ================================================ FILE: src/plugin/saiadmin/app/controller/tool/CrontabController.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\controller\tool; use plugin\saiadmin\app\logic\tool\CrontabLogic; use plugin\saiadmin\app\logic\tool\CrontabLogLogic; use plugin\saiadmin\app\validate\tool\CrontabValidate; use plugin\saiadmin\basic\BaseController; use plugin\saiadmin\service\Permission; use Webman\Channel\Client; use support\Request; use support\Response; /** * 定时任务控制器 */ class CrontabController extends BaseController { /** * 构造 */ public function __construct() { $this->logic = new CrontabLogic(); $this->validate = new CrontabValidate; parent::__construct(); } /** * 数据列表 * @param Request $request * @return Response */ #[Permission('定时任务列表', 'tool:crontab:index')] public function index(Request $request) : Response { $where = $request->more([ ['name', ''], ['type', ''], ['status', ''], ['create_time', ''], ]); $query = $this->logic->search($where); $data = $this->logic->getList($query); return $this->success($data); } /** * 保存数据 * @param Request $request * @return Response */ #[Permission('定时任务添加', 'tool:crontab:edit')] public function save(Request $request): Response { $data = $request->post(); $this->validate('save', $data); $result = $this->logic->add($data); if ($result) { return $this->success('添加成功'); } else { return $this->fail('添加失败'); } } /** * 更新数据 * @param Request $request * @return Response */ #[Permission('定时任务修改', 'tool:crontab:edit')] public function update(Request $request): Response { $data = $request->post(); $this->validate('update', $data); $result = $this->logic->edit($data['id'], $data); if ($result) { return $this->success('修改成功'); } else { return $this->fail('修改失败'); } } /** * 删除数据 * @param Request $request * @return Response */ #[Permission('定时任务删除', 'tool:crontab:edit')] public function destroy(Request $request) : Response { $ids = $request->post('ids', ''); if (empty($ids)) { return $this->fail('请选择要删除的数据'); } $result = $this->logic->destroy($ids); if ($result) { return $this->success('删除成功'); } else { return $this->fail('删除失败'); } } /** * 修改状态 * @param Request $request * @return Response */ #[Permission('定时任务状态修改', 'tool:crontab:edit')] public function changeStatus(Request $request) : Response { $id = $request->input('id', ''); $status = $request->input('status', 1); if (empty($id)) { return $this->fail('参数错误,请检查'); } $result = $this->logic->changeStatus($id, $status); if ($result) { return $this->success('操作成功'); } else { return $this->fail('操作失败'); } } /** * 执行定时任务 * @param Request $request * @return Response */ #[Permission('定时任务执行', 'tool:crontab:run')] public function run(Request $request) : Response { $id = $request->input('id', ''); $result = $this->logic->run($id); if ($result) { return $this->success('执行成功'); } else { return $this->fail('执行失败'); } } /** * 定时任务日志 * @param Request $request * @return Response */ #[Permission('定时任务日志', 'tool:crontab:index')] public function logPageList(Request $request) : Response { $where = $request->more([ ['crontab_id', ''], ['create_time', []] ]); $logic = new CrontabLogLogic(); $query = $logic->search($where); $data = $logic->getList($query); return $this->success($data); } /** * 定时任务日志删除 * @param Request $request * @return Response */ #[Permission('定时任务日志删除', 'tool:crontab:edit')] public function deleteCrontabLog(Request $request) : Response { $ids = $request->input('ids', ''); if (!empty($ids)) { $logic = new CrontabLogLogic(); $logic->destroy($ids); return $this->success('操作成功'); } else { return $this->fail('参数错误,请检查'); } } } ================================================ FILE: src/plugin/saiadmin/app/controller/tool/GenerateTablesController.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\controller\tool; use plugin\saiadmin\basic\BaseController; use plugin\saiadmin\app\logic\tool\GenerateTablesLogic; use plugin\saiadmin\app\validate\tool\GenerateTablesValidate; use plugin\saiadmin\app\cache\UserMenuCache; use plugin\saiadmin\service\Permission; use support\Request; use support\Response; /** * 代码生成控制器 */ class GenerateTablesController extends BaseController { /** * 构造 */ public function __construct() { $this->logic = new GenerateTablesLogic(); $this->validate = new GenerateTablesValidate; parent::__construct(); } /** * 数据列表 * @param Request $request * @return Response */ #[Permission('代码生成列表', 'tool:code:index')] public function index(Request $request): Response { $where = $request->more([ ['table_name', ''], ]); $query = $this->logic->search($where); $data = $this->logic->getList($query); return $this->success($data); } /** * 读取数据 * @param Request $request * @return Response */ #[Permission('代码生成列表', 'tool:code:index')] public function read(Request $request): Response { $id = $request->input('id', ''); $model = $this->logic->read($id); if ($model) { $data = is_array($model) ? $model : $model->toArray(); return $this->success($data); } else { return $this->fail('未查找到信息'); } } /** * 修改数据 * @param Request $request * @return Response */ #[Permission('代码生成修改', 'tool:code:edit')] public function update(Request $request): Response { $data = $request->post(); $this->validate('update', $data); $result = $this->logic->edit($data['id'], $data); if ($result) { return $this->success('修改成功'); } else { return $this->fail('修改失败'); } } /** * 删除数据 * @param Request $request * @return Response */ #[Permission('代码生成删除', 'tool:code:edit')] public function destroy(Request $request): Response { $ids = $request->post('ids', ''); if (empty($ids)) { return $this->fail('请选择要删除的数据'); } $result = $this->logic->destroy($ids); if ($result) { return $this->success('删除成功'); } else { return $this->fail('删除失败'); } } /** * 装载数据表 * @param Request $request * @return Response */ #[Permission('代码生成装载', 'tool:code:edit')] public function loadTable(Request $request): Response { $names = $request->input('names', []); $source = $request->input('source', ''); $this->logic->loadTable($names, $source); return $this->success('操作成功'); } /** * 同步数据表字段信息 * @param Request $request * @return Response */ #[Permission('代码生成同步表结构', 'tool:code:edit')] public function sync(Request $request): Response { $id = $request->input('id', ''); $this->logic->sync($id); return $this->success('操作成功'); } /** * 代码预览 */ #[Permission('代码生成预览', 'tool:code:edit')] public function preview(Request $request): Response { $id = $request->input('id', ''); $data = $this->logic->preview($id); return $this->success($data); } /** * 代码生成 */ #[Permission('代码生成文件', 'tool:code:edit')] public function generate(Request $request): Response { $ids = $request->input('ids', ''); $data = $this->logic->generate($ids); return response()->download($data['download'], $data['filename']); } /** * 生成到模块 */ #[Permission('代码生成到模块', 'tool:code:edit')] public function generateFile(Request $request): Response { $id = $request->input('id', ''); $this->logic->generateFile($id); UserMenuCache::clearMenuCache(); return $this->success('操作成功'); } /** * 获取数据表字段信息 * @param Request $request * @return Response */ #[Permission('代码生成读取表字段', 'tool:code:index')] public function getTableColumns(Request $request): Response { $table_id = $request->input('table_id', ''); $data = $this->logic->getTableColumns($table_id); return $this->success($data); } } ================================================ FILE: src/plugin/saiadmin/app/event/SystemUser.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\event; use plugin\saiadmin\app\cache\ReflectionCache; use plugin\saiadmin\app\model\system\SystemLoginLog; use plugin\saiadmin\app\model\system\SystemOperLog; class SystemUser { /** * 登录日志 * @param $item */ public function login($item) { $request = request(); $ip = $request ? $request->getRealIp() : '127.0.0.1'; $http_user_agent = $request ? $request->header('user-agent') : ''; $data['username'] = $item['username']; $data['ip'] = $ip; $data['ip_location'] = self::getIpLocation($ip); $data['os'] = self::getOs($http_user_agent); $data['browser'] = self::getBrowser($http_user_agent); $data['status'] = $item['status']; $data['message'] = $item['message']; $data['login_time'] = date('Y-m-d H:i:s'); if (isset($item['admin_id'])) { $data['created_by'] = $item['admin_id']; $data['updated_by'] = $item['admin_id']; } SystemLoginLog::create($data); } /** * 记录操作日志 */ public function operateLog(): bool { $request = request(); if (!$request) { return false; } if ($request->method() === 'GET') { return false; } $info = getCurrentInfo(); $ip = $request->getRealIp(); $module = $request->plugin; $rule = trim($request->uri()); $data['username'] = $info['username']; $data['method'] = $request->method(); $data['router'] = $rule; $data['service_name'] = self::getServiceName(); $data['app'] = $module; $data['ip'] = $ip; $data['ip_location'] = self::getIpLocation($ip); $data['request_data'] = $this->filterParams($request->all()); SystemOperLog::create($data); return true; } /** * 获取业务名称 */ protected function getServiceName(): string { $request = request(); if (!$request) { return '未命名业务'; } $permissions = ReflectionCache::getPermissionAttributes($request->controller, $request->action); if (!empty($permissions)) { return $permissions['title'] ?? '未命名业务'; } else { return '未命名业务'; } } /** * 过滤字段 */ protected function filterParams($params): string { $blackList = ['password', 'oldPassword', 'newPassword']; foreach ($params as $key => $value) { if (in_array($key, $blackList)) { $params[$key] = '******'; } } return json_encode($params, JSON_UNESCAPED_UNICODE); } /** * 获取IP地理位置 */ protected function getIpLocation($ip): string { $ip2region = new \Ip2Region(); try { $region = $ip2region->memorySearch($ip); } catch (\Exception $e) { return '未知'; } list($country, $province, $city, $network) = explode('|', $region['region']); if ($network === '内网IP') { return $network; } if ($country == '中国') { return $province . '-' . $city . ':' . $network; } else if ($country == '0') { return '未知'; } else { return $country; } } /** * 获取浏览器信息 */ protected function getBrowser($user_agent): string { $br = 'Unknown'; if (preg_match('/MSIE/i', $user_agent)) { $br = 'MSIE'; } elseif (preg_match('/Firefox/i', $user_agent)) { $br = 'Firefox'; } elseif (preg_match('/Chrome/i', $user_agent)) { $br = 'Chrome'; } elseif (preg_match('/Safari/i', $user_agent)) { $br = 'Safari'; } elseif (preg_match('/Opera/i', $user_agent)) { $br = 'Opera'; } else { $br = 'Other'; } return $br; } /** * 获取操作系统信息 */ protected function getOs($user_agent): string { $os = 'Unknown'; if (preg_match('/win/i', $user_agent)) { $os = 'Win'; } elseif (preg_match('/mac/i', $user_agent)) { $os = 'Mac'; } elseif (preg_match('/linux/i', $user_agent)) { $os = 'Linux'; } else { $os = 'Other'; } return $os; } } ================================================ FILE: src/plugin/saiadmin/app/exception/Handler.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\exception; use Throwable; use Webman\Http\Request; use Webman\Http\Response; use Webman\Exception\ExceptionHandler; use plugin\saiadmin\exception\ApiException; /** * 异常处理类 */ class Handler extends ExceptionHandler { public $dontReport = [ ApiException::class, ]; public function report(Throwable $exception) { if ($this->shouldntReport($exception)) { return; } $logs = ''; if ($request = \request()) { $user = getCurrentInfo(); $logs .= $request->method() . ' ' . $request->uri(); $logs .= PHP_EOL . '[request_param]: ' . json_encode($request->all()); $logs .= PHP_EOL . '[timestamp]: ' . date('Y-m-d H:i:s'); $logs .= PHP_EOL . '[client_ip]: ' . $request->getRealIp(); $logs .= PHP_EOL . '[action_user]: ' . var_export($user, true); $logs .= PHP_EOL . '[exception_handle]: ' . get_class($exception); $logs .= PHP_EOL . '[exception_info]: ' . PHP_EOL . $exception; } $this->logger->error($logs); } public function render(Request $request, Throwable $exception): Response { $debug = config('app.debug', true); $code = $exception->getCode(); $json = [ 'code' => $code ? $code : 500, 'message' => $code !== 500 ? $exception->getMessage() : 'Server internal error', 'type' => 'failed' ]; if ($debug) { $json['request_url'] = $request->method() . ' ' . $request->uri(); $json['timestamp'] = date('Y-m-d H:i:s'); $json['client_ip'] = $request->getRealIp(); $json['request_param'] = $request->all(); $json['exception_handle'] = get_class($exception); $json['exception_info'] = [ 'code' => $exception->getCode(), 'message' => $exception->getMessage(), 'file' => $exception->getFile(), 'line' => $exception->getLine(), 'trace' => explode("\n", $exception->getTraceAsString()) ]; } return new Response(200, ['Content-Type' => 'application/json;charset=utf-8'], json_encode($json)); } } ================================================ FILE: src/plugin/saiadmin/app/functions.php ================================================ // +---------------------------------------------------------------------- use Webman\Route; use support\Response; use Tinywan\Jwt\JwtToken; use plugin\saiadmin\exception\ApiException; use plugin\saiadmin\app\cache\ConfigCache; use plugin\saiadmin\app\cache\DictCache; if (!function_exists('getCurrentInfo')) { /** * 获取当前登录用户 */ function getCurrentInfo(): bool|array { if (!request()) { return false; } try { $token = JwtToken::getExtend(); } catch (\Throwable $e) { return false; } return $token; } } if (!function_exists('fastRoute')) { /** * 快速注册路由[index|save|update|read|destroy|import|export] * @param string $name * @param string $controller * @return void */ function fastRoute(string $name, string $controller): void { $name = trim($name, '/'); if (method_exists($controller, 'index')) Route::get("/$name/index", [$controller, 'index']); if (method_exists($controller, 'save')) Route::post("/$name/save", [$controller, 'save']); if (method_exists($controller, 'update')) Route::put("/$name/update", [$controller, 'update']); if (method_exists($controller, 'read')) Route::get("/$name/read", [$controller, 'read']); if (method_exists($controller, 'destroy')) Route::delete("/$name/destroy", [$controller, 'destroy']); if (method_exists($controller, 'import')) Route::post("/$name/import", [$controller, 'import']); if (method_exists($controller, 'export')) Route::post("/$name/export", [$controller, 'export']); } } if (!function_exists('downloadFile')) { /** * 下载模板 * @param $file_name * @return Response */ function downloadFile($file_name): Response { $base_dir = config('plugin.saiadmin.saithink.template', base_path() . '/public/template'); if (file_exists($base_dir . DIRECTORY_SEPARATOR . $file_name)) { return response()->download($base_dir . DIRECTORY_SEPARATOR . $file_name, urlencode($file_name)); } else { throw new ApiException('模板不存在'); } } } if (!function_exists('formatBytes')) { /** * 根据字节计算大小 * @param $bytes * @return string */ function formatBytes($bytes): string { $units = ['B', 'KB', 'MB', 'GB', 'TB']; for ($i = 0; $bytes > 1024; $i++) { $bytes /= 1024; } return round($bytes, 2) . ' ' . $units[$i]; } } if (!function_exists('getConfigGroup')) { /** * 读取配置组 * @param $group * @return array */ function getConfigGroup($group): array { return ConfigCache::getConfig($group); } } if (!function_exists('dictDataList')) { /** * 根据字典编码获取字典列表 * @param string $code 字典编码 * @return array */ function dictDataList(string $code): array { return DictCache::getDict($code); } } ================================================ FILE: src/plugin/saiadmin/app/logic/system/DatabaseLogic.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\logic\system; use plugin\saiadmin\basic\think\BaseLogic; use plugin\saiadmin\exception\ApiException; use support\think\Db; /** * 数据表维护逻辑层 */ class DatabaseLogic extends BaseLogic { /** * 获取数据源 * @return array */ public function getDbSource(): array { $data = config('think-orm.connections'); $list = []; foreach ($data as $k => $v) { $list[] = $k; } return $list; } /** * 数据列表 * @param $query * @return mixed */ public function getList($query): mixed { $request = request(); $page = $request ? ($request->input('page') ?: 1) : 1; $limit = $request ? ($request->input('limit') ?: 10) : 10; return self::getTableList($query, $page, $limit); } /** * 获取数据库表数据 */ public function getTableList($query, $current_page = 1, $per_page = 10): array { if (!empty($query['source'])) { if (!empty($query['name'])) { $sql = 'show table status where name=:name '; $list = Db::connect($query['source'])->query($sql, ['name' => $query['name']]); } else { $list = Db::connect($query['source'])->query('show table status'); } } else { if (!empty($query['name'])) { $sql = 'show table status where name=:name '; $list = Db::query($sql, ['name' => $query['name']]); } else { $list = Db::query('show table status'); } } $data = []; foreach ($list as $item) { $data[] = [ 'name' => $item['Name'], 'engine' => $item['Engine'], 'rows' => $item['Rows'], 'data_free' => $item['Data_free'], 'data_length' => $item['Data_length'], 'index_length' => $item['Index_length'], 'collation' => $item['Collation'], 'create_time' => $item['Create_time'], 'update_time' => $item['Update_time'], 'comment' => $item['Comment'], ]; } $total = count($data); $last_page = ceil($total / $per_page); $startIndex = ($current_page - 1) * $per_page; $pageData = array_slice($data, $startIndex, $per_page); return [ 'data' => $pageData, 'total' => $total, 'current_page' => $current_page, 'per_page' => $per_page, 'last_page' => $last_page, ]; } /** * 获取列信息 */ public function getColumnList($table, $source): array { $columnList = []; if (preg_match("/^[a-zA-Z0-9_]+$/", $table)) { if (!empty($source)) { $list = Db::connect($source)->query('SHOW FULL COLUMNS FROM `' . $table . '`'); } else { $list = Db::query('SHOW FULL COLUMNS FROM `' . $table . '`'); } foreach ($list as $column) { preg_match('/^\w+/', $column['Type'], $matches); $columnList[] = [ 'column_key' => $column['Key'], 'column_name' => $column['Field'], 'column_type' => $matches[0], 'column_comment' => trim(preg_replace("/\([^()]*\)/", "", $column['Comment'])), 'extra' => $column['Extra'], 'default_value' => $column['Default'], 'is_nullable' => $column['Null'], ]; } } return $columnList; } /** * 优化表 */ public function optimizeTable($tables) { foreach ($tables as $table) { if (preg_match("/^[a-zA-Z0-9_]+$/", $table)) { Db::execute('OPTIMIZE TABLE `' . $table . '`'); } } } /** * 清理表碎片 */ public function fragmentTable($tables) { foreach ($tables as $table) { if (preg_match("/^[a-zA-Z0-9_]+$/", $table)) { Db::execute('ANALYZE TABLE `' . $table . '`'); } } } /** * 获取回收站数据 */ public function recycleData($table) { if (preg_match("/^[a-zA-Z0-9_]+$/", $table)) { // 查询表字段 $sql = 'SHOW COLUMNS FROM `' . $table . '` where Field = "delete_time"'; $columns = Db::query($sql); $isDeleteTime = false; if (count($columns) > 0) { $isDeleteTime = true; } if (!$isDeleteTime) { throw new ApiException('当前表不支持回收站功能'); } // 查询软删除数据 $request = request(); $limit = $request ? ($request->input('limit') ?: 10) : 10; return Db::table($table)->whereNotNull('delete_time') ->order('delete_time', 'desc') ->paginate($limit) ->toArray(); } else { return []; } } /** * 删除数据 * @param $table * @param $ids * @return bool */ public function delete($table, $ids) { if (preg_match("/^[a-zA-Z0-9_]+$/", $table)) { $count = Db::table($table)->whereIn('id', $ids)->delete($ids); return $count > 0; } else { return false; } } /** * 恢复数据 * @param $table * @param $ids * @return bool */ public function recovery($table, $ids) { if (preg_match("/^[a-zA-Z0-9_]+$/", $table)) { $count = Db::table($table) ->where('id', 'in', $ids) ->update(['delete_time' => null]); return $count > 0; } else { return false; } } } ================================================ FILE: src/plugin/saiadmin/app/logic/system/SystemAttachmentLogic.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\logic\system; use Exception; use plugin\saiadmin\app\model\system\SystemAttachment; use plugin\saiadmin\app\model\system\SystemCategory; use plugin\saiadmin\basic\think\BaseLogic; use plugin\saiadmin\exception\ApiException; use plugin\saiadmin\service\storage\ChunkUploadService; use plugin\saiadmin\service\storage\UploadService; use plugin\saiadmin\utils\Arr; use plugin\saiadmin\utils\Helper; /** * 附件逻辑层 */ class SystemAttachmentLogic extends BaseLogic { /** * 构造函数 */ public function __construct() { $this->model = new SystemAttachment(); } /** * @param $category_id * @param $ids * @return mixed */ public function move($category_id, $ids): mixed { $category = SystemCategory::where('id', $category_id)->findOrEmpty(); if ($category->isEmpty()) { throw new ApiException('目标分类不存在'); } return $this->model->whereIn('id', $ids)->update(['category_id' => $category_id]); } /** * 保存网络图片 * @param $url * @param $config * @return array * @throws ApiException|Exception */ public function saveNetworkImage($url, $config): array { $image_data = file_get_contents($url); if ($image_data === false) { throw new ApiException('获取文件资源失败'); } $image_resource = imagecreatefromstring($image_data); if (!$image_resource) { throw new ApiException('创建图片资源失败'); } $filename = basename($url); $file_extension = pathinfo($filename, PATHINFO_EXTENSION); $full_dir = runtime_path() . '/resource/'; if (!is_dir($full_dir)) { mkdir($full_dir, 0777, true); } $save_path = $full_dir . $filename; $mime_type = 'image/'; switch ($file_extension) { case 'jpg': case 'jpeg': $mime_type = 'image/jpeg'; $result = imagejpeg($image_resource, $save_path); break; case 'png': $mime_type = 'image/png'; $result = imagepng($image_resource, $save_path); break; case 'gif': $mime_type = 'image/gif'; $result = imagegif($image_resource, $save_path); break; default: imagedestroy($image_resource); throw new ApiException('文件格式错误'); } imagedestroy($image_resource); if (!$result) { throw new ApiException('文件保存失败'); } $hash = md5_file($save_path); $size = filesize($save_path); $model = $this->model->where('hash', $hash)->find(); if ($model) { unlink($save_path); return $model->toArray(); } else { $logic = new SystemConfigLogic(); $uploadConfig = $logic->getGroup('upload_config'); $root = Arr::getConfigValue($uploadConfig, 'local_root'); $folder = date('Ymd'); $full_dir = base_path() . DIRECTORY_SEPARATOR . $root . $folder . DIRECTORY_SEPARATOR; if (!is_dir($full_dir)) { mkdir($full_dir, 0777, true); } $object_name = bin2hex(pack('Nn', time(), random_int(1, 65535))) . ".$file_extension"; $newPath = $full_dir . $object_name; copy($save_path, $newPath); unlink($save_path); $domain = Arr::getConfigValue($uploadConfig, 'local_domain'); $uri = Arr::getConfigValue($uploadConfig, 'local_uri'); $baseUrl = $domain . $uri . $folder . '/'; $info['storage_mode'] = 1; $info['category_id'] = request()->input('category_id', 1); $info['origin_name'] = $filename; $info['object_name'] = $object_name; $info['hash'] = $hash; $info['mime_type'] = $mime_type; $info['storage_path'] = $root . $folder . '/' . $object_name; $info['suffix'] = $file_extension; $info['size_byte'] = $size; $info['size_info'] = formatBytes($size); $info['url'] = $baseUrl . $object_name; $this->model->save($info); return $info; } } /** * 文件上传 * @param string $upload * @param bool $local * @return array */ public function uploadBase(string $upload = 'image', bool $local = false): array { $logic = new SystemConfigLogic(); $uploadConfig = $logic->getGroup('upload_config'); $type = Arr::getConfigValue($uploadConfig, 'upload_mode'); if ($local === true) { $type = 1; } $result = UploadService::disk($type, $upload)->uploadFile(); $data = $result[0]; $hash = $data['unique_id']; $hash_check = config('plugin.saiadmin.saithink.file_hash', false); if ($hash_check) { $model = $this->model->where('hash', $hash)->findOrEmpty(); if (!$model->isEmpty()) { return $model->toArray(); } } $url = str_replace('\\', '/', $data['url']); $savePath = str_replace('\\', '/', $data['save_path']); $info['storage_mode'] = $type; $info['category_id'] = request()->input('category_id', 1); $info['origin_name'] = $data['origin_name']; $info['object_name'] = $data['save_name']; $info['hash'] = $data['unique_id']; $info['mime_type'] = $data['mime_type']; $info['storage_path'] = $savePath; $info['suffix'] = $data['extension']; $info['size_byte'] = $data['size']; $info['size_info'] = formatBytes($data['size']); $info['url'] = $url; $this->model->save($info); return $info; } /** * 切片上传 * @param $data * @return array */ public function chunkUpload($data): array { $chunkService = new ChunkUploadService(); if ($data['index'] == 0) { $model = $this->model->where('hash', $data['hash'])->findOrEmpty(); if (!$model->isEmpty()) { return $model->toArray(); } else { return $chunkService->checkChunk($data); } } else { return $chunkService->uploadChunk($data); } } } ================================================ FILE: src/plugin/saiadmin/app/logic/system/SystemCategoryLogic.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\logic\system; use plugin\saiadmin\basic\think\BaseLogic; use plugin\saiadmin\exception\ApiException; use plugin\saiadmin\app\model\system\SystemCategory; use plugin\saiadmin\utils\Helper; use plugin\saiadmin\utils\Arr; /** * 附件分类逻辑层 */ class SystemCategoryLogic extends BaseLogic { /** * 构造函数 */ public function __construct() { $this->model = new SystemCategory(); } /** * 添加数据 */ public function add($data): bool { $data = $this->handleData($data); return $this->model->save($data); } /** * 修改数据 */ public function edit($id, $data): bool { $data = $this->handleData($data); if ($data['parent_id'] == $id) { throw new ApiException('上级分类和当前分类不能相同'); } if (in_array($id, explode(',', $data['level']))) { throw new ApiException('不能将上级分类设置为当前分类的子分类'); } $model = $this->model->findOrEmpty($id); if ($model->isEmpty()) { throw new ApiException('数据不存在'); } return $model->save($data); } /** * 数据删除 */ public function destroy($ids): bool { $num = $this->model->where('parent_id', 'in', $ids)->count(); if ($num > 0) { throw new ApiException('该部门下存在子分类,请先删除子分类'); } else { return $this->model->destroy($ids); } } /** * 数据处理 */ protected function handleData($data) { if (empty($data['parent_id']) || $data['parent_id'] == 0) { $data['level'] = '0'; $data['parent_id'] = 0; } else { $parentMenu = SystemCategory::findOrEmpty($data['parent_id']); $data['level'] = $parentMenu['level'] . $parentMenu['id'] . ','; } return $data; } /** * 数据树形化 * @param array $where * @return array */ public function tree(array $where = []): array { $query = $this->search($where); $request = request(); if ($request && $request->input('tree', 'false') === 'true') { $query->field('id, id as value, category_name as label, parent_id, category_name, sort'); } $query->order('sort', 'desc'); $data = $this->getAll($query); return Helper::makeTree($data); } } ================================================ FILE: src/plugin/saiadmin/app/logic/system/SystemConfigGroupLogic.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\logic\system; use plugin\saiadmin\app\cache\ConfigCache; use plugin\saiadmin\app\model\system\SystemConfigGroup; use plugin\saiadmin\basic\think\BaseLogic; use plugin\saiadmin\exception\ApiException; use plugin\saiadmin\app\model\system\SystemConfig; use support\think\Db; /** * 参数配置分组逻辑层 */ class SystemConfigGroupLogic extends BaseLogic { /** * 构造函数 */ public function __construct() { $this->model = new SystemConfigGroup(); } /** * 删除配置信息 */ public function destroy($ids): bool { $id = $ids[0]; $model = $this->model->where('id', $id)->findOrEmpty(); if ($model->isEmpty()) { throw new ApiException('配置数据未找到'); } if (in_array(intval($id), [1, 2, 3])) { throw new ApiException('系统默认分组,无法删除'); } Db::startTrans(); try { // 删除配置组 $model->delete(); // 删除配置组数据 $typeIds = SystemConfig::where('group_id', $id)->column('id'); SystemConfig::destroy($typeIds); ConfigCache::clearConfig($model->code); Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); throw new ApiException('删除数据异常,请检查'); } } } ================================================ FILE: src/plugin/saiadmin/app/logic/system/SystemConfigLogic.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\logic\system; use plugin\saiadmin\app\cache\ConfigCache; use plugin\saiadmin\app\model\system\SystemConfig; use plugin\saiadmin\app\model\system\SystemConfigGroup; use plugin\saiadmin\basic\think\BaseLogic; use plugin\saiadmin\exception\ApiException; use plugin\saiadmin\utils\Helper; /** * 参数配置逻辑层 */ class SystemConfigLogic extends BaseLogic { /** * 构造函数 */ public function __construct() { $this->model = new SystemConfig(); } /** * 添加数据 * @param mixed $data * @return mixed */ public function add($data): mixed { $result = $this->model->create($data); $group = SystemConfigGroup::find($data['group_id']); ConfigCache::clearConfig($group->code); return $result; } /** * 编辑数据 * @param mixed $id * @param mixed $data * @return bool */ public function edit($id, $data): bool { $result = parent::edit($id, $data); $group = SystemConfigGroup::find($data['group_id']); ConfigCache::clearConfig($group->code); return $result; } /** * 批量更新 * @param mixed $group_id * @param mixed $config * @return bool */ public function batchUpdate($group_id, $config): bool { $group = SystemConfigGroup::find($group_id); if (!$group) { throw new ApiException('配置组未找到'); } $saveData = []; foreach ($config as $key => $value) { $saveData[] = [ 'id' => $value['id'], 'group_id' => $group_id, 'name' => $value['name'], 'key' => $value['key'], 'value' => $value['value'] ]; } // upsert: 根据 id 更新,如果不存在则插入 $this->model->saveAll($saveData); ConfigCache::clearConfig($group->code); return true; } /** * 获取配置数据 * @param mixed $code * @return array */ public function getData($code): array { $group = SystemConfigGroup::where('code', $code)->findOrEmpty(); if (empty($group)) { return []; } $config = SystemConfig::where('group_id', $group['id'])->select()->toArray(); return $config; } /** * 获取配置组 */ public function getGroup($config): array { return ConfigCache::getConfig($config); } } ================================================ FILE: src/plugin/saiadmin/app/logic/system/SystemDeptLogic.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\logic\system; use plugin\saiadmin\basic\think\BaseLogic; use plugin\saiadmin\exception\ApiException; use plugin\saiadmin\app\model\system\SystemDept; use plugin\saiadmin\app\model\system\SystemUser; use plugin\saiadmin\utils\Helper; use plugin\saiadmin\utils\Arr; /** * 部门逻辑层 */ class SystemDeptLogic extends BaseLogic { /** * 构造函数 */ public function __construct() { $this->model = new SystemDept(); } /** * 添加数据 */ public function add($data): mixed { $data = $this->handleData($data); $this->model->save($data); return $this->model->getKey(); } /** * 修改数据 */ public function edit($id, $data): mixed { $oldLevel = $data['level'] . $id . ','; $data = $this->handleData($data); if ($data['parent_id'] == $id) { throw new ApiException('上级部门和当前部门不能相同'); } if (in_array($id, explode(',', $data['level']))) { throw new ApiException('不能将上级部门设置为当前部门的子部门'); } $newLevel = $data['level'] . $id . ','; $deptIds = $this->model->where('level', 'like', $oldLevel . '%')->column('id'); return $this->transaction(function () use ($deptIds, $oldLevel, $newLevel, $data, $id) { $this->model->whereIn('id', $deptIds)->exp('level', "REPLACE(level, '$oldLevel', '$newLevel')")->update([]); return $this->model->update($data, ['id' => $id]); }); } /** * 数据删除 */ public function destroy($ids): bool { $num = $this->model->where('parent_id', 'in', $ids)->count(); if ($num > 0) { throw new ApiException('该部门下存在子部门,请先删除子部门'); } else { $count = SystemUser::where('dept_id', 'in', $ids)->count(); if ($count > 0) { throw new ApiException('该部门下存在用户,请先删除或者转移用户'); } return $this->model->destroy($ids); } } /** * 数据处理 */ protected function handleData($data) { // 处理上级部门 if (empty($data['parent_id']) || $data['parent_id'] == 0) { $data['level'] = '0'; $data['parent_id'] = 0; } else { $parentMenu = SystemDept::findOrEmpty($data['parent_id']); $data['level'] = $parentMenu['level'] . $parentMenu['id'] . ','; } return $data; } /** * 数据树形化 * @param array $where * @return array */ public function tree(array $where = []): array { $query = $this->search($where); $request = request(); if ($request && $request->input('tree', 'false') === 'true') { $query->field('id, id as value, name as label, parent_id'); } $query->order('sort', 'desc'); $query->with(['leader']); $data = $this->getAll($query); return Helper::makeTree($data); } /** * 可操作部门 * @param array $where * @return array */ public function accessDept(array $where = []): array { $query = $this->search($where); $query->auth($this->adminInfo['deptList']); $query->field('id, id as value, name as label, parent_id'); $query->order('sort', 'desc'); $data = $this->getAll($query); return Helper::makeTree($data); } } ================================================ FILE: src/plugin/saiadmin/app/logic/system/SystemDictDataLogic.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\logic\system; use plugin\saiadmin\basic\think\BaseLogic; use plugin\saiadmin\exception\ApiException; use plugin\saiadmin\app\model\system\SystemDictData; use plugin\saiadmin\app\model\system\SystemDictType; use plugin\saiadmin\app\cache\DictCache; use plugin\saiadmin\utils\Helper; /** * 字典类型逻辑层 */ class SystemDictDataLogic extends BaseLogic { /** * 构造函数 */ public function __construct() { $this->model = new SystemDictData(); } /** * 添加数据 * @param $data * @return mixed */ public function add($data): mixed { $type = SystemDictType::where('id', $data['type_id'])->findOrEmpty(); if ($type->isEmpty()) { throw new ApiException('字典类型不存在'); } $data['code'] = $type->code; $model = $this->model->create($data); DictCache::clear(); return $model->getKey(); } } ================================================ FILE: src/plugin/saiadmin/app/logic/system/SystemDictTypeLogic.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\logic\system; use plugin\saiadmin\basic\think\BaseLogic; use plugin\saiadmin\exception\ApiException; use plugin\saiadmin\app\model\system\SystemDictType; use plugin\saiadmin\app\model\system\SystemDictData; use support\think\Db; /** * 字典类型逻辑层 */ class SystemDictTypeLogic extends BaseLogic { /** * 构造函数 */ public function __construct() { $this->model = new SystemDictType(); } /** * 添加数据 */ public function add($data): mixed { $model = $this->model->where('code', $data['code'])->findOrEmpty(); if (!$model->isEmpty()) { throw new ApiException('该字典标识已存在'); } return $this->model->save($data); } /** * 数据更新 */ public function edit($id, $data): mixed { Db::startTrans(); try { // 修改数据字典类型 $result = $this->model->update($data, ['id' => $id]); // 更新数据字典数据 SystemDictData::update(['code' => $data['code']], ['type_id' => $id]); Db::commit(); return $result; } catch (\Exception $e) { Db::rollback(); throw new ApiException('修改数据异常,请检查'); } } /** * 数据删除 */ public function destroy($ids): bool { Db::startTrans(); try { // 删除数据字典类型 $result = $this->model->destroy($ids); // 删除数据字典数据 $typeIds = SystemDictData::where('type_id', 'in', $ids)->column('id'); SystemDictData::destroy($typeIds); Db::commit(); return $result; } catch (\Exception $e) { Db::rollback(); throw new ApiException('删除数据异常,请检查'); } } /** * 获取全部字典 * @return array */ public function getDictAll(): array { $data = $this->model->where('status', 1)->field('id, name, code, remark') ->with([ 'dicts' => function ($query) { $query->where('status', 1)->field('id, type_id, label, value, color, code, sort')->order('sort', 'desc'); } ])->select()->toArray(); return $this->packageDict($data, 'code'); } /** * 组合数据 * @param $array * @param $field * @return array */ private function packageDict($array, $field): array { $result = []; foreach ($array as $item) { if (isset($item[$field])) { if (isset($result[$item[$field]])) { $result[$item[$field]] = [($result[$item[$field]])]; $result[$item[$field]][] = $item['dicts']; } else { $result[$item[$field]] = $item['dicts']; } } } return $result; } } ================================================ FILE: src/plugin/saiadmin/app/logic/system/SystemLoginLogLogic.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\logic\system; use plugin\saiadmin\app\model\system\SystemLoginLog; use plugin\saiadmin\basic\think\BaseLogic; use plugin\saiadmin\utils\Helper; use support\think\Db; /** * 登录日志逻辑层 */ class SystemLoginLogLogic extends BaseLogic { /** * 构造函数 */ public function __construct() { $this->model = new SystemLoginLog(); } /** * 登录统计图表 * @return array */ public function loginChart(): array { $sql = " SELECT d.date AS login_date, COUNT(l.login_time) AS login_count FROM (SELECT CURDATE() - INTERVAL (a.N) DAY AS date FROM (SELECT 0 AS N UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) a ) d LEFT JOIN sa_system_login_log l ON DATE(l.login_time) = d.date GROUP BY d.date ORDER BY d.date ASC; "; $data = Db::query($sql); return [ 'login_count' => array_column($data, 'login_count'), 'login_date' => array_column($data, 'login_date'), ]; } /** * 登录统计图表 * @return array */ public function loginBarChart(): array { $sql = " SELECT -- 拼接成 YYYY-MM 格式,例如 2023-01 CONCAT(LPAD(m.month_num, 2, '0'), '月') AS login_month, COUNT(l.login_time) AS login_count FROM -- 生成 1 到 12 的月份数字 (SELECT 1 AS month_num UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9 UNION ALL SELECT 10 UNION ALL SELECT 11 UNION ALL SELECT 12) m LEFT JOIN sa_system_login_log l -- 关联条件:年份等于今年 且 月份等于生成的数字 ON YEAR(l.login_time) = YEAR(CURDATE()) AND MONTH(l.login_time) = m.month_num GROUP BY m.month_num ORDER BY m.month_num ASC; "; $data = Db::query($sql); return [ 'login_count' => array_column($data, 'login_count'), 'login_month' => array_column($data, 'login_month'), ]; } } ================================================ FILE: src/plugin/saiadmin/app/logic/system/SystemMailLogic.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\logic\system; use plugin\saiadmin\app\model\system\SystemMail; use plugin\saiadmin\basic\think\BaseLogic; use plugin\saiadmin\utils\Helper; /** * 邮件模型逻辑层 */ class SystemMailLogic extends BaseLogic { /** * 构造函数 */ public function __construct() { $this->model = new SystemMail(); } } ================================================ FILE: src/plugin/saiadmin/app/logic/system/SystemMenuLogic.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\logic\system; use plugin\saiadmin\app\model\system\SystemMenu; use plugin\saiadmin\app\model\system\SystemRoleMenu; use plugin\saiadmin\app\model\system\SystemUserRole; use plugin\saiadmin\basic\think\BaseLogic; use plugin\saiadmin\exception\ApiException; use plugin\saiadmin\utils\Arr; use plugin\saiadmin\utils\Helper; /** * 菜单逻辑层 */ class SystemMenuLogic extends BaseLogic { /** * 构造函数 */ public function __construct() { $this->model = new SystemMenu(); } /** * 数据添加 */ public function add($data): mixed { $data = $this->handleData($data); return $this->model->save($data); } /** * 数据修改 */ public function edit($id, $data): mixed { $data = $this->handleData($data); if ($data['parent_id'] == $id) { throw new ApiException('不能设置父级为自身'); } return $this->model->update($data, ['id' => $id]); } /** * 数据删除 */ public function destroy($ids): bool { $num = $this->model->where('parent_id', 'in', $ids)->count(); if ($num > 0) { throw new ApiException('该菜单下存在子菜单,请先删除子菜单'); } else { return $this->model->destroy($ids); } } /** * 数据处理 */ protected function handleData($data) { // 处理上级菜单 if (empty($data['parent_id']) || $data['parent_id'] == 0) { $data['level'] = '0'; $data['parent_id'] = 0; } else { $parentMenu = $this->model->findOrEmpty($data['parent_id']); $data['level'] = $parentMenu['level'] . $parentMenu['id'] . ','; } return $data; } /** * 数据树形化 * @param $where * @return array */ public function tree($where = []): array { $query = $this->search($where); $request = request(); if ($request && $request->input('tree', 'false') === 'true') { $query->field('id, id as value, name as label, parent_id, type'); } $query->order('sort', 'desc'); $data = $this->getAll($query); return Helper::makeTree($data); } /** * 权限菜单 * @return array */ public function auth(): array { $roleLogic = new SystemRoleLogic(); $role_ids = Arr::getArrayColumn($this->adminInfo['roleList'], 'id'); $roles = $roleLogic->getMenuIdsByRoleIds($role_ids); $ids = $this->filterMenuIds($roles); $query = $this->model ->field('id, id as value, name as label, parent_id, type') ->where('status', 1) ->where('id', 'in', $ids) ->order('sort', 'desc'); $data = $this->getAll($query); return Helper::makeTree($data); } /** * 获取全部菜单 */ public function getAllMenus(): array { $query = $this->search(['status' => 1, 'type' => [1, 2, 4]])->order('sort', 'desc'); $data = $this->getAll($query); return Helper::makeArtdMenus($data); } /** * 获取全部权限 * @return array */ public function getAllAuth(): array { return SystemMenu::where('type', 3) ->where('status', 1) ->column('slug'); } /** * 根据角色获取权限 * @param $roleIds * @return array */ public function getAuthByRole($roleIds): array { $menuId = SystemRoleMenu::whereIn('role_id', $roleIds)->column('menu_id'); return SystemMenu::distinct(true) ->where('type', 3) ->where('status', 1) ->where('id', 'in', array_unique($menuId)) ->column('slug'); } /** * 根据角色获取菜单 * @param $roleIds * @return array */ public function getMenuByRole($roleIds): array { $menuId = SystemRoleMenu::whereIn('role_id', $roleIds)->column('menu_id'); $data = SystemMenu::distinct(true) ->where('status', 1) ->where('type', 'in', [1, 2, 4]) ->where('id', 'in', array_unique($menuId)) ->order('sort', 'desc') ->select() ->toArray(); return Helper::makeArtdMenus($data); } /** * 过滤通过角色查询出来的菜单id列表,并去重 * @param array $roleData * @return array */ public function filterMenuIds(array &$roleData): array { $ids = []; foreach ($roleData as $val) { foreach ($val['menus'] as $menu) { $ids[] = $menu['id']; } } unset($roleData); return array_unique($ids); } } ================================================ FILE: src/plugin/saiadmin/app/logic/system/SystemOperLogLogic.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\logic\system; use plugin\saiadmin\app\model\system\SystemOperLog; use plugin\saiadmin\basic\think\BaseLogic; use plugin\saiadmin\utils\Helper; /** * 操作日志逻辑层 */ class SystemOperLogLogic extends BaseLogic { /** * 构造函数 */ public function __construct() { $this->model = new SystemOperLog(); } /** * 获取自己的操作日志 * @param mixed $where * @return array */ public function getOwnOperLogList($where): array { $query = $this->search($where); $query->field('id, username, method, router, service_name, ip, ip_location, create_time'); return $this->getList($query); } } ================================================ FILE: src/plugin/saiadmin/app/logic/system/SystemPostLogic.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\logic\system; use plugin\saiadmin\app\model\system\SystemPost; use plugin\saiadmin\basic\think\BaseLogic; use plugin\saiadmin\exception\ApiException; use plugin\saiadmin\service\OpenSpoutWriter; use OpenSpout\Reader\XLSX\Reader; /** * 岗位管理逻辑层 */ class SystemPostLogic extends BaseLogic { /** * 构造函数 */ public function __construct() { $this->model = new SystemPost(); } /** * 可操作岗位 * @param array $where * @return array */ public function accessPost(array $where = []): array { $query = $this->search($where); $query->field('id, id as value, name as label, name, code'); return $this->getAll($query); } /** * 导入数据 */ public function import($file) { $path = $this->getImport($file); $reader = new Reader(); try { $reader->open($path); $data = []; foreach ($reader->getSheetIterator() as $sheet) { $isHeader = true; foreach ($sheet->getRowIterator() as $row) { if ($isHeader) { $isHeader = false; continue; } $cells = $row->getCells(); $data[] = [ 'name' => $cells[0]->getValue(), 'code' => $cells[1]->getValue(), 'sort' => $cells[2]->getValue(), 'status' => $cells[3]->getValue(), ]; } } $this->saveAll($data); } catch (\Exception $e) { throw new ApiException('导入文件错误,请上传正确的文件格式xlsx'); } } /** * 导出数据 */ public function export($where = []) { $query = $this->search($where)->field('id,name,code,sort,status,create_time'); $data = $this->getAll($query); $file_name = '岗位数据.xlsx'; $header = ['编号', '岗位名称', '岗位标识', '排序', '状态', '创建时间']; $filter = [ 'status' => [ ['value' => 1, 'label' => '正常'], ['value' => 2, 'label' => '禁用'] ] ]; $writer = new OpenSpoutWriter($file_name); $writer->setWidth([15, 15, 20, 15, 15, 25]); $writer->setHeader($header); $writer->setData($data, null, $filter); $file_path = $writer->returnFile(); return response()->download($file_path, urlencode($file_name)); } } ================================================ FILE: src/plugin/saiadmin/app/logic/system/SystemRoleLogic.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\logic\system; use plugin\saiadmin\app\cache\UserMenuCache; use plugin\saiadmin\app\model\system\SystemRole; use plugin\saiadmin\basic\think\BaseLogic; use plugin\saiadmin\exception\ApiException; use plugin\saiadmin\utils\Helper; use support\think\Cache; use support\think\Db; /** * 角色逻辑层 */ class SystemRoleLogic extends BaseLogic { /** * 构造函数 */ public function __construct() { $this->model = new SystemRole(); } /** * 添加数据 */ public function add($data): bool { $data = $this->handleData($data); return $this->model->save($data); } /** * 修改数据 */ public function edit($id, $data): bool { $model = $this->model->findOrEmpty($id); if ($model->isEmpty()) { throw new ApiException('数据不存在'); } $data = $this->handleData($data); return $model->save($data); } /** * 删除数据 */ public function destroy($ids): bool { // 越权保护 $levelArr = array_column($this->adminInfo['roleList'], 'level'); $maxLevel = max($levelArr); $num = SystemRole::where('level', '>=', $maxLevel)->whereIn('id', $ids)->count(); if ($num > 0) { throw new ApiException('不能操作比当前账户职级高的角色'); } else { return $this->model->destroy($ids); } } /** * 数据处理 */ protected function handleData($data) { // 越权保护 $levelArr = array_column($this->adminInfo['roleList'], 'level'); $maxLevel = max($levelArr); if ($data['level'] >= $maxLevel) { throw new ApiException('不能操作比当前账户职级高的角色'); } return $data; } /** * 可操作角色 * @param array $where * @return array */ public function accessRole(array $where = []): array { $query = $this->search($where); // 越权保护 $levelArr = array_column($this->adminInfo['roleList'], 'level'); $maxLevel = max($levelArr); $query->where('level', '<', $maxLevel); $query->order('sort', 'desc'); return $this->getAll($query); } /** * 根据角色数组获取菜单 * @param $ids * @return array */ public function getMenuIdsByRoleIds($ids): array { if (empty($ids)) return []; return $this->model->where('id', 'in', $ids)->with([ 'menus' => function ($query) { $query->where('status', 1)->order('sort', 'desc'); } ])->select()->toArray(); } /** * 根据角色获取菜单 * @param $id * @return array */ public function getMenuByRole($id): array { $role = $this->model->findOrEmpty($id); $menus = $role->menus ?: []; return [ 'id' => $id, 'menus' => $menus ]; } /** * 保存菜单权限 * @param $id * @param $menu_ids * @return mixed */ public function saveMenuPermission($id, $menu_ids): mixed { return $this->transaction(function () use ($id, $menu_ids) { $role = $this->model->findOrEmpty($id); if ($role) { $role->menus()->detach(); $data = array_map(function ($menu_id) use ($id) { return ['menu_id' => $menu_id, 'role_id' => $id]; }, $menu_ids); Db::name('sa_system_role_menu')->limit(100)->insertAll($data); } $cache = config('plugin.saiadmin.saithink.button_cache'); $tag = $cache['role'] . $id; Cache::tag($tag)->clear(); // 清理权限缓存-角色TAG UserMenuCache::clearMenuCache(); // 清理菜单缓存 return true; }); } } ================================================ FILE: src/plugin/saiadmin/app/logic/system/SystemUserLogic.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\logic\system; use plugin\saiadmin\app\cache\UserAuthCache; use plugin\saiadmin\app\cache\UserInfoCache; use plugin\saiadmin\app\cache\UserMenuCache; use plugin\saiadmin\app\model\system\SystemDept; use plugin\saiadmin\app\model\system\SystemRole; use plugin\saiadmin\app\model\system\SystemUser; use plugin\saiadmin\exception\ApiException; use plugin\saiadmin\basic\think\BaseLogic; use Webman\Event\Event; use Tinywan\Jwt\JwtToken; /** * 用户信息逻辑层 */ class SystemUserLogic extends BaseLogic { /** * 构造函数 */ public function __construct() { $this->model = new SystemUser(); } /** * 分页数据列表 * @param mixed $where * @return array */ public function indexList($where): array { $query = $this->search($where); $query->with(['depts']); $query->auth($this->adminInfo['deptList']); return $this->getList($query); } /** * 用户列表数据 * @param mixed $where * @return array */ public function openUserList($where): array { $query = $this->search($where); $query->field('id, username, realname, avatar, phone, email'); return $this->getList($query); } /** * 读取用户信息 * @param mixed $id * @return array */ public function getUser($id): array { $admin = $this->model->findOrEmpty($id); $data = $admin->hidden(['password'])->toArray(); $data['roleList'] = $admin->roles->toArray() ?: []; $data['postList'] = $admin->posts->toArray() ?: []; $data['deptList'] = $admin->depts ? $admin->depts->toArray() : []; return $data; } /** * 读取数据 * @param $id * @return array */ public function read($id): array { $data = $this->getUser($id); if ($this->adminInfo['id'] > 1) { // 部门保护 if (!$this->deptProtect($this->adminInfo['deptList'], $data['dept_id'])) { throw new ApiException('没有权限操作该部门数据'); } } return $data; } /** * 添加数据 * @param $data * @return mixed */ public function add($data): mixed { $data['password'] = password_hash($data['password'], PASSWORD_DEFAULT); return $this->transaction(function () use ($data) { $role_ids = $data['role_ids'] ?? []; $post_ids = $data['post_ids'] ?? []; if ($this->adminInfo['id'] > 1) { // 部门保护 if (!$this->deptProtect($this->adminInfo['deptList'], $data['dept_id'])) { throw new ApiException('没有权限操作该部门数据'); } // 越权保护 if (!$this->roleProtect($this->adminInfo['roleList'], $role_ids)) { throw new ApiException('没有权限操作该角色数据'); } } $user = SystemUser::create($data); $user->roles()->detach(); $user->posts()->detach(); $user->roles()->saveAll($role_ids); if (!empty($post_ids)) { $user->posts()->save($post_ids); } return $user; }); } /** * 修改数据 * @param $id * @param $data * @return mixed */ public function edit($id, $data): mixed { unset($data['password']); return $this->transaction(function () use ($data, $id) { $role_ids = $data['role_ids'] ?? []; $post_ids = $data['post_ids'] ?? []; // 仅可修改当前部门和子部门的用户 $query = $this->model->where('id', $id); $query->auth($this->adminInfo['deptList']); $user = $query->findOrEmpty(); if ($user->isEmpty()) { throw new ApiException('没有权限操作该数据'); } if ($this->adminInfo['id'] > 1) { // 部门保护 if (!$this->deptProtect($this->adminInfo['deptList'], $data['dept_id'])) { throw new ApiException('没有权限操作该部门数据'); } // 越权保护 if (!$this->roleProtect($this->adminInfo['roleList'], $role_ids)) { throw new ApiException('没有权限操作该角色数据'); } } $result = parent::edit($id, $data); if ($result) { $user->roles()->detach(); $user->posts()->detach(); $user->roles()->saveAll($role_ids); if (!empty($post_ids)) { $user->posts()->save($post_ids); } UserInfoCache::clearUserInfo($id); UserAuthCache::clearUserAuth($id); UserMenuCache::clearUserMenu($id); } return $result; }); } /** * 删除数据 * @param $ids * @return bool */ public function destroy($ids): bool { if (is_array($ids)) { if (count($ids) > 1) { throw new ApiException('禁止批量删除操作'); } $ids = $ids[0]; } if ($ids == 1) { throw new ApiException('超级管理员禁止删除'); } $query = $this->model->where('id', $ids); $query->auth($this->adminInfo['deptList']); $user = $query->findOrEmpty(); if ($user->isEmpty()) { throw new ApiException('没有权限操作该数据'); } if ($this->adminInfo['id'] > 1) { $role_ids = $user->roles->toArray() ?: []; if (!empty($role_ids)) { // 越权保护 if (!$this->roleProtect($this->adminInfo['roleList'], array_column($role_ids, 'id'))) { throw new ApiException('没有权限操作该角色数据'); } } } UserInfoCache::clearUserInfo($ids); UserAuthCache::clearUserAuth($ids); UserMenuCache::clearUserMenu($ids); return parent::destroy($ids); } /** * 用户登录 * @param string $username * @param string $password * @param string $type * @return array */ public function login(string $username, string $password, string $type): array { $adminInfo = $this->model->where('username', $username)->findOrEmpty(); $status = 1; $message = '登录成功'; if ($adminInfo->isEmpty()) { $message = '账号或密码错误,请重新输入!'; throw new ApiException($message); } if ($adminInfo->status === 2) { $status = 0; $message = '您已被禁止登录!'; } if (!password_verify($password, $adminInfo->password)) { $status = 0; $message = '账号或密码错误,请重新输入!'; } if ($status === 0) { // 登录事件 Event::emit('user.login', compact('username', 'status', 'message')); throw new ApiException($message); } $adminInfo->login_time = date('Y-m-d H:i:s'); $adminInfo->login_ip = request()->getRealIp(); $adminInfo->save(); $access_exp = config('plugin.saiadmin.saithink.access_exp', 3 * 3600); $token = JwtToken::generateToken([ 'access_exp' => $access_exp, 'id' => $adminInfo->id, 'username' => $adminInfo->username, 'type' => $type, 'plat' => 'saiadmin', ]); // 登录事件 $admin_id = $adminInfo->id; Event::emit('user.login', compact('username', 'status', 'message', 'admin_id')); return $token; } /** * 更新资料 * @param mixed $id * @param mixed $data * @return bool */ public function updateInfo($id, $data): bool { $this->model->update($data, ['id' => $id], ['realname', 'gender', 'phone', 'email', 'avatar', 'signed']); return true; } /** * 密码修改 * @param $adminId * @param $oldPassword * @param $newPassword * @return bool */ public function modifyPassword($adminId, $oldPassword, $newPassword): bool { $model = $this->model->findOrEmpty($adminId); if (password_verify($oldPassword, $model->password)) { $model->password = password_hash($newPassword, PASSWORD_DEFAULT); return $model->save(); } else { throw new ApiException('原密码错误'); } } /** * 修改数据 */ public function authEdit($id, $data) { if ($this->adminInfo['id'] > 1) { // 判断用户是否可以操作 $query = SystemUser::where('id', $id); $query->auth($this->adminInfo['deptList']); $user = $query->findOrEmpty(); if ($user->isEmpty()) { throw new ApiException('没有权限操作该数据'); } } parent::edit($id, $data); } /** * 部门保护 * @param $dept * @param $dept_id * @return bool */ public function deptProtect($dept, $dept_id): bool { // 部门保护 $deptIds = [$dept['id']]; $deptLevel = $dept['level'] . $dept['id'] . ','; $dept_ids = SystemDept::whereLike('level', $deptLevel . '%')->column('id'); $deptIds = array_merge($deptIds, $dept_ids); if (!in_array($dept_id, $deptIds)) { return false; } return true; } /** * 越权保护 * @param $roleList * @param $role_ids * @return bool */ public function roleProtect($roleList, $role_ids): bool { // 越权保护 $levelArr = array_column($roleList, 'level'); $maxLevel = max($levelArr); $currentLevel = SystemRole::whereIn('id', $role_ids)->max('level'); if ($currentLevel >= $maxLevel) { return false; } return true; } } ================================================ FILE: src/plugin/saiadmin/app/logic/tool/CrontabLogLogic.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\logic\tool; use plugin\saiadmin\app\model\tool\CrontabLog; use plugin\saiadmin\basic\think\BaseLogic; /** * 定时任务日志逻辑层 */ class CrontabLogLogic extends BaseLogic { /** * 构造函数 */ public function __construct() { $this->model = new CrontabLog(); } } ================================================ FILE: src/plugin/saiadmin/app/logic/tool/CrontabLogic.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\logic\tool; use Exception; use GuzzleHttp\Client; use GuzzleHttp\Exception\GuzzleException; use Webman\Channel\Client as ChannelClient; use plugin\saiadmin\app\model\tool\Crontab; use plugin\saiadmin\app\model\tool\CrontabLog; use plugin\saiadmin\basic\think\BaseLogic; use plugin\saiadmin\exception\ApiException; /** * 定时任务逻辑层 */ class CrontabLogic extends BaseLogic { /** * 构造函数 */ public function __construct() { $this->model = new Crontab(); } /** * 添加任务 */ public function add($data): bool { $second = $data['second']; $minute = $data['minute']; $hour = $data['hour']; $week = $data['week']; $day = $data['day']; $month = $data['month']; // 规则处理 $rule = match ($data['task_style']) { 1 => "0 {$minute} {$hour} * * *", 2 => "0 {$minute} * * * *", 3 => "0 {$minute} */{$hour} * * *", 4 => "0 */{$minute} * * * *", 5 => "*/{$second} * * * * *", 6 => "0 {$minute} {$hour} * * {$week}", 7 => "0 {$minute} {$hour} {$day} * *", 8 => "0 {$minute} {$hour} {$day} {$month} *", default => throw new ApiException("任务类型异常"), }; // 定时任务模型新增 $model = Crontab::create([ 'name' => $data['name'], 'type' => $data['type'], 'task_style' => $data['task_style'], 'rule' => $rule, 'target' => $data['target'], 'parameter' => $data['parameter'], 'status' => $data['status'], 'remark' => $data['remark'], ]); $id = $model->getKey(); // 连接到Channel服务 ChannelClient::connect(); ChannelClient::publish('crontab', ['args' => $id]); return true; } /** * 修改任务 */ public function edit($id, $data): bool { $second = $data['second']; $minute = $data['minute']; $hour = $data['hour']; $week = $data['week']; $day = $data['day']; $month = $data['month']; // 规则处理 $rule = match ($data['task_style']) { 1 => "0 {$minute} {$hour} * * *", 2 => "0 {$minute} * * * *", 3 => "0 {$minute} */{$hour} * * *", 4 => "0 */{$minute} * * * *", 5 => "*/{$second} * * * * *", 6 => "0 {$minute} {$hour} * * {$week}", 7 => "0 {$minute} {$hour} {$day} * *", 8 => "0 {$minute} {$hour} {$day} {$month} *", default => throw new ApiException("任务类型异常"), }; // 查询任务数据 $model = $this->model->findOrEmpty($id); if ($model->isEmpty()) { throw new ApiException('数据不存在'); } $result = $model->save([ 'name' => $data['name'], 'type' => $data['type'], 'task_style' => $data['task_style'], 'rule' => $rule, 'target' => $data['target'], 'parameter' => $data['parameter'], 'status' => $data['status'], 'remark' => $data['remark'], ]); if ($result) { // 连接到Channel服务 ChannelClient::connect(); ChannelClient::publish('crontab', ['args' => $id]); } // 修改任务数据 return $result; } /** * 删除定时任务 * @param $ids * @return bool * @throws Exception */ public function destroy($ids): bool { if (is_array($ids)) { if (count($ids) > 1) { throw new ApiException('禁止批量删除操作'); } $ids = $ids[0]; } $result = parent::destroy($ids); if ($result) { // 连接到Channel服务 ChannelClient::connect(); ChannelClient::publish('crontab', ['args' => $ids]); } return $result; } /** * 修改状态 * @param $id * @param $status * @return bool */ public function changeStatus($id, $status): bool { $model = $this->model->findOrEmpty($id); if ($model->isEmpty()) { throw new ApiException('数据不存在'); } $result = $model->save(['status' => $status]); if ($result) { // 连接到Channel服务 ChannelClient::connect(); ChannelClient::publish('crontab', ['args' => $id]); } return $result; } /** * 执行定时任务 * @param $id * @return bool */ public function run($id): bool { $info = $this->model->where('status', 1)->findOrEmpty($id); if ($info->isEmpty()) { return false; } $data['crontab_id'] = $info->id; $data['name'] = $info->name; $data['target'] = $info->target; $data['parameter'] = $info->parameter; switch ($info->type) { case 1: // URL任务GET $httpClient = new Client([ 'timeout' => 5, 'verify' => false, ]); try { $httpClient->request('GET', $info->target); $data['status'] = 1; CrontabLog::create($data); return true; } catch (GuzzleException $e) { $data['status'] = 2; $data['exception_info'] = $e->getMessage(); CrontabLog::create($data); return false; } case 2: // URL任务POST $httpClient = new Client([ 'timeout' => 5, 'verify' => false, ]); try { $res = $httpClient->request('POST', $info->target, [ 'form_params' => json_decode($info->parameter ?? '', true) ]); $data['status'] = 1; $data['exception_info'] = $res->getBody(); CrontabLog::create($data); return true; } catch (GuzzleException $e) { $data['status'] = 2; $data['exception_info'] = $e->getMessage(); CrontabLog::create($data); return false; } case 3: // 类任务 $class_name = $info->target; $method_name = 'run'; $class = new $class_name; if (method_exists($class, $method_name)) { $return = $class->$method_name($info->parameter); $data['status'] = 1; $data['exception_info'] = $return; CrontabLog::create($data); return true; } else { $data['status'] = 2; $data['exception_info'] = '类:' . $class_name . ',方法:run,未找到'; CrontabLog::create($data); return false; } default: return false; } } } ================================================ FILE: src/plugin/saiadmin/app/logic/tool/GenerateColumnsLogic.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\logic\tool; use plugin\saiadmin\app\model\tool\GenerateColumns; use plugin\saiadmin\basic\think\BaseLogic; use plugin\saiadmin\utils\Helper; /** * 代码生成业务字段逻辑层 */ class GenerateColumnsLogic extends BaseLogic { /** * 构造函数 */ public function __construct() { $this->model = new GenerateColumns(); } public function saveExtra($data) { $default_column = ['create_time', 'update_time', 'created_by', 'updated_by', 'delete_time', 'remark']; // 组装数据 foreach ($data as $k => $item) { if ($item['column_name'] == 'delete_time') { continue; } $column = [ 'table_id' => $item['table_id'], 'column_name' => $item['column_name'], 'column_comment' => $item['column_comment'], 'column_type' => $item['column_type'], 'default_value' => $item['default_value'], 'is_pk' => ($item['column_key'] == 'PRI') ? 2 : 1, 'is_required' => $item['is_nullable'] == 'NO' ? 2 : 1, 'query_type' => 'eq', 'view_type' => 'input', 'sort' => count($data) - $k, 'options' => $item['options'] ?? null ]; // 设置默认选项 if (!in_array($item['column_name'], $default_column) && empty($item['column_key'])) { $column = array_merge( $column, [ 'is_insert' => 2, 'is_edit' => 2, 'is_list' => 2, 'is_query' => 1, 'is_sort' => 1, ] ); } $keyList = [ 'column_comment', 'column_type', 'default_value', 'is_pk', 'is_required', 'is_insert', 'is_edit', 'is_list', 'is_query', 'is_sort', 'query_type', 'view_type', 'dict_type', 'options', 'sort', 'is_cover' ]; foreach ($keyList as $key) { if (isset($item[$key])) $column[$key] = $item[$key]; } GenerateColumns::create($this->fieldDispose($column)); } } public function update($data, $where) { $data['is_insert'] = $data['is_insert'] ? 2 : 1; $data['is_edit'] = $data['is_edit'] ? 2 : 1; $data['is_list'] = $data['is_list'] ? 2 : 1; $data['is_query'] = $data['is_query'] ? 2 : 1; $data['is_sort'] = $data['is_sort'] ? 2 : 1; $data['is_required'] = $data['is_required'] ? 2 : 1; $this->model->update($data, $where); } private function fieldDispose(array $column): array { $object = new class { public function viewTypeDispose(&$column): void { switch ($column['column_type']) { case 'varchar': $column['view_type'] = 'input'; break; // 富文本 case 'text': case 'longtext': $column['is_list'] = 1; $column['is_query'] = 1; $column['view_type'] = 'editor'; $options = [ 'height' => 400, ]; $column['options'] = $options; break; // 日期字段 case 'datetime': $column['view_type'] = 'date'; $options = [ 'mode' => 'datetime', 'value_format' => 'YYYY-MM-DD HH:mm:ss' ]; $column['options'] = $options; $column['query_type'] = 'between'; break; case 'date': $column['view_type'] = 'date'; $options = [ 'mode' => 'date', 'value_format' => 'YYYY-MM-DD' ]; $column['options'] = $options; $column['query_type'] = 'between'; break; } } public function columnName(&$column): void { if (stristr($column['column_name'], 'name')) { $column['is_query'] = 2; $column['is_required'] = 2; $column['query_type'] = 'like'; } if (stristr($column['column_name'], 'title')) { $column['is_query'] = 2; $column['is_required'] = 2; $column['query_type'] = 'like'; } if (stristr($column['column_name'], 'type')) { $column['is_query'] = 2; $column['is_required'] = 2; $column['query_type'] = 'eq'; } if (stristr($column['column_name'], 'image')) { $column['is_query'] = 1; $column['view_type'] = 'uploadImage'; $options = [ 'multiple' => false, 'limit' => 1, ]; $column['options'] = $options; } if (stristr($column['column_name'], 'file')) { $column['is_query'] = 1; $column['view_type'] = 'uploadFile'; $options = [ 'multiple' => false, 'limit' => 1, ]; $column['options'] = $options; } if (stristr($column['column_name'], 'attach')) { $column['is_query'] = 1; $column['view_type'] = 'uploadFile'; $options = [ 'multiple' => false, 'limit' => 1, ]; $column['options'] = $options; } if ($column['column_name'] === 'sort') { $column['view_type'] = 'inputNumber'; } if ($column['column_name'] === 'status') { $column['view_type'] = 'radio'; $column['dict_type'] = 'data_status'; } if (stristr($column['column_name'], 'is_')) { $column['view_type'] = 'radio'; $column['dict_type'] = 'yes_or_no'; } } }; if (!$column['is_cover']) { $object->viewTypeDispose($column); $object->columnName($column); } $column['options'] = json_encode($column['options'], JSON_UNESCAPED_UNICODE); return $column; } } ================================================ FILE: src/plugin/saiadmin/app/logic/tool/GenerateTablesLogic.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\logic\tool; use plugin\saiadmin\app\cache\UserMenuCache; use plugin\saiadmin\app\logic\system\DatabaseLogic; use plugin\saiadmin\app\model\system\SystemMenu; use plugin\saiadmin\app\model\tool\GenerateTables; use plugin\saiadmin\app\model\tool\GenerateColumns; use plugin\saiadmin\exception\ApiException; use plugin\saiadmin\basic\think\BaseLogic; use plugin\saiadmin\utils\Helper; use plugin\saiadmin\utils\code\CodeZip; use plugin\saiadmin\utils\code\CodeEngine; /** * 代码生成业务逻辑层 */ class GenerateTablesLogic extends BaseLogic { protected $columnLogic = null; protected $dataLogic = null; /** * 构造函数 */ public function __construct() { $this->model = new GenerateTables(); $this->columnLogic = new GenerateColumnsLogic(); $this->dataLogic = new DatabaseLogic(); } /** * 删除表和字段信息 * @param $ids * @return bool */ public function destroy($ids): bool { return $this->transaction(function () use ($ids) { parent::destroy($ids); GenerateColumns::destroy(function ($query) use ($ids) { $query->where('table_id', 'in', $ids); }); return true; }); } /** * 装载表信息 * @param $names * @param $source * @return void */ public function loadTable($names, $source): void { $data = config('think-orm.connections'); $config = $data[$source]; if (!$config) { throw new ApiException('数据库配置读取失败'); } $prefix = $config['prefix'] ?? ''; foreach ($names as $item) { $class_name = $item['name']; if (!empty($prefix)) { $class_name = Helper::str_replace_once($prefix, '', $class_name); } $class_name = Helper::camel($class_name); $tableInfo = [ 'table_name' => $item['name'], 'table_comment' => $item['comment'], 'class_name' => $class_name, 'business_name' => Helper::get_business($item['name']), 'belong_menu_id' => 80, 'menu_name' => $item['comment'], 'tpl_category' => 'single', 'template' => 'app', 'stub' => 'think', 'namespace' => '', 'package_name' => '', 'source' => $source, 'generate_menus' => 'index,save,update,read,destroy', ]; $model = GenerateTables::create($tableInfo); $columns = $this->dataLogic->getColumnList($item['name'], $source); foreach ($columns as &$column) { $column['table_id'] = $model->id; $column['is_cover'] = false; } $this->columnLogic->saveExtra($columns); } } /** * 同步表字段信息 * @param $id * @return void */ public function sync($id) { $model = $this->model->findOrEmpty($id); // 拉取已有数据表信息 $queryModel = $this->columnLogic->model->where('table_id', $id); $columnLogicData = $this->columnLogic->getAll($queryModel); $columnLogicList = []; foreach ($columnLogicData as $item) { $columnLogicList[$item['column_name']] = $item; } GenerateColumns::destroy(function ($query) use ($id) { $query->where('table_id', $id); }); $columns = $this->dataLogic->getColumnList($model->table_name, $model->source ?? ''); foreach ($columns as &$column) { $column['table_id'] = $model->id; $column['is_cover'] = false; if (isset($columnLogicList[$column['column_name']])) { // 存在历史信息的情况 $getcolumnLogicItem = $columnLogicList[$column['column_name']]; if ($getcolumnLogicItem['column_type'] == $column['column_type']) { $column['is_cover'] = true; foreach ($getcolumnLogicItem as $key => $item) { $array = [ 'column_comment', 'column_type', 'is_pk', 'is_required', 'is_insert', 'is_edit', 'is_list', 'is_query', 'is_sort', 'query_type', 'view_type', 'dict_type', 'options', 'sort', 'is_cover' ]; if (in_array($key, $array)) { $column[$key] = $item; } } } } } $this->columnLogic->saveExtra($columns); } /** * 代码预览 * @param $id * @return array */ public function preview($id): array { $data = $this->renderData($id); $codeEngine = new CodeEngine($data); $controllerContent = $codeEngine->renderContent('php', 'controller.stub'); $logicContent = $codeEngine->renderContent('php', 'logic.stub'); $modelContent = $codeEngine->renderContent('php', 'model.stub'); $validateContent = $codeEngine->renderContent('php', 'validate.stub'); $sqlContent = $codeEngine->renderContent('sql', 'sql.stub'); $indexContent = $codeEngine->renderContent('vue', 'index.stub'); $editContent = $codeEngine->renderContent('vue', 'edit-dialog.stub'); $searchContent = $codeEngine->renderContent('vue', 'table-search.stub'); $apiContent = $codeEngine->renderContent('ts', 'api.stub'); // 返回生成内容 return [ [ 'tab_name' => 'controller.php', 'name' => 'controller', 'lang' => 'php', 'code' => $controllerContent ], [ 'tab_name' => 'logic.php', 'name' => 'logic', 'lang' => 'php', 'code' => $logicContent ], [ 'tab_name' => 'model.php', 'name' => 'model', 'lang' => 'php', 'code' => $modelContent ], [ 'tab_name' => 'validate.php', 'name' => 'validate', 'lang' => 'php', 'code' => $validateContent ], [ 'tab_name' => 'sql.sql', 'name' => 'sql', 'lang' => 'sql', 'code' => $sqlContent ], [ 'tab_name' => 'index.vue', 'name' => 'index', 'lang' => 'html', 'code' => $indexContent ], [ 'tab_name' => 'edit-dialog.vue', 'name' => 'edit-dialog', 'lang' => 'html', 'code' => $editContent ], [ 'tab_name' => 'table-search.vue', 'name' => 'table-search', 'lang' => 'html', 'code' => $searchContent ], [ 'tab_name' => 'api.ts', 'name' => 'api', 'lang' => 'javascript', 'code' => $apiContent ] ]; } /** * 生成到模块 * @param $id */ public function genModule($id) { $data = $this->renderData($id); // 生成文件到模块 $codeEngine = new CodeEngine($data); $codeEngine->generateBackend('controller', $codeEngine->renderContent('php', 'controller.stub')); $codeEngine->generateBackend('logic', $codeEngine->renderContent('php', 'logic.stub')); $codeEngine->generateBackend('model', $codeEngine->renderContent('php', 'model.stub')); $codeEngine->generateBackend('validate', $codeEngine->renderContent('php', 'validate.stub')); $codeEngine->generateFrontend('index', $codeEngine->renderContent('vue', 'index.stub')); $codeEngine->generateFrontend('edit-dialog', $codeEngine->renderContent('vue', 'edit-dialog.stub')); $codeEngine->generateFrontend('table-search', $codeEngine->renderContent('vue', 'table-search.stub')); $codeEngine->generateFrontend('api', $codeEngine->renderContent('ts', 'api.stub')); } /** * 处理数据 * @param $id * @return array */ protected function renderData($id): array { $table = $this->model->findOrEmpty($id); if (!in_array($table['template'], ["plugin", "app"])) { throw new ApiException('应用类型必须为plugin或者app'); } if (empty($table['namespace'])) { throw new ApiException('请先设置应用名称'); } $columns = $this->columnLogic->where('table_id', $id) ->order('sort', 'desc') ->select() ->toArray(); $pk = 'id'; foreach ($columns as &$column) { if ($column['is_pk'] == 2) { $pk = $column['column_name']; } if ($column['column_name'] == 'delete_time') { unset($column['column_name']); } } // 处理特殊变量 if ($table['template'] == 'plugin') { $namespace_start = "plugin\\" . $table['namespace'] . "\\app\\admin\\"; $namespace_start_model = "plugin\\" . $table['namespace'] . "\\app\\"; $namespace_end = "\\" . $table['package_name']; $url_path = 'app/' . $table['namespace'] . '/admin/' . $table['package_name'] . '/' . $table['class_name']; $route = 'app/'; } else { $namespace_start = "app\\" . $table['namespace'] . "\\"; $namespace_start_model = "app\\" . $table['namespace'] . "\\"; $namespace_end = "\\" . $table['package_name']; $url_path = $table['namespace'] . '/' . $table['package_name'] . '/' . $table['class_name']; $route = ''; } $config = config('think-orm'); $data = $table->toArray(); $data['pk'] = $pk; $data['namespace_start'] = $namespace_start; $data['namespace_start_model'] = $namespace_start_model; $data['namespace_end'] = $namespace_end; $data['url_path'] = $url_path; $data['route'] = $route; $data['tables'] = [$data]; $data['columns'] = $columns; $data['db_source'] = $config['default'] ?? 'mysql'; return $data; } /** * 生成到模块 */ public function generateFile($id) { $table = $this->model->where('id', $id)->findOrEmpty(); if ($table->isEmpty()) { throw new ApiException('请选择要生成的表'); } $debug = config('app.debug', true); if (!$debug) { throw new ApiException('非调试模式下,不允许生成文件'); } $this->updateMenu($table); $this->genModule($id); UserMenuCache::clearMenuCache(); } /** * 代码生成下载 */ public function generate($idsArr): array { $zip = new CodeZip(); $tables = $this->model->where('id', 'in', $idsArr)->select()->toArray(); foreach ($idsArr as $table_id) { $data = $this->renderData($table_id); $data['tables'] = $tables; $codeEngine = new CodeEngine($data); $codeEngine->generateTemp(); } $filename = 'saiadmin.zip'; $download = $zip->compress(); return compact('filename', 'download'); } /** * 处理菜单列表 * @param $tables */ public function updateMenu($tables) { /*不存在的情况下进行新建操作*/ $url_path = $tables['namespace'] . ":" . $tables['package_name'] . ':' . $tables['business_name']; $code = $tables['namespace'] . "/" . $tables['package_name'] . '/' . $tables['business_name']; $path = $tables['package_name'] . '/' . $tables['business_name']; $component = $tables['namespace'] . "/" . $tables['package_name'] . '/' . $tables['business_name']; /*先获取一下已有的路由中是否包含当前ID的路由的核心信息*/ $model = new SystemMenu(); $tableMenu = $model->where('generate_id', $tables['id'])->findOrEmpty(); $fistMenu = [ 'parent_id' => $tables['belong_menu_id'], 'name' => $tables['menu_name'], 'code' => $code, 'path' => $path, 'icon' => 'ri:home-2-line', 'component' => "/plugin/$component/index", 'type' => 2, 'sort' => 100, 'is_iframe' => 2, 'is_keep_alive' => 2, 'is_hidden' => 2, 'is_fixed_tab' => 2, 'is_full_page' => 2, 'generate_id' => $tables['id'] ]; if ($tableMenu->isEmpty()) { $temp = SystemMenu::create($fistMenu); $fistMenuId = $temp->id; } else { $fistMenu['id'] = $tableMenu['id']; $tableMenu->save($fistMenu); $fistMenuId = $tableMenu['id']; } /*开始进行子权限的判定操作*/ $childNodes = [ ['name' => '列表', 'key' => 'index'], ['name' => '保存', 'key' => 'save'], ['name' => '更新', 'key' => 'update'], ['name' => '读取', 'key' => 'read'], ['name' => '删除', 'key' => 'destroy'], ]; foreach ($childNodes as $node) { $nodeData = $model->where('parent_id', $fistMenuId)->where('generate_key', $node['key'])->findOrEmpty(); $childNodeData = [ 'parent_id' => $fistMenuId, 'name' => $node['name'], 'slug' => "$url_path:{$node['key']}", 'type' => 3, 'sort' => 100, 'is_iframe' => 2, 'is_keep_alive' => 2, 'is_hidden' => 2, 'is_fixed_tab' => 2, 'is_full_page' => 2, 'generate_key' => $node['key'] ]; if (!empty($nodeData)) { $childNodeData['id'] = $nodeData['id']; $nodeData->save($childNodeData); } else { $menuModel = new SystemMenu(); $menuModel->save($childNodeData); } } } /** * 获取数据表字段信息 * @param $table_id * @return mixed */ public function getTableColumns($table_id): mixed { $query = $this->columnLogic->where('table_id', $table_id); return $this->columnLogic->getAll($query); } /** * 编辑数据 * @param $id * @param $data * @return mixed */ public function edit($id, $data): mixed { $columns = $data['columns']; unset($data['columns']); if (!empty($data['belong_menu_id'])) { $data['belong_menu_id'] = is_array($data['belong_menu_id']) ? array_pop($data['belong_menu_id']) : $data['belong_menu_id']; } else { $data['belong_menu_id'] = 0; } $data['generate_menus'] = implode(',', $data['generate_menus']); if (empty($data['options'])) { unset($data['options']); } $data['options'] = json_encode($data['options'], JSON_UNESCAPED_UNICODE); // 更新业务表 $this->update($data, ['id' => $id]); // 更新业务字段表 foreach ($columns as $column) { if ($column['options']) { $column['options'] = json_encode($column['options'], JSON_NUMERIC_CHECK); } $this->columnLogic->update($column, ['id' => $column['id']]); } return true; } } ================================================ FILE: src/plugin/saiadmin/app/middleware/CheckAuth.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\middleware; use Webman\Http\Request; use Webman\Http\Response; use Webman\MiddlewareInterface; use plugin\saiadmin\app\cache\UserAuthCache; use plugin\saiadmin\app\cache\ReflectionCache; use plugin\saiadmin\exception\SystemException; /** * 权限检查中间件 */ class CheckAuth implements MiddlewareInterface { public function process(Request $request, callable $handler) : Response { $controller = $request->controller; $action = $request->action; // 通过反射获取控制器哪些方法不需要登录 $noNeedLogin = ReflectionCache::getNoNeedLogin($controller); // 不登录访问,无需权限验证 if (in_array($action, $noNeedLogin)) { return $handler($request); } // 登录信息 $token = getCurrentInfo(); if ($token === false) { throw new SystemException('用户信息读取失败,无法访问或操作'); } // 系统默认超级管理员,无需权限验证 if ($token['id'] === 1) { return $handler($request); } // 2. 获取接口权限属性 (使用缓存类) $permissions = ReflectionCache::getPermissionAttributes($controller, $action); if (!empty($permissions) && !empty($permissions['slug'])) { // 用户权限缓存 $auth = UserAuthCache::getUserAuth($token['id']); if (!$this->checkPermissions($permissions, $auth)) { throw new SystemException('权限不足,无法访问或操作'); } } return $handler($request); } /** * 检查权限 */ private function checkPermissions(array $attr, array $userPermissions): bool { // 直接对比 slug return in_array($attr['slug'], $userPermissions); } } ================================================ FILE: src/plugin/saiadmin/app/middleware/CheckLogin.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\middleware; use Webman\Http\Request; use Webman\Http\Response; use Webman\MiddlewareInterface; use Tinywan\Jwt\JwtToken; use plugin\saiadmin\app\cache\ReflectionCache; use plugin\saiadmin\exception\ApiException; /** * 登录检查中间件 */ class CheckLogin implements MiddlewareInterface { public function process(Request $request, callable $handler): Response { // 通过反射获取控制器哪些方法不需要登录 $noNeedLogin = ReflectionCache::getNoNeedLogin($request->controller); // 访问的方法需要登录 if (!in_array($request->action, $noNeedLogin)) { try { $token = JwtToken::getExtend(); } catch (\Throwable $e) { throw new ApiException('您的登录凭证错误或者已过期,请重新登录', 401); } if ($token['plat'] !== 'saiadmin') { throw new ApiException('登录凭证校验失败'); } $request->setHeader('check_login', true); $request->setHeader('check_admin', $token); } return $handler($request); } } ================================================ FILE: src/plugin/saiadmin/app/middleware/CrossDomain.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\middleware; use Webman\Http\Request; use Webman\Http\Response; use Webman\MiddlewareInterface; /** * 跨域中间件 */ class CrossDomain implements MiddlewareInterface { public function process(Request $request, callable $handler) : Response { // 如果是options请求则返回一个空响应,否则继续向洋葱芯穿越,并得到一个响应 $response = $request->method() == 'OPTIONS' ? response('') : $handler($request); // 给响应添加跨域相关的http头 $response->withHeaders([ 'Access-Control-Allow-Credentials' => 'true', 'Access-Control-Allow-Origin' => $request->header('origin', '*'), 'Access-Control-Allow-Methods' => $request->header('access-control-request-method', '*'), 'Access-Control-Allow-Headers' => $request->header('access-control-request-headers', '*'), ]); return $response; } } ================================================ FILE: src/plugin/saiadmin/app/middleware/SystemLog.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\middleware; use Webman\Event\Event; use Webman\Http\Request; use Webman\Http\Response; use Webman\MiddlewareInterface; use plugin\saiadmin\exception\ApiException; use plugin\saiadmin\app\cache\ReflectionCache; class SystemLog implements MiddlewareInterface { /** * @param Request $request * @param callable $handler * @return Response */ public function process(Request $request, callable $handler): Response { // 通过反射获取控制器哪些方法不需要登录 $noNeedLogin = ReflectionCache::getNoNeedLogin($request->controller); // 访问的方法需要登录 if (!in_array($request->action, $noNeedLogin)) { try { // 记录日志 Event::emit('user.operateLog', true); } catch (\Throwable $e) { throw new ApiException('登录凭获取失败,请检查'); } } return $handler($request); } } ================================================ FILE: src/plugin/saiadmin/app/model/system/SystemAttachment.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\model\system; use plugin\saiadmin\basic\think\BaseModel; /** * 附件模型 * * sa_system_attachment 附件信息表 * * @property $id 主键 * @property $category_id 文件分类 * @property $storage_mode 存储模式 * @property $origin_name 原文件名 * @property $object_name 新文件名 * @property $hash 文件hash * @property $mime_type 资源类型 * @property $storage_path 存储目录 * @property $suffix 文件后缀 * @property $size_byte 字节数 * @property $size_info 文件大小 * @property $url url地址 * @property $remark 备注 * @property $created_by 创建者 * @property $updated_by 更新者 * @property $create_time 创建时间 * @property $update_time 修改时间 */ class SystemAttachment extends BaseModel { /** * 数据表主键 * @var string */ protected $pk = 'id'; protected $table = 'sa_system_attachment'; /** * 原文件名搜索 */ public function searchOriginNameAttr($query, $value) { $query->where('origin_name', 'like', '%' . $value . '%'); } /** * 文件类型搜索 */ public function searchMimeTypeAttr($query, $value) { $query->where('mime_type', 'like', $value . '/%'); } } ================================================ FILE: src/plugin/saiadmin/app/model/system/SystemCategory.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\model\system; use plugin\saiadmin\basic\think\BaseModel; /** * 附件分类模型 * * sa_system_category 附件分类表 * * @property $id 分类ID * @property $parent_id 父id * @property $level 组集关系 * @property $category_name 分类名称 * @property $sort 排序 * @property $status 状态 * @property $remark 备注 * @property $created_by 创建者 * @property $updated_by 更新者 * @property $create_time 创建时间 * @property $update_time 修改时间 */ class SystemCategory extends BaseModel { /** * 数据表主键 * @var string */ protected $pk = 'id'; protected $table = 'sa_system_category'; /** * 分类名称搜索 */ public function searchCategoryNameAttr($query, $value) { $query->where('category_name', 'like', '%' . $value . '%'); } } ================================================ FILE: src/plugin/saiadmin/app/model/system/SystemConfig.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\model\system; use plugin\saiadmin\basic\think\BaseModel; /** * 参数配置模型 * * sa_system_config 参数配置信息表 * * @property $id 编号 * @property $group_id 组id * @property $key 配置键名 * @property $value 配置值 * @property $name 配置名称 * @property $input_type 数据输入类型 * @property $config_select_data 配置选项数据 * @property $sort 排序 * @property $remark 备注 * @property $created_by 创建人 * @property $updated_by 更新人 * @property $create_time 创建时间 * @property $update_time 修改时间 */ class SystemConfig extends BaseModel { /** * 数据表主键 * @var string */ protected $pk = 'id'; protected $table = 'sa_system_config'; public function getConfigSelectDataAttr($value) { return json_decode($value ?? '', true); } } ================================================ FILE: src/plugin/saiadmin/app/model/system/SystemConfigGroup.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\model\system; use plugin\saiadmin\basic\think\BaseModel; /** * 参数配置分组模型 * * sa_system_config_group 参数配置分组表 * * @property $id 主键 * @property $name 字典名称 * @property $code 字典标示 * @property $remark 备注 * @property $created_by 创建人 * @property $updated_by 更新人 * @property $create_time 创建时间 * @property $update_time 修改时间 */ class SystemConfigGroup extends BaseModel { /** * 数据表主键 * @var string */ protected $pk = 'id'; protected $table = 'sa_system_config_group'; /** * 关联配置列表 */ public function configs() { return $this->hasMany(SystemConfig::class, 'group_id', 'id'); } /** * 名称搜索 */ public function searchNameAttr($query, $value) { return $query->where('name', 'like', '%' . $value . '%'); } /** * 编码搜索 */ public function searchCodeAttr($query, $value) { return $query->where('code', 'like', '%' . $value . '%'); } } ================================================ FILE: src/plugin/saiadmin/app/model/system/SystemDept.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\model\system; use plugin\saiadmin\basic\think\BaseModel; /** * 部门模型 * * sa_system_dept 部门表 * * @property $id 编号 * @property $parent_id 父级ID,0为根节点 * @property $name 部门名称 * @property $code 部门编码 * @property $leader_id 部门负责人ID * @property $level 祖级列表,格式: 0,1,5, * @property $sort 排序,数字越小越靠前 * @property $status 状态: 1启用, 0禁用 * @property $remark 备注 * @property $created_by 创建者 * @property $updated_by 更新者 * @property $create_time 创建时间 * @property $update_time 修改时间 */ class SystemDept extends BaseModel { /** * 数据表主键 * @var string */ protected $pk = 'id'; protected $table = 'sa_system_dept'; /** * 权限范围 */ public function scopeAuth($query, $value) { if (!empty($value)) { $deptIds = [$value['id']]; $deptLevel = $value['level'] . $value['id'] . ','; $ids = static::whereLike('level', $deptLevel . '%')->column('id'); $deptIds = array_merge($deptIds, $ids); $query->whereIn('id', $deptIds); } } /** * 部门领导 */ public function leader() { return $this->hasOne(SystemUser::class, 'id', 'leader_id'); } } ================================================ FILE: src/plugin/saiadmin/app/model/system/SystemDictData.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\model\system; use plugin\saiadmin\basic\think\BaseModel; /** * 字典数据模型 * * sa_system_dict_data 字典数据表 * * @property $id 主键 * @property $type_id 字典类型ID * @property $label 字典标签 * @property $value 字典值 * @property $color 字典颜色 * @property $code 字典标示 * @property $sort 排序 * @property $status 状态 * @property $remark 备注 * @property $created_by 创建者 * @property $updated_by 更新者 * @property $create_time 创建时间 * @property $update_time 修改时间 */ class SystemDictData extends BaseModel { /** * 数据表主键 * @var string */ protected $pk = 'id'; protected $table = 'sa_system_dict_data'; /** * 关键字搜索 */ public function searchKeywordsAttr($query, $value) { $query->where('label|code', 'LIKE', "%$value%"); } } ================================================ FILE: src/plugin/saiadmin/app/model/system/SystemDictType.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\model\system; use plugin\saiadmin\basic\think\BaseModel; /** * 字典类型模型 * * sa_system_dict_type 字典类型表 * * @property $id 主键 * @property $name 字典名称 * @property $code 字典标示 * @property $status 状态 * @property $remark 备注 * @property $created_by 创建者 * @property $updated_by 更新者 * @property $create_time 创建时间 * @property $update_time 修改时间 */ class SystemDictType extends BaseModel { /** * 数据表主键 * @var string */ protected $pk = 'id'; protected $table = 'sa_system_dict_type'; /** * 关联字典数据 */ public function dicts() { return $this->hasMany(SystemDictData::class, 'type_id', 'id'); } } ================================================ FILE: src/plugin/saiadmin/app/model/system/SystemLoginLog.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\model\system; use plugin\saiadmin\basic\think\BaseModel; /** * 登录日志模型 * * sa_system_login_log 登录日志表 * * @property $id 主键 * @property $username 用户名 * @property $ip 登录IP地址 * @property $ip_location IP所属地 * @property $os 操作系统 * @property $browser 浏览器 * @property $status 登录状态 * @property $message 提示消息 * @property $login_time 登录时间 * @property $remark 备注 * @property $created_by 创建者 * @property $updated_by 更新者 * @property $create_time 创建时间 * @property $update_time 更新时间 */ class SystemLoginLog extends BaseModel { /** * 数据表主键 * @var string */ protected $pk = 'id'; protected $table = 'sa_system_login_log'; /** * 时间范围搜索 */ public function searchLoginTimeAttr($query, $value) { $query->whereTime('login_time', 'between', $value); } } ================================================ FILE: src/plugin/saiadmin/app/model/system/SystemMail.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\model\system; use plugin\saiadmin\basic\think\BaseModel; /** * 邮件记录模型 * * sa_system_mail 邮件记录 * * @property $id 编号 * @property $gateway 网关 * @property $from 发送人 * @property $email 接收人 * @property $code 验证码 * @property $content 邮箱内容 * @property $status 发送状态 * @property $response 返回结果 * @property $create_time 创建时间 * @property $update_time 修改时间 */ class SystemMail extends BaseModel { /** * 数据表主键 * @var string */ protected $pk = 'id'; protected $table = 'sa_system_mail'; /** * 发送人搜索 */ public function searchFromAttr($query, $value) { $query->where('from', 'like', '%' . $value . '%'); } /** * 接收人搜索 */ public function searchEmailAttr($query, $value) { $query->where('email', 'like', '%' . $value . '%'); } } ================================================ FILE: src/plugin/saiadmin/app/model/system/SystemMenu.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\model\system; use plugin\saiadmin\basic\think\BaseModel; /** * 菜单模型 * * sa_system_menu 菜单权限表 * * @property $id * @property $parent_id 父级ID * @property $name 菜单名称 * @property $code 组件名称 * @property $slug 权限标识,如 user:list, user:add * @property $type 类型: 1目录, 2菜单, 3按钮/API * @property $path 路由地址或API路径 * @property $component 前端组件路径,如 layout/User * @property $method 请求方式 * @property $icon 图标 * @property $sort 排序 * @property $link_url 外部链接 * @property $is_iframe 是否iframe * @property $is_keep_alive 是否缓存 * @property $is_hidden 是否隐藏 * @property $is_fixed_tab 是否固定标签页 * @property $is_full_page 是否全屏 * @property $generate_id 生成id * @property $generate_key 生成key * @property $status 状态 * @property $remark * @property $created_by 创建者 * @property $updated_by 更新者 * @property $create_time 创建时间 * @property $update_time 修改时间 */ class SystemMenu extends BaseModel { // 完整数据库表名称 protected $table = 'sa_system_menu'; // 主键 protected $pk = 'id'; /** * Id搜索 */ public function searchIdAttr($query, $value) { $query->whereIn('id', $value); } public function searchNameAttr($query, $value) { $query->where('name', 'like', '%' . $value . '%'); } public function searchPathAttr($query, $value) { $query->where('path', 'like', '%' . $value . '%'); } public function searchMenuAttr($query, $value) { if (!empty($value)) { $query->whereIn('type', [1, 2]); } } /** * Type搜索 */ public function searchTypeAttr($query, $value) { if (is_array($value)) { $query->whereIn('type', $value); } else { $query->where('type', $value); } } } ================================================ FILE: src/plugin/saiadmin/app/model/system/SystemOperLog.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\model\system; use plugin\saiadmin\basic\think\BaseModel; /** * 操作日志模型 * * sa_system_oper_log 操作日志表 * * @property $id 主键 * @property $username 用户名 * @property $app 应用名称 * @property $method 请求方式 * @property $router 请求路由 * @property $service_name 业务名称 * @property $ip 请求IP地址 * @property $ip_location IP所属地 * @property $request_data 请求数据 * @property $remark 备注 * @property $created_by 创建者 * @property $updated_by 更新者 * @property $create_time 创建时间 * @property $update_time 更新时间 */ class SystemOperLog extends BaseModel { /** * 数据表主键 * @var string */ protected $pk = 'id'; protected $table = 'sa_system_oper_log'; } ================================================ FILE: src/plugin/saiadmin/app/model/system/SystemPost.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\model\system; use plugin\saiadmin\basic\think\BaseModel; /** * 岗位模型 * * sa_system_post 岗位信息表 * * @property $id 主键 * @property $name 岗位名称 * @property $code 岗位代码 * @property $sort 排序 * @property $status 状态 * @property $remark 备注 * @property $created_by 创建者 * @property $updated_by 更新者 * @property $create_time 创建时间 * @property $update_time 修改时间 */ class SystemPost extends BaseModel { /** * 数据表主键 * @var string */ protected $pk = 'id'; protected $table = 'sa_system_post'; } ================================================ FILE: src/plugin/saiadmin/app/model/system/SystemRole.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\model\system; use plugin\saiadmin\basic\think\BaseModel; /** * 角色模型 * * sa_system_role 角色表 * * @property $id * @property $name 角色名称 * @property $code 角色标识,如: hr_manager * @property $level 角色级别:用于行政控制,不可操作级别大于自己的角色 * @property $data_scope 数据范围: 1全部, 2本部门及下属, 3本部门, 4仅本人, 5自定义 * @property $remark 备注 * @property $sort * @property $status 状态: 1启用, 0禁用 * @property $created_by 创建者 * @property $updated_by 更新者 * @property $create_time 创建时间 * @property $update_time 修改时间 */ class SystemRole extends BaseModel { /** * 数据表主键 * @var string */ protected $pk = 'id'; /** * 数据表完整名称 * @var string */ protected $table = 'sa_system_role'; /** * 权限范围 */ public function scopeAuth($query, $value) { $id = $value['id']; $roles = $value['roles']; if ($id > 1) { $ids = []; foreach ($roles as $item) { $ids[] = $item['id']; $temp = static::whereRaw('FIND_IN_SET("' . $item['id'] . '", level) > 0')->column('id'); $ids = array_merge($ids, $temp); } $query->where('id', 'in', array_unique($ids)); } } /** * 通过中间表获取菜单 */ public function menus() { return $this->belongsToMany(SystemMenu::class, SystemRoleMenu::class, 'menu_id', 'role_id'); } /** * 通过中间表获取部门 */ public function depts() { return $this->belongsToMany(SystemDept::class, SystemRoleDept::class, 'dept_id', 'role_id'); } } ================================================ FILE: src/plugin/saiadmin/app/model/system/SystemRoleDept.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\model\system; use think\model\Pivot; /** * 角色部门关联模型 * * sa_system_role_dept 角色-自定义数据权限关联 * * @property $id * @property $role_id * @property $dept_id */ class SystemRoleDept extends Pivot { protected $pk = 'id'; protected $table = 'sa_system_role_dept'; } ================================================ FILE: src/plugin/saiadmin/app/model/system/SystemRoleMenu.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\model\system; use think\model\Pivot; /** * 角色菜单关联模型 * * sa_system_role_menu 角色权限关联 * * @property $id * @property $role_id * @property $menu_id */ class SystemRoleMenu extends Pivot { protected $pk = 'id'; protected $table = 'sa_system_role_menu'; } ================================================ FILE: src/plugin/saiadmin/app/model/system/SystemUser.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\model\system; use plugin\saiadmin\basic\think\BaseModel; /** * 用户信息模型 * * sa_system_user 用户表 * * @property $id * @property $username 登录账号 * @property $password 加密密码 * @property $realname 真实姓名 * @property $gender 性别 * @property $avatar 头像 * @property $email 邮箱 * @property $phone 手机号 * @property $signed 个性签名 * @property $dashboard 工作台 * @property $dept_id 主归属部门 * @property $is_super 是否超级管理员: 1是 * @property $status 状态: 1启用, 2禁用 * @property $remark 备注 * @property $login_time 最后登录时间 * @property $login_ip 最后登录IP * @property $created_by 创建者 * @property $updated_by 更新者 * @property $create_time 创建时间 * @property $update_time 修改时间 */ class SystemUser extends BaseModel { /** * 数据表主键 * @var string */ protected $pk = 'id'; /** * 数据表完整名称 * @var string */ protected $table = 'sa_system_user'; public function searchKeywordAttr($query, $value) { if ($value) { $query->where('username|realname|phone', 'like', '%' . $value . '%'); } } /** * 权限范围 - 过滤部门用户 */ public function scopeAuth($query, $value) { if (!empty($value)) { $deptIds = [$value['id']]; $deptLevel = $value['level'] . $value['id'] . ','; $dept_ids = SystemDept::whereLike('level', $deptLevel . '%')->column('id'); $deptIds = array_merge($deptIds, $dept_ids); $query->whereIn('dept_id', $deptIds); } } /** * 通过中间表关联角色 */ public function roles() { return $this->belongsToMany(SystemRole::class, SystemUserRole::class, 'role_id', 'user_id'); } /** * 通过中间表关联岗位 */ public function posts() { return $this->belongsToMany(SystemPost::class, SystemUserPost::class, 'post_id', 'user_id'); } /** * 通过中间表关联部门 */ public function depts() { return $this->belongsTo(SystemDept::class, 'dept_id', 'id'); } } ================================================ FILE: src/plugin/saiadmin/app/model/system/SystemUserPost.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\model\system; use think\model\Pivot; /** * 用户岗位关联模型 * * sa_system_user_post 用户与岗位关联表 * * @property $id 主键 * @property $user_id 用户主键 * @property $post_id 岗位主键 */ class SystemUserPost extends Pivot { protected $pk = 'id'; protected $table = 'sa_system_user_post'; } ================================================ FILE: src/plugin/saiadmin/app/model/system/SystemUserRole.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\model\system; use think\model\Pivot; /** * 用户角色关联模型 * * sa_system_user_role 用户角色关联 * * @property $id * @property $user_id * @property $role_id */ class SystemUserRole extends Pivot { protected $pk = 'id'; protected $table = 'sa_system_user_role'; /** * 获取角色id * @param mixed $user_id * @return array */ public static function getRoleIds($user_id): array { return static::where('user_id', $user_id)->column('role_id'); } } ================================================ FILE: src/plugin/saiadmin/app/model/tool/Crontab.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\model\tool; use plugin\saiadmin\basic\think\BaseModel; /** * 定时任务模型 * * sa_tool_crontab 定时任务信息表 * * @property $id 主键 * @property $name 任务名称 * @property $type 任务类型 * @property $target 调用任务字符串 * @property $parameter 调用任务参数 * @property $task_style 执行类型 * @property $rule 任务执行表达式 * @property $status 状态 * @property $remark 备注 * @property $created_by 创建者 * @property $updated_by 更新者 * @property $create_time 创建时间 * @property $update_time 修改时间 */ class Crontab extends BaseModel { /** * 数据表主键 * @var string */ protected $pk = 'id'; protected $table = 'sa_tool_crontab'; } ================================================ FILE: src/plugin/saiadmin/app/model/tool/CrontabLog.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\model\tool; use plugin\saiadmin\basic\think\BaseModel; /** * 定时任务日志模型 * * sa_tool_crontab_log 定时任务执行日志表 * * @property $id 主键 * @property $crontab_id 任务ID * @property $name 任务名称 * @property $target 任务调用目标字符串 * @property $parameter 任务调用参数 * @property $exception_info 异常信息 * @property $status 执行状态 * @property $create_time 创建时间 * @property $update_time 修改时间 */ class CrontabLog extends BaseModel { /** * 数据表主键 * @var string */ protected $pk = 'id'; protected $table = 'sa_tool_crontab_log'; } ================================================ FILE: src/plugin/saiadmin/app/model/tool/GenerateColumns.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\model\tool; use plugin\saiadmin\basic\think\BaseModel; /** * 代码生成业务字段模型 */ class GenerateColumns extends BaseModel { /** * 数据表主键 * @var string */ protected $pk = 'id'; protected $table = 'sa_tool_generate_columns'; public function getOptionsAttr($value) { return json_decode($value ?? '', true); } } ================================================ FILE: src/plugin/saiadmin/app/model/tool/GenerateTables.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\model\tool; use plugin\saiadmin\basic\think\BaseModel; /** * 代码生成业务模型 */ class GenerateTables extends BaseModel { /** * 数据表主键 * @var string */ protected $pk = 'id'; protected $table = 'sa_tool_generate_tables'; public function getOptionsAttr($value) { return json_decode($value ?? '', true); } } ================================================ FILE: src/plugin/saiadmin/app/validate/system/SystemCategoryValidate.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\validate\system; use plugin\saiadmin\basic\BaseValidate; /** * 附件分类验证器 */ class SystemCategoryValidate extends BaseValidate { /** * 定义验证规则 */ protected $rule = [ 'category_name' => 'require', ]; /** * 定义错误信息 */ protected $message = [ 'category_name' => '分类名称必须填写', ]; /** * 定义场景 */ protected $scene = [ 'add' => [ 'category_name', ], 'edit' => [ 'category_name', ], ]; } ================================================ FILE: src/plugin/saiadmin/app/validate/system/SystemConfigGroupValidate.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\validate\system; use plugin\saiadmin\basic\BaseValidate; use plugin\saiadmin\app\model\system\SystemConfigGroup; /** * 字典类型验证器 */ class SystemConfigGroupValidate extends BaseValidate { /** * 定义验证规则 */ protected $rule = [ 'name' => 'require|max:16', 'code' => 'require|alphaDash|unique:' . SystemConfigGroup::class, ]; /** * 定义错误信息 */ protected $message = [ 'name.require' => '组名称必须填写', 'name.max' => '组名称最多不能超过16个字符', 'name.chs' => '组名称必须是中文', 'code.require' => '组标识必须填写', 'code.alphaDash' => '组标识只能由英文字母组成', 'code.unique' => '配置组标识不能重复', ]; /** * 定义场景 */ protected $scene = [ 'save' => [ 'name', 'code', ], 'update' => [ 'name', 'code', ], ]; } ================================================ FILE: src/plugin/saiadmin/app/validate/system/SystemConfigValidate.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\validate\system; use plugin\saiadmin\basic\BaseValidate; /** * 字典类型验证器 */ class SystemConfigValidate extends BaseValidate { /** * 定义验证规则 */ protected $rule = [ 'name' => 'require', 'key' => 'require', 'group_id' => 'require', 'input_type' => 'require', ]; /** * 定义错误信息 */ protected $message = [ 'name' => '配置标题必须填写', 'key' => '配置标识必须填写', 'group_id' => '所属组必须填写', 'input_type' => '输入组件必须填写', ]; /** * 定义场景 */ protected $scene = [ 'save' => [ 'name', 'key', 'group_id', 'input_type', ], 'update' => [ 'name', 'key', 'group_id', 'input_type', ], ]; } ================================================ FILE: src/plugin/saiadmin/app/validate/system/SystemCrontabValidate.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\validate\system; use plugin\saiadmin\basic\BaseValidate; /** * 字典类型验证器 */ class SystemCrontabValidate extends BaseValidate { /** * 定义验证规则 */ protected $rule = [ 'name' => 'require', 'type' => 'require', 'rule' => 'require', 'target' => 'require', 'status' => 'require', ]; /** * 定义错误信息 */ protected $message = [ 'name' => '任务名称必须填写', 'type' => '任务类型必须填写', 'rule' => '任务规则必须填写', 'target' => '调用目标必须填写', 'status' => '状态必须填写', ]; /** * 定义场景 */ protected $scene = [ 'save' => [ 'name', 'type', 'rule', 'target', 'status', ], 'update' => [ 'name', 'type', 'rule', 'target', 'status', ], ]; } ================================================ FILE: src/plugin/saiadmin/app/validate/system/SystemDeptValidate.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\validate\system; use plugin\saiadmin\basic\BaseValidate; /** * 部门验证器 */ class SystemDeptValidate extends BaseValidate { /** * 定义验证规则 */ protected $rule = [ 'name' => 'require', 'status' => 'require', ]; /** * 定义错误信息 */ protected $message = [ 'name' => '部门名称必须填写', 'status' => '状态必须填写', ]; /** * 定义场景 */ protected $scene = [ 'add' => [ 'name', 'status', ], 'edit' => [ 'name', 'status', ], ]; } ================================================ FILE: src/plugin/saiadmin/app/validate/system/SystemDictDataValidate.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\validate\system; use plugin\saiadmin\basic\BaseValidate; /** * 字典数据验证器 */ class SystemDictDataValidate extends BaseValidate { /** * 定义验证规则 */ protected $rule = [ 'label' => 'require', 'value' => 'require', 'status' => 'require', 'type_id' => 'require', 'code' => 'require', ]; /** * 定义错误信息 */ protected $message = [ 'label' => '字典标签必须填写', 'value' => '字典键值必须填写', 'status' => '状态必须填写', 'type_id' => '字典类型必须填写', 'code' => '字典标识必须填写', ]; /** * 定义场景 */ protected $scene = [ 'save' => [ 'label', 'value', 'status', 'type_id', ], 'update' => [ 'label', 'value', 'status', ], ]; } ================================================ FILE: src/plugin/saiadmin/app/validate/system/SystemDictTypeValidate.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\validate\system; use plugin\saiadmin\basic\BaseValidate; use plugin\saiadmin\app\model\system\SystemDictType; /** * 字典类型验证器 */ class SystemDictTypeValidate extends BaseValidate { /** * 定义验证规则 */ protected $rule = [ 'name' => 'require|max:16', 'code' => 'require|alphaDash|unique:' . SystemDictType::class, 'status' => 'require', ]; /** * 定义错误信息 */ protected $message = [ 'name.require' => '字典名称必须填写', 'name.max' => '字典名称最多不能超过16个字符', 'code.require' => '字典标识必须填写', 'code.alphaDash' => '字典标识只能由英文字母组成', 'code.unique' => '字典标识已存在', 'status' => '状态必须填写', ]; /** * 定义场景 */ protected $scene = [ 'save' => [ 'name', 'code', 'status', ], 'update' => [ 'name', 'code', 'status', ], ]; } ================================================ FILE: src/plugin/saiadmin/app/validate/system/SystemMailValidate.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\validate\system; use plugin\saiadmin\basic\BaseValidate; /** * 邮件验证器 */ class SystemMailValidate extends BaseValidate { /** * 定义验证规则 */ protected $rule = [ 'gateway' => 'require', 'from' => 'require', 'email' => 'require', ]; /** * 定义错误信息 */ protected $message = [ 'gateway' => '网关必须填写', 'from' => '发件人必须填写', 'email' => '接收人必须填写', ]; /** * 定义场景 */ protected $scene = [ 'save' => [ 'gateway', 'from', 'email', ], 'update' => [ 'gateway', 'from', 'email', ], ]; } ================================================ FILE: src/plugin/saiadmin/app/validate/system/SystemMenuValidate.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\validate\system; use plugin\saiadmin\basic\BaseValidate; /** * 菜单验证器 */ class SystemMenuValidate extends BaseValidate { /** * 定义验证规则 */ protected $rule = [ 'name' => 'require|max:16', 'status' => 'require', ]; /** * 定义错误信息 */ protected $message = [ 'name.require' => '菜单名称必须填写', 'name.max' => '菜单名称最多不能超过16个字符', 'status' => '状态必须填写', ]; /** * 定义场景 */ protected $scene = [ 'save' => [ 'name', 'status', ], 'update' => [ 'name', 'status', ], ]; } ================================================ FILE: src/plugin/saiadmin/app/validate/system/SystemNoticeValidate.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\validate\system; use plugin\saiadmin\basic\BaseValidate; /** * 系统公告验证器 */ class SystemNoticeValidate extends BaseValidate { /** * 定义验证规则 */ protected $rule = [ 'title' => 'require|min:4', 'content' => 'require', 'type' => 'require', ]; /** * 定义错误信息 */ protected $message = [ 'title.require' => '公告标题必须填写', 'title.min' => '公告标题必须大于4个字符', 'content' => '公告内容必须填写', 'type' => '公告类型必须填写', ]; /** * 定义场景 */ protected $scene = [ 'save' => [ 'title', 'content', 'type', ], 'update' => [ 'title', 'content', 'type', ], ]; } ================================================ FILE: src/plugin/saiadmin/app/validate/system/SystemPostValidate.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\validate\system; use plugin\saiadmin\basic\BaseValidate; /** * 用户角色验证器 */ class SystemPostValidate extends BaseValidate { /** * 定义验证规则 */ protected $rule = [ 'name' => 'require', 'code' => 'require', 'status' => 'require', ]; /** * 定义错误信息 */ protected $message = [ 'name' => '岗位名称必须填写', 'code' => '岗位标识必须填写', 'status' => '状态必须填写', ]; /** * 定义场景 */ protected $scene = [ 'save' => [ 'name', 'code', 'status', ], 'update' => [ 'name', 'code', 'status', ], ]; } ================================================ FILE: src/plugin/saiadmin/app/validate/system/SystemRoleValidate.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\validate\system; use plugin\saiadmin\basic\BaseValidate; use plugin\saiadmin\app\model\system\SystemRole; /** * 用户角色验证器 */ class SystemRoleValidate extends BaseValidate { /** * 定义验证规则 */ protected $rule = [ 'name' => 'require|max:16', 'code' => 'require|alphaDash|unique:' . SystemRole::class, 'status' => 'require', ]; /** * 定义错误信息 */ protected $message = [ 'name.require' => '角色名称必须填写', 'name.max' => '角色名称最多不能超过16个字符', 'code.require' => '角色标识必须填写', 'code.alphaDash' => '角色标识只能由英文字母组成', 'code.unique' => '角色标识不能重复', 'status' => '状态必须填写', ]; /** * 定义场景 */ protected $scene = [ 'add' => [ 'name', 'code', 'status', ], 'edit' => [ 'name', 'code', 'status', ], ]; } ================================================ FILE: src/plugin/saiadmin/app/validate/system/SystemUserValidate.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\validate\system; use plugin\saiadmin\basic\BaseValidate; use plugin\saiadmin\app\model\system\SystemUser; /** * 用户信息验证器 */ class SystemUserValidate extends BaseValidate { /** * 定义验证规则 */ protected $rule = [ 'username' => 'require|max:16|unique:' . SystemUser::class, 'password' => 'require|min:6|max:16', 'role_ids' => 'require', ]; /** * 定义错误信息 */ protected $message = [ 'username.require' => '用户名必须填写', 'username.max' => '用户名最多不能超过16个字符', 'username.unique' => '用户名不能重复', 'password.require' => '密码必须填写', 'password.min' => '密码最少为6位', 'password.max' => '密码长度不能超过16位', 'role_ids' => '角色必须填写', ]; /** * 定义场景 */ protected $scene = [ 'save' => [ 'username', 'password', 'role_ids', ], 'update' => [ 'username', 'role_ids', ], ]; } ================================================ FILE: src/plugin/saiadmin/app/validate/tool/CrontabValidate.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\validate\tool; use plugin\saiadmin\basic\BaseValidate; /** * 字典类型验证器 */ class CrontabValidate extends BaseValidate { /** * 定义验证规则 */ protected $rule = [ 'name' => 'require', 'type' => 'require', 'target' => 'require', 'status' => 'require', ]; /** * 定义错误信息 */ protected $message = [ 'name' => '任务名称必须填写', 'type' => '任务类型必须填写', 'target' => '调用目标必须填写', 'status' => '状态必须填写', ]; /** * 定义场景 */ protected $scene = [ 'save' => [ 'name', 'type', 'target', 'status', ], 'update' => [ 'name', 'type', 'target', 'status', ], ]; } ================================================ FILE: src/plugin/saiadmin/app/validate/tool/GenerateTablesValidate.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\app\validate\tool; use plugin\saiadmin\basic\BaseValidate; /** * 用户角色验证器 */ class GenerateTablesValidate extends BaseValidate { /** * 定义验证规则 */ protected $rule = [ 'table_name' => 'require', 'table_comment' => 'require', 'class_name' => 'require|alphaDash', 'business_name' => 'require|alphaDash', 'template' => 'require', 'namespace' => 'require', 'menu_name' => 'require', ]; /** * 定义错误信息 */ protected $message = [ 'table_name' => '表名称必须填写', 'table_comment' => '表描述必须填写', 'class_name.require' => '实体类必须填写', 'class_name.alphaDash' => '实体类必须是英文', 'business_name.require' => '实体别名必须填写', 'business_name.alphaDash' => '实体别名必须是英文', 'template' => '模板必须填写', 'namespace' => '命名空间必须填写', 'menu_name' => '菜单名称必须填写', ]; /** * 定义场景 */ protected $scene = [ 'save' => [ 'table_name', 'table_comment', 'class_name', 'business_name', 'template', 'namespace', 'menu_name', ], 'update' => [ 'table_name', 'table_comment', 'class_name', 'business_name', 'template', 'namespace', 'menu_name', ] ]; } ================================================ FILE: src/plugin/saiadmin/app/view/install/error.html ================================================“平均亩产1209.1公斤,这标志着全国首个两百万亩玉米‘吨粮田’成功创建。”金秋时节,新疆伊犁哈萨克自治州传来喜讯。这一纪录的诞生,离不开中国农业科学院研发的“玉米密植高产精准调控技术”支撑。依托该技术,位于伊犁的200余万亩玉米高产田亩保苗株数从传统的不足5000株提升到7000—8000株,玉米收获穗数大幅提升。
这只是我国科技强农、粮食增产增收的一个缩影。“十四五”以来,我国粮食总产量始终保持在1.3万亿斤以上。2024年粮食总产量更是首次突破1.4万亿斤,比2020年增产740亿斤。
习近平总书记强调,发展现代农业,建设农业强国,必须依靠科技进步,让科技为农业现代化插上腾飞的翅膀。
“十四五”规划提出,完善农业科技创新体系,创新农技推广服务方式,建设智慧农业。5年来,在科技创新的强劲支撑下,14亿人的饭碗端得更牢、农业现代化水平显著提升、产业新动能持续增强,农业强国建设迈上新台阶。
科技铸“芯”,夯实大国粮仓之基
国以农为本,农以种为先,种子被誉为农业的“芯片”。前不久,四川省富顺县水稻百亩超高产攻关片进行实割实测,再生稻亩产达到494.81公斤,加上此前测产中稻亩产807.13公斤,合计亩产突破1300公斤。取得这一成绩的背后,是“甬优4949”等高产突破性品种的选育和“中稻+再生稻”生产模式的推广。
水稻是我国第一大口粮。“十四五”时期全国多地选育出一批水稻突破性品种:安徽农业大学水稻栽培团队推广自育水稻品种,帮助当地农户水稻亩产增至800公斤;湖南杂交水稻研究中心选育出“西子3号”,推动解决部分受重金属污染地区“镉大米”问题;国家耐盐碱水稻技术创新中心培育出“箐两优3261”,填补了我国华南滨海盐碱区暂无强耐盐、多抗、优质杂交稻品种的空白……
习近平总书记指出,中国人的饭碗要牢牢端在自己手中,就必须把种子牢牢攥在自己手里。
作为我国另一大口粮,小麦育种的创新步伐也不断提速。2025年,西北农林科技大学一次性通过国家审定12个新品种,覆盖半冬性、冬性、春性类型,在抗倒伏等方面实现全面突破。这些为不同生态区“量身定制”的品种,在丰富我国小麦品种的同时,也大幅提升了小麦产能潜力。截至目前,西农小麦系列品种累计推广面积已达18亿亩,为保障国家粮食安全提供了坚实的种源支撑。
“十四五”以来,我国深入实施种业振兴行动,育成了一批生产急需的重大品种,选育出优质高产水稻、节水抗病小麦、机收籽粒玉米、高油高产大豆等急需品种,农作物自主选育品种面积占比超过了95%,做到了“中国粮”主要用“中国种”。
“去年全国粮食亩产394.7公斤,比‘十三五’末提高了12.5公斤,单产提升对我国粮食产量增长的贡献超过60%,有些年份会超过80%。”农业农村部党组书记、部长韩俊表示,“十四五”以来,农业农村部深入实施国家粮食安全战略,“以我为主、立足国内、确保产能、适度进口、科技支撑”,坚持产量产能、生产生态、增产增收一起抓,强化藏粮于地、藏粮于技,全方位夯实粮食安全根基。
智慧提“效”,驱动耕作方式变革
气象墒情传感器、智能虫情测报站等设备如同“千里眼”,与空中无人机巡航、地面机器狗巡检形成立体监测网络。这是日前科技日报记者在北京市昌平区的天汇园果园见到的一幕。
“目前,该果园环境和土壤墒情覆盖10余项指标,虫情识别准确率达90%,种植生产信息化率超过95%,同时土壤成分快检技术能在30分钟内完成土壤成分‘体检’,辅助实现果园虫情和灾情等早预警、早干预。”北京市智慧农业创新团队岗位专家吴建伟介绍,该果园管理从“经验驱动”转向“数据驱动”,为果树生长提供了全天候守护。
在四川省成都市新都区稻菜现代农业园区,当地自主研发的农业巡检机器人已代替人工开展巡检工作;在浙江省衢州市龙游县田间地头,一架植保无人机3小时就能完成300亩农田的喷药流程,相当于40多个人整整一天的工作量……
“十四五”以来,类似的农业新场景新模式不断涌现,现代农业设施装备持续普及应用。我国先后支持建设国家智慧农业创新应用项目116个,深入开展国产化智慧农业技术的中试熟化、推广应用,探索形成了一批信息技术与农机农艺相融合的节本增产增效技术模式。
习近平总书记指出,农业科技创新要着力提升创新体系整体效能,农业科技工作要突出应用导向,把论文写在大地上。
5年来,我国农业科技创新体系整体效能显著提升。我国充分利用物联网、大数据、人工智能等现代信息技术发展智慧农业,并研制出一批先进智能适用的农机装备。
“随着智能农机加快推广,全国安装北斗终端的农机约200万台,植保无人机年作业面积超过4.1亿亩。人工智能、农业机器人等新技术与农业生产经营加速融合,精准播种、变量施肥、智慧灌溉、精准饲喂、环境控制等逐渐普及。”农业农村部市场与信息化司司长雷刘功介绍。
这些前沿技术的落地应用,正是农业科技现代化推动农业现代化的生动实践。“十四五”以来,我国坚持用现代设施装备武装农业,用现代科学技术服务农业,推动农业现代化水平不断提高。2024年底,农业科技进步贡献率已经达到了63.2%,农作物耕种收综合机械化率超过75%。
创新延“链”,拓宽食物供给版图
近日,蒙牛集团携多款产品参加第八届中国国际进口博览会,展示其发展新质生产力的最新成果。“我们打造的全球液态奶行业首座‘灯塔工厂’,已成为全球乳业最高人效比的新标杆,是中国乳业抢占全球智能制造新高地的生动写照。”中粮集团副总经理、蒙牛乳业董事长庆立军介绍。这座“灯塔工厂”通过实施30多项第四次工业革命技术,实现了“百人百亿”的极致人效比——100名员工,年产能达百万吨,创造产值百亿元。
今天,科研创新已成为发展现代化海洋牧场的强大引擎。南方海洋实验室研发“珠海琴”等多功能融合的新型组合式结构加强型养殖平台,为海洋养殖带来新变革;珠海市海洋集团形成海工型养殖装备设计、建造、施工和运维等全产业链条,成功研发“格盛一号”养殖平台,订单水体总量相当于新开拓28.25万亩耕地。
习近平总书记指出,要树立大农业观、大食物观,农林牧渔并举,构建多元化食物供给体系。
“十四五”以来,我国突出科技支撑,强化要素保障,努力向森林要食物,向草原要食物,向江河湖海要食物,向设施农业要食物,向植物动物微生物要热量、要蛋白,多元化食物供给体系加快构建。
一组数据表明,农业科技创新正通过看得见的方式,让老百姓的餐桌品类变得愈发丰富——2024年,我国肉蛋奶等畜产品总量达到1.75亿吨,比2020年增加2778万吨,增长18.8%;水产品总产量达到7358万吨,比2020年增长12.3%,水产品总产量持续36年居全球第一。
党的二十届四中全会审议通过的《中共中央关于制定国民经济和社会发展第十五个五年规划的建议》提出,“统筹发展科技农业、绿色农业、质量农业、品牌农业,把农业建成现代化大产业”。科技创新能够催生新产业、新模式、新动能,是发展新质生产力的核心要素。韩俊表示,加快建设农业强国,必须清醒认识到农业科技国际竞争新形势,把农业科技创新放在更加突出的位置,紧盯世界农业科技前沿,加快突破农业关键核心技术,努力抢占农业科技创新制高点,塑造农业农村发展新动能新优势,培育壮大农业新质生产力。
', 5, 100, 1, 2, '', 2, 1, 1, '2024-06-02 22:55:25', '2026-01-10 11:13:25', NULL); INSERT INTO `sa_article` VALUES (2, 1, '商业航天稳步快跑 “太空旅游”渐行渐近', '新华网', 'https://www.news.cn/tech/20251124/c7cb9d4e405c4c82b78a8f861889cb22/20251124c7cb9d4e405c4c82b78a8f861889cb22_20251124044f95bbab864da2b0c30861aa41279b.png', '业界普遍认为,以可复用火箭为代表的核心技术突破是商业航天提速的关键支撑。据统计,2025年底至2026年初,我国可复用火箭技术将进入密集首飞期,包括蓝箭航天“朱雀三号”、中科宇航“力箭二号”、星际荣耀“双曲线三号”和星河动力“智神星一号”在内的多款可复用火箭将迎来首飞。', '可搭载7名乘客穿越卡门线,体验约4分钟失重体验……记者从11月22日在京开幕的第四届中国空间科学大会上了解到我国太空旅游的最新进展。与会专家学者认为,随着产业链条不断完善、核心技术持续突破,我国商业航天已迈入稳步快跑的发展新阶段,曾经遥不可及的“太空旅游”正加速走进现实。
记者在第四届中国空间科学大会同期举行的“航天新技术、新成果展”上看到,我国首型面向太空旅游的可重复使用飞行器力鸿二号的模型吸引了众多参观者。中科宇航展台工作人员告诉记者,力鸿二号将采用“箭船分离”的方式将乘客送上太空:飞到既定高度之后,载人舱与火箭分离,继续飞越100公里的卡门线,开始约4分钟的失重段,之后返回地面,以伞降的方式着陆,火箭也将垂直着陆回收。“我们的目标是让力鸿二号可重复使用超30次,这样就能把飞行成本降下来,让更多的人体验太空旅游。”
我国商业航天的快速发展让太空旅游渐行渐近。业界普遍认为,以可复用火箭为代表的核心技术突破是商业航天提速的关键支撑。据统计,2025年底至2026年初,我国可复用火箭技术将进入密集首飞期,包括蓝箭航天“朱雀三号”、中科宇航“力箭二号”、星际荣耀“双曲线三号”和星河动力“智神星一号”在内的多款可复用火箭将迎来首飞。
不仅火箭研制加速突破,卫星应用也在不断拓展。此次展会上,微纳星空等卫星企业也带来了最新的研发成果。微纳星空品牌总监刘晓光介绍,即将发射的“全天候卫士”MN200S-2(01B)星是公司自主研制的商业X波段相控阵雷达成像领域的技术标杆型卫星,可广泛应用于应急救灾、海洋维权、国土安全、生态监测、智慧城市建设等场景,并可实现多星高密度堆叠发射,为后续卫星规模化组网编队提供关键技术验证与工程实践依据。“随着国家低轨卫星互联网的能力建设牵引,微纳星空已经开启批量化、低成本的卫星制造。”
业界认为,目前我国已形成覆盖火箭研制、卫星制造、发射服务、地面应用的完整商业航天产业链,产业集群效应逐步显现。在北京,“南箭北星”的产业格局已显露雏形:亦庄新城正在打造全国首个商业航天共性科研生产基地——火箭大街,海淀区作为“北星”的核心承载区,已集聚涵盖商业卫星制造、测运控、运营及数据应用的近200家相关企业。“在此基础上,海淀正全力推进卫星小镇‘两区一平台’的建设:先导区目前已有40余家商业航天企业聚集;紧邻航天城的卫星小镇核心区54万平方米空间预计2026年6月竣备,将重点引入卫星上下游企业;同时,卫星小镇拟建公共服务平台,提供卫星整星及组部件的力学、热真空、抗辐射等多种测试服务。”卫星小镇核心区对接人段叶叶介绍。
“我国发展商业航天的优势是人多、力量大、竞争强,技术和产品能够快速迭代,紧跟国际趋势。”中国科学院微小卫星创新研究院副院长张永合在接受记者专访时表示,但目前我国商业航天企业和人才大多集中在制造领域,“还需要更多能创造任务的人,有非常前沿的想法,有改变当前航天模式的颠覆性路径。”
张永合认为,商业航天关键是要创造需求,“比如太空旅游就是商业航天创造的需求,将人们日常生活中的旅游延伸到太空中去,在产业上就属于增量。”未来,低空经济、空间互联网等也将打开想象空间。“有了坚实的技术底座,新的产业形态就会自然而然生长出来。”
不过,业内专家也指出,我国商业航天发展仍面临体制机制创新不足、部分核心技术有待突破等挑战。从政策层面来看,近年来国家持续加大对商业航天的支持力度,相关扶持政策和行业规范正在逐步完善,旨在优化市场环境、加大核心技术研发支持,为商业航天高质量发展营造良好生态,推动太空旅游等新业态逐步走向成熟。
业内普遍认为,商业航天已成为航天强国建设的重要增长点。从运载火箭重复使用技术突破到卫星应用场景拓展,随着技术持续成熟、产业链不断完善和政策环境优化,未来“上太空”有望从专业探索逐步走向大众体验,中国商业航天也将在全球太空经济格局中占据重要地位。
随着中国式现代化不断向前推进,中国迎来了数字经济发展的新机遇。在数字经济快速发展的背景下,中国式现代化的内涵得以拓展,现代化动力得以重塑,现代化新动能得以培育,现代化新优势得以形成。数字技术创新、实体经济与数字经济融合、产业数字化、数字产业化成为推进中国式现代化的重要驱动力量。
在数字经济推动下,现代化由工业经济时代的现代化向数字经济时代的现代化转变,在这一大背景下需要在理论上研究数字经济赋能中国式现代化的逻辑和机制,需要深入探讨中国式现代化如何紧紧抓住数字经济发展带来的新机遇,以数字化的知识和信息作为关键生产要素,以数字技术为核心驱动力,在数据要素和数字技术的双轮驱动下推动中国式现代化走上新征程。
南京大学数字经济与管理学院任保平教授的专著《数字经济赋能中国式现代化》于2025年在江苏人民出版社出版,全书共17章,35.8万字。该书立足世界范围内数字化浪潮下的经济现代化背景,从理论与实践两个方面研究了数字经济发展对中国式现代化的赋能作用。
在理论层面,该书研究了数字经济发展对中国式现代化的影响、数字经济与中国式现代化的有机衔接,数字经济背景下中国式现代化目标的重塑、数字经济与中国式现代化深度融合的逻辑机制,数字经济背景下中国式现代化的延伸和拓展。在实践层面,从中国式现代化的不同方面具体研究了数字经济的赋能作用,具体包括数字经济赋能中国式新型工业化、新型城镇化、科技现代化、农业农村现代化、产业现代化和科技现代化。
该书的核心观点主要有以下方面。一是,中国式现代化战略在数字化转型背景下发生的一系列拓展。促进工业化与信息化的融合发展,以数字化带动工业化发展,加大数字技术研发力度,大力发展数字产业。以数字化带动农业现代化,补足中国式现代化短板。协同匹配数字经济时代的创新供求,提升产业技术创新能力。促进企业数字化转型,引领数字经济发展。协调产业数字化与数字产业化,推进产业基础现代化。加快新型基础设施建设,提升基础设施支撑能力。构建数字平台体系,打造现代化经济新形态。
二是,以数字经济发展培育中国式现代化新优势。针对数字经济带来的现代化新变化,研究了数字经济对中国式现代化的引擎作用,认为目前中国式现代化正处于数字经济蓬勃发展带来无数新机遇的时代,我们要抓住数字经济发展带来的新机遇,以数字经济推动中国式现代化的新发展。
三是,阐释数字经济赋能中国式现代化的逻辑。在理论上深刻阐释数字经济如何成为中国式现代化的新引擎,数字经济作为新引擎对中国式现代化赋能的驱动机制和路径,论证数字经济发展赋能中国式现代化在目标、路径和战略上的延伸和拓展,为数字经济赋能中国式现代化提供了一个理论框架。
四是,研究数字经济全面赋能中国式现代化的机制。中国式经济现代化涉及多方面内容,包括科技现代化、工业现代化、农业现代化、服务业现代化、产业链现代化、城市现代化、区域现代化、城市现代化、生态现代化、企业现代化、人的现代化和治理现代化,数字经济应该从上述方面赋能中国式现代化。
五是,提出了以数字经济培育中国式现代化新优势的路径。数字经济培育中国式现代化的新优势包括需求端的动力新优势、供给端的效率新优势等。需要从数字化转型的创新能力、基础设施的供给能力、数字化转型的战略支撑能力,数字化转型的保障能力等方面研究数字经济发展培育中国式现代化新优势的实现路径。而且,需要从效率变革机制、动力变革机制和质量变革机制等方面研究数字经济赋能中国式现代化新优势培育的机制,从数字产业化、产业数字化、产学研协同创新、劳动力质量和相关配套制度等方面实现数字经济培育中国式现代化的新优势,全面展示数字经济赋能中国式现代化中的应用场景。
', 2, 100, 1, 2, '', 2, 1, 1, '2024-06-02 22:58:41', '2026-01-10 11:13:01', NULL); INSERT INTO `sa_article` VALUES (4, 2, '2025腾讯全球数字生态大会在深圳举行', '新华网', 'https://www.news.cn/tech/20250918/a8a0f6e1a6d740188db7752e247518bb/20250918a8a0f6e1a6d740188db7752e247518bb_202509184f78f2904fa2456db9537d878cb89166.jpg', '5月26日晚上18:00,中超第14轮,深圳新鹏城主场迎战上海申花,上半场马莱莱补射斩获赛季第6球,半场战罢,申花暂1-0新鹏城', '9月16日,2025腾讯全球数字生态大会在深圳举行,会上公布多项AI技术和产品最新进展,并宣布全面开放腾讯AI落地能力及优势场景,助力“好用的AI”在千行百业中加速落地。
2026年美国拉斯维加斯消费电子展(CES)6日至9日举行,首次亮相海外展会的中国小机器人“启元Q1”刚一登场就成为焦点,凭借其出色表现“圈粉”海外。
', 3, 100, 1, 2, '', 2, 1, 1, '2024-06-02 23:01:17', '2026-01-10 13:42:24', NULL); INSERT INTO `sa_article` VALUES (6, 3, 'AI助力药物虚拟筛选提速百万倍 开启后AlphaFold时代创新药', '新华网', 'https://www.news.cn/tech/20260109/2e0f65d6733a4e2588a97dfe96593a09/202601092e0f65d6733a4e2588a97dfe96593a09_202601090012b088f5604e22a77ae70f8656f466.jpg', '团队与清华大学闫创业教授团队合作,在去甲肾上腺素转运体(NET)的临床相关靶点上开展了系列生物实验验证。', '1月9日,清华大学智能产业研究院(AIR)联合清华大学生命学院、清华大学化学系在《科学》杂志发表论文《深度对比学习实现基因组级别药物虚拟筛选》。该论文研发了一个AI驱动的超高通量药物虚拟筛选平台DrugCLIP, 筛选速度对比传统方法实现百万倍提升,同时在预测准确率上也取得显著突破。依托该平台,团队打通了从AlphaFold结构预测到药物发现的关键通道,首次完成了覆盖人类基因组规模的药物虚拟筛选,为后AlphaFold时代的创新药物发现带来新可能性。

长期以来,药物研发面临“高风险、高投入、低成功率”的难题,在靶点发现与先导化合物筛选阶段,受限于传统工具的计算能力,绝大多数潜在靶点和化合物仍未被充分探索。如何在广阔的生物与化学空间中精准高效地发现活性化合物,是当前创新药物研发面临的核心挑战。
据了解,为突破虚拟筛选规模瓶颈,DrugCLIP创新性地构建了蛋白口袋与小分子的“向量化结合空间”,将传统基于物理对接的筛选流程转化为高效的向量检索问题。该模型结合对比学习、3D结构预训练与多模态编码技术,能在三维结构层面精准建模蛋白-配体间的相互作用。训练后的高潜力分子将自然聚集于目标蛋白口袋的向量邻域,能够有效支撑快速的大规模虚拟筛选。依托这一机制,DrugCLIP在128核CPU+8张GPU的计算节点上,能实现毫秒级打分与万亿级日吞吐能力,筛选100万个候选分子仅需0.02秒,日处理能力达31万亿次,对比传统方法实现了百万倍提升。

团队与清华大学闫创业教授团队合作,在去甲肾上腺素转运体(NET)的临床相关靶点上开展了系列生物实验验证。团队使用DrugCLIP模型从160万个候选分子中筛选出约100个高评分分子,同位素配体转运实验检测显示,其中15%为有效抑制剂,其中12个分子结合能力优于现有抗抑郁药物安非他酮。相关复合物结构已通过冷冻电镜解析,进一步验证了DrugCLIP筛选结果的生物学可信度。
值得关注的是,DrugCLIP支持对AlphaFold预测的蛋白结构和apo(无配体)状态下的蛋白口袋进行筛选,扩大了其在真实药物发现场景中的适用性。团队和清华大学刘磊教授团队合作,针对E3泛素连接酶TRIP12(thyroid hormone receptor interactor 12)进行了虚拟筛选与实验验证。过往研究发现,TRIP12是多种肿瘤、帕金森综合征的潜在靶点,但是TRIP12缺少已知的小分子配体和复合物结构。团队使用DrugCLIP模型,从160万个候选分子中高通量筛选出约50个高评分分子,SPR实验证实,其中10个分子与TRIP12有结合能力,两个亲和力较高的分子也对TRIP12的泛素连接酶活性有一定的抑制活性。
此外,依托DrugCLIP,团队首次完成了人类基因组规模的虚拟筛选项目,覆盖约1万个蛋白靶点、2万个结合口袋,分析超过5亿个小分子,富集出200万余个高潜力活性分子,构建了目前已知最大规模的蛋白-配体筛选数据库。该数据库已面向全球科研社区开放,为基础研究与早期药物发现提供了强大数据支持。
DrugCLIP平台现已免费开放,用户无需本地部署,通过网页上传蛋白结构即可启动筛选任务。平台集成口袋/分子编码、向量检索、可视化与结果分析等功能,支持多种分子库调用与自定义上传,广泛适用于科研机构与企业用户。
未来,DrugCLIP将与科研产业生态合作伙伴深度合作,在抗癌、传染病、罕见病等方向加速新靶点与First-in-class药物的发现。团队将持续优化引擎性能、拓展支持模态,助力构建一个更智能、高效与普惠的全球药物创新生态。
', 4, 100, 1, 2, '', 2, 1, 1, '2024-06-02 23:02:40', '2026-01-10 13:38:51', NULL); INSERT INTO `sa_article` VALUES (7, 4, '高度重视低空经济为哪般', '新华网', 'https://www.news.cn/tech/20250312/c0453593a495424780c5424c054a1d4d/20250312c0453593a495424780c5424c054a1d4d_2025031215d8945b560d4d169997f7745d0ef56f.jpg', '当前,我国低空经济正处于市场培育初期,关键技术的实用性和商业价值仅得到初步验证,但已彰显出广阔的增长空间', '近年来,低空经济成为全球发达经济体角逐的重要方向。虽然世界范围内低空经济还处于培育初期阶段,但是美国、日本、欧盟等国家和地区已经重点围绕场景开发应用、交通管理能力、运行技术验证、系统标准体系等方面积极出台和完善相关政策,加快发展低空经济。
低空经济是依托低空飞行活动牵引串联的一系列相互关联的产业经济活动,不仅包括上游生产制造飞行器所必需的材料、零部件及分系统的行业企业,还包括中下游低空飞行器组装集成制造和测试试飞、设施配套及低空服务等领域。低空经济产业链条长、产业关联性强、应用场景丰富,具有战略引领性、高增长潜力等显著特征,既可以推动现代农牧业、先进制造业、现代服务业深度融合发展,又能够扩大有效投资、提振消费需求、提升创新能力。世界主要国家高度重视低空经济发展,就是因为看好其发展前景。
当前,我国低空经济正处于市场培育初期,关键技术的实用性和商业价值仅得到初步验证,但已彰显出广阔的增长空间。未来随着技术迭代升级和商业模式逐步成熟,低空经济的高增长潜力将会进一步释放,更容易实现相关产业企业的群体性爆发成长,有望成为拉动经济增长的新引擎。
一方面,低空飞行器的产业规模体量加快增长、产业生态持续完善。目前,我国无人机制造国际竞争力逐步增强,消费级无人机世界领先优势突出。截至2023年底,我国民用无人机研制企业已超过2300家,量产的无人机产品超过1000款。2023年,我国民用无人机产业规模达到1174.3亿元,同比增长32%。同时,新一代信息技术、新材料、新能源加速与航空科学技术融合发展,推动低空飞行器动力装备及系统、传感器、飞控系统等相关技术加速迭代,绿色高效、安全低噪的飞行器设计、制造与验证技术也持续更新升级。
另一方面,体量巨大、类型多样的应用场景持续涌现,牵引低空服务快速释放动能。运营航空器大幅增加,《2023—2024中国民用无人驾驶航空发展报告》显示,截至2024年8月底,我国无人机实名登记数达198.7万架,比2023年底增加72万架;共颁发无人机驾驶员执照22万本,比2023年底增加13.9%。随着影视航拍、航空运动、空中观光游览等低空文旅应用场景快速发展,低空经济能为满足人民群众美好生活需求提供新供给。2023年,横店“航空+影视+旅游”交旅融合案例入选第一批交通运输与旅游融合发展十佳案例;2024年,敦煌“飞天”通用航空项目等航空旅游产品案例入选第二批交通运输与旅游融合发展示范案例。低空旅游市场潜力开始显现。
同时,低空经济在农业植保、现代物流等行业领域的发展应用不断深入。随着无人机应用技术不断成熟和应用场景持续丰富,“农林牧副渔”多场景作业不断拓展,农业无人机服务市场规模呈蓬勃发展态势。2024年,全国植保无人机的保有量达到25.1万架,作业面积更是高达26.7亿亩次,同比增长近25%。从全球看,上世纪80年代以来,美国农业植保无人机作业渗透率超过50%,日本60%的稻田采用无人机进行植保作业。相较而言,我国农业无人机作业渗透率还比较低,有很大发展空间。在低空物流领域,以无人机为载运工具的无人化配送成为优化城市物流的重要方向,这能有效解决传统物流配送模式面临的劳动力成本、运输成本大幅攀升以及物资配送流通效率低下等诸多问题。在“低空+”领域,低空经济赋能社会治理成效突出,促进巡检、应急救援、城市管理、森林防火、医疗救护等公共服务快速发展。实践中,北京延庆、湖北武汉等地已采用电力线路无人机智能巡检,有效降低了巡检成本,提升了巡检效率。
但也要看到,我国低空经济发展还存在一些问题,如统筹发展和安全有短板、产业融合化发展不足、空域管理协同机制尚不健全、基础设施建设相对滞后等。对此,要从突出集群融合、强化科技创新、加强设施建设等方面综合施策,将低空经济的发展潜力充分释放出来。
一是突出集群融合,加快培育壮大低空经济产业集群,以市场需求为牵引、以科技创新为驱动,积极完善产业生态、谋划应用场景,推进低空制造业集群化发展。二是强化科技创新,聚焦低空经济创新链薄弱环节,加大科技创新投入,加快提升低空技术支撑能力。三是加强设施建设,构建低空经济基础设施综合保障体系,坚持绿色发展、节约集约,统筹推进通用机场、电动垂直起降飞行器起降场、固定运营基地、飞行服务站等地面配套基础设施建设,推进低空飞行通信、导航、气象监测等信息基础设施建设,加速低空经济智联网络设施建设。此外,还要统筹发展和安全,加强低空飞行器监控防护,强化低空安全技术攻关,提升空域精细化管理能力。坚持包容审慎的安全风险管控理念,建设监管服务体系,建立灵活调配、动态高效的低空空域管理使用机制,增强管理的协同性与联动性。
', 11, 100, 1, 2, '', 2, 1, 1, '2024-06-02 23:04:23', '2026-01-10 13:43:44', NULL); INSERT INTO `sa_article` VALUES (8, 4, '国家发改委成立低空经济发展司', '新华网', 'https://www.news.cn/tech/20241231/3f5396024a9749ee863292c04c7119dc/202412313f5396024a9749ee863292c04c7119dc_2024123101c42d384b83467f835ffd286af095d4.jpg', '近日,低空经济发展司召开推动低空基础设施建设座谈会和推动低空智能网联系统建设专题座谈会', '记者从国家发展和改革委员会官方网站获悉,低空经济发展司已正式成立。
低空经济发展司的具体职责是拟订并组织实施低空经济发展战略、中长期发展规划,提出有关政策建议,协调有关重大问题等。
近日,低空经济发展司召开推动低空基础设施建设座谈会和推动低空智能网联系统建设专题座谈会。
在推动低空基础设施建设座谈会上,低空经济发展司负责同志同自然资源部、生态环境部等部委和有关中央企业进行座谈,了解相关领域低空经济典型场景应用和相关基础设施建设发展情况,并就推动低空基础设施有序规划建设进行交流。
在推动低空智能网联系统建设专题座谈会上,低空经济发展司负责同志与通信、导航方面有关专家进行座谈,就低空智能网联系统建设进行交流。
', 6, 100, 1, 2, '', 2, 1, 1, '2024-06-02 23:04:23', '2026-01-10 13:42:32', NULL); -- ---------------------------- -- Table structure for sa_article_banner -- ---------------------------- DROP TABLE IF EXISTS `sa_article_banner`; CREATE TABLE `sa_article_banner` ( `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '编号', `banner_type` int(11) NULL DEFAULT NULL COMMENT '类型', `image` varchar(1000) NULL DEFAULT NULL COMMENT '图片地址', `is_href` tinyint(1) NULL DEFAULT 1 COMMENT '是否链接', `url` varchar(255) NULL DEFAULT NULL COMMENT '链接地址', `title` varchar(255) NULL DEFAULT NULL COMMENT '标题', `status` tinyint(1) NULL DEFAULT 1 COMMENT '状态', `sort` int(11) NULL DEFAULT 0 COMMENT '排序', `remark` varchar(255) NULL DEFAULT NULL COMMENT '描述', `created_by` int(11) NULL DEFAULT NULL COMMENT '创建者', `updated_by` int(11) NULL DEFAULT NULL COMMENT '更新者', `create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间', `update_time` datetime(0) NULL DEFAULT NULL COMMENT '修改时间', `delete_time` datetime(0) NULL DEFAULT NULL COMMENT '删除时间', PRIMARY KEY (`id`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 4 COMMENT = '文章轮播图' ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of sa_article_banner -- ---------------------------- INSERT INTO `sa_article_banner` VALUES (1, 1, 'https://picsum.photos/id/490/640/360', 1, '/blog/1', '探索亚洲的烹饪奇迹', 1, 100, '有一系列名为“新加坡传统烹饪”的食谱,探索了新加坡的美食和文化。它包括新加坡华人、马来人、印度人、欧亚人和土生华人(海峡华人)的美食', 1, 1, '2024-06-02 23:06:37', '2026-01-09 21:51:50', NULL); INSERT INTO `sa_article_banner` VALUES (2, 1, 'https://picsum.photos/id/29/640/360', 1, '/blog/2', '探索雄伟的山峰', 1, 100, '攀登这座风景如画的山峰的最佳方式是乘坐御在所索道,乘坐15 分钟即可将游客带入空中,欣赏周围一览无余的景观', 1, 1, '2024-06-02 23:06:49', '2026-01-09 21:51:54', NULL); INSERT INTO `sa_article_banner` VALUES (3, 1, 'https://picsum.photos/id/903/640/360', 1, '/blog/3', '揭秘奇迹', 1, 100, '极光是地球磁场与太阳风相互作用的产物,当太阳风中的带电粒子与地球高层大气中的原子、分子碰撞时,会产生发光现象,形成美丽的极光', 1, 1, '2024-06-02 23:06:56', '2026-01-09 21:53:32', NULL); -- ---------------------------- -- Table structure for sa_article_category -- ---------------------------- DROP TABLE IF EXISTS `sa_article_category`; CREATE TABLE `sa_article_category` ( `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '编号', `parent_id` int(11) NOT NULL DEFAULT 0 COMMENT '父级ID', `category_name` varchar(255) NOT NULL COMMENT '分类标题', `describe` varchar(255) NULL DEFAULT NULL COMMENT '分类简介', `image` varchar(255) NULL DEFAULT NULL COMMENT '分类图片', `sort` int(10) UNSIGNED NULL DEFAULT 100 COMMENT '排序', `status` tinyint(1) UNSIGNED NULL DEFAULT 1 COMMENT '状态', `created_by` int(11) NULL DEFAULT NULL COMMENT '创建者', `updated_by` int(11) NULL DEFAULT NULL COMMENT '更新者', `create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间', `update_time` datetime(0) NULL DEFAULT NULL COMMENT '修改时间', `delete_time` datetime(0) NULL DEFAULT NULL COMMENT '删除时间', PRIMARY KEY (`id`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 5 COMMENT = '文章分类表' ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of sa_article_category -- ---------------------------- INSERT INTO `sa_article_category` VALUES (1, 0, '大国科技', '', NULL, 100, 1, 1, 1, '2024-06-02 22:50:51', '2026-01-06 18:03:07', NULL); INSERT INTO `sa_article_category` VALUES (2, 0, '数字经济', '', NULL, 100, 1, 1, 1, '2024-06-02 22:50:56', '2026-01-09 16:54:05', NULL); INSERT INTO `sa_article_category` VALUES (3, 0, '科技快讯', '', NULL, 100, 1, 1, 1, '2024-06-02 22:51:01', '2026-01-07 01:03:37', NULL); INSERT INTO `sa_article_category` VALUES (4, 0, '低空经济', '', NULL, 100, 1, 1, 1, '2024-06-02 22:51:16', '2026-01-06 18:03:14', NULL); SET FOREIGN_KEY_CHECKS = 1; ================================================ FILE: src/plugin/saiadmin/db/saiadmin-pure.sql ================================================ SET NAMES utf8mb4; SET FOREIGN_KEY_CHECKS = 0; -- ---------------------------- -- Table structure for sa_system_attachment -- ---------------------------- DROP TABLE IF EXISTS `sa_system_attachment`; CREATE TABLE `sa_system_attachment` ( `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键', `category_id` int(11) NULL DEFAULT 0 COMMENT '文件分类', `storage_mode` smallint(6) NULL DEFAULT 1 COMMENT '存储模式 (1 本地 2 阿里云 3 七牛云 4 腾讯云)', `origin_name` varchar(255) NULL DEFAULT NULL COMMENT '原文件名', `object_name` varchar(50) NULL DEFAULT NULL COMMENT '新文件名', `hash` varchar(64) NULL DEFAULT NULL COMMENT '文件hash', `mime_type` varchar(255) NULL DEFAULT NULL COMMENT '资源类型', `storage_path` varchar(100) NULL DEFAULT NULL COMMENT '存储目录', `suffix` varchar(10) NULL DEFAULT NULL COMMENT '文件后缀', `size_byte` bigint(20) NULL DEFAULT NULL COMMENT '字节数', `size_info` varchar(50) NULL DEFAULT NULL COMMENT '文件大小', `url` varchar(255) NULL DEFAULT NULL COMMENT 'url地址', `remark` varchar(255) NULL DEFAULT NULL COMMENT '备注', `created_by` int(11) NULL DEFAULT NULL COMMENT '创建者', `updated_by` int(11) NULL DEFAULT NULL COMMENT '更新者', `create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间', `update_time` datetime(0) NULL DEFAULT NULL COMMENT '修改时间', `delete_time` datetime(0) NULL DEFAULT NULL COMMENT '删除时间', PRIMARY KEY (`id`) USING BTREE, INDEX `hash`(`hash`) USING BTREE, INDEX `idx_url`(`url`) USING BTREE, INDEX `idx_create_time`(`create_time`) USING BTREE, INDEX `idx_category_id`(`category_id`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 1 COMMENT = '附件信息表' ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of sa_system_attachment -- ---------------------------- -- ---------------------------- -- Table structure for sa_system_category -- ---------------------------- DROP TABLE IF EXISTS `sa_system_category`; CREATE TABLE `sa_system_category` ( `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '分类ID', `parent_id` int(11) NOT NULL DEFAULT 0 COMMENT '父id', `level` varchar(255) NULL DEFAULT NULL COMMENT '组集关系', `category_name` varchar(100) NOT NULL DEFAULT '' COMMENT '分类名称', `sort` int(11) NOT NULL DEFAULT 0 COMMENT '排序', `status` tinyint(1) NULL DEFAULT 1 COMMENT '状态', `remark` varchar(255) NULL DEFAULT NULL COMMENT '备注', `created_by` int(11) NULL DEFAULT NULL COMMENT '创建者', `updated_by` int(11) NULL DEFAULT NULL COMMENT '更新者', `create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间', `update_time` datetime(0) NULL DEFAULT NULL COMMENT '修改时间', `delete_time` datetime(0) NULL DEFAULT NULL COMMENT '删除时间', PRIMARY KEY (`id`) USING BTREE, INDEX `pid`(`parent_id`) USING BTREE, INDEX `sort`(`sort`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 6 COMMENT = '附件分类表' ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of sa_system_category -- ---------------------------- INSERT INTO `sa_system_category` VALUES (1, 0, '0,', '全部分类', 100, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_category` VALUES (2, 1, '0,1,', '图片分类', 100, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_category` VALUES (3, 1, '0,1,', '文件分类', 100, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_category` VALUES (4, 1, '0,1,', '系统图片', 100, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_category` VALUES (5, 1, '0,1,', '其他分类', 100, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); -- ---------------------------- -- Table structure for sa_system_config -- ---------------------------- DROP TABLE IF EXISTS `sa_system_config`; CREATE TABLE `sa_system_config` ( `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '编号', `group_id` int(11) NULL DEFAULT NULL COMMENT '组id', `key` varchar(32) NOT NULL COMMENT '配置键名', `value` text NULL COMMENT '配置值', `name` varchar(255) NULL DEFAULT NULL COMMENT '配置名称', `input_type` varchar(32) NULL DEFAULT NULL COMMENT '数据输入类型', `config_select_data` varchar(500) NULL DEFAULT NULL COMMENT '配置选项数据', `sort` smallint(5) UNSIGNED NULL DEFAULT 0 COMMENT '排序', `remark` varchar(255) NULL DEFAULT NULL COMMENT '备注', `created_by` int(11) NULL DEFAULT NULL COMMENT '创建人', `updated_by` int(11) NULL DEFAULT NULL COMMENT '更新人', `create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间', `update_time` datetime(0) NULL DEFAULT NULL COMMENT '修改时间', `delete_time` datetime(0) NULL DEFAULT NULL COMMENT '删除时间', PRIMARY KEY (`id`, `key`) USING BTREE, INDEX `group_id`(`group_id`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 302 COMMENT = '参数配置信息表' ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of sa_system_config -- ---------------------------- INSERT INTO `sa_system_config` VALUES (1, 1, 'site_copyright', 'Copyright © 2024 saithink', '版权信息', 'textarea', NULL, 96, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config` VALUES (2, 1, 'site_desc', '基于vue3 + webman 的极速开发框架', '网站描述', 'textarea', NULL, 97, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config` VALUES (3, 1, 'site_keywords', '后台管理系统', '网站关键字', 'input', NULL, 98, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config` VALUES (4, 1, 'site_name', 'SaiAdmin', '网站名称', 'input', NULL, 99, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config` VALUES (5, 1, 'site_record_number', '9527', '网站备案号', 'input', NULL, 95, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config` VALUES (6, 2, 'upload_allow_file', 'txt,doc,docx,xls,xlsx,ppt,pptx,rar,zip,7z,gz,pdf,wps,md,jpg,png,jpeg,mp4,pem,crt', '文件类型', 'input', NULL, 0, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config` VALUES (7, 2, 'upload_allow_image', 'jpg,jpeg,png,gif,svg,bmp', '图片类型', 'input', NULL, 0, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config` VALUES (8, 2, 'upload_mode', '1', '上传模式', 'select', '[{\"label\":\"本地上传\",\"value\":\"1\"},{\"label\":\"阿里云OSS\",\"value\":\"2\"},{\"label\":\"七牛云\",\"value\":\"3\"},{\"label\":\"腾讯云COS\",\"value\":\"4\"},{\"label\":\"亚马逊S3\",\"value\":\"5\"}]', 99, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config` VALUES (10, 2, 'upload_size', '52428800', '上传大小', 'input', NULL, 88, '单位Byte,1MB=1024*1024Byte', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config` VALUES (11, 2, 'local_root', 'public/storage/', '本地存储路径', 'input', NULL, 0, '本地存储文件路径', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config` VALUES (12, 2, 'local_domain', 'http://127.0.0.1:8787', '本地存储域名', 'input', NULL, 0, 'http://127.0.0.1:8787', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config` VALUES (13, 2, 'local_uri', '/storage/', '本地访问路径', 'input', NULL, 0, '访问是通过domain + uri', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config` VALUES (14, 2, 'qiniu_accessKey', '', '七牛key', 'input', NULL, 0, '七牛云存储secretId', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config` VALUES (15, 2, 'qiniu_secretKey', '', '七牛secret', 'input', NULL, 0, '七牛云存储secretKey', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config` VALUES (16, 2, 'qiniu_bucket', '', '七牛bucket', 'input', NULL, 0, '七牛云存储bucket', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config` VALUES (17, 2, 'qiniu_dirname', '', '七牛dirname', 'input', NULL, 0, '七牛云存储dirname', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config` VALUES (18, 2, 'qiniu_domain', '', '七牛domain', 'input', NULL, 0, '七牛云存储domain', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config` VALUES (19, 2, 'cos_secretId', '', '腾讯Id', 'input', NULL, 0, '腾讯云存储secretId', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config` VALUES (20, 2, 'cos_secretKey', '', '腾讯key', 'input', NULL, 0, '腾讯云secretKey', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config` VALUES (21, 2, 'cos_bucket', '', '腾讯bucket', 'input', NULL, 0, '腾讯云存储bucket', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config` VALUES (22, 2, 'cos_dirname', '', '腾讯dirname', 'input', NULL, 0, '腾讯云存储dirname', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config` VALUES (23, 2, 'cos_domain', '', '腾讯domain', 'input', NULL, 0, '腾讯云存储domain', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config` VALUES (24, 2, 'cos_region', '', '腾讯region', 'input', NULL, 0, '腾讯云存储region', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config` VALUES (25, 2, 'oss_accessKeyId', '', '阿里Id', 'input', NULL, 0, '阿里云存储accessKeyId', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config` VALUES (26, 2, 'oss_accessKeySecret', '', '阿里Secret', 'input', NULL, 0, '阿里云存储accessKeySecret', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config` VALUES (27, 2, 'oss_bucket', '', '阿里bucket', 'input', NULL, 0, '阿里云存储bucket', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config` VALUES (28, 2, 'oss_dirname', '', '阿里dirname', 'input', NULL, 0, '阿里云存储dirname', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config` VALUES (29, 2, 'oss_domain', '', '阿里domain', 'input', NULL, 0, '阿里云存储domain', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config` VALUES (30, 2, 'oss_endpoint', '', '阿里endpoint', 'input', NULL, 0, '阿里云存储endpoint', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config` VALUES (31, 3, 'Host', 'smtp.qq.com', 'SMTP服务器', 'input', '', 100, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config` VALUES (32, 3, 'Port', '465', 'SMTP端口', 'input', '', 100, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config` VALUES (33, 3, 'Username', '', 'SMTP用户名', 'input', '', 100, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config` VALUES (34, 3, 'Password', '', 'SMTP密码', 'input', '', 100, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config` VALUES (35, 3, 'SMTPSecure', 'ssl', 'SMTP验证方式', 'radio', '[\r\n {\"label\":\"ssl\",\"value\":\"ssl\"},\r\n {\"label\":\"tsl\",\"value\":\"tsl\"}\r\n]', 100, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config` VALUES (36, 3, 'From', '', '默认发件人', 'input', '', 100, '默认发件的邮箱地址', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config` VALUES (37, 3, 'FromName', '账户注册', '默认发件名称', 'input', '', 100, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config` VALUES (38, 3, 'CharSet', 'UTF-8', '编码', 'input', '', 100, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config` VALUES (39, 3, 'SMTPDebug', '0', '调试模式', 'radio', '[\r\n {\"label\":\"关闭\",\"value\":\"0\"},\r\n {\"label\":\"client\",\"value\":\"1\"},\r\n {\"label\":\"server\",\"value\":\"2\"}\r\n]', 100, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config` VALUES (40, 2, 's3_key', '', 'key', 'input', '', 0, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config` VALUES (41, 2, 's3_secret', '', 'secret', 'input', '', 0, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config` VALUES (42, 2, 's3_bucket', '', 'bucket', 'input', '', 0, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config` VALUES (43, 2, 's3_dirname', '', 'dirname', 'input', '', 0, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config` VALUES (44, 2, 's3_domain', '', 'domain', 'input', '', 0, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config` VALUES (45, 2, 's3_region', '', 'region', 'input', '', 0, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config` VALUES (46, 2, 's3_version', '', 'version', 'input', '', 0, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config` VALUES (47, 2, 's3_use_path_style_endpoint', '', 'path_style_endpoint', 'input', '', 0, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config` VALUES (48, 2, 's3_endpoint', '', 'endpoint', 'input', '', 0, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config` VALUES (49, 2, 's3_acl', '', 'acl', 'input', '', 0, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); -- ---------------------------- -- Table structure for sa_system_config_group -- ---------------------------- DROP TABLE IF EXISTS `sa_system_config_group`; CREATE TABLE `sa_system_config_group` ( `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键', `name` varchar(50) NULL DEFAULT NULL COMMENT '字典名称', `code` varchar(100) NULL DEFAULT NULL COMMENT '字典标示', `remark` varchar(255) NULL DEFAULT NULL COMMENT '备注', `created_by` int(11) NULL DEFAULT NULL COMMENT '创建人', `updated_by` int(11) NULL DEFAULT NULL COMMENT '更新人', `create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间', `update_time` datetime(0) NULL DEFAULT NULL COMMENT '修改时间', `delete_time` datetime(0) NULL DEFAULT NULL COMMENT '删除时间', PRIMARY KEY (`id`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 4 COMMENT = '参数配置分组表' ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of sa_system_config_group -- ---------------------------- INSERT INTO `sa_system_config_group` VALUES (1, '站点配置', 'site_config', '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config_group` VALUES (2, '上传配置', 'upload_config', NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_config_group` VALUES (3, '邮件服务', 'email_config', NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); -- ---------------------------- -- Table structure for sa_system_dept -- ---------------------------- DROP TABLE IF EXISTS `sa_system_dept`; CREATE TABLE `sa_system_dept` ( `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, `parent_id` bigint(20) UNSIGNED NULL DEFAULT 0 COMMENT '父级ID,0为根节点', `name` varchar(64) NOT NULL COMMENT '部门名称', `code` varchar(64) NULL DEFAULT NULL COMMENT '部门编码', `leader_id` bigint(20) UNSIGNED NULL DEFAULT NULL COMMENT '部门负责人ID', `level` varchar(255) NULL DEFAULT '' COMMENT '祖级列表,格式: 0,1,5, (便于查询子孙节点)', `sort` int(11) NULL DEFAULT 0 COMMENT '排序,数字越小越靠前', `status` tinyint(1) NULL DEFAULT 1 COMMENT '状态: 1启用, 0禁用', `remark` varchar(255) NULL DEFAULT NULL COMMENT '备注', `created_by` int(11) NULL DEFAULT NULL COMMENT '创建者', `updated_by` int(11) NULL DEFAULT NULL COMMENT '更新者', `create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间', `update_time` datetime(0) NULL DEFAULT NULL COMMENT '修改时间', `delete_time` datetime(0) NULL DEFAULT NULL COMMENT '删除时间', PRIMARY KEY (`id`) USING BTREE, INDEX `idx_parent_id`(`parent_id`) USING BTREE, INDEX `idx_path`(`level`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 1114 COMMENT = '部门表' ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of sa_system_dept -- ---------------------------- INSERT INTO `sa_system_dept` VALUES (1, 0, '腾讯集团', 'GROUP', 1, '0,', 100, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); -- ---------------------------- -- Table structure for sa_system_dict_data -- ---------------------------- DROP TABLE IF EXISTS `sa_system_dict_data`; CREATE TABLE `sa_system_dict_data` ( `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键', `type_id` int(11) UNSIGNED NULL DEFAULT NULL COMMENT '字典类型ID', `label` varchar(50) NULL DEFAULT NULL COMMENT '字典标签', `value` varchar(100) NULL DEFAULT NULL COMMENT '字典值', `color` varchar(50) NULL DEFAULT NULL COMMENT '字典颜色', `code` varchar(100) NULL DEFAULT NULL COMMENT '字典标示', `sort` smallint(5) UNSIGNED NULL DEFAULT 0 COMMENT '排序', `status` smallint(6) NULL DEFAULT 1 COMMENT '状态 (1正常 2停用)', `remark` varchar(255) NULL DEFAULT NULL COMMENT '备注', `created_by` int(11) NULL DEFAULT NULL COMMENT '创建者', `updated_by` int(11) NULL DEFAULT NULL COMMENT '更新者', `create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间', `update_time` datetime(0) NULL DEFAULT NULL COMMENT '修改时间', `delete_time` datetime(0) NULL DEFAULT NULL COMMENT '删除时间', PRIMARY KEY (`id`) USING BTREE, INDEX `type_id`(`type_id`) USING BTREE, INDEX `idx_code`(`code`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 50 COMMENT = '字典数据表' ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of sa_system_dict_data -- ---------------------------- INSERT INTO `sa_system_dict_data` VALUES (2, 2, '本地存储', '1', '#5d87ff', 'upload_mode', 99, 1, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_dict_data` VALUES (3, 2, '阿里云OSS', '2', '#f9901f', 'upload_mode', 98, 1, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_dict_data` VALUES (4, 2, '七牛云', '3', '#00ced1', 'upload_mode', 97, 1, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_dict_data` VALUES (5, 2, '腾讯云COS', '4', '#1d84ff', 'upload_mode', 96, 1, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_dict_data` VALUES (6, 2, '亚马逊S3', '5', '#ff80c8', 'upload_mode', 95, 1, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_dict_data` VALUES (7, 3, '正常', '1', '#13deb9', 'data_status', 0, 1, '1为正常', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_dict_data` VALUES (8, 3, '停用', '2', '#ff4d4f', 'data_status', 0, 1, '2为停用', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_dict_data` VALUES (9, 4, '统计页面', 'statistics', '#00ced1', 'dashboard', 100, 1, '管理员用', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_dict_data` VALUES (10, 4, '工作台', 'work', '#ff8c00', 'dashboard', 50, 1, '员工使用', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_dict_data` VALUES (11, 5, '男', '1', '#5d87ff', 'gender', 0, 1, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_dict_data` VALUES (12, 5, '女', '2', '#ff4500', 'gender', 0, 1, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_dict_data` VALUES (13, 5, '未知', '3', '#b48df3', 'gender', 0, 1, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_dict_data` VALUES (16, 12, '图片', 'image', '#60c041', 'attachment_type', 10, 1, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_dict_data` VALUES (17, 12, '文档', 'text', '#1d84ff', 'attachment_type', 9, 1, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_dict_data` VALUES (18, 12, '音频', 'audio', '#00ced1', 'attachment_type', 8, 1, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_dict_data` VALUES (19, 12, '视频', 'video', '#ff4500', 'attachment_type', 7, 1, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_dict_data` VALUES (20, 12, '应用程序', 'application', '#ff8c00', 'attachment_type', 6, 1, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_dict_data` VALUES (21, 13, '目录', '1', '#909399', 'menu_type', 100, 1, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_dict_data` VALUES (22, 13, '菜单', '2', '#1e90ff', 'menu_type', 100, 1, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_dict_data` VALUES (23, 13, '按钮', '3', '#ff4500', 'menu_type', 100, 1, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_dict_data` VALUES (24, 13, '外链', '4', '#00ced1', 'menu_type', 100, 1, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_dict_data` VALUES (25, 14, '是', '1', '#60c041', 'yes_or_no', 100, 1, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_dict_data` VALUES (26, 14, '否', '2', '#ff4500', 'yes_or_no', 100, 1, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_dict_data` VALUES (47, 20, 'URL任务GET', '1', '#5d87ff', 'crontab_task_type', 100, 1, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_dict_data` VALUES (48, 20, 'URL任务POST', '2', '#00ced1', 'crontab_task_type', 100, 1, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_dict_data` VALUES (49, 20, '类任务', '3', '#ff8c00', 'crontab_task_type', 100, 1, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); -- ---------------------------- -- Table structure for sa_system_dict_type -- ---------------------------- DROP TABLE IF EXISTS `sa_system_dict_type`; CREATE TABLE `sa_system_dict_type` ( `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键', `name` varchar(50) NULL DEFAULT NULL COMMENT '字典名称', `code` varchar(100) NULL DEFAULT NULL COMMENT '字典标示', `status` smallint(6) NULL DEFAULT 1 COMMENT '状态 (1正常 2停用)', `remark` varchar(255) NULL DEFAULT NULL COMMENT '备注', `created_by` int(11) NULL DEFAULT NULL COMMENT '创建者', `updated_by` int(11) NULL DEFAULT NULL COMMENT '更新者', `create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间', `update_time` datetime(0) NULL DEFAULT NULL COMMENT '修改时间', `delete_time` datetime(0) NULL DEFAULT NULL COMMENT '删除时间', PRIMARY KEY (`id`) USING BTREE, INDEX `idx_code`(`code`) USING BTREE, INDEX `idx_name`(`name`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 24 COMMENT = '字典类型表' ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of sa_system_dict_type -- ---------------------------- INSERT INTO `sa_system_dict_type` VALUES (2, '存储模式', 'upload_mode', 1, '上传文件存储模式', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_dict_type` VALUES (3, '数据状态', 'data_status', 1, '通用数据状态', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_dict_type` VALUES (4, '后台首页', 'dashboard', 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_dict_type` VALUES (5, '性别', 'gender', 1, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_dict_type` VALUES (12, '附件类型', 'attachment_type', 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_dict_type` VALUES (13, '菜单类型', 'menu_type', 1, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_dict_type` VALUES (14, '是否', 'yes_or_no', 1, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_dict_type` VALUES (20, '定时任务类型', 'crontab_task_type', 1, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); -- ---------------------------- -- Table structure for sa_system_login_log -- ---------------------------- DROP TABLE IF EXISTS `sa_system_login_log`; CREATE TABLE `sa_system_login_log` ( `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键', `username` varchar(20) NULL DEFAULT NULL COMMENT '用户名', `ip` varchar(45) NULL DEFAULT NULL COMMENT '登录IP地址', `ip_location` varchar(255) NULL DEFAULT NULL COMMENT 'IP所属地', `os` varchar(50) NULL DEFAULT NULL COMMENT '操作系统', `browser` varchar(50) NULL DEFAULT NULL COMMENT '浏览器', `status` smallint(6) NULL DEFAULT 1 COMMENT '登录状态 (1成功 2失败)', `message` varchar(50) NULL DEFAULT NULL COMMENT '提示消息', `login_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0) ON UPDATE CURRENT_TIMESTAMP(0) COMMENT '登录时间', `remark` varchar(255) NULL DEFAULT NULL COMMENT '备注', `created_by` int(11) NULL DEFAULT NULL COMMENT '创建者', `updated_by` int(11) NULL DEFAULT NULL COMMENT '更新者', `create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间', `update_time` datetime(0) NULL DEFAULT NULL COMMENT '更新时间', `delete_time` datetime(0) NULL DEFAULT NULL COMMENT '删除时间', PRIMARY KEY (`id`) USING BTREE, INDEX `username`(`username`) USING BTREE, INDEX `idx_create_time`(`create_time`) USING BTREE, INDEX `idx_login_time`(`login_time`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 1 COMMENT = '登录日志表' ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of sa_system_login_log -- ---------------------------- -- ---------------------------- -- Table structure for sa_system_mail -- ---------------------------- DROP TABLE IF EXISTS `sa_system_mail`; CREATE TABLE `sa_system_mail` ( `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '编号', `gateway` varchar(50) NULL DEFAULT NULL COMMENT '网关', `from` varchar(50) NULL DEFAULT NULL COMMENT '发送人', `email` varchar(50) NULL DEFAULT NULL COMMENT '接收人', `code` varchar(20) NULL DEFAULT NULL COMMENT '验证码', `content` varchar(500) NULL DEFAULT NULL COMMENT '邮箱内容', `status` varchar(20) NULL DEFAULT NULL COMMENT '发送状态', `response` varchar(500) NULL DEFAULT NULL COMMENT '返回结果', `create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间', `update_time` datetime(0) NULL DEFAULT NULL COMMENT '修改时间', `delete_time` datetime(0) NULL DEFAULT NULL COMMENT '删除时间', PRIMARY KEY (`id`) USING BTREE, INDEX `idx_create_time`(`create_time`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 1 COMMENT = '邮件记录' ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of sa_system_mail -- ---------------------------- -- ---------------------------- -- Table structure for sa_system_menu -- ---------------------------- DROP TABLE IF EXISTS `sa_system_menu`; CREATE TABLE `sa_system_menu` ( `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, `parent_id` bigint(20) UNSIGNED NULL DEFAULT 0 COMMENT '父级ID', `name` varchar(64) NOT NULL COMMENT '菜单名称', `code` varchar(64) NULL DEFAULT NULL COMMENT '组件名称', `slug` varchar(100) NULL DEFAULT NULL COMMENT '权限标识,如 user:list, user:add', `type` tinyint(1) NOT NULL DEFAULT 1 COMMENT '类型: 1目录, 2菜单, 3按钮/API', `path` varchar(255) NULL DEFAULT NULL COMMENT '路由地址(前端)或API路径(后端)', `component` varchar(255) NULL DEFAULT NULL COMMENT '前端组件路径,如 layout/User', `method` varchar(10) NULL DEFAULT NULL COMMENT '请求方式', `icon` varchar(64) NULL DEFAULT NULL COMMENT '图标', `sort` int(11) NULL DEFAULT 100 COMMENT '排序', `link_url` varchar(255) NULL DEFAULT NULL COMMENT '外部链接', `is_iframe` tinyint(1) NULL DEFAULT 2 COMMENT '是否iframe', `is_keep_alive` tinyint(1) NULL DEFAULT 2 COMMENT '是否缓存', `is_hidden` tinyint(1) NULL DEFAULT 2 COMMENT '是否隐藏', `is_fixed_tab` tinyint(1) NULL DEFAULT 2 COMMENT '是否固定标签页', `is_full_page` tinyint(1) NULL DEFAULT 2 COMMENT '是否全屏', `generate_id` int(11) NULL DEFAULT 0 COMMENT '生成id', `generate_key` varchar(255) NULL DEFAULT NULL COMMENT '生成key', `status` tinyint(1) NULL DEFAULT 1 COMMENT '状态', `remark` varchar(255) NULL DEFAULT NULL, `created_by` int(11) NULL DEFAULT NULL COMMENT '创建者', `updated_by` int(11) NULL DEFAULT NULL COMMENT '更新者', `create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间', `update_time` datetime(0) NULL DEFAULT NULL COMMENT '修改时间', `delete_time` datetime(0) NULL DEFAULT NULL COMMENT '删除时间', PRIMARY KEY (`id`) USING BTREE, INDEX `idx_parent_id`(`parent_id`) USING BTREE, INDEX `idx_slug`(`slug`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 1000 COMMENT = '菜单权限表' ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of sa_system_menu -- ---------------------------- INSERT INTO `sa_system_menu` VALUES (1, 0, '仪表盘', 'Dashboard', NULL, 1, '/dashboard', NULL, NULL, 'ri:pie-chart-line', 100, NULL, 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (2, 1, '工作台', 'Console', NULL, 2, 'console', '/dashboard/console', NULL, 'ri:home-smile-2-line', 100, NULL, 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (3, 0, '系统管理', 'System', NULL, 1, '/system', NULL, NULL, 'ri:user-3-line', 100, NULL, 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (4, 3, '用户管理', 'User', NULL, 2, 'user', '/system/user', NULL, 'ri:user-line', 100, NULL, 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (5, 3, '部门管理', 'Dept', NULL, 2, 'dept', '/system/dept', NULL, 'ri:node-tree', 100, NULL, 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (6, 3, '角色管理', 'Role', NULL, 2, 'role', '/system/role', NULL, 'ri:admin-line', 100, NULL, 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (7, 3, '岗位管理', 'Post', '', 2, 'post', '/system/post', NULL, 'ri:signpost-line', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (8, 3, '菜单管理', 'Menu', NULL, 2, 'menu', '/system/menu', NULL, 'ri:menu-line', 100, NULL, 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (10, 0, '运维管理', 'Safeguard', NULL, 1, '/safeguard', '', NULL, 'ri:shield-check-line', 100, NULL, 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (11, 10, '缓存管理', 'Cache', '', 2, 'cache', '/safeguard/cache', NULL, 'ri:keyboard-box-line', 80, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (12, 10, '数据字典', 'Dict', NULL, 2, 'dict', '/safeguard/dict', NULL, 'ri:database-2-line', 100, NULL, 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (13, 10, '附件管理', 'Attachment', '', 2, 'attachment', '/safeguard/attachment', NULL, 'ri:file-cloud-line', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (14, 10, '数据表维护', 'Database', '', 2, 'database', '/safeguard/database', NULL, 'ri:database-line', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (15, 10, '登录日志', 'LoginLog', '', 2, 'login-log', '/safeguard/login-log', NULL, 'ri:login-circle-line', 50, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (16, 10, '操作日志', 'OperLog', '', 2, 'oper-log', '/safeguard/oper-log', NULL, 'ri:shield-keyhole-line', 50, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (17, 10, '邮件日志', 'EmailLog', '', 2, 'email-log', '/safeguard/email-log', NULL, 'ri:mail-line', 50, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (18, 3, '系统设置', 'Config', NULL, 2, 'config', '/system/config', NULL, 'ri:settings-4-line', 100, NULL, 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (19, 0, '官方文档', 'Document', '', 4, '', '', NULL, 'ri:file-copy-2-fill', 90, 'https://saithink.top', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (20, 4, '数据列表', '', 'core:user:index', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (21, 1, '个人中心', 'UserCenter', '', 2, 'user-center', '/dashboard/user-center/index', NULL, 'ri:user-2-line', 100, '', 2, 2, 1, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (22, 4, '添加', '', 'core:user:save', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (23, 4, '修改', '', 'core:user:update', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (24, 4, '读取', '', 'core:user:read', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (25, 4, '删除', '', 'core:user:destroy', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (26, 4, '重置密码', '', 'core:user:password', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (27, 4, '清理缓存', '', 'core:user:cache', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (28, 4, '设置工作台', '', 'core:user:home', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (29, 5, '数据列表', '', 'core:dept:index', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (30, 5, '添加', '', 'core:dept:save', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (31, 5, '修改', '', 'core:dept:update', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (32, 5, '读取', '', 'core:dept:read', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (33, 5, '删除', '', 'core:dept:destroy', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (34, 6, '添加', '', 'core:role:save', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (35, 6, '数据列表', '', 'core:role:index', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (36, 6, '修改', '', 'core:role:update', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (37, 6, '读取', '', 'core:role:read', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (38, 6, '删除', '', 'core:role:destroy', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (39, 6, '菜单权限', '', 'core:role:menu', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (41, 7, '数据列表', '', 'core:post:index', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (42, 7, '添加', '', 'core:post:save', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (43, 7, '修改', '', 'core:post:update', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (44, 7, '读取', '', 'core:post:read', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (45, 7, '删除', '', 'core:post:destroy', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (46, 7, '导入', '', 'core:post:import', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (47, 7, '导出', '', 'core:post:export', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (48, 8, '数据列表', '', 'core:menu:index', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (49, 8, '读取', '', 'core:menu:read', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (50, 8, '添加', '', 'core:menu:save', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (51, 8, '修改', '', 'core:menu:update', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (52, 8, '删除', '', 'core:menu:destroy', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (53, 18, '数据列表', '', 'core:config:index', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (54, 18, '管理', '', 'core:config:edit', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (55, 18, '修改', '', 'core:config:update', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (56, 12, '数据列表', '', 'core:dict:index', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (57, 12, '管理', '', 'core:dict:edit', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (58, 13, '数据列表', '', 'core:attachment:index', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (59, 13, '管理', '', 'core:attachment:edit', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (60, 14, '数据表列表', '', 'core:database:index', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (61, 14, '数据表维护', '', 'core:database:edit', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (62, 14, '回收站数据', '', 'core:recycle:index', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (63, 14, '回收站管理', '', 'core:recycle:edit', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (64, 15, '数据列表', '', 'core:logs:login', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (65, 15, '删除', '', 'core:logs:deleteLogin', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (66, 16, '数据列表', '', 'core:logs:Oper', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (67, 16, '删除', '', 'core:logs:deleteOper', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (68, 17, '数据列表', '', 'core:email:index', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (69, 17, '删除', '', 'core:email:destroy', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (70, 10, '服务监控', 'Server', '', 2, 'server', '/safeguard/server', NULL, 'ri:server-line', 90, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (71, 70, '数据列表', '', 'core:server:monitor', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (72, 11, '数据列表', '', 'core:server:cache', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (73, 11, '缓存清理', '', 'core:server:clear', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (74, 2, '登录数据统计', '', 'core:console:list', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (75, 0, '附加权限', 'Permission', '', 1, 'permission', '', NULL, 'ri:apps-2-ai-line', 100, '', 2, 2, 1, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (76, 75, '上传图片', '', 'core:system:uploadImage', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (77, 75, '上传文件', '', 'core:system:uploadFile', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (78, 75, '附件列表', '', 'core:system:resource', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (79, 75, '用户列表', '', 'core:system:user', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (80, 0, '工具', 'Tool', '', 1, '/tool', '', NULL, 'ri:tools-line', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (81, 80, '代码生成', 'Code', '', 2, 'code', '/tool/code', NULL, 'ri:code-s-slash-line', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (82, 80, '定时任务', 'Crontab', '', 2, 'crontab', '/tool/crontab', NULL, 'ri:time-line', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (83, 82, '数据列表', '', 'tool:crontab:index', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (84, 82, '管理', '', 'tool:crontab:edit', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (85, 82, '运行任务', '', 'tool:crontab:run', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (86, 81, '数据列表', '', 'tool:code:index', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (87, 81, '管理', '', 'tool:code:edit', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (88, 0, '插件市场', 'Plugin', '', 2, '/plugin', '/plugin/saipackage/install/index', NULL, 'ri:apps-2-ai-line', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); -- ---------------------------- -- Table structure for sa_system_oper_log -- ---------------------------- DROP TABLE IF EXISTS `sa_system_oper_log`; CREATE TABLE `sa_system_oper_log` ( `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键', `username` varchar(20) NULL DEFAULT NULL COMMENT '用户名', `app` varchar(50) NULL DEFAULT NULL COMMENT '应用名称', `method` varchar(20) NULL DEFAULT NULL COMMENT '请求方式', `router` varchar(500) NULL DEFAULT NULL COMMENT '请求路由', `service_name` varchar(30) NULL DEFAULT NULL COMMENT '业务名称', `ip` varchar(45) NULL DEFAULT NULL COMMENT '请求IP地址', `ip_location` varchar(255) NULL DEFAULT NULL COMMENT 'IP所属地', `request_data` text NULL COMMENT '请求数据', `remark` varchar(255) NULL DEFAULT NULL COMMENT '备注', `created_by` int(11) NULL DEFAULT NULL COMMENT '创建者', `updated_by` int(11) NULL DEFAULT NULL COMMENT '更新者', `create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间', `update_time` datetime(0) NULL DEFAULT NULL COMMENT '更新时间', `delete_time` datetime(0) NULL DEFAULT NULL COMMENT '删除时间', PRIMARY KEY (`id`) USING BTREE, INDEX `username`(`username`) USING BTREE, INDEX `idx_create_time`(`create_time`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 1 COMMENT = '操作日志表' ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of sa_system_oper_log -- ---------------------------- -- ---------------------------- -- Table structure for sa_system_post -- ---------------------------- DROP TABLE IF EXISTS `sa_system_post`; CREATE TABLE `sa_system_post` ( `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键', `name` varchar(50) NULL DEFAULT NULL COMMENT '岗位名称', `code` varchar(100) NULL DEFAULT NULL COMMENT '岗位代码', `sort` smallint(5) UNSIGNED NULL DEFAULT 0 COMMENT '排序', `status` smallint(6) NULL DEFAULT 1 COMMENT '状态 (1正常 2停用)', `remark` varchar(255) NULL DEFAULT NULL COMMENT '备注', `created_by` int(11) NULL DEFAULT NULL COMMENT '创建者', `updated_by` int(11) NULL DEFAULT NULL COMMENT '更新者', `create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间', `update_time` datetime(0) NULL DEFAULT NULL COMMENT '修改时间', `delete_time` datetime(0) NULL DEFAULT NULL COMMENT '删除时间', PRIMARY KEY (`id`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 87 COMMENT = '岗位信息表' ROW_FORMAT = Dynamic; -- ---------------------------- -- Table structure for sa_system_role -- ---------------------------- DROP TABLE IF EXISTS `sa_system_role`; CREATE TABLE `sa_system_role` ( `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, `name` varchar(64) NOT NULL COMMENT '角色名称', `code` varchar(64) NOT NULL COMMENT '角色标识(英文唯一),如: hr_manager', `level` int(11) NULL DEFAULT 1 COMMENT '角色级别(1-100):用于行政控制,不可操作级别>=自己的角色', `data_scope` tinyint(4) NULL DEFAULT 1 COMMENT '数据范围: 1全部, 2本部门及下属, 3本部门, 4仅本人, 5自定义', `remark` varchar(255) NULL DEFAULT NULL COMMENT '备注', `sort` int(11) NULL DEFAULT 100, `status` tinyint(1) NULL DEFAULT 1 COMMENT '状态: 1启用, 0禁用', `created_by` int(11) NULL DEFAULT NULL COMMENT '创建者', `updated_by` int(11) NULL DEFAULT NULL COMMENT '更新者', `create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间', `update_time` datetime(0) NULL DEFAULT NULL COMMENT '修改时间', `delete_time` datetime(0) NULL DEFAULT NULL COMMENT '删除时间', PRIMARY KEY (`id`) USING BTREE, UNIQUE INDEX `uk_slug`(`code`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 17 COMMENT = '角色表' ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of sa_system_role -- ---------------------------- INSERT INTO `sa_system_role` VALUES (1, '超级管理员', 'super_admin', 100, 1, '系统维护者,拥有所有权限', 100, 1, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); -- ---------------------------- -- Table structure for sa_system_role_dept -- ---------------------------- DROP TABLE IF EXISTS `sa_system_role_dept`; CREATE TABLE `sa_system_role_dept` ( `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, `role_id` bigint(20) UNSIGNED NOT NULL, `dept_id` bigint(20) UNSIGNED NOT NULL, PRIMARY KEY (`id`) USING BTREE, INDEX `idx_role_id`(`role_id`) USING BTREE, INDEX `idx_dept_id`(`dept_id`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 1 COMMENT = '角色-自定义数据权限关联' ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of sa_system_role_dept -- ---------------------------- -- ---------------------------- -- Table structure for sa_system_role_menu -- ---------------------------- DROP TABLE IF EXISTS `sa_system_role_menu`; CREATE TABLE `sa_system_role_menu` ( `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, `role_id` bigint(20) UNSIGNED NOT NULL, `menu_id` bigint(20) UNSIGNED NOT NULL, PRIMARY KEY (`id`) USING BTREE, INDEX `idx_menu_id`(`menu_id`) USING BTREE, INDEX `idx_role_id`(`role_id`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 1 COMMENT = '角色权限关联' ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of sa_system_role_menu -- ---------------------------- -- ---------------------------- -- Table structure for sa_system_user -- ---------------------------- DROP TABLE IF EXISTS `sa_system_user`; CREATE TABLE `sa_system_user` ( `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, `username` varchar(64) NOT NULL COMMENT '登录账号', `password` varchar(255) NOT NULL COMMENT '加密密码', `realname` varchar(64) NULL DEFAULT NULL COMMENT '真实姓名', `gender` varchar(10) NULL DEFAULT NULL COMMENT '性别', `avatar` varchar(255) NULL DEFAULT NULL COMMENT '头像', `email` varchar(128) NULL DEFAULT NULL COMMENT '邮箱', `phone` varchar(20) NULL DEFAULT NULL COMMENT '手机号', `signed` varchar(255) NULL DEFAULT NULL COMMENT '个性签名', `dashboard` varchar(255) NULL DEFAULT 'work' COMMENT '工作台', `dept_id` bigint(20) UNSIGNED NULL DEFAULT NULL COMMENT '主归属部门', `is_super` tinyint(1) NULL DEFAULT 0 COMMENT '是否超级管理员: 1是(跳过权限检查), 0否', `status` tinyint(1) NULL DEFAULT 1 COMMENT '状态: 1启用, 0禁用', `remark` varchar(255) NULL DEFAULT NULL COMMENT '备注', `login_time` timestamp(0) NULL DEFAULT NULL COMMENT '最后登录时间', `login_ip` varchar(45) NULL DEFAULT NULL COMMENT '最后登录IP', `created_by` int(11) NULL DEFAULT NULL COMMENT '创建者', `updated_by` int(11) NULL DEFAULT NULL COMMENT '更新者', `create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间', `update_time` datetime(0) NULL DEFAULT NULL COMMENT '修改时间', `delete_time` datetime(0) NULL DEFAULT NULL COMMENT '删除时间', PRIMARY KEY (`id`) USING BTREE, UNIQUE INDEX `uk_username`(`username`) USING BTREE, INDEX `idx_dept_id`(`dept_id`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 110 COMMENT = '用户表' ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of sa_system_user -- ---------------------------- INSERT INTO `sa_system_user` VALUES (1, 'admin', '$2y$10$wnixh48uDnaW/6D9EygDd.OHJK0vQY/4nHaTjMKBCVDBP2NiTatqS', '祭道之上', '2', 'https://image.saithink.top/saiadmin/avatar.jpg', 'saiadmin@admin.com', '15888888888', 'SaiAdmin是兼具设计美学与高效开发的后台系统!', 'statistics', 1, 1, 1, NULL, NULL, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); -- ---------------------------- -- Table structure for sa_system_user_post -- ---------------------------- DROP TABLE IF EXISTS `sa_system_user_post`; CREATE TABLE `sa_system_user_post` ( `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键', `user_id` bigint(20) UNSIGNED NOT NULL COMMENT '用户主键', `post_id` bigint(20) UNSIGNED NOT NULL COMMENT '岗位主键', PRIMARY KEY (`id`) USING BTREE, INDEX `idx_user_id`(`user_id`) USING BTREE, INDEX `idx_post_id`(`post_id`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 1 COMMENT = '用户与岗位关联表' ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of sa_system_user_post -- ---------------------------- -- ---------------------------- -- Table structure for sa_system_user_role -- ---------------------------- DROP TABLE IF EXISTS `sa_system_user_role`; CREATE TABLE `sa_system_user_role` ( `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, `user_id` bigint(20) UNSIGNED NOT NULL, `role_id` bigint(20) UNSIGNED NOT NULL, PRIMARY KEY (`id`) USING BTREE, INDEX `idx_role_id`(`role_id`) USING BTREE, INDEX `idx_user_id`(`user_id`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 55 COMMENT = '用户角色关联' ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of sa_system_user_role -- ---------------------------- INSERT INTO `sa_system_user_role` VALUES (1, 1, 1); -- ---------------------------- -- Table structure for sa_tool_crontab -- ---------------------------- DROP TABLE IF EXISTS `sa_tool_crontab`; CREATE TABLE `sa_tool_crontab` ( `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键', `name` varchar(100) NULL DEFAULT NULL COMMENT '任务名称', `type` smallint(6) NULL DEFAULT 4 COMMENT '任务类型', `target` varchar(500) NULL DEFAULT NULL COMMENT '调用任务字符串', `parameter` varchar(1000) NULL DEFAULT NULL COMMENT '调用任务参数', `task_style` tinyint(1) NULL DEFAULT NULL COMMENT '执行类型', `rule` varchar(32) NULL DEFAULT NULL COMMENT '任务执行表达式', `singleton` smallint(6) NULL DEFAULT 1 COMMENT '是否单次执行 (1 是 2 不是)', `status` smallint(6) NULL DEFAULT 1 COMMENT '状态 (1正常 2停用)', `remark` varchar(255) NULL DEFAULT NULL COMMENT '备注', `created_by` int(11) NULL DEFAULT NULL COMMENT '创建者', `updated_by` int(11) NULL DEFAULT NULL COMMENT '更新者', `create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间', `update_time` datetime(0) NULL DEFAULT NULL COMMENT '修改时间', `delete_time` datetime(0) NULL DEFAULT NULL COMMENT '删除时间', PRIMARY KEY (`id`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 1 COMMENT = '定时任务信息表' ROW_FORMAT = Dynamic; -- ---------------------------- -- Table structure for sa_tool_crontab_log -- ---------------------------- DROP TABLE IF EXISTS `sa_tool_crontab_log`; CREATE TABLE `sa_tool_crontab_log` ( `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键', `crontab_id` int(11) UNSIGNED NULL DEFAULT NULL COMMENT '任务ID', `name` varchar(255) NULL DEFAULT NULL COMMENT '任务名称', `target` varchar(500) NULL DEFAULT NULL COMMENT '任务调用目标字符串', `parameter` varchar(1000) NULL DEFAULT NULL COMMENT '任务调用参数', `exception_info` varchar(2000) NULL DEFAULT NULL COMMENT '异常信息', `status` smallint(6) NULL DEFAULT 1 COMMENT '执行状态 (1成功 2失败)', `create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间', `update_time` datetime(0) NULL DEFAULT NULL COMMENT '修改时间', `delete_time` datetime(0) NULL DEFAULT NULL COMMENT '删除时间', PRIMARY KEY (`id`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 1 COMMENT = '定时任务执行日志表' ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of sa_tool_crontab_log -- ---------------------------- -- ---------------------------- -- Table structure for sa_tool_generate_columns -- ---------------------------- DROP TABLE IF EXISTS `sa_tool_generate_columns`; CREATE TABLE `sa_tool_generate_columns` ( `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键', `table_id` int(11) UNSIGNED NULL DEFAULT NULL COMMENT '所属表ID', `column_name` varchar(200) NULL DEFAULT NULL COMMENT '字段名称', `column_comment` varchar(255) NULL DEFAULT NULL COMMENT '字段注释', `column_type` varchar(50) NULL DEFAULT NULL COMMENT '字段类型', `default_value` varchar(50) NULL DEFAULT NULL COMMENT '默认值', `is_pk` smallint(6) NULL DEFAULT 1 COMMENT '1 非主键 2 主键', `is_required` smallint(6) NULL DEFAULT 1 COMMENT '1 非必填 2 必填', `is_insert` smallint(6) NULL DEFAULT 1 COMMENT '1 非插入字段 2 插入字段', `is_edit` smallint(6) NULL DEFAULT 1 COMMENT '1 非编辑字段 2 编辑字段', `is_list` smallint(6) NULL DEFAULT 1 COMMENT '1 非列表显示字段 2 列表显示字段', `is_query` smallint(6) NULL DEFAULT 1 COMMENT '1 非查询字段 2 查询字段', `is_sort` smallint(6) NULL DEFAULT 1 COMMENT '1 非排序 2 排序', `query_type` varchar(100) NULL DEFAULT 'eq' COMMENT '查询方式 eq 等于, neq 不等于, gt 大于, lt 小于, like 范围', `view_type` varchar(100) NULL DEFAULT 'text' COMMENT '页面控件,text, textarea, password, select, checkbox, radio, date, upload, ma-upload(封装的上传控件)', `dict_type` varchar(200) NULL DEFAULT NULL COMMENT '字典类型', `allow_roles` varchar(255) NULL DEFAULT NULL COMMENT '允许查看该字段的角色', `options` varchar(1000) NULL DEFAULT NULL COMMENT '字段其他设置', `sort` tinyint(3) UNSIGNED NULL DEFAULT 0 COMMENT '排序', `remark` varchar(255) NULL DEFAULT NULL COMMENT '备注', `created_by` int(11) NULL DEFAULT NULL COMMENT '创建者', `updated_by` int(11) NULL DEFAULT NULL COMMENT '更新者', `create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间', `update_time` datetime(0) NULL DEFAULT NULL COMMENT '修改时间', `delete_time` datetime(0) NULL DEFAULT NULL COMMENT '删除时间', PRIMARY KEY (`id`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 1 COMMENT = '代码生成业务字段表' ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of sa_tool_generate_columns -- ---------------------------- -- ---------------------------- -- Table structure for sa_tool_generate_tables -- ---------------------------- DROP TABLE IF EXISTS `sa_tool_generate_tables`; CREATE TABLE `sa_tool_generate_tables` ( `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键', `table_name` varchar(200) NULL DEFAULT NULL COMMENT '表名称', `table_comment` varchar(500) NULL DEFAULT NULL COMMENT '表注释', `stub` varchar(50) NULL DEFAULT NULL COMMENT 'stub类型', `template` varchar(50) NULL DEFAULT NULL COMMENT '模板名称', `namespace` varchar(255) NULL DEFAULT NULL COMMENT '命名空间', `package_name` varchar(100) NULL DEFAULT NULL COMMENT '控制器包名', `business_name` varchar(50) NULL DEFAULT NULL COMMENT '业务名称', `class_name` varchar(50) NULL DEFAULT NULL COMMENT '类名称', `menu_name` varchar(100) NULL DEFAULT NULL COMMENT '生成菜单名', `belong_menu_id` int(11) NULL DEFAULT NULL COMMENT '所属菜单', `tpl_category` varchar(100) NULL DEFAULT NULL COMMENT '生成类型,single 单表CRUD,tree 树表CRUD,parent_sub父子表CRUD', `generate_type` smallint(6) NULL DEFAULT 1 COMMENT '1 压缩包下载 2 生成到模块', `generate_path` varchar(100) NULL DEFAULT 'saiadmin-artd' COMMENT '前端根目录', `generate_model` smallint(6) NULL DEFAULT 1 COMMENT '1 软删除 2 非软删除', `generate_menus` varchar(255) NULL DEFAULT NULL COMMENT '生成菜单列表', `build_menu` smallint(6) NULL DEFAULT 1 COMMENT '是否构建菜单', `component_type` smallint(6) NULL DEFAULT 1 COMMENT '组件显示方式', `options` varchar(1500) NULL DEFAULT NULL COMMENT '其他业务选项', `form_width` int(11) NULL DEFAULT 800 COMMENT '表单宽度', `is_full` tinyint(1) NULL DEFAULT 1 COMMENT '是否全屏', `remark` varchar(255) NULL DEFAULT NULL COMMENT '备注', `source` varchar(255) NULL DEFAULT NULL COMMENT '数据源', `created_by` int(11) NULL DEFAULT NULL COMMENT '创建者', `updated_by` int(11) NULL DEFAULT NULL COMMENT '更新者', `create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间', `update_time` datetime(0) NULL DEFAULT NULL COMMENT '修改时间', `delete_time` datetime(0) NULL DEFAULT NULL COMMENT '删除时间', PRIMARY KEY (`id`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 1 COMMENT = '代码生成业务表' ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of sa_tool_generate_tables -- ---------------------------- SET FOREIGN_KEY_CHECKS = 1; ================================================ FILE: src/plugin/saiadmin/exception/ApiException.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\exception; use Webman\Http\Request; use Webman\Http\Response; use support\exception\BusinessException; /** * 常规操作异常-只返回json数据,不记录异常日志 */ class ApiException extends BusinessException { public function render(Request $request): ?Response { return json(['code' => $this->getCode() ?: 500, 'message' => $this->getMessage()]); } } ================================================ FILE: src/plugin/saiadmin/exception/SystemException.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\exception; use Throwable; /** * 系统接口错误-返回json数据,并且记录异常日志 */ class SystemException extends \RuntimeException { public function __construct($message, $code = 400, Throwable $previous = null) { parent::__construct($message, $code, $previous); } } ================================================ FILE: src/plugin/saiadmin/process/Task.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\process; use plugin\saiadmin\app\logic\tool\CrontabLogic; use Webman\Channel\Client; use Workerman\Crontab\Crontab; class Task { protected $logic; //login对象 public $crontabIds = []; //定时任务表主键id => Crontab对象id public function __construct() { $dbName = env('DB_NAME'); if (!empty($dbName)) { $this->logic = new CrontabLogic(); // 连接webman channel服务 Client::connect(); // 订阅某个自定义事件并注册回调,收到事件后会自动触发此回调 Client::on('crontab', function ($data) { $this->reload($data); }); } } public function onWorkerStart() { $dbName = env('DB_NAME'); if (!empty($dbName)) { $this->initStart(); } } public function initStart() { $logic = new CrontabLogic(); $taskList = $logic->getAll($logic->search(['status' => 1])); foreach ($taskList as $item) { $crontab = new Crontab($item['rule'], function () use ($item) { $this->logic->run($item['id']); }); $this->crontabIds[intval($item['id'])] = $crontab->getId(); //存储定时任务表主键id => Crontab对象id echo PHP_EOL . date('Y-m-d H:i:s') . " => 定时任务[" . $item['id'] . "][" . $item['name'] . "]:启动成功" . PHP_EOL; } } public function reload($data) { $id = intval($data['args'] ?? 0); //定时任务表主键id if (isset($this->crontabIds[$id])) { Crontab::remove($this->crontabIds[$id]); unset($this->crontabIds[$id]); //删除定时任务表主键id => Crontab对象id echo PHP_EOL . date('Y-m-d H:i:s') . " => 定时任务[" . $id . "]:移除成功" . PHP_EOL; } $item = $this->logic->read($id);// 查询定时任务表数据 if ($item && $item['status'] == 1) { $crontab = new Crontab($item['rule'], function () use ($item) { $this->logic->run($item['id']); }); $this->crontabIds[$id] = $crontab->getId(); //存储定时任务表主键id => Crontab对象id echo PHP_EOL . date('Y-m-d H:i:s') . " => 定时任务[" . $item['id'] . "][" . $item['name'] . "]:启动成功" . PHP_EOL; } } } ================================================ FILE: src/plugin/saiadmin/process/Test.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\process; class Test { public function run($args): void { echo '任务[Test]调用:' . date('Y-m-d H:i:s') . "\n"; } } ================================================ FILE: src/plugin/saiadmin/service/EmailService.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\service; use PHPMailer\PHPMailer\Exception; use PHPMailer\PHPMailer\PHPMailer; use plugin\saiadmin\app\logic\system\SystemConfigLogic; use plugin\saiadmin\exception\ApiException; use plugin\saiadmin\utils\Arr; /** * 邮件服务类 */ class EmailService { /** * 读取配置 * @return array */ public static function getConfig(): array { $logic = new SystemConfigLogic(); $config = $logic->getGroup('email_config'); if (!$config) { throw new ApiException('未设置邮件配置'); } return $config; } /** * Get Mailer * @return PHPMailer */ public static function getMailer(): PHPMailer { if (!class_exists(PHPMailer::class)) { throw new ApiException('请执行 composer require phpmailer/phpmailer 并重启'); } $config = static::getConfig(); $mailer = new PHPMailer(); $mailer->SMTPDebug = intval(Arr::getConfigValue($config,'SMTPDebug')); $mailer->isSMTP(); $mailer->Host = Arr::getConfigValue($config,'Host'); $mailer->SMTPAuth = true; $mailer->CharSet = Arr::getConfigValue($config,'CharSet'); $mailer->Username = Arr::getConfigValue($config,'Username'); $mailer->Password = Arr::getConfigValue($config,'Password'); $mailer->SMTPSecure = Arr::getConfigValue($config,'SMTPSecure'); $mailer->Port = Arr::getConfigValue($config,'Port'); return $mailer; } /** * 发送邮件 * @param $from * @param $to * @param $subject * @param $content * @return string * @throws Exception */ public static function send($from, $to, $subject, $content): string { $mailer = static::getMailer(); call_user_func_array([$mailer, 'setFrom'], (array)$from); call_user_func_array([$mailer, 'addAddress'], (array)$to); $mailer->Subject = $subject; $mailer->isHTML(true); $mailer->Body = $content; $mailer->send(); return $mailer->ErrorInfo; } /** * 按照模版发送 * @param string|array $to * @param $subject * @param $content * @param array $templateData * @return string * @throws Exception */ public static function sendByTemplate($to, $subject, $content, array $templateData = []): string { if ($templateData) { $search = []; foreach ($templateData as $key => $value) { $search[] = '{' . $key . '}'; } $content = str_replace($search, array_values($templateData), $content); } $config = static::getConfig(); return static::send([Arr::getConfigValue($config,'From'), Arr::getConfigValue($config,'FromName')], $to, $subject, $content); } } ================================================ FILE: src/plugin/saiadmin/service/OpenSpoutWriter.php ================================================ filepath = $this->getFileName($fileName); $this->instance = new Writer(); $this->instance->openToFile($this->filepath); } /** * 获取完整的文件路径 * @param string $fileName * @return string */ public function getFileName(string $fileName): string { $path = config('plugin.saiadmin.saithink.export_path',base_path() . '/plugin/saiadmin/public/export/'); @mkdir($path, 0777, true); return $path . $fileName; } /** * 设置表格宽度 * @param array $width 宽度数组 * @return void */ public function setWidth(array $width = []) { if (empty($width)) { return; } $sheet = $this->instance->getCurrentSheet(); foreach ($width as $key => $value) { $sheet->setColumnWidth($value, $key + 1); } } /** * 设置表头 * @param array $header 表头数组 * @param $style * @return void */ public function setHeader(array $header = [], $style = null): void { if (empty($style)) { $border = new Border( new BorderPart("top", "black", "thin"), new BorderPart("right", "black", "thin"), new BorderPart("bottom", "black", "thin"), new BorderPart("left", "black", "thin"), ); $style = new Style(); $style->setFontBold(); $style->setCellAlignment("center"); $style->setBorder($border); } $rowFromValues = Row::fromValues($header, $style); $this->instance->addRow($rowFromValues); } /** * 设置数据 * @param array $data 数据数组 * @param $style * @return void */ public function setData(array $data = [], $style = null, array $filter = []): void { if (empty($style)) { $border = new Border( new BorderPart("top", "black", "thin"), new BorderPart("right", "black", "thin"), new BorderPart("bottom", "black", "thin"), new BorderPart("left", "black", "thin"), ); $style = new Style(); $style->setCellAlignment("center"); $style->setBorder($border); } foreach($data as $row) { if (!empty($filter)) { foreach ($filter as $key => $value) { foreach ($value as $item) { if ($item['value'] == $row[$key]) { $row[$key] = $item['label']; break; } } } } $rowFromValues = Row::fromValues($row, $style); $this->instance->addRow($rowFromValues); } } /** * 获取文件 * @return string */ public function returnFile(): string { $this->instance->close(); return $this->filepath; } } ================================================ FILE: src/plugin/saiadmin/service/Permission.php ================================================ title = $title ?? ''; $this->slug = $slug; } /** * 获取权限标题 */ public function getTitle(): string { return $this->title; } /** * 获取权限标识 */ public function getSlug(): ?string { return $this->slug; } } ================================================ FILE: src/plugin/saiadmin/service/storage/ChunkUploadService.php ================================================ folder = $folder; $this->config = $logic->getGroup('upload_config'); $this->path = $this->checkPath(); } /** * 检查并创建上传路径 * @return string */ public function checkPath(): string { $root = Arr::getConfigValue($this->config, 'local_root'); $path = base_path() . DIRECTORY_SEPARATOR . $root . $this->folder . DIRECTORY_SEPARATOR; if (!is_dir($path)) { mkdir($path, 0777, true); } return $path; } /** * 检查切片文件上传状态 * @param $data * @return array */ public function checkChunk($data): array { $allow_file = Arr::getConfigValue($this->config, 'upload_allow_file'); if (!in_array($data['ext'], explode(',', $allow_file))) { throw new ApiException('不支持该格式的文件上传'); } // 检查已经上传的分片文件 for ($i = 0; $i < $data['total']; ++$i) { $chunkFile = $this->path . "{$data['hash']}_{$data['total']}_{$i}.chunk"; if (!file_exists($chunkFile)) { if ($i == 0) { return $this->uploadChunk($data); } else { return ['chunk' => $i, 'status' => 'resume']; } } } // 分片文件已经全部上传 return ['chunk' => $i, 'status' => 'success']; } /** * 上传切片 * @param $data * @return array */ public function uploadChunk($data): array { $allow_file = Arr::getConfigValue($this->config, 'upload_allow_file'); if (!in_array($data['ext'], explode(',', $allow_file))) { throw new ApiException('不支持该格式的文件上传'); } $request = request(); if (!$request) { throw new ApiException('切片上传服务必须在 HTTP 请求环境下调用'); } $uploadFile = current($request->file()); $chunkName = $this->path . "{$data['hash']}_{$data['total']}_{$data['index']}.chunk"; $uploadFile->move($chunkName); if (($data['index'] + 1) == $data['total']) { return $this->mergeChunk($data); } return ['chunk' => $data['index'], 'status' => 'success']; } /** * 合并切片文件 * @param $data * @return array */ public function mergeChunk($data): array { $filePath = $this->path . $data['hash'] . '.' . $data['ext']; $fileHandle = fopen($filePath, 'w'); for ($i = 0; $i < $data['total']; ++$i) { $chunkFile = $this->path . "{$data['hash']}_{$data['total']}_{$i}.chunk"; if (!file_exists($chunkFile)) { throw new ApiException('切片文件查找失败,请重新上传'); } fwrite($fileHandle, file_get_contents($chunkFile)); unlink($chunkFile); } $domain = Arr::getConfigValue($this->config, 'local_domain'); $uri = Arr::getConfigValue($this->config, 'local_uri'); $baseUrl = $domain . $uri . $this->folder . '/'; $save_path = Arr::getConfigValue($this->config, 'local_root') . $this->folder . '/'; $object_name = $data['hash'] . '.' . $data['ext']; $info['storage_mode'] = 1; $info['category_id'] = 1; $info['origin_name'] = $data['name']; $info['object_name'] = $object_name; $info['hash'] = $data['hash']; $info['mime_type'] = $data['type']; $info['storage_path'] = $save_path . $object_name; $info['suffix'] = $data['ext']; $info['size_byte'] = $data['size']; $info['size_info'] = formatBytes($data['size']); $info['url'] = $baseUrl . $object_name; SystemAttachment::create($info); return $info; } } ================================================ FILE: src/plugin/saiadmin/service/storage/UploadService.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\service\storage; use plugin\saiadmin\app\logic\system\SystemConfigLogic; use plugin\saiadmin\exception\ApiException; use plugin\saiadmin\utils\Arr; /** * 文件上传服务 * @method static array uploadFile(array $config = []) 上传文件 * @method static array uploadBase64(string $base64, string $extension = 'png') 上传Base64文件 * @method static array uploadServerFile(string $file_path) 上传服务端文件 */ class UploadService { /** * @desc 存储磁盘 * @param int $type * @param string $upload * @param bool $_is_file_upload * @return mixed */ public static function disk(int $type = 1, string $upload = 'image', bool $_is_file_upload = true) { $logic = new SystemConfigLogic(); $uploadConfig = $logic->getGroup('upload_config'); $file = current(request()->file()); $ext = $file->getUploadExtension() ?: null; $file_size = $file->getSize(); if ($file_size > Arr::getConfigValue($uploadConfig, 'upload_size')) { throw new ApiException('文件大小超过限制'); } $allow_file = Arr::getConfigValue($uploadConfig, 'upload_allow_file'); $allow_image = Arr::getConfigValue($uploadConfig, 'upload_allow_image'); if ($upload == 'image') { if (!in_array($ext, explode(',', $allow_image))) { throw new ApiException('不支持该格式的文件上传'); } } else { if (!in_array($ext, explode(',', $allow_file))) { throw new ApiException('不支持该格式的文件上传'); } } switch ($type) { case 1: // 本地 $config = [ 'adapter' => \Tinywan\Storage\Adapter\LocalAdapter::class, 'root' => Arr::getConfigValue($uploadConfig, 'local_root'), 'dirname' => function () { return date('Ymd'); }, 'domain' => Arr::getConfigValue($uploadConfig, 'local_domain'), 'uri' => Arr::getConfigValue($uploadConfig, 'local_uri'), 'algo' => 'sha1', ]; break; case 2: // 阿里云 $config = [ 'adapter' => \Tinywan\Storage\Adapter\OssAdapter::class, 'accessKeyId' => Arr::getConfigValue($uploadConfig, 'oss_accessKeyId'), 'accessKeySecret' => Arr::getConfigValue($uploadConfig, 'oss_accessKeySecret'), 'bucket' => Arr::getConfigValue($uploadConfig, 'oss_bucket'), 'dirname' => Arr::getConfigValue($uploadConfig, 'oss_dirname'), 'domain' => Arr::getConfigValue($uploadConfig, 'oss_domain'), 'endpoint' => Arr::getConfigValue($uploadConfig, 'oss_endpoint'), 'algo' => 'sha1', ]; break; case 3: // 七牛 $config = [ 'adapter' => \Tinywan\Storage\Adapter\QiniuAdapter::class, 'accessKey' => Arr::getConfigValue($uploadConfig, 'qiniu_accessKey'), 'secretKey' => Arr::getConfigValue($uploadConfig, 'qiniu_secretKey'), 'bucket' => Arr::getConfigValue($uploadConfig, 'qiniu_bucket'), 'dirname' => Arr::getConfigValue($uploadConfig, 'qiniu_dirname'), 'domain' => Arr::getConfigValue($uploadConfig, 'qiniu_domain'), ]; break; case 4: // 腾讯云 $config = [ 'adapter' => \Tinywan\Storage\Adapter\CosAdapter::class, 'secretId' => Arr::getConfigValue($uploadConfig, 'cos_secretId'), 'secretKey' => Arr::getConfigValue($uploadConfig, 'cos_secretKey'), 'bucket' => Arr::getConfigValue($uploadConfig, 'cos_bucket'), 'dirname' => Arr::getConfigValue($uploadConfig, 'cos_dirname'), 'domain' => Arr::getConfigValue($uploadConfig, 'cos_domain'), 'region' => Arr::getConfigValue($uploadConfig, 'cos_region'), ]; break; case 5: // s3 亚马逊 $config = [ 'adapter' => \Tinywan\Storage\Adapter\S3Adapter::class, 'key' => Arr::getConfigValue($uploadConfig, 's3_key'), 'secret' => Arr::getConfigValue($uploadConfig, 's3_secret'), 'bucket' => Arr::getConfigValue($uploadConfig, 's3_bucket'), 'dirname' => Arr::getConfigValue($uploadConfig, 's3_dirname'), 'domain' => Arr::getConfigValue($uploadConfig, 's3_domain'), 'region' => Arr::getConfigValue($uploadConfig, 's3_region'), 'version' => Arr::getConfigValue($uploadConfig, 's3_version'), // 'use_path_style_endpoint' => Arr::getConfigValue($uploadConfig,'s3_use_path_style_endpoint'), 'use_path_style_endpoint' => filter_var(Arr::getConfigValue($uploadConfig, 's3_use_path_style_endpoint'), FILTER_VALIDATE_BOOLEAN), 'endpoint' => Arr::getConfigValue($uploadConfig, 's3_endpoint'), 'acl' => Arr::getConfigValue($uploadConfig, 's3_acl'), ]; break; default: throw new ApiException('该上传模式不存在'); } return new $config['adapter'](array_merge( $config, ['_is_file_upload' => $_is_file_upload] )); } /** * @param $name * @param $arguments * @return mixed * @author Tinywan(ShaoBo Wan) */ public static function __callStatic($name, $arguments) { return static::disk()->{$name}(...$arguments); } } ================================================ FILE: src/plugin/saiadmin/utils/Arr.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\utils; /** * Array操作类 * Class Arr */ class Arr { /** * 获取数组中指定的列 * @param array $source * @param string $column * @return array */ public static function getArrayColumn($source, $column): array { $columnArr = []; foreach ($source as $item) { $columnArr[] = $item[$column]; } return $columnArr; } /** * 批量获取数组中指定的列 * @param array $source * @param array $column * @return array */ public static function getArrayColumns($source, $columns): array { $columnArr = []; foreach ($source as $item) { $tempArr = []; foreach ($columns as $key) { $temp = explode('.', $key); if (count($temp) > 1) { $tempArr[$key] = $item[$temp[0]][$temp[1]]; } else { $tempArr[$key] = $item[$key]; } } $columnArr[] = $tempArr; } return $columnArr; } /** * 把二维数组中某列设置为key返回 * @param array $array 输入数组 * @param string $field 要作为键的字段名 * @param bool $unique 要做键的字段是否唯一(该字段与记录是否一一对应) * @return array */ public static function fieldAsKey($array, $field, $unique = false) { $result = []; foreach ($array as $item) { if (isset($item[$field])) { if (!$unique && isset($result[$item[$field]])) { $unique = true; $result[$item[$field]] = [($result[$item[$field]])]; $result[$item[$field]][] = $item; } elseif ($unique) { $result[$item[$field]][] = $item; } else { $result[$item[$field]] = $item; } } } return $result; } /** * 数组转字符串去重复 * @param array $data * @return false|string[] */ public static function unique(array $data) { return array_unique(explode(',', implode(',', $data))); } /** * 获取数组中去重复过后的指定key值 * @param array $list * @param string $key * @return array */ public static function getUniqueKey(array $list, string $key) { return array_unique(array_column($list, $key)); } /** * 合并二维数组,并且指定key去重, 第一个覆盖第二个 * @param array $arr1 * @param array $arr2 * @param string $key * @return array */ public static function mergeArray(array $arr1, array $arr2, string $key) { $arr = array_merge($arr1,$arr2); $tmp_arr = []; foreach($arr as $k => $v) { if(in_array($v[$key], $tmp_arr)) { unset($arr[$k]); } else { $tmp_arr[] = $v[$key]; } } return $arr; } /** * 相同键值的合并作为键生成新数组 * @param array $data * @param string $field * @return array */ public static function groupSameField(array $data, string $field) { $result= []; foreach ($data as $key => $info) { $result[$info[$field]][] = $info; } return $result; } /** * 生成无限级树算法 * @param array $arr 输入数组 * @param number $pid 根级的pid * @param string $column_name 列名,id|pid父id的名字|children子数组的键名 * @return array $ret */ public static function makeTree($arr, $pid = 0, $column_name = 'id|pid|children') { list($idname, $pidname, $cldname) = explode('|', $column_name); $ret = array(); foreach ($arr as $k => $v) { if ($v [$pidname] == $pid) { $tmp = $arr [$k]; unset($arr [$k]); $tmp [$cldname] = self::makeTree($arr, $v [$idname], $column_name); $ret [] = $tmp; } } return $ret; } /** * 二位数组按某个键值排序 * @param array $arr * @param string $key * @param int $sort * @return array */ public static function sortArray($arr, $key, $sort = SORT_ASC) { array_multisort(array_column($arr,$key),$sort,$arr); return $arr; } /** * 数组中根据某一列中某个字段的值来查询这一列数据 * @param $array * @param $column * @param $value * @return array */ public static function getArrayByColumn($array, $column, $value): array { $result = []; foreach ($array as $key => $item) { if ($item[$column] == $value) { $result = $item; } } return $result; } /** * 数组中根据key值获取value * @param $array * @param $key * @return mixed|string */ public static function getConfigValue($array, $key) { foreach ($array as $item) { if ($item['key'] === $key) { return $item['value']; } } return ''; } } ================================================ FILE: src/plugin/saiadmin/utils/Captcha.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\utils; use support\think\Cache; use Ramsey\Uuid\Uuid; use Webman\Captcha\CaptchaBuilder; use Webman\Captcha\PhraseBuilder; use plugin\saiadmin\exception\ApiException; /** * 验证码工具类 */ class Captcha { /** * 图形验证码 * @return array */ public static function imageCaptcha(): array { $builder = new PhraseBuilder(4, 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ'); $captcha = new CaptchaBuilder(null, $builder); $captcha->setBackgroundColor(242, 243, 245); $captcha->build(120, 36); $uuid = Uuid::uuid4(); $key = $uuid->toString(); $mode = config('plugin.saiadmin.saithink.captcha.mode', 'session'); $expire = config('plugin.saiadmin.saithink.captcha.expire', 300); $code = strtolower($captcha->getPhrase()); if ($mode === 'cache') { try { Cache::set($key, $code, $expire); } catch (\Exception $e) { return [ 'result' => -1, 'message' => '验证码获取失败,请检查缓存配置' ]; } } else { $request = request(); if ($request) { $request->session()->set($key, $code); } } $img_content = $captcha->get(); return [ 'result' => 1, 'uuid' => $key, 'image' => 'data:image/png;base64,' . base64_encode($img_content) ]; } /** * 数字验证码 * @param string $key * @param int $length * @return array */ public static function numberCaptcha(string $key, int $length = 4): array { $code = str_pad(rand(0, 999999), $length, '0', STR_PAD_LEFT); $mode = config('plugin.saiadmin.saithink.captcha.mode', 'session'); $expire = config('plugin.saiadmin.saithink.captcha.expire', 300); if ($mode === 'cache') { try { Cache::set($key, $code, $expire); } catch (\Exception $e) { return [ 'result' => -1, 'message' => '验证码获取失败,请检查缓存配置' ]; } } else { $request = request(); if ($request) { $request->session()->set($key, $code); } } return [ 'result' => 1, 'uuid' => $key, 'code' => $code, ]; } /** * 验证码验证 * @param string $uuid * @param string|int $captcha * @return bool */ public static function checkCaptcha(string $uuid, string|int $captcha): bool { $mode = config('plugin.saiadmin.saithink.captcha.mode', 'session'); if ($mode === 'cache') { try { $code = Cache::get($uuid); Cache::delete($uuid); } catch (\Exception $e) { throw new ApiException($e->getMessage()); } } else { try { $code = session($uuid); session()->forget($uuid); } catch (\Exception $e) { throw new ApiException($e->getMessage()); } } if (strtolower($captcha) !== $code) { return false; } return true; } } ================================================ FILE: src/plugin/saiadmin/utils/Helper.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\utils; /** * 帮助类 */ class Helper { /** * 数据树形化 * @param array $data 数据 * @param string $childrenname 子数据名 * @param string $keyName 数据key名 * @param string $pidName 数据上级key名 * @return array */ public static function makeTree(array $data, string $childrenname = 'children', string $keyName = 'id', string $pidName = 'parent_id') { $list = []; foreach ($data as $value) { $list[$value[$keyName]] = $value; } $tree = []; //格式化好的树 foreach ($list as $item) { if (isset($list[$item[$pidName]])) { $list[$item[$pidName]][$childrenname][] = &$list[$item[$keyName]]; } else { $tree[] = &$list[$item[$keyName]]; } } return $tree; } /** * 生成Arco菜单 * @param array $data 数据 * @param string $childrenname 子数据名 * @param string $keyName 数据key名 * @param string $pidName 数据上级key名 * @return array */ public static function makeArcoMenus(array $data, string $childrenname = 'children', string $keyName = 'id', string $pidName = 'parent_id') { $list = []; foreach ($data as $value) { if ($value['type'] === 'M'){ $path = '/'.$value['route']; $layout = isset($value['is_layout']) ? $value['is_layout'] : 1; $temp = [ $keyName => $value[$keyName], $pidName => $value[$pidName], 'name' => $value['route'], 'path' => $path, 'component' => $value['component'], 'redirect' => $value['redirect'], 'meta' => [ 'title' => $value['name'], 'type' => $value['type'], 'hidden' => $value['is_hidden'] === 1, 'layout' => $layout === 1, 'hiddenBreadcrumb' => false, 'icon' => $value['icon'], ], ]; $list[$value[$keyName]] = $temp; } if ($value['type'] === 'I' || $value['type'] === 'L'){ $temp = [ $keyName => $value[$keyName], $pidName => $value[$pidName], 'name' => $value['code'], 'path' => $value['route'], 'meta' => [ 'title' => $value['name'], 'type' => $value['type'], 'hidden' => $value['is_hidden'] === 1, 'hiddenBreadcrumb' => false, 'icon' => $value['icon'], ], ]; $list[$value[$keyName]] = $temp; } } $tree = []; //格式化好的树 foreach ($list as $item) { if (isset($list[$item[$pidName]])) { $list[$item[$pidName]][$childrenname][] = &$list[$item[$keyName]]; } else { $tree[] = &$list[$item[$keyName]]; } } return $tree; } /** * 生成Artd菜单 * @param array $data * @param string $childrenname * @param string $keyName * @param string $pidName * @return array */ public static function makeArtdMenus(array $data, string $childrenname = 'children', string $keyName = 'id', string $pidName = 'parent_id') { $list = []; foreach ($data as $value) { $component = ''; if ($value['type'] === 1) { $component = '/index/index'; } if ($value['type'] === 2) { $component = $value['component']; } $temp = [ $keyName => $value[$keyName], $pidName => $value[$pidName], 'name' => $value['code'], 'path' => $value['path'], 'component' => $component, 'meta' => [ 'title' => $value['name'], 'icon' => $value['icon'], 'isIframe' => $value['is_iframe'] === 1, 'keepAlive' => $value['is_keep_alive'] === 1, 'isHide' => $value['is_hidden'] === 1, 'fixedTab' => $value['is_fixed_tab'] === 1, 'isFullPage' => $value['is_full_page'] === 1, ], ]; if ($value['type'] === 4) { $temp['path'] = '/outside/Iframe'; $temp['meta']['link'] = $value['link_url']; } $list[$value[$keyName]] = $temp; } $tree = []; foreach ($list as $item) { if (isset($list[$item[$pidName]])) { $list[$item[$pidName]][$childrenname][] = &$list[$item[$keyName]]; } else { $tree[] = &$list[$item[$keyName]]; } } return $tree; } /** * 下划线转驼峰 */ public static function camelize($uncamelized_words,$separator='_') { $uncamelized_words = $separator. str_replace($separator, " ", strtolower($uncamelized_words)); return ltrim(str_replace(" ", "", ucwords($uncamelized_words)), $separator ); } /** * 驼峰命名转下划线命名 */ public static function uncamelize($camelCaps,$separator='_') { return strtolower(preg_replace('/([a-z])([A-Z])/', "$1" . $separator . "$2", $camelCaps)); } /** * 转换为驼峰 * @param string $value * @return string */ public static function camel(string $value): string { static $cache = []; $key = $value; if (isset($cache[$key])) { return $cache[$key]; } $value = ucwords(str_replace(['-', '_'], ' ', $value)); return $cache[$key] = str_replace(' ', '', $value); } /** * 获取业务名称 * @param string $tableName * @return mixed */ public static function get_business(string $tableName) { $start = strrpos($tableName,'_'); if ($start !== false) { $result = substr($tableName, $start + 1); } else { $result = $tableName; } return static::camelize($result); } /** * 获取业务名称 * @param string $tableName * @return mixed */ public static function get_big_business(string $tableName) { $start = strrpos($tableName,'_'); $result = substr($tableName, $start + 1); return static::camel($result); } /** * 只替换一次字符串 * @param $needle * @param $replace * @param $haystack * @return array|mixed|string|string[] */ public static function str_replace_once($needle, $replace, $haystack) { $pos = strpos($haystack, $needle); if ($pos === false) { return $haystack; } return substr_replace($haystack, $replace, $pos, strlen($needle)); } /** * 遍历目录 * @param $template_name * @return array */ public static function get_dir($template_name) { $dir = base_path($template_name); $fileDir = []; if (is_dir($dir)){ if ($dh = opendir($dir)){ while (($file = readdir($dh)) !== false){ if($file != "." && $file != ".."){ array_push($fileDir, $file); } } closedir($dh); } } return $fileDir; } } ================================================ FILE: src/plugin/saiadmin/utils/ServerMonitor.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\utils; /** * 服务器监控信息 */ class ServerMonitor { /** * 获取内存信息 * @return array */ public function getMemoryInfo(): array { $totalMem = 0; // 总内存 (Bytes) $freeMem = 0; // 可用/剩余内存 (Bytes) if (stristr(PHP_OS, 'WIN')) { // Windows 系统 // 一次性获取 总可见内存 和 空闲物理内存 (单位都是 KB) // TotalVisibleMemorySize: 操作系统可识别的内存总数 (比物理内存条总数略少,更准确反映可用上限) // FreePhysicalMemory: 当前可用物理内存 $cmd = 'wmic OS get FreePhysicalMemory,TotalVisibleMemorySize /format:csv'; $output = shell_exec($cmd); $output = mb_convert_encoding($output ?? '', 'UTF-8', 'GBK, UTF-8, ASCII'); $lines = explode("\n", trim($output)); foreach ($lines as $line) { $line = trim($line); if (empty($line)) continue; // CSV 格式: Node,FreePhysicalMemory,TotalVisibleMemorySize $parts = str_getcsv($line); // 确保解析正确且排除标题行 (通常索引1是Free, 2是Total) if (count($parts) >= 3 && is_numeric($parts[1])) { $freeMem = floatval($parts[1]) * 1024; // KB -> Bytes $totalMem = floatval($parts[2]) * 1024; // KB -> Bytes break; } } } else { // Linux 系统 // 读取 /proc/meminfo,效率远高于 shell_exec('cat ...') $memInfo = @file_get_contents('/proc/meminfo'); if ($memInfo) { // 使用正则提取 MemTotal 和 MemAvailable (单位 kB) // MemAvailable 是较新的内核指标,比单纯的 MemFree 更准确(包含可回收的缓存) if (preg_match('/^MemTotal:\s+(\d+)\s+kB/m', $memInfo, $matches)) { $totalMem = floatval($matches[1]) * 1024; } if (preg_match('/^MemAvailable:\s+(\d+)\s+kB/m', $memInfo, $matches)) { $freeMem = floatval($matches[1]) * 1024; } else { // 如果内核太老没有 MemAvailable,退化使用 MemFree if (preg_match('/^MemFree:\s+(\d+)\s+kB/m', $memInfo, $matches)) { $freeMem = floatval($matches[1]) * 1024; } } } } // 计算已用内存 $usedMem = $totalMem - $freeMem; // 避免除以0 $rate = ($totalMem > 0) ? ($usedMem / $totalMem) * 100 : 0; // PHP 自身占用 $phpMem = memory_get_usage(true); return [ // 人类可读格式 (String) 'total' => $this->formatBytes($totalMem), 'free' => $this->formatBytes($freeMem), 'used' => $this->formatBytes($usedMem), 'php' => $this->formatBytes($phpMem), 'rate' => sprintf('%.2f', $rate) . '%', // 原始数值 (Float/Int),方便前端图表使用或逻辑判断,统一单位 Bytes 'raw' => [ 'total' => $totalMem, 'free' => $freeMem, 'used' => $usedMem, 'php' => $phpMem, 'rate' => round($rate, 2) ] ]; } /** * 获取PHP及环境信息 * @return array */ public function getPhpAndEnvInfo(): array { return [ 'php_version' => PHP_VERSION, 'os' => PHP_OS, 'project_path' => BASE_PATH, 'memory_limit' => ini_get('memory_limit'), 'max_execution_time' => ini_get('max_execution_time'), 'error_reporting' => ini_get('error_reporting'), 'display_errors' => ini_get('display_errors'), 'upload_max_filesize' => ini_get('upload_max_filesize'), 'post_max_size' => ini_get('post_max_size'), 'extension_dir' => ini_get('extension_dir'), 'loaded_extensions' => implode(', ', get_loaded_extensions()), ]; } /** * 获取磁盘信息 * @return array */ public function getDiskInfo(): array { $disk = []; if (stristr(PHP_OS, 'WIN')) { // Windows 系统 // 使用 CSV 格式输出,避免空格解析错误;SkipTop=1 跳过空行 // LogicalDisk 包含: Caption(盘符), FreeSpace(剩余字节), Size(总字节) $cmd = 'wmic logicaldisk get Caption,FreeSpace,Size /format:csv'; $output = shell_exec($cmd); // 转换编码,防止中文乱码(视服务器环境而定,通常 Windows CMD 输出为 GBK) $output = mb_convert_encoding($output ?? '', 'UTF-8', 'GBK, UTF-8, ASCII'); $lines = explode("\n", trim($output)); foreach ($lines as $line) { $line = trim($line); if (empty($line)) continue; // CSV 格式: Node,Caption,FreeSpace,Size $parts = str_getcsv($line); // 确保数据列足够且是一个盘符 (例如 "C:") // 索引通常是: 1=>Caption, 2=>FreeSpace, 3=>Size (索引0通常是计算机名) if (count($parts) >= 4 && preg_match('/^[A-Z]:$/', $parts[1])) { $caption = $parts[1]; $freeSpace = floatval($parts[2]); $totalSize = floatval($parts[3]); // 避免除以 0 错误(如光驱未放入光盘时 Size 可能为 0 或 null) if ($totalSize <= 0) continue; $usedSpace = $totalSize - $freeSpace; $disk[] = [ 'filesystem' => $caption, 'mounted_on' => $caption, 'size' => $this->formatBytes($totalSize), 'available' => $this->formatBytes($freeSpace), 'used' => $this->formatBytes($usedSpace), 'use_percentage' => sprintf('%.2f', ($usedSpace / $totalSize) * 100) . '%', 'raw' => [ // 保留原始数据以便前端或其他逻辑使用 'size' => $totalSize, 'available' => $freeSpace, 'used' => $usedSpace ] ]; } } } else { // Linux 系统 // -P: POSIX 输出格式(强制在一行显示,防止长挂载点换行) // -T: 显示文件系统类型 // 默认单位是 1K-blocks (1024字节) $output = shell_exec('df -TP 2>/dev/null'); $lines = explode("\n", trim($output ?? '')); // 过滤表头 array_shift($lines); foreach ($lines as $line) { $line = trim($line); if (empty($line)) continue; // 限制分割数量,防止挂载点名称中有空格导致解析错位(虽然 -P 很大程度避免了这个问题,但仍需谨慎) $parts = preg_split('/\s+/', $line); // df -TP 输出列: Filesystem(0), Type(1), 1024-blocks(2), Used(3), Available(4), Capacity(5), Mounted on(6) if (count($parts) >= 7) { $filesystem = $parts[0]; $type = $parts[1]; $totalKB = floatval($parts[2]); // 单位是 KB $usedKB = floatval($parts[3]); $availKB = floatval($parts[4]); $mountedOn = $parts[6]; // 过滤逻辑:只显示物理硬盘或特定挂载点 // 通常过滤掉 tmpfs, devtmpfs, overlay, squashfs(snap) 等 // 如果你只想看 /dev/ 开头的物理盘,保留原来的正则即可 if (!preg_match('/^\/dev\//', $filesystem)) { // continue; // 根据需求决定是否取消注释此行 } // 过滤掉 Docker overlay 或 kubelet 等产生的繁杂挂载 if (strpos($filesystem, 'overlay') !== false) continue; // 转换为字节 $totalSize = $totalKB * 1024; $usedSize = $usedKB * 1024; $freeSize = $availKB * 1024; if ($totalSize <= 0) continue; $disk[] = [ 'filesystem' => $filesystem, 'type' => $type, 'mounted_on' => $mountedOn, 'size' => $this->formatBytes($totalSize), 'available' => $this->formatBytes($freeSize), 'used' => $this->formatBytes($usedSize), 'use_percentage' => sprintf('%.2f', ($usedSize / $totalSize) * 100) . '%', 'raw' => [ 'size' => $totalSize, 'available' => $freeSize, 'used' => $usedSize ] ]; } } } return $disk; } /** * 格式化字节为可读格式 (B, KB, MB, GB, TB...) * @param int|float $bytes 字节数 * @param int $precision 小数点后保留位数 * @return string */ private function formatBytes($bytes, int $precision = 2): string { if ($bytes <= 0) { return '0 B'; } $base = log($bytes, 1024); $suffixes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB']; // 确保不会数组越界 $class = min((int)floor($base), count($suffixes) - 1); return sprintf("%." . $precision . "f", $bytes / pow(1024, $class)) . ' ' . $suffixes[$class]; } } ================================================ FILE: src/plugin/saiadmin/utils/code/CodeEngine.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\utils\code; use Twig\TwigFilter; use Twig\Environment; use Twig\Loader\FilesystemLoader; use plugin\saiadmin\exception\ApiException; // 定义目录分隔符常量 defined('DS') or define('DS', DIRECTORY_SEPARATOR); /** * 代码生成引擎 */ class CodeEngine { /** * @var array 值栈 */ private array $value = []; /** * 模板名称 * @var string */ private string $stub = 'saiadmin'; /** * 获取配置文件 * @return string[] */ private static function _getConfig(): array { return [ 'template_path' => base_path() . DS . 'plugin' . DS . 'saiadmin' . DS . 'utils' . DS . 'code' . DS . 'stub', 'generate_path' => runtime_path() . DS . 'code_engine' . DS . 'saiadmin', ]; } /** * 初始化 * @param array $data 数据 */ public function __construct(array $data) { // 读取配置文件 $config = self::_getConfig(); // 判断模板是否存在 if (!is_dir($config['template_path'])) { throw new ApiException('模板目录不存在!'); } // 判断文件生成目录是否存在 if (!is_dir($config['generate_path'])) { mkdir($config['generate_path'], 0770, true); } // 赋值 $this->value = $data; } /** * 设置模板名称 * @param $stub * @return void */ public function setStub($stub): void { $this->stub = $stub; } /** * 渲染文件内容 */ public function renderContent($path, $filename): string { $config = self::_getConfig(); $path = $config['template_path'] . DS . $this->stub . DS . $path; $loader = new FilesystemLoader($path); $twig = new Environment($loader); $camelFilter = new TwigFilter('camel', function ($value) { static $cache = []; $key = $value; if (isset($cache[$key])) { return $cache[$key]; } $value = ucwords(str_replace(['-', '_'], ' ', $value)); return $cache[$key] = str_replace(' ', '', $value); }); $boolFilter = new TwigFilter('bool', function ($value) { if ($value == 1) { return 'true'; } else { return 'false'; } }); $formatFilter = new TwigFilter('formatNumber', function ($value) { if (ctype_digit((string) $value)) { return $value; } else { return '1'; } }); $defaultFilter = new TwigFilter('parseNumber', function ($value) { if (\is_numeric($value)) { return $value; } else { return 'null'; } }); $containsFilter = new TwigFilter('str_contains', function ($haystack, $needle) { return str_contains($haystack ?? '', $needle ?? ''); }); $twig->addFilter($camelFilter); $twig->addFilter($boolFilter); $twig->addFilter($containsFilter); $twig->addFilter($formatFilter); $twig->addFilter($defaultFilter); return $twig->render($filename, $this->value); } /** * 生成后端文件 */ public function generateBackend($action, $content): void { $outPath = ''; if ($this->value['template'] == 'app') { $rootPath = base_path() . DS . 'app' . DS . $this->value['namespace']; $adminPath = ''; } else { $rootPath = base_path() . DS . 'plugin' . DS . $this->value['namespace'] . DS . 'app'; $adminPath = DS . 'admin'; } $subPath = DS . $this->value['package_name']; switch ($action) { case 'controller': $outPath = $rootPath . $adminPath . DS . 'controller' . $subPath . DS . $this->value['class_name'] . 'Controller.php'; break; case 'logic': $outPath = $rootPath . $adminPath . DS . 'logic' . $subPath . DS . $this->value['class_name'] . 'Logic.php'; break; case 'validate': $outPath = $rootPath . $adminPath . DS . 'validate' . $subPath . DS . $this->value['class_name'] . 'Validate.php'; break; case 'model': $outPath = $rootPath . DS . 'model' . $subPath . DS . $this->value['class_name'] . '.php'; break; default: break; } if (empty($outPath)) { throw new ApiException('文件类型异常,无法生成指定文件!'); } if (!is_dir(dirname($outPath))) { mkdir(dirname($outPath), 0777, true); } file_put_contents($outPath, $content); } /** * 生成前端文件 */ public function generateFrontend($action, $content): void { $rootPath = dirname(base_path()) . DS . $this->value['generate_path']; if (!is_dir($rootPath)) { throw new ApiException('前端目录查找失败,必须与后端目录为同级目录!'); } $rootPath = $rootPath . DS . 'src' . DS . 'views' . DS . 'plugin' . DS . $this->value['namespace']; $subPath = DS . $this->value['package_name']; switch ($action) { case 'index': $outPath = $rootPath . $subPath . DS . $this->value['business_name'] . DS . 'index.vue'; break; case 'edit-dialog': $outPath = $rootPath . $subPath . DS . $this->value['business_name'] . DS . 'modules' . DS . 'edit-dialog.vue'; break; case 'table-search': $outPath = $rootPath . $subPath . DS . $this->value['business_name'] . DS . 'modules' . DS . 'table-search.vue'; break; case 'api': $outPath = $rootPath . DS . 'api' . $subPath . DS . $this->value['business_name'] . '.ts'; break; default: break; } if (empty($outPath)) { throw new ApiException('文件类型异常,无法生成指定文件!'); } if (!is_dir(dirname($outPath))) { mkdir(dirname($outPath), 0777, true); } file_put_contents($outPath, $content); } /** * 生成临时文件 */ public function generateTemp(): void { $config = self::_getConfig(); $rootPath = $config['generate_path']; $vuePath = $rootPath . DS . 'vue' . DS . 'src' . DS . 'views' . DS . 'plugin' . DS . $this->value['namespace']; $phpPath = $rootPath . DS . 'php'; $sqlPath = $rootPath . DS . 'sql'; if ($this->value['template'] == 'app') { $phpPath = $phpPath . DS . 'app' . DS . $this->value['namespace']; $adminPath = ''; } else { $phpPath = $phpPath . DS . 'plugin' . DS . $this->value['namespace'] . DS . 'app'; $adminPath = DS . 'admin'; } $subPath = DS . $this->value['package_name']; $indexOutPath = $vuePath . $subPath . DS . $this->value['business_name'] . DS . 'index.vue'; $this->checkPath($indexOutPath); $indexContent = $this->renderContent('vue', 'index.stub'); file_put_contents($indexOutPath, $indexContent); $editOutPath = $vuePath . $subPath . DS . $this->value['business_name'] . DS . 'modules' . DS . 'edit-dialog.vue'; $this->checkPath($editOutPath); $editContent = $this->renderContent('vue', 'edit-dialog.stub'); file_put_contents($editOutPath, $editContent); $searchOutPath = $vuePath . $subPath . DS . $this->value['business_name'] . DS . 'modules' . DS . 'table-search.vue'; $this->checkPath($searchOutPath); $searchContent = $this->renderContent('vue', 'table-search.stub'); file_put_contents($searchOutPath, $searchContent); $viewOutPath = $vuePath . DS . 'api' . $subPath . DS . $this->value['business_name'] . '.ts'; $this->checkPath($viewOutPath); $viewContent = $this->renderContent('ts', 'api.stub'); file_put_contents($viewOutPath, $viewContent); $controllerOutPath = $phpPath . $adminPath . DS . 'controller' . $subPath . DS . $this->value['class_name'] . 'Controller.php'; $this->checkPath($controllerOutPath); $controllerContent = $this->renderContent('php', 'controller.stub'); file_put_contents($controllerOutPath, $controllerContent); $logicOutPath = $phpPath . $adminPath . DS . 'logic' . $subPath . DS . $this->value['class_name'] . 'Logic.php'; $this->checkPath($logicOutPath); $logicContent = $this->renderContent('php', 'logic.stub'); file_put_contents($logicOutPath, $logicContent); $validateOutPath = $phpPath . $adminPath . DS . 'validate' . $subPath . DS . $this->value['class_name'] . 'Validate.php'; $this->checkPath($validateOutPath); $validateContent = $this->renderContent('php', 'validate.stub'); file_put_contents($validateOutPath, $validateContent); $modelOutPath = $phpPath . DS . 'model' . $subPath . DS . $this->value['class_name'] . '.php'; $this->checkPath($modelOutPath); $modelContent = $this->renderContent('php', 'model.stub'); file_put_contents($modelOutPath, $modelContent); $sqlOutPath = $sqlPath . DS . 'sql.sql'; $this->checkPath($sqlOutPath); $sqlContent = $this->renderContent('sql', 'sql.stub'); file_put_contents($sqlOutPath, $sqlContent); } /** * 检查并生成路径 * @param $path * @return void */ protected function checkPath($path): void { if (!is_dir(dirname($path))) { mkdir(dirname($path), 0777, true); } } } ================================================ FILE: src/plugin/saiadmin/utils/code/CodeZip.php ================================================ // +---------------------------------------------------------------------- namespace plugin\saiadmin\utils\code; use plugin\saiadmin\exception\ApiException; /** * 代码构建 压缩类 */ class CodeZip { /** * 获取配置文件 * @return string[] */ private static function _getConfig(): array { return [ 'template_path' => base_path().DIRECTORY_SEPARATOR.'plugin'.DIRECTORY_SEPARATOR.'saiadmin'.DIRECTORY_SEPARATOR.'utils'.DIRECTORY_SEPARATOR.'code'.DIRECTORY_SEPARATOR.'stub', 'generate_path' => runtime_path().DIRECTORY_SEPARATOR.'code_engine'.DIRECTORY_SEPARATOR.'saiadmin', ]; } /** * 构造器 */ public function __construct() { // 读取配置文件 $config = self::_getConfig(); // 清理源目录 if (is_dir($config['generate_path'])) { $this->recursiveDelete($config['generate_path']); } // 清理压缩文件 $zipName = $config['generate_path'].'.zip'; if (is_file($zipName)) { unlink($zipName); } } /** * 文件压缩 */ public function compress(bool $isDownload = false) { // 读取配置文件 $config = self::_getConfig(); $zipArc = new \ZipArchive; $zipName = $config['generate_path'].'.zip'; $dirPath = $config['generate_path']; if ($zipArc->open($zipName, \ZipArchive::OVERWRITE | \ZipArchive::CREATE) !== true) { throw new ApiException('无法打开文件,或者文件创建失败'); } $this->addFileToZip($dirPath, $zipArc); $zipArc->close(); // 是否下载 if ($isDownload) { $this->toBinary($zipName); } else { return $zipName; } } /** * 文件解压 */ public function deCompress(string $file, string $dirName) { if (!file_exists($file)) { return false; } // zip实例化对象 $zipArc = new \ZipArchive(); // 打开文件 if (!$zipArc->open($file)) { return false; } // 解压文件 if (!$zipArc->extractTo($dirName)) { // 关闭 $zipArc->close(); return false; } return $zipArc->close(); } /** * 将文件加入到压缩包 */ public function addFileToZip($rootPath, $zip) { $files = new \RecursiveIteratorIterator( new \RecursiveDirectoryIterator($rootPath), \RecursiveIteratorIterator::LEAVES_ONLY ); foreach ($files as $name => $file) { // Skip directories (they would be added automatically) if (!$file->isDir()) { // Get real and relative path for current file $filePath = $file->getRealPath(); $relativePath = substr($filePath, strlen($rootPath) + 1); // Add current file to archive $zip->addFile($filePath, $relativePath); } } } /** * 递归删除目录下所有文件和文件夹 */ public function recursiveDelete($dir) { // 打开指定目录 if ($handle = @opendir($dir)) { while (($file = readdir($handle)) !== false) { if (($file == ".") || ($file == "..")) { continue; } if (is_dir($dir . '/' . $file)) { // 递归 self::recursiveDelete($dir . '/' . $file); } else { unlink($dir . '/' . $file); // 删除文件 } } @closedir($handle); } rmdir($dir); } /** * 下载二进制流文件 */ public function toBinary(string $fileName) { try { header("Cache-Control: public"); header("Content-Description: File Transfer"); header('Content-disposition: attachment; filename=' . basename($fileName)); //文件名 header("Content-Type: application/zip"); //zip格式的 header("Content-Transfer-Encoding: binary"); //告诉浏览器,这是二进制文件 header('Content-Length: ' . filesize($fileName)); //告诉浏览器,文件大小 if(ob_get_length() > 0) { ob_clean(); } flush(); @readfile($fileName); @unlink($fileName); } catch (\Throwable $th) { throw new ApiException('系统生成文件错误'); } } } ================================================ FILE: src/plugin/saiadmin/utils/code/stub/saiadmin/php/controller.stub ================================================ logic = new {{class_name}}Logic(); $this->validate = new {{class_name}}Validate; parent::__construct(); } /** * 数据列表 * @param Request $request * @return Response */ #[Permission('{{menu_name}}列表', '{{namespace}}:{{package_name}}:{{business_name}}:index')] public function index(Request $request): Response { $where = $request->more([ {% for column in columns %} {% if column.is_query == '2' %} ['{{column.column_name}}', ''], {% endif %} {% endfor %} ]); {% if tpl_category == 'single' %} $query = $this->logic->search($where); {% if options.relations != null %} $query->with([ {% for item in options.relations %} '{{item.name}}', {% endfor %} ]); {% endif %} $data = $this->logic->getList($query); {% endif %} {% if tpl_category == 'tree' %} $data = $this->logic->tree($where); {% endif %} return $this->success($data); } /** * 读取数据 * @param Request $request * @return Response */ #[Permission('{{menu_name}}读取', '{{namespace}}:{{package_name}}:{{business_name}}:read')] public function read(Request $request): Response { $id = $request->input('id', ''); $model = $this->logic->read($id); if ($model) { $data = is_array($model) ? $model : $model->toArray(); return $this->success($data); } else { return $this->fail('未查找到信息'); } } /** * 保存数据 * @param Request $request * @return Response */ #[Permission('{{menu_name}}添加', '{{namespace}}:{{package_name}}:{{business_name}}:save')] public function save(Request $request): Response { $data = $request->post(); $this->validate('save', $data); $result = $this->logic->add($data); if ($result) { return $this->success('添加成功'); } else { return $this->fail('添加失败'); } } /** * 更新数据 * @param Request $request * @return Response */ #[Permission('{{menu_name}}修改', '{{namespace}}:{{package_name}}:{{business_name}}:update')] public function update(Request $request): Response { $data = $request->post(); $this->validate('update', $data); $result = $this->logic->edit($data['id'], $data); if ($result) { return $this->success('修改成功'); } else { return $this->fail('修改失败'); } } /** * 删除数据 * @param Request $request * @return Response */ #[Permission('{{menu_name}}删除', '{{namespace}}:{{package_name}}:{{business_name}}:destroy')] public function destroy(Request $request): Response { $ids = $request->post('ids', ''); if (empty($ids)) { return $this->fail('请选择要删除的数据'); } $result = $this->logic->destroy($ids); if ($result) { return $this->success('删除成功'); } else { return $this->fail('删除失败'); } } } ================================================ FILE: src/plugin/saiadmin/utils/code/stub/saiadmin/php/logic.stub ================================================ model = new {{class_name}}(); } {% if tpl_category == 'tree' %} /** * 修改数据 * @param $id * @param $data * @return mixed */ public function edit($id, $data): mixed { if (!isset($data['{{options.tree_parent_id}}'])) { $data['{{options.tree_parent_id}}'] = 0; } if ($data['{{options.tree_parent_id}}'] == $data['{{options.tree_id}}']) { throw new ApiException('不能设置父级为自身'); } return parent::edit($id, $data); } /** * 删除数据 * @param $ids */ public function destroy($ids): bool { $num = $this->model->whereIn('{{options.tree_parent_id}}', $ids)->count(); if ($num > 0) { throw new ApiException('该分类下存在子分类,请先删除子分类'); } else { return parent::destroy($ids); } } /** * 树形数据 */ public function tree($where) { $query = $this->search($where); $request = request(); if ($request && $request->input('tree', 'false') === 'true') { {% if stub == 'eloquent' %} $query->select('{{options.tree_id}}', '{{options.tree_id}} as value', '{{options.tree_name}} as label', '{{options.tree_parent_id}}'); {% else %} $query->field('{{options.tree_id}}, {{options.tree_id}} as value, {{options.tree_name}} as label, {{options.tree_parent_id}}'); {% endif %} } {% if options.relations != null %} $query->with([ {% for item in options.relations %} '{{item.name}}', {% endfor %} ]); {% endif %} $data = $this->getAll($query); return Helper::makeTree($data); } {% endif %} } ================================================ FILE: src/plugin/saiadmin/utils/code/stub/saiadmin/php/model.stub ================================================ 'array', {% endif %} {% if column.view_type == 'uploadImage' and column.options.limit > 1 %} '{{column.column_name}}' => 'array', {% endif %} {% if column.view_type == 'imagePicker' and column.options.limit > 1 %} '{{column.column_name}}' => 'array', {% endif %} {% if column.view_type == 'uploadFile' and column.options.limit > 1 %} '{{column.column_name}}' => 'array', {% endif %} {% if column.view_type == 'chunkUpload' and column.options.limit > 1 %} '{{column.column_name}}' => 'array', {% endif %} {% endfor %} ]); } {% else %} {% for column in columns %} {% if column.view_type == 'inputTag' or column.view_type == 'checkbox' %} /** * {{column.column_comment}} 保存数组转换 */ public function set{{column.column_name | camel}}Attr($value) { return json_encode($value, JSON_UNESCAPED_UNICODE); } /** * {{column.column_comment}} 读取数组转换 */ public function get{{column.column_name | camel}}Attr($value) { return json_decode($value ?? '', true); } {% endif %} {% if column.view_type == 'uploadImage' and column.options.limit > 1 %} /** * {{column.column_comment}} 保存数组转换 */ public function set{{column.column_name | camel}}Attr($value) { return json_encode($value, JSON_UNESCAPED_UNICODE); } /** * {{column.column_comment}} 读取数组转换 */ public function get{{column.column_name | camel}}Attr($value) { return json_decode($value ?? '', true); } {% endif %} {% if column.view_type == 'imagePicker' and column.options.limit > 1 %} /** * {{column.column_comment}} 保存数组转换 */ public function set{{column.column_name | camel}}Attr($value) { return json_encode($value, JSON_UNESCAPED_UNICODE); } /** * {{column.column_comment}} 读取数组转换 */ public function get{{column.column_name | camel}}Attr($value) { return json_decode($value ?? '', true); } {% endif %} {% if column.view_type == 'uploadFile' and column.options.limit > 1 %} /** * {{column.column_comment}} 保存数组转换 */ public function set{{column.column_name | camel}}Attr($value) { return json_encode($value, JSON_UNESCAPED_UNICODE); } /** * {{column.column_comment}} 读取数组转换 */ public function get{{column.column_name | camel}}Attr($value) { return json_decode($value ?? '', true); } {% endif %} {% if column.view_type == 'chunkUpload' and column.options.limit > 1 %} /** * {{column.column_comment}} 保存数组转换 */ public function set{{column.column_name | camel}}Attr($value) { return json_encode($value, JSON_UNESCAPED_UNICODE); } /** * {{column.column_comment}} 读取数组转换 */ public function get{{column.column_name | camel}}Attr($value) { return json_decode($value ?? '', true); } {% endif %} {% endfor %} {% endif %} {% for column in columns %} {% if column.is_query == 2 and column.query_type == 'neq' %} /** * {{column.column_comment}} 搜索 */ public function search{{column.column_name | camel}}Attr($query, $value) { $query->where('{{column.column_name}}', '<>', $value); } {% endif %} {% if column.is_query == 2 and column.query_type == 'gt' %} /** * {{column.column_comment}} 搜索 */ public function search{{column.column_name | camel}}Attr($query, $value) { $query->where('{{column.column_name}}', '>', $value); } {% endif %} {% if column.is_query == 2 and column.query_type == 'gte' %} /** * {{column.column_comment}} 搜索 */ public function search{{column.column_name | camel}}Attr($query, $value) { $query->where('{{column.column_name}}', '>=', $value); } {% endif %} {% if column.is_query == 2 and column.query_type == 'lt' %} /** * {{column.column_comment}} 搜索 */ public function search{{column.column_name | camel}}Attr($query, $value) { $query->where('{{column.column_name}}', '<', $value); } {% endif %} {% if column.is_query == 2 and column.query_type == 'lte' %} /** * {{column.column_comment}} 搜索 */ public function search{{column.column_name | camel}}Attr($query, $value) { $query->where('{{column.column_name}}', '<=', $value); } {% endif %} {% if column.is_query == 2 and column.query_type == 'like' %} /** * {{column.column_comment}} 搜索 */ public function search{{column.column_name | camel}}Attr($query, $value) { $query->where('{{column.column_name}}', 'like', '%'.$value.'%'); } {% endif %} {% if column.is_query == 2 and column.query_type == 'in' %} /** * {{column.column_comment}} 搜索 */ public function search{{column.column_name | camel}}Attr($query, $value) { $query->whereIn('{{column.column_name}}', $value); } {% endif %} {% if column.is_query == 2 and column.query_type == 'notin' %} /** * {{column.column_comment}} 搜索 */ public function search{{column.column_name | camel}}Attr($query, $value) { $query->whereNotIn('{{column.column_name}}', $value); } {% endif %} {% if column.is_query == 2 and column.query_type == 'between' %} /** * {{column.column_comment}} 搜索 */ public function search{{column.column_name | camel}}Attr($query, $value) { $query->whereBetween('{{column.column_name}}', $value); } {% endif %} {% endfor %} {% for item in options.relations %} {% if item.type == 'belongsTo' %} /** * 关联模型 {{item.name}} */ public function {{item.name}}() { return $this->{{item.type}}({{item.model}}::class, '{{item.localKey}}', '{{item.foreignKey}}'); } {% endif %} {% if item.type == 'hasOne' or item.type == 'hasMany' %} /** * 关联模型 {{item.name}} */ public function {{item.name}}() { return $this->{{item.type}}({{item.model}}::class, '{{item.localKey}}', '{{item.foreignKey}}'); } {% endif %} {% if item.type == 'belongsToMany' and stub == 'think' %} /** * 关联模型 {{item.name}} */ public function {{item.name}}() { return $this->{{item.type}}({{item.model}}::class, {{item.table}}::class, '{{item.localKey}}', '{{item.foreignKey}}'); } {% endif %} {% if item.type == 'belongsToMany' and stub == 'eloquent' %} /** * 关联模型 {{item.name}} */ public function {{item.name}}() { return $this->{{item.type}}({{item.model}}::class, {{item.table}}::class, '{{item.foreignKey}}', '{{item.localKey}}'); } {% endif %} {% endfor %} } ================================================ FILE: src/plugin/saiadmin/utils/code/stub/saiadmin/php/validate.stub ================================================ 'require', {% endif %} {% endfor %} ]; /** * 定义错误信息 */ protected $message = [ {% for column in columns %} {% if column.is_required == 2 and column.is_pk != 2 %} '{{column.column_name}}' => '{{column.column_comment}}必须填写', {% endif %} {% endfor %} ]; /** * 定义场景 */ protected $scene = [ 'save' => [ {% for column in columns %} {% if column.is_required == 2 and column.is_pk != 2 %} '{{column.column_name}}', {% endif %} {% endfor %} ], 'update' => [ {% for column in columns %} {% if column.is_required == 2 and column.is_pk != 2 %} '{{column.column_name}}', {% endif %} {% endfor %} ], ]; } ================================================ FILE: src/plugin/saiadmin/utils/code/stub/saiadmin/sql/sql.stub ================================================ -- 数据库语句-- {% for column in tables %} -- 菜单[{{column.menu_name}}] SQL INSERT INTO `sa_system_menu`(`parent_id`, `name`, `code`, `slug`, `type`, `path`, `component`, `icon`, `sort`, `is_iframe`, `is_keep_alive`, `is_hidden`, `is_fixed_tab`, `is_full_page`, `create_time`, `update_time`) VALUES ({{column.belong_menu_id}}, '{{column.menu_name}}', '{{column.namespace}}/{{column.package_name}}/{{column.business_name}}', '', 2, '{{column.package_name}}/{{column.business_name}}', '/plugin/{{column.namespace}}/{{column.package_name}}/{{column.business_name}}/index', 'ri:home-2-line', 100, 2, 2, 2, 2, 2, now(), now()); SET @id := LAST_INSERT_ID(); INSERT INTO `sa_system_menu`(`parent_id`, `name`, `slug`, `type`, `sort`, `is_iframe`, `is_keep_alive`, `is_hidden`, `is_fixed_tab`, `is_full_page`, `create_time`, `update_time`) VALUES (@id, '列表', '{{column.namespace}}:{{column.package_name}}:{{column.business_name}}:index', 3, 100, 2, 2, 2, 2, 2, now(), now()); INSERT INTO `sa_system_menu`(`parent_id`, `name`, `slug`, `type`, `sort`, `is_iframe`, `is_keep_alive`, `is_hidden`, `is_fixed_tab`, `is_full_page`, `create_time`, `update_time`) VALUES (@id, '保存', '{{column.namespace}}:{{column.package_name}}:{{column.business_name}}:save', 3, 100, 2, 2, 2, 2, 2, now(), now()); INSERT INTO `sa_system_menu`(`parent_id`, `name`, `slug`, `type`, `sort`, `is_iframe`, `is_keep_alive`, `is_hidden`, `is_fixed_tab`, `is_full_page`, `create_time`, `update_time`) VALUES (@id, '更新', '{{column.namespace}}:{{column.package_name}}:{{column.business_name}}:update', 3, 100, 2, 2, 2, 2, 2, now(), now()); INSERT INTO `sa_system_menu`(`parent_id`, `name`, `slug`, `type`, `sort`, `is_iframe`, `is_keep_alive`, `is_hidden`, `is_fixed_tab`, `is_full_page`, `create_time`, `update_time`) VALUES (@id, '读取', '{{column.namespace}}:{{column.package_name}}:{{column.business_name}}:read', 3, 100, 2, 2, 2, 2, 2, now(), now()); INSERT INTO `sa_system_menu`(`parent_id`, `name`, `slug`, `type`, `sort`, `is_iframe`, `is_keep_alive`, `is_hidden`, `is_fixed_tab`, `is_full_page`, `create_time`, `update_time`) VALUES (@id, '删除', '{{column.namespace}}:{{column.package_name}}:{{column.business_name}}:destroy', 3, 100, 2, 2, 2, 2, 2, now(), now()); {% endfor %} ================================================ FILE: src/plugin/saiadmin/utils/code/stub/saiadmin/ts/api.stub ================================================ import request from '@/utils/http' /** * {{menu_name}} API接口 */ export default { /** * 获取数据列表 * @param params 搜索参数 * @returns 数据列表 */ list(params: Record