Browse Source

商品复制--如果商品包含http即绝对路径,则上传,相对路径则复制

master
liangyuyan 5 years ago
parent
commit
3db7511e55
  1. 25
      app/Admin/Common/CustomFileController.php
  2. 15
      app/Admin/Forms/v3/GoodsCopyForm.php

25
app/Admin/Common/CustomFileController.php

@ -72,4 +72,29 @@ class CustomFileController
? ['status' => true , 'msg' => '文件复制成功', 'path' => $path, 'url' => $disk->url($path)]
: ['status' => false , 'msg' => '文件复制失败'];
}
/**
* 上传文件
* @param $imageDir 存储文件夹
* @param $filePath 文件相对路径
*/
public function autoUploadFile($imageDir, $file)
{
$disk = $this->disk('oss');
// 图片拓展名
$fileOriginalExtension = pathinfo($file)['extension'];
$fileName = md5(time().rand(0000,9999));
$dir = $imageDir;
$newName = 'upload_'.$fileName.'.'.$fileOriginalExtension;
$path = "{$dir}/$newName";
$result = $disk->putFileAs($dir, $file, $newName);
return $result
? ['status' => true , 'msg' => '文件上传成功', 'path' => $path, 'url' => $disk->url($path)]
: ['status' => false , 'msg' => '文件上传失败'];
}
}

15
app/Admin/Forms/v3/GoodsCopyForm.php

@ -112,15 +112,22 @@ class GoodsCopyForm extends Form
/**
* 复制的商品图片
* @param $ossImageDir oss 存储文件夹
* @param $imagePath 图片对路径
* @param $imagePath 图片对路径
*/
public function copyImage($ossImageDir, $imagePath)
{
$return = '';
$oldCoverImg = $imagePath;
$customFile = new CustomFileController();
$result = $customFile->autoCopyFile($ossImageDir, $oldCoverImg);
// 判断图片是否包含http
if(stripos($imagePath,'http') !== false && @getimagesize($imagePath)){
// 上传模式
$result = $customFile->autoUploadFile($ossImageDir, $imagePath);
}else{
// 复制模式
$result = $customFile->autoCopyFile($ossImageDir, $imagePath);
};
if($result['status']){
$return = $result['path'];
}

Loading…
Cancel
Save