diff --git a/app/Controller/v3/GoodsController.php b/app/Controller/v3/GoodsController.php index 1bed88a..9e5cfd7 100644 --- a/app/Controller/v3/GoodsController.php +++ b/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); @@ -175,9 +179,9 @@ class GoodsController extends BaseController $banners = $this->request->input('banner',0); $res = $this->goodsService->create($data); if(!empty($banners)){ - $banners = explode(',',$banners); + $banners = json_decode($banners,true); foreach ($banners as $banner){ - $this->goodsService->bannerCreate($res['id'],$banner,1); + $this->goodsService->bannerCreate($res['id'],$banner['path'],1); } } return $this->success($res); diff --git a/app/Service/v3/Implementations/GoodsService.php b/app/Service/v3/Implementations/GoodsService.php index ada3795..2309f4a 100644 --- a/app/Service/v3/Implementations/GoodsService.php +++ b/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 + ]); } } \ No newline at end of file diff --git a/app/Service/v3/Interfaces/GoodsServiceInterface.php b/app/Service/v3/Interfaces/GoodsServiceInterface.php index 5462562..d2a1a19 100644 --- a/app/Service/v3/Interfaces/GoodsServiceInterface.php +++ b/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); } \ No newline at end of file