dever 3 years ago
parent
commit
1f29a055d4
2 changed files with 19 additions and 2 deletions
  1. 5 1
      app/goods/lib/Info.php
  2. 14 1
      app/mshop/src/Data.php

+ 5 - 1
app/goods/lib/Info.php

@@ -44,7 +44,7 @@ class Info
     }
 
     # 根据商品条形码获取商品
-    public function getGoodsByCode($type_id = false, $type = 1, $check = false)
+    public function getGoodsByCode($type_id = false, $type = 1, $check = true)
     {
         $code = Dever::input('code');
 
@@ -105,6 +105,10 @@ class Info
             }
         }
 
+        if ($sku['key'] == -1) {
+            $sku['id'] = -1;
+        }
+
         $goods['sku'] = $sku;
         return $goods;
     }

+ 14 - 1
app/mshop/src/Data.php

@@ -318,6 +318,19 @@ class Data extends Core
         return $this->data['cart'];
     }
 
+    # 扫码加入购物车
+    public function scan()
+    {
+        $goods = Dever::load('goods/lib/info')->getGoodsByCode($this->shop_id, 1, true);
+        if ($goods) {
+            Dever::setInput('goods_id', $goods['id']);
+            Dever::setInput('price_id', $goods['sku']['id']);
+
+            return $this->addCart();
+        }
+        Dever::alert('错误的商品');
+    }
+
     # 加入到购物车
     public function addCart()
     {
@@ -330,7 +343,7 @@ class Data extends Core
 
         $info = Dever::db('shop/shop_cart')->find($where);
 
-        $where['num'] = Dever::input('num');
+        $where['num'] = Dever::input('num', 1);
         if (!$info) {
             # 验证库存
             Dever::load('shop/lib/info')->checkTotal($where['num'], $where['goods_id'], $this->shop_id, $where['sku_id'], 2);