From 4ab86306171327430908c196a9af07f918ada3d3 Mon Sep 17 00:00:00 2001 From: augushong Date: Tue, 12 Jul 2022 11:00:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E5=A4=A7=E5=A4=9A=E6=95=B0?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=9A=84=E5=A4=96=E9=83=A8=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E4=BE=9D=E8=B5=96=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/Ajax.php | 47 ++++++++------------- app/admin/middleware/SystemLog.php | 4 +- app/admin/service/curd/BuildCurdService.php | 1 - app/admin/service/node/Node.php | 1 - app/common/command/Curd.php | 38 +++++++---------- app/common/controller/AdminController.php | 3 +- app/common/service/AuthService.php | 3 +- app/common/service/UploadService.php | 8 ++-- 8 files changed, 43 insertions(+), 62 deletions(-) diff --git a/app/admin/controller/Ajax.php b/app/admin/controller/Ajax.php index ddf574a..9fc58e9 100644 --- a/app/admin/controller/Ajax.php +++ b/app/admin/controller/Ajax.php @@ -7,10 +7,9 @@ use app\admin\model\SystemUploadfile; use app\common\controller\AdminController; use app\common\service\MenuService; use app\common\service\UploadService; -use EasyAdmin\upload\Uploadfile; use think\db\Query; use think\facade\Cache; -use think\facade\Filesystem; + class Ajax extends AdminController { @@ -61,7 +60,7 @@ class Ajax extends AdminController 'upload_type' => $this->request->post('upload_type'), 'file' => $this->request->file('file'), ]; - + try { $upload_service = new UploadService($data['upload_type']); @@ -69,7 +68,6 @@ class Ajax extends AdminController $upload_service->validateException($data['file']); $result = $upload_service->save($data['file']); - } catch (\Exception $e) { $this->error($e->getMessage()); } @@ -88,35 +86,26 @@ class Ajax extends AdminController 'upload_type' => $this->request->post('upload_type'), 'file' => $this->request->file('upload'), ]; - $uploadConfig = sysconfig('upload'); - empty($data['upload_type']) && $data['upload_type'] = $uploadConfig['upload_type']; - $rule = [ - 'upload_type|指定上传类型有误' => "in:{$uploadConfig['upload_allow_type']}", - 'file|文件' => "require|file|fileExt:{$uploadConfig['upload_allow_ext']}|fileSize:{$uploadConfig['upload_allow_size']}", - ]; - $this->validate($data, $rule); + try { - $upload = Uploadfile::instance() - ->setUploadType($data['upload_type']) - ->setUploadConfig($uploadConfig) - ->setFile($data['file']) - ->save(); + $upload_service = new UploadService($data['upload_type']); + + $upload_service->validateException($data['file']); + + $result = $upload_service->save($data['file']); } catch (\Exception $e) { $this->error($e->getMessage()); } - if ($upload['save'] == true) { - return json([ - 'error' => [ - 'message' => '上传成功', - 'number' => 201, - ], - 'fileName' => '', - 'uploaded' => 1, - 'url' => $upload['url'], - ]); - } else { - $this->error($upload['msg']); - } + + return json([ + 'error' => [ + 'message' => '上传成功', + 'number' => 201, + ], + 'fileName' => '', + 'uploaded' => 1, + 'url' => $result['url'], + ]); } /** diff --git a/app/admin/middleware/SystemLog.php b/app/admin/middleware/SystemLog.php index 0fe2f07..50d2ac2 100644 --- a/app/admin/middleware/SystemLog.php +++ b/app/admin/middleware/SystemLog.php @@ -4,8 +4,8 @@ namespace app\admin\middleware; use app\Request; -use EasyAdmin\tool\CommonTool; use think\facade\Log; +use think\facade\Request as FacadeRequest; /** * 系统操作日志中间件 @@ -40,7 +40,7 @@ class SystemLog if ($request->isAjax()) { if (in_array($method, ['post', 'put', 'delete'])) { - $ip = CommonTool::getRealIp(); + $ip = FacadeRequest::ip(); $data = [ 'admin_id' => session('admin.id'), 'url' => $url, diff --git a/app/admin/service/curd/BuildCurdService.php b/app/admin/service/curd/BuildCurdService.php index 0287ef1..e17593c 100644 --- a/app/admin/service/curd/BuildCurdService.php +++ b/app/admin/service/curd/BuildCurdService.php @@ -11,7 +11,6 @@ use think\helper\Str; /** * 快速构建系统CURD * Class BuildCurd - * @package EasyAdmin\curd */ class BuildCurdService { diff --git a/app/admin/service/node/Node.php b/app/admin/service/node/Node.php index d3da471..903ce8a 100644 --- a/app/admin/service/node/Node.php +++ b/app/admin/service/node/Node.php @@ -22,7 +22,6 @@ use think\helper\Str; /** * 节点处理类 * Class Node - * @package EasyAdmin\auth */ class Node { diff --git a/app/common/command/Curd.php b/app/common/command/Curd.php index abd7d47..db20ccc 100644 --- a/app/common/command/Curd.php +++ b/app/common/command/Curd.php @@ -4,15 +4,11 @@ namespace app\common\command; -use app\admin\model\SystemNode; use app\admin\service\curd\BuildCurdService; -use EasyAdmin\console\CliEcho; -use app\common\tools\BuildCurdTools; use think\console\Command; use think\console\Input; use think\console\input\Option; use think\console\Output; -use EasyAdmin\auth\Node as NodeService; use think\Exception; class Curd extends Command @@ -39,10 +35,8 @@ class Curd extends Command $force = $input->getOption('force'); $delete = $input->getOption('delete'); - - if (empty($table)) { - CliEcho::error('请设置主表'); + $output->error('请设置主表'); return false; } @@ -63,7 +57,7 @@ class Curd extends Command $define = $column['define']; if (!isset($define['table'])) { - CliEcho::error("关联字段{$field}没有设置关联表名称"); + $output->error("关联字段{$field}没有设置关联表名称"); return false; } @@ -92,40 +86,40 @@ class Curd extends Command if (!$delete) { if ($force) { - $output->info(">>>>>>>>>>>>>>>"); + $output->writeln(">>>>>>>>>>>>>>>"); foreach ($fileList as $key => $val) { - $output->info($key); + $output->writeln($key); } - $output->info(">>>>>>>>>>>>>>>"); - $output->info("确定强制生成上方所有文件? 如果文件存在会直接覆盖。 请输入 'yes' 按回车键继续操作: "); + $output->writeln(">>>>>>>>>>>>>>>"); + $output->writeln("确定强制生成上方所有文件? 如果文件存在会直接覆盖。 请输入 'yes' 按回车键继续操作: "); $line = fgets(defined('STDIN') ? STDIN : fopen('php://stdin', 'r')); if (trim($line) != 'yes') { throw new Exception("取消文件CURD生成操作"); } } $result = $build->create(); - CliEcho::success('自动生成CURD成功'); + $output->info('自动生成CURD成功'); } else { - $output->info(">>>>>>>>>>>>>>>"); + $output->writeln(">>>>>>>>>>>>>>>"); foreach ($fileList as $key => $val) { - $output->info($key); + $output->writeln($key); } - $output->info(">>>>>>>>>>>>>>>"); - $output->info("确定删除上方所有文件? 请输入 'yes' 按回车键继续操作: "); + $output->writeln(">>>>>>>>>>>>>>>"); + $output->writeln("确定删除上方所有文件? 请输入 'yes' 按回车键继续操作: "); $line = fgets(defined('STDIN') ? STDIN : fopen('php://stdin', 'r')); if (trim($line) != 'yes') { throw new Exception("取消删除文件操作"); } $result = $build->delete(); - CliEcho::success('>>>>>>>>>>>>>>>'); - CliEcho::success('删除自动生成CURD文件成功'); + $output->info('>>>>>>>>>>>>>>>'); + $output->info('删除自动生成CURD文件成功'); } - CliEcho::success('>>>>>>>>>>>>>>>'); + $output->info('>>>>>>>>>>>>>>>'); foreach ($result as $vo) { - CliEcho::success($vo); + $output->info($vo); } } catch (\Exception $e) { - CliEcho::error($e->getMessage()); + $output->error($e->getMessage()); return false; } } diff --git a/app/common/controller/AdminController.php b/app/common/controller/AdminController.php index f205e6e..dba553e 100644 --- a/app/common/controller/AdminController.php +++ b/app/common/controller/AdminController.php @@ -9,7 +9,6 @@ use app\admin\service\ConfigService; use app\BaseController; use app\common\constants\AdminConstant; use app\common\service\AuthService; -use EasyAdmin\tool\CommonTool; use think\facade\Env; use think\facade\View; use think\Model; @@ -208,7 +207,7 @@ class AdminController extends BaseController $excludes = []; // 判断是否关联查询 - $tableName = CommonTool::humpToLine(lcfirst($this->model->getName())); + $tableName = \think\helper\Str::snake(lcfirst($this->model->getName())); foreach ($filters as $key => $val) { if (in_array($key, $excludeFields)) { diff --git a/app/common/service/AuthService.php b/app/common/service/AuthService.php index ef1e787..1542b78 100644 --- a/app/common/service/AuthService.php +++ b/app/common/service/AuthService.php @@ -4,7 +4,6 @@ namespace app\common\service; use app\common\constants\AdminConstant; -use EasyAdmin\tool\CommonTool; use think\facade\Config; use think\facade\Db; @@ -200,7 +199,7 @@ class AuthService if ($key == 0) { $val = explode('.', $val); foreach ($val as &$vo) { - $vo = CommonTool::humpToLine(lcfirst($vo)); + $vo = \think\helper\Str::snake(lcfirst($vo)); } $val = implode('.', $val); $array[$key] = $val; diff --git a/app/common/service/UploadService.php b/app/common/service/UploadService.php index ee3bdfa..458169e 100644 --- a/app/common/service/UploadService.php +++ b/app/common/service/UploadService.php @@ -56,7 +56,7 @@ class UploadService return $url; } - public function save(File $file) + public function save(File $file, string $save_name = null) { $model_file = new SystemUploadfile(); @@ -74,8 +74,10 @@ class UploadService $model_file->mime_type = $file->getMime(); } - - $save_name = Filesystem::disk($this->uploadType)->putFile('upload', $file, function () { + $save_name = Filesystem::disk($this->uploadType)->putFile('upload', $file, function () use ($save_name) { + if (!is_null($save_name)) { + return $save_name; + } return date('Ymd') . '/' . uniqid(); });