43 lines
1.1 KiB
PHP
43 lines
1.1 KiB
PHP
<?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');
|
|
|
|
$this->checkTodayCutOffTime();
|
|
|
|
$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();
|
|
}
|
|
} |