diff --git a/app/Controller/Api/OrderController.php b/app/Controller/Api/OrderController.php index 4a38131..6045692 100644 --- a/app/Controller/Api/OrderController.php +++ b/app/Controller/Api/OrderController.php @@ -8,6 +8,7 @@ use App\Controller\AbstractController; use App\Middleware\Api\JwtAuthMiddleware; use App\Service\Api\Order\CancelOrderService; use App\Service\Api\Order\CheckCartService; +use App\Service\Api\Order\CheckStockService; use App\Service\Api\Order\ConfirmationOrderService; use App\Service\Api\Order\OrderInfoService; use App\Service\Api\Order\OrderListService; @@ -38,6 +39,18 @@ class OrderController extends AbstractController return (new CheckCartService)->handle(); } + /** + * @return array + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ + #[RequestMapping(path: 'check_stock',methods: 'post')] + #[Scene(scene: 'check_stock')] + public function checkGoodStock() + { + return (new CheckStockService)->handle(); + } + /** * @return array * @throws ContainerExceptionInterface diff --git a/app/Service/Api/Order/CheckStockService.php b/app/Service/Api/Order/CheckStockService.php new file mode 100644 index 0000000..c8e8e19 --- /dev/null +++ b/app/Service/Api/Order/CheckStockService.php @@ -0,0 +1,41 @@ +siteId = (int)$this->request->input('site_id'); + $skuId = (int)$this->request->input('sku_id'); + + $kitchenId = $this->checkSite($this->siteId); + + $this->stockKey = ApiRedisKey::goodStockKey($this->cycleId,$kitchenId); + + if (!$this->redis->exists($this->stockKey)) throw new ErrException('库存不足'); + + if (($this->redis->zScore($this->stockKey,$skuId) ?? 0) < 1) throw new ErrException('商品库存不足',ApiCode::ORDER_GOOD_INSUFFICIENT_STOCK); + + return $this->return->success(); + } +} \ No newline at end of file diff --git a/app/Service/ServiceTrait/Api/OrderTrait.php b/app/Service/ServiceTrait/Api/OrderTrait.php index 6c59fdc..760cf7d 100644 --- a/app/Service/ServiceTrait/Api/OrderTrait.php +++ b/app/Service/ServiceTrait/Api/OrderTrait.php @@ -130,6 +130,11 @@ trait OrderTrait } } + protected function buildCartStock() + { + + } + /** * @return void * @throws ContainerExceptionInterface