Kirin 2 years ago
parent
commit
fd4883a876
2 changed files with 20 additions and 0 deletions
  1. 19 0
      app/models/store/StoreCart.php
  2. 1 0
      app/models/store/StoreSeckill.php

+ 19 - 0
app/models/store/StoreCart.php

@@ -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();
 

+ 1 - 0
app/models/store/StoreSeckill.php

@@ -203,6 +203,7 @@ class StoreSeckill extends BaseModel
         return $res;
     }
 
+
     /**
      * 增加库存较少销量
      * @param int $num