From 54b55fdccea3659b4c197c169d71badaaebdfce1 Mon Sep 17 00:00:00 2001 From: liaofei <136327134@qq.com> Date: Mon, 17 Apr 2023 10:14:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=A4=9A=E8=AF=AD=E8=A8=80?= =?UTF-8?q?=E7=BF=BB=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/v1/setting/SystemCrud.php | 26 +++++++++---------- .../controller/v1/setting/SystemRoute.php | 14 +++++----- .../controller/v1/setting/SystemRouteCate.php | 14 +++++----- .../services/system/SystemCrudServices.php | 12 ++++----- .../services/system/SystemRouteServices.php | 2 +- crmeb/crmeb/services/crud/Make.php | 6 ++--- crmeb/crmeb/services/crud/Route.php | 2 +- crmeb/crmeb/services/crud/ViewApi.php | 2 +- crmeb/crmeb/services/crud/ViewRouter.php | 2 +- 9 files changed, 39 insertions(+), 41 deletions(-) diff --git a/crmeb/app/adminapi/controller/v1/setting/SystemCrud.php b/crmeb/app/adminapi/controller/v1/setting/SystemCrud.php index 1fd145b83..2c9747b77 100644 --- a/crmeb/app/adminapi/controller/v1/setting/SystemCrud.php +++ b/crmeb/app/adminapi/controller/v1/setting/SystemCrud.php @@ -98,12 +98,12 @@ class SystemCrud extends AuthController $data['fromField'] = $fromField; $data['columnField'] = $columnField; if (!$data['tableName']) { - return app('json')->fail('缺少表名'); + return app('json')->fail(500045); } $this->services->createCrud($data); - return app('json')->success('创建成功'); + return app('json')->success(500046); } /** @@ -121,11 +121,11 @@ class SystemCrud extends AuthController ], true); if (!$tableName) { - return app('json')->fail('缺少表名'); + return app('json')->fail(500045); } if (in_array($tableName, SystemCrudServices::NOT_CRUD_TABANAME)) { - return app('json')->fail('不能生成系统自带数据表'); + return app('json')->fail(500044); } $routeName = 'crud/' . Str::snake($tableName); @@ -176,12 +176,12 @@ class SystemCrud extends AuthController public function read($id) { if (!$id) { - return app('json')->fail('缺少参数'); + return app('json')->fail(500035); } $info = $this->services->get($id); if (!$info) { - return app('json')->fail('查看的生成的文件不存在'); + return app('json')->fail(500043); } $routeName = 'crud/' . Str::snake($info->table_name); @@ -256,12 +256,12 @@ class SystemCrud extends AuthController public function delete(SystemMenusServices $services, $id) { if (!$id) { - return app('json')->fail('缺少参数'); + return app('json')->fail(500035); } $info = $this->services->get($id); if (!$info) { - return app('json')->fail('删除的数据不存在'); + return app('json')->fail(500042); } $services->transaction(function () use ($services, $info) { @@ -283,12 +283,12 @@ class SystemCrud extends AuthController unlink($item); } } catch (\Throwable $e) { - return app('json')->success('删除生成的菜单和信息成功,删除文件出错,详细错误:' . $e->getMessage()); + return app('json')->success(500041, [], ['message' => $e->getMessage()]); } } - return app('json')->success('删除成功'); + return app('json')->success(100002); } /** @@ -302,12 +302,12 @@ class SystemCrud extends AuthController public function download($id) { if (!$id) { - return app('json')->fail('缺少参数'); + return app('json')->fail(500035); } $info = $this->services->get($id); if (!$info) { - return app('json')->fail('下载的文件不存在'); + return app('json')->fail(500039); } $zipPath = app()->getRootPath() . 'backup' . DS . Str::camel($info->table_name); $zipName = app()->getRootPath() . 'backup' . DS . Str::camel($info->table_name) . '.zip'; @@ -353,7 +353,7 @@ class SystemCrud extends AuthController ], $makePath); if (!extension_loaded('zip')) { - return app('json')->fail('请安装zip扩展后在尝试下载'); + return app('json')->fail(500040); } $fileService = new FileService(); diff --git a/crmeb/app/adminapi/controller/v1/setting/SystemRoute.php b/crmeb/app/adminapi/controller/v1/setting/SystemRoute.php index 9e9eb4ee3..cc472f8ca 100644 --- a/crmeb/app/adminapi/controller/v1/setting/SystemRoute.php +++ b/crmeb/app/adminapi/controller/v1/setting/SystemRoute.php @@ -112,16 +112,16 @@ class SystemRoute extends AuthController ]); if (!$data['name']) { - return app('json')->fail('请输入路由名称'); + return app('json')->fail(500031); } if (!$data['path']) { - return app('json')->fail('请输入路由路径'); + return app('json')->fail(500032); } if (!$data['method']) { - return app('json')->fail('请选择路由请求方式'); + return app('json')->fail(500033); } if (!$data['app_name']) { - return app('json')->fail('缺少应用名参数'); + return app('json')->fail(500034); } if ($id) { $this->services->update($id, $data); @@ -130,7 +130,7 @@ class SystemRoute extends AuthController $this->services->save($data); } - return app('json')->success($id ? '修改成功' : '添加成功'); + return app('json')->success($id ? 100001 : 100021); } /** @@ -155,12 +155,12 @@ class SystemRoute extends AuthController public function delete($id) { if (!$id) { - return app('json')->fail('缺少参数'); + return app('json')->fail(500035); } $this->services->destroy($id); - return app('json')->success('删除成功'); + return app('json')->success(100002); } diff --git a/crmeb/app/adminapi/controller/v1/setting/SystemRouteCate.php b/crmeb/app/adminapi/controller/v1/setting/SystemRouteCate.php index fd2f5eb17..798d807e0 100644 --- a/crmeb/app/adminapi/controller/v1/setting/SystemRouteCate.php +++ b/crmeb/app/adminapi/controller/v1/setting/SystemRouteCate.php @@ -80,7 +80,7 @@ class SystemRouteCate extends AuthController ]); if (!$data['name']) { - return app('json')->fail('缺少分类名称'); + return app('json')->fail(500037); } $data['add_time'] = time(); @@ -88,7 +88,7 @@ class SystemRouteCate extends AuthController $this->services->save($data); - return app('json')->success('保存成功'); + return app('json')->success(100000); } @@ -122,13 +122,13 @@ class SystemRouteCate extends AuthController ]); if (!$data['name']) { - return app('json')->fail('缺少分类名称'); + return app('json')->fail(500037); } $data['pid'] = $data['path'][count($data['path']) - 1] ?? 0; $this->services->update($id, $data); - return app('json')->success('修改成功'); + return app('json')->success(100001); } /** @@ -142,15 +142,15 @@ class SystemRouteCate extends AuthController public function delete(SystemRouteServices $service, $id) { if (!$id) { - return app('json')->fail('缺少参数'); + return app('json')->fail(500035); } if ($service->count(['cate_id' => $id])) { - return app('json')->fail('请先删除分类下的接口'); + return app('json')->fail(500038); } $this->services->delete($id); - return app('json')->success('删除成功'); + return app('json')->success(100002); } } diff --git a/crmeb/app/services/system/SystemCrudServices.php b/crmeb/app/services/system/SystemCrudServices.php index fb735e3b5..9afa6e25d 100644 --- a/crmeb/app/services/system/SystemCrudServices.php +++ b/crmeb/app/services/system/SystemCrudServices.php @@ -16,6 +16,7 @@ namespace app\services\system; use app\dao\system\SystemCrudDao; use app\services\BaseServices; +use crmeb\exceptions\AdminException; use crmeb\services\crud\Controller; use crmeb\services\crud\Dao; use crmeb\services\crud\Make; @@ -27,11 +28,8 @@ use crmeb\services\crud\ViewApi; use crmeb\services\crud\ViewPages; use crmeb\services\crud\ViewRouter; use Phinx\Db\Adapter\AdapterFactory; -use think\exception\ValidateException; use think\facade\Db; use think\helper\Str; -use think\migration\Migrator; -use Phinx\Db\Adapter\MysqlAdapter; use think\migration\db\Table; /** @@ -140,7 +138,7 @@ class SystemCrudServices extends BaseServices { if (!in_array($type, $this->getTabelRule()['types'])) { - throw new ValidateException('类型不在支持范围'); + throw new AdminException(500047); } return $this->getTabelRule()['rule'][$type] ?? $type; @@ -234,7 +232,7 @@ class SystemCrudServices extends BaseServices $filePath = $this->valueReplace($data['filePath']); if ($this->dao->value(['table_name' => $tableName])) { - throw new ValidateException('此表已经生成请在列表中查看'); + throw new AdminException(500048); } $data['softDelete'] = false; @@ -247,13 +245,13 @@ class SystemCrudServices extends BaseServices } if (in_array($tableName, self::NOT_CRUD_TABANAME)) { - throw new ValidateException('不能生成系统自带数据表'); + throw new AdminException(500044); } //读取表结构 $column = $this->getColumnNamesList($tableName); if (!$column) { - throw new ValidateException('请先创建' . $tableName . '表'); + throw new AdminException(500049, ['_name' => $tableName]); } $tableInfo = $this->getTableInfo($tableName); diff --git a/crmeb/app/services/system/SystemRouteServices.php b/crmeb/app/services/system/SystemRouteServices.php index a1f1fea42..7e0e07337 100644 --- a/crmeb/app/services/system/SystemRouteServices.php +++ b/crmeb/app/services/system/SystemRouteServices.php @@ -65,7 +65,7 @@ class SystemRouteServices extends BaseServices { $routeInfo = $this->dao->get($id); if (!$routeInfo) { - throw new ValidateException('修改的路由不存在'); + throw new ValidateException(500036); } $routeInfo = $routeInfo->toArray(); diff --git a/crmeb/crmeb/services/crud/Make.php b/crmeb/crmeb/services/crud/Make.php index 5dd8752dd..a4aad281d 100644 --- a/crmeb/crmeb/services/crud/Make.php +++ b/crmeb/crmeb/services/crud/Make.php @@ -445,7 +445,7 @@ abstract class Make if ($this->isExistsMake) { unlink($pathname); } else { - throw new CrudException($this->name . ':' . $pathname . ' already exists!'); + throw new CrudException(500052, ['filename' => $this->name . ':' . $pathname]); } } @@ -454,13 +454,13 @@ abstract class Make mkdir(dirname($pathname), 0755, true); } } catch (\Throwable $e) { - throw new CrudException('CRUD创建目录报错,无法创建:' . dirname($pathname)); + throw new CrudException(500050, ['pathname' => dirname($pathname)]); } try { file_put_contents($pathname, $this->content); } catch (\Throwable $e) { - throw new CrudException('CRUD生成文件报错,无法写入:' . $pathname); + throw new CrudException(500051, ['pathname' => $pathname]); } } } diff --git a/crmeb/crmeb/services/crud/Route.php b/crmeb/crmeb/services/crud/Route.php index bdcce1157..f69776722 100644 --- a/crmeb/crmeb/services/crud/Route.php +++ b/crmeb/crmeb/services/crud/Route.php @@ -49,7 +49,7 @@ class Route extends Make $routePath = $options['routePath'] ?? ''; $menus = $options['menus'] ?? ''; if (!$route) { - throw new CrudException('缺少路由名称'); + throw new CrudException(500053); } if (!$action) { $action = ['index', 'create', 'save', 'edit', 'update', 'delete']; diff --git a/crmeb/crmeb/services/crud/ViewApi.php b/crmeb/crmeb/services/crud/ViewApi.php index 41f85e323..c5f5f69f9 100644 --- a/crmeb/crmeb/services/crud/ViewApi.php +++ b/crmeb/crmeb/services/crud/ViewApi.php @@ -75,7 +75,7 @@ class ViewApi extends Make } $route = $options['route'] ?? ''; if (!$route) { - throw new CrudException('缺少路由名称'); + throw new CrudException(500053); } $contentJs = ''; diff --git a/crmeb/crmeb/services/crud/ViewRouter.php b/crmeb/crmeb/services/crud/ViewRouter.php index f56ce73f8..125206095 100644 --- a/crmeb/crmeb/services/crud/ViewRouter.php +++ b/crmeb/crmeb/services/crud/ViewRouter.php @@ -75,7 +75,7 @@ class ViewRouter extends Make $route = $options['route'] ?? Str::snake($name); $pagePath = $options['pagePath'] ?? Str::camel($name); if (!$route) { - throw new CrudException('缺少路由名称'); + throw new CrudException(500053); } $this->value['menus'] = $menus;