From 10b67cff01f0dfaa4b7ad71dff7b6927db4fdc63 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Mon, 16 Nov 2020 15:23:51 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/v3/GoodsController.php | 8 ++++++-- app/Service/v3/Implementations/GoodsService.php | 16 ++++++++++++++-- .../v3/Interfaces/GoodsServiceInterface.php | 1 + 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/app/Controller/v3/GoodsController.php b/app/Controller/v3/GoodsController.php index 1bed88a..05bc716 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); 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 From 6c2911d5dc2e290ae72075ec4aa26cb036096e08 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Mon, 16 Nov 2020 18:06:55 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/v3/GoodsController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Controller/v3/GoodsController.php b/app/Controller/v3/GoodsController.php index 05bc716..f5657a0 100644 --- a/app/Controller/v3/GoodsController.php +++ b/app/Controller/v3/GoodsController.php @@ -179,7 +179,7 @@ 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); } From 29568957a014bf8e2e7e77f5aeaf73a812a39b2d Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Thu, 19 Nov 2020 09:35:25 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=96=B0=E5=BB=BA=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/v3/GoodsController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Controller/v3/GoodsController.php b/app/Controller/v3/GoodsController.php index f5657a0..9e5cfd7 100644 --- a/app/Controller/v3/GoodsController.php +++ b/app/Controller/v3/GoodsController.php @@ -181,7 +181,7 @@ class GoodsController extends BaseController if(!empty($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);