|
@@ -41,6 +41,7 @@ class ImageController extends Controller |
|
@@ -41,6 +41,7 @@ class ImageController extends Controller |
|
41
|
public $cache = '';//缓存数据
|
41
|
public $cache = '';//缓存数据
|
|
42
|
|
42
|
|
|
43
|
public $upload_location = 0;//是否同步到cos
|
43
|
public $upload_location = 0;//是否同步到cos
|
|
|
|
44
|
+ //上传图片类型
|
|
44
|
public $image_type = [
|
45
|
public $image_type = [
|
|
45
|
1 => 'image_product',
|
46
|
1 => 'image_product',
|
|
46
|
2 => 'image_news',
|
47
|
2 => 'image_news',
|
|
@@ -157,15 +158,15 @@ class ImageController extends Controller |
|
@@ -157,15 +158,15 @@ class ImageController extends Controller |
|
157
|
return $this->response('图片资源',Code::SUCCESS,['image'=>$hash]);
|
158
|
return $this->response('图片资源',Code::SUCCESS,['image'=>$hash]);
|
|
158
|
}
|
159
|
}
|
|
159
|
$url = $this->config['root'].$this->path;
|
160
|
$url = $this->config['root'].$this->path;
|
|
160
|
- $fileName = uniqid().rand(10000,99999).'.'.$files->getClientOriginalExtension();
|
|
|
|
161
|
- //同步数据到cos
|
161
|
+ $fileName = uniqid().rand(10000,99999).'.'.$image_type;
|
|
|
|
162
|
+ //上传到cos
|
|
162
|
if($this->upload_location == 1){
|
163
|
if($this->upload_location == 1){
|
|
163
|
$cosService = new CosService();
|
164
|
$cosService = new CosService();
|
|
164
|
$is_cos = 1;//上传到cos
|
165
|
$is_cos = 1;//上传到cos
|
|
165
|
$cosService->uploadFile($files,$this->path,$fileName);
|
166
|
$cosService->uploadFile($files,$this->path,$fileName);
|
|
166
|
}else{
|
167
|
}else{
|
|
167
|
$res = $files->move($url,$fileName);
|
168
|
$res = $files->move($url,$fileName);
|
|
168
|
- $is_cos = 0;//上传到cos
|
169
|
+ $is_cos = 0;
|
|
169
|
if ($res === false) {
|
170
|
if ($res === false) {
|
|
170
|
return $this->response($files->getError(), Code::USER_ERROR);
|
171
|
return $this->response($files->getError(), Code::USER_ERROR);
|
|
171
|
}
|
172
|
}
|
|
@@ -223,7 +224,7 @@ class ImageController extends Controller |
|
@@ -223,7 +224,7 @@ class ImageController extends Controller |
|
223
|
* @time :2023/6/17 16:31
|
224
|
* @time :2023/6/17 16:31
|
|
224
|
*/
|
225
|
*/
|
|
225
|
private function multi(&$files) {
|
226
|
private function multi(&$files) {
|
|
226
|
- $save_data = [];
|
227
|
+ $save_data = [];//保存数据
|
|
227
|
$data = [];
|
228
|
$data = [];
|
|
228
|
foreach ($files as $file) {
|
229
|
foreach ($files as $file) {
|
|
229
|
$size = $file->getSize();
|
230
|
$size = $file->getSize();
|
|
@@ -243,21 +244,14 @@ class ImageController extends Controller |
|
@@ -243,21 +244,14 @@ class ImageController extends Controller |
|
243
|
$is_cos = 1;//上传到cos
|
244
|
$is_cos = 1;//上传到cos
|
|
244
|
$cosService->uploadFile($file,$this->path,$fileName);
|
245
|
$cosService->uploadFile($file,$this->path,$fileName);
|
|
245
|
}else{
|
246
|
}else{
|
|
|
|
247
|
+ $is_cos = 0;
|
|
246
|
$res = $file->move($url,$fileName);
|
248
|
$res = $file->move($url,$fileName);
|
|
247
|
if ($res === false) {
|
249
|
if ($res === false) {
|
|
248
|
return $this->response($file->getError(), Code::USER_ERROR);
|
250
|
return $this->response($file->getError(), Code::USER_ERROR);
|
|
249
|
}
|
251
|
}
|
|
250
|
}
|
252
|
}
|
|
251
|
- $save_data[] = [
|
|
|
|
252
|
- 'path' => $this->path.'/'.$fileName,
|
|
|
|
253
|
- 'created_at' => date('Y-m-d H:i:s',time()),
|
|
|
|
254
|
- 'updated_at'=>date('Y-m-d H:i:s',time()),
|
|
|
|
255
|
- 'size' => $size,
|
|
|
|
256
|
- 'hash' => $hash,
|
|
|
|
257
|
- 'type'=>$image_type,
|
|
|
|
258
|
- 'refer'=>$this->param['refer'] ?? 0,
|
|
|
|
259
|
- 'is_cos'=>$is_cos ?? 0
|
|
|
|
260
|
- ];
|
253
|
+ //批量存储
|
|
|
|
254
|
+ $save_data = $this->saveMysqlAll($save_data,$fileName,$size,$hash,$image_type,$is_cos);
|
|
261
|
$data[] = ['image'=>$hash];
|
255
|
$data[] = ['image'=>$hash];
|
|
262
|
}
|
256
|
}
|
|
263
|
$imageModel->insert($save_data);
|
257
|
$imageModel->insert($save_data);
|
|
@@ -265,6 +259,31 @@ class ImageController extends Controller |
|
@@ -265,6 +259,31 @@ class ImageController extends Controller |
|
265
|
}
|
259
|
}
|
|
266
|
|
260
|
|
|
267
|
/**
|
261
|
/**
|
|
|
|
262
|
+ * @param $save_data
|
|
|
|
263
|
+ * @param $fileName
|
|
|
|
264
|
+ * @param $size
|
|
|
|
265
|
+ * @param $hash
|
|
|
|
266
|
+ * @param $image_type
|
|
|
|
267
|
+ * @remark :批量拼接数据
|
|
|
|
268
|
+ * @name :saveMysqlAll
|
|
|
|
269
|
+ * @author :lyh
|
|
|
|
270
|
+ * @method :post
|
|
|
|
271
|
+ * @time :2023/7/20 9:26
|
|
|
|
272
|
+ */
|
|
|
|
273
|
+ public function saveMysqlAll(&$save_data,$fileName,$size,$hash,$image_type,$is_cos){
|
|
|
|
274
|
+ $save_data[] = [
|
|
|
|
275
|
+ 'path' => $this->path.'/'.$fileName,
|
|
|
|
276
|
+ 'created_at' => date('Y-m-d H:i:s',time()),
|
|
|
|
277
|
+ 'updated_at'=>date('Y-m-d H:i:s',time()),
|
|
|
|
278
|
+ 'size' => $size,
|
|
|
|
279
|
+ 'hash' => $hash,
|
|
|
|
280
|
+ 'type'=>$image_type,
|
|
|
|
281
|
+ 'refer'=>$this->param['refer'] ?? 0,
|
|
|
|
282
|
+ 'is_cos'=>$is_cos ?? 0
|
|
|
|
283
|
+ ];
|
|
|
|
284
|
+ return $save_data;
|
|
|
|
285
|
+ }
|
|
|
|
286
|
+ /**
|
|
268
|
* @param $filename
|
287
|
* @param $filename
|
|
269
|
* @remark :下载
|
288
|
* @remark :下载
|
|
270
|
* @name :download
|
289
|
* @name :download
|