|
@@ -72,6 +72,25 @@ class StoreCart extends BaseModel
|
|
|
$cart->cart_num = $cart_num;
|
|
|
else
|
|
|
$cart->cart_num = bcadd($cart_num, $cart->cart_num, 3);
|
|
|
+
|
|
|
+ $stock = 0;
|
|
|
+ if ($cart['bargain_id']) {
|
|
|
+ //TODO 获取砍价产品的库存
|
|
|
+ $stock = StoreBargain::getBargainStock($cart['bargain_id']);
|
|
|
+ } else if ($cart['seckill_id']) {
|
|
|
+ //TODO 获取秒杀产品的库存
|
|
|
+ $stock = StoreSeckill::getProductStock($cart['seckill_id']);
|
|
|
+ } else if ($cart['combination_id']) {
|
|
|
+ //TODO 获取拼团产品的库存
|
|
|
+ $stock = StoreCombination::getCombinationStock($cart['combination_id'], $cart->cart_num);
|
|
|
+ } else if ($cart['product_id']) {
|
|
|
+ //TODO 获取普通产品的库存
|
|
|
+ $stock = StoreProduct::getProductStock($cart['product_id'], $cart['product_attr_unique']);
|
|
|
+ }
|
|
|
+ if (!$stock) return self::setErrorInfo('暂无库存');
|
|
|
+ if (!$cart->cart_num) return self::setErrorInfo('库存错误');
|
|
|
+ if ($stock < $cart->cart_num) return self::setErrorInfo('库存不足' . $cart->cart_num);
|
|
|
+
|
|
|
$cart->add_time = time();
|
|
|
$cart->save();
|
|
|
|