dever 3 gadi atpakaļ
vecāks
revīzija
4898a5056f

+ 7 - 3
app/factory/lib/Sku.php

@@ -6,9 +6,13 @@ use Dever;
 
 class Sku
 {
-    # 设置sku特殊字段
-	public $col = array
+    # 设置sku
+	public $set = array
     (
-        'p_price' => '出厂价',
+    	# 设置特殊字段
+    	'col' => array
+    	(
+    		'p_price' => '出厂价',
+    	),
     );
 }

+ 2 - 2
app/goods/assets/manage/html/sku.html

@@ -5,8 +5,8 @@
 <input type="hidden" name="other_id" id="other_id" value="">
 <input type="hidden" name="function" id="function" value="skuMsg">
 <iframe id="f10" name="f10" style="display:none;"></iframe>
-<div class="layui-form-item">
-    <table class="layui-table" id="sku">
+<div class="layui-form-item" id="sku">
+    <table class="layui-table">
       <thead>
         <tr>
           <th>昵称</th>

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

@@ -560,6 +560,7 @@ class Info
                             'id' => $v['id'],
                             'info_id' => $v['info_id'],
                             'name' => $v['name'],
+                            'parent_name' => $data['name'],
                             'icon' => $v['icon'],
                             'value' => $key,
                         );
@@ -570,6 +571,7 @@ class Info
             
             $info['sell_attr'][] = $data;
         } elseif ($data['is_sell'] == 3) {
+            print_r($data);die;
             $info['option_attr'][] = $data;
         }
     }

+ 123 - 39
app/goods/lib/Sku.php

@@ -37,30 +37,33 @@ class Sku
         $data['key'] = Dever::input('key');
         $data['hook'] = Dever::input('hook');
 
-        $data['col'] = $this->getCol($data['other']);
+        $data['set'] = $this->getSet($data['other']);
         return $data;
     }
 
-    private function getCol($other)
+    private function getSet($other)
     {
         if ($other) {
             if (Dever::project($other)) {
-                $col = Dever::load($other . '/lib/sku')->col;
+                $set = Dever::load($other . '/lib/sku')->set;
+                if (!isset($set['price_type'])) {
+                    $set['price_type'] = false;
+                }
             } else {
                 Dever::alert($other . '不存在');
             }
         } else {
-            $col = $this->col;
+            $set = array('col' => $this->col, 'price_type' => false);
         }
 
-        return $col;
+        return $set;
     }
 
     public function show()
     {
         $config = Dever::load('goods/lib/sku')->config();
 
-        return $this->table($config['goods_id'], $config['other'], $config['other_id'], $config['col'], true);
+        return $this->table($config['goods_id'], $config['other'], $config['other_id'], $config['set'], true);
     }
 
     public function update_api()
@@ -90,7 +93,7 @@ class Sku
             }
 
             $update = $where;
-            foreach ($config['col'] as $k => $v) {
+            foreach ($config['set']['col'] as $k => $v) {
                 $update[$k] = Dever::input($k);
             }
 
@@ -141,7 +144,7 @@ class Sku
                         $data[$key] = $v;
                     }
                     
-                    foreach ($config['col'] as $k1 => $v1) {
+                    foreach ($config['set']['col'] as $k1 => $v1) {
                         $value = Dever::input($k1);
                         $cur_sku = false;
                         if (isset($value[$k])) {
@@ -179,7 +182,7 @@ class Sku
                 if ($sku_id) {
                     $update['sku_id'] = $sku_id;
                 }
-                foreach ($config['col'] as $k => $v) {
+                foreach ($config['set']['col'] as $k => $v) {
                     if (isset($min[$k])) {
                         $update[$k] = $min[$k];
                     }
@@ -194,28 +197,31 @@ class Sku
         Dever::out('yes');
     }
 
-    public function table($goods, $other = false, $other_id = false, $col = false, $update = true, $parent_goods = false)
+    public function table($goods, $other = false, $other_id = false, $set = false, $update = true, $parent_goods = false)
     {
-        if (!$col) {
-            $col = $this->getCol($other);
+        if (!$set) {
+            $set = $this->getSet($other);
         }
         $info = is_array($goods) ? $goods : Dever::db('goods/info')->one($goods);
         $info = Info::init(-1)->info($info, 'view_reorder');
 
-        if ($info && $info['price_type'] == 4) {
-            if ($update) {
-                return '组合商品无法设置库存';
-            }
-            if ($info['goods'] && is_array($info['goods'])) {
-                $html = '';
-                foreach ($info['goods'] as $k => $v) {
-                    $html .= $this->table($v['id'], $other, $other_id, $col, $update, $v) . '<br />';
+        if ($info && $other && isset($set['price_type']) && $set['price_type']) {
+            $price_type = explode(',', $set['price_type']);
+            if (in_array($info['price_type'], $price_type)) {
+                if ($update) {
+                    return '组合商品无法设置库存';
                 }
+                if ($info['goods'] && is_array($info['goods'])) {
+                    $html = '';
+                    foreach ($info['goods'] as $k => $v) {
+                        $html .= $this->table($v['id'], $other, $other_id, $set, $update, $v) . '<br />';
+                    }
 
-                $html .= '*组合商品的库存为以上商品中的最低库存为准';
-                return $html;
-            } else {
-                return '';
+                    $html .= '*组合商品的库存为以上商品中的最低库存为准';
+                    return $html;
+                } else {
+                    return '';
+                }
             }
         }
 
@@ -229,24 +235,37 @@ class Sku
 
         $sku = Dever::db('goods/info_sku')->getDataByKeys(array('info_id' => $info['id']));
 
-        $option = array();
-        $head = '<thead><tr>';
+        $sell_attr = $option_attr = array();
+        $head = $option_head = '<thead><tr>';
         $html = '请先选择属性';
 
+        if ($parent_goods) {
+            $head .= '<th>商品名称</th>';
+            $option_head .= '<th>商品名称</th>';
+        }
+
         if (isset($info['sell_attr']) && $info['sell_attr']) {
             foreach ($info['sell_attr'] as $k => $v) {
                 $head .= '<th>'.$v['name'].'</th>';
                 if (isset($v['option_sku'])) {
-                    $option[$k] = $v['option_sku'];
+                    $sell_attr[$k] = $v['option_sku'];
                 }
             }
         }
 
-        $col_num = 0;
-        if ($parent_goods) {
-            $head .= '<th>商品名称</th>';
+        if (isset($info['option_attr']) && $info['option_attr']) {
+            $option_head .= '<th>属性名称</th>';
+            foreach ($info['option_attr'] as $k => $v) {
+                if (isset($v['option'])) {
+                    $option_attr = array_merge($option_attr, $v['option']);
+                }
+            }
         }
-        foreach ($col as $k => $v) {
+
+
+        $col_num = 0;
+        
+        foreach ($set['col'] as $k => $v) {
             if (!$update && strstr($v, '^')) {
                 continue;
             }
@@ -259,13 +278,18 @@ class Sku
             }
             
             $head .= '<th>'.$v.'</th>';
+            $option_head .= '<th>'.$v.'</th>';
         }
         
         $head .= '</tr></thead>';
+        $option_head .= '</tr></thead>';
 
         $body = '<tbody>';
+        $option_body = '<tbody>';
 
-        if (!$option) {
+        if (!$sell_attr) {
+
+            $prefix = '[单价设置]:';
 
             if (!$update && $col_num <= 1) {
                 $head = '';
@@ -277,10 +301,10 @@ class Sku
             $body .= '<tr>';
 
             if ($parent_goods) {
-                $body .= '<td>'.$parent_goods['name'].'</td>';
+                $body .= '<td width="10">'.$parent_goods['name'].'</td>';
             }
 
-            foreach ($col as $k1 => $v1) {
+            foreach ($set['col'] as $k1 => $v1) {
                 if (!$update && strstr($v1, '^')) {
                     continue;
                 } 
@@ -310,11 +334,13 @@ class Sku
 
         } else {
             
-            $option = Dever::cartesian($option);
+            $prefix = '[多价设置]:';
+
+            $sell_attr = Dever::cartesian($sell_attr);
 
             $show = false;
 
-            foreach ($option as $k => $v) {
+            foreach ($sell_attr as $k => $v) {
                 $body .= '<tr data-row="' .($k+1). '">';
 
                 if ($parent_goods) {
@@ -334,7 +360,7 @@ class Sku
                 }
                 $key = implode('_', $key);
 
-                foreach ($col as $k1 => $v1) {
+                foreach ($set['col'] as $k1 => $v1) {
                     if (!$update && strstr($v1, '^')) {
                         continue;
                     } 
@@ -372,9 +398,67 @@ class Sku
                 
         $html = $head . $body;
 
-        if (!$update) {
-            $html = '<table>' . $html . '</table>';
+        if ($update) {
+            $html = $prefix . '<table class="layui-table">' . $html . '</table>';
+        } else {
+            $html = '<table class="layui-table">' . $html . '</table>';
+        }
+
+        if ($option_attr) {
+            print_r($option_attr);die;
+            foreach ($option_attr as $k => $v) {
+
+                $option_body .= '<tr data-row="' .($k+1). '">';
+
+                if ($parent_goods) {
+                    $option_body .= '<td>'.$parent_goods['name'].'</td>';
+                }
+
+                $rows = 1;
+                $option_body .= '<td width="50" rowspan="'.$rows.'">'.$v['parent_name'] . '-' . $v['name'].'</td>';
+                $id = array
+                (
+                    'id' => $v['id'],
+                    'attr_id' => $v['info_id'],
+                );
+                $key = $v['info_id'] . '-' . $v['id'];
+
+                foreach ($set['col'] as $k1 => $v1) {
+                    if (!$update && strstr($v1, '^')) {
+                        continue;
+                    } 
+                    $value = '';
+                    if (isset($sku[$key])) {
+                        if (isset($sku_value[$sku[$key]['id']][$k1])) {
+                            $value = $sku_value[$sku[$key]['id']][$k1];
+                        } elseif (isset($sku[$key][$k1])) {
+                            $value = $sku[$key][$k1];
+                        }
+                    }
+                    
+                    if ($update) {
+                        if (strstr($v1, '|')) {
+                            $v1 = str_replace('|', '', $v1);
+                            $option_body .= '<td width="30">'.$value.'</td>';
+                        } else {
+                            $option_body .= '<td width="30"><input type="text" class="layui-input" name="'.$k1.'['.$k.']"  value="'.$value.'"/></td>';
+                        }
+                        
+                    } else {
+                        $option_body .= '<td width="30">'.$value.'</td>';
+                    }
+                }
+
+                if ($update) {
+                    $option_body .= '<input type="hidden" name="key['.$k.']" value="'.$key.'"/><textarea style="display:none;" name="attr['.$k.']">'.json_encode($id).'</textarea>';
+                }
+                
+                $option_body .= '</tr>';
+            }
+
+            $html = $html . '<br />[加价设置]:<table class="layui-table">' . $option_head . $option_body . '</table>';;
         }
+        
 
         return $html;
     }

+ 9 - 14
app/mshop/lib/Buy.php

@@ -39,16 +39,14 @@ class Buy
         }
 
         foreach($goods as $k => $v) {
-            if ($v['ku_state'] == 1) {
-                $data['shop_id'] = $shop['id'];
-                $data['order_id'] = $id;
-                $data['goods_id'] = $v['id'];
-                $data['sku_id'] = $v['sku_id'];
-                $data['price'] = $v['price'];
-                $data['num'] = $v['buy_num'];
-
-                Dever::db('shop/buy_order_goods')->insert($data);
-            }
+            $data['shop_id'] = $shop['id'];
+            $data['order_id'] = $id;
+            $data['goods_id'] = $v['id'];
+            $data['sku_id'] = $v['sku_id'];
+            $data['price'] = $v['price'];
+            $data['num'] = $v['buy_num'];
+
+            Dever::db('shop/buy_order_goods')->insert($data);
         }
 
         if ($card || $price <= 0) {
@@ -150,12 +148,9 @@ class Buy
         if ($order && $order['pay_status'] == 1) {
 
             if ($status == 2) {
-                # 减少库存 增加销量
-                $this->updateSell($order);
-
                 # 发消息
                 if (Dever::project('message')) {
-                    Dever::load('message/lib/data')->push(-1, $order['uid'], '订购成功通知', '购买成功', 1);
+                    Dever::load('message/lib/data')->push(-1, $order['shop_id'], '订购成功通知', '购买成功', 1);
                 }
             }
 

+ 2 - 2
app/shop/lib/Sell.php

@@ -218,10 +218,10 @@ class Sell
                     Dever::load('message/lib/data')->push(-1, $order['uid'], '订购成功通知', '购买成功', 1);
                 }
 
-                # 如果是自提订单,生成自提码
+                # 生成自提码或者取件码
+                $update['code'] = $this->getCode();
                 if ($order['method'] == 1) {
                 	$update['code_status'] = 2;
-                	$update['code'] = $this->getCode();
                 } else {
                 	$update['ps_status'] = 2;
                 }

+ 12 - 5
app/shop/lib/Sku.php

@@ -6,11 +6,18 @@ use Dever;
 
 class Sku
 {
-    # 设置sku特殊字段
-	public $col = array
+    # 设置sku
+	public $set = array
     (
-        'add_num' => '新增库存数^-输入小于0的数字,则为减少库存',
-        'total' => '当前库存|',
-        'total_num' => '总库存|',
+    	# 设置特殊字段
+    	'col' => array
+    	(
+    		'add_num' => '新增库存数^-输入小于0的数字,则为减少库存',
+	        'total' => '当前库存|',
+	        'total_num' => '总库存|',
+    	),
+
+    	# 设置哪个商品类型无法设置上述字段
+    	'price_type' => 4,
     );
 }

+ 12 - 5
app/store/lib/Sku.php

@@ -6,11 +6,18 @@ use Dever;
 
 class Sku
 {
-    # 设置sku特殊字段
-	public $col = array
+    # 设置sku
+	public $set = array
     (
-        'add_num' => '新增库存数^-输入小于0的数字,则为减少库存',
-        'total' => '当前库存|',
-        'total_num' => '总库存|',
+    	# 设置特殊字段
+    	'col' => array
+    	(
+    		'add_num' => '新增库存数^-输入小于0的数字,则为减少库存',
+	        'total' => '当前库存|',
+	        'total_num' => '总库存|',
+    	),
+
+    	# 设置哪个商品类型无法设置上述字段
+    	'price_type' => 4,
     );
 }