rabin 3 年之前
父节点
当前提交
29f320fd78

+ 211 - 0
app/act/assets/pc/html/setGoods.html

@@ -0,0 +1,211 @@
+<!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>商品列表
+
+                    <!-- <a class="mini-button" onclick="location.href='<{$link}>'">返回上一页</a> -->
+                </div>
+                <div class="left_main">
+                    <input id="key" class="mini-textbox" placeholder="请输入商品名称" onenter="onKeyEnter"/>
+                    <a class="mini-button" onclick="search()">查询</a> 
+                    <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="goods_list" style="height:645px;">
+                    <table class="layui-table">
+                        <thead>
+                            <tr>
+                            	<th lay-data="{field:'cate'}">商品分类</th>
+                                <th lay-data="{field:'id'}">商品编码</th>
+                                <th lay-data="{field:'name'}">商品名称</th>
+                                <th lay-data="{field:'operation'}">操作</th>
+                            </tr>
+                        </thead>
+                        <tbody id="goods">
+                            
+                        </tbody>
+                    </table>
+                </div>
+                <div class="total ft16">
+                    合计:【<span> 当前选择商品数:<i class="totalNum">0</i> </span>】
+                </div>
+                <div class="towbtn">
+                    <input type="button" id="settlement" value="确认设置">
+                </div>
+            </div>
+        </div>
+    </div>
+</div>
+</form>
+</div>
+<script>
+    var form;
+    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;
+        $('#give').val('<{$give}>');
+        form.render(); 
+    });
+
+    $(function()
+    {
+        $("#settlement").click(function(){
+            var url = '<{$submit}>';
+            var discount_id = '<{$discount_id}>';
+            var link = '<{$link}>';
+
+            layui.layer.confirm('确定进行此项设置吗?', function() {
+                var goods_string = JSON.stringify(goods);
+
+                var data = {};
+                data = {discount_id:discount_id, goods:goods_string,link:link};
+                $.post(url, data, function(t) {
+                    t = JSON.parse(t);
+                    if (t.status == 1) {
+                        layui.layer.alert('礼品卡商品设置成功', function(index){
+                          location.reload();
+                          layer.close(index);
+                        });
+                    } else {
+                        layui.layer.alert(t.msg);
+                    }
+                });
+            });
+        })
+    })
+    var goods = {};
+    var del_goods = {};
+    mini.parse();
+    var 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 search() 
+    {
+        var key = mini.get("key").getValue();
+        if (key == "") {
+            tree.clearFilter();
+        } else {
+            key = key.toLowerCase();                
+            tree.filter(function (node) {
+                var name = node.name ? node.name.toLowerCase() : "";
+                if (name.indexOf(key) != -1) {
+                    return true;
+                }
+            });
+        }
+    }
+    function onKeyEnter(e)
+    {
+        search();
+    }
+
+    function onNodeClick()
+    {
+        var tree=mini.get("tree1");
+        node=tree.getSelectedNode();
+        if(node.end) {
+            setGoods(node);
+        }
+    }
+
+    function setGoods(node)
+    {
+        if (node.id) {
+            var key = node.id;
+            if (!goods[key] || (goods[key] && goods[key].del == 2)) {
+                goods[key] = node;
+                goods[key].num = 0;
+                goods[key].del = 1;
+                create(node);
+                setTotal();
+            }
+        }
+    }
+
+    function get(key)
+    {
+        return $('#goods_' + key);
+    }
+
+    function create(node)
+    {
+        if (!get(node.id).length) {
+            var addtr = '<tr class="mytr" id="goods_'+node.id+'">';
+            addtr += '<td class="goods_class">'+node.class_name+'</td>';
+            addtr += '<td class="goods_id">'+node.id+'</td>';
+            addtr += '<td class="goods_name">'+node.name+'</td>';     
+            addtr += '<td><a class="delete_btn" onclick="del(\''+node.id+'\')">删除</a></td>';    
+            addtr += '</tr>';
+            $("#goods").append(addtr);
+        }
+    }
+
+    function del(id)
+    {
+        if (confirm('确定删除吗?')) {
+            goods[id].del = 2;
+            get(id).remove();
+            setTotal();
+        }
+    }
+
+    function setTotal()
+    {
+        var total = 0;
+        for (var i in goods) {
+            if (goods[i].del == 1) {
+            	total += 1;
+            }
+        }
+        //$(".totalQuantity").html(num);
+        $(".totalNum").html(total);
+    }
+</script>
+</body>
+</html>

+ 133 - 0
app/act/database/discount.php

@@ -0,0 +1,133 @@
+<?php
+$role = array
+(
+    1 => '代理商角色',
+);
+
+$cate = function() 
+{
+    $where['project_id'] = 1;
+    return Dever::db('category/info')->getTop($where);
+};
+
+return array
+(
+    # 表名
+    'name' => 'discount',
+    # 显示给用户看的名称
+    'lang' => '角色折扣管理',
+    'order' => 90,
+
+    # 数据结构
+    'struct' => array
+    (
+        'id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            'list'      => true,
+        ),
+
+        'role'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '折扣角色',
+            'default'   => '1',
+            'desc'      => '折扣角色',
+            'match'     => 'is_numeric',
+            'update'    => 'select',
+            'option'    => $role,
+            'search'    => 'radio',
+            'list'      => true,
+        ),
+        
+        'name'      => array
+        (
+            'type'      => 'varchar-80',
+            'name'      => '折扣标题',
+            'default'   => '',
+            'desc'      => '标题',
+            'match'     => 'is_string',
+            'update'    => 'text',
+            'list'      => true,
+            'search'    => 'fulltext',
+        ),
+
+        'num'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '折扣数值-直接填写折扣的数值,如填写9,就是9折,如一个角色填写了多个折扣,支付时自动使用最低折扣结算',
+            'default'   => '9',
+            'desc'      => '折扣数值',
+            'match'     => 'is_numeric',
+            'update'    => 'text',
+            'list'      => true,
+        ),
+
+        'category'      => array
+        (
+            'type'      => 'varchar-500',
+            'name'      => '可用商品分类-不选择则所有商品可用',
+            'default'   => '',
+            'desc'      => '可用商品分类',
+            'match'     => 'option',
+            //'search'    => 'linkage',
+            'update'    => 'checkbox',
+            'option'    => $cate,
+            //'option'    => Dever::url('api.get', 'category'),
+            //'list'        => 'Dever::load("category/api.string", "{category}")',
+        ),
+
+        '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,
+        ),
+    ),
+
+    # 默认值
+    'default' => array
+    (
+        'col' => 'name,role,num,state,cdate',
+        'value' => array
+        (
+            '"代理优惠",1,9,1,' . time(),
+        ),
+    ),
+    
+    # 管理功能
+    'manage' => array
+    (
+        //'insert' => false,
+        //'edit' => false,
+        'delete' => false,
+        # 列表
+        'list_button' => array
+        (
+            //'edit' => array('预览', str_replace('https://api.', 'http://www.', Dever::url('main/preview.get?type=1'))),
+            'location' => array('商品设置', Dever::url('lib/goods_set.home', 'act')),
+        ),
+    ),
+
+    # request 请求接口定义
+    'request' => array
+    (
+        
+    ),
+);

+ 99 - 0
app/act/database/discount_goods.php

@@ -0,0 +1,99 @@
+<?php
+
+return array
+(
+    # 表名
+    'name' => 'discount_goods',
+    # 显示给用户看的名称
+    'lang' => '折扣商品设置',
+    'menu' => false,
+    # 数据结构
+    'struct' => array
+    (
+    
+        'id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            'search'    => 'order',
+            'update'    => 'hidden',
+            //'list'        => true,
+        ),
+
+        'discount_id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '折扣',
+            'default'   => '',
+            'desc'      => '折扣',
+            'match'     => 'is_numeric',
+            'update'    => 'hidden',
+            'search'    => 'hidden',
+            'value'     => Dever::input('search_option_discount_id'),
+            'list'      => 'Dever::load("act/discount-find#name", "{discount_id}")',
+        ),
+
+        'cate_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '商品分类id',
+            'default'   => '-1',
+            'desc'      => '商品id',
+            'match'     => 'is_numeric',
+        ),
+
+        'goods_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '商品id',
+            'default'   => '-1',
+            'desc'      => '商品id',
+            'match'     => 'is_numeric',
+        ),
+
+        '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
+    (
+        
+    ),
+
+    'request' => array
+    (
+        'getData' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'discount_id' => 'yes',
+                'state' => 1,
+            ),
+            'order' => array('id' => 'desc'),
+            'type' => 'all',
+            'col' => '*|goods_id|',
+        ),
+    ),
+);

+ 133 - 0
app/act/lib/Goods_set.php

@@ -0,0 +1,133 @@
+<?php
+
+namespace Act\Lib;
+
+use Dever;
+
+# 批量设置商品
+class Goods_set
+{
+	public function __construct()
+    {
+        Dever::load('manage/auth.init');
+    }
+
+    # 获取商品列表
+    public function goods_api()
+    {
+        $result = array();
+        $id = Dever::input('discount_id', 1);
+        $discount = Dever::db('act/discount')->find($id);
+        if (!$discount) {
+            return Dever::outDiy($result);
+        }
+        $where['project_id'] = 1;
+        if ($discount['category']) {
+            $where['ids'] = $discount['category'];
+        }
+        $data = Dever::db('category/info')->getTop($where);
+        if ($data) {
+            $i = 0;
+            foreach ($data as $k => $v) {
+
+                $result[$i]['id'] = $v['id'];
+                $result[$i]['name'] = $v['name'];
+                $result[$i]['select'] = 2;
+                $result[$i]['del'] = 1;
+                $result[$i]['children'] = array();
+
+                $w['top_category_id'] = $v['id'];
+                $goods = Dever::db('goods/info')->select($w);
+                if ($goods) {
+
+                    foreach ($goods as $v1) {
+                        $children = array
+                        (
+                            'id' => $v['id'] . '-' . $v1['id'],
+                            'name' => $v1['name'],
+                            'class_name' => $v['name'],
+                            'del' => 1,
+                            'select' => 2,
+                            'end' => true,
+                        );
+
+                        $bind = Dever::db('act/discount_goods')->find(array('discount_id' => $id, 'goods_id' => $v1['id']));
+
+                        if ($bind) {
+                            $children['select'] = 1;
+                        }
+                        $result[$i]['children'][] = $children;
+                    }
+
+                    $i++;
+                } else {
+                    unset($result[$i]);
+                }
+            }
+        }
+
+        return Dever::outDiy($result);
+    }
+
+    # 设置商品
+    public function home_api()
+    {
+        $data = array();
+        $data['link'] = Dever::decode(Dever::input('refer'));
+        $data['discount_id'] = Dever::input('id', 1);
+        Dever::setInput('discount_id', $data['discount_id']);
+        $data['host'] = Dever::url('lib/goods_set.home?id=' . $data['discount_id'], 'act');
+        $data['url'] = Dever::url('lib/goods_set.goods?json=1&discount_id=' . $data['discount_id'], 'act');
+        $data['submit'] = Dever::url('lib/goods_set.action_commit?json=1', 'act');
+
+        return Dever::render('setGoods', $data);
+    }
+
+    # 设置
+    public function action_commit_api()
+    {
+        $goods = Dever::input('goods');
+        if (!$goods) {
+            Dever::alert('请传入商品');
+        }
+        $goods = Dever::json_decode($goods);
+        $discount_id = Dever::input('discount_id');
+
+        $where['option_discount_id'] = $discount_id;
+        $where['set_state'] = 2;
+        Dever::db('act/discount_goods')->updates($where);
+
+        foreach ($goods as $k => $v) {
+            $temp = explode('-', $k);
+            $cate_id = $temp[0];
+            $goods_id = $temp[1];
+
+            $w = array();
+            $w['cate_id'] = $cate_id;
+            $w['goods_id'] = $goods_id;
+            $w['discount_id'] = $discount_id;
+            $info = Dever::db('act/discount_goods')->one($w);
+            if ($v['del'] == 2) {
+                if ($info) {
+                    Dever::db('act/discount_goods')->update(array('where_id' => $info['id'], 'state' => 2));
+                }
+            } else {
+
+                if (!$info) {
+                    Dever::db('act/discount_goods')->insert($w);
+                } else {
+                    $w['where_id'] = $info['id'];
+                    $w['state'] = 1;
+                    Dever::db('act/discount_goods')->update($w);
+                }
+            }
+        }
+
+        $link = Dever::input('link');
+        if ($link) {
+            return $link;
+        } else {
+            return 'reload';
+        }
+    }
+}

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

@@ -384,7 +384,7 @@ class Data extends Core
         );
 
         $this->data['price'] -= $cash;
-        $pay = Dever::load('shop/lib/sell')->pay($this->data['method'], $this->data['pay_method'], $pay_type, $this->user, $this->shop, $this->data['name'], $this->data['num'], $this->data['list'], $this->data['oprice'], $this->data['price'], $cash, $address_id, $invoice_id, $info, $this->data['card'], 0, $this->data['coupon_id'], $this->data['user_coupon_id'], $this->data['coupon_cash'], $cart, 4, $refer);
+        $pay = Dever::load('shop/lib/sell')->pay($this->data['method'], $this->data['pay_method'], $pay_type, $this->user, $this->shop, $this->data['name'], $this->data['num'], $this->data['list'], $this->data['oprice'], $this->data['price'], $cash, $address_id, $invoice_id, $info, $this->data['card'], 0, $this->data['coupon_id'], $this->data['user_coupon_id'], $this->data['coupon_cash'], $this->data['discount_id'], $this->data['discount_cash'], $cart, 4, $refer);
         return $pay;
     }
 

+ 19 - 0
app/shop/database/sell_order.php

@@ -474,6 +474,25 @@ return array
             'update'    => 'text',
         ),
 
+        'discount_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '折扣ID',
+            'default'   => '',
+            'desc'      => '折扣ID',
+            'match'     => 'option',
+        ),
+
+        'discount_cash'      => array
+        (
+            'type'      => 'varchar-300',
+            'name'      => '折扣优惠金额',
+            'default'   => '0',
+            'desc'      => '折扣优惠金额',
+            'match'     => 'option',
+            'update'    => 'text',
+        ),
+
         'method'        => array
         (
             'type'      => 'int-11',

+ 19 - 0
app/shop/database/sell_order_goods.php

@@ -118,6 +118,25 @@ return array
             'update'    => 'text',
         ),
 
+        'discount_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '使用的折扣id',
+            'default'   => '',
+            'desc'      => '使用的折扣id',
+            'match'     => 'option',
+        ),
+
+        'discount_cash'      => array
+        (
+            'type'      => 'varchar-300',
+            'name'      => '折扣优惠金额',
+            'default'   => '0',
+            'desc'      => '折扣优惠金额',
+            'match'     => 'option',
+            'update'    => 'text',
+        ),
+
         'status'        => array
         (
             'type'      => 'int-11',

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

@@ -7,7 +7,7 @@ use Dever;
 class Goods
 {
     # 根据店铺获取商品列表
-    public function getList()
+    public function getList($uid = -1)
     {
         $shop_id = Dever::input('shop_id');
         $lng = Dever::input('lng');
@@ -22,7 +22,7 @@ class Goods
         $data['shop'] = Dever::load('shop/lib/info')->getOne($shop_id, $lng, $lat);
         if ($column) {
             foreach ($column as $k => $v) {
-                $v['data'] = Dever::load('shop/lib/info')->getGoods($shop_id, $v['id'], false, 1);
+                $v['data'] = Dever::load('shop/lib/info')->getGoods($shop_id, $v['id'], false, 1, false, $uid);
                 if ($v['data']) {
                     $data['cate'][] = $v;
                 }

+ 23 - 3
app/shop/lib/Info.php

@@ -118,7 +118,7 @@ class Info
     }
 
     # 获取店铺的商品列表
-    public function getGoods($shop, $column = false, $price_type = false, $sell_type = false, $status = false)
+    public function getGoods($shop, $column = false, $price_type = false, $sell_type = false, $status = false, $uid = -1)
     {
         $table = 'shop/goods';
         $where['shop_id'] = isset($shop['id']) ? $shop['id'] : $shop;
@@ -156,7 +156,7 @@ class Info
         $result_2 = array();
         if ($data) {
             foreach ($data as $k => $v) {
-                $d = $this->getGoodsInfo($where['shop_id'], $v);
+                $d = $this->getGoodsInfo($where['shop_id'], $v, false, true, true, $uid);
                 if ($d) {
                     if ($d['total'] <= 0) {
                         $result_2[] = $d;
@@ -310,7 +310,7 @@ class Info
     }
 
     # 获取库存
-    public function getGoodsInfo($shop_id, $info, $sku_id = false, $attr = true, $check = true)
+    public function getGoodsInfo($shop_id, $info, $sku_id = false, $attr = true, $check = true, $uid = -1)
     {
         $where['shop_id'] = $shop_id;
         $where['goods_id'] = isset($info['goods_id']) ? $info['goods_id'] : $info;
@@ -375,11 +375,31 @@ class Info
             if ($data['min'] && floor($data['min']) == $data['min']) {
                 $data['min'] = intval($data['min']);
             }
+
+            # 根据角色计算折扣
+            $data['discount'] = array();
+            if ($uid && $uid > 0) {
+                $role = $this->getRole($uid);
+                if ($role) {
+                    $data['discount'] = $role;
+                }
+            }
         }
 
         return $data;
     }
 
+    # 获取角色
+    public function getRole($uid)
+    {
+        $bind = Dever::db('agent/user_bind')->find(array('uid' => $uid, 'status' => 2));
+        if ($bind) {
+            $discount = Dever::db('act/discount')->find(array('role' => 1));
+            return $discount;
+        }
+        return false;
+    }
+
     # 验证库存
     public function checkTotal(&$num, $goods_id, $shop_id, $sku_id, $state = 1)
     {

+ 12 - 2
app/shop/lib/Refund.php

@@ -171,6 +171,10 @@ class Refund
                         }
                     }
 
+                    if (isset($info['discount_cash']) && $info['discount_cash']) {
+                        $info['total_price'] = $info['total_price'] - $info['discount_cash'];
+                    }
+
                 	if (isset($info['coupon_cash']) && $info['coupon_cash']) {
                 		$cash = $info['total_price'] - $info['coupon_cash'];
                 	} else {
@@ -522,10 +526,16 @@ class Refund
             if ($type > 10) {
                 $info['price'] = $info['p_price'];
             }
+
+            $total = ($info['price'] * $info['num']);
+
+            if (isset($info['discount_cash']) && $info['discount_cash']) {
+                $total = $total - $info['discount_cash'];
+            }
         	if (isset($info['coupon_cash']) && $info['coupon_cash']) {
-        		$info['tui_price'] = ($info['price'] * $info['num']) - $info['coupon_cash'];
+        		$info['tui_price'] = $total - $info['coupon_cash'];
         	} else {
-        		$info['tui_price'] = $info['price'] * $info['num'];
+        		$info['tui_price'] = $total;
         	}
 
             $info['tui_one_price'] = $info['price'];

+ 63 - 1
app/shop/lib/Sell.php

@@ -173,6 +173,9 @@ class Sell
         if (!$info['coupon_cash']) {
             $info['coupon_cash'] = 0;
         }
+        if (!$info['discount_cash']) {
+            $info['discount_cash'] = 0;
+        }
         if (!$info['refund_cash']) {
             $info['refund_cash'] = 0;
         }
@@ -821,6 +824,13 @@ class Sell
         $data['num'] = 0;
         $data['name'] = array();
         $count = count($goods_id);
+
+        # 获取角色
+        $role = $this->getRole($data);
+        $data['discount_goods'] = array();
+        $data['discount_cash'] = 0;
+        $data['discount_id'] = 0;
+
         # 计算总价格
         foreach ($goods_id as $k => $v) {
             $s = isset($sku_id[$k]) ? $sku_id[$k] : -1;
@@ -860,6 +870,30 @@ class Sell
             if ($data['list'][$k]['ku_state'] == 1) {
                 $data['list'][$k]['buy_num'] = $n;
                 $data['num'] += $n;
+
+                # 根据角色设置折扣
+                if ($role) {
+                    $role_state = false;
+                    $discount_goods = Dever::db('act/discount_goods')->getData(array('discount_id' => $role['id']));
+                    if ($discount_goods) {
+                        $discount_goods = array_keys($discount_goods);
+                        if (in_array($data['list'][$k]['id'], $discount_goods)) {
+                            $role_state = true;
+                        }
+                    } elseif ($role['category'] && in_array($data['list'][$k]['top_category_id'], $role['category'])) {
+                        $role_state = true;
+                    }
+
+                    if ($role_state) {
+                        $discount_cash = round($data['list'][$k]['price'] * ($role['num']/10), 2);
+                        $data['list'][$k]['discount_id'] = $role['id'];
+                        $data['discount_goods'][] = $data['list'][$k];
+                        $data['discount_id'] = $role['id'];
+                        $data['list'][$k]['discount_cash'] = ($data['list'][$k]['price'] - $data['list'][$k]['discount_cash']) * $n;
+                        $data['discount_cash'] += $data['list'][$k]['discount_cash'];
+                    }
+                }
+                
                 $data['price'] += $data['list'][$k]['price'] * $n;
                 $data['name'][] = $data['list'][$k]['name'];
             }
@@ -882,8 +916,16 @@ class Sell
         return $data;
     }
 
+    public function getRole($data)
+    {
+        if(isset($data['uid']) && $data['uid'] > 0) {
+            return Dever::load('shop/lib/info')->getRole($data['uid']);
+        }
+        return false;
+    }
+
     # 发起支付
-	public function pay($method, $pay_method, $pay_type, $user, $shop, $name, $num, $goods, $oprice, $price, $cash, $address_id, $invoice_id, $info, $card, $wallet_cash, $coupon_id, $user_coupon_id, $coupon_cash, $cart = false, $system_source = 5, $refer = '')
+	public function pay($method, $pay_method, $pay_type, $user, $shop, $name, $num, $goods, $oprice, $price, $cash, $address_id, $invoice_id, $info, $card, $wallet_cash, $coupon_id, $user_coupon_id, $coupon_cash, $discount_id, $discount_cash, $cart = false, $system_source = 5, $refer = '')
     {
         if (!$user) {
             Dever::alert('错误的用户信息');
@@ -954,6 +996,13 @@ class Sell
             $order_data['coupon_cash'] = $coupon_cash;
         }
 
+        if ($discount_id) {
+            $order_data['discount_id'] = $discount_id;
+        }
+        if ($discount_cash) {
+            $order_data['discount_cash'] = $discount_cash;
+        }
+
         $order_data['order_num'] = $this->getOrderId();
         $id = Dever::db('shop/sell_order')->insert($order_data);
 
@@ -983,6 +1032,14 @@ class Sell
                     $data['coupon_cash'] = 0;
                 }
 
+                if (isset($v['discount_id']) && $v['discount_id']) {
+                    $data['discount_id'] = $v['discount_id'];
+                }
+
+                if (isset($v['discount_cash']) && $v['discount_cash']) {
+                    $data['discount_cash'] = $v['discount_cash'];
+                }
+
                 Dever::db('shop/sell_order_goods')->insert($data);
             }
         }
@@ -1480,6 +1537,10 @@ class Sell
             $info['coupon_cash'] = 0;
         }
 
+        if (!$info['discount_cash']) {
+            $info['discount_cash'] = 0;
+        }
+
         if (!$info['kou_cash']) {
             $info['kou_cash'] = 0;
         }
@@ -1576,6 +1637,7 @@ class Sell
                     array('礼品卡抵扣', '¥ ' . round($info['card_code_cash'], 2) . $info['card']),
                     array('钱包抵扣', '¥ ' . round($info['wallet_cash'], 2)),
                     array('抹零', '¥ ' . round($info['kou_cash'], 2)),
+                    array('代理优惠', '¥ ' . round($info['discount_cash'], 2)),
                 ),
 
                 $time,

+ 1 - 1
app/shop/src/Buy.php

@@ -248,7 +248,7 @@ class Buy extends Core
 			Dever::alert('收货地址不能为空');
 		}
 
-		$pay = Dever::load('shop/lib/sell')->pay($this->data['method'], $this->data['pay_method'], 1, $this->user, $this->shop, $this->data['name'], $this->data['num'], $this->data['list'], $this->data['oprice'], $this->data['price'], 0, $address_id, $invoice_id, $info, $this->data['card'], $this->data['wallet_cash'], $this->data['coupon_id'], $this->data['user_coupon_id'], $this->data['coupon_cash'], $cart, 5, $refer);
+		$pay = Dever::load('shop/lib/sell')->pay($this->data['method'], $this->data['pay_method'], 1, $this->user, $this->shop, $this->data['name'], $this->data['num'], $this->data['list'], $this->data['oprice'], $this->data['price'], 0, $address_id, $invoice_id, $info, $this->data['card'], $this->data['wallet_cash'], $this->data['coupon_id'], $this->data['user_coupon_id'], $this->data['coupon_cash'], $this->data['discount_id'], $this->data['discount_cash'], $cart, 5, $refer);
 		return $pay;
 	}
 

+ 1 - 1
app/shop/src/Main.php

@@ -174,7 +174,7 @@ class Main extends Core
     # 根据店铺获取商品列表
     public function getGoods()
     {
-        return Dever::load('shop/lib/goods')->getList();
+        return Dever::load('shop/lib/goods')->getList($this->uid);
     }
 
     # 获取文章详情