feat : check stock
This commit is contained in:
@@ -8,6 +8,7 @@ use App\Controller\AbstractController;
|
|||||||
use App\Middleware\Api\JwtAuthMiddleware;
|
use App\Middleware\Api\JwtAuthMiddleware;
|
||||||
use App\Service\Api\Order\CancelOrderService;
|
use App\Service\Api\Order\CancelOrderService;
|
||||||
use App\Service\Api\Order\CheckCartService;
|
use App\Service\Api\Order\CheckCartService;
|
||||||
|
use App\Service\Api\Order\CheckStockService;
|
||||||
use App\Service\Api\Order\ConfirmationOrderService;
|
use App\Service\Api\Order\ConfirmationOrderService;
|
||||||
use App\Service\Api\Order\OrderInfoService;
|
use App\Service\Api\Order\OrderInfoService;
|
||||||
use App\Service\Api\Order\OrderListService;
|
use App\Service\Api\Order\OrderListService;
|
||||||
@@ -38,6 +39,18 @@ class OrderController extends AbstractController
|
|||||||
return (new CheckCartService)->handle();
|
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
|
* @return array
|
||||||
* @throws ContainerExceptionInterface
|
* @throws ContainerExceptionInterface
|
||||||
|
|||||||
41
app/Service/Api/Order/CheckStockService.php
Normal file
41
app/Service/Api/Order/CheckStockService.php
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* This service file is part of item.
|
||||||
|
*
|
||||||
|
* @author ctexthuang
|
||||||
|
* @contact ctexthuang@qq.com
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Service\Api\Order;
|
||||||
|
|
||||||
|
use App\Cache\Redis\Api\ApiRedisKey;
|
||||||
|
use App\Constants\ApiCode;
|
||||||
|
use App\Exception\ErrException;
|
||||||
|
use Psr\Container\ContainerExceptionInterface;
|
||||||
|
use Psr\Container\NotFoundExceptionInterface;
|
||||||
|
|
||||||
|
class CheckStockService extends BaseOrderService
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
* @throws ContainerExceptionInterface
|
||||||
|
* @throws NotFoundExceptionInterface
|
||||||
|
*/
|
||||||
|
public function handle(): array
|
||||||
|
{
|
||||||
|
$this->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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -130,6 +130,11 @@ trait OrderTrait
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function buildCartStock()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return void
|
* @return void
|
||||||
* @throws ContainerExceptionInterface
|
* @throws ContainerExceptionInterface
|
||||||
|
|||||||
Reference in New Issue
Block a user