dever преди 3 години
родител
ревизия
63b6e2e878
променени са 7 файла, в които са добавени 129 реда и са изтрити 7 реда
  1. 12 0
      app/goods/database/info.php
  2. 17 5
      app/goods/database/info_sku.php
  3. 66 0
      app/goods/lib/Info.php
  4. 2 1
      app/goods/lib/Set.php
  5. 12 0
      app/goods/lib/Sku.php
  6. 6 0
      app/mshop/src/My.php
  7. 14 1
      app/shop/database/info.php

+ 12 - 0
app/goods/database/info.php

@@ -247,6 +247,18 @@ $config = array
             'match'     => 'is_numeric',
         ),
 
+        'code'      => array
+        (
+            'type'      => 'varchar-100',
+            'name'      => '商品条码号',
+            'default'   => '',
+            'desc'      => '商品条码号',
+            'match'     => 'is_string',
+            'update'    => 'text',
+            'search'    => 'fulltext',
+            'list'      => true,
+        ),
+
         'price'     => array
         (
             'type'      => 'varchar-100',

+ 17 - 5
app/goods/database/info_sku.php

@@ -66,6 +66,18 @@ $config = array
             'option'    => $type,
         ),
 
+        'code'      => array
+        (
+            'type'      => 'varchar-100',
+            'name'      => '商品条码号',
+            'default'   => '',
+            'desc'      => '商品条码号',
+            'match'     => 'is_string',
+            'update'    => 'text',
+            'search'    => 'fulltext',
+            'list'      => true,
+        ),
+
         'price'     => array
         (
             'type'      => 'varchar-100',
@@ -225,7 +237,7 @@ $config = array
             ),
             'type' => 'all',
             'order' => array('id' => 'desc'),
-            'col' => 'id,info_id,`key`,price,s_price,f_price,type,min',
+            'col' => 'id,info_id,`key`,price,s_price,f_price,type,min,code',
         ),
 
         # 列表
@@ -239,7 +251,7 @@ $config = array
             ),
             'type' => 'all',
             'order' => array('id' => 'desc'),
-            'col' => 'id,info_id,`key`,price,s_price,f_price,min|key',
+            'col' => 'id,info_id,`key`,price,s_price,f_price,min,code|key',
         ),
 
         # 获取单条数据
@@ -252,7 +264,7 @@ $config = array
                 'state' => 1,
             ),
             'type' => 'one',
-            'col' => 'id,info_id,price,s_price,f_price,min',
+            'col' => 'id,info_id,price,s_price,f_price,min,code',
         ),
 
         'getMinOne' => array
@@ -265,7 +277,7 @@ $config = array
             ),
             'type' => 'one',
             'order' => array('price' => 'asc', 'id' => 'desc'),
-            'col' => 'id,info_id,price,s_price,min',
+            'col' => 'id,info_id,price,s_price,min,code',
         ),
 
         'getMaxOne' => array
@@ -278,7 +290,7 @@ $config = array
             ),
             'type' => 'one',
             'order' => array('price' => 'desc', 'id' => 'desc'),
-            'col' => 'id,info_id,price,s_price,min',
+            'col' => 'id,info_id,price,s_price,min,code',
         ),
 
         # 更新售出量

+ 66 - 0
app/goods/lib/Info.php

@@ -43,6 +43,72 @@ class Info
         }
     }
 
+    # 根据商品条形码获取商品
+    public function getGoodsByCode($type_id = false, $type = 1, $check = false)
+    {
+        $code = Dever::input('code');
+
+        if (!$code) {
+            Dever::alert('错误的条形码');
+        }
+        $where['code'] = $code;
+        $sku = Dever::db('goods/info_sku')->find($where);
+
+        if (!$sku) {
+            Dever::alert('商品不存在');
+        }
+
+        $goods = Dever::db('goods/info')->find($sku['info_id']);
+
+        if (!$goods) {
+            Dever::alert('商品不存在');
+        }
+        if ($goods['status'] != 1) {
+            Dever::alert('商品已下架');
+        }
+
+        if ($type_id > 0) {
+            if ($type == 1) {
+                $table = 'shop/goods_sku';
+                $col = 'shop_id';
+                $name = '门店';
+            } elseif ($type == 2) {
+                $table = 'store/goods_sku';
+                $col = 'store_id';
+                $name = '仓库';
+            } elseif ($type == 3) {
+                $table = 'factory/goods_sku';
+                $col = 'factory_id';
+                $name = '工厂';
+            }
+
+            $where = array();
+            $where[$col] = $type_id;
+            $where['goods_id'] = $goods['id'];
+            $where['sku_id'] = $sku['id'];
+            $data = Dever::db($table)->getOne($where);
+            if (!$data) {
+                if ($sku['key'] == -1) {
+                    $where['sku_id'] = -1;
+                    $data = Dever::db($table)->getOne($where);
+                    if (!$data) {
+                        Dever::alert($name . '商品不存在');
+                    }
+                } else {
+                    Dever::alert($name . '商品不存在');
+                }
+            }
+
+            if ($check && $data['total'] <= 0) {
+                # 验证库存
+                Dever::alert($name . '商品库存不足');
+            }
+        }
+
+        $goods['sku'] = $sku;
+        return $goods;
+    }
+
     private function setAttr($cate, $order = 'list_reorder')
     {
         if ($order != 'list_reorder') {

+ 2 - 1
app/goods/lib/Set.php

@@ -24,7 +24,7 @@ class Set
                 $sku = Dever::db('goods/info_sku')->select(array('info_id' => $v['id']));
 
                 if ($sku) {
-                    $other = Dever::db($table)->find(array($type => $id, 'goods_id' => $v['id'], 'key' => -1));
+                    $other = Dever::db($table)->find(array($type => $id, 'goods_id' => $v['id'], 'sku_id' => -1));
                     $result[$i]['id'] = $v['id'];
                     $result[$i]['name'] = $v['name'];
                     $result[$i]['price'] = $v['price'];
@@ -52,6 +52,7 @@ class Set
                     $result[$i]['children'] = array();
                     $num = count($sku);
                     if ($num == 1 && $sku[0]['key'] == -1) {
+                        //$result[$i]['id'] .=  '-' . $sku[0]['id'];
                         $result[$i]['end'] = true;
                     } else {
                         foreach ($sku as $k1 => $v1) {

+ 12 - 0
app/goods/lib/Sku.php

@@ -9,6 +9,7 @@ class Sku
     # 设置sku特殊字段
     private $col = array
     (
+        'code' => '商品条码号',
         's_price' => '市场价',
         'f_price' => '采购价',
         'price' => '销售价',
@@ -114,6 +115,12 @@ class Sku
             }
 
             $where[$key] = -1;
+            /*
+            if ($config['other']) {
+                $info_sku = Dever::db('goods/info_sku')->one(array('goods_id' => $config['goods_id'], 'key' => -1));
+                $where[$key] = $info_sku['id'];
+            }
+            */
 
             $info = Dever::db($sku_table)->one($where);
 
@@ -700,6 +707,11 @@ class Sku
         }
         
         if ($key == -1) {
+            /*
+            if (isset($sku_value[$sku[$key]['id']]) && isset($sku_value[$sku[$key]['id']][$k1])) {
+                $value = $sku_value[$sku[$key]['id']][$k1];
+            } 
+            */
             if (isset($sku_value[-1]) && isset($sku_value[-1][$k1])) {
                 $value = $sku_value[-1][$k1];
             } elseif (isset($sku[-1]) && isset($sku[-1][$k1])) {

+ 6 - 0
app/mshop/src/My.php

@@ -495,4 +495,10 @@ class My extends Core
         return $this->data;
     }
 
+    # 根据商品条形码编号获取商品
+    public function getGoods()
+    {
+        return Dever::load('goods/lib/info')->getGoodsByCode($this->shop_id, 1, true);
+    }
+
 }

+ 14 - 1
app/shop/database/info.php

@@ -75,6 +75,7 @@ return array
     'order' => 99,
     'act' => $act,
     'config_col' => $col,
+    'check' => 'sid',
 
     'end' => array
     (
@@ -92,7 +93,7 @@ return array
             'desc'      => '',
             'match'     => 'is_numeric',
             'search'    => 'order',
-            'list'      => true,
+            //'list'      => true,
             'order'     => 'desc',
         ),
 
@@ -120,6 +121,18 @@ return array
             ),
             //'list'      => '{uid} > 0 ? Dever::load("passport/user-find#username", {uid}) : "匿名用户"',
         ),
+
+        'sid'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '店铺编号-一般为5位数字,不能重复',
+            'default'   => '',
+            'desc'      => '店铺编号',
+            'match'     => 'is_numeric',
+            'update'    => 'text',
+            'search'    => 'fulltext',
+            'list'      => true,
+        ),
         
         'name'      => array
         (