rabin 3 年之前
父節點
當前提交
b16cc6b954
共有 9 個文件被更改,包括 1074 次插入35 次删除
  1. 371 0
      assets/pc/html/set_price_goods.html
  2. 2 2
      database/category.php
  3. 14 14
      database/info.php
  4. 2 2
      database/info_sku.php
  5. 124 0
      database/price.php
  6. 243 0
      database/price_rule.php
  7. 187 0
      database/price_rule_sku.php
  8. 36 17
      lib/Info.php
  9. 95 0
      lib/Price.php

+ 371 - 0
assets/pc/html/set_price_goods.html

@@ -0,0 +1,371 @@
+<!doctype html>
+<html>
+<head>
+<meta charset="utf-8">
+<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0" />
+<meta name="author" content="siweiyong 2602812659@qq.com"/>
+<title>设置商品</title>
+<link rel="stylesheet" href="../script/lib/miniui/themes/default/miniui.css">
+<link rel="stylesheet" href="../script/lib/layui/css/layui.css" />
+<link rel="stylesheet" href="../script/lib/cashier/common.css">
+<link rel="stylesheet" href="../script/lib/layui/admin/modules/plugin/formselects/formselects.css" media="all" />
+<script src="../script/lib/jquery/jquery.min.js"></script>
+<script src="../script/lib/miniui/miniui.js"></script>
+<script src="../script/lib/layui/layui.js"></script>
+<script><{Dever::script()}></script>
+<script src="../script/dever/core.js"></script>
+</head>
+<body style="background: #F6F7F9;">
+<div class="main">
+<form class="layui-form" lay-filter="form">
+    <div class="layui-row">
+        <div class="main_left layui-col-xs12 layui-col-md3">
+            <div class="layui-row">
+                <div class="top">
+                    <i class="layui-icon layui-icon-app"></i>商品列表
+                </div>
+                <div class="left_main">
+                    <input id="key" class="mini-textbox" onenter="onKeyEnter" value="请输入商品名称" onclick="setVal('key')"/>
+                    <a class="mini-button" onclick="search()">查询</a> 
+                    <button class="layui-btn layui-btn-button" type="button" style="vertical-align: middle;margin-bottom: 2px;" onclick="addGoods()">一键添加</button>
+                    <button class="layui-btn layui-btn-button" type="button" style="vertical-align: middle;margin-bottom: 2px;" onclick="delGoods()">一键删除</button>
+                    <ul id="tree1" class="mini-tree" url="<{$url}>" showTreeIcon="true" textField="name" idField="id" expandOnLoad="true" onNodeClick="onNodeClick">
+                    </ul>
+                </div>
+            </div>
+        </div>
+        <div class="main_right layui-col-xs12 layui-col-md9">
+            <div class="layui-row">
+                <div class="top">
+                    <div class="layui-input-inline" style="margin-left:20px">
+                        <input id="search_key" class="mini-textbox" value="请输入商品名称" onclick="setVal('search_key')"/>
+                        <a class="mini-button" onclick="searchGoods()">搜索</a> 
+                    </div>
+                </div>
+                <div class="goods_list" style="height:645px;">
+                    <table class="layui-table">
+                        <thead>
+                            <tr>
+                                <th lay-data="{field:'id'}" width="15%">商品编码</th>
+                                <th lay-data="{field:'name'}" width="15%">商品名称</th>
+                                <{if($type == 1):}>
+                                <th lay-data="{field:'price', edit: 'text'}" width="10%">原销售价</th>
+                                <th lay-data="{field:'price', edit: 'text'}" width="10%">销售调价</th>
+                                <th lay-data="{field:'price', edit: 'text'}" width="10%">新销售价</th>
+
+                                <th lay-data="{field:'buy_price', edit: 'text'}" width="10%">原采购价</th>
+                                <th lay-data="{field:'buy_price', edit: 'text'}" width="10%">采购调价</th>
+                                <th lay-data="{field:'buy_price', edit: 'text'}" width="10%">新采购价</th>
+
+                                <{else:}>
+                                <th lay-data="{field:'price', edit: 'text'}" width="15%">原销售价</th>
+                                <th lay-data="{field:'price', edit: 'text'}" width="15%">新销售价</th>
+                                <th lay-data="{field:'buy_price', edit: 'text'}" width="15%">原采购价</th>
+                                <th lay-data="{field:'buy_price', edit: 'text'}" width="15%">新采购价</th>
+                                <{endif;}>
+                                <th lay-data="{field:'operation'}" width="15%">操作</th>
+                            </tr>
+                        </thead>
+                        <tbody id="goods">
+                            
+                        </tbody>
+                    </table>
+                </div>
+                <div class="towbtn">
+                    <input type="button" id="settlement" value="确认设置">
+                </div>
+            </div>
+        </div>
+    </div>
+</div>
+</form>
+</div>
+<script>
+    var form;
+    var goods = {};
+    var del_goods = {};
+    var tree = {};
+    var type = "<{$type}>";
+    var num = "<{$num}>";
+    layui.config(
+    {
+        base: '../script/lib/layui/admin/' //静态资源所在路径
+        ,version: true
+    }).extend(
+    {
+        index: 'lib/index', //主入口模块
+        formSelects: 'plugin/formselects/formselects'
+    }).use(['index', 'contlist', 'table', 'form', 'formSelects','layer'], function()
+    {
+        var table = layui.table;
+        form = layui.form; 
+        var formSelects = layui.formSelects;
+
+        mini.parse();
+        tree = mini.get("tree1");
+        for (var i in tree.data) {
+            if (typeof(tree.data[i].children) == 'object') {
+                if (tree.data[i].children.length > 0) {
+                    for (var j in tree.data[i].children) {
+                        if(tree.data[i].children[j].select == 1) {
+                            setGoods(tree.data[i].children[j]);
+                        }
+                    }
+                } else if(tree.data[i].select == 1) {
+                    setGoods(tree.data[i]);
+                }
+            }
+        }
+    });
+
+    $(function()
+    {
+        $("#settlement").click(function(){
+            var url = '<{$submit}>';
+            var price_rule_id = '<{$price_rule_id}>';
+
+            layui.layer.confirm('确定进行此项设置吗?', function() {
+                var goods_string = JSON.stringify(goods);
+
+                var data = {};
+                data = {price_rule_id:price_rule_id, goods:goods_string};
+                $.post(url, data, function(t) {
+                    t = JSON.parse(t);
+                    if (t.status == 1) {
+                        layui.layer.alert('商品设置成功', function(index){
+                          if (t.data == 'refer') {
+                                history.back();
+                            } else {
+                                location.href = t.data;
+                            }
+                          layer.close(index);
+                        });
+                    } else {
+                        layui.layer.alert(t.msg);
+                    }
+                });
+            });
+        });
+
+        $("#goods").on("keyup", ".goods_price", function() {
+        	var num = parseFloat($(this).find('input').val());
+            var id = $(this).parent().attr('value');
+            goods[id].price = num;
+            setTotal();
+        });
+
+        $("#goods").on("keyup", ".goods_buy_price", function() {
+        	var num = parseFloat($(this).find('input').val());
+            var id = $(this).parent().attr('value');
+            goods[id].buy_price = num;
+            setTotal();
+        });
+    })
+
+    function onNodeClick()
+    {
+        var tree=mini.get("tree1");
+        node=tree.getSelectedNode();
+        if(node.end) {
+            setGoods(node);
+        }
+    }
+
+    function setVal(e)
+    {
+        mini.get(e).setValue('');
+    }
+
+    function searchGoods() 
+    {
+        var key = mini.get("search_key").getValue();
+
+        if (key == "") {
+            $(".mytr").show();
+        } else {
+            key = key.toLowerCase(); 
+            $(".mytr").show();               
+            $(".goods_name").each(function(t) {
+                var name = $(this).html();
+                name = name.toLowerCase(); 
+                if (name.indexOf(key) == -1) {
+                    $(this).parent().hide();
+                }
+            });
+        }
+    }
+
+    // 一键添加
+    function addGoods()
+    {
+        var key = mini.get("key").getValue();
+        if (key == '请输入商品名称') {
+            key = '';
+        }
+        if (key) {
+            key = key.toLowerCase();
+        }
+        for (var i in tree.data) {
+            if (typeof(tree.data[i].children) == 'object') {
+                if (tree.data[i].children.length > 0) {
+                    for (var j in tree.data[i].children) {
+                        if (key) {
+                            var name = tree.data[i].children[j].name;
+                            if (name.indexOf(key) != -1) {
+                                setGoods(tree.data[i].children[j]);
+                            }
+                        } else {
+                            setGoods(tree.data[i].children[j]);
+                        }
+                    }
+                } else {
+                    if (key) {
+                        var name = tree.data[i].name;
+                        if (name.indexOf(key) != -1) {
+                            setGoods(tree.data[i]);
+                        }
+                    } else {
+                        setGoods(tree.data[i]);
+                    }
+                }
+            }
+        }
+    }
+
+    // 一键删除
+    function delGoods()
+    {
+        if (confirm('确定删除吗?')) {
+            var key = mini.get("key").getValue();
+            if (key == '请输入商品名称') {
+                key = '';
+            }
+            if (key) {
+                key = key.toLowerCase();
+            }
+            for (var i in tree.data) {
+                if (typeof(tree.data[i].children) == 'object') {
+                    if (tree.data[i].children.length > 0) {
+                        for (var j in tree.data[i].children) {
+                            if (key) {
+                                var name = tree.data[i].children[j].name;
+                                if (name.indexOf(key) != -1) {
+                                    unsetGoods(tree.data[i].children[j]);
+                                }
+                            } else {
+                                unsetGoods(tree.data[i].children[j]);
+                            }
+                        }
+                    } else {
+                        if (key) {
+                            var name = tree.data[i].name;
+                            if (name.indexOf(key) != -1) {
+                                unsetGoods(tree.data[i]);
+                            }
+                        } else {
+                            unsetGoods(tree.data[i]);
+                        }
+                    }
+                }
+            }
+            setTotal();
+        }
+    }
+
+    function unsetGoods(node)
+    {
+        if (node.id) {
+            if (goods[node.id]) {
+                goods[node.id].del = 2;
+                goods[node.id].num = 0;
+                goods[node.id].total = 0;
+                get(node.id).remove();
+            }
+        }
+    }
+
+    function setGoods(node)
+    {
+        if (node.id) {
+            var key = node.id;
+            if (!goods[key] || (goods[key] && goods[key].del == 2)) {
+                goods[key] = node;
+                goods[key].type = parseInt(goods[key].type);
+                goods[key].total = parseFloat(goods[key].total);
+                goods[key].min = goods[key].min ? parseFloat(goods[key].min) : 1;
+                goods[key].num = 0;
+                goods[key].del = 1;
+                create(node);
+                setTotal();
+            } else if(node.type < 4) {
+                add(key);
+            }
+        }
+    }
+
+    function get(key)
+    {
+        return $('#goods_' + key);
+    }
+
+    function create(node)
+    {
+        if (!get(node.id).length) {
+            var select = '';
+
+            var addtr = '<tr class="mytr" id="goods_'+node.id+'" value="'+node.id+'">';
+            addtr += '<td class="goods_id">'+node.id+'</td>';
+            addtr += '<td class="goods_name">'+node.name+'</td>';
+            addtr += '<td class="goods_old_price">'+node.old_price+'</td>'; 
+            addtr += '<td class="goods_price"><span><input type="text" value="'+node.price+'" class="layui-input"></span></td>'; 
+            if (type == 1) {
+                node.new_price = getPrice(node.old_price, node.price);
+                addtr += '<td class="goods_new_price">'+node.new_price+'</td>'; 
+            }
+            addtr += '<td class="goods_old_buy_price">'+node.old_buy_price+'</td>'; 
+            addtr += '<td class="goods_buy_price"><span><input type="text" value="'+node.buy_price+'" class="layui-input"></span></td>'; 
+            if (type == 1) {
+                addtr += '<td class="goods_new_buy_price">'+node.new_buy_price+'</td>'; 
+            }
+            
+            addtr += '<td><a class="delete_btn" onclick="del(\''+node.id+'\')">删除</a></td>';
+                                  
+            addtr += '</tr>';
+            $("#goods").append(addtr);
+            form.render();
+            //$('.goods_price_template').change();
+        }
+    }
+
+    function getPrice(price, num)
+    {
+        if (num.indexOf('%') > -1) {
+            num = num.replace('%', '');
+        } else {
+            // 数字
+        }
+    }
+
+    function del(id)
+    {
+        if (confirm('确定删除吗?')) {
+            goods[id].del = 2;
+            goods[id].num = 0;
+            get(id).remove();
+            setTotal();
+        }
+    }
+
+    function setTotal()
+    {
+    	return;
+    }
+
+    function add(id)
+    {
+        
+    }
+
+</script>
+</body>
+</html>

+ 2 - 2
database/category.php

@@ -11,9 +11,9 @@ return array
 	# 表名
 	'name' => 'category',
 	# 显示给用户看的名称
-	'lang' => '属性分类设置',
+	'lang' => '属性分类',
 	# 是否显示在后台菜单
-	'order' => 10,
+	'order' => 300,
 
 	'end' => array
 	(

+ 14 - 14
database/info.php

@@ -77,7 +77,7 @@ $config = array
 	# 表名
 	'name' => 'info',
 	# 显示给用户看的名称
-	'lang' => '商品设置',
+	'lang' => '商品资料',
 	'order' => 200,
 	'auto' => 10000000,
 	'set' => array
@@ -117,7 +117,7 @@ $config = array
 		'id' 		=> array
 		(
 			'type' 		=> 'int-11',
-			'name' 		=> '商品ID',
+			'name' 		=> '商品编码',
 			'default' 	=> '',
 			'desc' 		=> '',
 			'match' 	=> 'is_numeric',
@@ -267,17 +267,6 @@ $config = array
 			'show'		=> 'pay_money=1',
 		),
 
-		'commission'		=> array
-		(
-			'type' 		=> 'varchar-20',
-			'name' 		=> '销售商佣金-设置佣金之后,销售商销售了商品,能得到的相应佣金,也可以在销售商里单独设置,填写10%就是销售价的百分之10,直接填写数字就是佣金数额',
-			'default' 	=> '0',
-			'desc' 		=> '销售商佣金',
-			'match' 	=> 'is_numeric',
-			'update'	=> 'text',
-			'tab'		=> 1,
-		),
-
 		'score_id'		=> array
 		(
 			'type' 		=> 'int-11',
@@ -291,10 +280,21 @@ $config = array
 			'show'		=> 'pay_money=2',
 		),
 
+		'commission'		=> array
+		(
+			'type' 		=> 'varchar-20',
+			'name' 		=> '销售商佣金-设置佣金之后,销售商销售了商品,能得到的相应佣金,也可以在销售商里单独设置,填写10%就是销售价的百分之10,直接填写数字就是佣金数额',
+			'default' 	=> '0',
+			'desc' 		=> '销售商佣金',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'tab'		=> 1,
+		),
+
 		'category'		=> array
 		(
 			'type' 		=> 'varchar-500',
-			'name' 		=> '商品分类',
+			'name' 		=> '属性分类',
 			'default' 	=> '',
 			'desc' 		=> '分类',
 			'match' 	=> 'is_string',

+ 2 - 2
database/info_sku.php

@@ -47,9 +47,9 @@ $config = array
         'code'      => array
         (
             'type'      => 'varchar-100',
-            'name'      => '商品码',
+            'name'      => '商品码',
             'default'   => '',
-            'desc'      => '商品码',
+            'desc'      => '商品码',
             'match'     => 'is_string',
             'update'    => 'text',
             'search'    => 'fulltext',

+ 124 - 0
database/price.php

@@ -0,0 +1,124 @@
+<?php
+$goods = array
+(
+	1 => '所有商品',
+	2 => '部分商品',
+);
+$category = function()
+{
+	$array = array();
+	$data = Dever::load('product/category-getTop');
+	if($data)
+	{
+		$array += $data;
+	}
+	return $array;
+};
+$status = array
+(
+	1 => '有效',
+	2 => '失效',
+);
+$type = array
+(
+	1 => '统一调价',
+	2 => '手动调价',
+);
+$time = array
+(
+	1 => '长期有效',
+	2 => '短期有效',
+);
+return array
+(
+	# 表名
+	'name' => 'price',
+	# 显示给用户看的名称
+	'lang' => '价格模板',
+	'info' => '在商品中设置的价格是默认价格,如果一个SKU想设置不同的价格,则可以通过价格模板设置',
+	# 是否显示在后台菜单
+	'order' => 9,
+
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			'list'		=> true,
+			'order'		=> 'asc',
+		),
+
+		'name'		=> array
+		(
+			'type' 		=> 'varchar-150',
+			'name' 		=> '模板名称',
+			'default' 	=> '',
+			'desc' 		=> '模板名称',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'search'	=> 'fulltext',
+			'list'		=> true,
+			'edit'		=> true,
+		),
+
+		'product-price_rule'=> array
+		(
+			'name' 		=> '策略设置',
+			'default' 	=> '',
+			'desc' 		=> '策略设置',
+			'match' 	=> 'option',
+			# 同步更新另外一个表的内容,两个表相关联的id,更新另一个表的字段
+			'sync'		=> array('id', 'price_id'),
+			# 根据category字段的值,获取product/attr.search接口的内容
+			'update'	=> array(1),
+		),
+		
+		'state'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '状态',
+			'default' 	=> '1',
+			'desc' 		=> '请选择状态',
+			'match' 	=> 'is_numeric',
+		),
+		
+		'cdate'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '录入时间',
+			'match' 	=> array('is_numeric', time()),
+			'desc' 		=> '',
+			# 只有insert时才生效
+			'insert'	=> true,
+			//'search'	=> 'date',
+			'list'		=> 'date("Y-m-d H:i:s", {cdate})',
+		),
+	),
+
+	'manage' => array
+	(
+		//'insert' => false,
+        //'edit' => false,
+
+        # 自定义快捷新增和编辑
+        'button' => array
+        (
+            //'新增' => array('fast'),
+        ),
+		'list_button' => array
+        (
+        	//'edit' => array('编辑'),
+        	'list' => array('策略管理', 'price_rule&oper_table=price&search_option_price_id={id}'),
+        )
+	),
+
+	'request' => array
+	(
+		
+	)
+);

+ 243 - 0
database/price_rule.php

@@ -0,0 +1,243 @@
+<?php
+$goods = array
+(
+	1 => '所有商品',
+	2 => '部分商品',
+);
+$category = function()
+{
+	$array = array();
+	$data = Dever::load('product/category-getTop');
+	if($data)
+	{
+		$array += $data;
+	}
+	return $array;
+};
+$status = array
+(
+	1 => '有效',
+	2 => '失效',
+);
+$type = array
+(
+	1 => '统一调价',
+	2 => '手动改价',
+);
+$time = array
+(
+	1 => '长期有效',
+	2 => '短期有效',
+);
+return array
+(
+	# 表名
+	'name' => 'price_rule',
+	# 显示给用户看的名称
+	'lang' => '价格模板策略',
+	# 是否显示在后台菜单
+	'order' => 9,
+	'menu' => false,
+
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			//'list'		=> true,
+			'order'		=> 'asc',
+		),
+
+		'price_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '所属价格模板',
+            'default'   => '',
+            'desc'      => '所属价格模板',
+            'match'     => 'is_numeric',
+            'update'    => 'hidden',
+            'search'    => 'hidden',
+            'value'     => Dever::input('search_option_price_id'),
+            'list'      => 'Dever::load("product/price-one#name", {price_id})',
+        ),
+
+		'name'		=> array
+		(
+			'type' 		=> 'varchar-150',
+			'name' 		=> '策略名称',
+			'default' 	=> '',
+			'desc' 		=> '策略名称',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'search'	=> 'fulltext',
+			'list'		=> true,
+			'edit'		=> true,
+		),
+
+        'category'		=> array
+		(
+			'type' 		=> 'varchar-2000',
+			'name' 		=> '影响分类-如不选择就是影响所有商品',
+			'default' 	=> '',
+			'desc' 		=> '模板影响分类',
+			'match' 	=> 'is_string',
+			'update'	=> 'checkbox',
+			'option'	=> $category,
+		),
+
+		'type'        => array
+        (
+            'type'      => 'tinyint-1',
+            'name'      => '调价规则-手动调价需要在配置商品中进行手动调整',
+            'default'   => '1',
+            'desc'      => '调价规则',
+            'match'     => 'is_numeric',
+            'update'    => 'radio',
+            'option'    => $type,
+            'list'		=> true,
+            'control'	=> 'type',
+        ),
+
+        'sell_num'		=> array
+		(
+			'type' 		=> 'varchar-30',
+			'name' 		=> '销售调价数值-直接输入数字就是统一调价的增减数值,负数就是减少,如果是百分比,就带上%号即可,如10%,模板下的商品将统一进行加价或者减价',
+			'default' 	=> '',
+			'desc' 		=> '销售调价数值',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'show'		=> 'type=1',
+		),
+
+		'buy_num'		=> array
+		(
+			'type' 		=> 'varchar-30',
+			'name' 		=> '采购调价数值-直接输入数字就是统一调价的增减数值,负数就是减少,如果是百分比,就带上%号即可,如10%,模板下的商品将统一进行加价或者减价',
+			'default' 	=> '',
+			'desc' 		=> '采购调价数值',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'show'		=> 'type=1',
+		),
+
+		'day'		=> array
+		(
+			'type' 		=> 'varchar-30',
+			'name' 		=> '临期天数-填写该天数,如果商品有保质期,在小于等于该天数的时间内,将是不同的价格,为0则不验证保质期',
+			'default' 	=> '0',
+			'desc' 		=> '临期天数',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+		),
+
+		'time'        => array
+        (
+            'type'      => 'tinyint-1',
+            'name'      => '模板有效期',
+            'default'   => '1',
+            'desc'      => '模板有效期',
+            'match'     => 'is_numeric',
+            'update'    => 'radio',
+            'option'    => $time,
+            'list'		=> true,
+            'control'	=> 'time',
+        ),
+
+        'time_start'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '开始时间',
+			'default'   => '',
+			'match' 	=> 'is_numeric',
+			'desc' 		=> '开始时间',
+			'update'	=> 'date',
+			'show'		=> 'time=2',
+		),
+
+		'time_end'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '结束时间',
+			'default'   => '',
+			'match' 	=> 'is_numeric',
+			'desc' 		=> '结束时间',
+			'update'	=> 'date',
+			'show'		=> 'time=2',
+		),
+
+		'status'        => array
+        (
+            'type'      => 'tinyint-1',
+            'name'      => '是否有效',
+            'default'   => '1',
+            'desc'      => '是否有效',
+            'match'     => 'is_numeric',
+            //'update'    => 'radio',
+            'option'    => $status,
+            'list'		=> true,
+            'edit'		=> true,
+        ),
+
+		'reorder'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '优先级-数值越大优先级越高',
+			'default' 	=> '1',
+			'desc' 		=> '优先级排序',
+			'match' 	=> 'option',
+			'update'	=> 'text',
+			'search'	=> 'order',
+			'list'		=> true,
+			'order'		=> 'desc',
+			'edit'		=> true,
+		),
+		
+		'state'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '状态',
+			'default' 	=> '1',
+			'desc' 		=> '请选择状态',
+			'match' 	=> 'is_numeric',
+		),
+		
+		'cdate'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '录入时间',
+			'match' 	=> array('is_numeric', time()),
+			'desc' 		=> '',
+			# 只有insert时才生效
+			'insert'	=> true,
+			//'search'	=> 'date',
+			'list'		=> 'date("Y-m-d H:i:s", {cdate})',
+		),
+	),
+
+	'manage' => array
+	(
+		//'insert' => false,
+        //'edit' => false,
+
+        # 自定义快捷新增和编辑
+        'button' => array
+        (
+            //'新增' => array('fast'),
+        ),
+		'list_button' => array
+        (
+        	//'edit' => array('编辑'),
+        	'location' => array('配置商品', Dever::url('lib/price.setGoods', 'product')),
+        )
+	),
+
+	'request' => array
+	(
+		
+	)
+);

+ 187 - 0
database/price_rule_sku.php

@@ -0,0 +1,187 @@
+<?php
+
+$config = array
+(
+    # 表名
+    'name' => 'price_rule_sku',
+    # 显示给用户看的名称
+    'lang' => '价格模板单价设置',
+    'order' => 200,
+    'menu' => false,
+    /*
+    'end' => array
+    (
+        'insert' => 'role/lib/seller.skuUpdate',
+        'update' => 'role/lib/seller.skuUpdate',
+    ),
+    */
+
+    # 数据结构 不同的字段放这里
+    'struct' => array
+    (
+        'id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            //'list'        => true,
+        ),
+
+        'price_rule_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '所属价格策略',
+            'default'   => '',
+            'desc'      => '所属价格策略',
+            'match'     => 'is_numeric',
+            'update'    => 'hidden',
+            'search'    => 'hidden',
+            'value'     => Dever::input('search_option_price_rule_id'),
+            'list'      => 'Dever::load("product/price_rule-one#name", {price_rule_id})',
+        ),
+
+        'goods_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '商品名称',
+            'default'   => '',
+            'desc'      => '商品名称',
+            'match'     => 'is_numeric',
+            'update'    => 'select',
+            'update_search' => 'product/lib/manage.search',
+            'list'      => 'Dever::load("product/info-one#name", {goods_id})',
+        ),
+
+        'sku_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '规格型号',
+            'default'   => '-1',
+            'desc'      => '规格型号',
+            'match'     => 'is_numeric',
+        ),
+
+        'price'     => array
+        (
+            'type'      => 'varchar-100',
+            'name'      => '销售价',
+            'default'   => '',
+            'desc'      => '销售价',
+            'match'     => 'option',
+            'update'    => 'text',
+            'list'      => true,
+        ),
+
+        'buy_price'       => array
+        (
+            'type'      => 'varchar-100',
+            'name'      => '采购价',
+            'default'   => '',
+            'desc'      => '采购价',
+            'match'     => 'option',
+            'update'    => 'text',
+            'list'      => true,
+        ),
+
+        'state'     => array
+        (
+            'type'      => 'tinyint-1',
+            'name'      => '数据状态',
+            'default'   => '1',
+            'desc'      => '请选择状态',
+            'match'     => 'is_numeric',
+        ),
+
+        'cdate'     => array
+        (
+            'type'      => 'int-11',
+            'name'      => '发布时间',
+            'match'     => array('is_numeric', time()),
+            'desc'      => '',
+            # 只有insert时才生效
+            'insert'    => true,
+            //'search'  => 'date',
+            //'list'        => 'date("Y-m-d H:i:s", {cdate})',
+        ),
+    ),
+
+    'manage' => array
+    (
+        'insert' => false,
+        'edit' => false,
+        'delete' => false,
+        //'excel' => array(array('导出门店库存', '门店库存', '')),
+        'page_list_table' => 'sku',
+    ),
+
+    # request 请求接口定义
+    'request' => array
+    (
+        'getDataPage' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'price_id' => array('yes-t_1.price_id'),
+                'name' => array('yes-t_2.name', 'like'),
+                'category' => array('yes-t_2.category', 'like'),
+                'top_category_id' => array('yes-t_2.top_category_id'),
+                'second_category_id' => array('yes-t_2.second_category_id'),
+                'category_id' => array('yes-t_2.category_id'),
+                'status' => array('yes-t_2.status', 1),
+                'state' => array('yes-t_2.state', 1),
+                'state_1' => array('yes-t_1.state', 1),
+            ),
+            # 联表
+            'join' => array
+            (
+                array
+                (
+                    'table' => 'product/info',
+                    'type' => 'left join',
+                    'on' => array('goods_id','id'),
+                    'col' => 'goods_id',
+                ),
+            ),
+            'type' => 'all',
+            'order' => array('t_2.reorder' => 'desc', 't_2.id' => 'desc', 't_2.price' => 'asc'),
+            'page' => array(30, 'list'),
+            'col' => '*,t_2.name,t_2.pic,t_2.video,t_2.id as id',
+        ),
+
+        'getData' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'price_id' => array('yes-t_1.price_id'),
+                'name' => array('yes-t_2.name', 'like'),
+                'category' => array('yes-t_2.category', 'like'),
+                'top_category_id' => array('yes-t_2.top_category_id'),
+                'second_category_id' => array('yes-t_2.second_category_id'),
+                'category_id' => array('yes-t_2.category_id'),
+                'status' => array('yes-t_2.status', 1),
+                'state' => array('yes-t_2.state', 1),
+                'state_1' => array('yes-t_1.state', 1),
+            ),
+            # 联表
+            'join' => array
+            (
+                array
+                (
+                    'table' => 'product/info',
+                    'type' => 'left join',
+                    'on' => array('goods_id','id'),
+                    'col' => 'goods_id',
+                ),
+            ),
+            'type' => 'all',
+            'order' => array('t_2.reorder' => 'desc', 't_2.id' => 'desc', 't_2.price' => 'asc'),
+            'col' => '*,t_2.name,t_2.pic,t_2.video,t_2.id as id',
+        ),
+    ),
+);
+
+return $config;

+ 36 - 17
lib/Info.php

@@ -35,6 +35,8 @@ class Info
     # 获取商品及其属性列表
     public function getSetList($table, $other_where, $cate_id = false, $col = 'goods_id')
     {
+        $price = Dever::input('price', 0);
+        $buy_price = Dever::input('buy_price', 0);
         $total = Dever::input('total', 1);
         if ($cate_id) {
             $where['top_category_id'] = $cate_id;
@@ -59,18 +61,27 @@ class Info
                     $result[$i]['type'] = $v['type'];
                     $result[$i]['stock'] = $v['stock'];
                     $result[$i]['commission'] = $v['commission'];
-                    $result[$i]['price'] = 0;
+
+                    $result[$i]['old_price'] = 0;
+                    $result[$i]['old_buy_price'] = 0;
+
+                    $result[$i]['price'] = $price;
+                    $result[$i]['buy_price'] = $buy_price;
                     $result[$i]['select'] = 2;
                     $result[$i]['del'] = 1;
+                    $result[$i]['total'] = 0;
                     
                     if ($other) {
-                        if (isset($other['commission'])) {
+                        if (isset($other['commission']) && $other['commission']) {
                             $result[$i]['commission'] = $other['commission'];
                         }
-                        if (isset($other['price'])) {
+                        if (isset($other['price']) && $other['price']) {
                             $result[$i]['price'] = $other['price'];
                         }
-                        if (isset($other['min'])) {
+                        if (isset($other['buy_price']) && $other['buy_price']) {
+                            $result[$i]['buy_price'] = $other['buy_price'];
+                        }
+                        if (isset($other['min']) && $other['min']) {
                             $result[$i]['min'] = $other['min'];
                         }
                         if (isset($other['total_num'])) {
@@ -80,24 +91,27 @@ class Info
                                 $result[$i]['total'] = $other['total_num'];
                             }
                             
-                        } else {
+                        } elseif (isset($other['num'])) {
                             $result[$i]['total'] = $other['num'];
                         }
                         
                         $result[$i]['select'] = $other['state'];
-                    } else {
-                        $result[$i]['total'] = 0;
                     }
 
                     $result[$i]['total'] = $result[$i]['total'] * $total;
                     $result[$i]['children'] = array();
                     $num = count($sku);
-                    if ($num == 1 && $sku[0]['key'] == -1) {
-                        if ($result[$i]['price'] <= 0) {
+                    if ($sku[0]['key'] == -1) {
+                        $result[$i]['old_price'] = $sku[0]['price'];
+                        $result[$i]['old_buy_price'] = $sku[0]['buy_price'];
+                        if (!$price && $result[$i]['price'] <= 0) {
                             $result[$i]['price'] = $sku[0]['price'];
                         }
+                        if (!$buy_price && $result[$i]['buy_price'] <= 0) {
+                            $result[$i]['buy_price'] = $sku[0]['buy_price'];
+                        }
                         
-                        $result[$i]['id'] .=  '-' . $sku[0]['id'];
+                        //$result[$i]['id'] .=  '-' . $sku[0]['id'];
                         $result[$i]['end'] = true;
                     } else {
                         foreach ($sku as $k1 => $v1) {
@@ -121,10 +135,14 @@ class Info
                                 'name' => $name,
                                 'stock' => $v['stock'],
                                 'commission' => $v['commission'],
-                                'price' => $v1['price'] ? $v1['price'] : 0,
+                                'old_price' => $v1['price'] ? $v1['price'] : 0,
+                                'old_buy_price' => $v1['buy_price'] ? $v1['buy_price'] : 0,
+                                'price' => $price ? $price : $v1['price'],
+                                'buy_price' => $buy_price ? $buy_price : $v1['buy_price'],
                                 'type' => $v['type'],
                                 'del' => 1,
                                 'end' => true,
+                                'total' => 0,
                             );
                             $other_where['sku_id'] = $v1['id'];
                             $other_sku = Dever::db($table)->find($other_where);
@@ -132,13 +150,16 @@ class Info
                             $children['select'] = 2;
                             $children['total'] = 0;
                             if ($other_sku) {
-                                if (isset($other_sku['commission'])) {
+                                if (isset($other_sku['commission']) && $other_sku['commission']) {
                                     $children['commission'] = $other_sku['commission'];
                                 }
-                                if (isset($other_sku['price'])) {
+                                if (isset($other_sku['price']) && $other_sku['price']) {
                                     $children['price'] = $other_sku['price'];
                                 }
-                                if (isset($other_sku['min'])) {
+                                if (isset($other_sku['buy_price']) && $other_sku['buy_price']) {
+                                    $children['buy_price'] = $other_sku['buy_price'];
+                                }
+                                if (isset($other_sku['min']) && $other_sku['min']) {
                                     $children['min'] = $other_sku['min'];
                                 }
                                 if (isset($other_sku['total_num'])) {
@@ -147,9 +168,7 @@ class Info
                                     } else {
                                         $children['total'] = $other_sku['total_num'];
                                     }
-                                    
-                                    
-                                } else {
+                                } elseif (isset($other_sku['num'])) {
                                     $children['total'] = $other_sku['num'];
                                 }
                                 

+ 95 - 0
lib/Price.php

@@ -0,0 +1,95 @@
+<?php
+
+namespace Product\Lib;
+
+use Dever;
+
+class Price
+{
+    public function __construct()
+    {
+        Dever::load('manage/auth.init');
+    }
+
+    # 获取商品列表
+    public function goods_api()
+    {
+        $price_rule_id = Dever::input('price_rule_id', 1);
+        $goods_category = Dever::input('goods_category');
+        $where['price_rule_id'] = $price_rule_id;
+        return Dever::outDiy(Dever::load('product/lib/info')->getSetList('product/price_rule_sku', $where, $goods_category));
+    }
+
+    # 配置商品
+    public function setGoods_api()
+    {
+        $data = array();
+        $data['price_rule_id'] = Dever::input('id', 1);
+        $price = Dever::db('product/price_rule')->find($data['price_rule_id']);
+        $goods_category = '';
+        $data['type'] = 1;
+        $data['sell_num'] = $data['sell_num'] = 0;
+        if ($price) {
+            $goods_category = $price['category'];
+            $data['type'] = $price['type'];
+            $data['sell_num'] = $price['sell_num'];
+            $data['buy_num'] = $price['buy_num'];
+        }
+        
+        $data['host'] = Dever::url('lib/price.setGoods', 'product');
+        $data['url'] = Dever::url('lib/price.goods?price_rule_id=' . $data['price_rule_id'] . '&goods_category=' . $goods_category . '&price=' . $data['sell_num'] . '&buy_price=' . $data['buy_num'], 'product');
+        $data['submit'] = Dever::url('lib/price.setGoods_action_commit?json=1', 'product');
+
+        return Dever::render('set_price_goods', $data);
+    }
+
+    # 配置商品
+    public function setGoods_action_commit_api()
+    {
+        $goods = Dever::input('goods');
+        if (!$goods) {
+            Dever::alert('请传入商品');
+        }
+        $goods = Dever::json_decode($goods);
+        $price_rule_id = Dever::input('price_rule_id');
+
+        $shop = Dever::db('product/price')->one($price_rule_id);
+        $where['option_price_rule_id'] = $price_rule_id;
+        $where['set_state'] = 2;
+        Dever::db('product/price_rule_sku')->updates($where);
+
+        foreach ($goods as $k => $v) {
+            if ($v['del'] == 1) {
+            	$temp = explode('-', $k);
+	            $goods_id = $temp[0];
+	            $sku_id = -1;
+	            if (isset($temp[1])) {
+	                $sku_id = $temp[1];
+	            }
+
+                $goods_info = Dever::db('product/info')->one($goods_id);
+                $w = array();
+                $w['goods_id'] = $goods_id;
+                $w['sku_id'] = $sku_id;
+                $w['price_rule_id'] = $price_rule_id;
+                $sku_info = Dever::db('product/price_rule_sku')->one($w);
+
+                $w['status'] = $goods_info['status'];
+                if (isset($v['price']) && $v['price']) {
+                    $w['price'] = $v['price'];
+                }
+                if (isset($v['buy_price']) && $v['buy_price']) {
+                    $w['buy_price'] = $v['buy_price'];
+                }
+                if (!$sku_info) {
+                    Dever::db('product/price_rule_sku')->insert($w);
+                } else {
+                    $w['where_id'] = $sku_info['id'];
+                    $w['state'] = 1;
+                    Dever::db('product/price_rule_sku')->update($w);
+                }
+            }
+        }
+        return 'refer';
+    }
+}