From a901444fd974fbec41d83db3df6e8650446a43cd Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Wed, 21 Oct 2020 10:12:08 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=95=86=E5=93=81=E8=AF=A6=E6=83=85=20?= =?UTF-8?q?=E8=BF=94=E5=9B=9Ebanner=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Model/v3/Goods.php | 5 +++++ app/Service/v3/Implementations/GoodsService.php | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/Model/v3/Goods.php b/app/Model/v3/Goods.php index 13e4411..5e07991 100644 --- a/app/Model/v3/Goods.php +++ b/app/Model/v3/Goods.php @@ -173,4 +173,9 @@ class Goods extends Model { $this->attributes['spec'] = json_encode(json_decode($value, true)); } + + public function banner() + { + return $this->hasMany(GoodsBanner::class, 'goods_id','id'); + } } \ No newline at end of file diff --git a/app/Service/v3/Implementations/GoodsService.php b/app/Service/v3/Implementations/GoodsService.php index 25bf28c..8105130 100644 --- a/app/Service/v3/Implementations/GoodsService.php +++ b/app/Service/v3/Implementations/GoodsService.php @@ -187,7 +187,7 @@ class GoodsService implements GoodsServiceInterface public function info($goodsId) { - $res = Goods::query()->withoutGlobalScope('normal')->where('id',$goodsId)->first(); + $res = Goods::query()->withoutGlobalScope('normal')->where('id',$goodsId)->with('banner')->first(); return $res; } From 5aef8bec6a1789590a0e6818260c38bcbfb26283 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Wed, 21 Oct 2020 15:09:33 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E6=96=B0=E5=A2=9Ebanner=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/v3/GoodsController.php | 6 ++++++ app/Service/v3/Implementations/GoodsService.php | 6 ++++++ app/Service/v3/Interfaces/GoodsServiceInterface.php | 1 + config/routes.php | 1 + 4 files changed, 14 insertions(+) diff --git a/app/Controller/v3/GoodsController.php b/app/Controller/v3/GoodsController.php index 7e8bb5c..2f4c5b3 100644 --- a/app/Controller/v3/GoodsController.php +++ b/app/Controller/v3/GoodsController.php @@ -171,4 +171,10 @@ class GoodsController extends BaseController $goodsId = $this->request->input('id',0); return $this->success($this->goodsService->updateOnSale($goodsId)); } + + public function bannerDelete() + { + $bannerId = $this->request->input('banner_id',0); + return $this->success($this->goodsService->bannerDelete($bannerId)); + } } \ No newline at end of file diff --git a/app/Service/v3/Implementations/GoodsService.php b/app/Service/v3/Implementations/GoodsService.php index 8105130..5b4aa4a 100644 --- a/app/Service/v3/Implementations/GoodsService.php +++ b/app/Service/v3/Implementations/GoodsService.php @@ -6,6 +6,7 @@ use App\Commons\Log; use App\Constants\v3\ErrorCode; use App\Constants\v3\LogLabel; use App\Exception\ErrorCodeException; +use App\Model\v3\Banner; use App\Service\v3\Interfaces\GoodsInventoryServiceInterface; use App\Service\v3\Interfaces\GoodsServiceInterface; use App\Model\v3\Goods; @@ -207,4 +208,9 @@ class GoodsService implements GoodsServiceInterface $goods->on_sale = $onSale % 2; return $goods->save(); } + + public function bannerDelete($bannerId) + { + return GoodsBanner::query()->where('id',$bannerId)->delete(); + } } \ No newline at end of file diff --git a/app/Service/v3/Interfaces/GoodsServiceInterface.php b/app/Service/v3/Interfaces/GoodsServiceInterface.php index 638fb70..eee7b3a 100644 --- a/app/Service/v3/Interfaces/GoodsServiceInterface.php +++ b/app/Service/v3/Interfaces/GoodsServiceInterface.php @@ -16,4 +16,5 @@ interface GoodsServiceInterface public function info($goodsId); public function getTags(); public function updateOnSale($goodsId); + public function bannerDelete($bannerId); } \ No newline at end of file diff --git a/config/routes.php b/config/routes.php index ec068d8..750125c 100644 --- a/config/routes.php +++ b/config/routes.php @@ -163,6 +163,7 @@ Router::addGroup('/v3/', function () { Router::post('category/third', 'App\Controller\v3\CategoryController@third'); Router::post('goods/create', 'App\Controller\v3\GoodsController@create'); Router::post('goods/updateOnSale', 'App\Controller\v3\GoodsController@updateOnSale'); + Router::post('goods/bannerDelete', 'App\Controller\v3\GoodsController@bannerDelete'); },['middleware' => [\App\Middleware\Auth\ApiMiddleware::class, \App\Middleware\Auth\UserMiddleware::class]]); // 微信支付回调 From 5181d604d5cc319f45dd799bc9c93e5a46ef36c1 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Wed, 21 Oct 2020 16:03:15 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=95=86=E5=93=81banner?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/v3/GoodsController.php | 14 +++ app/Model/v3/GoodsBanner.php | 6 ++ .../v3/Implementations/GoodsService.php | 99 ++++++++++--------- .../v3/Interfaces/GoodsServiceInterface.php | 1 + 4 files changed, 75 insertions(+), 45 deletions(-) diff --git a/app/Controller/v3/GoodsController.php b/app/Controller/v3/GoodsController.php index 2f4c5b3..ebbf6c7 100644 --- a/app/Controller/v3/GoodsController.php +++ b/app/Controller/v3/GoodsController.php @@ -109,6 +109,13 @@ class GoodsController extends BaseController $data['is_infinite'] = $this->request->input('is_infinite',0); $data['user_id'] = $this->request->input('user_id',0); $res = $this->goodsService->update($data); + $banners = $this->request->input('banner',0); + if(!empty($banners)){ + $banners = explode(',',$banners); + foreach ($banners as $banner){ + $this->goodsService->bannerCreate($data['id'],$banner,1); + } + } return $this->success($res); } @@ -157,6 +164,13 @@ class GoodsController extends BaseController $data['is_infinite'] = $this->request->input('is_infinite',0); $data['user_id'] = $this->request->input('user_id',0); $res = $this->goodsService->create($data); + $banners = $this->request->input('banner',0); + if(!empty($banners)){ + $banners = explode(',',$banners); + foreach ($banners as $banner){ + $this->goodsService->bannerCreate($res['id'],$banner,1); + } + } return $this->success($res); } diff --git a/app/Model/v3/GoodsBanner.php b/app/Model/v3/GoodsBanner.php index d0cfa69..1ae4438 100644 --- a/app/Model/v3/GoodsBanner.php +++ b/app/Model/v3/GoodsBanner.php @@ -24,6 +24,12 @@ class GoodsBanner extends Model 'banner_url', ]; + protected $fillable = [ + 'id', + 'goods_id', + 'path', + 'type' + ]; public function getBannerUrlAttribute() { diff --git a/app/Service/v3/Implementations/GoodsService.php b/app/Service/v3/Implementations/GoodsService.php index 5b4aa4a..60545f7 100644 --- a/app/Service/v3/Implementations/GoodsService.php +++ b/app/Service/v3/Implementations/GoodsService.php @@ -6,7 +6,6 @@ use App\Commons\Log; use App\Constants\v3\ErrorCode; use App\Constants\v3\LogLabel; use App\Exception\ErrorCodeException; -use App\Model\v3\Banner; use App\Service\v3\Interfaces\GoodsInventoryServiceInterface; use App\Service\v3\Interfaces\GoodsServiceInterface; use App\Model\v3\Goods; @@ -109,28 +108,28 @@ class GoodsService implements GoodsServiceInterface 'on_sale' => $params['on_sale'], 'is_infinite' => $params['is_infinite'] ]; - $this->log->event(LogLabel::CREATE_GOODS_LOG, ['logData' => json_encode( - [ - 'id' => $params['id'], - 'market_id' => $params['market_id'], - 'store_id' => $params['store_id'], - 'name' => $params['name'], - 'category_id' => $params['category_id'], - 'goods_category_id' => $params['goods_category_id'], - 'goods_unit' => $params['goods_unit'], - 'price' => $params['price'], - 'original_price' => $params['original_price'], - 'inventory' => $params['inventory'], - 'restrict_num' => $params['restrict_num'], - 'start_num' => $params['start_num'], - 'spec' => $params['spec'], - 'tags' => $params['tags'], - 'remark' => $params['remark'], - 'on_sale' => $params['on_sale'], - 'is_infinite' => $params['is_infinite'], - 'user_id' => $params['user_id'] - ] - )]); + // $this->log->event(LogLabel::CREATE_GOODS_LOG, ['logData' => json_encode( + // [ + // 'id' => $params['id'], + // 'market_id' => $params['market_id'], + // 'store_id' => $params['store_id'], + // 'name' => $params['name'], + // 'category_id' => $params['category_id'], + // 'goods_category_id' => $params['goods_category_id'], + // 'goods_unit' => $params['goods_unit'], + // 'price' => $params['price'], + // 'original_price' => $params['original_price'], + // 'inventory' => $params['inventory'], + // 'restrict_num' => $params['restrict_num'], + // 'start_num' => $params['start_num'], + // 'spec' => $params['spec'], + // 'tags' => $params['tags'], + // 'remark' => $params['remark'], + // 'on_sale' => $params['on_sale'], + // 'is_infinite' => $params['is_infinite'], + // 'user_id' => $params['user_id'] + // ] + // )]); return Goods::create($data); } @@ -161,28 +160,28 @@ class GoodsService implements GoodsServiceInterface 'on_sale' => $params['on_sale'], 'is_infinite' => $params['is_infinite'] ]); - $this->log->event(LogLabel::UPDATE_GOODS_LOG, ['logData' => json_encode( - [ - 'id' => $params['id'], - 'market_id' => $params['market_id'], - 'store_id' => $params['store_id'], - 'name' => $params['name'], - 'category_id' => $params['category_id'], - 'goods_category_id' => $params['goods_category_id'], - 'goods_unit' => $params['goods_unit'], - 'price' => $params['price'], - 'original_price' => $params['original_price'], - 'inventory' => $params['inventory'], - 'restrict_num' => $params['restrict_num'], - 'start_num' => $params['start_num'], - 'spec' => $params['spec'], - 'tags' => $params['tags'], - 'remark' => $params['remark'], - 'on_sale' => $params['on_sale'], - 'is_infinite' => $params['is_infinite'], - 'user_id' => $params['user_id'] - ] - )]); + // $this->log->event(LogLabel::UPDATE_GOODS_LOG, ['logData' => json_encode( + // [ + // 'id' => $params['id'], + // 'market_id' => $params['market_id'], + // 'store_id' => $params['store_id'], + // 'name' => $params['name'], + // 'category_id' => $params['category_id'], + // 'goods_category_id' => $params['goods_category_id'], + // 'goods_unit' => $params['goods_unit'], + // 'price' => $params['price'], + // 'original_price' => $params['original_price'], + // 'inventory' => $params['inventory'], + // 'restrict_num' => $params['restrict_num'], + // 'start_num' => $params['start_num'], + // 'spec' => $params['spec'], + // 'tags' => $params['tags'], + // 'remark' => $params['remark'], + // 'on_sale' => $params['on_sale'], + // 'is_infinite' => $params['is_infinite'], + // 'user_id' => $params['user_id'] + // ] + // )]); return $goods; } @@ -213,4 +212,14 @@ class GoodsService implements GoodsServiceInterface { return GoodsBanner::query()->where('id',$bannerId)->delete(); } + + public function bannerCreate($goodsId,$path,$type = 1) + { + $date = [ + 'goods_id' => $goodsId, + 'path' => $path, + 'type' => $type + ]; + return GoodsBanner::create($date); + } } \ No newline at end of file diff --git a/app/Service/v3/Interfaces/GoodsServiceInterface.php b/app/Service/v3/Interfaces/GoodsServiceInterface.php index eee7b3a..5462562 100644 --- a/app/Service/v3/Interfaces/GoodsServiceInterface.php +++ b/app/Service/v3/Interfaces/GoodsServiceInterface.php @@ -17,4 +17,5 @@ interface GoodsServiceInterface public function getTags(); public function updateOnSale($goodsId); public function bannerDelete($bannerId); + public function bannerCreate($goodsId, $path, $type = 1); } \ No newline at end of file From cac1fd0933e5912ebd851d551b2d2188470f9510 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Wed, 21 Oct 2020 16:21:33 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E5=95=86=E5=93=81=E4=B8=BB=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/v3/GoodsController.php | 6 ++++-- app/Model/v3/Goods.php | 3 ++- app/Service/v3/Implementations/GoodsService.php | 6 ++++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/Controller/v3/GoodsController.php b/app/Controller/v3/GoodsController.php index ebbf6c7..4bb6165 100644 --- a/app/Controller/v3/GoodsController.php +++ b/app/Controller/v3/GoodsController.php @@ -108,8 +108,9 @@ class GoodsController extends BaseController $data['on_sale'] = $this->request->input('on_sale',0); $data['is_infinite'] = $this->request->input('is_infinite',0); $data['user_id'] = $this->request->input('user_id',0); - $res = $this->goodsService->update($data); + $data['cover_img'] = $this->request->input('cover_img',0); $banners = $this->request->input('banner',0); + $res = $this->goodsService->update($data); if(!empty($banners)){ $banners = explode(',',$banners); foreach ($banners as $banner){ @@ -163,8 +164,9 @@ class GoodsController extends BaseController $data['on_sale'] = $this->request->input('on_sale',0); $data['is_infinite'] = $this->request->input('is_infinite',0); $data['user_id'] = $this->request->input('user_id',0); - $res = $this->goodsService->create($data); + $data['cover_img'] = $this->request->input('cover_img',0); $banners = $this->request->input('banner',0); + $res = $this->goodsService->create($data); if(!empty($banners)){ $banners = explode(',',$banners); foreach ($banners as $banner){ diff --git a/app/Model/v3/Goods.php b/app/Model/v3/Goods.php index 5e07991..3ce1db5 100644 --- a/app/Model/v3/Goods.php +++ b/app/Model/v3/Goods.php @@ -62,7 +62,8 @@ class Goods extends Model 'tags', 'remark', 'on_sale', - 'is_infinite' + 'is_infinite', + 'cover_img' ]; /** * The attributes that should be cast to native types. diff --git a/app/Service/v3/Implementations/GoodsService.php b/app/Service/v3/Implementations/GoodsService.php index 60545f7..35d616d 100644 --- a/app/Service/v3/Implementations/GoodsService.php +++ b/app/Service/v3/Implementations/GoodsService.php @@ -106,7 +106,8 @@ class GoodsService implements GoodsServiceInterface 'tags' => $params['tags'], 'remark' => $params['remark'], 'on_sale' => $params['on_sale'], - 'is_infinite' => $params['is_infinite'] + 'is_infinite' => $params['is_infinite'], + 'cover_img' => $params['cover_img'] ]; // $this->log->event(LogLabel::CREATE_GOODS_LOG, ['logData' => json_encode( // [ @@ -158,7 +159,8 @@ class GoodsService implements GoodsServiceInterface 'tags' => $params['tags'], 'remark' => $params['remark'], 'on_sale' => $params['on_sale'], - 'is_infinite' => $params['is_infinite'] + 'is_infinite' => $params['is_infinite'], + 'cover_img' => $params['cover_img'] ]); // $this->log->event(LogLabel::UPDATE_GOODS_LOG, ['logData' => json_encode( // [