|
...
|
...
|
@@ -41,6 +41,7 @@ class ImageController extends Controller |
|
|
|
public $cache = '';//缓存数据
|
|
|
|
|
|
|
|
public $upload_location = 0;//是否同步到cos
|
|
|
|
//上传图片类型
|
|
|
|
public $image_type = [
|
|
|
|
1 => 'image_product',
|
|
|
|
2 => 'image_news',
|
|
...
|
...
|
@@ -157,15 +158,15 @@ class ImageController extends Controller |
|
|
|
return $this->response('图片资源',Code::SUCCESS,['image'=>$hash]);
|
|
|
|
}
|
|
|
|
$url = $this->config['root'].$this->path;
|
|
|
|
$fileName = uniqid().rand(10000,99999).'.'.$files->getClientOriginalExtension();
|
|
|
|
//同步数据到cos
|
|
|
|
$fileName = uniqid().rand(10000,99999).'.'.$image_type;
|
|
|
|
//上传到cos
|
|
|
|
if($this->upload_location == 1){
|
|
|
|
$cosService = new CosService();
|
|
|
|
$is_cos = 1;//上传到cos
|
|
|
|
$cosService->uploadFile($files,$this->path,$fileName);
|
|
|
|
}else{
|
|
|
|
$res = $files->move($url,$fileName);
|
|
|
|
$is_cos = 0;//上传到cos
|
|
|
|
$is_cos = 0;
|
|
|
|
if ($res === false) {
|
|
|
|
return $this->response($files->getError(), Code::USER_ERROR);
|
|
|
|
}
|
|
...
|
...
|
@@ -223,7 +224,7 @@ class ImageController extends Controller |
|
|
|
* @time :2023/6/17 16:31
|
|
|
|
*/
|
|
|
|
private function multi(&$files) {
|
|
|
|
$save_data = [];
|
|
|
|
$save_data = [];//保存数据
|
|
|
|
$data = [];
|
|
|
|
foreach ($files as $file) {
|
|
|
|
$size = $file->getSize();
|
|
...
|
...
|
@@ -243,21 +244,14 @@ class ImageController extends Controller |
|
|
|
$is_cos = 1;//上传到cos
|
|
|
|
$cosService->uploadFile($file,$this->path,$fileName);
|
|
|
|
}else{
|
|
|
|
$is_cos = 0;
|
|
|
|
$res = $file->move($url,$fileName);
|
|
|
|
if ($res === false) {
|
|
|
|
return $this->response($file->getError(), Code::USER_ERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$save_data[] = [
|
|
|
|
'path' => $this->path.'/'.$fileName,
|
|
|
|
'created_at' => date('Y-m-d H:i:s',time()),
|
|
|
|
'updated_at'=>date('Y-m-d H:i:s',time()),
|
|
|
|
'size' => $size,
|
|
|
|
'hash' => $hash,
|
|
|
|
'type'=>$image_type,
|
|
|
|
'refer'=>$this->param['refer'] ?? 0,
|
|
|
|
'is_cos'=>$is_cos ?? 0
|
|
|
|
];
|
|
|
|
//批量存储
|
|
|
|
$save_data = $this->saveMysqlAll($save_data,$fileName,$size,$hash,$image_type,$is_cos);
|
|
|
|
$data[] = ['image'=>$hash];
|
|
|
|
}
|
|
|
|
$imageModel->insert($save_data);
|
|
...
|
...
|
@@ -265,6 +259,31 @@ class ImageController extends Controller |
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $save_data
|
|
|
|
* @param $fileName
|
|
|
|
* @param $size
|
|
|
|
* @param $hash
|
|
|
|
* @param $image_type
|
|
|
|
* @remark :批量拼接数据
|
|
|
|
* @name :saveMysqlAll
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/7/20 9:26
|
|
|
|
*/
|
|
|
|
public function saveMysqlAll(&$save_data,$fileName,$size,$hash,$image_type,$is_cos){
|
|
|
|
$save_data[] = [
|
|
|
|
'path' => $this->path.'/'.$fileName,
|
|
|
|
'created_at' => date('Y-m-d H:i:s',time()),
|
|
|
|
'updated_at'=>date('Y-m-d H:i:s',time()),
|
|
|
|
'size' => $size,
|
|
|
|
'hash' => $hash,
|
|
|
|
'type'=>$image_type,
|
|
|
|
'refer'=>$this->param['refer'] ?? 0,
|
|
|
|
'is_cos'=>$is_cos ?? 0
|
|
|
|
];
|
|
|
|
return $save_data;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @param $filename
|
|
|
|
* @remark :下载
|
|
|
|
* @name :download
|
...
|
...
|
|