dever 3 years ago
parent
commit
d63e836c45
44 changed files with 3660 additions and 245 deletions
  1. 14 1
      app/factory/database/info.php
  2. 15 0
      app/goods/database/info.php
  3. 14 0
      app/goods/database/info_sku.php
  4. 1 0
      app/goods/lib/Info.php
  5. 1 0
      app/goods/lib/Manage.php
  6. 1 0
      app/goods/lib/Sku.php
  7. 5 1
      app/mshop/lib/Buy.php
  8. 5 1
      app/mshop/lib/Out.php
  9. 1 1
      app/mshop/src/Buy.php
  10. 2 56
      app/mshop/src/Data.php
  11. 1 1
      app/mshop/src/Out.php
  12. 180 17
      app/shop/database/buy_order.php
  13. 42 0
      app/shop/database/buy_order_goods.php
  14. 13 6
      app/shop/database/buy_stat.php
  15. 103 10
      app/shop/database/goods_sku.php
  16. 216 0
      app/shop/database/goods_stat.php
  17. 14 0
      app/shop/database/info.php
  18. 79 16
      app/shop/database/out_order.php
  19. 177 28
      app/shop/database/sell_order.php
  20. 43 0
      app/shop/database/sell_order_goods.php
  21. 7 0
      app/shop/database/sell_order_ps.php
  22. 13 6
      app/shop/database/sell_stat.php
  23. 187 0
      app/shop/database/shop_stat.php
  24. 176 0
      app/shop/database/user_buy_stat.php
  25. 218 0
      app/shop/database/user_stat.php
  26. 89 0
      app/shop/lib/Area.php
  27. 225 9
      app/shop/lib/Cron.php
  28. 146 2
      app/shop/lib/Manage.php
  29. 7 0
      app/shop/lib/Refund.php
  30. 63 0
      app/shop/lib/Sell.php
  31. 2 0
      app/shop/lib/Set.php
  32. 657 0
      app/shop/src/Excel.php
  33. 217 0
      app/store/database/goods_log.php
  34. 141 14
      app/store/database/goods_sku.php
  35. 18 3
      app/store/database/info.php
  36. 22 8
      app/store/lib/Manage.php
  37. 3 0
      config/base.php
  38. 2 0
      main/template/pc/home.php
  39. 1 0
      service/agent/assets/pc/html/setGoods.html
  40. 264 0
      service/agent/assets/pc/html/setOrderGoods.html
  41. 43 7
      service/agent/database/order_process.php
  42. 23 0
      service/agent/lib/Manage.php
  43. 104 58
      service/agent/lib/Order.php
  44. 105 0
      service/agent/lib/Order_set.php

+ 14 - 1
app/factory/database/info.php

@@ -398,6 +398,19 @@ return array
 
     'request' => array
     (
-        
+        'like' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'name' => array('yes', 'like'),
+                'id' => 'yes',
+                'status' => 1,
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('reorder' => 'desc', 'id' => 'desc'),
+            'col' => '*|id',
+        ),
     ),
 );

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

@@ -676,6 +676,21 @@ $config = array
                 'sell_num' => array('yes', '+='),
             ),
         ),
+
+        'like' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'name' => array('yes', 'like'),
+                'id' => 'yes',
+                'status' => 1,
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('reorder' => 'desc', 'id' => 'desc'),
+            'col' => '*|id',
+        ),
     ),
 );
 

+ 14 - 0
app/goods/database/info_sku.php

@@ -318,6 +318,20 @@ $config = array
                 'sell_num' => array('yes', '+='),
             ),
         ),
+
+        'like' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'code' => array('yes', 'like'),
+                'id' => 'yes',
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('reorder' => 'desc', 'id' => 'desc'),
+            'col' => '*|id',
+        ),
     ),
 );
 

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

@@ -438,6 +438,7 @@ class Info
             if ($sku && $sku['attr']) {
                 $sku['attr'] = Dever::json_decode($sku['attr']);
                 $info['sku'] = Dever::load('attr/api')->getInfoByJson($sku['attr']);
+                $info['code'] = $sku['code'];
             }
         }
 

+ 1 - 0
app/goods/lib/Manage.php

@@ -81,6 +81,7 @@ class Manage
             Dever::db('shop/goods')->updates(array('option_goods_id' => $id, 'set_status' => $status));
             Dever::db('store/goods')->updates(array('option_goods_id' => $id, 'set_status' => $status));
             Dever::db('factory/goods')->updates(array('option_goods_id' => $id, 'set_status' => $status));
+            Dever::db('store/goods_sku')->updates(array('option_goods_id' => $id, 'set_status' => $status));
         }
 
         # 更新分类id

+ 1 - 0
app/goods/lib/Sku.php

@@ -143,6 +143,7 @@ class Sku
             } else {
                 $update['where_id'] = $info['id'];
                 $update['state'] = 1;
+                print_r($update);
                 $state = Dever::db($sku_table)->update($update);
             }
             

+ 5 - 1
app/mshop/lib/Buy.php

@@ -253,7 +253,7 @@ class Buy
     }
 
     # 发起支付
-    public function action($uid, $type, $type_id, $name, $num, $goods, $price, $info, $refer = '')
+    public function action($uid, $type, $type_id, $name, $num, $goods, $price, $info, $refer = '', $area = '')
     {
         $openid = false;
         if ($uid > 0) {
@@ -268,6 +268,10 @@ class Buy
 
         $order_data['type'] = $type;
         $order_data['type_id'] = $type_id;
+        if ($area) {
+            $order_data['area'] = $area . ',' . $type_id;
+        }
+        
         $order_data['name'] = $name;
         $order_data['num'] = $num;
         $order_data['info'] = $info;

+ 5 - 1
app/mshop/lib/Out.php

@@ -113,9 +113,13 @@ class Out
     }
 
     # 出库下单
-    public function action($type_id, $name, $num, $goods, $price, $member_id, $out_type, $info, $status = 2)
+    public function action($type_id, $name, $num, $goods, $price, $member_id, $out_type, $info, $status = 2, $area = '')
     {
         $order_data = $this->where($type_id);
+        if ($area) {
+            $order_data['area'] = $area . ','  $type_id;
+        }
+        
         $order_data['name'] = $name;
         $order_data['num'] = $num;
         $order_data['info'] = $info;

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

@@ -108,7 +108,7 @@ class Buy extends Core
 
         $this->goods();
 
-        $pay = Dever::load('mshop/lib/buy')->set(1,1)->action($this->passport_uid, 1, $this->shop_id, $this->data['name'], $this->data['num'], $this->data['list'], $this->data['price'], $info, $refer);
+        $pay = Dever::load('mshop/lib/buy')->set(1,1)->action($this->passport_uid, 1, $this->shop_id, $this->data['name'], $this->data['num'], $this->data['list'], $this->data['price'], $info, $refer, $this->shop['area']);
         return $pay;
     }
 

+ 2 - 56
app/mshop/src/Data.php

@@ -74,66 +74,12 @@ class Data extends Core
         $info = Dever::db('shop/sell_order')->find(array('id' => $order_id));
 
         if ($info && $info['shop_id'] == $this->shop_id && $info['status'] < 3) {
-            $config = Dever::db('shop/sell_order')->config;
-            $state = Dever::db('shop/sell_order')->update(array('where_id' => $info['id'], 'status' => 3, 'operdate' => time()));
 
-            # 给用户发消息
-            if ($info['uid'] && $info['uid'] > 0) {
-                $shop = Dever::db('shop/info')->one($info['shop_id']);
-                $msg_param['type'] = 1;//消息类型1是订单消息
-                $msg_param['id'] = $info['id'];
-                $msg_param['name'] = $shop['name'];
-                $msg_param = Dever::json_encode($msg_param);
-                if ($info['method'] == 1) {
-                    $msg = '您有一件自提商品已完成配货,请尽快到指定门店使用取件码取货,取件码:' . $info['code'];
-                    $name = '取货通知';
-                    $wechat_msg = '您的商品已完成配货';
-                } else {
-                    $msg = '您有一件外送商品已开始配送,收货时请将取件码提供给配送员核实货品信息,取件码:' . $info['code'];
-                    $name = '配送通知';
-                    $wechat_msg = '您的商品已开始配送';
-                }
-                
-                Dever::load('message/lib/data')->push(-1, $info['uid'], $name, $msg, 1, 1, false, $msg_param);
-
-                if (Dever::load('wechat_applet')) {
-                    $user = Dever::db('passport/wechat')->one(array('uid' => $info['uid'], 'system_id' => 1, 'system_source' => 5));
-                    if ($user && $user['openid']) {
-                        $info['status_name'] = $config['status'][$info['status']];
-                        $send = array
-                        (
-                            'character_string6' => array
-                            (
-                                'value' => $info['order_num'],
-                            ),
-                            
-                            'phrase7' => array
-                            (
-                                'value' => $info['status_name'],
-                            ),
-                            'thing8' => array
-                            (
-                                'value' => $info['code'],
-                            ),
-                            'amount1' => array
-                            (
-                                'value' => $info['price'] . '元',
-                            ),
-                            'thing5' => array
-                            (
-                                'value' => $wechat_msg,
-                            ),
-                        );
-
-                        $send = Dever::json_encode($send);
-                        Dever::load('wechat_applet/subscribe')->sendOne('order_process', 1, $user['openid'], 'pages/app/order/order?id=' . $info['id'], $send, Dever::config('base')->wechat_applet);
-                    }
-                }
-            }
+            Dever::load('shop/lib/sell')->notice($info);
+            
             if ($info['method'] == 2) {
                 Dever::load('shop/lib/sell')->updatePs($info, 2, $ps_service_id, $ps_order_num);
             }
-
             
             return 'ok';
         } else {

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

@@ -110,7 +110,7 @@ class Out extends Core
 
         $this->goods();
 
-        return Dever::load('mshop/lib/out')->set(1,1)->action($this->shop_id, $this->data['name'], $this->data['num'], $this->data['list'], $this->data['price'], $this->uid, $type, $info);
+        return Dever::load('mshop/lib/out')->set(1,1)->action($this->shop_id, $this->data['name'], $this->data['num'], $this->data['list'], $this->data['price'], $this->uid, $type, $info, 2, $this->shop['area']);
     }
 
     # 打印

+ 180 - 17
app/shop/database/buy_order.php

@@ -27,6 +27,7 @@ $refund_status = array
 );
 
 $type = Dever::config('base')->source;
+unset($type[3]);
 $shop = function()
 {
     $array = array();
@@ -52,13 +53,54 @@ $store = function()
 $search_option_type = Dever::input('search_option_type', 1);
 
 if ($search_option_type == 1) {
-    $search_name = '所属门店';
+    $search_name = '门店名称';
     $search_option = $shop;
     $search_url = 'shop/lib/manage.search';
-} elseif ($search_option_type != 1) {
-    $search_name = '所属仓库';
+    $search_table = 'shop';
+    $search = $search_table . '/info-like';
+    $excel = array
+    (
+        array('导出订单', '门店采购订单', ''),
+        array('导出订单明细', '门店采购订单明细', 'shop/excel.buy_order'),
+    );
+    $source_name = '供货商';
+    $source_order = 4;
+} elseif ($search_option_type == 2) {
+    $search_name = '仓库名称';
     $search_option = $store;
     $search_url = 'store/lib/manage.search';
+    $search_table = 'store';
+    $search = $search_table . '/info-like';
+    $excel = array
+    (
+        array('导出订单', '仓库入库订单', ''),
+        array('导出订单明细', '仓库入库订单明细', 'shop/excel.store_buy_order'),
+    );
+    $source_name = '发货工厂';
+    $source_order = 4;
+}
+
+$search_option_source_type = Dever::input('search_option_source_type');
+if ($search_option_source_type == 2) {
+    $source_name = '仓库名称';
+    $source_order = -1;
+    $excel = array
+    (
+        array('导出订单', '仓库发货订单', ''),
+        array('导出订单明细', '仓库发货订单明细', 'shop/excel.store_buy_order_fa'),
+    );
+} elseif ($search_option_source_type == 3) {
+    $search_option_type = 3;
+    $search_name = '收件人名称';
+    $search_table = 'store';
+    $search = $search_table . '/info-like';
+    $source_name = '工厂名称';
+    $source_order = -1;
+    $excel = array
+    (
+        array('导出订单', '工厂发货订单', ''),
+        array('导出订单明细', '工厂发货订单明细', 'shop/excel.factory_buy_order_fa'),
+    );
 }
 
 return array
@@ -69,6 +111,7 @@ return array
     'lang' => '采购订单',
     'order' => 99,
     'status' => $status,
+    'refund_status' => $refund_status,
     'end' => array
     (
         'insert' => 'shop/lib/manage.buyOrderUpdate',
@@ -92,11 +135,14 @@ return array
         'type'      => array
         (
             'type'      => 'int-11',
-            'name'      => '采购人类型',
+            'name'      => '收件人类型',
             'default'   => '',
-            'desc'      => '采购人类型',
+            'desc'      => '收件人类型',
             'match'     => 'is_numeric',
-            'search'    => 'hidden',
+            'search'    => $search_option_source_type == 3 ? 'select' : 'hidden',
+            'option'    => $type,
+            'list'      => $search_option_source_type == 3 ? true : false,
+            'list_order' => 3,
         ),
 
         'type_id'      => array
@@ -106,10 +152,54 @@ return array
             'default'   => '',
             'desc'      => '拥有人',
             'match'     => 'is_numeric',
-            'search'    => $search_option_type == 3 ? '' : 'select',
-            'option'    => $search_option,
+            //'search'    => $search_option_type == 3 ? '' : 'select',
+            'search'    => $search_option_type == 3 ? '' : array
+            (
+                'api' => $search,
+                'col' => 'name',
+                'result' => 'id',
+            ),
+            //'option'    => $search_option,
             //'update_search' => $search_url,
             'list'      => 'Dever::load("shop/lib/manage.buyInfo", "{type}", "{type_id}")',
+            'list_order' => 2,
+        ),
+
+        'shop-info-sid'=> array
+        (
+            'name'      => '门店编号',
+            'default'   => '',
+            'desc'      => '门店编号',
+            'match'     => 'option',
+            # 读取另外表的关联方式
+            'sync'      => array('type_id', 'id'),
+            'list'      => $search_option_type == 1 ? true : false,
+            'list_order' => 1,
+        ),
+
+        'shop-info-type'=> array
+        (
+            'name'      => '门店类型',
+            'default'   => '',
+            'desc'      => '门店类型',
+            'match'     => 'option',
+            # 读取另外表的关联方式
+            'sync'      => array('type_id', 'id'),
+            'list'      => $search_option_type == 1 ? 'Dever::load("shop/lib/manage.shopInfoType", {shop-info-type})' : false,
+            'list_order' => 3,
+        ),
+
+        'area'       => array
+        (
+            'type'      => 'varchar-500',
+            'name'      => '所在街道',
+            'default'   => '',
+            'desc'      => '所在街道',
+            'match'     => 'option',
+            'search'    => $search_option_type == 1 ? 'linkage' : false,
+            'update'    => 'linkage',
+            'option'    => Dever::url('lib/area.get', $search_table),
+            //'list'      => 'Dever::load("area/api.string", "{area}")',
         ),
 
         'source_type'      => array
@@ -119,16 +209,30 @@ return array
             'default'   => '',
             'desc'      => '供货商类型',
             'match'     => 'is_numeric',
+            'search'    => 'hidden',
+            'value'     => $search_option_source_type,
         ),
 
         'source_id'      => array
         (
             'type'      => 'int-11',
-            'name'      => '供货商',
+            'name'      => $source_name,
             'default'   => '',
             'desc'      => '供货商',
             'match'     => 'is_numeric',
+            'search'    => $search_option_source_type == 2 ? array
+            (
+                'api' => 'store/info-like',
+                'col' => 'name',
+                'result' => 'id',
+            ) : array
+            (
+                'api' => 'factory/info-like',
+                'col' => 'name',
+                'result' => 'id',
+            ),
             'list'      => 'Dever::load("shop/lib/manage.buyInfo", "{source_type}", "{source_id}")',
+            'list_order' => $source_order,
         ),
 
         'name'      => array
@@ -153,13 +257,14 @@ return array
         'order_num'      => array
         (
             'type'      => 'varchar-100',
-            'name'      => '订单号',
+            'name'      => '订单号',
             'default'   => '',
-            'desc'      => '订单号',
+            'desc'      => '订单号',
             'match'     => 'is_string',
             'update'    => 'text',
             'search'    => 'fulltext',
             'list'      => true,
+            'list_order' => 5,
         ),
 
         'price'      => array
@@ -171,6 +276,8 @@ return array
             'match'     => 'option',
             'update'    => 'text',
             'list'      => $search_option_type == 1 ? true : false,
+            'list_name'   => '订货单总金额',
+            'list_order' => 7,
         ),
 
         'p_price'     => array
@@ -181,7 +288,9 @@ return array
             'desc'      => '购买价格',
             'match'     => 'option',
             'update'    => 'text',
-            'list'      => $search_option_type == 2 ? true : false,
+            'list'      => $search_option_source_type == 3 ? true : false,
+            'list_name'   => '订货单总金额',
+            'list_order' => 7,
         ),
 
         'num'        => array
@@ -193,6 +302,8 @@ return array
             'match'     => 'is_numeric',
             'search'    => 'select',
             'list'        => true,
+            'list_name'   => '订货总数量',
+            'list_order' => 6,
         ),
 
         'refund_cash'      => array
@@ -203,6 +314,9 @@ return array
             'desc'      => '退款合计金额',
             'match'     => 'option',
             'update'    => 'text',
+            'list'      => ($search_option_type == 1 || $search_option_source_type == 3) ? true : false,
+            'list_name'   => '退款金额',
+            'list_order' => 11,
         ),
 
         'refund_p_cash'      => array
@@ -213,17 +327,23 @@ return array
             'desc'      => '退款合计金额',
             'match'     => 'option',
             'update'    => 'text',
+            'list'      => ($search_option_type == 2 || $search_option_source_type == 2 || $search_option_source_type == 3) ? 'Dever::load("shop/lib/manage.buyInfoRefundNum", "{id}")' : false,
+            'list_name'   => '已退商品数量',
+            'list_order' => 11,
         ),
 
         'refund_status'        => array
         (
             'type'      => 'tinyint-1',
-            'name'      => '申请退款类型',
+            'name'      => '退款状态',
             'default'   => '1',
-            'desc'      => '申请退款类型',
+            'desc'      => '退款状态',
             'match'     => 'is_numeric',
             'option'    => $refund_status,
             //'search'    => 'select',
+            'list'      => $search_option_type == 1 ? 'Dever::load("shop/lib/manage.buyInfoRefundStatus", "{id}")' : false,
+            'list_name'   => '退款状态',
+            'list_order' => 10,
         ),
 
         'info'      => array
@@ -246,6 +366,8 @@ return array
             'option'    => $status,
             'search'    => 'select',
             'list'      => 'Dever::load("mshop/lib/buy.orderStatus", "{id}")',
+            'list_name'   => '订货单状态',
+            'list_order' => 9,
         ),
 
         'audit'        => array
@@ -256,7 +378,7 @@ return array
             'desc'      => '审核状态',
             'match'     => 'is_numeric',
             'option'    => $audit,
-            'search'    => 'select',
+            //'search'    => 'select',
             'update'    => 'radio',
         ),
 
@@ -296,6 +418,30 @@ return array
             'match'     => 'is_numeric',
             'desc'      => '',
         ),
+
+        'shop-buy_order_ps-cdate'=> array
+        (
+            'name'      => '发货日期',
+            'default'   => '',
+            'desc'      => '发货日期',
+            'match'     => 'option',
+            # 读取另外表的关联方式
+            'sync'      => array('id', 'order_id'),
+            'list'      => ($search_option_type == 2 || $search_option_source_type == 2 || $search_option_source_type == 3) ? '"{shop-buy_order_ps-cdate}" ? date("Y-m-d H:i", {shop-buy_order_ps-cdate}) : "-"' : false,
+            'list_order' => 9,
+        ),
+
+        'shop-buy_order_ps-ydate'=> array
+        (
+            'name'      => '收货日期',
+            'default'   => '',
+            'desc'      => '收货日期',
+            'match'     => 'option',
+            # 读取另外表的关联方式
+            'sync'      => array('id', 'order_id'),
+            'list'      => $search_option_type == 2 ? '"{shop-buy_order_ps-ydate}" ? date("Y-m-d H:i", {shop-buy_order_ps-ydate}) : "-"': false,
+            'list_order' => 9,
+        ),
         
         'cdate'     => array
         (
@@ -305,8 +451,10 @@ return array
             'desc'      => '',
             # 只有insert时才生效
             'insert'    => true,
-            'search'    => 'date',
-            'list'        => 'date("Y-m-d H:i:s", {cdate})',
+            'search'    => 'sdate',
+            'list'        => 'date("Y-m-d H:i", {cdate})',
+            'list_name'   => '订货日期',
+            'list_order' => 8,
             //'list'      => 'Dever::load("service/lib/manage.showOrderTime", "{id}")',
         ),
     ),
@@ -316,6 +464,7 @@ return array
         'delete' => false,
         'edit' => false,
         'insert' => false,
+        'excel' => $excel,
 
         'button' => array
         (
@@ -491,5 +640,19 @@ return array
             'order' => array('cdate' => 'desc'),
             'col' => '*',
         ),
+        # 获取商品数量
+        'getGoodsTotal' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'type' => 'yes',
+                'type_id' => 'yes',
+                'status' => array('yes', 'in'),
+                'state' => 1,
+            ),
+            'type' => 'one',
+            'col' => 'sum(num) as total',
+        ),
     ),
 );

+ 42 - 0
app/shop/database/buy_order_goods.php

@@ -190,5 +190,47 @@ return array
             'type' => 'count',
             'col' => '*',
         ),
+
+        # 获取商品数量
+        'getGoodsNum' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'order_id' => 'yes',
+                'status' => 'yes',
+                'state' => 1,
+            ),
+            'type' => 'one',
+            'col' => 'sum(num) as total',
+        ),
+
+        # 获取商品数量
+        'getGoodsTotal' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'type' => array('yes-t_2.type'),
+                'type_id' => array('yes-t_2.type_id'),
+                'status' => array('yes-t_2.status', 'in'),
+                'goods_id' => array('yes-t_1.goods_id'),
+                'sku_id' => array('yes-t_1.sku_id'),
+                'state' => array('yes-t_2.state', 1),
+                'state_1' => array('yes-t_1.state', 1),
+            ),
+            # 联表
+            'join' => array
+            (
+                array
+                (
+                    'table' => 'shop/buy_order',
+                    'type' => 'left join',
+                    'on' => array('order_id','id'),
+                ),
+            ),
+            'type' => 'one',
+            'col' => 'id,sum(t_2.num) as total',
+        ),
     ),
 );

+ 13 - 6
app/shop/database/buy_stat.php

@@ -58,13 +58,20 @@ return array
         'shop_id'      => array
         (
             'type'      => 'int-11',
-            'name'      => '所属门店',
+            'name'      => '门店名称',
             'default'   => '',
-            'desc'      => '所属门店',
+            'desc'      => '门店名称',
             'match'     => 'is_numeric',
-            'option'    => $shop,
+            'search'    => 'select',
+            //'option'    => $shop,
             'update'    => 'hidden',
             'search'    => 'hidden',
+            'search'    => array
+            (
+                'api' => 'shop/info-like',
+                'col' => 'name',
+                'result' => 'id',
+            ),
             'value'     => Dever::input('search_option_shop_id'),
             'list'      => 'Dever::load("shop/info-one#name", {shop_id})',
         ),
@@ -72,13 +79,13 @@ return array
         'area'       => array
         (
             'type'      => 'varchar-500',
-            'name'      => '选择地区',
+            'name'      => '所在街道',
             'default'   => '',
-            'desc'      => '选择地区',
+            'desc'      => '所在街道',
             'match'     => 'option',
             'search'    => 'linkage',
             'update'    => 'linkage',
-            'option'    => Dever::url('api.get?level_total=4', 'area'),
+            'option'    => Dever::url('lib/area.get', 'shop'),
             //'list'      => 'Dever::load("area/api.string", "{area}")',
         ),
 

+ 103 - 10
app/shop/database/goods_sku.php

@@ -27,14 +27,87 @@ $config = array
             //'list'        => true,
         ),
 
+        'shop-info-sid'=> array
+        (
+            'name'      => '门店编号',
+            'default'   => '',
+            'desc'      => '门店编号',
+            'match'     => 'option',
+            # 读取另外表的关联方式
+            'sync'      => array('shop_id', 'id'),
+            'list'      => true,
+            'list_order' => 1,
+        ),
+
         'shop_id'      => array
         (
             'type'      => 'int-11',
-            'name'      => '所属门店',
+            'name'      => '门店名称',
             'default'   => '',
-            'desc'      => '所属门店',
+            'desc'      => '门店名称',
             'match'     => 'is_numeric',
-            //'list'      => 'Dever::load("shop/info-find#name", {shop_id})',
+            'search'    => 'select',
+            //'option'    => $shop,
+            'update'    => 'hidden',
+            'search'    => 'hidden',
+            'search'    => array
+            (
+                'api' => 'shop/info-like',
+                'col' => 'name',
+                'result' => 'id',
+            ),
+            'value'     => Dever::input('search_option_shop_id'),
+            'list'      => 'Dever::load("shop/info-one#name", {shop_id})',
+            'list_order' => 2,
+        ),
+
+        'shop-info-type'=> array
+        (
+            'name'      => '门店类型',
+            'default'   => '',
+            'desc'      => '门店类型',
+            'match'     => 'option',
+            # 读取另外表的关联方式
+            'sync'      => array('shop_id', 'id'),
+            'list'      => 'Dever::load("shop/lib/manage.shopInfoType", {shop-info-type})',
+            'list_order' => 3,
+        ),
+
+        'goods-info-code'=> array
+        (
+            'name'      => '商品编码',
+            'default'   => '',
+            'desc'      => '商品编码',
+            'match'     => 'option',
+            # 读取另外表的关联方式
+            'sync'      => array('sku_id', 'id'),
+            'list'      => true,
+            'list_order' => 4,
+        ),
+
+        'goods-info-price'=> array
+        (
+            'name'      => '零售单价',
+            'default'   => '',
+            'desc'      => '零售单价',
+            'match'     => 'option',
+            # 读取另外表的关联方式
+            'sync'      => array('sku_id', 'id'),
+            'list'      => true,
+            'list_order' => 7,
+        ),
+
+        'area'       => array
+        (
+            'type'      => 'varchar-500',
+            'name'      => '所在街道',
+            'default'   => '',
+            'desc'      => '所在街道',
+            'match'     => 'option',
+            'search'    => 'linkage',
+            'update'    => 'linkage',
+            'option'    => Dever::url('lib/area.get', 'shop'),
+            //'list'      => 'Dever::load("area/api.string", "{area}")',
         ),
 
         'goods_id'      => array
@@ -44,16 +117,25 @@ $config = array
             'default'   => '',
             'desc'      => '商品名称',
             'match'     => 'is_numeric',
-            //'list'      => 'Dever::load("goods/info-find#name", {goods_id})',
+            'search'    => array
+            (
+                'api' => 'goods/info-like',
+                'col' => 'name',
+                'result' => 'id',
+            ),
+            'list'      => 'Dever::load("goods/info-find#name", {goods_id})',
+            'list_order' => 5,
         ),
 
         'sku_id'      => array
         (
             'type'      => 'int-11',
-            'name'      => 'sku_id',
+            'name'      => '规格型号',
             'default'   => '-1',
-            'desc'      => 'sku_id',
+            'desc'      => '规格型号',
             'match'     => 'is_numeric',
+            'list'      => 'Dever::load("shop/lib/manage.getSku", {goods_id}, {sku_id})',
+            'list_order' => 6,
         ),
 
         'add_num'        => array
@@ -63,6 +145,9 @@ $config = array
             'default'   => '0',
             'desc'      => '新增库存',
             'match'     => 'is_numeric',
+            'list_name' => '当前库存',
+            'list'      => '{total_num} - {sell_num}',
+            'list_order' => 8,
         ),
 
         'total_num'        => array
@@ -72,6 +157,8 @@ $config = array
             'default'   => '0',
             'desc'      => '总库存',
             'match'     => 'is_numeric',
+            'list'      => true,
+            'list_order' => 10,
         ),
 
         'sell_num'      => array
@@ -81,8 +168,10 @@ $config = array
             'default'   => '0',
             'desc'      => '请填写销量',
             'match'     => 'option',
-            'search'    => 'order',
-            //'list'      => true,
+            //'search'    => 'order',
+            'list_name' => '占用库存',
+            'list'      => true,
+            'list_order' => 9,
         ),
 
         'min'       => array
@@ -94,6 +183,9 @@ $config = array
             'match'     => 'is_string',
             'update'    => 'text',
             //'list'      => true,
+            'list_name' => '在途库存',
+            'list'      => 'Dever::load("shop/lib/manage.getGoodsTotal", 1, {shop_id})',
+            'list_order' => 10,
         ),
 
         'reorder'       => array
@@ -105,9 +197,9 @@ $config = array
             'match'     => 'option',
             //'update'  => 'text',
             'search'    => 'order',
-            'list'      => true,
+            //'list'      => true,
             'order'     => 'desc',
-            'edit'      => true,
+            //'edit'      => true,
         ),
 
         'state'     => array
@@ -138,6 +230,7 @@ $config = array
         'edit' => false,
         'delete' => false,
         'num' => false,
+        'excel' => true,
         'page_list_table' => 'sku',
 
         # 自定义快捷新增和编辑

+ 216 - 0
app/shop/database/goods_stat.php

@@ -0,0 +1,216 @@
+<?php
+
+$config = array
+(
+    # 表名
+    'name' => 'goods_stat',
+    # 显示给用户看的名称
+    'lang' => '门店单品销售统计',
+    'order' => -12,
+
+    # 数据结构 不同的字段放这里
+    'struct' => array
+    (
+        'id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            //'list'        => true,
+        ),
+
+        'day'     => array
+        (
+            'type'      => 'int-11',
+            'name'      => '日期',
+            'default'   => '',
+            'match'     => 'is_numeric',
+            'desc'      => '',
+            'search'    => 'day',
+            'search_button' => array
+            (
+                'sum' => 'num,cash',
+                'option' => array(
+                    'day' => '按天',
+                    'week' => '按周',
+                    'month' => '按月',
+                ),
+                'group' => 'goods_id',
+            ),
+            'order'     => 'desc',
+            'list'      => 'Dever::showDay("{day}")',
+        ),
+
+        'shop_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '门店名称',
+            'default'   => '',
+            'desc'      => '门店名称',
+            'match'     => 'is_numeric',
+            'search'    => 'select',
+            //'option'    => $shop,
+            'update'    => 'hidden',
+            'search'    => 'hidden',
+            'search'    => array
+            (
+                'api' => 'shop/info-like',
+                'col' => 'name',
+                'result' => 'id',
+            ),
+            'value'     => Dever::input('search_option_shop_id'),
+            //'list'      => 'Dever::load("shop/info-one#name", {shop_id})',
+        ),
+
+        'area'       => array
+        (
+            'type'      => 'varchar-500',
+            'name'      => '所在街道',
+            'default'   => '',
+            'desc'      => '所在街道',
+            'match'     => 'option',
+            'search'    => 'linkage',
+            'update'    => 'linkage',
+            'option'    => Dever::url('lib/area.get', 'shop'),
+            //'list'      => 'Dever::load("area/api.string", "{area}")',
+        ),
+
+        'goods_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '商品名称',
+            'default'   => '',
+            'desc'      => '商品名称',
+            'match'     => 'is_numeric',
+            'search'    => array
+            (
+                'api' => 'goods/info-like',
+                'col' => 'name',
+                'result' => 'id',
+                'search' => 'goods_id',//本表的字段,默认为当前的字段
+            ),
+            'list'      => 'Dever::load("goods/info-find#name", {goods_id})',
+            'list_order' => 5,
+        ),
+
+        'category'      => array
+        (
+            'type'      => 'varchar-500',
+            'name'      => '商品分类',
+            'default'   => '',
+            'desc'      => '商品分类',
+            'match'     => 'is_string',
+            'search'    => 'linkage',
+            'update'    => 'linkage',
+            'option'    => Dever::url('api.get', 'category'),
+            'list'        => 'Dever::load("category/api.string", "{category}")',
+        ),
+
+        'num'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '数量',
+            'default'   => '0',
+            'desc'      => '数量',
+            'match'     => 'is_numeric',
+            'search'    => 'order',
+            'list'      => true,
+        ),
+
+        'cash'        => array
+        (
+            'type'      => 'varchar-100',
+            'name'      => '金额',
+            'default'   => '0',
+            'desc'      => '金额',
+            'match'     => 'is_string',
+            'search'    => 'order',
+            'list'      => true,
+        ),
+
+        'hb'      => array
+        (
+            'type'      => 'varchar-11',
+            'name'      => '环比增长',
+            'default'   => '0',
+            'desc'      => '环比增长',
+            'match'     => 'option',
+            'update'    => 'text',
+            'list'      => 'Dever::load("shop/lib/manage.getGoodsHb", "{num}", "{time}", "{goods_id}")',
+        ),
+
+        '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,
+        'num' => false,
+        'excel' => true,
+    ),
+
+    # request 请求接口定义
+    'request' => array
+    (
+        'list' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'shop_id' => 'yes',
+                'area' => array('yes', 'like'),
+                'category' => array('yes', 'like'),
+                'start_day' => array('yes-day', '>='),
+                'end_day' => array('yes-day', '<='),
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('time' => 'desc', 'cdate' => 'desc'),
+            'page' => array(20, 'list'),
+            'group' => 'goods_id,day',
+            'col' => '*,min(day) as time,sum(cash) as cash, sum(num) as num',
+        ),
+
+        'prev' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'day' => array('yes-day', '<'),
+                //'start_day' => array('yes-day', '>='),
+                //'end_day' => array('yes-day', '<='),
+                'state' => 1,
+            ),
+            'order' => array('time' => 'desc', 'id' => 'desc'),
+            'type' => 'one',
+            'col' => '*,min(day) as time,sum(cash) as cash, sum(num) as num',
+            # 允许自定义以上配置
+            'config' => true,
+        ),
+    ),
+);
+
+return $config;

+ 14 - 0
app/shop/database/info.php

@@ -749,5 +749,19 @@ return array
             'order' => array('reorder' => 'desc', 'id' => 'desc'),
             'col' => $col . '|id',
         ),
+
+        'getAll' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'town' => 'yes',
+                'area' => array('yes', 'like'),
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('reorder' => 'desc', 'id' => 'desc'),
+            'col' => 'id,id as value, name',
+        ),
     ),
 );

+ 79 - 16
app/shop/database/out_order.php

@@ -33,7 +33,7 @@ $store = function()
 $search = Dever::input('search_option_type', 1);
 
 if ($search == 1) {
-    $search_name = '所属门店';
+    $search_name = '门店名称';
     $search_option = $shop;
     $search_url = 'shop/lib/manage.search';
     $out_type = function()
@@ -46,8 +46,14 @@ if ($search == 1) {
         }
         return $array;
     };
+    $search_table = 'shop';
+    $excel = array
+    (
+        array('导出订单', '门店出库订单', ''),
+        array('导出订单明细', '门店出库订单明细', 'shop/excel.out_order'),
+    );
 } elseif ($search != 1) {
-    $search_name = '所属仓库';
+    $search_name = '仓库名称';
     $search_option = $store;
     $search_url = 'store/lib/manage.search';
     $out_type = function()
@@ -60,6 +66,12 @@ if ($search == 1) {
         }
         return $array;
     };
+    $search_table = 'store';
+    $excel = array
+    (
+        array('导出订单', '仓库出库订单', ''),
+        array('导出订单明细', '仓库出库订单明细', 'shop/excel.store_out_order'),
+    );
 }
 
 return array
@@ -103,10 +115,54 @@ return array
             'default'   => '',
             'desc'      => '拥有人',
             'match'     => 'is_numeric',
-            'search'    => $search == 3 ? '' : 'select',
-            'option'    => $search_option,
+            //'search'    => $search == 3 ? '' : 'select',
+            'search'    => $search == 3 ? '' : array
+            (
+                'api' => $search_table . '/info-like',
+                'col' => 'name',
+                'result' => 'id',
+            ),
+            //'option'    => $search_option,
             //'update_search' => $search_url,
             'list'      => 'Dever::load("shop/lib/manage.buyInfo", "{type}", "{type_id}")',
+            'list_order' => 2,
+        ),
+
+        'shop-info-sid'=> array
+        (
+            'name'      => '门店编号',
+            'default'   => '',
+            'desc'      => '门店编号',
+            'match'     => 'option',
+            # 读取另外表的关联方式
+            'sync'      => array('type_id', 'id'),
+            'list'      => $search == 1 ? true : false,
+            'list_order' => 1,
+        ),
+
+        'shop-info-type'=> array
+        (
+            'name'      => '门店类型',
+            'default'   => '',
+            'desc'      => '门店类型',
+            'match'     => 'option',
+            # 读取另外表的关联方式
+            'sync'      => array('type_id', 'id'),
+            'list'      => $search == 1 ? 'Dever::load("shop/lib/manage.shopInfoType", {shop-info-type})' : false,
+            'list_order' => 3,
+        ),
+
+        'area'       => array
+        (
+            'type'      => 'varchar-500',
+            'name'      => '所在街道',
+            'default'   => '',
+            'desc'      => '所在街道',
+            'match'     => 'option',
+            'search'    => 'linkage',
+            'update'    => 'linkage',
+            'option'    => Dever::url('lib/area.get', $search_table),
+            //'list'      => 'Dever::load("area/api.string", "{area}")',
         ),
 
         'name'      => array
@@ -122,36 +178,39 @@ return array
         'order_num'      => array
         (
             'type'      => 'varchar-100',
-            'name'      => '订单编号',
+            'name'      => '出库单号',
             'default'   => '',
-            'desc'      => '订单编号',
+            'desc'      => '出库单号',
             'match'     => 'is_string',
             'update'    => 'text',
             'search'    => 'fulltext',
             'list'      => true,
+            'list_order' => 4,
         ),
 
         'price'      => array
         (
             'type'      => 'varchar-50',
-            'name'      => '价格',
+            'name'      => '出库总金额',
             'default'   => '',
-            'desc'      => '价格',
+            'desc'      => '出库总金额',
             'match'     => 'option',
             'update'    => 'text',
-            'list_name'      => $search == 1 ? '总价' : '采购总价',
-            'list'      => $search == 1 ? true : false,
+            'list_name'      => $search == 1 ? '出库总金额' : '出库总金额',
+            'list'      => $search == 1 ? true : true,
+            'list_order' => 5,
         ),
 
         'num'        => array
         (
             'type'      => 'int-11',
-            'name'      => '数量',
+            'name'      => '出库数量',
             'default'   => '',
-            'desc'      => '数量',
+            'desc'      => '出库数量',
             'match'     => 'is_numeric',
             'search'    => 'select',
             'list'        => true,
+            'list_order' => 5,
         ),
 
         'info'      => array
@@ -177,25 +236,27 @@ return array
         'out_type'        => array
         (
             'type'      => 'int-11',
-            'name'      => '类型',
+            'name'      => '出库类型',
             'default'   => '1',
             'desc'      => '类型',
             'match'     => 'is_numeric',
             'option'    => $out_type,
             'search'    => 'select',
             'list'      => true,
+            'list_order'    => 7,
         ),
 
         'status'        => array
         (
             'type'      => 'tinyint-1',
-            'name'      => '状态',
+            'name'      => '出库状态',
             'default'   => '1',
             'desc'      => '状态',
             'match'     => 'is_numeric',
             'option'    => $status,
             'search'    => 'select',
             'list'      => true,
+            'list_order' => 8,
         ),
 
         'state'     => array
@@ -210,13 +271,14 @@ return array
         'cdate'     => array
         (
             'type'      => 'int-11',
-            'name'      => '出库时间',
+            'name'      => '出库日期',
             'match'     => array('is_numeric', time()),
             'desc'      => '',
             # 只有insert时才生效
             'insert'    => true,
-            'search'    => 'date',
+            'search'    => 'sdate',
             'list'        => 'date("Y-m-d H:i:s", {cdate})',
+            'list_order'    => 6,
             //'list'      => 'Dever::load("service/lib/manage.showOrderTime", "{id}")',
         ),
     ),
@@ -236,6 +298,7 @@ return array
         'edit' => false,
         'insert' => false,
         'excel' => 'mshop/lib/out.excel',
+        'excel' => $excel,
 
         'button' => array
         (

+ 177 - 28
app/shop/database/sell_order.php

@@ -66,6 +66,17 @@ $shop = function()
     return $array;
 };
 
+$store = function()
+{
+    $array = array();
+    $info = Dever::db('store/info')->select();
+    if($info)
+    {
+        $array += $info;
+    }
+    return $array;
+};
+
 $withdraw = array
 (
     1 => '未提现',
@@ -78,6 +89,22 @@ $shop_type = array
     2 => '平台店',
 );
 
+$search_option_shop_type = Dever::input('search_option_shop_type', 1);
+
+if ($search_option_shop_type == 1) {
+    $excel = array
+    (
+        array('导出订单', '门店零售订单', ''),
+        array('导出订单明细', '门店零售订单明细', 'shop/excel.sell_order'),
+    );
+} elseif ($search_option_shop_type == 2) {
+    $excel = array
+    (
+        array('导出订单', '平台商城订单', ''),
+        array('导出订单明细', '平台商城订单明细', 'shop/excel.p_sell_order'),
+    );
+}
+
 return array
 (
     # 表名
@@ -113,7 +140,8 @@ return array
             'match'     => 'option',
             # 读取另外表的关联方式
             'sync'      => array('shop_id', 'id'),
-            'list'      => true,
+            'list'      => $search_option_shop_type == 1 ? true : false,
+            'list_order' => 1,
         ),
 
         'shop_id'      => array
@@ -127,14 +155,36 @@ return array
             'option'    => $shop,
             'update'    => 'hidden',
             'search'    => 'hidden',
-            'search'    => array
+            'search'    => $search_option_shop_type == 1 ? array
             (
                 'api' => 'shop/info-like',
                 'col' => 'name',
                 'result' => 'id',
-            ),
+            ) : 'hidden',
             'value'     => Dever::input('search_option_shop_id'),
-            'list'      => 'Dever::load("shop/info-one#name", {shop_id})',
+            'list'      => $search_option_shop_type == 1 ? 'Dever::load("shop/info-one#name", {shop_id})' : false,
+            'list_order' => 2,
+        ),
+
+        'store_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '发货仓库',
+            'default'   => '',
+            'desc'      => '发货仓库',
+            'match'     => 'is_numeric',
+            'search'    => 'select',
+            'option'    => $store,
+            'update'    => 'select',
+            'search'    => 'hidden',
+            'search'    => $search_option_shop_type == 2 ? array
+            (
+                'api' => 'store/info-like',
+                'col' => 'name',
+                'result' => 'id',
+            ) : 'hidden',
+            'list'      => $search_option_shop_type == 2 ? '"{store_id}" > 0 ? Dever::load("store/info-one#name", {store_id}) : ""' : false,
+            'list_order' => 6,
         ),
 
         'shop-info-type'=> array
@@ -145,44 +195,65 @@ return array
             'match'     => 'option',
             # 读取另外表的关联方式
             'sync'      => array('shop_id', 'id'),
-            'list'      => 'Dever::load("shop/lib/manage.shopInfoType", {shop-info-type})',
+            'list'      => $search_option_shop_type == 1 ? 'Dever::load("shop/lib/manage.shopInfoType", {shop-info-type})' : false,
+            'list_order' => 3,
+        ),
+
+        'area'       => array
+        (
+            'type'      => 'varchar-500',
+            'name'      => '所在街道',
+            'default'   => '',
+            'desc'      => '所在街道',
+            'match'     => 'option',
+            'search'    => $search_option_shop_type == 1 ? 'linkage' : false,
+            'update'    => 'linkage',
+            'option'    => Dever::url('lib/area.get', 'shop'),
+            //'list'      => 'Dever::load("area/api.string", "{area}")',
         ),
 
         'uid'       => array
         (
             'type'      => 'int-11',
-            'name'      => '购买人',
+            'name'      => $search_option_shop_type == 1 ? '购买人' : '收件人',
             'default'   => '0',
             'desc'      => '请选择用户',
             'match'     => 'is_numeric',
             'update'    => 'text',
             //'search'  => 'select',
-            'search'    => array
+            'search'    => $search_option_shop_type == 1 ? array
             (
                 'api' => 'passport/user-one',
                 'col' => 'username',
                 'result' => 'id',
+            ) : array
+            (
+                'api' => 'passport/address-one',
+                'col' => 'contact',
+                'result' => 'uid',
             ),
-            'list'      => 'Dever::load("shop/lib/manage.user", {id})',
+            'list'      => $search_option_shop_type == 1 ? 'Dever::load("shop/lib/manage.user", {id})' : 'Dever::load("passport/address-one#contact", {address_id})',
+            'list_order' => 5,
         ),
 
         'mobile'        => array
         (
             'type'      => 'varchar-300',
-            'name'      => '下单手机号',
+            'name'      => $search_option_shop_type == 1 ? '下单手机号' : '收件人手机',
             'default'   => '',
             'desc'      => '手机号',
             'match'     => 'option',
             'search'    => 'fulltext',
-            /*
-            'search'    => array
+            
+            'search'    => $search_option_shop_type == 1 ? 'fulltext' : array
             (
-                'api' => 'passport/user-select',//接口地址,最好是获取多条数据的地址
+                'api' => 'passport/address-one',//接口地址,最好是获取多条数据的地址
                 'col' => 'mobile',//要查询的字段
-                'result' => 'id',//返回的字段
+                'result' => 'uid',//返回的字段
                 'search' => 'uid',//本表的字段,默认为当前的字段
             ),
-            */
+            'list'      => $search_option_shop_type == 1 ? false : 'Dever::load("passport/address-one#mobile", {address_id})',
+            'list_order' => 6,
         ),
 
         'address_id'      => array
@@ -225,6 +296,7 @@ return array
             'update'    => 'text',
             'search'    => 'fulltext',
             'list'      => true,
+            'list_order' => 4,
         ),
 
         'oprice'      => array
@@ -236,40 +308,44 @@ return array
             'match'     => 'option',
             'update'    => 'text',
             'list_name' => '合计金额',
-            'list'        => 'Dever::load("shop/lib/manage.getTotalCash", {id})',
+            'list'        => $search_option_shop_type == 1 ? 'Dever::load("shop/lib/manage.getTotalCash", {id})' : false,
+            'list_order' => 10,
         ),
 
         'price'      => array
         (
             'type'      => 'varchar-50',
-            'name'      => '实付金额',
+            'name'      => $search_option_shop_type == 1 ? '实付金额' : '订单总金额',
             'default'   => '0',
             'desc'      => '实付金额',
             'match'     => 'option',
             'update'    => 'text',
             'list'      => 'Dever::load("cash/lib/set.getCash", "{price}")',
+            'list_order' => 11,
         ),
 
         'num'        => array
         (
             'type'      => 'int-11',
-            'name'      => '购买数量',
+            'name'      => '购买数量',
             'default'   => '',
-            'desc'      => '购买数量',
+            'desc'      => '购买数量',
             'match'     => 'is_numeric',
             'search'    => 'select',
-            //'list'        => true,
+            'list'        => $search_option_shop_type == 2 ? true : false,
+            'list_order'    => 10,
         ),
 
         'refund_cash'      => array
         (
             'type'      => 'varchar-50',
-            'name'      => '已退订单金额',
+            'name'      => $search_option_shop_type == 1 ? '已退订单金额' : '退款金额',
             'default'   => '0',
             'desc'      => '已退订单金额',
             'match'     => 'option',
             'update'    => 'text',
             'list'      => true,
+            'list_order' => $search_option_shop_type == 1 ? 12 : 19,
         ),
 
         'refund_status'        => array
@@ -281,6 +357,9 @@ return array
             'match'     => 'is_numeric',
             'option'    => $refund_status,
             //'search'    => 'select',
+            'list'      => $search_option_shop_type == 2 ? 'Dever::load("shop/lib/manage.buyInfoRefundStatus", "{id}", "sell_order")' : false,
+            'list_name'   => '退款状态',
+            'list_order' => 18,
         ),
 
         'kou_cash'      => array
@@ -378,9 +457,10 @@ return array
             'desc'      => '配送类型',
             'match'     => 'is_numeric',
             'update'    => 'radio',
-            'search'    => 'select',
+            'search'    => $search_option_shop_type == 1 ? 'select' : false,
             'option'    => $method,
-            'list'      => true,
+            'list'      => $search_option_shop_type == 1 ? true : false,
+            'list_order' => 5,
         ),
 
         'code'        => array
@@ -400,9 +480,10 @@ return array
             'desc'      => '订单类型',
             'match'     => 'is_numeric',
             'update'    => 'radio',
-            'search'    => 'select',
+            'search'    => $search_option_shop_type == 1 ? 'select' : false,
             'option'    => $pay_method,
-            'list'      => true,
+            'list'      => $search_option_shop_type == 1 ? true : false,
+            'list_order' => 6,
         ),
 
         'pay_type'        => array
@@ -414,7 +495,8 @@ return array
             'match'     => 'is_numeric',
             'update'    => 'radio',
             'option'    => $pay_type,
-            'list'      => true,
+            'list'      => $search_option_shop_type == 1 ? true : false,
+            'list_order' => 13,
         ),
 
         'info'      => array
@@ -459,6 +541,7 @@ return array
             'option'    => $status_manage,
             'search'    => 'select',
             'list'      => true,
+            'list_order' => 14,
         ),
 
         'notice'        => array
@@ -479,6 +562,17 @@ return array
             'desc'      => '',
         ),
 
+        'paydate'     => array
+        (
+            'type'      => 'int-11',
+            'name'      => '付款时间',
+            'default'   => '',
+            'match'     => 'is_numeric',
+            'desc'      => '',
+            'list'      => '"{paydate}" > 0 ? date("Y-m-d H:i", {paydate}) : "-"',
+            'list_order' => 8,
+        ),
+
         'operdate'     => array
         (
             'type'      => 'int-11',
@@ -486,6 +580,21 @@ return array
             'default'   => '',
             'match'     => 'is_numeric',
             'desc'      => '',
+            //'list'      => '"{operdate}" > 0 ? date("Y-m-d H:i:s", {operdate}) : "-"',
+            //'list_name' => '发货时间',
+            //'list_order' => 8,
+        ),
+
+        'shop-sell_order_ps-cdate'=> array
+        (
+            'name'      => '发货时间',
+            'default'   => '',
+            'desc'      => '发货时间',
+            'match'     => 'option',
+            # 读取另外表的关联方式
+            'sync'      => array('id', 'order_id'),
+            'list'      => '"{shop-sell_order_ps-cdate}" ? date("Y-m-d H:i", {shop-sell_order_ps-cdate}) : "-"',
+            'list_order' => 8,
         ),
 
         'state'     => array
@@ -505,9 +614,10 @@ return array
             'desc'      => '',
             # 只有insert时才生效
             'insert'    => true,
-            'search'    => 'date',
-            'list'        => 'date("Y-m-d H:i:s", {cdate})',
+            'search'    => 'sdate',
+            'list'        => 'date("Y-m-d H:i", {cdate})',
             //'list'      => 'Dever::load("service/lib/manage.showOrderTime", "{id}")',
+            'list_order' => 7,
         ),
     ),
 
@@ -516,10 +626,11 @@ return array
         'delete' => false,
         'edit' => false,
         'insert' => false,
+        'excel' => $excel,
 
         'button' => array
         (
-            //'导出订单' => array('location', 'user/lib/manage.out'),
+            //'导出订单明细' => array('excel', 'shop/excel.sell_order'),
         ),
 
         'list_button' => array
@@ -527,6 +638,12 @@ return array
             //fast_list
             'list' => array('查看详情', '"sell_order_goods&project=shop&order_id={id}&page_type=1"'),
 
+            //'location2' => array('分配仓库', Dever::url('lib/set.store', 'shop')),
+
+            'edit' => array('分配仓库', 'store_id'),
+
+            'fast1' => array('发货', '"sell_order_ps&where_id={id}&search_option_order_id={id}&oper_save_jump=sell_order&oper_table=sell_order&oper_parent=sell_order"', '{status} < 3'),
+
             //'edit' => array('退款', 'status,tk_time,tk_pic,tk_desc,tk_admin,tk_status', '{status} == 6'),
             //'delete' => array('删除', '', '{status} == 1'),
         ),
@@ -709,5 +826,37 @@ return array
             'type' => 'one',
             'col' => 'sum(num) as total',
         ),
+
+        # 获取订单数量
+        'getUser' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'start' => array('yes-cdate', '>='),
+                'end' => array('yes-cdate', '<='),
+                'shop_id' => 'yes',
+                'status' => array('yes', 'in'),
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'group' => 'uid',
+            'col' => 'count(uid) as total',
+        ),
+
+        'getUserNum' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'start' => array('yes-cdate', '>='),
+                'end' => array('yes-cdate', '<='),
+                'shop_id' => 'yes',
+                'status' => array('yes', 'in'),
+                'state' => 1,
+            ),
+            'type' => 'count',
+            'col' => '*',
+        ),
     ),
 );

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

@@ -40,6 +40,15 @@ return array
             'match'     => 'is_numeric',
         ),
 
+        'shop_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '门店名称',
+            'default'   => '',
+            'desc'      => '门店名称',
+            'match'     => 'is_numeric',
+        ),
+
         'goods_id'      => array
         (
             'type'      => 'int-11',
@@ -199,5 +208,39 @@ return array
             'type' => 'count',
             'col' => '*',
         ),
+
+        # 获取订单数量
+        'getOrderNum' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'start' => array('yes-cdate', '>='),
+                'end' => array('yes-cdate', '<='),
+                'shop_id' => 'yes',
+                'goods_id' => 'yes',
+                'status' => 'yes',
+                'state' => 1,
+            ),
+            'type' => 'count',
+            'col' => '*',
+        ),
+
+        # 获取总金额
+        'getCashNum' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'start' => array('yes-cdate', '>='),
+                'end' => array('yes-cdate', '<='),
+                'shop_id' => 'yes',
+                'goods_id' => 'yes',
+                'status' => 'yes',
+                'state' => 1,
+            ),
+            'type' => 'one',
+            'col' => 'sum(price) as total',
+        ),
     ),
 );

+ 7 - 0
app/shop/database/sell_order_ps.php

@@ -22,6 +22,11 @@ return array
     'lang' => '订单配送表',
     'menu' => false,
     'status' => $status,
+    'end' => array
+    (
+        'insert' => 'shop/lib/manage.sellOrderPs',
+        'update' => 'shop/lib/manage.sellOrderPs',
+    ),
     # 数据结构
     'struct' => array
     (
@@ -45,6 +50,8 @@ return array
             'default'   => '',
             'desc'      => '订单表id',
             'match'     => 'is_numeric',
+            'update'      => 'hidden',
+            'value'     => Dever::input('search_option_order_id'),
         ),
 
         'service_id'        => array

+ 13 - 6
app/shop/database/sell_stat.php

@@ -58,13 +58,20 @@ return array
         'shop_id'      => array
         (
             'type'      => 'int-11',
-            'name'      => '所属门店',
+            'name'      => '门店名称',
             'default'   => '',
-            'desc'      => '所属门店',
+            'desc'      => '门店名称',
             'match'     => 'is_numeric',
-            'option'    => $shop,
+            'search'    => 'select',
+            //'option'    => $shop,
             'update'    => 'hidden',
             'search'    => 'hidden',
+            'search'    => array
+            (
+                'api' => 'shop/info-like',
+                'col' => 'name',
+                'result' => 'id',
+            ),
             'value'     => Dever::input('search_option_shop_id'),
             'list'      => 'Dever::load("shop/info-one#name", {shop_id})',
         ),
@@ -72,13 +79,13 @@ return array
         'area'       => array
         (
             'type'      => 'varchar-500',
-            'name'      => '选择地区',
+            'name'      => '所在街道',
             'default'   => '',
-            'desc'      => '选择地区',
+            'desc'      => '所在街道',
             'match'     => 'option',
             'search'    => 'linkage',
             'update'    => 'linkage',
-            'option'    => Dever::url('api.get?level_total=4', 'area'),
+            'option'    => Dever::url('lib/area.get', 'shop'),
             //'list'      => 'Dever::load("area/api.string", "{area}")',
         ),
 

+ 187 - 0
app/shop/database/shop_stat.php

@@ -0,0 +1,187 @@
+<?php
+
+$config = array
+(
+    # 表名
+    'name' => 'shop_stat',
+    # 显示给用户看的名称
+    'lang' => '门店数据统计',
+    'order' => -11,
+
+    # 数据结构 不同的字段放这里
+    'struct' => array
+    (
+        'id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            //'list'        => true,
+        ),
+
+        'day'     => array
+        (
+            'type'      => 'int-11',
+            'name'      => '日期',
+            'default'   => '',
+            'match'     => 'is_numeric',
+            'desc'      => '',
+            'search'    => 'sday',
+            'search_buttons' => array
+            (
+                'sum' => 'buy_num,buy_cash,sell_num,sell_cash,sl_num',
+                'option' => array(
+                    'day' => '按天',
+                    'week' => '按周',
+                    'month' => '按月',
+                ),
+                'group' => 'shop_id',
+            ),
+            'order'     => 'desc',
+            //'list'      => 'Dever::showDay("{day}")',
+        ),
+
+        'shop_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '门店名称',
+            'default'   => '',
+            'desc'      => '门店名称',
+            'match'     => 'is_numeric',
+            'search'    => 'select',
+            //'option'    => $shop,
+            'update'    => 'hidden',
+            'search'    => 'hidden',
+            'search'    => array
+            (
+                'api' => 'shop/info-like',
+                'col' => 'name',
+                'result' => 'id',
+            ),
+            'value'     => Dever::input('search_option_shop_id'),
+            'list'      => 'Dever::load("shop/info-one#name", {shop_id})',
+        ),
+
+        'area'       => array
+        (
+            'type'      => 'varchar-500',
+            'name'      => '所在街道',
+            'default'   => '',
+            'desc'      => '所在街道',
+            'match'     => 'option',
+            'search'    => 'linkage',
+            'update'    => 'linkage',
+            'option'    => Dever::url('lib/area.get', 'shop'),
+            //'list'      => 'Dever::load("area/api.string", "{area}")',
+        ),
+
+        'buy_num'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '采购订单量',
+            'default'   => '0',
+            'desc'      => '采购订单量',
+            'match'     => 'is_numeric',
+            'list'      => true,
+        ),
+
+        'buy_cash'        => array
+        (
+            'type'      => 'varchar-100',
+            'name'      => '采购金额',
+            'default'   => '0',
+            'desc'      => '采购金额',
+            'match'     => 'is_string',
+            'search'    => 'order',
+            'list'      => true,
+        ),
+
+        'sell_num'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '销售订单量',
+            'default'   => '0',
+            'desc'      => '销售订单量',
+            'match'     => 'is_numeric',
+            'list'      => true,
+        ),
+
+        'sell_cash'        => array
+        (
+            'type'      => 'varchar-100',
+            'name'      => '销售金额',
+            'default'   => '0',
+            'desc'      => '销售金额',
+            'match'     => 'is_string',
+            'search'    => 'order',
+            'list'      => true,
+        ),
+
+        'sl_num'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '沙龙消耗商品数量',
+            'default'   => '0',
+            'desc'      => '沙龙消耗商品数量',
+            'match'     => 'is_numeric',
+            'search'    => 'order',
+            //'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,
+        'num' => false,
+        'excel' => true,
+    ),
+
+    # request 请求接口定义
+    'request' => array
+    (
+        'list' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'shop_id' => 'yes',
+                'area' => array('yes', 'like'),
+                'start_day' => array('yes-day', '>='),
+                'end_day' => array('yes-day', '<='),
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('day' => 'desc', 'cdate' => 'desc'),
+            'page' => array(20, 'list'),
+            'group' => 'shop_id',
+            'col' => '*,sum(buy_num) as buy_num, sum(buy_cash) as buy_cash, sum(sell_num) as sell_num, sum(sell_cash) as sell_cash, sum(sl_num) as sl_num',
+        ),
+    ),
+);
+
+return $config;

+ 176 - 0
app/shop/database/user_buy_stat.php

@@ -0,0 +1,176 @@
+<?php
+
+$config = array
+(
+    # 表名
+    'name' => 'user_buy_stat',
+    # 显示给用户看的名称
+    'lang' => '用户排名统计',
+    'order' => -1,
+
+    # 数据结构 不同的字段放这里
+    'struct' => array
+    (
+        'id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            //'list'        => true,
+        ),
+
+        'day'     => array
+        (
+            'type'      => 'int-11',
+            'name'      => '日期',
+            'default'   => '',
+            'match'     => 'is_numeric',
+            'desc'      => '',
+            'search'    => 'sday',
+            'search_buttons' => array
+            (
+                'sum' => 'num,cash',
+                'option' => array(
+                    'day' => '按天',
+                    'week' => '按周',
+                    'month' => '按月',
+                ),
+                'group' => 'uid',
+            ),
+            'order'     => 'desc',
+            //'list'      => 'Dever::showDay("{day}")',
+        ),
+
+        'uid'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '用户名',
+            'default'   => '',
+            'desc'      => '用户名',
+            'match'     => 'is_numeric',
+            'search'    => 'select',
+            'update'    => 'hidden',
+            'search'    => 'hidden',
+            'search'    => array
+            (
+                'api' => 'passport/user-like',
+                'col' => 'username',
+                'result' => 'id',
+            ),
+            'list'      => 'Dever::load("passport/user-one#username", {uid})',
+        ),
+
+        'area'       => array
+        (
+            'type'      => 'varchar-500',
+            'name'      => '客户所在城市',
+            'default'   => '',
+            'desc'      => '客户所在城市',
+            'match'     => 'option',
+            'search'    => 'linkage',
+            'update'    => 'linkage',
+            'option'    => Dever::url('api.get', 'area'),
+            'list'      => 'Dever::load("area/api.string", "{area}")',
+        ),
+
+        'wechat'        => array
+        (
+            'type'      => 'varchar-100',
+            'name'      => '微信号',
+            'default'   => '0',
+            'desc'      => '微信号',
+            'match'     => 'is_string',
+            'list'      => true,
+        ),
+
+        'mobile'        => array
+        (
+            'type'      => 'varchar-32',
+            'name'      => '手机号',
+            'default'   => '0',
+            'desc'      => '手机号',
+            'match'     => 'is_string',
+            'list'      => true,
+        ),
+
+        'num'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '数量',
+            'default'   => '0',
+            'desc'      => '数量',
+            'match'     => 'is_numeric',
+            'search'    => 'order',
+            'list'      => true,
+        ),
+
+        'cash'        => array
+        (
+            'type'      => 'varchar-100',
+            'name'      => '金额',
+            'default'   => '0',
+            'desc'      => '金额',
+            'match'     => 'is_string',
+            'search'    => 'order',
+            '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,
+        'num' => false,
+        'excel' => true,
+    ),
+
+    # request 请求接口定义
+    'request' => array
+    (
+        'list' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'uid' => 'yes',
+                'area' => array('yes', 'like'),
+                'wechat' => array('yes', 'like'),
+                'mobile' => array('yes', 'like'),
+                'start_day' => array('yes-day', '>='),
+                'end_day' => array('yes-day', '<='),
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('day' => 'desc', 'cdate' => 'desc'),
+            'page' => array(20, 'list'),
+            'group' => 'uid',
+            'col' => '*,sum(cash) as cash, sum(num) as num',
+        ),
+    ),
+);
+
+return $config;

+ 218 - 0
app/shop/database/user_stat.php

@@ -0,0 +1,218 @@
+<?php
+
+$config = array
+(
+    # 表名
+    'name' => 'user_stat',
+    # 显示给用户看的名称
+    'lang' => '门店用户复购统计',
+    'order' => -13,
+
+    # 数据结构 不同的字段放这里
+    'struct' => array
+    (
+        'id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            //'list'        => true,
+        ),
+
+        'day'     => array
+        (
+            'type'      => 'int-11',
+            'name'      => '日期',
+            'default'   => '',
+            'match'     => 'is_numeric',
+            'desc'      => '',
+            'search'    => 'day',
+            'search_button' => array
+            (
+                'sum' => 'num,total,order_num',
+                'option' => array(
+                    'day' => '按天',
+                    'week' => '按周',
+                    'month' => '按月',
+                ),
+                'group' => '',
+            ),
+            'order'     => 'desc',
+            'list'      => 'Dever::showDay("{day}")',
+        ),
+
+        'shop_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '门店名称',
+            'default'   => '',
+            'desc'      => '门店名称',
+            'match'     => 'is_numeric',
+            'search'    => 'select',
+            //'option'    => $shop,
+            'update'    => 'hidden',
+            'search'    => 'hidden',
+            'search'    => array
+            (
+                'api' => 'shop/info-like',
+                'col' => 'name',
+                'result' => 'id',
+            ),
+            'value'     => Dever::input('search_option_shop_id'),
+            //'list'      => 'Dever::load("shop/info-one#name", {shop_id})',
+        ),
+
+        'area'       => array
+        (
+            'type'      => 'varchar-500',
+            'name'      => '所在街道',
+            'default'   => '',
+            'desc'      => '所在街道',
+            'match'     => 'option',
+            'search'    => 'linkage',
+            'update'    => 'linkage',
+            'option'    => Dever::url('lib/area.get', 'shop'),
+            //'list'      => 'Dever::load("area/api.string", "{area}")',
+        ),
+
+        'total'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '总下单客户数',
+            'default'   => '0',
+            'desc'      => '总下单客户数',
+            'match'     => 'is_numeric',
+            'search'    => 'order',
+            'list'      => true,
+        ),
+
+        'num'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '重复购买人数',
+            'default'   => '0',
+            'desc'      => '重复购买人数',
+            'match'     => 'is_numeric',
+            'search'    => 'order',
+            'list'      => true,
+        ),
+
+        'fg'        => array
+        (
+            'type'      => 'varchar-100',
+            'name'      => '复购率',
+            'default'   => '0',
+            'desc'      => '复购率',
+            'match'     => 'is_string',
+            'search'    => 'order',
+            'list'      => 'Dever::load("shop/lib/manage.getUserStat#fg", "{num}", "{total}", "{order_num}")',
+        ),
+
+        'hb'      => array
+        (
+            'type'      => 'varchar-100',
+            'name'      => '复购环比',
+            'default'   => '0',
+            'desc'      => '复购环比',
+            'match'     => 'option',
+            'update'    => 'text',
+            'list'      => 'Dever::load("shop/lib/manage.getUserHb", "{num}", "{total}", "{time}")',
+        ),
+
+        'order_num'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '购买次数',
+            'default'   => '0',
+            'desc'      => '购买次数',
+            'match'     => 'is_numeric',
+            //'search'    => 'order',
+            //'list'      => true,
+        ),
+
+        'per_num'        => array
+        (
+            'type'      => 'varchar-100',
+            'name'      => '人均购买频次',
+            'default'   => '0',
+            'desc'      => '人均购买频次',
+            'match'     => 'is_numeric',
+            'search'    => 'order',
+            'list'      => 'Dever::load("shop/lib/manage.getUserStat#per_num", "{num}", "{total}", "{order_num}")',
+        ),
+
+        '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,
+        'num' => false,
+        'excel' => true,
+    ),
+
+    # request 请求接口定义
+    'request' => array
+    (
+        'list' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'shop_id' => 'yes',
+                'area' => array('yes', 'like'),
+                'start_day' => array('yes-day', '>='),
+                'end_day' => array('yes-day', '<='),
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('time' => 'desc', 'cdate' => 'desc'),
+            'page' => array(20, 'list'),
+            'group' => 'day',
+            'col' => '*,min(day) as time, sum(total) as total, sum(num) as num, sum(order_num) as order_num',
+        ),
+
+        'prev' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'day' => array('yes-day', '<'),
+                //'start_day' => array('yes-day', '>='),
+                //'end_day' => array('yes-day', '<='),
+                'state' => 1,
+            ),
+            'order' => array('time' => 'desc', 'id' => 'desc'),
+            'type' => 'one',
+            'col' => '*,min(day) as time, sum(total) as total, sum(num) as num, sum(order_num) as order_num',
+            'group' => 'day',
+            # 允许自定义以上配置
+            'config' => true,
+        ),
+    ),
+);
+
+return $config;

+ 89 - 0
app/shop/lib/Area.php

@@ -0,0 +1,89 @@
+<?php
+
+namespace Shop\Lib;
+
+use Dever;
+
+class Area
+{
+    private $default = array
+    (
+        'value' => -1,
+        'name' => '不限',
+    );
+
+    private $search_default = array
+    (
+        'value' => -1,
+        'name' => '地区选择',
+    );
+
+    /**
+     * 获取地区数据
+     *
+     * @return mixed
+     */
+    public function get_api()
+    {
+        # 联动总数,默认到县区
+        $level_total = Dever::input('level_total', 5);
+
+        # 当前联动级别
+        $level_num = Dever::input('level_num');
+
+        # 一般为id
+        $level_id = Dever::input('level_id');
+
+        # 是否是搜索列表页
+        $level_search = Dever::input('level_search');
+        if ($level_search) {
+            $default = $this->search_default;
+            if ($level_num == 1) {
+                $default['name'] = '省份选择';
+            } elseif ($level_num == 2) {
+                $default['name'] = '城市选择';
+            } elseif ($level_num == 3) {
+                $default['name'] = '县区选择';
+            } elseif ($level_num == 4) {
+                $default['name'] = '街道选择';
+            } else {
+                $default['name'] = '门店选择';
+            }
+        } else {
+            $default = $this->default;
+        }
+
+        # 四级联动
+        if ($level_num == 1) {
+            $t = 'area/province';
+            $data = Dever::db($t)->getAll();
+        } elseif ($level_num == 2) {
+            $t = 'area/city';
+            $data = Dever::db($t)->getAll(array('province_id' => $level_id));
+        } elseif ($level_num == 3) {
+            $t = 'area/county';
+            $data = Dever::db($t)->getAll(array('city_id' => $level_id));
+        } elseif ($level_num == 4) {
+            $t = 'area/town';
+            $data = Dever::db($t)->getAll(array('county_id' => $level_id));
+        } elseif ($level_num == 5) {
+            if ($level_id > 0) {
+                $data = Dever::db('shop/info')->getAll(array('town' => $level_id));
+            } else {
+                $data = false;
+            }
+        }
+
+        if (!$data) {
+            Dever::alert('error');
+        }
+
+        if ($level_search || $level_num > 1) {
+            array_unshift($data, $default);
+        }
+
+        $result['level_total'] = $level_total;
+        $result['list'] = $data;
+        return $result;
+    }
+}

+ 225 - 9
app/shop/lib/Cron.php

@@ -189,7 +189,7 @@ class Cron
         $start = Dever::input('start', date('Y-m-d', strtotime('-'.$num.' day')));
         $end = Dever::input('end', date('Y-m-d'));
 
-        $where['status'] = '1,2,3,4,5,6';
+        $where['status'] = '2,3,4,5,6';
         $start = Dever::maketime($start . ' 00:00:00');
         $end = Dever::maketime($end . ' 23:59:59');
         $day = intval(($end - $start)/86400);
@@ -206,7 +206,7 @@ class Cron
                 $data['day'] = $where['start'];
                 $info = Dever::db('shop/sell_stat')->find($data);
                 $cash = Dever::db('shop/sell_order')->getCashNum($where);
-                $data['cash'] = $cash['total'];
+                $data['cash'] = round($cash['total'], 2);
                 $data['order'] = Dever::db('shop/sell_order')->getOrderNum($where);
                 $goods = Dever::db('shop/sell_order')->getGoodsNum($where);
                 $data['goods'] = $goods['total'];
@@ -231,7 +231,7 @@ class Cron
         $start = Dever::input('start', date('Y-m-d', strtotime('-'.$num.' day')));
         $end = Dever::input('end', date('Y-m-d'));
 
-        $where['status'] = '1,2,3,4,5,6';
+        $where['status'] = '2,3,4,5,6';
         $start = Dever::maketime($start . ' 00:00:00');
         $end = Dever::maketime($end . ' 23:59:59');
         $day = intval(($end - $start)/86400);
@@ -239,19 +239,19 @@ class Cron
         $shop = Dever::db('shop/info')->select();
 
         foreach ($shop as $k => $v) {
-            $where['shop_id'] = $v['id'];
+            $where['type'] = 1;
+            $where['type_id'] = $v['id'];
             for($i=0; $i<=$day; $i++) {
                 $where['start'] = $start + 86400*$i;
-                //$where['end'] = $start + 86400*$i + 86399;
+                $where['end'] = $start + 86400*$i + 86399;
                 $data = array();
-                $data['type'] = 1;
-                $data['type_id'] = $v['id'];
+                $data['shop_id'] = $v['id'];
                 $data['day'] = $where['start'];
                 $info = Dever::db('shop/buy_stat')->find($data);
                 $cash = Dever::db('shop/buy_order')->getCashNum($where);
-                $data['cash'] = $cash['total'];
+                $data['cash'] = round($cash['total'], 2);
                 $cash = Dever::db('shop/buy_order')->getPCashNum($where);
-                $data['p_cash'] = $cash['total'];
+                $data['p_cash'] = round($cash['total'], 2);
 
                 $data['order'] = Dever::db('shop/buy_order')->getOrderNum($where);
                 $goods = Dever::db('shop/buy_order')->getGoodsNum($where);
@@ -273,6 +273,222 @@ class Cron
         }
     }
 
+    /**
+     * 门店数据统计
+     *
+     * @return mixed
+     */
+    public function shop_api()
+    {
+        $num = Dever::input('num', 1);
+        $start = Dever::input('start', date('Y-m-d', strtotime('-'.$num.' day')));
+        $end = Dever::input('end', date('Y-m-d'));
+
+        $start = Dever::maketime($start . ' 00:00:00');
+        $end = Dever::maketime($end . ' 23:59:59');
+        $day = intval(($end - $start)/86400);
+
+        $shop = Dever::db('shop/info')->select();
+
+        foreach ($shop as $k => $v) {
+            $where = array();
+            $where['status'] = '2,3,4,5,6';
+            $where['shop_id'] = $v['id'];
+            for($i=0; $i<=$day; $i++) {
+                $where['start'] = $start + 86400*$i;
+                $where['end'] = $start + 86400*$i + 86399;
+                $data = array();
+                $data['shop_id'] = $v['id'];
+                $data['day'] = $where['start'];
+                $info = Dever::db('shop/shop_stat')->find($data);
+                $cash = Dever::db('shop/sell_order')->getCashNum($where);
+                $data['sell_cash'] = round($cash['total'], 2);
+                $data['sell_num'] = Dever::db('shop/sell_order')->getOrderNum($where);
+                
+                $where['type'] = 1;
+                $where['type_id'] = $v['id'];
+                $cash = Dever::db('shop/buy_order')->getCashNum($where);
+                $data['buy_cash'] = round($cash['total'], 2);
+                $data['buy_num'] = Dever::db('shop/buy_order')->getOrderNum($where);
+
+                $data['sl_num'] = 0;
+
+                $data['area'] = $v['area'];
+                $data['province'] = $v['province'];
+                $data['city'] = $v['city'];
+                $data['county'] = $v['county'];
+                $data['town'] = $v['town'];
+                if (!$info) {
+                    Dever::db('shop/shop_stat')->insert($data);
+                } else {
+                    $data['where_id'] = $info['id'];
+                    Dever::db('shop/shop_stat')->update($data);
+                }
+            }
+        }
+    }
+
+    /**
+     * 商品数据统计
+     *
+     * @return mixed
+     */
+    public function goods_api()
+    {
+        $num = Dever::input('num', 1);
+        $start = Dever::input('start', date('Y-m-d', strtotime('-'.$num.' day')));
+        $end = Dever::input('end', date('Y-m-d'));
+
+        $where['status'] = '1';
+        $start = Dever::maketime($start . ' 00:00:00');
+        $end = Dever::maketime($end . ' 23:59:59');
+        $day = intval(($end - $start)/86400);
+
+        $goods = Dever::db('goods/info')->select();
+        $shop = Dever::db('shop/info')->select();
+
+        foreach ($shop as $k => $v) {
+            $where['shop_id'] = $v['id'];
+            foreach ($goods as $k1 => $v1) {
+                $where['goods_id'] = $v1['id'];
+                for($i=0; $i<=$day; $i++) {
+                    $where['start'] = $start + 86400*$i;
+                    $where['end'] = $start + 86400*$i + 86399;
+                    $data = array();
+                    $data['shop_id'] = $v['id'];
+                    $data['goods_id'] = $v1['id'];
+                    $data['day'] = $where['start'];
+                    $info = Dever::db('shop/goods_stat')->find($data);
+                    $cash = Dever::db('shop/sell_order_goods')->getCashNum($where);
+                    $data['cash'] = round($cash['total'], 2);
+                    $data['num'] = Dever::db('shop/sell_order_goods')->getOrderNum($where);
+
+                    $data['area'] = $v['area'];
+                    $data['category'] = $v1['category'];
+                    if (!$info) {
+                        Dever::db('shop/goods_stat')->insert($data);
+                    } else {
+                        $data['where_id'] = $info['id'];
+                        Dever::db('shop/goods_stat')->update($data);
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * 门店数据统计
+     *
+     * @return mixed
+     */
+    public function user_api()
+    {
+        $num = Dever::input('num', 1);
+        $start = Dever::input('start', date('Y-m-d', strtotime('-'.$num.' day')));
+        $end = Dever::input('end', date('Y-m-d'));
+
+        $start = Dever::maketime($start . ' 00:00:00');
+        $end = Dever::maketime($end . ' 23:59:59');
+        $day = intval(($end - $start)/86400);
+
+        $shop = Dever::db('shop/info')->select();
+
+        foreach ($shop as $k => $v) {
+            $where = array();
+            $where['status'] = '2,3,4,5,6';
+            $where['shop_id'] = $v['id'];
+            for($i=0; $i<=$day; $i++) {
+                $where['start'] = $start + 86400*$i;
+                $where['end'] = $start + 86400*$i + 86399;
+                $data = array();
+                $data['shop_id'] = $v['id'];
+                $data['day'] = $where['start'];
+                $info = Dever::db('shop/user_stat')->find($data);
+                $total = Dever::db('shop/sell_order')->getUser($where);
+                $data['total'] = count($total);
+                foreach ($total as $k1 => $v1) {
+                    if ($v1['total'] <= 1) {
+                        unset($total[$k1]);
+                    }
+                }
+                $data['num'] = count($total);
+
+                $data['order_num'] = Dever::db('shop/sell_order')->getOrderNum($where);
+                
+
+                $data['area'] = $v['area'];
+                if (!$info) {
+                    Dever::db('shop/user_stat')->insert($data);
+                } else {
+                    $data['where_id'] = $info['id'];
+                    Dever::db('shop/user_stat')->update($data);
+                }
+            }
+        }
+    }
+
+    /**
+     * 门店数据统计
+     *
+     * @return mixed
+     */
+    public function user_buy_api()
+    {
+        return;
+        $num = Dever::input('num', 1);
+        $start = Dever::input('start', date('Y-m-d', strtotime('-'.$num.' day')));
+        $end = Dever::input('end', date('Y-m-d'));
+
+        $start = Dever::maketime($start . ' 00:00:00');
+        $end = Dever::maketime($end . ' 23:59:59');
+        $day = intval(($end - $start)/86400);
+
+        $user = Dever::db('passport/user')->select();
+
+        foreach ($user as $k => $v) {
+            $where = array();
+            $where['status'] = '2,3,4,5,6';
+            $where['uid'] = $v['id'];
+            for($i=0; $i<=$day; $i++) {
+                $where['start'] = $start + 86400*$i;
+                $where['end'] = $start + 86400*$i + 86399;
+                $data = array();
+                $data['shop_id'] = $v['id'];
+                $data['day'] = $where['start'];
+                $info = Dever::db('shop/user_buy_stat')->find($data);
+                $total = Dever::db('shop/sell_order')->getUser($where);
+                $data['total'] = count($total);
+                foreach ($total as $k1 => $v1) {
+                    if ($v1['total'] <= 1) {
+                        unset($total[$k1]);
+                    }
+                }
+                $data['num'] = count($total);
+
+                $data['order_num'] = Dever::db('shop/sell_order')->getOrderNum($where);
+                
+
+                $data['area'] = $v['area_id'];
+                $data['wechat'] = $v['wechat'];
+                $data['mobile'] = $v['mobile'];
+                if (!$info) {
+                    Dever::db('shop/user_buy_stat')->insert($data);
+                } else {
+                    $data['where_id'] = $info['id'];
+                    Dever::db('shop/user_buy_stat')->update($data);
+                }
+            }
+        }
+    }
+
+    # 获取下单用户量
+    public function order_user($where)
+    {
+        $where['status'] = '1,2,3,4,5,6';
+        $user = Dever::db('shop/sell_order')->getUser($where);
+        return $user;
+    }
+
     # 处理月度对账数据 废弃,直接用结算单处理
     public function sell_month_api()
     {

+ 146 - 2
app/shop/lib/Manage.php

@@ -6,6 +6,71 @@ use Dever;
 
 class Manage
 {
+    public function sellOrderPs($id, $name, $data)
+    {
+        Dever::config('base')->hook = true;
+        $order_id = Dever::param('order_id', $data);
+        if ($order_id) {
+            $info = Dever::db('shop/sell_order')->find(array('id' => $order_id));
+            if ($info && $info['status'] < 3) {
+                Dever::load('shop/lib/sell')->notice($info);
+            }
+        }
+    }
+
+    # 获取规格型号
+    public function getSku($goods_id, $sku_id)
+    {
+        $goods_info = Dever::load('goods/lib/info')->getInfoBySku($goods_id, $sku_id);
+        if (isset($goods_info['sku'])) {
+            $sku = $goods_info['sku']['string'];
+        } else {
+            $sku = '';
+        }
+
+        return $sku;
+    }
+
+    # 获取在途库存
+    public function getGoodsTotal($type, $type_id, $goods_id, $sku_id)
+    {
+        $where['type'] = $type;
+        $where['type_id'] = $type_id;
+        $where['status'] = '2,3,4';
+        $where['goods_id'] = $goods_id;
+        $where['sku_id'] = $sku_id;
+        $order = Dever::db('shop/buy_order_goods')->getGoodsTotal($where);
+        if ($order && $order['total']) {
+            return $order['total'];
+        }
+        return 0;
+    }
+
+    public function buyInfoRefundNum($id)
+    {
+        $where['status'] = 3;
+        $where['order_id'] = $id;
+        $order = Dever::db('shop/buy_order_goods')->getGoodsNum($where);
+        if ($order && $order['total']) {
+            return $order['total'];
+        }
+        return 0;
+    }
+
+    public function buyInfoRefundStatus($id, $table = 'buy_order')
+    {
+        $info = Dever::db('shop/' . $table)->find($id);
+        if ($info['refund_cash'] > 0) {
+            if ($info['status'] == 6 || $info['status'] == 8) {
+                return '已退款';
+            } else {
+                return '申请中';
+            }
+        } else {
+            return '未申请';
+        }
+    }
+
     public function shopInfoType($type)
     {
         $config_type = Dever::db('shop/info')->config['config_type'];
@@ -49,7 +114,7 @@ class Manage
         return $cash - $p_cash;
     }
     # 获取用户信息
-    public function user($id)
+    public function user($id, $type = 1)
     {
         $info = Dever::db('shop/sell_order')->one($id);
 
@@ -57,7 +122,7 @@ class Manage
             $user = Dever::db('passport/user')->one($info['uid']);
 
             $result = $user['username'];
-            if ($info['mobile']) {
+            if ($type == 1 && $info['mobile']) {
                 $result .= '('.$info['mobile'].')';
             }
         } else {
@@ -218,6 +283,16 @@ class Manage
             if (isset($temp[3])) {
                 $update['town'] = $temp[3];
             }
+
+            if (is_array($area)) {
+                $area = implode(',', $area);
+            }
+            $gup['option_shop_id'] = $id;
+            $gup['set_area'] = $area;
+            Dever::db('shop/goods_sku')->updates($gup);
+            Dever::db('shop/sell_order')->updates($gup);
+            Dever::db('shop/buy_order')->updates($gup);
+            Dever::db('shop/out_order')->updates($gup);
         }
 
         $map = Dever::param('map', $data);
@@ -396,4 +471,73 @@ class Manage
     {
         return Dever::search('shop/info');
     }
+
+    # 获取环比增长
+    public function getGoodsHb($num, $day, $goods_id)
+    {
+        $where = array('day' => $day, 'goods_id' => $goods_id);
+        $search = Dever::search_button();
+        if ($search) {
+            $where['config']['group'] = $search[0];
+            $where['config']['col'] = str_replace('|id', '', $search[1]);
+        }
+        if ($num < 0) {
+            $num = 0;
+        }
+        $prev = Dever::db('shop/goods_stat')->prev($where);
+        if ($prev && $prev['num'] >= 0) {
+            $n = $prev['num'];
+            if ($n == 0) {
+                $n = 1;
+            }
+            $hb = round(($num-$prev['num'])/$n, 2)*100;
+        } else {
+            $hb = 0;
+        }
+
+        return $hb . '%';
+    }
+
+    public function getUserHb($num, $total, $day)
+    {
+        $result = $this->getUserStat($num, $total, 0);
+        $where = array('day' => $day);
+        $search = Dever::search_button();
+        if ($search) {
+            $where['config']['group'] = $search[0];
+            $where['config']['col'] = str_replace('|id', '', $search[1]);
+        }
+        $hb = 0;
+        $prev = Dever::db('shop/user_stat')->prev($where);
+        if ($prev) {
+            $prev = $this->getUserStat($prev['num'], $prev['total'], $prev['order_num']);
+            if ($prev['fg'] >= 0) {
+                $fg = $prev['fg'];
+                if ($fg == 0) {
+                    $fg = 1;
+                }
+                $hb = round(($result['fg']-$prev['fg'])/$fg, 2)*100;
+            }
+        }
+
+        return $hb . '%';
+    }
+
+    public function getUserStat($num, $total, $order_num)
+    {
+        //print_r($info);die;
+        if ($num && $total) {
+            $result['fg'] = round($num/$total, 2);
+        } else {
+            $result['fg'] = 0;
+        }
+
+        if ($order_num) {
+            $result['per_num'] = round($order_num/$total, 2);
+        } else {
+            $result['per_num'] = 0;
+        }
+        
+        return $result;
+    }
 }

+ 7 - 0
app/shop/lib/Refund.php

@@ -157,6 +157,9 @@ class Refund
                     Dever::alert('您没有权限操作');
                 }
             } else {
+
+                Dever::db($this->goods_table)->updates(array('option_order_id' => $data['id'], 'option_status' => 1, 'set_status' => 2));
+
                 if (!$num) {
                     $num = $data['num'];
                 }
@@ -274,6 +277,8 @@ class Refund
 
             if ($info['type'] == 2) {
                 Dever::db($this->goods_table)->update(array('where_id' => $info['order_goods_id'], 'status' => 1));
+            } else {
+                Dever::db($this->goods_table)->updates(array('option_order_id' => $order['id'], 'option_status' => 2, 'set_status' => 1));
             }
 
             if ($cash && $this->type == 'buy' && $order['source_id'] && $order['source_id'] > 0) {
@@ -311,6 +316,8 @@ class Refund
                 $update['status'] = 8;
                 $state = Dever::db($this->order_table)->update($update);
                 if ($state) {
+                    Dever::db($this->goods_table)->updates(array('option_order_id' => $order['id'], 'option_status' => 2, 'set_status' => 3));
+
                     $this->notice($state, $order, $info);
                     if (isset($order['user_coupon_id']) && $order['user_coupon_id']) {
                         # 还原优惠券

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

@@ -757,6 +757,7 @@ class Sell
             $order_data['shop_type'] = 1;
         }
         
+        $order_data['area'] = $shop['area'] . ',' . $shop['id'];
         $order_data['uid'] = $uid;
         $order_data['mobile'] = $user['mobile'];
         $order_data['address_id'] = $address_id;
@@ -801,6 +802,7 @@ class Sell
             if ($v['ku_state'] == 1) {
                 $data['uid'] = $uid;
                 $data['order_id'] = $id;
+                $data['shop_id'] = $shop['id'];
                 $data['goods_id'] = $v['id'];
                 $data['sku_id'] = $v['sku_id'];
                 $data['price'] = $v['price'];
@@ -1068,6 +1070,7 @@ class Sell
 
                 $update['status'] = $status;
                 $update['where_id'] = $order['id'];
+                $update['paydate'] = time();
                 Dever::db('shop/sell_order')->update($update);
             }
         }
@@ -1466,4 +1469,64 @@ class Sell
         }
     }
     
+    # 发货
+    public function notice($info)
+    {
+        $config = Dever::db('shop/sell_order')->config;
+        $state = Dever::db('shop/sell_order')->update(array('where_id' => $info['id'], 'status' => 3, 'operdate' => time()));
+
+        # 给用户发消息
+        if ($info['uid'] && $info['uid'] > 0) {
+            $shop = Dever::db('shop/info')->one($info['shop_id']);
+            $msg_param['type'] = 1;//消息类型1是订单消息
+            $msg_param['id'] = $info['id'];
+            $msg_param['name'] = $shop['name'];
+            $msg_param = Dever::json_encode($msg_param);
+            if ($info['method'] == 1) {
+                $msg = '您有一件自提商品已完成配货,请尽快到指定门店使用取件码取货,取件码:' . $info['code'];
+                $name = '取货通知';
+                $wechat_msg = '您的商品已完成配货';
+            } else {
+                $msg = '您有一件外送商品已开始配送,收货时请将取件码提供给配送员核实货品信息,取件码:' . $info['code'];
+                $name = '配送通知';
+                $wechat_msg = '您的商品已开始配送';
+            }
+            
+            Dever::load('message/lib/data')->push(-1, $info['uid'], $name, $msg, 1, 1, false, $msg_param);
+
+            if (Dever::load('wechat_applet')) {
+                $user = Dever::db('passport/wechat')->one(array('uid' => $info['uid'], 'system_id' => 1, 'system_source' => 5));
+                if ($user && $user['openid']) {
+                    $info['status_name'] = $config['status'][$info['status']];
+                    $send = array
+                    (
+                        'character_string6' => array
+                        (
+                            'value' => $info['order_num'],
+                        ),
+                        
+                        'phrase7' => array
+                        (
+                            'value' => $info['status_name'],
+                        ),
+                        'thing8' => array
+                        (
+                            'value' => $info['code'],
+                        ),
+                        'amount1' => array
+                        (
+                            'value' => $info['price'] . '元',
+                        ),
+                        'thing5' => array
+                        (
+                            'value' => $wechat_msg,
+                        ),
+                    );
+
+                    $send = Dever::json_encode($send);
+                    Dever::load('wechat_applet/subscribe')->sendOne('order_process', 1, $user['openid'], 'pages/app/order/order?id=' . $info['id'], $send, Dever::config('base')->wechat_applet);
+                }
+            }
+        }
+    }
 }

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

@@ -49,6 +49,7 @@ class Set
         $goods = Dever::json_decode($goods);
         $shop_id = Dever::input('shop_id');
 
+        $shop = Dever::db('shop/info')->one($shop_id);
         $where['option_shop_id'] = $shop_id;
         $where['set_state'] = 2;
         Dever::db('shop/goods')->updates($where);
@@ -114,6 +115,7 @@ class Set
                 $w['status'] = $goods_info['status'];
                 $w['total_num'] = $v['num'];
                 $w['min'] = $v['min'];
+                $w['area'] = $shop['area'];
                 if (!$info) {
                     Dever::db('shop/goods_sku')->insert($w);
                 } else {

+ 657 - 0
app/shop/src/Excel.php

@@ -0,0 +1,657 @@
+<?php
+
+namespace Shop\Src;
+
+use Dever;
+
+class Excel
+{
+    # 门店零售单
+    public function sell_order($data)
+    {
+        if (!$data) {
+            Dever::alert('无导出数据');
+        }
+        $file = Dever::input('excel_name');
+
+        $header = array('门店编号', '门店名称', '门店类型', '订单号', '购买人', '商品编码', '商品名称', '规格型号', '商品单价', '购买数量', '商品合计金额', '配送类型', '订单类型', '下单时间', '付款时间', '发货时间', '订单合计金额', '订单实付金额', '已退订单金额', '支付渠道', '订单状态');
+
+        $table = 'shop/info';
+
+        $body = array();
+        $status = Dever::db('shop/sell_order')->config['status_manage'];
+        $method = Dever::db('shop/sell_order')->config['method'];
+        $pay_method = Dever::db('shop/sell_order')->config['pay_method'];
+        $pay_type = Dever::db('shop/sell_order')->config['pay_type'];
+
+        $info_type = Dever::db($table)->config['config_type'];
+        foreach ($data as $k => $v) {
+            if (!is_array($v)) {
+                continue;
+            }
+            $info = Dever::db($table)->find($v['shop_id']);
+            $goods = Dever::db('shop/sell_order_goods')->select(array('order_id' => $v['id']));
+            $ps = Dever::db('shop/sell_order_ps')->find(array('order_id' => $v['id']));
+            $cdate = strstr($v['cdate'], '-') ? $v['cdate'] : date('Y-m-d H:i', $v['cdate']);
+            $paydate = isset($v['paydate']) && $v['paydate'] ? date('Y-m-d H:i', $v['paydate']) : '-';
+            $operdate = ($ps && $ps['cdate']) ? date('Y-m-d H:i', $ps['cdate']) : '-';
+
+            $total_cash = Dever::load("shop/lib/manage.getTotalCash", $v['id']);
+            $v['refund_cash'] = $v['refund_cash'] ? $v['refund_cash'] : 0;
+            
+            $user = Dever::load("shop/lib/manage.user", $v['id']);
+            foreach ($goods as $k1 => $v1) {
+
+                $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v1['goods_id'], $v1['sku_id']);
+                if (isset($goods_info['sku'])) {
+                    $sku = $goods_info['sku']['string'];
+                } else {
+                    $sku = '';
+                }
+
+                $d = array
+                (
+                    $info['sid'],
+                    $info['name'],
+                    $info_type[$info['type']],
+
+                    $v['order_num'],
+                    $user,
+
+                    $goods_info['code'],
+                    $goods_info['name'],
+                    $sku,
+                    $v1['price'],
+                    $v1['num'],
+                    $v1['price']*$v1['num'],
+
+
+                    $method[$v['method']],
+                    $pay_method[$v['pay_method']],
+                    $cdate,
+                    $paydate,
+                    $operdate,
+
+                    $total_cash,
+                    $v['price'],
+                    $v['refund_cash'],
+                    $pay_type[$v['pay_type']],
+                    $status[$v['status']],
+                );
+
+                $body[] = $d;
+            }
+        }
+
+        Dever::excelExport($body, $header, $file);
+    }
+
+    # 平台零售订单
+    public function p_sell_order($data)
+    {
+        if (!$data) {
+            Dever::alert('无导出数据');
+        }
+        $file = Dever::input('excel_name');
+
+        $header = array('订单号', '收件人', '收件人手机', '收件人地址', '发货仓库', '商品编码', '商品名称', '规格型号', '商品单价', '购买数量', '商品合计金额', '下单时间', '付款时间', '发货时间', '订单总数量', '订单总金额', '订单状态', '退款状态', '退款金额');
+
+        $table = 'shop/info';
+
+        $body = array();
+        $status = Dever::db('shop/sell_order')->config['status_manage'];
+
+        $info_type = Dever::db($table)->config['config_type'];
+        foreach ($data as $k => $v) {
+            if (!is_array($v)) {
+                continue;
+            }
+            $info = Dever::db($table)->find($v['shop_id']);
+            if ($v['store_id']) {
+                $store = Dever::db('store/info')->find($v['store_id']);
+            } else {
+                $store['name'] = '';
+            }
+            
+            $goods = Dever::db('shop/sell_order_goods')->select(array('order_id' => $v['id']));
+            $ps = Dever::db('shop/sell_order_ps')->find(array('order_id' => $v['id']));
+            $cdate = strstr($v['cdate'], '-') ? $v['cdate'] : date('Y-m-d H:i', $v['cdate']);
+            $paydate = isset($v['paydate']) && $v['paydate'] ? date('Y-m-d H:i', $v['paydate']) : '-';
+            $operdate = ($ps && $ps['cdate']) ? date('Y-m-d H:i', $ps['cdate']) : '-';
+            
+            $refund_status = Dever::load("shop/lib/manage.buyInfoRefundStatus", $v['id'], 'sell_order');
+            $v['refund_cash'] = $v['refund_cash'] ? $v['refund_cash'] : 0;
+            $address = Dever::load('passport/address')->getOne($v['uid'], $v['address_id']);
+            foreach ($goods as $k1 => $v1) {
+
+                $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v1['goods_id'], $v1['sku_id']);
+                if (isset($goods_info['sku'])) {
+                    $sku = $goods_info['sku']['string'];
+                } else {
+                    $sku = '';
+                }
+
+                $d = array
+                (
+                    $v['order_num'],
+                    $address['contact'],
+                    $address['mobile'],
+                    $address['add_string'],
+                    $store['name'],
+
+                    $goods_info['code'],
+                    $goods_info['name'],
+                    $sku,
+                    $v1['price'],
+                    $v1['num'],
+                    $v1['price']*$v1['num'],
+
+                    $cdate,
+                    $paydate,
+                    $operdate,
+
+                    $v['num'],
+                    $v['price'],
+                    $status[$v['status']],
+                    $refund_status,
+                    $v['refund_cash'],
+                );
+
+                $body[] = $d;
+            }
+        }
+
+        Dever::excelExport($body, $header, $file);
+    }
+
+    # 门店订货单
+    public function buy_order($data)
+    {
+        if (!$data) {
+            Dever::alert('无导出数据');
+        }
+        $file = Dever::input('excel_name');
+
+
+        $header = array('门店编号', '门店名称', '门店类型', '供货商', '订货单号', '订货总数量', '订货单总金额', '商品编码', '商品名称', '规格型号', '订货单价', '订货数量', '商品合计金额', '订货日期', '订货单状态', '退款状态', '退款金额');
+
+        $table = 'shop/info';
+
+        $body = array();
+        $status = Dever::db('shop/buy_order')->config['status'];
+        //$refund_status = Dever::db('shop/buy_order')->config['refund_status'];
+        $info_type = Dever::db($table)->config['config_type'];
+
+        foreach ($data as $k => $v) {
+            if (!is_array($v)) {
+                continue;
+            }
+            $info = Dever::db($table)->find($v['type_id']);
+            $goods = Dever::db('shop/buy_order_goods')->select(array('order_id' => $v['id']));
+            $cdate = strstr($v['cdate'], '-') ? $v['cdate'] : date('Y-m-d H:i', $v['cdate']);
+            $refund_status = Dever::load("shop/lib/manage.buyInfoRefundStatus", $v['id']);
+
+            $source = Dever::load("shop/lib/manage.buyInfo", $v['source_type'], $v['source_id']);
+            foreach ($goods as $k1 => $v1) {
+
+                $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v1['goods_id'], $v1['sku_id']);
+                if (isset($goods_info['sku'])) {
+                    $sku = $goods_info['sku']['string'];
+                } else {
+                    $sku = '';
+                }
+
+                $d = array
+                (
+                    $info['sid'],
+                    $info['name'],
+                    $info_type[$info['type']],
+
+                    $source,
+                    $v['order_num'],
+                    $v['num'],
+                    $v['price'],
+
+                    $goods_info['code'],
+                    $goods_info['name'],
+                    $sku,
+                    $v1['price'],
+                    $v1['num'],
+                    $v1['price']*$v1['num'],
+
+                    $cdate,
+                    $status[$v['status']],
+                    $refund_status,
+                    $v['refund_cash'],
+                );
+
+                $body[] = $d;
+            }
+        }
+
+        Dever::excelExport($body, $header, $file);
+    }
+
+    # 仓库订货单
+    public function store_buy_order($data)
+    {
+        if (!$data) {
+            Dever::alert('无导出数据');
+        }
+        $file = Dever::input('excel_name');
+
+
+        $header = array('仓库名称', '发货工厂', '订货单号', '订货总数量', '商品编码', '商品名称', '规格型号', '商品订货数量', '订货日期', '发货日期', '收货日期', '订货单状态', '已退商品数量');
+
+        $table = 'store/info';
+
+        $body = array();
+        $status = Dever::db('shop/buy_order')->config['status'];
+        //$refund_status = Dever::db('shop/buy_order')->config['refund_status'];
+
+        foreach ($data as $k => $v) {
+            if (!is_array($v)) {
+                continue;
+            }
+            $info = Dever::db($table)->find($v['type_id']);
+            $goods = Dever::db('shop/buy_order_goods')->select(array('order_id' => $v['id']));
+            $ps = Dever::db('shop/buy_order_ps')->find(array('order_id' => $v['id']));
+            $cdate = strstr($v['cdate'], '-') ? $v['cdate'] : date('Y-m-d H:i', $v['cdate']);
+            $fdate = ($ps && $ps['cdate']) ? date('Y-m-d H:i', $ps['cdate']) : '-';
+            $ydate = ($ps && $ps['ydate']) ? date('Y-m-d H:i', $ps['ydate']) : '-';
+            $num = Dever::load("shop/lib/manage.buyInfoRefundNum", $v['id']);
+            $refund_status = Dever::load("shop/lib/manage.buyInfoRefundStatus", $v['id']);
+            $v['refund_cash'] = $v['refund_cash'] ? $v['refund_cash'] : 0;
+
+            $source = Dever::load("shop/lib/manage.buyInfo", $v['source_type'], $v['source_id']);
+            foreach ($goods as $k1 => $v1) {
+
+                $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v1['goods_id'], $v1['sku_id']);
+                if (isset($goods_info['sku'])) {
+                    $sku = $goods_info['sku']['string'];
+                } else {
+                    $sku = '';
+                }
+
+                $d = array
+                (
+                    $info['name'],
+                    $source,
+                    $v['order_num'],
+                    $v['num'],
+
+                    $goods_info['code'],
+                    $goods_info['name'],
+                    $sku,
+                    $v1['num'],
+
+                    $cdate,
+                    $fdate,
+                    $ydate,
+                    $status[$v['status']],
+                    $num,
+                );
+
+                $body[] = $d;
+            }
+        }
+
+        Dever::excelExport($body, $header, $file);
+    }
+
+    # 仓库发货单
+    public function store_buy_order_fa($data)
+    {
+        if (!$data) {
+            Dever::alert('无导出数据');
+        }
+        $file = Dever::input('excel_name');
+
+
+        $header = array('仓库名称', '门店编号', '门店名称', '门店类型', '订货单号', '订货总数量', '订货单总金额', '商品编码', '商品名称', '规格型号', '订货单价', '订货数量', '商品合计金额', '订货日期', '发货日期', '订货单状态', '退款状态', '已退商品数量', '退款金额');
+
+        $table = 'shop/info';
+
+        $body = array();
+        $status = Dever::db('shop/buy_order')->config['status'];
+        //$refund_status = Dever::db('shop/buy_order')->config['refund_status'];
+        $info_type = Dever::db($table)->config['config_type'];
+
+        foreach ($data as $k => $v) {
+            if (!is_array($v)) {
+                continue;
+            }
+            $info = Dever::db($table)->find($v['type_id']);
+            $goods = Dever::db('shop/buy_order_goods')->select(array('order_id' => $v['id']));
+            $ps = Dever::db('shop/buy_order_ps')->find(array('order_id' => $v['id']));
+            $cdate = strstr($v['cdate'], '-') ? $v['cdate'] : date('Y-m-d H:i', $v['cdate']);
+            $fdate = ($ps && $ps['cdate']) ? date('Y-m-d H:i', $ps['cdate']) : '-';
+            $ydate = ($ps && $ps['ydate']) ? date('Y-m-d H:i', $ps['ydate']) : '-';
+            $num = Dever::load("shop/lib/manage.buyInfoRefundNum", $v['id']);
+            $refund_status = Dever::load("shop/lib/manage.buyInfoRefundStatus", $v['id']);
+            $v['refund_cash'] = $v['refund_cash'] ? $v['refund_cash'] : 0;
+
+            $source = Dever::load("shop/lib/manage.buyInfo", $v['source_type'], $v['source_id']);
+            foreach ($goods as $k1 => $v1) {
+
+                $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v1['goods_id'], $v1['sku_id']);
+                if (isset($goods_info['sku'])) {
+                    $sku = $goods_info['sku']['string'];
+                } else {
+                    $sku = '';
+                }
+
+                $d = array
+                (
+                    $source,
+                    $info['sid'],
+                    $info['name'],
+                    $info_type[$info['type']],
+
+                    $v['order_num'],
+                    $v['num'],
+                    $v['price'],
+
+                    $goods_info['code'],
+                    $goods_info['name'],
+                    $sku,
+                    $v1['price'],
+                    $v1['num'],
+                    $v1['price']*$v1['num'],
+
+                    $cdate,
+                    $fcdate,
+                    $status[$v['status']],
+                    $refund_status,
+                    $num,
+                    $v['refund_cash'],
+                );
+
+                $body[] = $d;
+            }
+        }
+
+        Dever::excelExport($body, $header, $file);
+    }
+
+    # 工厂发货单
+    public function factory_buy_order_fa($data)
+    {
+        if (!$data) {
+            Dever::alert('无导出数据');
+        }
+        $file = Dever::input('excel_name');
+
+
+        $header = array('工厂名称', '收件人名称', '收件人类型', '订货单号', '订货总数量', '订货单总金额', '商品编码', '商品名称', '规格型号', '商品进货单价', '订货数量', '商品合计金额', '订货日期', '发货日期', '订货单状态', '已退商品数量', '退款金额');
+
+        $table = 'shop/info';
+
+        $body = array();
+        $status = Dever::db('shop/buy_order')->config['status'];
+        //$refund_status = Dever::db('shop/buy_order')->config['refund_status'];
+        $info_type = Dever::db($table)->config['config_type'];
+
+        foreach ($data as $k => $v) {
+            if (!is_array($v)) {
+                continue;
+            }
+            $info = Dever::db($table)->find($v['type_id']);
+            $goods = Dever::db('shop/buy_order_goods')->select(array('order_id' => $v['id']));
+            $ps = Dever::db('shop/buy_order_ps')->find(array('order_id' => $v['id']));
+            $cdate = strstr($v['cdate'], '-') ? $v['cdate'] : date('Y-m-d H:i', $v['cdate']);
+            $fdate = ($ps && $ps['cdate']) ? date('Y-m-d H:i', $ps['cdate']) : '-';
+            $ydate = ($ps && $ps['ydate']) ? date('Y-m-d H:i', $ps['ydate']) : '-';
+            $num = Dever::load("shop/lib/manage.buyInfoRefundNum", $v['id']);
+            $refund_status = Dever::load("shop/lib/manage.buyInfoRefundStatus", $v['id']);
+            $v['refund_p_cash'] = $v['refund_p_cash'] ? $v['refund_p_cash'] : 0;
+
+            $source = Dever::load("shop/lib/manage.buyInfo", $v['source_type'], $v['source_id']);
+            foreach ($goods as $k1 => $v1) {
+
+                $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v1['goods_id'], $v1['sku_id']);
+                if (isset($goods_info['sku'])) {
+                    $sku = $goods_info['sku']['string'];
+                } else {
+                    $sku = '';
+                }
+
+                $d = array
+                (
+                    $source,
+                    $info['sid'],
+                    $info['name'],
+                    $info_type[$info['type']],
+
+                    $v['order_num'],
+                    $v['num'],
+                    $v['p_price'],
+
+                    $goods_info['code'],
+                    $goods_info['name'],
+                    $sku,
+                    $v1['p_price'],
+                    $v1['num'],
+                    $v1['p_price']*$v1['num'],
+
+                    $cdate,
+                    $fcdate,
+                    $status[$v['status']],
+                    $num,
+                    $v['refund_p_cash'],
+                );
+
+                $body[] = $d;
+            }
+        }
+
+        Dever::excelExport($body, $header, $file);
+    }
+
+    # 门店出库单
+    public function out_order($data)
+    {
+        if (!$data) {
+            Dever::alert('无导出数据');
+        }
+        $file = Dever::input('excel_name');
+
+
+        $header = array('门店编号', '门店名称', '门店类型', '出库单号', '出库总数量', '出库总金额', '商品编码', '商品名称', '规格型号', '订货单价', '订货数量', '商品合计金额', '出库日期', '出库类型', '出库状态');
+
+        $table = 'shop/info';
+
+        $body = array();
+        $status = Dever::db('shop/out_order')->config['config_status'];
+        $config_type = Dever::db('shop/out_order')->config['config_type'];
+        $config_type = $config_type();
+        $info_type = Dever::db($table)->config['config_type'];
+
+        foreach ($data as $k => $v) {
+            if (!is_array($v)) {
+                continue;
+            }
+            $info = Dever::db($table)->find($v['type_id']);
+            $goods = Dever::db('shop/out_order_goods')->select(array('order_id' => $v['id']));
+            $cdate = strstr($v['cdate'], '-') ? $v['cdate'] : date('Y-m-d H:i', $v['cdate']);
+
+            foreach ($goods as $k1 => $v1) {
+
+                $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v1['goods_id'], $v1['sku_id']);
+                if (isset($goods_info['sku'])) {
+                    $sku = $goods_info['sku']['string'];
+                } else {
+                    $sku = '';
+                }
+
+                $d = array
+                (
+                    $info['sid'],
+                    $info['name'],
+                    $info_type[$info['type']],
+
+                    $v['order_num'],
+                    $v['num'],
+                    $v['price'],
+
+                    $goods_info['code'],
+                    $goods_info['name'],
+                    $sku,
+                    $v1['price'],
+                    $v1['num'],
+                    $v1['price']*$v1['num'],
+
+                    $cdate,
+                    $config_type[$v['config_type']]['name'],
+                    $status[$v['status']],
+                );
+
+                $body[] = $d;
+            }
+        }
+
+        Dever::excelExport($body, $header, $file);
+    }
+
+    # 仓库出库单
+    public function store_out_order($data)
+    {
+        if (!$data) {
+            Dever::alert('无导出数据');
+        }
+        $file = Dever::input('excel_name');
+
+
+        $header = array('仓库名称', '出库单号', '出库总数量', '出库总金额', '商品编码', '商品名称', '规格型号', '门店进货单价', '订货数量', '商品合计金额', '出库日期', '出库类型', '出库状态');
+
+        $table = 'store/info';
+
+        $body = array();
+        $status = Dever::db('shop/out_order')->config['config_status'];
+        $config_type = Dever::db('shop/out_order')->config['config_type'];
+        $config_type = $config_type();
+        $info_type = Dever::db($table)->config['config_type'];
+
+        foreach ($data as $k => $v) {
+            if (!is_array($v)) {
+                continue;
+            }
+            $info = Dever::db($table)->find($v['type_id']);
+            $goods = Dever::db('shop/out_order_goods')->select(array('order_id' => $v['id']));
+            $cdate = strstr($v['cdate'], '-') ? $v['cdate'] : date('Y-m-d H:i', $v['cdate']);
+
+            foreach ($goods as $k1 => $v1) {
+
+                $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v1['goods_id'], $v1['sku_id']);
+                if (isset($goods_info['sku'])) {
+                    $sku = $goods_info['sku']['string'];
+                } else {
+                    $sku = '';
+                }
+
+                $d = array
+                (
+                    $info['name'],
+                    $v['order_num'],
+                    $v['num'],
+                    $v['price'],
+
+                    $goods_info['code'],
+                    $goods_info['name'],
+                    $sku,
+                    $v1['price'],
+                    $v1['num'],
+                    $v1['price']*$v1['num'],
+
+                    $cdate,
+                    $config_type[$v['config_type']]['name'],
+                    $status[$v['status']],
+                );
+
+                $body[] = $d;
+            }
+        }
+
+        Dever::excelExport($body, $header, $file);
+    }
+
+    public function goods_log()
+    {
+        //Array ( [search_option_state] => 1 [search_api_goods_id] => 猪肉 [search_api_goods-info-code] => [search_option_status] => 0 [search_option_store_id] => 6 [search_option_start_cdate] => [search_option_end_cdate] => [search_option_sday] => 0 )
+        $data = Dever::input();
+
+        $where = array();
+        if (isset($data['search_option_store_id']) && $data['search_option_store_id']) {
+            $where['store_id'] = $data['search_option_store_id'];
+        }
+
+        if (isset($data['search_option_status']) && $data['search_option_status']) {
+            $where['status'] = $data['search_option_status'];
+        }
+
+        if (isset($data['search_option_start_cdate']) && $data['search_option_start_cdate']) {
+            $where['start'] = $data['search_option_start_cdate'];
+        }
+
+        if (isset($data['search_option_end_cdate']) && $data['search_option_end_cdate']) {
+            $where['end'] = $data['search_option_end_cdate'];
+        }
+
+        if (isset($data['search_api_goods_id']) && $data['search_api_goods_id']) {
+            $goods_info = Dever::db('goods/info')->like(array('name' => $data['search_api_goods_id']));
+            if ($goods_info) {
+                $where['goods_id'] = array_keys($goods_info);
+            }
+        }
+
+        if (isset($data['search_api_goods-info-code']) && $data['search_api_goods-info-code']) {
+            $goods_sku = Dever::db('goods/info_sku')->like(array('code' => $data['search_api_goods-info-code']));
+            if ($goods_sku) {
+                $where['sku_id'] = array_keys($goods_sku);
+            }
+        }
+
+        $goods = Dever::db('store/goods_log')->getDataByDate($where);
+
+        $file = '仓库调整明细';
+        $header = array('仓库名称', '商品编码', '商品名称', '规格型号', '当前库存', '占用库存', '在途库存', '总库存', '调整数量', '调整后库存', '调整后总库存', '调整时间');
+
+        $body = array();
+        if ($goods) {
+            foreach ($goods as $k => $v) {
+                $info = Dever::db('store/info')->find($v['store_id']);
+                $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v['goods_id'], $v['sku_id']);
+                if (isset($goods_info['sku'])) {
+                    $sku = $goods_info['sku']['string'];
+                } else {
+                    $sku = '';
+                }
+
+                $cdate = date('Y-m-d H:i', $v['cdate']);
+                $d = array
+                (
+                    $info['name'],
+                    $goods_info['code'],
+                    $goods_info['name'],
+                    $sku,
+
+                    $v['cur_num'],
+                    $v['sell_num'],
+                    $v['online_num'],
+                    $v['total_num'],
+
+                    $v['num'],
+                    $v['after_cur_num'],
+                    $v['after_total_num'],
+                    $cdate,
+                );
+
+                $body[] = $d;
+            }
+        } else {
+            Dever::alert('无导出数据');
+        }
+
+        Dever::excelExport($body, $header, $file);
+    }
+}

+ 217 - 0
app/store/database/goods_log.php

@@ -0,0 +1,217 @@
+<?php
+$config = array
+(
+    # 表名
+    'name' => 'goods_log',
+    # 显示给用户看的名称
+    'lang' => '商品库存日志',
+    'order' => 200,
+    'menu' => false,
+
+    # 数据结构 不同的字段放这里
+    'struct' => array
+    (
+        'id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            //'list'        => true,
+        ),
+
+        'store_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '仓库名称',
+            'default'   => '',
+            'desc'      => '仓库名称',
+            'match'     => 'is_numeric',
+            'list'      => 'Dever::load("store/info-find#name", {store_id})',
+            'search'    => array
+            (
+                'api' => 'store/info-like',
+                'col' => 'name',
+                'result' => 'id',
+            ),
+            'search'    => 'hidden',
+            'list_order' => 1,
+        ),
+
+        'goods-info-code'=> array
+        (
+            'name'      => '商品编码',
+            'default'   => '',
+            'desc'      => '商品编码',
+            'match'     => 'option',
+            # 读取另外表的关联方式
+            'sync'      => array('sku_id', 'id'),
+            'list'      => true,
+            'list_order' => 2,
+        ),
+
+        'goods_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '商品名称',
+            'default'   => '',
+            'desc'      => '商品名称',
+            'match'     => 'is_numeric',
+            'search'    => array
+            (
+                'api' => 'goods/info-like',
+                'col' => 'name',
+                'result' => 'id',
+            ),
+            'list'      => 'Dever::load("goods/info-find#name", {goods_id})',
+            'list_order' => 3,
+        ),
+
+        'sku_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '规格型号',
+            'default'   => '-1',
+            'desc'      => '规格型号',
+            'match'     => 'is_numeric',
+            'search'    => 'hidden',
+            'list'      => 'Dever::load("shop/lib/manage.getSku", {goods_id}, {sku_id})',
+            'list_order' => 4,
+        ),
+
+        'cur_num'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '当前库存',
+            'default'   => '0',
+            'desc'      => '新增库存',
+            'match'     => 'is_numeric',
+            'list_name' => '当前库存',
+            'list'      => true,
+            'list_order' => 5,
+        ),
+
+        'sell_num'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '占用库存',
+            'default'   => '0',
+            'desc'      => '占用库存',
+            'match'     => 'option',
+            'list'      => true,
+            'list_order' => 6,
+        ),
+
+        'online_num'  => array
+        (
+            'type'      => 'int-11',
+            'name'      => '在途库存',
+            'default'   => '0',
+            'desc'      => '在途库存',
+            'match'     => 'option',
+            //'search'    => 'order',
+            'list'      => true,
+            'list_order' => 7,
+        ),
+
+        'total_num'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '总库存',
+            'default'   => '0',
+            'desc'      => '总库存',
+            'match'     => 'is_numeric',
+            'list'      => true,
+            'list_order' => 8,
+        ),
+
+        'num'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '调整数量',
+            'default'   => '0',
+            'desc'      => '调整数量',
+            'match'     => 'is_numeric',
+            'list'      => true,
+            'list_order' => 9,
+        ),
+
+        'after_cur_num'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '调整后库存',
+            'default'   => '0',
+            'desc'      => '调整后库存',
+            'match'     => 'is_numeric',
+            'list'      => true,
+            'list_order' => 10,
+        ),
+
+        'after_total_num'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '调整后总库存',
+            'default'   => '0',
+            'desc'      => '调整后总库存',
+            'match'     => 'is_numeric',
+            'list'      => true,
+            'list_order' => 11,
+        ),
+
+        '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'  => 'sday',
+            'list'        => 'date("Y-m-d H:i", {cdate})',
+            'list_order' => 13,
+        ),
+    ),
+
+    'manage' => array
+    (
+        'insert' => false,
+        'edit' => false,
+        'delete' => false,
+        'num' => false,
+        'excel' => true,
+    ),
+
+    # request 请求接口定义
+    'request' => array
+    (
+        'getDataByDate' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'store_id' => 'yes',
+                'status' => 'yes',
+                'start' => array('yes-cdate', '>='),
+                'end' => array('yes-cdate', '<='),
+                'sku_id' => array('yes', 'in'),
+                'goods_id' => array('yes', 'in'),
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('store_id' => 'desc', 'goods_id' => 'desc', 'id' => 'desc'),
+            'col' => '*',
+        ),
+    ),
+);
+
+return $config;

+ 141 - 14
app/store/database/goods_sku.php

@@ -1,5 +1,6 @@
 <?php
-
+$type = Dever::input('search_type');
+$status = Dever::config('base')->status;
 $config = array
 (
     # 表名
@@ -14,6 +15,19 @@ $config = array
         'update' => 'store/lib/manage.skuUpdate',
     ),
 
+    'fill' => array
+    (
+        # 从哪个表填充
+        'goods/info' => array
+        (
+            # 条件,另外一个表的字段 => 本表的字段
+            'where' => array('id' => 'goods_id'),
+            # 要填充的数据,另外一个表的字段 => 本表的字段,如果不填写就是所有的
+            'update' => array('status' => 'status'),
+            # 不需要填充的字段 与update互斥
+            //'no' => array('id', 'seller_id', 'service_id', 'chose', 'state', 'cdate')
+        )
+    ),
     # 数据结构 不同的字段放这里
     'struct' => array
     (
@@ -30,11 +44,51 @@ $config = array
         'store_id'      => array
         (
             'type'      => 'int-11',
-            'name'      => '所属仓库',
+            'name'      => '仓库名称',
             'default'   => '',
-            'desc'      => '所属仓库',
+            'desc'      => '仓库名称',
             'match'     => 'is_numeric',
             'list'      => 'Dever::load("store/info-find#name", {store_id})',
+            'search'    => array
+            (
+                'api' => 'store/info-like',
+                'col' => 'name',
+                'result' => 'id',
+                'search' => 'store_id',//本表的字段,默认为当前的字段
+            ),
+            'search'    => 'hidden',
+            'list_order' => 1,
+        ),
+
+        'goods-info-code'=> array
+        (
+            'name'      => '商品编码',
+            'default'   => '',
+            'desc'      => '商品编码',
+            'match'     => 'option',
+            # 读取另外表的关联方式
+            'sync'      => array('sku_id', 'id'),
+            'search'    => array
+            (
+                'api' => 'goods/info_sku-like',
+                'col' => 'code',
+                'result' => 'id',
+                'search' => 'sku_id',//本表的字段,默认为当前的字段
+            ),
+            'list'      => true,
+            'list_order' => 2,
+        ),
+
+        'goods-info-f_price'=> array
+        (
+            'name'      => '门店进货单价',
+            'default'   => '',
+            'desc'      => '门店进货单价',
+            'match'     => 'option',
+            # 读取另外表的关联方式
+            'sync'      => array('sku_id', 'id'),
+            'list'      => $type != 1 ? true : false,
+            'list_order' => 7,
         ),
 
         'goods_id'      => array
@@ -44,16 +98,25 @@ $config = array
             'default'   => '',
             'desc'      => '商品名称',
             'match'     => 'is_numeric',
+            'search'    => array
+            (
+                'api' => 'goods/info-like',
+                'col' => 'name',
+                'result' => 'id',
+            ),
             'list'      => 'Dever::load("goods/info-find#name", {goods_id})',
+            'list_order' => 5,
         ),
 
         'sku_id'      => array
         (
             'type'      => 'int-11',
-            'name'      => 'sku_id',
+            'name'      => '规格型号',
             'default'   => '-1',
-            'desc'      => 'sku_id',
+            'desc'      => '规格型号',
             'match'     => 'is_numeric',
+            'list'      => 'Dever::load("shop/lib/manage.getSku", {goods_id}, {sku_id})',
+            'list_order' => 6,
         ),
 
         'add_num'        => array
@@ -63,6 +126,9 @@ $config = array
             'default'   => '0',
             'desc'      => '新增库存',
             'match'     => 'is_numeric',
+            'list_name' => '当前库存',
+            'list'      => '{total_num} - {sell_num}',
+            'list_order' => 8,
         ),
 
         'total_num'        => array
@@ -72,6 +138,8 @@ $config = array
             'default'   => '0',
             'desc'      => '总库存',
             'match'     => 'is_numeric',
+            'list'      => true,
+            'list_order' => 10,
         ),
 
         'sell_num'      => array
@@ -81,8 +149,10 @@ $config = array
             'default'   => '0',
             'desc'      => '请填写销量',
             'match'     => 'option',
-            'search'    => 'order',
-            //'list'      => true,
+            //'search'    => 'order',
+            'list_name' => '占用库存',
+            'list'      => true,
+            'list_order' => 9,
         ),
 
         'reorder'       => array
@@ -93,10 +163,40 @@ $config = array
             'desc'      => '请输入排序',
             'match'     => 'option',
             //'update'  => 'text',
-            'search'    => 'order',
-            'list'      => true,
+            //'search'    => 'order',
+            //'list'      => true,
             'order'     => 'desc',
-            'edit'      => true,
+            //'edit'      => true,
+            'list_name' => '在途库存',
+            'list'      => 'Dever::load("shop/lib/manage.getGoodsTotal", 2, {store_id}, {goods_id}, {sku_id})',
+            'list_order' => 9,
+        ),
+
+        'operdate'     => array
+        (
+            'type'      => 'int-11',
+            'name'      => '最近调整时间',
+            'default'   => '',
+            'match'     => 'is_numeric',
+            'desc'      => '',
+            'search'  => 'sday',
+            'list'      => '"{operdate}" > 0 ? date("Y-m-d H:i", {operdate}) : date("Y-m-d H:i", {cdate})',
+            'list_order' => 13,
+        ),
+
+        'status'        => array
+        (
+            'type'      => 'tinyint-1',
+            'name'      => '商品状态',
+            'default'   => '2',
+            'desc'      => '状态',
+            'match'     => 'is_numeric',
+            //'update'  => 'select',
+            'option'    => $status,
+            'search'    => 'select',
+            'list'      => true,
+            'list_order' => 11,
+            //'edit'      => true,
         ),
 
         'state'     => array
@@ -111,13 +211,14 @@ $config = array
         'cdate'     => array
         (
             'type'      => 'int-11',
-            'name'      => '发布时间',
+            'name'      => '创建时间',
             'match'     => array('is_numeric', time()),
             'desc'      => '',
             # 只有insert时才生效
             'insert'    => true,
-            //'search'  => 'date',
-            //'list'        => 'date("Y-m-d H:i:s", {cdate})',
+            //'search'  => 'sday',
+            'list'        => $type == 1 ? 'date("Y-m-d H:i", {cdate})' : false,
+            'list_order' => 12,
         ),
     ),
 
@@ -127,12 +228,20 @@ $config = array
         'edit' => false,
         'delete' => false,
         'num' => false,
+        'excel' => true,
         'page_list_table' => 'sku',
 
         # 自定义快捷新增和编辑
         'button' => array
         (
-            //'自定义属性' => array('fast', 1, 'config&where_id=1'),
+            '新增仓库商品' => array('location', Dever::url('lib/set.home?id=' . Dever::input('search_option_store_id'), 'store')),
+            '导出调整明细' => array('excel', 'shop/excel.goods_log'),
+        ),
+
+        'list_button' => array
+        (
+            'list' => array('查看详情', '"goods_log&search_option_store_id={store_id}&earch_option_goods_id={goods_id}&earch_option_sku_id={sku_id}&oper_table=goods_sku&top_table=info"'),
+            'fast_list' => array('库存设置', '"info_sku&project=goods&goods_id={goods_id}&other=store&other_id={store_id}&page_type=1"'),
         ),
     ),
 
@@ -281,6 +390,24 @@ $config = array
                 'total_num' => array('yes', '-='),
             ),
         ),
+
+        'getDataByDate' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'store_id' => 'yes',
+                'status' => 'yes',
+                'start' => array('yes-cdate', '>='),
+                'end' => array('yes-cdate', '<='),
+                'sku_id' => array('yes', 'in'),
+                'goods_id' => array('yes', 'in'),
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('id' => 'desc'),
+            'col' => '*',
+        ),
     ),
 );
 

+ 18 - 3
app/store/database/info.php

@@ -336,10 +336,12 @@ return array
     (
         'list_button' => array
         (
-            'location' => array('商品设置', Dever::url('lib/set.home', 'store')),
+            //'location' => array('商品设置', Dever::url('lib/set.home', 'store')),
             //'add' => array('设置库存清单', '"info&where_id={id}&col=goods&oper_save_jump=info&oper_table=info&oper_parent=info"'),
 
-            'list3' => array('商品列表', '"goods&search_option_store_id={id}&oper_table=info"'),
+            //'list3' => array('商品列表', '"goods&search_option_store_id={id}&oper_table=info"'),
+
+            'list3' => array('商品库存设置', '"goods_sku&search_option_store_id={id}&oper_table=info&search_type=1"'),
 
             'list1' => array('账号管理', '"member&search_option_store_id={id}&oper_table=info"'),
 
@@ -349,6 +351,19 @@ return array
 
     'request' => array
     (
-        
+        'like' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'name' => array('yes', 'like'),
+                'id' => 'yes',
+                'status' => 1,
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('reorder' => 'desc', 'id' => 'desc'),
+            'col' => '*|id',
+        ),
     ),
 );

+ 22 - 8
app/store/lib/Manage.php

@@ -144,20 +144,34 @@ class Manage
         $update = array();
         $add_num = Dever::param('add_num', $data);
         if ($add_num) {
+            $goods_sku = Dever::db('store/goods_sku')->one($id);
             $state = Dever::db('store/goods_sku')->updateTotal(array('where_id' => $id, 'total_num' => $add_num));
             if ($state) {
-                $state = Dever::db('store/goods_sku')->update(array('where_id' => $id, 'add_num' => 0));
-                $info = Dever::db('store/goods_sku')->one($id);
-                $goods = Dever::db('store/goods')->one(array('goods_id' => $info['goods_id'], 'store_id' => $info['store_id']));
+                $state = Dever::db('store/goods_sku')->update(array('where_id' => $id, 'add_num' => 0, 'operdate' => time()));
+                $goods = Dever::db('store/goods')->one(array('goods_id' => $goods_sku['goods_id'], 'store_id' => $goods_sku['store_id']));
                 if ($goods) {
-                    Dever::db('store/goods')->update(array('where_id' => $goods['id'], 'total_num' => $info['total_num'], 'add_num' => 0));
+                    Dever::db('store/goods')->update(array('where_id' => $goods['id'], 'total_num' => $goods_sku['total_num'], 'add_num' => 0));
                 }
 
-                if ($add_num < 0) {
-                    # 记录出库日志
-                } else {
-                    # 记录入库日志
+                $log['store_id'] = $goods_sku['store_id'];
+                $log['goods_id'] = $goods_sku['goods_id'];
+                $log['sku_id'] = $goods_sku['sku_id'];
+                $log['sell_num'] = $goods_sku['sell_num'];
+                $log['total_num'] = $goods_sku['total_num'];
+                $log['num'] = $add_num;
+                $log['after_total_num'] = $goods_sku['total_num'] + $add_num;
+                $log['cur_num'] = $log['total_num'] - $goods_sku['sell_num'];
+                $log['after_cur_num'] = $log['after_total_num'] - $goods_sku['sell_num'];
+                if ($log['cur_num'] < 0) {
+                    $log['cur_num'] = 0;
                 }
+                if ($log['after_cur_num'] < 0) {
+                    $log['after_cur_num'] = 0;
+                }
+                
+                $log['online_num'] = Dever::load("shop/lib/manage.getGoodsTotal", 2, $goods_sku['store_id'], $goods_sku['goods_id'], $goods_sku['sku_id']);
+
+                Dever::db('store/goods_log')->insert($log);
             }
         }
     }

+ 3 - 0
config/base.php

@@ -102,6 +102,9 @@ $config['base'] = array
         */
     ),
 
+    # 用户中心的用户下单量统计接口
+    'passport_stat_order' => 'shop/lib/cron.order_user',
+
     # 日志系统
     'log' => array
     (

+ 2 - 0
main/template/pc/home.php

@@ -1,4 +1,6 @@
 <?php
+
+echo Dever::maketime('2022-01-13 15:45:09');die;
 /*
 |--------------------------------------------------------------------------
 | home

+ 1 - 0
service/agent/assets/pc/html/setGoods.html

@@ -184,6 +184,7 @@
                 goods[key].price = parseFloat(goods[key].price);
                 goods[key].price_type = parseInt(goods[key].price_type);
                 goods[key].total = parseFloat(goods[key].total);
+                goods[key].total = goods[key].total > 0 ? goods[key].total : 1;
                 goods[key].num = 0;
                 goods[key].del = 1;
                 create(node);

+ 264 - 0
service/agent/assets/pc/html/setOrderGoods.html

@@ -0,0 +1,264 @@
+<!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" 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:'id'}">商品编码</th>
+                                <th lay-data="{field:'name'}">商品名称</th>
+                                <th lay-data="{field:'price', edit: 'text'}">销售价(元)</th>
+                                <th lay-data="{field:'number', edit: 'text'}">更改数量</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;
+        form.render(); 
+    });
+
+    $(function()
+    {
+        $("#settlement").click(function(){
+            var url = '<{$submit}>';
+            var role_id = '<{$role_id}>';
+            var order_id = '<{$order_id}>';
+
+            layui.layer.confirm('确定进行此项设置吗?', function() {
+                var goods_string = JSON.stringify(goods);
+
+                var data = {};
+                data = {role_id:role_id, order_id:order_id, goods:goods_string};
+                $.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);
+                    }
+                });
+            });
+        })
+
+        $("#goods").on("keyup", ".goods_num", function() {
+            var num = parseInt($(this).val());
+            if (!num || num <= 0) {
+                num = 0;
+                $(this).val(0);
+            }
+            var id = $(this).parent().attr('value');
+            goods[id].total = num;
+            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() 
+    {
+        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].price = parseFloat(goods[key].price);
+                goods[key].price_type = parseInt(goods[key].price_type);
+                goods[key].total = parseFloat(goods[key].total);
+                goods[key].total = goods[key].total > 0 ? goods[key].total : 1;
+                goods[key].num = 0;
+                goods[key].del = 1;
+                create(node);
+                setTotal();
+            } else if(node.price_type < 4) {
+                add(key);
+            }
+        }
+    }
+
+    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_id">'+node.id+'</td>';
+            addtr += '<td class="goods_name">'+node.name+'</td>';     
+            addtr += '<td class="goods_price">'+node.price+'</td>';     
+            addtr += '<td><div class="jiajian" value='+node.id+'><span class="jian" onclick="dec(\''+node.id+'\')">-</span><input type="text" value="'+node.total+'" 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 {
+                addtr += '<td></td>';
+            }
+                                  
+            addtr += '</tr>';
+            $("#goods").append(addtr);
+        }
+    }
+
+    function add(id)
+    {
+        goods[id].total += 1;
+        get(id).find('.goods_num').val(goods[id].total);
+        setTotal();
+    }
+    
+    function dec(id)
+    {
+        goods[id].total -= 1;
+        if (goods[id].total < 1) {
+            goods[id].total = 0;
+        }
+
+        get(id).find('.goods_num').val(goods[id].total);
+        setTotal();
+    }
+
+    function del(id)
+    {
+        if (confirm('确定删除吗?')) {
+            goods[id].del = 2;
+            get(id).remove();
+            setTotal();
+        }
+    }
+
+    function setTotal()
+    {
+        var cash = 0;
+        var num = 0;
+        var total = 0;
+        for (var i in goods) {
+            //num += goods[i].num;
+            total += goods[i].total;
+        }
+        //$(".totalQuantity").html(num);
+        $(".totalNum").html(total);
+    }
+
+    function setShop()
+    {
+        var give = $('#give').val();
+        if (!give) {
+            layui.layer.alert('请选择赠送类型');
+            return;
+        }
+        layui.layer.confirm('确定切换赠送类型吗?切换后现在选择的商品都将清空', function() {
+            location.href = '<{$host}>&give=' + give;
+        });
+    }
+</script>
+</body>
+</html>

+ 43 - 7
service/agent/database/order_process.php

@@ -1,10 +1,17 @@
 <?php
 
+$audit = array
+(
+    1 => '审核通过',
+    2 => '拒绝',
+);
+
 $status = array
 (
     1 => '初审',
     2 => '终审',
     3 => '权益发放',
+    4 => '已完成',
 );
 
 $type = array
@@ -16,6 +23,14 @@ $type = array
     5 => '代理合同已生成',
 );
 
+$status_value = Dever::input('status', 1);
+$audit_desc = '';
+if ($status_value == 1) {
+    $audit_desc = '需确认代理商信息无误则通过审核。审核通过后,需确认支付金额是否拆分。';
+} elseif ($status_value == 2) {
+    $audit_desc = '现行确认是否已到账,未确认到账时,无法发放权益等操作。';
+}
+
 return array
 (
     # 表名
@@ -24,6 +39,11 @@ return array
     'lang' => '订单审核进度表',
     'menu' => false,
     'status' => $status,
+    'end' => array
+    (
+        'insert' => 'agent/lib/manage.orderUpdate',
+        'update' => 'agent/lib/manage.orderUpdate',
+    ),
     # 数据结构
     'struct' => array
     (
@@ -47,6 +67,8 @@ return array
             'default'   => '',
             'desc'      => '订单表id',
             'match'     => 'is_numeric',
+            'update'    => 'hidden',
+            'value'     => Dever::input('order_id', 1),
         ),
 
         'status'        => array
@@ -56,20 +78,34 @@ return array
             'default'   => '1',
             'desc'      => '状态',
             'match'     => 'is_numeric',
-            'update'  	=> 'radio',
+            'update'  	=> 'hidden',
             'option'    => $status,
             'search'    => 'select',
+            'value'     => $status_value,
             'control'	=> 'status',
         ),
 
+        'audit'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '审核状态-' . $audit_desc,
+            'default'   => '1',
+            'desc'      => '审核状态',
+            'match'     => 'is_numeric',
+            'update'    => 'radio',
+            'option'    => $audit,
+            'search'    => 'select',
+            'control'   => 'status',
+        ),
+
         'desc'      => array
         (
             'type'      => 'varchar-400',
             'name'      => '备注',
             'default'   => '',
             'desc'      => '备注',
-            'match'     => 'is_string',
-            'update'    => 'text',
+            'match'     => 'option',
+            'update'    => 'textarea',
             'search'    => 'fulltext',
             'list'      => true,
             'show'		=> 'type=1,2',
@@ -77,11 +113,11 @@ return array
 
         'type'        => array
         (
-            'type'      => 'int-11',
+            'type'      => 'varchar-400',
             'name'      => '权益发放情况',
             'default'   => '1',
             'desc'      => '权益发放情况',
-            'match'     => 'is_numeric',
+            'match'     => 'option',
             'update'  	=> 'radio',
             'option'    => $type,
             'search'    => 'select',
@@ -128,8 +164,8 @@ return array
                 'state' => 1,
             ),
             'type' => 'all',
-            'order' => array('status' => 'asc', 'cdate' => 'desc'),
-            'col' => '*',
+            'order' => array('status' => 'asc', 'cdate' => 'asc'),
+            'col' => '*|status',
         ),
     ),
 );

+ 23 - 0
service/agent/lib/Manage.php

@@ -0,0 +1,23 @@
+<?php
+
+namespace Agent\Lib;
+
+use Dever;
+
+class Manage
+{
+    public function orderUpdate($id, $name, $data)
+    {
+        Dever::config('base')->hook = true;
+        $audit = Dever::param('audit', $data);
+        $status = Dever::param('status', $data);
+        $order_id = Dever::param('order_id', $data);
+        if ($order_id && $status) {
+            if ($audit == 1) {
+                Dever::db('agent/order')->update(array('where_id' => $order_id, 'status' => $status+1));
+            } else {
+                Dever::db('agent/order')->update(array('where_id' => $order_id, 'status' => 5));
+            }
+        }
+    }
+}

+ 104 - 58
service/agent/lib/Order.php

@@ -253,8 +253,11 @@ class Order
         if (!$role) {
         	Dever::alert('代理类型不正确');
         }
+        if ($role['opset'] != 1) {
+            Dever::alert('代理类型不正确');
+        }
         $data['area'] = Dever::input('area');
-        if (!$data['area']) {
+        if ($role['type'] == 2 && !$data['area']) {
             Dever::alert('代理区域不能为空');
         }
 
@@ -294,7 +297,9 @@ class Order
         $info = Dever::db('agent/order')->one($id);
 
         $process = Dever::db('agent/order_process')->getData(array('order_id' => $id));
+        $process_status = Dever::db('agent/order_process')->config['status'];
 
+        //print_r($process);die;
         $role = Dever::db('setting/role')->one($info['role']);
         $area = Dever::load("area/api.string", $info['area']);
 
@@ -320,6 +325,15 @@ class Order
 
         $result = array();
 
+        $status_value = array();
+
+        if ($process) {
+            foreach ($process as $k => $v) {
+                $v['cdate'] = date('Y-m-d H:i', $v['cdate']);
+                $status_value[] = array($process_status[$v['status']], $v['cdate']);
+            }
+        }
+
         $result[$info['order_num']] = array
         (
             'type' => 'info',
@@ -330,6 +344,7 @@ class Order
                     array('订单状态', $status),
                     array('申请日期', $cdate),
                 ),
+                $status_value,
             )
         );
 
@@ -396,77 +411,108 @@ class Order
                 ),
             ),
         );
-        
-        if ($parent_member) {
-            # 这里要获取上级信息
-            $result['分润信息'] = array
+
+        $button = array();
+
+        if ($info['status'] == 1) {
+            $button[] = array
+            (
+                'type' => 'edit',
+                'link' => Dever::url('project/database/update?project=agent&table=order_process&order_id='.$info['id'].'&status=1&col=order_id,status,audit,desc', 'manage'),
+                'name' => '业务初审',
+            );
+        } elseif ($info['status'] == 2) {
+            $button[] = array
             (
-                'type' => 'info',
-                'content' => array
+                'type' => 'edit',
+                'link' => Dever::url('project/database/update?project=agent&table=order_process&order_id='.$info['id'].'&status=2&col=order_id,status,audit,desc', 'manage'),
+                'name' => '财务终审',
+            );
+        }
+        
+        if ($info['status'] == 3 || $info['status'] == 4) {
+            if ($parent_member) {
+                # 这里要获取上级信息
+                $result['分润信息'] = array
                 (
-                    array
+                    'type' => 'info',
+                    'content' => array
                     (
-                        array('支付方式', $config['pay_type'][$info['pay_type']]),
-                        array('支付金额', '¥' . $info['price'] . '元'),
-                        array('系统查询', $config['pay_status'][$info['pay_status']]),
+                        array
+                        (
+                            array('支付方式', $config['pay_type'][$info['pay_type']]),
+                            array('支付金额', '¥' . $info['price'] . '元'),
+                            array('系统查询', $config['pay_status'][$info['pay_status']]),
+                        ),
+
+                        array
+                        (
+                            array('付款备注', $info['desc']),
+                            array('支付凭证', $pay_pic),
+                        ),
                     ),
+                );
+            }
 
-                    array
-                    (
-                        array('付款备注', $info['desc']),
-                        array('支付凭证', $pay_pic),
-                    ),
-                ),
-            );
-        }
-
-        //$goods = Dever::db('setting/role_goods')->select(array('role_id' => $info['role'], 'give' => $info['order_type']));
+            if (isset($process[3]) && $process[3]) {
+                $process[3]['type'] = explode(',', $process[3]['type']);
 
-        $goods = Dever::db('agent/order_goods')->select(array('order_id' => $info['id']));
-        if ($goods) {
-            foreach ($goods as $k => $v) {
-                $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v['goods_id'], $v['sku_id']);
-                if (isset($goods_info['sku'])) {
-                    $sku = $goods_info['sku']['string'];
+                if (in_array(2, $process[3]['type'])) {
+                    $process_status = 1;
+                    $process_name = '(已发放权益)';
+                    $process_button = array();
+                    $goods = Dever::db('agent/order_goods')->select(array('order_id' => $info['id']));
                 } else {
-                    $sku = '无';
+                    $process_status = 2;
+                    $process_name = '(未发放权益)';
+                    
+                    $process_button = array(
+                        'type' => 'link',
+                        'link' => Dever::url('lib/order_set.home?order_id='.$info['id'].'&role_id=' . $info['role'] . '&give=' . $info['order_type'], 'agent'),
+                        'name' => '发放权益'
+                    );
+                    $goods = Dever::db('setting/role_goods')->select(array('role_id' => $info['role'], 'give' => $info['order_type']));
+                }
+                
+                if ($goods) {
+                    foreach ($goods as $k => $v) {
+                        $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v['goods_id'], $v['sku_id']);
+                        if (isset($goods_info['sku'])) {
+                            $sku = $goods_info['sku']['string'];
+                        } else {
+                            $sku = '无';
+                        }
+                        $del = Dever::url('order_tui?order_goods_id=' . $v['id'] . '&order_id=' . $info['id'] . '&type=13', 'factory');
+
+                        $status = '<a href="javascript:;" onclick="audit('.$v['id'].', 2, \''.$del.'\')" class="layui-btn">删除</a>';
+
+                        $d = array
+                        (
+                            'pic' => $goods_info['cover'],
+                            'name' => $goods_info['name'],
+                            'sku' => $sku,
+                            'price' => $goods_info['price'],
+                            'num' => $v['num'],
+                            //'status' => $status,
+                        );
+                        $body[] = $d;
+                    }
+
+                    $result['权益信息' . $process_name] = array
+                    (
+                        'type' => 'list',
+                        'head' => array('name' => '商品权益:', 'btn' => array($process_button)),
+                        'content' => $body,
+                    );
                 }
-                $del = Dever::url('order_tui?order_goods_id=' . $v['id'] . '&order_id=' . $info['id'] . '&type=13', 'factory');
-
-                $status = '<a href="javascript:;" onclick="audit('.$tk['id'].', 2, \''.$url.'\')" class="layui-btn">删除</a>';
-
-                $d = array
-                (
-                    'pic' => $goods_info['cover'],
-                    'name' => $goods_info['name'],
-                    'sku' => $sku,
-                    'price' => $goods_info['price'],
-                    'num' => $v['num'],
-                    'status' => $status,
-                );
-                $body[] = $d;
             }
-
-            $result['权益信息'] = array
-            (
-                'type' => 'list',
-                'content' => $body,
-            );
-        } else {
-            $result['权益信息'] = array
-            (
-                'type' => 'button',
-                'content' => array
-                (
-                    array('发放权益', $config['pay_type'][$info['pay_type']]),
-                ),
-            );
         }
         
+        
         $head = array
         (
             'name' => '基本信息',
-            'btn' => array(),
+            'btn' => $button,
         );
         $html = Dever::show($head, $result);
 

+ 105 - 0
service/agent/lib/Order_set.php

@@ -0,0 +1,105 @@
+<?php
+
+namespace Agent\Lib;
+
+use Dever;
+
+# 批量设置商品
+class Order_set
+{
+    public function __construct()
+    {
+        Dever::load('manage/auth.init');
+    }
+
+    # 获取商品列表
+    public function goods_api()
+    {
+        $id = Dever::input('role_id', 1);
+        return Dever::outDiy(Dever::load('goods/lib/set.getGoodsList', $id, 'role_id', 'setting/role_goods'));
+    }
+
+    # 设置商品
+    public function home_api()
+    {
+        $data = array();
+        $data['order_id'] = Dever::input('order_id');
+        $data['role_id'] = Dever::input('role_id', 1);
+        $data['give'] = Dever::input('give', 1);
+        $data['host'] = Dever::url('lib/order_set.home?id=' . $data['role_id'], 'agent');
+        $data['url'] = Dever::url('lib/order_set.goods?id=' . $data['role_id'] . '&give=' . $data['give'], 'agent');
+        $data['search'] = Dever::db('setting/role_goods')->config['set']['give'];
+        $data['submit'] = Dever::url('lib/order_set.action_cmmmit?json=1', 'agent');
+
+        return Dever::render('setOrderGoods', $data);
+    }
+
+    # 设置生产能力
+    public function action_cmmmit_api()
+    {
+        $goods = Dever::input('goods');
+        if (!$goods) {
+            Dever::alert('请传入商品');
+        }
+        $goods = Dever::json_decode($goods);
+        $order_id = Dever::input('order_id');
+
+        $where['option_order_id'] = $order_id;
+        $where['set_state'] = 2;
+        Dever::db('agent/order_goods')->updates($where);
+
+        foreach ($goods as $k => $v) {
+            $temp = explode('-', $k);
+            $goods_id = $temp[0];
+            if (isset($temp[1])) {
+                $sku_id = $temp[1];
+            } else {
+                $sku_id = -1;
+            }
+            if ($v['total'] <= 0) {
+                continue;
+            }
+            $w = array();
+            $w['goods_id'] = $goods_id;
+            $w['sku_id'] = $sku_id;
+            $w['order_id'] = $order_id;
+            if (isset($v['type']) && $v['type']) {
+                $w['type'] = $v['type'];
+            }
+            
+            $info = Dever::db('agent/order_goods')->one($w);
+            if ($v['del'] == 2) {
+                if ($info) {
+                    Dever::db('agent/order_goods')->update(array('where_id' => $info['id'], 'state' => 2));
+                }
+            } else {
+                $w['num'] = $v['total'];
+                
+                if (!$info) {
+                    Dever::db('agent/order_goods')->insert($w);
+                } else {
+                    $w['where_id'] = $info['id'];
+                    $w['state'] = 1;
+                    Dever::db('agent/order_goods')->update($w);
+                }
+
+                $wp = array();
+                $wp['order_id'] = $order_id;
+                $wp['status'] = 3;
+                $process = Dever::db('agent/order_goods')->find($wp);
+                if ($process) {
+                    $process['type'] = explode(',', $process['type']);
+                    $wp['audit'] = 1;
+                    $wp['type'] = '1,2';
+                    Dever::db('agent/order_goods')->insert($wp);
+                } else {
+                    $wp['audit'] = 1;
+                    $wp['type'] = '1,2';
+                    Dever::db('agent/order_goods')->insert($wp);
+                }
+            }
+        }
+
+        return 'reload';
+    }
+}