作者 lyh

gx

... ... @@ -7,7 +7,9 @@ use App\Helper\Common;
use App\Http\Controllers\Controller;
use App\Http\Logic\Aside\Project\ProjectLogic;
use App\Http\Requests\Scene;
use App\Models\File\Image;
use App\Models\User\User as UserModel;
use App\Services\CosService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Exceptions\HttpResponseException;
... ... @@ -155,24 +157,6 @@ class BaseController extends Controller
}
//获取操作人
switch ((string) $k) {
case 'image':
$data['image_link'] = url('/b/image/' . $v);
break;
case 'images':
$v = explode(',',$v);
foreach ($v as $k1=>$v1){
$data['images_link'][$k1] = url('/b/image/' . $v1);
}
break;
case 'file':
$data['file_link'] = url('/b/file_hash/' . $v);
break;
case 'video':
$v = explode(',',$v);
foreach ($v as $k1=>$v1){
$data['file_link'][$k1] = url('/b/file_hash/' . $v1);
}
break;
case 'operator_id':
if(!empty($v)){
$name = (new UserModel())->read(['id'=>$v],['id','name']);
... ... @@ -228,6 +212,13 @@ class BaseController extends Controller
return false;
}
/**
* @remark :获取域名
* @name :getProjectDomain
* @author :lyh
* @method :post
* @time :2023/7/20 16:45
*/
public function getProjectDomain(){
$project = (new ProjectLogic())->getInfo($this->user['project_id']);
if(!empty($project['deploy_optimize']['domain'])){
... ... @@ -238,4 +229,24 @@ class BaseController extends Controller
}
return '';
}
/**
* @remark :获取图片链接
* @name :getImageUrl
* @author :lyh
* @method :post
* @time :2023/7/20 16:46
*/
public function getImageUrl($hash){
$imageModel = new Image();
$info = $imageModel->read(['hash'=>$hash]);
$url = '';
if($info['is_cos'] == 1){
$cos = new CosService();
$url = $cos->getImageUrl($info['path']);
}else{
$url = url('b/image/'.$info['hash']);
}
return $url;
}
}
... ...
... ... @@ -34,6 +34,7 @@ class BlogController extends BaseController
$v = $blogLabelLogic->get_label_name($v);
$v['route'] = RouteMap::getRoute(RouteMap::SOURCE_BLOG, $v['id'], $this->user['project_id']);
$v['url'] = $this->getProjectDomain() . $v['route'];
$v['image_link'] = $this->getImageUrl($v['image']);
$lists['list'][$k] = $v;
}
}
... ... @@ -77,6 +78,7 @@ class BlogController extends BaseController
$info = $blogLogic->blog_info();
$info['route'] = RouteMap::getRoute(RouteMap::SOURCE_BLOG, $info['id'], $this->user['project_id']);
$info['url'] = $this->getProjectDomain() . $info['route'];
$info['image_link'] = $this->getImageUrl($info['image']);
$this->response('success',Code::SUCCESS,$info);
}
... ...
... ... @@ -32,6 +32,7 @@ class NewsController extends BaseController
$v = $newsCategoryLogic->get_category_name($v);
$v['route'] = RouteMap::getRoute(RouteMap::SOURCE_NEWS, $v['id'], $this->user['project_id']);
$v['url'] = $this->getProjectDomain() . $v['route'];
$v['image_link'] = $this->getImageUrl($v['image']);
$lists['list'][$k] = $v;
}
}
... ... @@ -74,6 +75,7 @@ class NewsController extends BaseController
$info = $newsLogic->news_info();
$info['route'] = RouteMap::getRoute(RouteMap::SOURCE_NEWS, $info['id'], $this->user['project_id']);
$info['url'] = $this->getProjectDomain() . $info['route'];
$info['image_link'] = $this->getImageUrl($info['image']);
$this->response('success',Code::SUCCESS,$info);
}
/**
... ...
... ... @@ -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');
}
}
... ...
... ... @@ -65,14 +65,12 @@ class AyrReleaseLogic extends BaseLogic
$imageModel = new Image();
$list = $imageModel->list(['hash'=>['in',$images]],'id');
foreach ($list as $v1){
$filename = basename($v1['path']);
$arr[] = url('/upload/images/'.$filename);
$arr[] = url('/upload'.$v1['path']);
}
}else{
$fileModel = new File();
$info = $fileModel->read(['hash'=>$v]);
$filename = basename($info['path']);
$arr[] = url('/upload/files/'.$filename);
$arr[] = url('/upload'.$info['path']);
}
}
return $this->success($arr);
... ...