rabin 3 rokov pred
rodič
commit
5fe2546a8d

+ 1 - 1
assets/layadmin/html/inc/script.html

@@ -39,4 +39,4 @@
 <script type="text/javascript" src="../script/lib/excel/excel.js?v16"></script>
 
 <!-- 加载主要js,很乱,后续优化 -->
-<script type="text/javascript" src="../script/lib/manage/main.js?v300"></script>
+<script type="text/javascript" src="../script/lib/manage/main.js?v303"></script>

+ 15 - 5
assets/layadmin/html/project/database/update.html

@@ -78,8 +78,8 @@
   
   <script class="include" system="" path="inc/" file="script">include()</script>
   <script id="update_script">
-  var skuTable;
   var form;
+  var skuTable;
   layui.config({
     base: '../script/lib/layui/admin/' //静态资源所在路径
     ,version:true
@@ -94,6 +94,10 @@
     var formSelects = layui.formSelects;
     skuTable = layui.skuTable;
 
+    if ($('#sku_spec_type').length) {
+        sku($('#sku_spec_type'));
+    }
+
     /*
     $('select').each(function() {
         if ($(this).attr('xm-value')) {
@@ -101,16 +105,17 @@
         }
     });
     */
+
     /*
-    var obj = skuTable.render({
+    var obj = layui.skuTable.render({
             //规格类型 0统一规格 1多规格
             isAttributeValue: 0,
             //规格类型容器id
-            isAttributeElemId: 'fairy-is-attribute',
+            isAttributeElemId: 'sku_spec_type',
             //规格表容器id
-            specTableElemId: 'fairy-spec-table',
+            specTableElemId: 'sku_spec_table',
             //sku表容器id
-            skuTableElemId: 'fairy-sku-table',
+            skuTableElemId: 'sku_table',
             //规格拖拽排序
             sortable: false,
             //sku表相同属性值是否合并行
@@ -123,11 +128,13 @@
             //统一规格配置项
             singleSkuTableConfig: {
                 thead: [
+                    {title: '商品编码', icon: 'layui-icon-cols'},
                     {title: '销售价(元)', icon: 'layui-icon-cols'},
                     {title: '采购价(元)', icon: 'layui-icon-cols'},
                     {title: '成本价(元)', icon: 'layui-icon-cols'},
                 ],
                 tbody: [
+                    {type: 'input', field: 'code', value: '', verify: 'required', reqtext: '商品编码不能为空'},
                     {type: 'input', field: 'price', value: '0', verify: 'required|number', reqtext: '销售价不能为空'},
                     {type: 'input', field: 'buy_price', value: '0', verify: 'required|number', reqtext: '采购价不能为空'},
                     {type: 'input', field: 'cost_price', value: '0', verify: 'required|number', reqtext: '成本价不能为空'},
@@ -137,12 +144,14 @@
             multipleSkuTableConfig: {
                 thead: [
                     {title: '图片', icon: ''},
+                    {title: '商品编码', icon: 'layui-icon-cols'},
                     {title: '销售价(元)', icon: 'layui-icon-cols'},
                     {title: '采购价(元)', icon: 'layui-icon-cols'},
                     {title: '成本价(元)', icon: 'layui-icon-cols'},
                 ],
                 tbody: [
                     {type: 'image', field: 'pic', value: '', verify: '', reqtext: ''},
+                    {type: 'input', field: 'code', value: '', verify: 'required', reqtext: '商品编码不能为空'},
                     {type: 'input', field: 'price', value: '0', verify: 'required|number', reqtext: '销售价不能为空'},
                     {type: 'input', field: 'buy_price', value: '0', verify: 'required|number', reqtext: '采购价不能为空'},
                     {type: 'input', field: 'cost_price', value: '0', verify: 'required|number', reqtext: '成本价不能为空'},
@@ -178,6 +187,7 @@
                     ]
                 }
             ],
+            specData: [],
             //获取规格数据接口地址,如果为空或者不配置则使用 specData 参数配置
             //接口要求返回格式参考 specData.json
             // specDataUrl: './json/specData.json',

+ 10 - 3
database/admin.php

@@ -883,11 +883,18 @@ return array
 	*/
 	
 	# 索引
+	/*
 	'index' => array
 	(
-		# 索引名 => 索引id
-		//'id' => 'id,state',
-	),
+		1 => array
+		(
+			# 索引名 => 索引id 如果有后缀.unique,则为建立索引的类型,如id,state.unique
+			'id' => 'id,state',
+		),
+		
+		# 版本号 更改版本号会更新当前表的索引
+		'version' => 1,
+	),*/
 	
 	# request 请求接口定义
 	'request' => array

+ 85 - 49
src/Database.php

@@ -3342,6 +3342,11 @@ class Database
                     $v['upload_call'] = $upload_call . '&key=' . $k;
                 }
 
+                if (isset($config['manage']['sku']) && $v['update'] == 'sku') {
+                    $v['sku'] = $config['manage']['sku'];
+                    $v['data'] = $data;
+                }
+
                 $result[$k] .= $this->create_update_html($k, $v, $data, false, $prefix);
 
                 $result[$k] .= '</div></div>';
@@ -3716,9 +3721,7 @@ class Database
                     $param['upload_search_value'] = $this->value($param['upload_search_value'], $data + $param);
                 }
 
-                if ($param['update'] == 'load') {
-                    $param['where_id'] = $this->id;
-                }
+                $param['where_id'] = $this->id;
 
                 $result .= Html::$method($param);
             }
@@ -4161,60 +4164,95 @@ class Database
                         }
                     }
 
-                    if (isset($config['manage']['sku'])) {
-                        $spec_table = $config['manage']['sku']['spec'];
-                        $sku_table = $config['manage']['sku']['sku'];
-                    }
-
-                    /*
-                    [{"id":1,"title":"颜色","child":[{"id":"1","title":"红","checked":true},{"id":"2","title":"黄","checked":false},{"id":"3","title":"蓝","checked":false}]},{"id":2,"title":"尺码","child":[{"id":"4","title":"S","checked":true},{"id":"5","title":"M","checked":true},{"id":"6","title":"L","checked":false},{"id":"7","title":"XL","checked":false}]},{"id":3,"title":"款式","child":[{"id":"8","title":"男款","checked":true},{"id":"9","title":"女款","checked":true}]},{"id":"4w627wudvpy000","title":"test","child":[{"id":"2kct9uahekm000","title":"111","checked":true},{"id":"vishp09dv4000","title":"222","checked":true}]}]
+                    $this->spec($id, $config);
+                }
+            }
+        }
 
-                    skus[1-4-8-2kct9uahekm000][price]: 0
-                    */
+        Dever::out('yes');
+    }
 
-                    $spec = Dever::input('spec');
-                    $sku = Dever::input('skus');
-                    if ($spec && $sku) {
-                        if (!isset($spec_table)) {
-                            $spec_table = 'info_spec';
+    private function spec($id, $config)
+    {
+        if (isset($config['manage']['sku'])) {
+            $spec_table = $config['manage']['sku']['spec'];
+            $sku_table = $config['manage']['sku']['sku'];
+        }
+        if (!isset($sku_table)) {
+            $sku_table = 'info_sku';
+        }
+        $sku_table = $this->project . '/' . $sku_table;
+
+        $spec_type = Dever::input('update_spec_type');
+        if ($spec_type == 2) {
+            $spec = Dever::input('spec');
+            $sku = Dever::input('skus');
+            if ($spec && $sku) {
+                if (!isset($spec_table)) {
+                    $spec_table = 'info_spec';
+                }
+                $spec_table = $this->project . '/' . $spec_table;
+                $spec_value_table = $spec_table . '_value';
+                $spec = Dever::json_decode($spec);
+                if ($spec) {
+                    $sku_id = array();
+                    Dever::db($spec_table)->updates(array('option_info_id' => $id, 'set_state' => 2));
+                    Dever::db($spec_value_table)->updates(array('option_info_id' => $id, 'set_state' => 2));
+                    foreach ($spec as $k1 => $v1) {
+                        if (is_numeric($v1['id'])) {
+                            $spec_id = Dever::db($spec_table)->update(array('where_id' => $v1['id'], 'set_state' => 1));
+                        } else {
+                            $spec_id = Dever::db($spec_table)->insert(array('name' => $v1['title'], 'info_id' => $id));
                         }
-                        $spec_table = $this->project . '/' . $spec_table;
-                        $spec_value_table = $spec_table . '_value';
-                        $spec = Dever::json_decode($spec);
-                        if ($spec) {
-                            $sku_id = array();
-                            Dever::db($spec_table)->updates(array('option_info_id' => $id, 'set_state' => 2));
-                            Dever::db($spec_value_table)->updates(array('option_info_id' => $id, 'set_state' => 2));
-                            foreach ($spec as $k1 => $v1) {
-                                if (is_numeric($v1['id'])) {
-                                    $spec_id = Dever::db($spec_table)->update(array('where_id' => $v1['id'], 'set_state' => 1));
-                                } else {
-                                    $spec_id = Dever::db($spec_table)->insert(array('name' => $v1['title'], 'info_id' => $id));
-                                }
-                                foreach ($v1['child'] as $k2 => $v2) {
-                                    if (is_numeric($v2['id'])) {
-                                        $sku_id[$v2['id']] = Dever::db($spec_value_table)->update(array('where_id' => $v2['id'], 'set_state' => 1));
-                                    } else {
-                                        $v2['checked'] = $v2['checked'] ? 1 : 2;
-                                        $sku_id[$v2['id']] = Dever::db($spec_value_table)->insert(array('value' => $v2['title'], 'is_checked' => $v2['checked'], 'info_id' => $id, 'spec_id' => $spec_id));
-                                    }
-                                }
-                            }
-
-                            //Dever::db($spec_table)->delete(array('info_id' => $id, 'state' => 2));
-                            if ($sku_id) {
-                                foreach ($sku as $k1 => $v1) {
-                                    $temp = explode('-', $k1);
-                                }
+                        foreach ($v1['child'] as $k2 => $v2) {
+                            $v2['checked'] = $v2['checked'] ? 1 : 2;
+                            if (is_numeric($v2['id'])) {
+                                Dever::db($spec_value_table)->update(array('where_id' => $v2['id'], 'set_state' => 1, 'set_is_checked' => $v2['checked']));
+                            } else {
+                                $sku_id[$v2['id']] = Dever::db($spec_value_table)->insert(array('value' => $v2['title'], 'is_checked' => $v2['checked'], 'info_id' => $id, 'spec_id' => $spec_id));
                             }
                         }
                     }
+                    Dever::db($spec_table)->delete(array('info_id' => $id, 'state' => 2));
+                    Dever::db($spec_value_table)->delete(array('info_id' => $id, 'state' => 2));
+
+                    $this->sku($id, $sku_table, $sku, $sku_id);
                 }
             }
-
+        } else {
+            $sku = Dever::input('skus');
+            if ($sku) {
+                $this->sku($id, $sku_table, $sku);
+            }
         }
+    }
 
-        Dever::out('yes');
+    private function sku($id, $sku_table, $sku, $sku_id = false)
+    {
+        Dever::db($sku_table)->updates(array('option_info_id' => $id, 'set_state' => 2));
+        foreach ($sku as $k1 => $v1) {
+            if ($sku_id) {
+                foreach ($sku_id as $k2 => $v2) {
+                    $k1 = str_replace($k2, $v2, $k1);
+                }
+            }
+
+            $sku_data = array();
+            $sku_data['info_id'] = $id;
+            $sku_data['key'] = $k1;
+            $sku_info = Dever::db($sku_table)->one($sku_data);
+            foreach ($v1 as $k3 => $v3) {
+                $sku_data[$k3] = $v3;
+            }
+            if ($sku_info) {
+                $sku_data['where_id'] = $sku_info['id'];
+                $sku_data['state'] = 1;
+                Dever::db($sku_table)->update($sku_data);
+            } else {
+                Dever::db($sku_table)->insert($sku_data);
+            }
+        }
+        Dever::db($sku_table)->delete(array('info_id' => $id, 'state' => 2));
     }
 
     public function struct_data($struct, $data, $old = array())
@@ -4330,8 +4368,6 @@ class Database
                     if ($old_name) {
                         $old[$i] = implode(',', $old_name);
                     }
-                    
-                    
                 }
 
                 if ($log[$j['name']] == 'null') {

+ 13 - 3
src/Lib/Input.php

@@ -1417,12 +1417,22 @@ class Input
      */
     public static function _sku($param)
     {
+        $col = Dever::json_encode($param['sku']['col']);
+        $param['sku']['api']['spec'] = Dever::url($param['sku']['api']['spec'] . '?json=1&id=' . $param['where_id']);
+        $param['sku']['api']['sku'] = Dever::url($param['sku']['api']['sku'] . '?json=1&id=' . $param['where_id']);
+        $param['sku']['api']['upload'] = Dever::url($param['sku']['api']['upload']);
+        if (isset($param['data']) && isset($param['data']['spec_type']) && $param['data']['spec_type']) {
+            $type = $param['data']['spec_type'];
+        } else {
+            $type = 1;
+        }
+
         $html = '<!-- 规格类型 -->
-        <div id="fairy-is-attribute"></div>
+        <div id="sku_spec_type" data-id="'.$param['where_id'].'" data-type="'.$type.'" data-spec="'.$param['sku']['api']['spec'].'" data-sku="'.$param['sku']['api']['sku'].'" data-upload="'.$param['sku']['api']['upload'].'"></div>
         <!--商品规格表-->
-        <div id="fairy-spec-table"></div>
+        <div id="sku_spec_table"></div>
         <!--商品库存表-->
-        <div id="fairy-sku-table"></div>';
+        <div id="sku_table"></div><div id="sku_table_col" style="display:none">'.$col.'</div>';
         return $html;
     }
 }

+ 2 - 1
src/Menu.php

@@ -888,13 +888,14 @@ class Menu
      */
     public function link()
     {
+        $link = Dever::input('link');
         return array
             (
             'project' => Dever::url('project/list?menu=manage&table=manage_project'),
             'log' => Dever::url('log/list?menu=manage&table=manage_log'),
             'logout' => Dever::url('auth.quit'),
             'index' => Dever::url('home'),
-            'console' => Dever::url('console'),
+            'console' => $link ? urldecode($link) : Dever::url('console'),
         );
     }