dever hace 3 años
padre
commit
011812324e
Se han modificado 1 ficheros con 9 adiciones y 2 borrados
  1. 9 2
      app/shop/src/Buy.php

+ 9 - 2
app/shop/src/Buy.php

@@ -170,12 +170,19 @@ class Buy extends Core
                 $where['num'] = $num;
                 
                 # 验证库存
-                Dever::load('shop/lib/info')->checkTotal($where['num'], $info['goods_id'], $this->shop_id, $info['sku_id'], 2);
+                $total = Dever::load('shop/lib/info')->checkTotal($num, $info['goods_id'], $this->shop_id, $info['sku_id']);
+
+                if ($where['num'] > $total) {
+                    # 库存不足
+                    $where['num'] = $total;
+                    $state = Dever::db('shop/cart')->update($where); 
+                    return array('cart' => 2, 'data' => $total);
+                }
                 $state = Dever::db('shop/cart')->update($where); 
             }
         }
 
-        return $this->getCart();
+        return array('cart' => 1, 'data' => $this->getCart());
     }
 
     # 确认订单页面