diff --git a/.gitignore b/.gitignore index 320e9e7..9d4c3a4 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,5 @@ vendor/ composer.lock /static/export /static/super -/static/upload \ No newline at end of file +/static/upload +/static/h5 \ No newline at end of file diff --git a/app/Controller/Admin/System.php b/app/Controller/Admin/System.php index 3fa23f1..e509f18 100644 --- a/app/Controller/Admin/System.php +++ b/app/Controller/Admin/System.php @@ -118,7 +118,7 @@ class System extends Base public function deptList() { $dept_name = $this->request->input("dept_name", ""); - return $this->success("菜单列表", dModel::list($this->accountId(), $this->account()['account_type'], $dept_name)); + return $this->success("菜单列表", dModel::list($this->account()['belong_id'], $this->account()['account_type'], $dept_name)); } #[GetMapping(path: "dept/option")] diff --git a/app/Event/WebSocket.php b/app/Event/WebSocket.php index 527a525..c06458c 100644 --- a/app/Event/WebSocket.php +++ b/app/Event/WebSocket.php @@ -44,6 +44,10 @@ class WebSocket implements OnMessageInterface, OnOpenInterface, OnCloseInterface public function onOpen($server, $request): void { $token = $request->get['Authorization']; + if (!$token) { + $server->push($request->fd, 'connection refused'); + return; + } $result = Token::parseToken(str_replace("Bearer ", "", $token)); $container = ApplicationContext::getContainer(); $cache = $container->get(CacheInterface::class); diff --git a/app/Job/FileExportJob.php b/app/Job/FileExportJob.php index 3df040f..35ff3c2 100644 --- a/app/Job/FileExportJob.php +++ b/app/Job/FileExportJob.php @@ -11,7 +11,7 @@ use App\Model\Message as mModel; class FileExportJob extends Job { - protected int $maxAttempts = 1; + protected int $maxAttempts = 0; protected int $attachmentId; public function __construct(array $params) @@ -40,8 +40,6 @@ class FileExportJob extends Job return aModel::edit(['attachment_id' => $this->attachmentId, 'status' => 2, 'fail_reason' => "导出失败"]); } aModel::edit(['attachment_id' => $this->attachmentId, 'status' => 1, 'type' => $type, 'path' => $res]); - // 导出成功,消息通知 - $data['type'] = 'system'; $id = mModel::add([ 'type' => 'attach', 'title' => $attach->name . " [执行成功]", @@ -58,6 +56,15 @@ class FileExportJob extends Job 'status' => 2, 'fail_reason' => $e->getMessage() ]); + $id = mModel::add([ + 'type' => 'attach', + 'title' => $attach->name . " [执行失败]", + 'content' => '执行失败', + 'create_id' => $attach->account_id, + ]); + if ($id) { + QueueClient::push("App\Job\NotifyJob", ['messageId' => $id, 'channels' => ['websocket', 'email'], 'userIds' => [$attach->account_id]]); + } } return true; } diff --git a/app/Middleware/JWTMiddleware.php b/app/Middleware/JWTMiddleware.php index f1d04c2..92854c3 100644 --- a/app/Middleware/JWTMiddleware.php +++ b/app/Middleware/JWTMiddleware.php @@ -42,7 +42,6 @@ class JWTMiddleware implements MiddlewareInterface */ public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { - $container = ApplicationContext::getContainer(); // 管理端 和 商户端 $request = $request->withAttribute("isLogin", false); $request = $request->withAttribute("account", []); diff --git a/app/Utils/Excel.php b/app/Utils/Excel.php index 294409c..5949e3c 100644 --- a/app/Utils/Excel.php +++ b/app/Utils/Excel.php @@ -4,7 +4,6 @@ namespace App\Utils; use Exception; use PhpOffice\PhpSpreadsheet\IOFactory; -use PhpOffice\PhpSpreadsheet\Reader\Xlsx; use PhpOffice\PhpSpreadsheet\Spreadsheet; use function Hyperf\Config\config; @@ -17,14 +16,18 @@ class Excel { try { if (!$file) return false; - $file = BASE_PATH . DIRECTORY_SEPARATOR . 'runtime' . DIRECTORY_SEPARATOR . $file; if (!file_exists($file)) return false; // 显式使用 Xlsx 读取器并配置兼容选项 - $reader = new Xlsx(); + $reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx(); // 关键配置:跳过样式/公式等兼容性陷阱 - $reader->setReadDataOnly(true); // 只读数据,忽略公式 - $reader->setReadEmptyCells(false); // 跳过空单元格处理 + $reader->setReadDataOnly(true); // 只读数据,忽略公式 + $reader->setReadEmptyCells(false); // 跳过空单元格处理 $reader->setLoadSheetsOnly(["Sheet1"]); // 明确加载指定工作表 + // 处理大文件内存问题 + $memoryLimit = (int)ini_get('memory_limit') * 1024 * 1024; + if (filesize($file) > $memoryLimit * 0.3) { + \PhpOffice\PhpSpreadsheet\Settings::setCache(new \PhpOffice\PhpSpreadsheet\Cache\Filesys()); + } $spreadsheet = $reader->load($file); return $spreadsheet->getSheet(0)->toArray(); } catch (Exception $e) { diff --git a/app/Utils/Str.php b/app/Utils/Str.php index 204fff2..48ba97c 100644 --- a/app/Utils/Str.php +++ b/app/Utils/Str.php @@ -7,7 +7,6 @@ namespace App\Utils; use App\Exception\ServiceException; use function Hyperf\Config\config; -use function PHPUnit\Framework\matches; class Str { diff --git a/composer.json b/composer.json index c61864e..ea90bc4 100644 --- a/composer.json +++ b/composer.json @@ -58,7 +58,8 @@ }, "autoload": { "psr-4": { - "App\\": "app/" + "App\\": "app/", + "Plugins\\": "plugins/" }, "files": [ "app/Utils/helpers.php" diff --git a/config/autoload/server.php b/config/autoload/server.php index 1854159..17946c0 100644 --- a/config/autoload/server.php +++ b/config/autoload/server.php @@ -59,9 +59,9 @@ return [ Constant::OPTION_BUFFER_OUTPUT_SIZE => 2 * 1024 * 1024, Constant::OPTION_PACKAGE_MAX_LENGTH => 50 * 1024 * 1024, - 'document_root' => BASE_PATH . '/static', - 'enable_static_handler' => true, - 'http_index_files' => ['index.html'], + Constant::OPTION_DOCUMENT_ROOT => BASE_PATH . '/static', + Constant::OPTION_ENABLE_STATIC_HANDLER => true, + Constant::OPTION_HTTP_INDEX_FILES => ['index.html'], ], 'callbacks' => [ Event::ON_BEFORE_START => [Hyperf\Framework\Bootstrap\ServerStartCallback::class, 'beforeStart'],