Browse Source

Merge branch 'img'

master
Lemon 5 years ago
parent
commit
69ff75c1e8
  1. 12
      app/Controller/v3/GoodsController.php
  2. 16
      app/Service/v3/Implementations/GoodsService.php
  3. 1
      app/Service/v3/Interfaces/GoodsServiceInterface.php

12
app/Controller/v3/GoodsController.php

@ -119,9 +119,13 @@ class GoodsController extends BaseController
$banners = $this->request->input('banner',0); $banners = $this->request->input('banner',0);
$res = $this->goodsService->update($data); $res = $this->goodsService->update($data);
if(!empty($banners)){ if(!empty($banners)){
$banners = explode(',',$banners);
$banners = json_decode($banners,true);
foreach ($banners as $banner){ 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); return $this->success($res);
@ -175,9 +179,9 @@ class GoodsController extends BaseController
$banners = $this->request->input('banner',0); $banners = $this->request->input('banner',0);
$res = $this->goodsService->create($data); $res = $this->goodsService->create($data);
if(!empty($banners)){ if(!empty($banners)){
$banners = explode(',',$banners);
$banners = json_decode($banners,true);
foreach ($banners as $banner){ foreach ($banners as $banner){
$this->goodsService->bannerCreate($res['id'],$banner,1);
$this->goodsService->bannerCreate($res['id'],$banner['path'],1);
} }
} }
return $this->success($res); 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) public function bannerCreate($goodsId,$path,$type = 1)
{ {
$date = [
$data = [
'goods_id' => $goodsId, 'goods_id' => $goodsId,
'path' => $path, 'path' => $path,
'type' => $type '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 updateOnSale($goodsId);
public function bannerDelete($bannerId); public function bannerDelete($bannerId);
public function bannerCreate($goodsId, $path, $type = 1); public function bannerCreate($goodsId, $path, $type = 1);
public function bannerUpdate($bannerId, $goodsId, $path, $type = 1);
} }
Loading…
Cancel
Save