cartFirstData[$oneGood] = ($this->cartFirstData[$oneGood] ?? 0) + 1; $one[$oneGood] = ($one[$oneGood] ?? 0) + 1; } $this->cartSecondData[] = $one; $copies++; } $this->copies = $copies; } /** * @param array $goodIds * @return void */ protected function checkGood(array $goodIds): void { foreach ($this->cartFirstData as $key => $one) { if (in_array($key, $goodIds)) continue; throw new ErrException('商品不存在'); } } /** * @return void * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ protected function checkStock(): void { foreach ($this->cartFirstData as $key => $one) { if (($this->redis->zScore($this->stockKey,$key) ?? 0) >= $one) continue; throw new ErrException('商品库存不足'); } } }