为什么 decreaseStock 需要用 where 来判断 id? 而 addStock 不需要呢
public function decreaseStock($amount) {
if ($amount < 0) {
throw new InternalException('减库存不可小于0');
}
return $this->where('id', $this->id)->where('stock','>=',$amount)->decrement('stock', $amount); }
关于 LearnKu
减库存可能出现减成负数的情况,也就是超卖,而加库存不会出现这种情况。