正在显示
5 个修改的文件
包含
46 行增加
和
59 行删除
| @@ -7,7 +7,9 @@ use App\Helper\Common; | @@ -7,7 +7,9 @@ use App\Helper\Common; | ||
| 7 | use App\Http\Controllers\Controller; | 7 | use App\Http\Controllers\Controller; |
| 8 | use App\Http\Logic\Aside\Project\ProjectLogic; | 8 | use App\Http\Logic\Aside\Project\ProjectLogic; |
| 9 | use App\Http\Requests\Scene; | 9 | use App\Http\Requests\Scene; |
| 10 | +use App\Models\File\Image; | ||
| 10 | use App\Models\User\User as UserModel; | 11 | use App\Models\User\User as UserModel; |
| 12 | +use App\Services\CosService; | ||
| 11 | use Illuminate\Http\JsonResponse; | 13 | use Illuminate\Http\JsonResponse; |
| 12 | use Illuminate\Http\Request; | 14 | use Illuminate\Http\Request; |
| 13 | use Illuminate\Http\Exceptions\HttpResponseException; | 15 | use Illuminate\Http\Exceptions\HttpResponseException; |
| @@ -155,24 +157,6 @@ class BaseController extends Controller | @@ -155,24 +157,6 @@ class BaseController extends Controller | ||
| 155 | } | 157 | } |
| 156 | //获取操作人 | 158 | //获取操作人 |
| 157 | switch ((string) $k) { | 159 | switch ((string) $k) { |
| 158 | - case 'image': | ||
| 159 | - $data['image_link'] = url('/b/image/' . $v); | ||
| 160 | - break; | ||
| 161 | - case 'images': | ||
| 162 | - $v = explode(',',$v); | ||
| 163 | - foreach ($v as $k1=>$v1){ | ||
| 164 | - $data['images_link'][$k1] = url('/b/image/' . $v1); | ||
| 165 | - } | ||
| 166 | - break; | ||
| 167 | - case 'file': | ||
| 168 | - $data['file_link'] = url('/b/file_hash/' . $v); | ||
| 169 | - break; | ||
| 170 | - case 'video': | ||
| 171 | - $v = explode(',',$v); | ||
| 172 | - foreach ($v as $k1=>$v1){ | ||
| 173 | - $data['file_link'][$k1] = url('/b/file_hash/' . $v1); | ||
| 174 | - } | ||
| 175 | - break; | ||
| 176 | case 'operator_id': | 160 | case 'operator_id': |
| 177 | if(!empty($v)){ | 161 | if(!empty($v)){ |
| 178 | $name = (new UserModel())->read(['id'=>$v],['id','name']); | 162 | $name = (new UserModel())->read(['id'=>$v],['id','name']); |
| @@ -228,6 +212,13 @@ class BaseController extends Controller | @@ -228,6 +212,13 @@ class BaseController extends Controller | ||
| 228 | return false; | 212 | return false; |
| 229 | } | 213 | } |
| 230 | 214 | ||
| 215 | + /** | ||
| 216 | + * @remark :获取域名 | ||
| 217 | + * @name :getProjectDomain | ||
| 218 | + * @author :lyh | ||
| 219 | + * @method :post | ||
| 220 | + * @time :2023/7/20 16:45 | ||
| 221 | + */ | ||
| 231 | public function getProjectDomain(){ | 222 | public function getProjectDomain(){ |
| 232 | $project = (new ProjectLogic())->getInfo($this->user['project_id']); | 223 | $project = (new ProjectLogic())->getInfo($this->user['project_id']); |
| 233 | if(!empty($project['deploy_optimize']['domain'])){ | 224 | if(!empty($project['deploy_optimize']['domain'])){ |
| @@ -238,4 +229,24 @@ class BaseController extends Controller | @@ -238,4 +229,24 @@ class BaseController extends Controller | ||
| 238 | } | 229 | } |
| 239 | return ''; | 230 | return ''; |
| 240 | } | 231 | } |
| 232 | + | ||
| 233 | + /** | ||
| 234 | + * @remark :获取图片链接 | ||
| 235 | + * @name :getImageUrl | ||
| 236 | + * @author :lyh | ||
| 237 | + * @method :post | ||
| 238 | + * @time :2023/7/20 16:46 | ||
| 239 | + */ | ||
| 240 | + public function getImageUrl($hash){ | ||
| 241 | + $imageModel = new Image(); | ||
| 242 | + $info = $imageModel->read(['hash'=>$hash]); | ||
| 243 | + $url = ''; | ||
| 244 | + if($info['is_cos'] == 1){ | ||
| 245 | + $cos = new CosService(); | ||
| 246 | + $url = $cos->getImageUrl($info['path']); | ||
| 247 | + }else{ | ||
| 248 | + $url = url('b/image/'.$info['hash']); | ||
| 249 | + } | ||
| 250 | + return $url; | ||
| 251 | + } | ||
| 241 | } | 252 | } |
| @@ -34,6 +34,7 @@ class BlogController extends BaseController | @@ -34,6 +34,7 @@ class BlogController extends BaseController | ||
| 34 | $v = $blogLabelLogic->get_label_name($v); | 34 | $v = $blogLabelLogic->get_label_name($v); |
| 35 | $v['route'] = RouteMap::getRoute(RouteMap::SOURCE_BLOG, $v['id'], $this->user['project_id']); | 35 | $v['route'] = RouteMap::getRoute(RouteMap::SOURCE_BLOG, $v['id'], $this->user['project_id']); |
| 36 | $v['url'] = $this->getProjectDomain() . $v['route']; | 36 | $v['url'] = $this->getProjectDomain() . $v['route']; |
| 37 | + $v['image_link'] = $this->getImageUrl($v['image']); | ||
| 37 | $lists['list'][$k] = $v; | 38 | $lists['list'][$k] = $v; |
| 38 | } | 39 | } |
| 39 | } | 40 | } |
| @@ -77,6 +78,7 @@ class BlogController extends BaseController | @@ -77,6 +78,7 @@ class BlogController extends BaseController | ||
| 77 | $info = $blogLogic->blog_info(); | 78 | $info = $blogLogic->blog_info(); |
| 78 | $info['route'] = RouteMap::getRoute(RouteMap::SOURCE_BLOG, $info['id'], $this->user['project_id']); | 79 | $info['route'] = RouteMap::getRoute(RouteMap::SOURCE_BLOG, $info['id'], $this->user['project_id']); |
| 79 | $info['url'] = $this->getProjectDomain() . $info['route']; | 80 | $info['url'] = $this->getProjectDomain() . $info['route']; |
| 81 | + $info['image_link'] = $this->getImageUrl($info['image']); | ||
| 80 | $this->response('success',Code::SUCCESS,$info); | 82 | $this->response('success',Code::SUCCESS,$info); |
| 81 | } | 83 | } |
| 82 | 84 |
| @@ -32,6 +32,7 @@ class NewsController extends BaseController | @@ -32,6 +32,7 @@ class NewsController extends BaseController | ||
| 32 | $v = $newsCategoryLogic->get_category_name($v); | 32 | $v = $newsCategoryLogic->get_category_name($v); |
| 33 | $v['route'] = RouteMap::getRoute(RouteMap::SOURCE_NEWS, $v['id'], $this->user['project_id']); | 33 | $v['route'] = RouteMap::getRoute(RouteMap::SOURCE_NEWS, $v['id'], $this->user['project_id']); |
| 34 | $v['url'] = $this->getProjectDomain() . $v['route']; | 34 | $v['url'] = $this->getProjectDomain() . $v['route']; |
| 35 | + $v['image_link'] = $this->getImageUrl($v['image']); | ||
| 35 | $lists['list'][$k] = $v; | 36 | $lists['list'][$k] = $v; |
| 36 | } | 37 | } |
| 37 | } | 38 | } |
| @@ -74,6 +75,7 @@ class NewsController extends BaseController | @@ -74,6 +75,7 @@ class NewsController extends BaseController | ||
| 74 | $info = $newsLogic->news_info(); | 75 | $info = $newsLogic->news_info(); |
| 75 | $info['route'] = RouteMap::getRoute(RouteMap::SOURCE_NEWS, $info['id'], $this->user['project_id']); | 76 | $info['route'] = RouteMap::getRoute(RouteMap::SOURCE_NEWS, $info['id'], $this->user['project_id']); |
| 76 | $info['url'] = $this->getProjectDomain() . $info['route']; | 77 | $info['url'] = $this->getProjectDomain() . $info['route']; |
| 78 | + $info['image_link'] = $this->getImageUrl($info['image']); | ||
| 77 | $this->response('success',Code::SUCCESS,$info); | 79 | $this->response('success',Code::SUCCESS,$info); |
| 78 | } | 80 | } |
| 79 | /** | 81 | /** |
| @@ -78,11 +78,6 @@ class ImageController extends Controller | @@ -78,11 +78,6 @@ class ImageController extends Controller | ||
| 78 | if ($info === false) { | 78 | if ($info === false) { |
| 79 | $this->response('指定图片不存在!', Code::USER_ERROR); | 79 | $this->response('指定图片不存在!', Code::USER_ERROR); |
| 80 | } | 80 | } |
| 81 | - //获取cos链接 | ||
| 82 | - if($info['is_cos'] == 1){ | ||
| 83 | - $cos = new CosService(); | ||
| 84 | - return $cos->getImageUrl($info['path']); | ||
| 85 | - } | ||
| 86 | //查看缩略图是否存在 | 81 | //查看缩略图是否存在 |
| 87 | $filename = $this->config['root'] . '/' .$info['path'] . '_' . $w . '_' . $h; | 82 | $filename = $this->config['root'] . '/' .$info['path'] . '_' . $w . '_' . $h; |
| 88 | if(is_file($filename)){ | 83 | if(is_file($filename)){ |
| @@ -127,8 +122,6 @@ class ImageController extends Controller | @@ -127,8 +122,6 @@ class ImageController extends Controller | ||
| 127 | 'image.required'=>'图片必须填写', | 122 | 'image.required'=>'图片必须填写', |
| 128 | ]); | 123 | ]); |
| 129 | $files = $this->request->file('image'); | 124 | $files = $this->request->file('image'); |
| 130 | - $size = $files->getSize(); | ||
| 131 | - $image_type = $files->getClientOriginalExtension(); | ||
| 132 | if (empty($files)) { | 125 | if (empty($files)) { |
| 133 | $this->response('没有上传的文件!', 400); | 126 | $this->response('没有上传的文件!', 400); |
| 134 | } | 127 | } |
| @@ -137,6 +130,8 @@ class ImageController extends Controller | @@ -137,6 +130,8 @@ class ImageController extends Controller | ||
| 137 | if ($type == 'multi') { | 130 | if ($type == 'multi') { |
| 138 | return $this->multi($files); | 131 | return $this->multi($files); |
| 139 | }else{ | 132 | }else{ |
| 133 | + $size = $files->getSize(); | ||
| 134 | + $image_type = $files->getClientOriginalExtension(); | ||
| 140 | return $this->single($files,$size,$image_type); | 135 | return $this->single($files,$size,$image_type); |
| 141 | } | 136 | } |
| 142 | } | 137 | } |
| @@ -247,39 +242,13 @@ class ImageController extends Controller | @@ -247,39 +242,13 @@ class ImageController extends Controller | ||
| 247 | } | 242 | } |
| 248 | } | 243 | } |
| 249 | //批量存储 | 244 | //批量存储 |
| 250 | - $save_data = $this->saveMysqlAll($save_data,$fileName,$size,$hash,$image_type,$this->upload_location); | 245 | + $this->saveMysql($imageModel,$size,$image_type,$fileName,$hash,$this->upload_location); |
| 251 | $data[] = ['image'=>$hash]; | 246 | $data[] = ['image'=>$hash]; |
| 252 | } | 247 | } |
| 253 | - $imageModel->insert($save_data); | ||
| 254 | return $this->response('图片资源',Code::SUCCESS,$data); | 248 | return $this->response('图片资源',Code::SUCCESS,$data); |
| 255 | } | 249 | } |
| 256 | 250 | ||
| 257 | /** | 251 | /** |
| 258 | - * @param $save_data | ||
| 259 | - * @param $fileName | ||
| 260 | - * @param $size | ||
| 261 | - * @param $hash | ||
| 262 | - * @param $image_type | ||
| 263 | - * @remark :批量拼接数据 | ||
| 264 | - * @name :saveMysqlAll | ||
| 265 | - * @author :lyh | ||
| 266 | - * @method :post | ||
| 267 | - * @time :2023/7/20 9:26 | ||
| 268 | - */ | ||
| 269 | - public function saveMysqlAll(&$save_data,$fileName,$size,$hash,$image_type,$is_cos){ | ||
| 270 | - $save_data[] = [ | ||
| 271 | - 'path' => $this->path.'/'.$fileName, | ||
| 272 | - 'created_at' => date('Y-m-d H:i:s',time()), | ||
| 273 | - 'updated_at'=>date('Y-m-d H:i:s',time()), | ||
| 274 | - 'size' => $size, | ||
| 275 | - 'hash' => $hash, | ||
| 276 | - 'type'=>$image_type, | ||
| 277 | - 'refer'=>$this->param['refer'] ?? 0, | ||
| 278 | - 'is_cos'=>$is_cos ?? 0 | ||
| 279 | - ]; | ||
| 280 | - return $save_data; | ||
| 281 | - } | ||
| 282 | - /** | ||
| 283 | * @param $filename | 252 | * @param $filename |
| 284 | * @remark :下载 | 253 | * @remark :下载 |
| 285 | * @name :download | 254 | * @name :download |
| @@ -374,15 +343,20 @@ class ImageController extends Controller | @@ -374,15 +343,20 @@ class ImageController extends Controller | ||
| 374 | * @time :2023/7/18 15:36 | 343 | * @time :2023/7/18 15:36 |
| 375 | */ | 344 | */ |
| 376 | public function setUrl(){ | 345 | public function setUrl(){ |
| 377 | - if(!isset($this->param['refer'])){ | ||
| 378 | - $this->param['refer'] = 1; | ||
| 379 | - } | 346 | + //A端上传 |
| 380 | if(isset($this->param['refer_type']) && $this->param['refer_type'] == 1){ | 347 | if(isset($this->param['refer_type']) && $this->param['refer_type'] == 1){ |
| 381 | $this->path = $this->uploads['path_a'].'/'.$this->image_type[$this->param['refer']].'/'.date('Y-m'); | 348 | $this->path = $this->uploads['path_a'].'/'.$this->image_type[$this->param['refer']].'/'.date('Y-m'); |
| 382 | }else{ | 349 | }else{ |
| 350 | + //B端上传 | ||
| 351 | + if(!isset($this->param['upload_method']) && $this->param['upload_method'] == 1){ | ||
| 352 | + //强制上传本地配置 | ||
| 353 | + $this->upload_location = 0; | ||
| 354 | + }else{ | ||
| 355 | + //根据项目上传标识区分上传到cos/本地 | ||
| 383 | $projectModel = new Project(); | 356 | $projectModel = new Project(); |
| 384 | $project_info = $projectModel->read(['id'=>$this->cache['project_id']],['upload_location']); | 357 | $project_info = $projectModel->read(['id'=>$this->cache['project_id']],['upload_location']); |
| 385 | $this->upload_location = $project_info['upload_location']; | 358 | $this->upload_location = $project_info['upload_location']; |
| 359 | + } | ||
| 386 | $this->path = $this->uploads['path_b'].'/'.$this->cache['project_id'].'/'.$this->image_type[$this->param['refer']].'/'.date('Y-m'); | 360 | $this->path = $this->uploads['path_b'].'/'.$this->cache['project_id'].'/'.$this->image_type[$this->param['refer']].'/'.date('Y-m'); |
| 387 | } | 361 | } |
| 388 | } | 362 | } |
| @@ -65,14 +65,12 @@ class AyrReleaseLogic extends BaseLogic | @@ -65,14 +65,12 @@ class AyrReleaseLogic extends BaseLogic | ||
| 65 | $imageModel = new Image(); | 65 | $imageModel = new Image(); |
| 66 | $list = $imageModel->list(['hash'=>['in',$images]],'id'); | 66 | $list = $imageModel->list(['hash'=>['in',$images]],'id'); |
| 67 | foreach ($list as $v1){ | 67 | foreach ($list as $v1){ |
| 68 | - $filename = basename($v1['path']); | ||
| 69 | - $arr[] = url('/upload/images/'.$filename); | 68 | + $arr[] = url('/upload'.$v1['path']); |
| 70 | } | 69 | } |
| 71 | }else{ | 70 | }else{ |
| 72 | $fileModel = new File(); | 71 | $fileModel = new File(); |
| 73 | $info = $fileModel->read(['hash'=>$v]); | 72 | $info = $fileModel->read(['hash'=>$v]); |
| 74 | - $filename = basename($info['path']); | ||
| 75 | - $arr[] = url('/upload/files/'.$filename); | 73 | + $arr[] = url('/upload'.$info['path']); |
| 76 | } | 74 | } |
| 77 | } | 75 | } |
| 78 | return $this->success($arr); | 76 | return $this->success($arr); |
-
请 注册 或 登录 后发表评论