|
@@ -6,6 +6,7 @@ use App\Enums\Common\Code; |
|
@@ -6,6 +6,7 @@ use App\Enums\Common\Code; |
|
6
|
use App\Http\Controllers\Controller;
|
6
|
use App\Http\Controllers\Controller;
|
|
7
|
use App\Http\Controllers\type;
|
7
|
use App\Http\Controllers\type;
|
|
8
|
use App\Models\File\Image as ImageModel;
|
8
|
use App\Models\File\Image as ImageModel;
|
|
|
|
9
|
+use App\Models\Project\Project;
|
|
9
|
use App\Services\CosService;
|
10
|
use App\Services\CosService;
|
|
10
|
use App\Services\TencentCosService;
|
11
|
use App\Services\TencentCosService;
|
|
11
|
use Illuminate\Http\Exceptions\HttpResponseException;
|
12
|
use Illuminate\Http\Exceptions\HttpResponseException;
|
|
@@ -27,8 +28,6 @@ class ImageController extends Controller |
|
@@ -27,8 +28,6 @@ class ImageController extends Controller |
|
27
|
'Content-Description' => 'File Transfer',
|
28
|
'Content-Description' => 'File Transfer',
|
|
28
|
],
|
29
|
],
|
|
29
|
];
|
30
|
];
|
|
30
|
- const TYPE = 1;
|
|
|
|
31
|
-
|
|
|
|
32
|
public $path = '';//路径
|
31
|
public $path = '';//路径
|
|
33
|
|
32
|
|
|
34
|
public $config = '';//存储默认配置
|
33
|
public $config = '';//存储默认配置
|
|
@@ -41,6 +40,7 @@ class ImageController extends Controller |
|
@@ -41,6 +40,7 @@ class ImageController extends Controller |
|
41
|
|
40
|
|
|
42
|
public $cache = '';//缓存数据
|
41
|
public $cache = '';//缓存数据
|
|
43
|
|
42
|
|
|
|
|
43
|
+ public $upload_location = 1;
|
|
44
|
public $image_type = [
|
44
|
public $image_type = [
|
|
45
|
1 => 'image_product',
|
45
|
1 => 'image_product',
|
|
46
|
2 => 'image_news',
|
46
|
2 => 'image_news',
|
|
@@ -127,7 +127,7 @@ class ImageController extends Controller |
|
@@ -127,7 +127,7 @@ class ImageController extends Controller |
|
127
|
$this->setUrl();
|
127
|
$this->setUrl();
|
|
128
|
if ($type == 'multi') {
|
128
|
if ($type == 'multi') {
|
|
129
|
return $this->multi($files);
|
129
|
return $this->multi($files);
|
|
130
|
- } else {
|
130
|
+ }else{
|
|
131
|
return $this->single($files);
|
131
|
return $this->single($files);
|
|
132
|
}
|
132
|
}
|
|
133
|
}
|
133
|
}
|
|
@@ -166,8 +166,11 @@ class ImageController extends Controller |
|
@@ -166,8 +166,11 @@ class ImageController extends Controller |
|
166
|
if ($rs === false) {
|
166
|
if ($rs === false) {
|
|
167
|
return $this->response('添加失败', Code::USER_ERROR);
|
167
|
return $this->response('添加失败', Code::USER_ERROR);
|
|
168
|
}
|
168
|
}
|
|
|
|
169
|
+ //同步数据到cos
|
|
|
|
170
|
+ if($this->upload_location == 1){
|
|
169
|
$cosService = new CosService();
|
171
|
$cosService = new CosService();
|
|
170
|
$cosService->uploadFile($this->path,$fileName);
|
172
|
$cosService->uploadFile($this->path,$fileName);
|
|
|
|
173
|
+ }
|
|
171
|
return $this->response('图片资源',Code::SUCCESS,['image'=>$hash]);
|
174
|
return $this->response('图片资源',Code::SUCCESS,['image'=>$hash]);
|
|
172
|
}
|
175
|
}
|
|
173
|
|
176
|
|
|
@@ -226,6 +229,11 @@ class ImageController extends Controller |
|
@@ -226,6 +229,11 @@ class ImageController extends Controller |
|
226
|
'refer'=>$this->param['refer'] ?? '',
|
229
|
'refer'=>$this->param['refer'] ?? '',
|
|
227
|
];
|
230
|
];
|
|
228
|
$data[] = ['image'=>$hash];
|
231
|
$data[] = ['image'=>$hash];
|
|
|
|
232
|
+ //同步数据到cos
|
|
|
|
233
|
+ if($this->upload_location == 1){
|
|
|
|
234
|
+ $cosService = new CosService();
|
|
|
|
235
|
+ $cosService->uploadFile($this->path,$fileName);
|
|
|
|
236
|
+ }
|
|
229
|
}
|
237
|
}
|
|
230
|
$imageModel->insert($save_data);
|
238
|
$imageModel->insert($save_data);
|
|
231
|
return $this->response('图片资源',Code::SUCCESS,$data);
|
239
|
return $this->response('图片资源',Code::SUCCESS,$data);
|
|
@@ -318,6 +326,11 @@ class ImageController extends Controller |
|
@@ -318,6 +326,11 @@ class ImageController extends Controller |
|
318
|
if(isset($this->param['refer_type']) && $this->param['refer_type'] == 1){
|
326
|
if(isset($this->param['refer_type']) && $this->param['refer_type'] == 1){
|
|
319
|
$this->path = $this->uploads['path_a'].'/'.$this->image_type[$this->param['refer']].'/'.date('Y-m');
|
327
|
$this->path = $this->uploads['path_a'].'/'.$this->image_type[$this->param['refer']].'/'.date('Y-m');
|
|
320
|
}else{
|
328
|
}else{
|
|
|
|
329
|
+ $projectModel = new Project();
|
|
|
|
330
|
+ $project_info = $projectModel->read(['id'=>$this->cache['project_id']],['upload_location']);
|
|
|
|
331
|
+ if($project_info['upload_location'] != 1){
|
|
|
|
332
|
+ $this->upload_location = 0;
|
|
|
|
333
|
+ }
|
|
321
|
$this->path = $this->uploads['path_b'].'/'.$this->cache['project_id'].'/'.$this->image_type[$this->param['refer']].'/'.date('Y-m');
|
334
|
$this->path = $this->uploads['path_b'].'/'.$this->cache['project_id'].'/'.$this->image_type[$this->param['refer']].'/'.date('Y-m');
|
|
322
|
}
|
335
|
}
|
|
323
|
}
|
336
|
}
|