|
...
|
...
|
@@ -78,11 +78,6 @@ class ImageController extends Controller |
|
|
|
if ($info === false) {
|
|
|
|
$this->response('指定图片不存在!', Code::USER_ERROR);
|
|
|
|
}
|
|
|
|
//获取cos链接
|
|
|
|
if($info['is_cos'] == 1){
|
|
|
|
$cos = new CosService();
|
|
|
|
return $cos->getImageUrl($info['path']);
|
|
|
|
}
|
|
|
|
//查看缩略图是否存在
|
|
|
|
$filename = $this->config['root'] . '/' .$info['path'] . '_' . $w . '_' . $h;
|
|
|
|
if(is_file($filename)){
|
|
...
|
...
|
@@ -127,8 +122,6 @@ class ImageController extends Controller |
|
|
|
'image.required'=>'图片必须填写',
|
|
|
|
]);
|
|
|
|
$files = $this->request->file('image');
|
|
|
|
$size = $files->getSize();
|
|
|
|
$image_type = $files->getClientOriginalExtension();
|
|
|
|
if (empty($files)) {
|
|
|
|
$this->response('没有上传的文件!', 400);
|
|
|
|
}
|
|
...
|
...
|
@@ -137,6 +130,8 @@ class ImageController extends Controller |
|
|
|
if ($type == 'multi') {
|
|
|
|
return $this->multi($files);
|
|
|
|
}else{
|
|
|
|
$size = $files->getSize();
|
|
|
|
$image_type = $files->getClientOriginalExtension();
|
|
|
|
return $this->single($files,$size,$image_type);
|
|
|
|
}
|
|
|
|
}
|
|
...
|
...
|
@@ -247,39 +242,13 @@ class ImageController extends Controller |
|
|
|
}
|
|
|
|
}
|
|
|
|
//批量存储
|
|
|
|
$save_data = $this->saveMysqlAll($save_data,$fileName,$size,$hash,$image_type,$this->upload_location);
|
|
|
|
$this->saveMysql($imageModel,$size,$image_type,$fileName,$hash,$this->upload_location);
|
|
|
|
$data[] = ['image'=>$hash];
|
|
|
|
}
|
|
|
|
$imageModel->insert($save_data);
|
|
|
|
return $this->response('图片资源',Code::SUCCESS,$data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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
|
|
...
|
...
|
@@ -374,15 +343,20 @@ class ImageController extends Controller |
|
|
|
* @time :2023/7/18 15:36
|
|
|
|
*/
|
|
|
|
public function setUrl(){
|
|
|
|
if(!isset($this->param['refer'])){
|
|
|
|
$this->param['refer'] = 1;
|
|
|
|
}
|
|
|
|
//A端上传
|
|
|
|
if(isset($this->param['refer_type']) && $this->param['refer_type'] == 1){
|
|
|
|
$this->path = $this->uploads['path_a'].'/'.$this->image_type[$this->param['refer']].'/'.date('Y-m');
|
|
|
|
}else{
|
|
|
|
$projectModel = new Project();
|
|
|
|
$project_info = $projectModel->read(['id'=>$this->cache['project_id']],['upload_location']);
|
|
|
|
$this->upload_location = $project_info['upload_location'];
|
|
|
|
//B端上传
|
|
|
|
if(!isset($this->param['upload_method']) && $this->param['upload_method'] == 1){
|
|
|
|
//强制上传本地配置
|
|
|
|
$this->upload_location = 0;
|
|
|
|
}else{
|
|
|
|
//根据项目上传标识区分上传到cos/本地
|
|
|
|
$projectModel = new Project();
|
|
|
|
$project_info = $projectModel->read(['id'=>$this->cache['project_id']],['upload_location']);
|
|
|
|
$this->upload_location = $project_info['upload_location'];
|
|
|
|
}
|
|
|
|
$this->path = $this->uploads['path_b'].'/'.$this->cache['project_id'].'/'.$this->image_type[$this->param['refer']].'/'.date('Y-m');
|
|
|
|
}
|
|
|
|
}
|
...
|
...
|
|