Ver código fonte

Merge branch 'master' of http://git.dever.cc/dever-product/churen

Your Name 2 anos atrás
pai
commit
7574a212a2

+ 11 - 5
app/cash/lib/Cron.php

@@ -45,6 +45,7 @@ class Cron
             $where['pay_type'] = 1;
         	$this->up($where, $v, 'shop', $num);
         }
+        return 'ok';
     }
 
     # 处理门店零售对账单
@@ -61,8 +62,9 @@ class Cron
             $where['type'] = 1;
             $where['type_id'] = $v['id'];
             $where['pay_type'] = '2,3';
-            $this->up($where, $v, 'shop', $num);
+            $this->up($where, $v, 'shop_sell', $num);
         }
+        return 'ok';
     }
 
     public function store_api(){}
@@ -110,6 +112,10 @@ class Cron
     	} else {
             $method = 'day';
         }
+        $table = 'cash/' . $type;
+        if ($type == 'shop_sell') {
+            $type = 'shop';
+        }
 
     	list($start, $end) = Dever::$method($num);
 
@@ -121,7 +127,7 @@ class Cron
         $data['type'] = $info['stat_type'];
         $data['day'] = $start;
         $data['t'] = $k;
-        $find = Dever::db('cash/' . $type)->find($data);
+        $find = Dever::db($table)->find($data);
         if ($type == 'factory') {
             $msg_type = 4;
             $cash = Dever::db('cash/order')->getPCash($where);
@@ -137,10 +143,10 @@ class Cron
         $data['start'] = $start;
         $data['end'] = $end;
         if (!$find) {
-            $id = Dever::db('cash/' . $type)->insert($data);
+            $id = Dever::db($table)->insert($data);
         } else {
             $id = $data['where_id'] = $find['id'];
-            Dever::db('cash/' . $type)->update($data);
+            Dever::db($table)->update($data);
         }
 
         if ($id > 0 && $type == 'store') {
@@ -157,7 +163,7 @@ class Cron
             $data['cash'] += $up['cash'];
             $data['num'] += $up['num'];
             $data['where_id'] = $id;
-            Dever::db('cash/' . $type)->update($data);
+            Dever::db($table)->update($data);
         }
 
         if (($type == 'factory' || $type == 'store') && Dever::project('message') && $id) {

+ 19 - 12
app/cash/lib/Set.php

@@ -33,10 +33,13 @@ class Set
         return date($string, $day);
     }
 
-    public function statYes($info, $type)
+    public function statYes($info, $type, $source = false)
     {
         $table = 'cash/' . $type;
 
+        if ($type == 'shop_sell') {
+            $type = 'shop';
+        }
         $info = is_array($info) ? $info : Dever::db($table)->one($info);
         $other = Dever::db($type . '/info')->find($info[$type . '_id']);
         if (!$other) {
@@ -99,7 +102,7 @@ class Set
         if ($data) {
             Dever::db($table)->update(array('where_id' => $id, 'status' => 2));
 
-            if ($type == 'shop_sell') {
+            if ($type == 'shop_sell' && $data['cash'] > 0) {
                 $card = Dever::db('cash/order')->getCardAll(array('start'=>$data['start'],'end'=>$data['end'],'pay_type'=>2,'status'=>2,'type'=>1,'type_id'=>$data['shop_id'],'state'=>1));
                 $shop = Dever::db('shop/info')->find($data['shop_id']);
                 if ($card && $card['cash'] > 0) {
@@ -149,6 +152,8 @@ class Set
         $show = Dever::input('show', 1);
         $type = Dever::input('type', 'shop');
         $pay_type = 1;
+        $table = 'cash/' . $type;
+        $source_type = $type;
         if ($type == 'shop') {
             $search_option_type = 1;
             $name = '门店';
@@ -156,6 +161,7 @@ class Set
             $search_option_type = 1;
             $pay_type = '2,3';
             $name = '门店零售';
+            $type = 'shop';
         } elseif ($type == 'store') {
             $search_option_type = 3;
             $name = '仓库';
@@ -164,8 +170,6 @@ class Set
             $name = '工厂';
         }
 
-        $table = 'cash/' . $type;
-
         $config = Dever::db($table)->config;
 
         $info = Dever::db($table)->one($id);
@@ -236,28 +240,28 @@ class Set
         if ($show == 1) {
             if ($info['status'] == 1) {
 
-                $url = Dever::url('lib/set.audit&id='.$id.'&type=' . $type, 'cash');
-                $button[] = '<button class="layui-btn layui-btn-primary" onclick="load(\''.$url.'\', \''.$this->statYes($info, $type).'\', \'请确认\')">立即确认</button>';
+                $url = Dever::url('lib/set.audit&id='.$id.'&type=' . $source_type, 'cash');
+                $button[] = '<button class="layui-btn layui-btn-primary" onclick="load(\''.$url.'\', \''.$this->statYes($info, $source_type).'\', \'请确认\')">立即确认</button>';
             }
             $config['phone'] = '联系人:' . $other['truename'] . ',联系电话:' . $other['mobile'];
             $button[] = '<button class="layui-btn layui-btn-primary" onclick="showAlert(\''.$config['phone'].'\')">联系'.$name.'</button>';
 
             $start = date('Y-m-d H:i:s', $info['start']);
             $end = date('Y-m-d H:i:s', $info['end']);
-            $out = Dever::url('lib/set.excel?id=' . $info['id'] . '&type=' . $type, 'cash');
+            $out = Dever::url('lib/set.excel?id=' . $info['id'] . '&type=' . $source_type, 'cash');
             
             $button[] = '<a class="layui-btn layui-btn-primary" href="'.$out.'">导出对账单</a>';
         } elseif ($show == 2) {
             if ($info[$type . '_status'] == 1 && $show != 1) {
 
-                $url = Dever::url('lib/set.audit_other&id='.$id.'&type=' . $type, 'cash');
-                $button[] = '<button class="layui-btn layui-btn-primary" onclick="load(\''.$url.'\', \''.$this->statYes($info, $type).'\', \'请确认\')">立即确认</button>';
+                $url = Dever::url('lib/set.audit_other&id='.$id.'&type=' . $source_type, 'cash');
+                $button[] = '<button class="layui-btn layui-btn-primary" onclick="load(\''.$url.'\', \''.$this->statYes($info, $source_type).'\', \'请确认\')">立即确认</button>';
             }
             $config = Dever::load('factory/admin/auth.config');
             $config['phone'] = '联系电话:' . $config['dz_phone'];
             $button[] = '<button class="layui-btn layui-btn-primary" onclick="showAlert(\''.$config['phone'].'\')">联系对账专员</button>';
             
-            $print = Dever::url('admin/stat.print?id=' . $info['id'] . '&type=' . $type, $type);
+            $print = Dever::url('admin/stat.print?id=' . $info['id'] . '&type=' . $source_type, $type);
 
             $button[] = '<a class="layui-btn layui-btn-primary" href="'.$print.'" target="_blank">打印对账单</a>';
         }
@@ -401,6 +405,7 @@ class Set
         $pay_type = 1;
         if ($type == 'shop_sell') {
             $pay_type = '2,3';
+            $type = 'shop';
         }
 
         $config = Dever::db($table)->config;
@@ -478,20 +483,22 @@ class Set
         }
 
         $type = Dever::input('type', 'shop');
+
+        $table = 'cash/' . $type;
+
         $pay_type = 1;
         if ($type == 'shop') {
             $name = '门店';
         } elseif ($type == 'shop_sell') {
             $pay_type = '2,3';
             $name = '门店';
+            $type = 'shop';
         } elseif ($type == 'store') {
             $name = '仓库';
         } elseif ($type == 'factory') {
             $name = '工厂';
         }
 
-        $table = 'cash/' . $type;
-
         $config = Dever::db($table)->config;
 
         $info = Dever::db($table)->one($id);

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

@@ -570,6 +570,8 @@ $config = array
             'fast' => array('属性设置', '"info_attr&project=goods&search_option_info_id={id}&search_option_category={category}&oper_parent=info&oper_project=goods&oper_save_jump=info&where_id={id}"', '{price_type} == 2'),
 
             'fast_list' => array('价格设置', '"info_sku&project=goods&goods_id={id}&page_type=1"', '{price_type} > 0'),
+
+            'list2' => array('价格模板', '"goods&project=price&search_option_goods_id={id}&oper_table=info&oper_project=goods"', '{price_type} > 0'),
             'br1' => array('<br />'),
             //'delete' => '删除',
         ),

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

@@ -63,7 +63,11 @@ class Set
                     } else {
                         if ($type == 'store_id') {
                             $result[$i]['price'] = $v['f_price'];
-                        } 
+                        }
+                        if ($type == 'store_id' || $type == 'shop_id') {
+                            $result[$i]['price_template'] = Dever::db('price/goods')->select(array('goods_id' => $v['id']));
+                            $result[$i]['price_template_id'] = (isset($other['price_id']) && $other['price_id']) ? $other['price_id'] : 0;
+                        }
                         if ($other) {
                             if (isset($other['min'])) {
                                 $result[$i]['min'] = $other['min'];
@@ -158,6 +162,11 @@ class Set
                                 if ($type == 'store_id') {
                                     $children['price'] = $v1['f_price'];
                                 }
+                                if ($type == 'store_id' || $type == 'shop_id') {
+                                    $children['price_template'] = $result[$i]['price_template'];
+                                    $children['price_template_sku'] = Dever::db('price/goods_sku')->getDataByPrice(array('goods_id' => $v['id'], 'sku_id' => $v1['id']));
+                                    $children['price_template_id'] = (isset($other_sku['price_id']) && $other_sku['price_id']) ? $other_sku['price_id'] : 0;
+                                }
                                 $children['total'] = 0;
                                 if ($other_sku) {
                                     if (isset($other_sku['min'])) {

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

@@ -107,7 +107,12 @@ class Sku
         if ($config['key'] == -1) {
 
             if ($config['other']) {
-                $info = Dever::db($table)->one($where);
+                if ($config['other'] == 'price') {
+                    $info = Dever::db($table)->one($config['other_id']);
+                } else {
+                    $info = Dever::db($table)->one($where);
+                }
+                
             } else {
                 $info = Dever::db($table)->one($config['goods_id']);
             }
@@ -388,7 +393,9 @@ class Sku
         if ($other) {
             $other_col = $other . '_id';
             $sku_value = Dever::db($other . '/goods_sku')->getData(array('goods_id' => $info['id'], $other_col => $other_id, 'state_1' => 1));
-
+            if ($other == 'price') {
+                $other_col = 'id';
+            }
             $input = '<input type="hidden" name="goods_id" value="'.$info['id'].'"/><input type="hidden" name="'.$other_col.'" value="'.$other_id.'"/>';
         }
 
@@ -461,7 +468,7 @@ class Sku
 
         if (!$group_attr) {
 
-            $prefix = '[总价]:';
+            $prefix = '[单一规格]:';
 
             if (!$update && $col_num <= 1) {
                 $head = '';
@@ -516,7 +523,7 @@ class Sku
 
         } else {
             
-            $prefix = '[组合格]:';
+            $prefix = '[组合格]:';
 
             $group_attr = Dever::cartesian($group_attr);
 
@@ -685,7 +692,7 @@ class Sku
                 $single_body .= '</tr>';
             }
 
-            $html = $html . '[单选格]:<table class="layui-table">' . $single_head . $single_body . '</table>';
+            $html = $html . '[单选格]:<table class="layui-table">' . $single_head . $single_body . '</table>';
         }
 
         if ($input_attr && $sku_value) {

+ 23 - 3
app/mshop/src/Buy.php

@@ -86,9 +86,29 @@ class Buy extends Core
             $s = isset($sku_id[$k]) ? $sku_id[$k] : -1;
             $n = isset($num[$k]) ? $num[$k] : 1;
             $this->data['list'][$k] = Dever::load('goods/lib/info')->getPayInfo($v, $s, 2);
-            if (isset($data['list'][$k]['min']) && $data['list'][$k]['min'] > 0) {
-                if ($n < $data['list'][$k]['min']) {
-                    $n = $data['list'][$k]['min'];
+
+            $w = array();
+            $w['goods_id'] = $v;
+            $w['sku_id'] = $s;
+            $w['shop_id'] = $this->shop_id;
+            $goods_sku = Dever::db('shop/goods_sku')->find($w);
+            if ($goods_sku) {
+                if (isset($goods_sku['price_id']) && $goods_sku['price_id'] > 0) {
+                    $price_template = Dever::load('price/lib/data')->get($v, $s, $goods_sku['price_id']);
+                    if ($price_template) {
+                        if ($price_template['price_num'] > 0) {
+                            $this->data['list'][$k]['min'] = $price_template['price_num'];
+                        }
+                        if ($price_template['price_buy'] && $price_template['price_buy'] > 0) {
+                            $this->data['list'][$k]['price'] = $price_template['price_buy'];
+                        }
+                    }
+                }
+            }
+
+            if (isset($this->data['list'][$k]['min']) && $this->data['list'][$k]['min'] > 0) {
+                if ($n < $this->data['list'][$k]['min']) {
+                    $n = $this->data['list'][$k]['min'];
                 }
             }
 

+ 156 - 0
app/price/database/goods.php

@@ -0,0 +1,156 @@
+<?php
+
+$config = array
+(
+    # 表名
+    'name' => 'goods',
+    # 显示给用户看的名称
+    'lang' => '商品价格模板',
+    'order' => 200,
+    'menu' => false,
+    'fill' => array
+    (
+        # 从哪个表填充
+        'goods/info' => array
+        (
+            # 条件,另外一个表的字段 => 本表的字段
+            'where' => array('id' => 'goods_id'),
+            # 要填充的数据,另外一个表的字段 => 本表的字段,如果不填写就是所有的
+            'update' => array('price_type' => 'price_type', 'status' => 'status'),
+            # 不需要填充的字段 与update互斥
+            //'no' => array('id', 'seller_id', 'service_id', 'chose', 'state', 'cdate')
+        )
+    ),
+
+    # 数据结构 不同的字段放这里
+    'struct' => array
+    (
+        'id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            //'list'        => true,
+        ),
+
+        'name'      => array
+        (
+            'type'      => 'varchar-800',
+            'name'      => '模板名称',
+            'default'   => '',
+            'desc'      => '模板名称',
+            'match'     => 'is_string',
+            'update'    => 'text',
+            'search'    => 'fulltext',
+            'list'        => true,
+            'edit'        => true,
+        ),
+
+        'goods_id'       => array
+        (
+            'type'      => 'int-11',
+            'name'      => '商品名称',
+            'default'   => '',
+            'desc'      => '商品ID',
+            'match'     => 'is_numeric',
+            'update'    => 'hidden',
+            'value'		=> Dever::input('search_option_goods_id'),
+            'list'      => 'Dever::load("goods/info-one#name", {goods_id})',
+        ),
+
+        'category_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '分类id',
+            'default'   => '',
+            'desc'      => '分类id',
+            'match'     => 'is_numeric',
+        ),
+
+        'price_type'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '价格类型',
+            'default'   => '0',
+            'desc'      => '价格类型',
+            'match'     => 'is_numeric',
+            'table'     => 'goods/info',
+        ),
+
+        'price_sell'     => array
+        (
+            'type'      => 'varchar-100',
+            'name'      => '销售价',
+            'default'   => '',
+            'desc'      => '销售价',
+            'match'     => 'option',
+            'list_name' => '模板价格',
+            'list'      => 'Dever::load("goods/lib/sku.table", "{goods_id}", "price", "{id}", false, false)',
+        ),
+
+        'price_buy'       => array
+        (
+            'type'      => 'varchar-100',
+            'name'      => '门店采购价',
+            'default'   => '',
+            'desc'      => '采购价',
+            'match'     => 'option',
+        ),
+
+        'price_num'       => array
+        (
+            'type'      => 'int-11',
+            'name'      => '起购数',
+            'default'   => '1',
+            'desc'      => '起购数',
+            'match'     => 'is_string',
+        ),
+
+        '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
+    (
+        'edit' => false,
+        'insert' => false,
+        //'delete' => false,
+        'button' => array
+        (
+            '新增' => array('fast', 1, 'goods'),
+        ),
+        # 列表里的按钮
+        'list_button' => array
+        (
+            'fast_list' => array('编辑', '"info_sku&project=goods&goods_id={goods_id}&other=price&other_id={id}&page_type=1"', '{price_type} <= 3'),
+        ),
+    ),
+
+    # request 请求接口定义
+    'request' => array
+    (
+        
+    ),
+);
+
+return $config;

+ 243 - 0
app/price/database/goods_sku.php

@@ -0,0 +1,243 @@
+<?php
+
+$config = array
+(
+    # 表名
+    'name' => 'goods_sku',
+    # 显示给用户看的名称
+    'lang' => '商品价格设置',
+    'order' => 200,
+    'menu' => false,
+
+    # 数据结构 不同的字段放这里
+    'struct' => array
+    (
+        'id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            //'list'        => true,
+        ),
+
+        'price_id'       => array
+        (
+            'type'      => 'int-11',
+            'name'      => '商品价格模板ID',
+            'default'   => '',
+            'desc'      => '商品价格模板ID',
+            'match'     => 'is_numeric',
+            'update'    => 'text',
+            'list'      => true,
+        ),
+
+        'goods_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '商品名称',
+            'default'   => '',
+            'desc'      => '商品名称',
+            'match'     => 'is_numeric',
+            'search'    => array
+            (
+                'api' => 'goods/info-like',
+                'col' => 'name',
+                'result' => 'id',
+            ),
+        ),
+
+        'sku_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '规格型号',
+            'default'   => '-1',
+            'desc'      => '规格型号',
+            'match'     => 'is_numeric',
+        ),
+
+        'price_sell'     => array
+        (
+            'type'      => 'varchar-100',
+            'name'      => '销售价',
+            'default'   => '',
+            'desc'      => '销售价',
+            'match'     => 'option',
+            'update'    => 'text',
+        ),
+
+        'price_buy'       => array
+        (
+            'type'      => 'varchar-100',
+            'name'      => '门店采购价',
+            'default'   => '',
+            'desc'      => '采购价',
+            'match'     => 'option',
+            'update'    => 'text',
+        ),
+
+        'price_num'       => array
+        (
+            'type'      => 'int-11',
+            'name'      => '起购数',
+            'default'   => '1',
+            'desc'      => '起购数',
+            'match'     => 'is_string',
+            'update'    => 'text',
+        ),
+
+        '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,
+        'page_list_table' => 'sku',
+
+        # 自定义快捷新增和编辑
+        'button' => array
+        (
+            //'自定义属性' => array('fast', 1, 'config&where_id=1'),
+        ),
+    ),
+
+    # request 请求接口定义
+    'request' => array
+    (
+    	'getDataPage' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'price_id' => array('yes-t_1.price_id'),
+                'name' => array('yes-t_2.name', 'like'),
+                'column' => array('yes-t_2.column_id', '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' => 'goods/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.cover,t_2.id as id',
+        ),
+
+        'getAllData' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'price_id' => array('yes-t_1.price_id'),
+                'name' => array('yes-t_2.name', 'like'),
+                'column' => array('yes-t_2.column_id', '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' => 'goods/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.cover,t_2.id as id',
+        ),
+
+       	# 列表
+        'getData' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'price_id' => 'yes',
+                'goods_id' => 'yes',
+                'sku_id' => 'yes',
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('id' => 'desc'),
+            'col' => '*|sku_id',
+        ),
+
+        # 列表
+        'getDataByPrice' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'price_id' => 'yes',
+                'goods_id' => 'yes',
+                'sku_id' => 'yes',
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('id' => 'desc'),
+            'col' => '*|price_id',
+        ),
+
+        # 获取单条数据
+        'getOne' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'price_id' => 'yes',
+                'goods_id' => 'yes',
+                'sku_id' => 'yes',
+                'state' => 1,
+            ),
+            'type' => 'one',
+            'col' => '*',
+        ),
+    ),
+);
+
+return $config;

+ 8 - 0
app/price/index.php

@@ -0,0 +1,8 @@
+<?php
+
+define('DEVER_APP_NAME', 'price');
+define('DEVER_APP_LANG', '商品价格模板');
+define('DEVER_APP_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR);
+define('DEVER_MANAGE_ORDER', 98);
+define('DEVER_MANAGE_ICON', 'glyphicon glyphicon-tower layui-icon-component');
+include(DEVER_APP_PATH . '../boot.php');

+ 23 - 0
app/price/lib/Data.php

@@ -0,0 +1,23 @@
+<?php
+
+namespace Price\Lib;
+
+use Dever;
+
+class Data
+{
+    public function get($goods_id, $sku_id, $price_id)
+    {
+    	if ($price_id > 0) {
+            $template = Dever::db('price/goods')->find($price_id);
+            if ($template) {
+            	$sku = Dever::db('price/goods_sku')->find(array('price_id' => $price_id, 'goods_id' => $goods_id, 'sku_id' => $sku_id));
+
+            	if ($sku) {
+            		return $sku;
+            	}
+            }
+        }
+        return array();
+    }
+}

+ 23 - 0
app/price/lib/Sku.php

@@ -0,0 +1,23 @@
+<?php
+
+namespace Price\Lib;
+
+use Dever;
+
+class Sku
+{
+    # 设置sku
+	public $set = array
+    (
+    	# 设置特殊字段
+    	'col' => array
+    	(
+    		'price_buy' => '门店采购价',
+	        'price_sell' => '销售价',
+	        'price_num' => '采购起订数',
+    	),
+
+    	# 设置哪个商品类型无法设置上述字段
+    	'price_type' => 4,
+    );
+}

+ 54 - 18
app/shop/assets/pc/html/setGoods.html

@@ -83,6 +83,8 @@
 </div>
 <script>
     var form;
+    var goods = {};
+    var del_goods = {};
     layui.config(
     {
         base: '../script/lib/layui/admin/' //静态资源所在路径
@@ -96,6 +98,22 @@
         var table = layui.table;
         form = layui.form; 
         var formSelects = layui.formSelects;
+
+        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()
@@ -145,23 +163,6 @@
             setTotal();
         });
     })
-    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() 
     {
@@ -333,10 +334,34 @@
     function create(node)
     {
         if (!get(node.id).length) {
+            var select = '';
+            if (node.price_type < 3) {
+                select = '<select name="goods_price_template[]" class="goods_price_template" style="width: 120px;margin: 10px;" onchange="setPrice($(this), \''+node.id+'\')" lay-ignore>';
+                var l = node.price_template.length;
+                var i = 0;
+                select += '<option value="0_'+node.price+'_1" selected>默认价格模板</option>';
+                var selected = '';
+                for (i = 0; i < l; i=i+1) {
+                    var id = node.price_template[i].id;
+                    var price = node.price_template[i].price_sell;
+                    var price_num = node.price_template[i].price_num;
+                    if (node.price_template_sku && node.price_template_sku[id]) {
+                        price = node.price_template_sku[id].price_sell;
+                        price_num = node.price_template_sku[id].price_num;
+                    }
+                    selected = '';
+                    if (node.price_template_id == id) {
+                        selected = 'selected';
+                    }
+                    select += '<option value="'+id+'_'+price+'_'+price_num+'" '+selected+'>'+node.price_template[i].name+'</option>';
+                }
+                select += '</select>';
+            }
+
             var addtr = '<tr class="mytr" id="goods_'+node.id+'">';
             addtr += '<td class="goods_id">'+node.id+'</td>';
             addtr += '<td class="goods_name">'+node.name+'</td>';     
-            addtr += '<td class="goods_price">'+node.price+'</td>'; 
+            addtr += '<td class="goods_price"><span>'+node.price+'元</span>'+select+'</td>'; 
             addtr += '<td class="goods_total">'+node.total+'</td>';       
             if (node.price_type == 4) {
                 addtr += '<td>组合商品无法设置库存</td>';
@@ -354,9 +379,20 @@
                                   
             addtr += '</tr>';
             $("#goods").append(addtr);
+            form.render();
+            $('.goods_price_template').change();
         }
     }
 
+    function setPrice(e, id)
+    {
+        var val = e.val().split('_');
+        goods[id].price_template_id = val[0];
+        e.parent().find('span').html(val[1] + '元');
+        //goods[id].min = val[2];
+        //e.parent().parent().find('.goods_min').val(val[2]);
+    }
+
     function add(id)
     {
         goods[id].num += 1;

+ 9 - 0
app/shop/database/goods_sku.php

@@ -142,6 +142,15 @@ $config = array
             'list_order' => 6,
         ),
 
+        'price_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '价格模板',
+            'default'   => '0',
+            'desc'      => '价格模板',
+            'match'     => 'option',
+        ),
+
         'add_num'        => array
         (
             'type'      => 'float-11,2',

+ 20 - 5
app/shop/lib/Sell.php

@@ -854,17 +854,32 @@ class Sell
             $n = isset($num[$k]) ? $num[$k] : 1;
 
             $data['list'][$k] = Dever::load('goods/lib/info')->getPayInfo($v, $s);
-            $data['list'][$k]['cash'] = $data['list'][$k]['price'];
 
             $w = array();
             $w['goods_id'] = $v;
             $w['sku_id'] = $s;
             $w['shop_id'] = $data['shop']['id'];
             $goods_sku = Dever::db('shop/goods_sku')->find($w);
-            if ($goods_sku && isset($goods_sku['min'])) {
-                $data['list'][$k]['min'] = $goods_sku['min'];
+            if ($goods_sku) {
+                if (isset($goods_sku['min'])) {
+                    $data['list'][$k]['min'] = $goods_sku['min'];
+                }
+                if (isset($goods_sku['price_id']) && $goods_sku['price_id'] > 0) {
+                    $price_template = Dever::load('price/lib/data')->get($v, $s, $goods_sku['price_id']);
+                    if ($price_template) {
+                        /*
+                        if ($goods_sku['min'] <= 0 && $price_template['price_num'] > 0) {
+                            $data['list'][$k]['min'] = $price_template['price_num'];
+                        }
+                        */
+                        if ($price_template['price_sell'] && $price_template['price_sell'] > 0) {
+                            $data['list'][$k]['price'] = $price_template['price_sell'];
+                        }
+                    }
+                }
             }
-
+            
+            $data['list'][$k]['cash'] = $data['list'][$k]['price'];
             $data['list'][$k]['num'] = $n;
 
             # 2是库存不足
@@ -1200,7 +1215,7 @@ class Sell
             }
             
         } elseif ($wallet_cash) {
-            $wallet_cash = -1*$wallet_cash;
+            //$wallet_cash = -1*$wallet_cash;
             Dever::load('shop/lib/money')->up($order_data['uid'], 12, $wallet_cash, $order_data['id'], '购买商品', 2);
 
             $order_data['type'] = 1;

+ 1 - 0
app/shop/lib/Set.php

@@ -116,6 +116,7 @@ class Set
                 $w['total_num'] = $v['num'];
                 $w['min'] = $v['min'];
                 $w['area'] = $shop['area'];
+                $w['price_id'] = $v['price_template_id'];
                 if (!$info) {
                     Dever::db('shop/goods_sku')->insert($w);
                 } else {

+ 52 - 18
app/store/assets/pc/html/setGoodsNum.html

@@ -82,6 +82,7 @@
 </div>
 <script>
     var form;
+    var goods = {};
     layui.config(
     {
         base: '../script/lib/layui/admin/' //静态资源所在路径
@@ -94,7 +95,24 @@
     {
         var table = layui.table;
         form = layui.form; 
+
         var formSelects = layui.formSelects;
+
+        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()
@@ -133,22 +151,6 @@
             setTotal();
         });
     })
-    var 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();
@@ -318,16 +320,39 @@
     function create(node)
     {
         if (!get(node.id).length) {
+            var select = '';
+            /*
+            if (node.price_type < 3) {
+                select = '<select name="goods_price_template[]" class="goods_price_template" style="width: 120px;margin: 10px;" onchange="setPrice($(this), \''+node.id+'\')" lay-ignore>';
+                var l = node.price_template.length;
+                var i = 0;
+                select += '<option value="0_'+node.price+'" selected>默认价格模板</option>';
+                var selected = '';
+                for (i = 0; i < l; i=i+1) {
+                    var id = node.price_template[i].id;
+                    var price = node.price_template[i].price_buy;
+                    if (node.price_template_sku && node.price_template_sku[id]) {
+                        price = node.price_template_sku[id].price_buy;
+                    }
+                    selected = '';
+                    if (node.price_template_id == id) {
+                        selected = 'selected';
+                    }
+                    select += '<option value="'+id+'_'+price+'" '+selected+'>'+node.price_template[i].name+'</option>';
+                }
+                select += '</select>';
+            }*/
+
             var addtr = '<tr class="mytr" id="goods_'+node.id+'">';
             addtr += '<td class="goods_id">'+node.id+'</td>';
             addtr += '<td class="goods_name">'+node.name+'</td>';     
-            addtr += '<td class="goods_price">'+node.price+'</td>'; 
+            addtr += '<td class="goods_price"><span>'+node.price+'元</span>'+select+'</td>'; 
             addtr += '<td class="goods_price">'+node.total+'</td>';             
             if (node.price_type == 4) {
                 addtr += '<td>组合商品无法设置库存</td>';
             } else {
                 addtr += '<td><div class="jiajian" value='+node.id+'><span class="jian" onclick="dec(\''+node.id+'\')">-</span><input type="text" value="'+node.num+'" class="goods_num"><span class="jia" onclick="add(\''+node.id+'\')">+</span></div></td>';
-            } 
+            }
             if (node.total <= 0) {
                 addtr += '<td><a class="delete_btn" onclick="del(\''+node.id+'\')">删除</a></td>';
             } else {
@@ -335,9 +360,18 @@
             }                 
             addtr += '</tr>';
             $("#goods").append(addtr);
+            form.render();
+            //$('.goods_price_template').change();
         }
     }
 
+    function setPrice(e, id)
+    {
+        var val = e.val().split('_');
+        goods[id].price_template_id = val[0];
+        e.parent().find('span').html(val[1] + '元');
+    }
+
     function add(id)
     {
         goods[id].num += 1;

+ 9 - 0
app/store/database/goods_sku.php

@@ -136,6 +136,15 @@ $config = array
             'list_order' => 6,
         ),
 
+        'price_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '价格模板',
+            'default'   => '0',
+            'desc'      => '价格模板',
+            'match'     => 'option',
+        ),
+
         'add_num'        => array
         (
             'type'      => 'float-11,2',

+ 4 - 0
app/store/lib/Set.php

@@ -114,6 +114,10 @@ class Set
 
                 $w['status'] = $goods_info['status'];
                 $w['total_num'] = $v['num'];
+                if (isset($v['price_template_id']) && $v['price_template_id']) {
+                    $w['price_id'] = $v['price_template_id'];
+                }
+                
                 if (!$info) {
                     Dever::db('store/goods_sku')->insert($w);
                 } else {

+ 70 - 0
service/agent/lib/Tool.php

@@ -592,4 +592,74 @@ class Tool
 
         return 'ok';
     }
+
+    public function test_api()
+    {
+        include_once('/share/lib/php/dever_package/excel/src/PHPExcel.php');
+
+        Dever::config('base')->hook = true;
+        $file = '/www/churen/data/test.xlsx';
+
+        $data = Dever::excelImport($file, 0, 18, 'excel');
+
+        $result = array();
+        $month_key = array_flip($data[1]);
+
+        foreach ($data as $k => $v) {
+            if ($k > 1 && strstr($v['D'], '-')) {
+                $month = date('Y-m', Dever::maketime($v['D']));
+                if ($v['E'] != '街道代理商' && $v['E'] != '区县代理商' && $v['E'] != '城市代理商') {
+                    $v['E'] = '其他';
+                }
+                if (!isset($result[$month][$v['E']])) {
+                    $result[$month][$v['E']] = array();
+                    $result[$month][$v['E']]['total'] = 0;
+                    $result[$month][$v['E']]['touru'] = 0;
+                    $result[$month][$v['E']]['shouyi'] = 0;
+                }
+                $result[$month][$v['E']]['total'] += 1;
+                $result[$month][$v['E']]['touru'] += $v['F'];
+                if (isset($month_key[$month]) && isset($v[$month_key[$month]])) {
+                    $result[$month][$v['E']]['shouyi'] += $v[$month_key[$month]];
+                }
+                $result[$month][$v['E']]['touru'] = round($result[$month][$v['E']]['touru'], 2);
+                $result[$month][$v['E']]['shouyi'] = round($result[$month][$v['E']]['shouyi'], 2);
+            }
+        }
+
+        $header = array('类型', '数量', '投入', '收益');
+
+        $xls = false;
+        $file = '代理商区域数据';
+        $i = 0;
+        $t = count($result) - 1;
+
+        foreach ($result as $k => $v) {
+            $body = array();
+            foreach ($v as $k1 => $v1) {
+                $body[] = array
+                (
+                    $k1,
+                    $v1['total'],
+                    $v1['touru'],
+                    $v1['shouyi'],
+                    
+                );
+            }
+            
+            $i++;
+
+            if ($i == $t) {
+                return Dever::excelExport($body, $header, $file, $i, $k, false, $xls);
+            } else {
+                if (!$xls) {
+                    $xls = Dever::excelExport($body, $header, $file, $i, $k, true);
+                } else {
+                    $xls = Dever::excelExport($body, $header, $file, $i, $k, true, $xls);
+                }
+            }
+        }
+
+        return 'ok';
+    }
 }