Browse Source

我的定案

master
weigang 5 years ago
parent
commit
0a7b59e974
  1. 13
      app/Service/AttachmentService.php
  2. 21
      app/Service/OrderService.php

13
app/Service/AttachmentService.php

@ -70,4 +70,17 @@ class AttachmentService implements AttachmentServiceInterface
$path .= '/'.date('Y').'/'.date('m').'/'.date('d');
return $baseDir.$path;
}
public function switchImgToAliOss($path, $bucket = 'thumbnail_q50')
{
if (strpos($path, 'http') === false || strpos($path, 'https') === false) {
$path = 'https://img.lanzulive.com/' . $path;
} else {
$temp = explode('//', $path);
$temp = explode('/', $temp[1]);
unset($temp[0]);
$path = 'https://img.lanzulive.com/' . implode('/', $temp);
}
return $path . '!' . $bucket;
}
}

21
app/Service/OrderService.php

@ -64,6 +64,12 @@ class OrderService implements OrderServiceInterface
*/
protected $financialService;
/**
* @Inject
* @var AttachmentServiceInterface
*/
protected $attachmentService;
/**
* @inheritDoc
*/
@ -972,22 +978,9 @@ class OrderService implements OrderServiceInterface
$goods = OrderGoods::query()->whereIn('order_id', $orderChildIds)->select(['name', 'img'])->first();
$order['good_name'] = $goods->name;
// TODO 临时写死oss压缩类型
$order['img'] = $this->switchImgToAliOss($goods->img);
$order['img'] = $this->attachmentService->switchImgToAliOss($goods->img);
}
return $orders;
}
public function switchImgToAliOss($path, $bucket = 'thumbnail_q50')
{
if (strpos($path, 'http') === false || strpos($path, 'https') === false) {
$path = 'https://img.lanzulive.com/' . $path;
} else {
$temp = explode('//', $path);
$temp = explode('/', $temp[1]);
unset($temp[0]);
$path = 'https://img.lanzulive.com/' . implode('/', $temp);
}
return $path . '!' . $bucket;
}
}
Loading…
Cancel
Save