From 8be407f374334b57ccdd5aad79ff64063272c603 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Mon, 28 Sep 2020 16:45:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=93=81=E4=B8=8A=E4=B8=8B=E6=9E=B6?= 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 | 8 ++++++++ app/Service/v3/Interfaces/GoodsServiceInterface.php | 1 + config/routes.php | 1 + 4 files changed, 16 insertions(+) diff --git a/app/Controller/v3/GoodsController.php b/app/Controller/v3/GoodsController.php index 05cefba..5b7c4a5 100644 --- a/app/Controller/v3/GoodsController.php +++ b/app/Controller/v3/GoodsController.php @@ -165,4 +165,10 @@ class GoodsController extends BaseController $tags = $this->goodsService->getTags(); return $this->success(['tags' => $tags]); } + + public function updateOnSale() + { + $goodsId = $this->request->input('id',0); + return $this->success($this->goodsService->updateOnSale($goodsId)); + } } \ No newline at end of file diff --git a/app/Service/v3/Implementations/GoodsService.php b/app/Service/v3/Implementations/GoodsService.php index 3f2162b..256d259 100644 --- a/app/Service/v3/Implementations/GoodsService.php +++ b/app/Service/v3/Implementations/GoodsService.php @@ -196,4 +196,12 @@ class GoodsService implements GoodsServiceInterface '新鲜' ]; } + + public function updateOnSale($goodsId) + { + $goods = Goods::query()->withoutGlobalScope('normal')->find($goodsId); + $onSale = $goods->on_sale + 1; + $goods->on_sale = $onSale % 2; + return $goods->save(); + } } \ No newline at end of file diff --git a/app/Service/v3/Interfaces/GoodsServiceInterface.php b/app/Service/v3/Interfaces/GoodsServiceInterface.php index efb6f77..638fb70 100644 --- a/app/Service/v3/Interfaces/GoodsServiceInterface.php +++ b/app/Service/v3/Interfaces/GoodsServiceInterface.php @@ -15,4 +15,5 @@ interface GoodsServiceInterface public function update($params); public function info($goodsId); public function getTags(); + public function updateOnSale($goodsId); } \ No newline at end of file diff --git a/config/routes.php b/config/routes.php index 76fd698..f72d483 100644 --- a/config/routes.php +++ b/config/routes.php @@ -162,6 +162,7 @@ Router::addGroup('/v3/', function () { Router::post('category/secend', 'App\Controller\v3\CategoryController@secend'); 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'); },['middleware' => [\App\Middleware\Auth\ApiMiddleware::class, \App\Middleware\Auth\UserMiddleware::class]]); // 微信支付回调