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]]); // 微信支付回调