Commit 830899a9 by lizhilin

更新

parent 97e375f2
...@@ -32,9 +32,12 @@ public function deletePublicOssFile() ...@@ -32,9 +32,12 @@ public function deletePublicOssFile()
{ {
$ossPath = request()->post('key') ?? ''; $ossPath = request()->post('key') ?? '';
$aliOss = new AilOss(); $aliOss = new AilOss();
if (strstr($ossPath, 'aliyuncs') !== false) {
$res = $aliOss->delete($ossPath); //, 'OSS_BUCKET' $res = $aliOss->delete($ossPath); //, 'OSS_BUCKET'
return $res ? $this->responseDeleted() : $this->responseDeleteFailed('文件删除失败'); return $res ? $this->responseDeleted() : $this->responseDeleteFailed('文件删除失败');
} else {
return $this->deleteFileAndResponse();
}
} }
public function merchantUpload() public function merchantUpload()
......
...@@ -34,6 +34,7 @@ public function upload($object, $filepath, $bucket = 'OSS_BUCKET') ...@@ -34,6 +34,7 @@ public function upload($object, $filepath, $bucket = 'OSS_BUCKET')
{ {
$res = false; $res = false;
$bucket = env($bucket); //获取阿里云oss的bucket $bucket = env($bucket); //获取阿里云oss的bucket
if (self::$oss->uploadFile($bucket, $object, $filepath)) { //调用uploadFile方法把服务器文件上传到阿里云oss if (self::$oss->uploadFile($bucket, $object, $filepath)) { //调用uploadFile方法把服务器文件上传到阿里云oss
$res = true; $res = true;
} }
......
...@@ -31,3 +31,14 @@ function generateRandomString($length = 10) ...@@ -31,3 +31,14 @@ function generateRandomString($length = 10)
} }
return $randomString; return $randomString;
} }
function togetherFilePath($path = '')
{
if ($path) {
if (strstr($path, 'aliyuncs') === false) {
$path = env('IMAGE_URL') . $path;
}
}
return $path;
}
...@@ -127,7 +127,7 @@ public function getList(Request $request) ...@@ -127,7 +127,7 @@ public function getList(Request $request)
'market_price' => sprintf("%.2f", $market_price), 'market_price' => sprintf("%.2f", $market_price),
'goods_price' => $mer_id ? sprintf("%.2f", $cg_price) : sprintf("%.2f", $market_price), 'goods_price' => $mer_id ? sprintf("%.2f", $cg_price) : sprintf("%.2f", $market_price),
'tags' => $tags, 'tags' => $tags,
'cover_img' => (isset($goodsObj->cover_img) ? env('IMAGE_URL') . $goodsObj->cover_img : ''), 'cover_img' => (isset($goodsObj->cover_img) ? togetherFilePath($goodsObj->cover_img) : ''),
]; ];
} }
} }
...@@ -185,6 +185,7 @@ public function getIndexGoods(Request $request) ...@@ -185,6 +185,7 @@ public function getIndexGoods(Request $request)
} }
//标签 //标签
$tags = $datum->tags ? json_decode($datum->tags, true) : []; $tags = $datum->tags ? json_decode($datum->tags, true) : [];
$data['list'][] = [ $data['list'][] = [
'id' => $datum->id, 'id' => $datum->id,
'goods_name' => $datum->goods_name, 'goods_name' => $datum->goods_name,
...@@ -193,7 +194,7 @@ public function getIndexGoods(Request $request) ...@@ -193,7 +194,7 @@ public function getIndexGoods(Request $request)
'market_price' => floor($market_price), 'market_price' => floor($market_price),
'goods_price' => $mer_id ? floor($dg_price) : floor($market_price), 'goods_price' => $mer_id ? floor($dg_price) : floor($market_price),
'tags' => $tags, 'tags' => $tags,
'cover_img' => ($datum->cover_img) ? env('IMAGE_URL') . $datum->cover_img : '', 'cover_img' => togetherFilePath($datum->cover_img),
]; ];
} }
} }
...@@ -228,7 +229,7 @@ public function getDetail(Request $request) ...@@ -228,7 +229,7 @@ public function getDetail(Request $request)
$cover = []; $cover = [];
if (!empty($cover_arr)) { if (!empty($cover_arr)) {
foreach ($cover_arr as $item) { foreach ($cover_arr as $item) {
$cover[] = env('IMAGE_URL') . $item; $cover[] = togetherFilePath($item);
} }
} }
...@@ -321,7 +322,7 @@ public function getAttrKey(Request $request) ...@@ -321,7 +322,7 @@ public function getAttrKey(Request $request)
// 'dg_price' => sprintf('%.2f', $cg_price), // 'dg_price' => sprintf('%.2f', $cg_price),
'goods_price' => $mer_id ? sprintf('%.2f', $cg_price) : sprintf('%.2f', $market_price), 'goods_price' => $mer_id ? sprintf('%.2f', $cg_price) : sprintf('%.2f', $market_price),
'stock' => $stock, 'stock' => $stock,
'pic' => $attrObj->pic ? env('IMAGE_URL') . $attrObj->pic : '' 'pic' => $attrObj->pic ? togetherFilePath($attrObj->pic) : ''
]; ];
return $this->JsonResponse($data); return $this->JsonResponse($data);
} }
......
...@@ -70,7 +70,7 @@ public function collectList(Request $request) ...@@ -70,7 +70,7 @@ public function collectList(Request $request)
'attr' => $attrRowObj ? $attrRowObj->attr_val : '', 'attr' => $attrRowObj ? $attrRowObj->attr_val : '',
'tags' => $tags, 'tags' => $tags,
'goods_price' => $merchant_id ? sprintf("%.2f", $attrRowObj->cg_price) : sprintf("%.2f", $attrRowObj->market_price), 'goods_price' => $merchant_id ? sprintf("%.2f", $attrRowObj->cg_price) : sprintf("%.2f", $attrRowObj->market_price),
'cover_img' => ($goodObj->cover_img ? env('IMAGE_URL') . $goodObj->cover_img : ''), 'cover_img' => ($goodObj->cover_img ? togetherFilePath($goodObj->cover_img) : ''),
'addtime' => date('Y-m-d H:i:s', strtotime($datum->created_at)) 'addtime' => date('Y-m-d H:i:s', strtotime($datum->created_at))
]; ];
} }
......
...@@ -262,8 +262,8 @@ ...@@ -262,8 +262,8 @@
'upload' => [ 'upload' => [
// Disk in `config/filesystem.php`. // Disk in `config/filesystem.php`.
'disk' => 'public_oss', //admin 'disk' => 'admin', //admin
'extra_disk' => 'public_oss', //扩展oss,原系统不兼容
// Image and file upload path under the disk above. // Image and file upload path under the disk above.
'directory' => [ 'directory' => [
'image' => 'images', 'image' => 'images',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment