|
@@ -3,8 +3,10 @@ |
|
@@ -3,8 +3,10 @@ |
|
3
|
namespace App\Http\Controllers\File;
|
3
|
namespace App\Http\Controllers\File;
|
|
4
|
|
4
|
|
|
5
|
use App\Enums\Common\Code;
|
5
|
use App\Enums\Common\Code;
|
|
|
|
6
|
+use App\Helper\Translate;
|
|
6
|
use App\Models\File\ErrorFile;
|
7
|
use App\Models\File\ErrorFile;
|
|
7
|
use App\Models\File\File;
|
8
|
use App\Models\File\File;
|
|
|
|
9
|
+use App\Models\File\Image as ImageModel;
|
|
8
|
use App\Models\Project\Project;
|
10
|
use App\Models\Project\Project;
|
|
9
|
use App\Services\AmazonS3Service;
|
11
|
use App\Services\AmazonS3Service;
|
|
10
|
use App\Services\CosService;
|
12
|
use App\Services\CosService;
|
|
@@ -120,7 +122,7 @@ class FileController |
|
@@ -120,7 +122,7 @@ class FileController |
|
120
|
if($file_hash !== false){
|
122
|
if($file_hash !== false){
|
|
121
|
return $this->response('资源',Code::SUCCESS,$this->responseData($file_hash['path'], $name));
|
123
|
return $this->response('资源',Code::SUCCESS,$this->responseData($file_hash['path'], $name));
|
|
122
|
}
|
124
|
}
|
|
123
|
- $fileName = uniqid().rand(10000,99999).'.'.$files->getClientOriginalExtension();
|
125
|
+ $fileName = $this->getOnlyFilename($name,$param['project_id'] ?? 0);
|
|
124
|
//同步数据到cos
|
126
|
//同步数据到cos
|
|
125
|
if($this->upload_location == 0){
|
127
|
if($this->upload_location == 0){
|
|
126
|
$cosService = new CosService();
|
128
|
$cosService = new CosService();
|
|
@@ -155,6 +157,40 @@ class FileController |
|
@@ -155,6 +157,40 @@ class FileController |
|
155
|
}
|
157
|
}
|
|
156
|
|
158
|
|
|
157
|
/**
|
159
|
/**
|
|
|
|
160
|
+ * @remark :获取唯一名称
|
|
|
|
161
|
+ * @name :getOnlyFilename
|
|
|
|
162
|
+ * @author :lyh
|
|
|
|
163
|
+ * @method :post
|
|
|
|
164
|
+ * @time :2024/4/26 16:10
|
|
|
|
165
|
+ */
|
|
|
|
166
|
+ public function getOnlyFilename($name,$project_id = 0){
|
|
|
|
167
|
+ $nameArr = explode('.',$name);
|
|
|
|
168
|
+ $enName = generateRoute(Translate::tran($nameArr[0], 'en'));
|
|
|
|
169
|
+ $i=1;
|
|
|
|
170
|
+ while($this->onlyName($enName.'.'.$nameArr[1],$project_id)){
|
|
|
|
171
|
+ $enName = $enName .'-'.$i;
|
|
|
|
172
|
+ $i++;
|
|
|
|
173
|
+ }
|
|
|
|
174
|
+ return $enName.'.'.$nameArr[1];
|
|
|
|
175
|
+ }
|
|
|
|
176
|
+
|
|
|
|
177
|
+ /**
|
|
|
|
178
|
+ * @remark :唯一名称
|
|
|
|
179
|
+ * @name :onlyName
|
|
|
|
180
|
+ * @author :lyh
|
|
|
|
181
|
+ * @method :post
|
|
|
|
182
|
+ * @time :2024/4/26 16:21
|
|
|
|
183
|
+ */
|
|
|
|
184
|
+ public function onlyName($enName,$project_id){
|
|
|
|
185
|
+ $fileModel = new File();
|
|
|
|
186
|
+ $info = $fileModel->read(['project_id' => $project_id, 'en_name' => $enName]);
|
|
|
|
187
|
+ if($info !== false){
|
|
|
|
188
|
+ return true;
|
|
|
|
189
|
+ }
|
|
|
|
190
|
+ return false;
|
|
|
|
191
|
+ }
|
|
|
|
192
|
+
|
|
|
|
193
|
+ /**
|
|
158
|
* 接口上传单文件
|
194
|
* 接口上传单文件
|
|
159
|
* @param $files
|
195
|
* @param $files
|
|
160
|
* @return array
|
196
|
* @return array
|
|
@@ -254,7 +290,7 @@ class FileController |
|
@@ -254,7 +290,7 @@ class FileController |
|
254
|
}
|
290
|
}
|
|
255
|
$url = $this->config['root'].'/'.$this->path;
|
291
|
$url = $this->config['root'].'/'.$this->path;
|
|
256
|
$file_type = $file->getClientOriginalExtension();
|
292
|
$file_type = $file->getClientOriginalExtension();
|
|
257
|
- $fileName = uniqid().rand(10000,99999).'.'.$file_type;
|
293
|
+ $fileName = $this->getOnlyFilename($name,$param['project_id'] ?? 0);
|
|
258
|
//同步数据到cos
|
294
|
//同步数据到cos
|
|
259
|
if($this->upload_location == 0){
|
295
|
if($this->upload_location == 0){
|
|
260
|
$cosService = new CosService();
|
296
|
$cosService = new CosService();
|