|
...
|
...
|
@@ -165,7 +165,7 @@ class ImageController extends Controller |
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->saveMysql($imageModel,$size,$image_type,$fileName,$hash,$this->upload_location);
|
|
|
|
return $this->response('图片资源',Code::SUCCESS,['image'=>$hash]);
|
|
|
|
return $this->response('图片资源',Code::SUCCESS,['image'=>$hash,'image_link'=>$this->getImageUrl($hash)]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
...
|
...
|
@@ -217,7 +217,6 @@ class ImageController extends Controller |
|
|
|
* @time :2023/6/17 16:31
|
|
|
|
*/
|
|
|
|
private function multi(&$files) {
|
|
|
|
$save_data = [];//保存数据
|
|
|
|
$data = [];
|
|
|
|
foreach ($files as $file) {
|
|
|
|
$size = $file->getSize();
|
|
...
|
...
|
@@ -226,7 +225,7 @@ class ImageController extends Controller |
|
|
|
$hash = hash_file('md5', $file->getPathname());
|
|
|
|
$image_hash = $imageModel->read(['hash'=>$hash]);
|
|
|
|
if($image_hash !== false){
|
|
|
|
$data[] = ['image'=>$hash];
|
|
|
|
$data[] = ['image'=>$hash,'image_link'=>$this->getImageUrl($hash)];
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$url = $this->config['root'].$this->path;
|
|
...
|
...
|
@@ -243,7 +242,7 @@ class ImageController extends Controller |
|
|
|
}
|
|
|
|
//批量存储
|
|
|
|
$this->saveMysql($imageModel,$size,$image_type,$fileName,$hash,$this->upload_location);
|
|
|
|
$data[] = ['image'=>$hash];
|
|
|
|
$data[] = ['image'=>$hash,'image_link'=>$this->getImageUrl($hash)];
|
|
|
|
}
|
|
|
|
return $this->response('图片资源',Code::SUCCESS,$data);
|
|
|
|
}
|
|
...
|
...
|
@@ -279,48 +278,13 @@ class ImageController extends Controller |
|
|
|
$result = [
|
|
|
|
'msg' => $msg == ' ' ? $code->description : $msg,
|
|
|
|
'code' => $code->value,
|
|
|
|
'data' => $this->_extents($data),
|
|
|
|
'data' => $data,
|
|
|
|
];
|
|
|
|
$this->header['Content-Type'] = $type;
|
|
|
|
$response = response($result,$result_code,$this->header);
|
|
|
|
throw new HttpResponseException($response);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $data
|
|
|
|
* @name :返回参数处理
|
|
|
|
* @return array|string
|
|
|
|
* @author :liyuhang
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
protected function _extents($data) {
|
|
|
|
if (empty($data) || !is_array($data)) {
|
|
|
|
return empty($data) ? is_array($data) ? [] : '' : $data;
|
|
|
|
}
|
|
|
|
foreach ($data as $k => $v) {
|
|
|
|
if (is_array($v)) {
|
|
|
|
$data[$k] = $this->_extents($v);
|
|
|
|
} else {
|
|
|
|
if (is_null($v)) {
|
|
|
|
$data[$k] = '';
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
//获取操作人
|
|
|
|
switch ((string) $k) {
|
|
|
|
case 'image':
|
|
|
|
$data['image_link'] = url('/b/image/' . $v);
|
|
|
|
break;
|
|
|
|
case 'hash':
|
|
|
|
$data['image_link'] = url('/b/image/' . $v);
|
|
|
|
break;
|
|
|
|
case 'path':
|
|
|
|
$data['path_link'] = url('/upload/images/' . basename($v));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :获取所有图片
|
|
...
|
...
|
@@ -332,6 +296,9 @@ class ImageController extends Controller |
|
|
|
public function getImageList(){
|
|
|
|
$imageModel = new ImageModel();
|
|
|
|
$lists = $imageModel->list([],$order = 'id',['id','hash','type','path','created_at']);
|
|
|
|
foreach ($lists as $k => $v){
|
|
|
|
$v['image_link'] = $this->getImageUrl($v['image']);
|
|
|
|
}
|
|
|
|
$this->response('success',Code::SUCCESS,$lists);
|
|
|
|
}
|
|
|
|
|
|
...
|
...
|
@@ -348,7 +315,7 @@ class ImageController extends Controller |
|
|
|
$this->path = $this->uploads['path_a'].'/'.$this->image_type[$this->param['refer']].'/'.date('Y-m');
|
|
|
|
}else{
|
|
|
|
//B端上传
|
|
|
|
if(!isset($this->param['upload_method']) && $this->param['upload_method'] == 1){
|
|
|
|
if(isset($this->param['upload_method']) && $this->param['upload_method'] == 1){
|
|
|
|
//强制上传本地配置
|
|
|
|
$this->upload_location = 0;
|
|
|
|
}else{
|
|
...
|
...
|
@@ -361,4 +328,22 @@ class ImageController extends Controller |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :获取图片链接
|
|
|
|
* @name :getImageUrl
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/7/20 16:46
|
|
|
|
*/
|
|
|
|
public function getImageUrl($hash){
|
|
|
|
$imageModel = new ImageModel();
|
|
|
|
$info = $imageModel->read(['hash'=>$hash]);
|
|
|
|
if($info['is_cos'] == 1){
|
|
|
|
$cos = new CosService();
|
|
|
|
$url = $cos->getImageUrl($info['path']);
|
|
|
|
}else{
|
|
|
|
$url = url('b/image/'.$info['hash']);
|
|
|
|
}
|
|
|
|
return $url;
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|