Merge branch 'feature/stock_next' into develop
This commit is contained in:
@@ -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'])
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\service;
|
||||
|
||||
use support\exception\BusinessException;
|
||||
use support\Log;
|
||||
use support\Request;
|
||||
|
||||
class UploadService
|
||||
{
|
||||
|
||||
/**
|
||||
* 从服务器本地路径上传文件到 OSS
|
||||
*
|
||||
* @param Request $request
|
||||
* - path: 本地文件绝对路径
|
||||
* - scene: 业务分区/场景(可选)
|
||||
* - category: 文件分类(可选)
|
||||
* - original_name: 原始文件名(可选)
|
||||
*/
|
||||
public function uploadLocalFile($param)
|
||||
{
|
||||
try {
|
||||
$filePath = $param['path'];
|
||||
$scene = $param['scene'];
|
||||
$category = $param['category']??'general';
|
||||
$providedOriginalName = $param['original_name'];
|
||||
|
||||
if (empty($filePath)) {
|
||||
Log::error('本地文件路径不能为空',$param);
|
||||
throw new BusinessException('本地文件路径不能为空');
|
||||
}
|
||||
|
||||
if (!file_exists($filePath) || !is_readable($filePath)) {
|
||||
Log::error('本地文件不存在或不可读',$param);
|
||||
throw new BusinessException('本地文件不存在或不可读');
|
||||
}
|
||||
if (empty($scene)) {
|
||||
Log::error('上传场景不能为空',$param);
|
||||
throw new BusinessException('上传场景不能为空');
|
||||
}
|
||||
|
||||
$basename = basename($filePath);
|
||||
$originalName = $providedOriginalName ?: $basename;
|
||||
$extensionFromName = pathinfo($originalName, PATHINFO_EXTENSION);
|
||||
$extensionFromPath = pathinfo($basename, PATHINFO_EXTENSION);
|
||||
$extension = $extensionFromName ?: $extensionFromPath;
|
||||
|
||||
$mime = mime_content_type($filePath) ?: 'application/octet-stream';
|
||||
$size = filesize($filePath) ?: 0;
|
||||
|
||||
$sceneUrl = $scene ? ($scene . '/') : '';
|
||||
$dir = 'vehicle_album/' . $sceneUrl . date('Ymd') . '/';
|
||||
$uniqueName = md5($originalName . microtime(true));
|
||||
$objectKey = $dir . $uniqueName . ($extension ? ('.' . $extension) : '');
|
||||
|
||||
$ossService = new OssService();
|
||||
$ossService->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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
+4
-3
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
namespace app\queue\translation\jobs;
|
||||
namespace app\common\utils\translation\jobs;
|
||||
|
||||
use support\Log;
|
||||
use app\queue\translation\service\TranslatorClient;
|
||||
use app\common\utils\translation\service\TranslatorClient;
|
||||
|
||||
class TranslationJob
|
||||
{
|
||||
@@ -11,7 +11,8 @@ class TranslationJob
|
||||
|
||||
public function __construct(array $payload)
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace app\queue\translation\queue;
|
||||
namespace app\common\utils\translation\queue;
|
||||
|
||||
use support\Log;
|
||||
use Webman\RedisQueue\Consumer;
|
||||
use app\queue\translation\jobs\TranslationJob;
|
||||
use app\common\utils\translation\jobs\TranslationJob;
|
||||
|
||||
class Translation implements Consumer
|
||||
{
|
||||
+5
-3
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace app\queue\translation\service;
|
||||
namespace app\common\utils\translation\service;
|
||||
|
||||
// use Webman\RedisQueue\Client;
|
||||
use Webman\RedisQueue\Redis;
|
||||
@@ -12,7 +12,8 @@ class TranslationService
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->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 = [
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace app\queue\translation\service;
|
||||
namespace app\common\utils\translation\service;
|
||||
|
||||
use app\queue\utils\XunfeiFanyi;
|
||||
use support\Log;
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace app\ticket\service;
|
||||
|
||||
use app\queue\translation\service\TranslationService;
|
||||
use app\common\utils\translation\service\TranslationService;
|
||||
use app\queue\utils\Translat;
|
||||
use app\ticket\logic\CategorieLogic;
|
||||
use app\ticket\model\CategorieTranslation;
|
||||
|
||||
Reference in New Issue
Block a user