Browse Source

替换图片

master
Lemon 5 years ago
parent
commit
10b67cff01
  1. 8
      app/Controller/v3/GoodsController.php
  2. 16
      app/Service/v3/Implementations/GoodsService.php
  3. 1
      app/Service/v3/Interfaces/GoodsServiceInterface.php

8
app/Controller/v3/GoodsController.php

@ -119,9 +119,13 @@ class GoodsController extends BaseController
$banners = $this->request->input('banner',0);
$res = $this->goodsService->update($data);
if(!empty($banners)){
$banners = explode(',',$banners);
$banners = json_decode($banners,true);
foreach ($banners as $banner){
$this->goodsService->bannerCreate($data['id'],$banner,1);
if(!empty($banner['id'])){
$this->goodsService->bannerUpdate($banner['id'],$data['id'],$banner['path'],1);
}else{
$this->goodsService->bannerCreate($data['id'],$banner['path'],1);
}
}
}
return $this->success($res);

16
app/Service/v3/Implementations/GoodsService.php

@ -219,11 +219,23 @@ class GoodsService implements GoodsServiceInterface
public function bannerCreate($goodsId,$path,$type = 1)
{
$date = [
$data = [
'goods_id' => $goodsId,
'path' => $path,
'type' => $type
];
return GoodsBanner::create($date);
return GoodsBanner::create($data);
}
public function bannerUpdate($bannerId,$goodsId,$path,$type = 1)
{
return GoodsBanner::query()->where([
'id' => $bannerId,
'goods_id' => $goodsId
])
->update([
'path' => $path,
'type' => $type
]);
}
}

1
app/Service/v3/Interfaces/GoodsServiceInterface.php

@ -18,4 +18,5 @@ interface GoodsServiceInterface
public function updateOnSale($goodsId);
public function bannerDelete($bannerId);
public function bannerCreate($goodsId, $path, $type = 1);
public function bannerUpdate($bannerId, $goodsId, $path, $type = 1);
}
Loading…
Cancel
Save