diff --git a/app/common/controller/UploadController.php b/app/common/controller/UploadController.php index a900b2d..6d89815 100644 --- a/app/common/controller/UploadController.php +++ b/app/common/controller/UploadController.php @@ -79,12 +79,15 @@ class UploadController return $this->error('上传失败'); } if (empty($scene)) { - return $this->error('上传场景不能为空'); +// return $this->error('上传场景不能为空'); + $sceneUrl = ''; + }else{ + $sceneUrl = $scene . '/'; } $originalName = $file->getUploadName(); $result = Storage::adapter('oss') - ->path('vehicle_album/' . $scene . '/' . date('Ymd')) + ->path('vehicle_album/' . $sceneUrl . date('Ymd')) ->size(1024*1024*5) ->upload($file); @@ -118,11 +121,14 @@ class UploadController return $this->error('上传失败'); } if (empty($scene)) { - return $this->error('上传场景不能为空'); +// return $this->error('上传场景不能为空'); + $sceneUrl = ''; + }else{ + $sceneUrl = $scene . '/'; } $result = Storage::adapter('oss') - ->path('vehicle_album/' . $scene . '/' . date('Ymd')) + ->path('vehicle_album/' . $sceneUrl . date('Ymd')) ->size(1024*1024*5) ->extYes(['image/jpeg','image/png']) ->extNo(['image/gif']) diff --git a/app/common/service/UploadService.php b/app/common/service/UploadService.php new file mode 100644 index 0000000..74193d5 --- /dev/null +++ b/app/common/service/UploadService.php @@ -0,0 +1,87 @@ +uploadImage($filePath, $objectKey); + $privateUrl = $ossService->generatePrivateUrl($objectKey); + + // 记录文件信息到数据库 + $uploadedFilesService = new UploadedFilesService(); + $fileInfo = [ + 'file_name' => $objectKey, + 'file_path' => $objectKey, + 'file_size' => $size, + 'file_type' => $mime, + 'original_name' => $originalName, + ]; + $recordResult = $uploadedFilesService->recordFileInfo($fileInfo, null, $scene, $category); + + $data = [ + 'original_name' => $originalName, + 'file_name' => $objectKey, + 'file_url' => $privateUrl, + 'file_id' => $recordResult['id'] ?? null, + 'partition' => $scene, + 'category' => $category, + ]; + + return $data; + } catch (\Throwable $e) { + Log::error($e->getMessage(),$param); + throw new BusinessException($e->getMessage()); + } + } +} \ No newline at end of file diff --git a/app/common/service/UploadedFilesService.php b/app/common/service/UploadedFilesService.php index 4fbab7c..1319ab3 100644 --- a/app/common/service/UploadedFilesService.php +++ b/app/common/service/UploadedFilesService.php @@ -52,13 +52,13 @@ class UploadedFilesService * 记录文件信息到数据库 * * @param array $fileInfo 文件信息 - * @param Request $request 请求对象 + * @param Request|null $request 请求对象(可选) * @param string $partition 分区名称 * @param string $category 文件分类 * @return array * @throws BusinessException */ - public function recordFileInfo(array $fileInfo, Request $request, string $partition = 'other', string $category = 'general'): array + public function recordFileInfo(array $fileInfo, ?Request $request = null, string $partition = 'other', string $category = 'general'): array { // 验证必需的文件信息 @@ -73,6 +73,9 @@ class UploadedFilesService $fileExtension = pathinfo($fileInfo['file_name'], PATHINFO_EXTENSION); // 记录到数据库 + $uploadIp = $request ? $request->getRealIp() : '0.0.0.0'; + $userAgent = $request ? $request->header('User-Agent', '') : ''; + $fileData = [ 'file_name' => $fileInfo['file_name'], 'file_path' => $fileInfo['file_path'], @@ -82,8 +85,8 @@ class UploadedFilesService 'original_name' => $fileInfo['original_name'] ?? '', 'extension' => $fileExtension, 'partition' => $partition, - 'upload_ip' => $request->getRealIp(), - 'user_agent' => $request->header('User-Agent', ''), + 'upload_ip' => $uploadIp, + 'user_agent' => $userAgent, ]; $uploadedFile = $this->logicCreate($fileData); diff --git a/app/queue/translation/config/trans.php b/app/common/utils/translation/config/trans.php similarity index 100% rename from app/queue/translation/config/trans.php rename to app/common/utils/translation/config/trans.php diff --git a/app/queue/translation/jobs/TranslationJob.php b/app/common/utils/translation/jobs/TranslationJob.php similarity index 87% rename from app/queue/translation/jobs/TranslationJob.php rename to app/common/utils/translation/jobs/TranslationJob.php index eb5e704..ca584e2 100644 --- a/app/queue/translation/jobs/TranslationJob.php +++ b/app/common/utils/translation/jobs/TranslationJob.php @@ -1,8 +1,8 @@ config = getConfig('/queue/translation/config/trans.php'); + $this->config = getConfig('/common/utils/translation/config/trans.php'); +// $this->config = getConfig('/queue/translation/config/trans.php'); $this->payload = $payload; } diff --git a/app/queue/translation/queue/Translation.php b/app/common/utils/translation/queue/Translation.php similarity index 93% rename from app/queue/translation/queue/Translation.php rename to app/common/utils/translation/queue/Translation.php index 0b5841a..e9935f6 100644 --- a/app/queue/translation/queue/Translation.php +++ b/app/common/utils/translation/queue/Translation.php @@ -1,10 +1,10 @@ config = getConfig('/queue/translation/config/trans.php'); + $this->config = getConfig('/common/utils/translation/config/trans.php'); +// $this->config = getConfig('/queue/translation/config/trans.php'); } /** @@ -23,8 +24,9 @@ class TranslationService * @param string $sourceLocale 源语种,如 'zh' * @param array $sourceFields 源语种字段 ['name'=>…,'condition_desc'=>…] * @param array $clientFields 前端已传翻译 ['en'=>[...], …] + * @param array $intactFields 不需要翻译的字段 */ - public function queueTranslations(string $entityType, int $entityId, string $sourceLocale, array $sourceFields, array $clientFields = []): void + public function queueTranslations(string $entityType, int $entityId, string $sourceLocale, array $sourceFields, array $clientFields = [], array $intactFields = []): void { foreach ($this->config['locales'] as $locale) { $payload = [ diff --git a/app/queue/translation/service/TranslatorClient.php b/app/common/utils/translation/service/TranslatorClient.php similarity index 95% rename from app/queue/translation/service/TranslatorClient.php rename to app/common/utils/translation/service/TranslatorClient.php index 3abc1df..ee227da 100644 --- a/app/queue/translation/service/TranslatorClient.php +++ b/app/common/utils/translation/service/TranslatorClient.php @@ -1,5 +1,5 @@