dever 3 years ago
parent
commit
9411e6fe73

+ 6 - 3
app/factory/assets/pc/html/cashier.html

@@ -208,7 +208,10 @@
 				data = {store_id:store_id, factory_id:factory_id, goods:goods_string, info:info};
 				$.getJSON(url, data, function(t) {
 					if (t.status == 1) {
-						layui.layer.alert(t.data);
+						layui.layer.alert('订货下单成功', function(index){
+						  location.href = t.data;
+						  layer.close(index);
+						});
 					} else {
 						layui.layer.alert(t.msg);
 					}
@@ -337,10 +340,10 @@
 		var num = 0;
 		for (var i in goods) {
 			num += goods[i].num;
-			cash += goods[i].price;
+			cash += goods[i].price * goods[i].num;
 		}
 		$(".totalQuantity").html(num);
-		$(".totalMoney").html(cash*num); 
+		$(".totalMoney").html(cash); 
 	}
 
 	function setFactory()

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

@@ -367,7 +367,7 @@ return array
 
             'list1' => array('账号管理', '"member&search_option_factory_id={id}&oper_table=info"'),
             
-            'list2' => array('订货单', '"order&search_option_factory_id={id}&oper_table=info"'),
+            //'list2' => array('订货单', '"order&search_option_factory_id={id}&oper_table=info"'),
         ),
     ),
 

+ 0 - 169
app/factory/database/order.php

@@ -1,169 +0,0 @@
-<?php
-$status = array
-(
-    1 => '待支付',
-    2 => '待生产发货',
-    3 => '已发货',
-    4 => '已到货',
-    5 => '已取消',
-    6 => '缺货与报损',
-);
-
-$type = array
-(
-    1 => '仓库',
-    2 => '门店',
-);
-
-return array
-(
-    # 表名
-    'name' => 'order',
-    # 显示给用户看的名称
-    'lang' => '工厂订货单',
-    'order' => 99,
-    'status' => $status,
-    # 数据结构
-    'struct' => array
-    (
-    
-        'id'        => array
-        (
-            'type'      => 'int-11',
-            'name'      => 'ID',
-            'default'   => '',
-            'desc'      => '',
-            'match'     => 'is_numeric',
-            'search'    => 'order',
-            //'list'      => true,
-        ), 
-
-        'factory_id'      => array
-        (
-            'type'      => 'int-11',
-            'name'      => '所属工厂',
-            'default'   => '',
-            'desc'      => '所属工厂',
-            'match'     => 'is_numeric',
-            'update'    => 'hidden',
-            'value'     => Dever::input('search_option_factory_id'),
-            'list'      => 'Dever::load("factory/info-find#name", {factory_id})',
-        ),
-
-        'name'      => array
-        (
-            'type'      => 'varchar-800',
-            'name'      => '订单名称',
-            'default'   => '',
-            'desc'      => '订单名称',
-            'match'     => 'is_string',
-            'update'    => 'text',
-        ),
-
-        'order_num'      => array
-        (
-            'type'      => 'varchar-100',
-            'name'      => '订单编号',
-            'default'   => '',
-            'desc'      => '订单编号',
-            'match'     => 'is_string',
-            'update'    => 'text',
-            'search'    => 'fulltext',
-            'list'      => true,
-        ),
-
-        'type'      => array
-        (
-            'type'      => 'int-11',
-            'name'      => '采购来源',
-            'default'   => '',
-            'desc'      => '采购来源',
-            'match'     => 'is_numeric',
-        ),
-
-        'type_id'      => array
-        (
-            'type'      => 'int-11',
-            'name'      => '来源id',
-            'default'   => '',
-            'desc'      => '来源id',
-            'match'     => 'is_numeric',
-        ),
-
-        'price'      => array
-        (
-            'type'      => 'varchar-50',
-            'name'      => '购买价格',
-            'default'   => '',
-            'desc'      => '购买价格',
-            'match'     => 'option',
-            'update'    => 'text',
-            'list'        => true,
-        ),
-
-        'num'        => array
-        (
-            'type'      => 'int-11',
-            'name'      => '购买数量',
-            'default'   => '',
-            'desc'      => '购买数量',
-            'match'     => 'is_numeric',
-            'search'    => 'select',
-            'list'        => true,
-        ),
-
-        'info'      => array
-        (
-            'type'      => 'varchar-300',
-            'name'      => '订单备注',
-            'default'   => '',
-            'desc'      => '订单备注',
-            'match'     => 'option',
-            'update'    => 'textarea',
-        ),
-
-        '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})',
-            //'list'      => 'Dever::load("service/lib/manage.showOrderTime", "{id}")',
-        ),
-    ),
-
-    'manage' => array
-    (
-        'delete' => false,
-        'edit' => false,
-        'insert' => false,
-
-        'button' => array
-        (
-            //'导出订单' => array('location', 'user/lib/manage.out'),
-        ),
-
-        'list_button' => array(
-            //'edit' => array('退款', 'status,tk_time,tk_pic,tk_desc,tk_admin', '{status} == 2'),
-            //'delete' => array('删除', '', '{status} == 1'),
-        ),
-    ),
-
-    'request' => array
-    (
-        
-    ),
-);

+ 6 - 0
app/factory/lib/Manage.php

@@ -6,6 +6,12 @@ use Dever;
 
 class Manage
 {
+    # 导出订单
+    public function out_api()
+    {
+        print_r(Dever::input());die;
+    }
+
     /**
      * 更新信息
      *

+ 18 - 92
app/factory/lib/Order.php

@@ -6,87 +6,6 @@ use Dever;
 
 class Order
 {
-	# 单个商品下单
-	public function pay($shop_order_id, $shop, $factory_id, $price, $num, $goods_id, $sku_id)
-	{
-		# 先更新销量
-		$state = $this->updateSell($factory_id, $goods_id, $sku_id, $num);
-
-		if (!$state) {
-			return false;
-		}
-
-		$where['order_num'] = $shop_order_id;
-		$where['shop_id'] = $shop['id'];
-		$where['type'] = 2;
-		$where['type_id'] = $factory_id;
-		$info = Dever::db('shop/buy_order')->find($where);
-
-		if (!$info) {
-			$data = $where;
-			$data['name'] = $shop_order_id;
-			$data['mobile'] = $shop['mobile'];
-			$data['area'] = $shop['area'];
-			$data['province'] = $shop['province'];
-			$data['city'] = $shop['city'];
-			$data['county'] = $shop['county'];
-			$data['town'] = $shop['town'];
-			$data['operdate'] = time();
-			$data['status'] = 3;
-			$data['price'] = $price;
-			$data['num'] = $num;
-			$id = $state = Dever::db('shop/buy_order')->insert($data);
-		} else {
-			$id = $info['id'];
-
-			$data['where_id'] = $id;
-			$data['price'] = $info['price'] + $price;
-			$data['num'] = $info['num'] + $num;
-			$state = Dever::db('shop/buy_order')->update($data);
-		}
-
-		if ($state && $id > 0) {
-			$goods_info = Dever::db('shop/buy_order_goods')->find(array('order_id' => $id));
-			if (!$goods_info) {
-				$goods['order_id'] = $id;
-				$goods['shop_id'] = $shop['id'];
-				$goods['goods_id'] = $goods_id;
-				$goods['sku_id'] = $sku_id;
-				$goods['price'] = $price;
-				$goods['num'] = $num;
-				Dever::db('shop/buy_order_goods')->insert($goods);
-			}
-
-			return $id;
-		}
-
-		return false;
-	}
-
-	# 增加销量
-    public function updateSell($factory_id, $goods_id, $sku_id, $num)
-    {
-        $up = array();
-        $up['where_factory_id'] = $factory_id;
-        $up['where_goods_id'] = $goods_id;
-        $up['sell_num'] = $num;
-        $state = Dever::db('factory/goods')->incSell($up);
-
-        if ($state) {
-        	if ($sku_id > 0) {
-	            
-	        } else {
-	            $sku_id = -1;
-	        }
-	        $upSku = $up;
-	        $upSku['where_sku_id'] = $sku_id;
-	        $state = Dever::db('factory/goods_sku')->incSell($upSku);
-        }
-
-        return $state;
-    }
-
-
     # 得到商品和总价
     private function goods()
     {
@@ -99,6 +18,7 @@ class Order
         $this->data['price'] = 0;
         $this->data['num'] = 0;
         $this->data['name'] = array();
+        $factory_id = Dever::input('factory_id');
         # 计算总价格
         foreach ($goods as $k => $v) {
         	if (strstr($v['id'], '-')) {
@@ -109,61 +29,67 @@ class Order
         		$s = -1;
         	}
             $n = $v['num'];
+            $goods_sku = Dever::db('factory/goods_sku')->find(array('factory_id' => $factory_id, 'goods_id' => $v['id'], 'sku_id' => $s));
+
             $this->data['list'][$k] = Dever::load('goods/lib/info')->getPayInfo($v['id'], $s, $n);
             $this->data['list'][$k]['num'] = $n;
 
             $this->data['list'][$k]['buy_num'] = $n;
             $this->data['num'] += $n;
-            $this->data['price'] += $this->data['list'][$k]['price'] * $n;
+            if ($goods_sku) {
+                $price = $goods_sku['p_price'];
+            } else {
+                $price = $this->data['list'][$k]['price'];
+            }
+            $this->data['price'] += $price * $n;
             $this->data['name'][] = $this->data['list'][$k]['name'];
         }
 
         $this->data['name'] = implode(',', $this->data['name']);
     }
 
-    # 出库下单
+    # 下单
     public function action_commit_api()
     {
-    	Dever::alert('下单失败');
         $info = Dever::input('info');
 
         $this->goods();
         
-        $order_data['factory_id'] = Dever::input('factory_id');
+        $order_data['type'] = 2;
         $order_data['type_id'] = Dever::input('store_id');
-        $order_data['type'] = 1;
+        $order_data['source_id'] = Dever::input('factory_id');
+        $order_data['source_type'] = 3;
         $order_data['name'] = $this->data['name'];
         $order_data['num'] = $this->data['num'];
         $order_data['info'] = $info;
         $order_data['price'] = $this->data['price'];
-        $order_data['status'] = 2;
+        $order_data['status'] = 3;
 
         $order_data['order_num'] = $this->getOrderId();
-        $id = Dever::db('factory/order')->insert($order_data);
+        $id = Dever::db('shop/buy_order')->insert($order_data);
 
         if (!$id) {
             Dever::alert('下单失败');
         }
 
         foreach($this->data['list'] as $k => $v) {
-        	$data['factory_id'] = $order_data['factory_id'];
             $data['order_id'] = $id;
             $data['goods_id'] = $v['id'];
             $data['sku_id'] = $v['sku_id'];
             $data['price'] = $v['price'] * $v['buy_num'];
             $data['num'] = $v['buy_num'];
 
-            $state = Dever::db('factory/order_goods')->insert($data);
+            $state = Dever::db('shop/buy_order_goods')->insert($data);
         }
 
-        return '订货下单成功';
+        return Dever::url('project/database/list&project=shop&&table=buy_order&menu=shop&menu_id=77&search_option_state=1&search_option_type=2', 'manage');
     }
 
     # 生成订单号
     public function getOrderId()
     {
         $where['order_num'] = Dever::order('F');
-        $state = Dever::db('factory/order')->one($where);
+        $state = Dever::db('shop/buy_order')->one($where);
         if (!$state) {
             return $where['order_num'];
         } else {

+ 254 - 84
app/mshop/lib/Buy.php

@@ -8,7 +8,7 @@ use Dever;
 
 class Buy
 {
-    # 1是用户自己看,2是门店看
+    # 1是门店,2是仓库,3是工厂,1,2,3是查看采购人的订单,11,12,13是查看供货商的订单
     public $type = 1;
     # 1是列表,2是详情
     public $view = 1;
@@ -36,7 +36,15 @@ class Buy
     public function where($id)
     {
         $where = array();
-        $where['shop_id'] = $id;
+        if ($this->type > 10) {
+            $type = $this->type - 10;
+            $where['source_type'] = $type;
+            $where['source_type_id'] = $id;
+        } else {
+            $where['type'] = $this->type;
+            $where['type_id'] = $id;
+        }
+        
         if (!$where) {
             Dever::alert('参数错误');
         }
@@ -49,10 +57,6 @@ class Buy
     {
         $result = array();
         $where = $this->where($id);
-        $mobile = Dever::input('mobile');
-        if ($mobile) {
-            $where['mobile'] = $mobile;
-        }
         $status = Dever::input('status');
         if ($status) {
             $where['status'] = $status;
@@ -138,12 +142,29 @@ class Buy
         $info['status_name'] = $this->config['status'][$info['status']];
 
         $info['goods'] = Dever::db('shop/buy_order_goods')->select(array('order_id' => $info['id']));
-        $info['shop'] = Dever::db('shop/info')->getOne($info['shop_id']);
-        $info['cdate'] = date('Y-m-d H:i', $info['cdate']);
+        if ($info['type'] == 1) {
+            $info['type_info'] = Dever::db('shop/info')->getOne($info['type_id']);
+        } elseif ($info['type'] == 2) {
+            $info['type_info'] = Dever::db('store/info')->find($info['type_id']);
+        } elseif ($info['type'] == 3) {
+            $info['type_info'] = Dever::db('factory/info')->find($info['type_id']);
+        }
 
+        if ($info['source_type'] == 1) {
+            $info['source_info'] = Dever::db('shop/info')->getOne($info['source_id']);
+        } elseif ($info['source_type'] == 2) {
+            $info['source_info'] = Dever::db('store/info')->find($info['source_id']);
+        } elseif ($info['source_type'] == 3) {
+            $info['source_info'] = Dever::db('factory/info')->find($info['source_id']);
+        }
+        
+        $info['cdate'] = date('Y-m-d H:i', $info['cdate']);
+        if ($info['operdate']) {
+            $info['operdate'] = date('Y-m-d H:i', $info['operdate']);
+        }
         $goods_status = Dever::db('shop/buy_order_goods')->config['status'];
         $goods_process = Dever::db('shop/buy_order_refund')->config['process'];
-        if ($view) {
+        if ($view || $this->view == 2) {
             foreach ($info['goods'] as $k => $v) {
                 $info['goods'][$k]['info'] = Dever::load('goods/lib/info')->getPayInfo($v['goods_id'], $v['sku_id']);
                 $info['goods'][$k]['status_name'] = $goods_status[$v['status']];
@@ -162,42 +183,36 @@ class Buy
             $info['refund_cash'] = 0;
         }
 
-        if ($info['fdate']) {
-            $info['fdate'] = date('Y-m-d H:i', $info['fdate']);
-        }
-        if ($info['qfdate']) {
-            $info['qfdate'] = date('Y-m-d H:i', $info['qfdate']);
-        }
-        if ($info['operdate']) {
-            $info['operdate'] = date('Y-m-d H:i', $info['operdate']);
-        }
-        if ($info['shdate']) {
-            $info['shdate'] = date('Y-m-d H:i', $info['shdate']);
+        # 配送信息
+        $info['ps_info'] = Dever::db('shop/buy_order_ps')->find(array('order_id' => $info['id']));
+        if ($info['ps_info']) {
+            $info['ps_info']['service_name'] = '商家自送';
+            $info['ps_info']['cdate'] = date('Y-m-d H:i', $info['ps_info']['cdate']);
+            if ($info['ps_info']['ydate']) {
+                $info['ps_info']['ydate'] = date('Y-m-d H:i', $info['ps_info']['ydate']);
+            }
+
+            $status = Dever::db('shop/buy_order_ps')->config['status'];
+            $info['ps_info']['status_name'] = $status[$info['ps_info']['status']];
+            
+            if ($info['ps_info']['service_id'] > 0) {
+                //暂时还没有
+            }
         }
 
         return $info;
     }
 
     # 发起支付
-    public function action($shop, $name, $num, $goods, $price, $info, $refer = '')
+    public function action($type, $type_id, $name, $num, $goods, $price, $info, $refer = '')
     {
-        if (!$shop) {
-            Dever::alert('错误的门店信息');
-        }
-        
-        $order_data['shop_id'] = $shop['id'];
-        $order_data['mobile'] = $shop['mobile'];
+        $order_data['type'] = $type;
+        $order_data['type_id'] = $type_id;
         $order_data['name'] = $name;
         $order_data['num'] = $num;
         $order_data['info'] = $info;
         $order_data['price'] = $price;
 
-        $order_data['area'] = $shop['area'];
-        $order_data['province'] = $shop['province'];
-        $order_data['city'] = $shop['city'];
-        $order_data['county'] = $shop['county'];
-        $order_data['town'] = $shop['town'];
-
         $order_data['order_num'] = $this->getOrderId();
         $id = Dever::db('shop/buy_order')->insert($order_data);
 
@@ -206,7 +221,6 @@ class Buy
         }
 
         foreach($goods as $k => $v) {
-            $data['shop_id'] = $shop['id'];
             $data['order_id'] = $id;
             $data['goods_id'] = $v['id'];
             $data['sku_id'] = $v['sku_id'];
@@ -352,6 +366,20 @@ class Buy
         }
     }
 
+    # 添加配送信息
+    public function updatePs($order, $status = 1)
+    {
+        $where['order_id'] = $order['id'];
+        $data = Dever::db('shop/buy_order_ps')->find($where);
+
+        if ($data) {
+            $update['where_id'] = $data['id'];
+            $update['status'] = $status;
+            $update['ydate'] = time();
+            Dever::db('shop/buy_order_ps')->update($update);
+        }
+    }
+
     # 确认收货
     public function finish($id, $order_id)
     {
@@ -362,14 +390,15 @@ class Buy
             } else {
                 $status = 5;
             }
-            $state = Dever::db('shop/buy_order')->update(array('where_id' => $data['id'], 'status' => $status, 'qsdate' => time()));
+            $state = Dever::db('shop/buy_order')->update(array('where_id' => $data['id'], 'status' => $status));
             if ($state) {
+                $this->updatePs($data, 3);
                 # 增加库存
                 $where['order_id'] = $data['id'];
                 $where['status'] = 1;
-                $data = Dever::db('shop/buy_order_goods')->select($where);
-                if ($data) {
-                    Dever::load('shop/lib/goods')->oper(1, 1, $data);
+                $goods = Dever::db('shop/buy_order_goods')->select($where);
+                if ($goods) {
+                    Dever::load('shop/lib/goods')->oper($data, 1, 1, $goods);
                 }
             }
 
@@ -423,8 +452,6 @@ class Buy
 
         $info = Dever::db('shop/buy_order')->one($id);
 
-        $shop = Dever::db('shop/info')->find($info['shop_id']);
-
         $tk_status = Dever::db('shop/buy_order_refund')->config['status'];
         $tk_process = Dever::db('shop/buy_order_refund')->config['process'];
 
@@ -440,25 +467,43 @@ class Buy
 
         </tr>';
 
-        $html .= '<tr>
-          <td>门店信息</td>
-          <td>'.$this->table(false, array(array('门店名称:' . $shop['name'], '联系人:' . $shop['truename'], '联系电话:' . $shop['mobile']))).'</td>
+        if ($info['type'] == 1) {
+            $type_info = Dever::db('shop/info')->find($info['type_id']);
+            $html .= '<tr>
+              <td>门店信息</td>
+              <td>'.$this->table(false, array(array('门店名称:' . $type_info['name'], '联系人:' . $type_info['truename'], '联系电话:' . $type_info['mobile']))).'</td>
 
-        </tr>';
+            </tr>';
+        } elseif ($info['type'] == 2) {
+            $type_info = Dever::db('store/info')->find($info['type_id']);
+            $html .= '<tr>
+              <td>仓库信息</td>
+              <td>'.$this->table(false, array(array('仓库名称:' . $type_info['name'], '联系人:' . $type_info['truename'], '联系电话:' . $type_info['mobile']))).'</td>
+
+            </tr>';
+        } elseif ($info['type'] == 3) {
+            $type_info = Dever::db('store/info')->find($info['type_id']);
+            $html .= '<tr>
+              <td>工厂信息</td>
+              <td>'.$this->table(false, array(array('工厂名称:' . $type_info['name'], '联系人:' . $type_info['truename'], '联系电话:' . $type_info['mobile']))).'</td>
+
+            </tr>';
+        }
+        
 
-        if ($info['type_id'] > 0) {
-            if ($info['type'] == 1) {
+        if ($info['source_id'] > 0) {
+            if ($info['source_type'] == 2) {
                 # 仓库
-                $store = Dever::db('store/info')->find($info['type_id']);
+                $store = Dever::db('store/info')->find($info['source_id']);
 
                 $html .= '<tr>
                   <td>供应商信息</td>
                   <td>'.$this->table(false, array(array('仓库名称:' . $store['name'], '联系人:' . $store['truename'], '联系电话:' . $store['mobile']))).'</td>
 
                 </tr>';
-            } elseif ($info['type'] == 2) {
+            } elseif ($info['source_type'] == 3) {
                 # 工厂
-                $factory = Dever::db('factory/info')->find($info['type_id']);
+                $factory = Dever::db('factory/info')->find($info['source_id']);
 
                 $html .= '<tr>
                   <td>供应商信息</td>
@@ -467,32 +512,56 @@ class Buy
                 </tr>';
             }
         }
-            
+        
+        if ($info['info']) {
+            $html .= '<tr>
+              <td>订单备注</td>
+              <td>'.$this->table(false, array(array($info['info']))).'</td>
+
+            </tr>';
+        }
 
         $url = Dever::url('lib/buy.refund', 'mshop');
+        if (!$info['refund_cash']) {
+            $info['refund_cash'] = 0;
+        }
 
-        if ($tk && $tk['process'] == 1) {
-            $status = '申请' . $tk_status[$tk['status']];
-            $process = $tk_process[$tk['process']];
-            $process = '';
+        if ($info['refund_cash'] > 0) {
+            
+            if ($tk) {
+                $process = $tk_process[$tk['process']];
+                $process = '';
+
+                if ($tk['process'] == 1) {
+                    $status = '申请' . $tk_status[$tk['status']];
+                    $process .= '&nbsp;&nbsp;<a href="javascript:;" onclick="audit('.$tk['id'].', 2, \''.$url.'\')" class="layui-btn">通过</a><a href="javascript:;" onclick="audit('.$tk['id'].', 3, \''.$url.'\')" class="layui-btn layui-btn-danger">驳回</a>';
 
-            if ($tk['process'] == 1) {
-                $process .= '&nbsp;&nbsp;<a href="javascript:;" onclick="audit('.$tk['id'].', 2, \''.$url.'\')" class="layui-btn">通过</a><a href="javascript:;" onclick="audit('.$tk['id'].', 3, \''.$url.'\')" class="layui-btn layui-btn-danger">驳回</a>';
+                }
+                $desc = array();
+                $desc['原因'] = $tk['desc'];
+                if ($tk['pic']) {
+                    $desc['图片'] = '';
+                    $pic = explode(',', $tk['pic']);
+                    foreach ($pic as $k => $v) {
+                        $desc['图片'] .= '<a href="'.$v.'" target="_blank"><img src="'.$v.'" width="100"/></a>';
+                    }
+                }
+                $tk['desc'] = '<a href="javascript:layer.alert($(\'#desc_content\').html());">查看</a><span id="desc_content" style="display:none">'.Dever::table($desc).'</span>';
             }
+
             $html .= '<tr>
               <td>订单信息</td>
-              <td>'.$this->table(array('金额', '退款金额', '数量', '订单状态', '审核状态'), array(array($info['price'], $info['refund_cash'], $info['num'], $status, $process))).'</td>
+              <td>'.$this->table(array('金额', '数量', '订单状态', '退款金额', '退款原因', '退款审核'), array(array($info['price'], $info['num'], $status, $info['refund_cash'], $tk['desc'], $process))).'</td>
             </tr>';
+
         } else {
             $html .= '<tr>
               <td>订单信息</td>
-              <td>'.$this->table(array('金额', '退款金额', '数量', '订单状态'), array(array($info['price'], $info['refund_cash'], $info['num'], $status))).'</td>
+              <td>'.$this->table(array('金额', '数量', '订单状态'), array(array($info['price'], $info['num'], $status))).'</td>
             </tr>';
         }
         
 
-        # 增加仓库和工厂信息
-
         $html .= '</tbody></table>';
 
         $html .= '[商品清单]:';
@@ -508,16 +577,32 @@ class Buy
             $tk = Dever::db('shop/buy_order_refund')->find(array('order_id' => $info['id'], 'order_goods_id' => $v['id'], 'type' => 2));
             if ($tk && $tk['process'] == 1) {
                 $status = '申请' . $tk_status[$tk['status']];
-                //$status .= '&nbsp;&nbsp;[' . $tk_process[$tk['process']] . ']';
+
+                $desc = array();
+                $desc['原因'] = $tk['desc'];
+                if ($tk['pic']) {
+                    $desc['图片'] = '';
+                    $pic = explode(',', $tk['pic']);
+                    foreach ($pic as $k => $v) {
+                        $desc['图片'] .= '<a href="'.$v.'" target="_blank"><img src="'.$v.'" width="100"/></a>';
+                    }
+                }
+                $status .= '&nbsp;&nbsp;<a href="javascript:layer.alert($(\'#desc_content\').html());">查看原因</a><span id="desc_content" style="display:none">'.Dever::table($desc).'</span>';
 
                 if ($tk['process'] == 1) {
                     $status .= '&nbsp;&nbsp;<a href="javascript:;" onclick="audit('.$tk['id'].', 2, \''.$url.'\')" class="layui-btn">通过</a><a href="javascript:;" onclick="audit('.$tk['id'].', 3, \''.$url.'\')" class="layui-btn layui-btn-danger">驳回</a>';
                 }
             }
+
+            if (isset($goods_info['sku'])) {
+                $sku = $goods_info['sku']['string'];
+            } else {
+                $sku = '无';
+            }
             $body[$k] = array
             (
                 $goods_info['name'],
-                $v['price'],
+                $sku,
                 $v['price'],
                 $v['num'],
                 $status,
@@ -565,6 +650,7 @@ class Buy
     }
 
     # 发货
+    /*
     public function send_commit()
     {
         $order_id = Dever::input('order_id');
@@ -574,10 +660,14 @@ class Buy
             Dever::alert('当前订单状态无法发货');
         }
 
-        $state = Dever::db('shop/buy_order')->update(array('where_id' => $order['id'], 'status' => 4, 'fdate' => time()));
+        $state = Dever::db('shop/buy_order')->update(array('where_id' => $order['id'], 'status' => 4));
+
+        if ($state) {
+            $this->updatePs($order, 1);
+        }
 
         return 'reload';
-    }
+    }*/
 
     # 采购订单审核 拆单
     public function audit_commit()
@@ -589,9 +679,13 @@ class Buy
             Dever::alert('当前订单状态无法拆单');
         }
 
+        if ($order['type'] != 1) {
+            Dever::alert('这不是门店的订单');
+        }
+
         $goods = Dever::db('shop/buy_order_goods')->select(array('order_id' => $order_id));
 
-        $shop = Dever::db('shop/info')->find($order['shop_id']);
+        $shop = Dever::db('shop/info')->find($order['type_id']);
 
         # 获取门店分配的仓库和工厂
         $shop_store = Dever::db('shop/store')->select(array('shop_id' => $shop['id']));
@@ -624,25 +718,21 @@ class Buy
 
         array_multisort($distance, SORT_ASC, SORT_NUMERIC, $factory);
 
-        $num = 0;
+        $this->order_num = 0;
         foreach ($goods as $k => $v) {
             # 开始找仓库
-            $find = $this->store($order['order_num'] . '_' . $num, $shop, $store, $v);
+            $find = $this->store($order['id'], $order['order_num'] . '_' . $this->order_num, $shop, $store, $v);
             if (!$find[1]) {
                 # 仓库没有,找厂家
                 if ($factory) {
-                    $find = $this->factory($order['order_num'] . '_' . $num, $shop, $factory, $v);
+                    $find = $this->factory($order['id'], $order['order_num'] . '_' . $this->order_num, $shop, $factory, $v);
                 }
             }
-
-            if ($find[1]) {
-                $num++;
-            }
         }
 
-        if ($num > 0) {
-            if ($num == 1 && count($find[1]) == 1) {
-                Dever::db('shop/buy_order')->update(array('where_id' => $order['id'], 'status' => 3, 'type' => $find[0], 'type_id' => implode('', $find[1])));
+        if ($this->order_num > 0) {
+            if ($this->order_num == 1) {
+                Dever::db('shop/buy_order')->update(array('where_id' => $order['id'], 'status' => 3, 'source_type' => $find[0], 'source_id' => implode('', $find[1])));
 
                 Dever::db('shop/buy_order')->delete($find[2][0]);
                 Dever::db('shop/buy_order_goods')->delete(array('order_id' => $find[2][0]));
@@ -659,13 +749,13 @@ class Buy
         return 'ok';
     }
 
-    private function store($order_id, $shop, $store, $goods, $state = 2)
+    private function store($order_id, $order_num, $shop, $store, $goods, $state = 2)
     {
         $find = array();
         $type_id = array();
         $id = array();
         if (!$store) {
-            return array(1, $type_id, $id);
+            return array(2, $type_id, $id);
         }
         foreach ($store as $k => $v) {
             $where['store_id'] = $v['id'];
@@ -676,7 +766,7 @@ class Buy
             if ($sku) {
                 if ($goods['num'] <= $sku['total']) {
                     # 如果库存符合,直接下单即可,生成仓库订单
-                    $state = Dever::load('store/lib/order')->pay($order_id, $shop, $where['store_id'], $goods['price'], $goods['num'], $where['goods_id'], $where['sku_id']);
+                    $state = $this->createOrder($order_id, $order_num, 1, $shop['id'], 2, $where['store_id'], $goods['price'], $goods['num'], $where['goods_id'], $where['sku_id']);
                     if ($state) {
                         $type_id[] = $where['store_id'];
                         $id[] = $state;
@@ -686,7 +776,7 @@ class Buy
                     # 如果库存不够,从这个仓库扣下一部分,剩余的从另外仓库处理
                     $goods['num'] = $goods['num'] - $sku['total'];
                     # 生成仓库订单
-                    $state = Dever::load('store/lib/order')->pay($order_id, $shop, $where['store_id'], $goods['price'], $sku['total'], $where['goods_id'], $where['sku_id']);
+                    $state = $this->createOrder($order_id, $order_num, 1, $shop['id'], 2, $where['store_id'], $goods['price'], $sku['total'], $where['goods_id'], $where['sku_id']);
                     if (!$state) {
                         $goods['num'] = $goods['num'] + $sku['total'];
                     } else {
@@ -702,16 +792,16 @@ class Buy
             }
         }
 
-        return array(1, $type_id, $id);
+        return array(2, $type_id, $id);
     }
 
-    private function factory($order_id, $shop, $factory, $goods)
+    private function factory($order_id, $order_num, $shop, $factory, $goods)
     {
         $find = array();
         $type_id = array();
         $id = array();
         if (!$factory) {
-            return array(1, $type_id, $id);
+            return array(3, $type_id, $id);
         }
 
         foreach ($factory as $k => $v) {
@@ -721,7 +811,7 @@ class Buy
             $sku = Dever::db('factory/goods_sku')->select($where);
 
             if ($sku) {
-                $state = Dever::load('factory/lib/order')->pay($order_id, $shop, $where['factory_id'], $goods['price'], $goods['num'], $where['goods_id'], $where['sku_id']);
+                $state = $this->createOrder($order_id, $order_num, 1, $shop['id'], 3, $where['factory_id'], $goods['price'], $goods['num'], $where['goods_id'], $where['sku_id']);
                 if ($state) {
                     $type_id[] = $where['factory_id'];
                     $id[] = $state;
@@ -732,6 +822,86 @@ class Buy
             }
         }
 
-        return array(2, $type_id, $id);
+        return array(3, $type_id, $id);
+    }
+
+    # 生成拆单的订单
+    private function createOrder($order_id, $order_num, $type, $type_id, $source_type, $source_id, $price, $num, $goods_id, $sku_id)
+    {
+        $where['parent_order_id'] = $order_id;
+        $where['type'] = $type;
+        $where['type_id'] = $type_id;
+        $where['source_type'] = $source_type;
+        $where['source_id'] = $source_id;
+        $where['r'] = $goods_id;
+        $info = Dever::db('shop/buy_order')->find($where);
+
+        if (!$info) {
+            $this->order_num++;
+            $data = $where;
+            $data['name'] = $order_id;
+            $data['order_num'] = $order_num;
+            $data['operdate'] = time();
+            $data['status'] = 3;
+            $data['price'] = $price;
+            $data['num'] = $num;
+            $id = $state = Dever::db('shop/buy_order')->insert($data);
+        } else {
+            $id = $info['id'];
+
+            $data['where_id'] = $id;
+            $data['price'] = $info['price'] + $price;
+            $data['num'] = $info['num'] + $num;
+            $state = Dever::db('shop/buy_order')->update($data);
+        }
+
+        if ($state && $id > 0) {
+            $goods_info = Dever::db('shop/buy_order_goods')->find(array('order_id' => $id));
+            if (!$goods_info) {
+                $goods['order_id'] = $id;
+                $goods['goods_id'] = $goods_id;
+                $goods['sku_id'] = $sku_id;
+                $goods['price'] = $price;
+                $goods['num'] = $num;
+                Dever::db('shop/buy_order_goods')->insert($goods);
+            }
+
+            //$state = $this->updateSell($source_type, $source_id, $goods_id, $sku_id, $num);
+
+            return $id;
+        }
+
+        return false;
+    }
+
+    # 减少库存,增加销量
+    public function updateSell($source_type, $source_id, $goods_id, $sku_id, $num)
+    {
+        if ($source_type == 2) {
+            $data['store_id'] = $source_id;
+            $data['goods_id'] = $goods_id;
+            $data['sku_id'] = $sku_id;
+            $data['num'] = $num;
+            return Dever::load('store/lib/goods')->oper($source_id, 1, 2, array($data));
+        } else {
+            $up = array();
+            $up['where_factory_id'] = $source_id;
+            $up['where_goods_id'] = $goods_id;
+            $up['sell_num'] = $num;
+            $state = Dever::db('factory/goods')->incSell($up);
+
+            if ($state) {
+                if ($sku_id > 0) {
+                    
+                } else {
+                    $sku_id = -1;
+                }
+                $upSku = $up;
+                $upSku['where_sku_id'] = $sku_id;
+                $state = Dever::db('factory/goods_sku')->incSell($upSku);
+            }
+
+            return $state;
+        }
     }
 }

+ 10 - 16
app/mshop/src/Buy.php

@@ -29,7 +29,7 @@ class Buy extends Core
     # 采购订单列表
     public function getList()
     {
-        return Dever::load('mshop/lib/buy')->getList($this->shop_id);
+        return Dever::load('mshop/lib/buy')->set(1,1)->getList($this->shop_id);
     }
 
     # 查看订单详情
@@ -37,7 +37,7 @@ class Buy extends Core
     {
         $order_id = Dever::input('order_id');
 
-        return Dever::load('mshop/lib/buy')->getView($this->shop_id, $order_id);
+        return Dever::load('mshop/lib/buy')->set(1,2)->getView($this->shop_id, $order_id);
     }
 
     # 确认订单页面
@@ -97,7 +97,7 @@ class Buy extends Core
 
         $this->goods();
 
-        $pay = Dever::load('mshop/lib/buy')->action($this->shop, $this->data['name'], $this->data['num'], $this->data['list'], $this->data['price'], $info, $refer);
+        $pay = Dever::load('mshop/lib/buy')->set(1,1)->action(1, $this->shop_id, $this->data['name'], $this->data['num'], $this->data['list'], $this->data['price'], $info, $refer);
         return $pay;
     }
 
@@ -107,7 +107,7 @@ class Buy extends Core
         $refer = Dever::input('refer');
         $order_id = Dever::input('order_id');
 
-        $pay = Dever::load('mshop/lib/buy')->raction($order_id, $refer);
+        $pay = Dever::load('mshop/lib/buy')->set(1,2)->raction($order_id, $refer);
 
         return $pay;
     }
@@ -117,7 +117,7 @@ class Buy extends Core
     {
         $order_id = Dever::input('order_id');
 
-        return Dever::load('mshop/lib/buy')->cancel($this->shop_id, $order_id);
+        return Dever::load('mshop/lib/buy')->set(1,1)->cancel($this->shop_id, $order_id);
     }
 
     # 获取订单退款记录
@@ -125,7 +125,7 @@ class Buy extends Core
     {
         $order_id = Dever::input('order_id');
 
-        return Dever::load('shop/lib/refund')->set('buy')->getList($this->shop_id, $order_id);
+        return Dever::load('shop/lib/refund')->set('buy')->getList(1, $this->shop_id, $order_id);
     }
 
     # 货物未发出,仅退款
@@ -144,7 +144,7 @@ class Buy extends Core
         $desc = Dever::input('desc');
         $pic = Dever::input('pic');
 
-        return Dever::load('shop/lib/refund')->set('buy')->apply(2, $this->shop_id, $order_id, false, $status, 0, $desc, $pic, 1);
+        return Dever::load('shop/lib/refund')->set('buy')->apply(1, $this->shop_id, $order_id, false, $status, 0, $desc, $pic, 1);
     }
 
     # 部分退款信息 报损
@@ -153,7 +153,7 @@ class Buy extends Core
         $order_id = Dever::input('order_id');
         $order_goods_id = Dever::input('order_goods_id');
 
-        return Dever::load('shop/lib/refund')->set('buy')->getInfo(2, $this->shop_id, $order_id, $order_goods_id);
+        return Dever::load('shop/lib/refund')->set('buy')->getInfo(1, $this->shop_id, $order_id, $order_goods_id);
     }
 
     # 部分退款 报损
@@ -166,7 +166,7 @@ class Buy extends Core
         $desc = Dever::input('desc');
         $pic = Dever::input('pic');
 
-        return Dever::load('shop/lib/refund')->set('buy')->apply(2, $this->shop_id, $order_id, $order_goods_id, $status, $num, $desc, $pic, 1);
+        return Dever::load('shop/lib/refund')->set('buy')->apply(1, $this->shop_id, $order_id, $order_goods_id, $status, $num, $desc, $pic, 1);
     }
 
     # 收货确认
@@ -174,12 +174,6 @@ class Buy extends Core
     {
         $order_id = Dever::input('order_id');
 
-        return Dever::load('mshop/lib/buy')->finish($this->shop_id, $order_id);
-    }
-
-    # 测试审核拆单
-    public function audit()
-    {
-        Dever::load('mshop/lib/buy.audit_commit');
+        return Dever::load('mshop/lib/buy')->set(1,1)->finish($this->shop_id, $order_id);
     }
 }

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

@@ -100,6 +100,10 @@ class Data extends Core
     {
         $code = Dever::input('code');
 
+        if (!$code) {
+            Dever::alert('请输入自提码');
+        }
+
         $order_id = Dever::input('order_id');
 
         $info = Dever::db('shop/sell_order')->find(array('code' => $code, 'id' => $order_id));
@@ -137,7 +141,7 @@ class Data extends Core
     {
         $order_id = Dever::input('order_id');
 
-        return Dever::load('shop/lib/refund')->set('sell')->getList($this->shop_id, $order_id);
+        return Dever::load('shop/lib/refund')->set('sell')->getList(2, $this->shop_id, $order_id);
     }
 
     # 门店全部退款

+ 44 - 120
app/shop/database/buy_order.php

@@ -1,7 +1,5 @@
 <?php
 
-$pay_status = Dever::config('base', 'pay')->pay['status'];
-
 $status = array
 (
     1 => '待支付',
@@ -15,10 +13,11 @@ $status = array
     11 => '已过期',
 );
 
-$source_type = array
+$type = array
 (
-    1 => '仓库',
-    2 => '工厂',
+    1 => '门店',
+    2 => '仓库',
+    3 => '工厂',
 );
 
 return array
@@ -44,32 +43,42 @@ return array
             //'list'      => true,
         ), 
 
-        'shop_id'      => array
+        'type'      => array
         (
             'type'      => 'int-11',
-            'name'      => '所属门店',
+            'name'      => '采购人类型',
             'default'   => '',
-            'desc'      => '所属门店',
+            'desc'      => '采购人类型',
             'match'     => 'is_numeric',
-            'update'    => 'hidden',
-            'value'     => Dever::input('search_option_shop_id'),
-            'list'      => 'Dever::load("shop/info-find#name", {shop_id})',
         ),
 
-        'mobile'        => array
+        'type_id'      => array
         (
-            'type'      => 'varchar-300',
-            'name'      => '下单手机号',
+            'type'      => 'int-11',
+            'name'      => '采购人',
             'default'   => '',
-            'desc'      => '手机号',
-            'match'     => 'option',
-            'search'    => array
-            (
-                'api' => 'shop/info-select',//接口地址,最好是获取多条数据的地址
-                'col' => 'mobile',//要查询的字段
-                'result' => 'id',//返回的字段
-                'search' => 'shop_id',//本表的字段,默认为当前的字段
-            ),
+            'desc'      => '采购人',
+            'match'     => 'is_numeric',
+            'list'      => 'Dever::load("shop/lib/manage.buyInfo", "{type}", "{type_id}")',
+        ),
+
+        'source_type'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '供货商类型',
+            'default'   => '',
+            'desc'      => '供货商类型',
+            'match'     => 'is_numeric',
+        ),
+
+        'source_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '供货商',
+            'default'   => '',
+            'desc'      => '供货商',
+            'match'     => 'is_numeric',
+            'list'      => 'Dever::load("shop/lib/manage.buyInfo", "{source_type}", "{source_id}")',
         ),
 
         'name'      => array
@@ -82,6 +91,15 @@ return array
             'update'    => 'text',
         ),
 
+        'parent_order_id'      => array
+        (
+            'type'      => 'varchar-100',
+            'name'      => '原订单编号',
+            'default'   => '',
+            'desc'      => '订单编号',
+            'match'     => 'is_string',
+        ),
+
         'order_num'      => array
         (
             'type'      => 'varchar-100',
@@ -126,24 +144,6 @@ return array
             'update'    => 'text',
         ),
 
-        'type'      => array
-        (
-            'type'      => 'int-11',
-            'name'      => '采购来源',
-            'default'   => '',
-            'desc'      => '采购来源',
-            'match'     => 'is_numeric',
-        ),
-
-        'type_id'      => array
-        (
-            'type'      => 'int-11',
-            'name'      => '来源id',
-            'default'   => '',
-            'desc'      => '来源id',
-            'match'     => 'is_numeric',
-        ),
-
         'info'      => array
         (
             'type'      => 'varchar-300',
@@ -154,57 +154,6 @@ return array
             'update'    => 'textarea',
         ),
 
-        'area'       => array
-        (
-            'type'      => 'varchar-500',
-            'name'      => '所在地区',
-            'default'   => '',
-            'desc'      => '所在地区',
-            'match'     => 'option',
-            'search'    => 'linkage',
-            'option'    => Dever::url('api.get?level_total=4', 'area'),
-        ),
-
-        'province'      => array
-        (
-            'type'      => 'int-11',
-            'name'      => '省份',
-            'default'   => '',
-            'desc'      => '省份',
-            'match'     => 'option',
-            //'update'  => 'text',
-        ),
-
-        'city'      => array
-        (
-            'type'      => 'int-11',
-            'name'      => '城市',
-            'default'   => '',
-            'desc'      => '城市',
-            'match'     => 'option',
-            //'update'  => 'text',
-        ),
-
-        'county'      => array
-        (
-            'type'      => 'int-11',
-            'name'      => '县区',
-            'default'   => '',
-            'desc'      => '县区',
-            'match'     => 'option',
-            //'update'  => 'text',
-        ),
-
-        'town'      => array
-        (
-            'type'      => 'int-11',
-            'name'      => '街道',
-            'default'   => '',
-            'desc'      => '街道',
-            'match'     => 'option',
-            //'update'  => 'text',
-        ),
-
         'status'        => array
         (
             'type'      => 'tinyint-1',
@@ -234,33 +183,6 @@ return array
             'match'     => 'is_numeric',
             'desc'      => '',
         ),
-
-        'fdate'     => array
-        (
-            'type'      => 'int-11',
-            'name'      => '发货时间',
-            'default'   => '',
-            'match'     => 'is_numeric',
-            'desc'      => '',
-        ),
-
-        'qfdate'     => array
-        (
-            'type'      => 'int-11',
-            'name'      => '确认发货时间',
-            'default'   => '',
-            'match'     => 'is_numeric',
-            'desc'      => '',
-        ),
-
-        'shdate'     => array
-        (
-            'type'      => 'int-11',
-            'name'      => '确认收货时间',
-            'default'   => '',
-            'match'     => 'is_numeric',
-            'desc'      => '',
-        ),
         
         'cdate'     => array
         (
@@ -295,7 +217,9 @@ return array
 
             'oper'  => array('审核', '"mshop/lib/manage.audit?order_id={id}"', '{status} == 2'),
 
-            'oper1'  => array('发货', '"mshop/lib/manage.send?order_id={id}"', '{status} == 3'),
+            //'oper1'  => array('发货', '"mshop/lib/manage.send?order_id={id}"', '{status} == 3'),
+
+            'fast1' => array('发货', '"buy_order_ps&where_id={id}&search_option_order_id={id}&oper_save_jump=buy_order&oper_table=buy_order&oper_parent=buy_order"', '{status} == 3'),
         ),
     ),
 

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

@@ -31,18 +31,6 @@ return array
             //'list'        => true,
         ),
 
-        'shop_id'      => array
-        (
-            'type'      => 'int-11',
-            'name'      => '所属门店',
-            'default'   => '',
-            'desc'      => '所属门店',
-            'match'     => 'is_numeric',
-            'update'    => 'hidden',
-            'value'     => Dever::input('search_option_shop_id'),
-            'list'      => 'Dever::load("shop/info-find#name", {shop_id})',
-        ),
-
         'order_id'      => array
         (
             'type'      => 'int-11',

+ 92 - 69
app/factory/database/order_goods.php → app/shop/database/buy_order_ps.php

@@ -2,19 +2,31 @@
 
 $status = array
 (
-    1 => '正常',
-    2 => '已申报',
-    3 => '已退款',
+    1 => '待处理',
+    2 => '配送中',
+    3 => '已配送',
+    4 => '未配送',
 );
 
+$service = function()
+{
+    $info = Dever::db('shop/service')->select(array('type' => 1));
+    return $info;
+};
+
 return array
 (
     # 表名
-    'name' => 'order_goods',
+    'name' => 'buy_order_ps',
     # 显示给用户看的名称
-    'lang' => '订单商品表',
+    'lang' => '订单配送表',
     'menu' => false,
     'status' => $status,
+    'end' => array
+    (
+        'insert' => 'shop/lib/manage.buyOrderPs',
+        'update' => 'shop/lib/manage.buyOrderPs',
+    ),
     # 数据结构
     'struct' => array
     (
@@ -31,68 +43,101 @@ return array
             //'list'        => true,
         ),
 
-        'factory_id'      => array
+        'order_id'      => array
         (
             'type'      => 'int-11',
-            'name'      => '所属工厂',
+            'name'      => '订单表id',
             'default'   => '',
-            'desc'      => '所属工厂',
+            'desc'      => '订单表id',
             'match'     => 'is_numeric',
             'update'    => 'hidden',
-            'value'     => Dever::input('search_option_factory_id'),
-            'list'      => 'Dever::load("factory/info-find#name", {factory_id})',
+            'value'     => Dever::input('search_option_order_id'),
         ),
 
-        'order_id'      => array
+        'service_id'        => array
         (
             'type'      => 'int-11',
-            'name'      => '订单表id',
-            'default'   => '',
-            'desc'      => '订单表id',
+            'name'      => '配送服务商',
+            'default'   => '-1',
+            'desc'      => '配送服务商',
             'match'     => 'is_numeric',
+            'update'    => 'select',
+            'option'    => $service,
         ),
 
-        'goods_id'      => array
+        'order_num'        => array
         (
-            'type'      => 'int-11',
-            'name'      => '商品名称',
+            'type'      => 'varchar-800',
+            'name'      => '快递单号-多个用换行隔开',
             'default'   => '',
-            'desc'      => '商品名称',
-            'match'     => 'is_numeric',
-            'list'      => 'Dever::load("goods/info-find#name", {goods_id})',
+            'desc'      => '快递单号',
+            'match'     => 'is_string',
+            'update'    => 'textarea',
         ),
 
-        'sku_id'      => array
+        'phy'        => array
         (
-            'type'      => 'int-11',
-            'name'      => 'sku_id',
-            'default'   => '-1',
-            'desc'      => 'sku_id',
-            'match'     => 'is_numeric',
+            'type'      => 'varchar-200',
+            'name'      => '配货员',
+            'default'   => '',
+            'desc'      => '配货员',
+            'match'     => 'is_string',
+            'update'    => 'text',
         ),
 
-        'price'      => array
+        'dby'        => array
         (
-            'type'      => 'varchar-50',
-            'name'      => '价格',
+            'type'      => 'varchar-200',
+            'name'      => '打包员',
             'default'   => '',
-            'desc'      => '价格',
-            'match'     => 'option',
+            'desc'      => '打包员',
+            'match'     => 'is_string',
             'update'    => 'text',
-            'list'        => true,
         ),
 
+        'zl'        => array
+        (
+            'type'      => 'varchar-200',
+            'name'      => '包裹重量-单位:克',
+            'default'   => '',
+            'desc'      => '包裹重量',
+            'match'     => 'is_string',
+            'update'    => 'text',
+        ),
+
+        'tj'        => array
+        (
+            'type'      => 'varchar-200',
+            'name'      => '包裹体积-单位:立方厘米',
+            'default'   => '',
+            'desc'      => '包裹体积',
+            'match'     => 'is_string',
+            'update'    => 'text',
+        ),
+
+
         'num'        => array
         (
             'type'      => 'int-11',
-            'name'      => '购买数量',
+            'name'      => '包裹数量',
             'default'   => '',
-            'desc'      => '购买数量',
+            'desc'      => '包裹数量',
             'match'     => 'is_numeric',
             'search'    => 'select',
             'list'        => true,
         ),
 
+        'price'      => array
+        (
+            'type'      => 'varchar-50',
+            'name'      => '快递费用',
+            'default'   => '',
+            'desc'      => '快递费用',
+            'match'     => 'option',
+            'update'    => 'text',
+            'list'        => true,
+        ),
+
         'status'        => array
         (
             'type'      => 'int-11',
@@ -107,6 +152,15 @@ return array
             'edit'      => true,
         ),
 
+        'ydate'     => array
+        (
+            'type'      => 'int-11',
+            'name'      => '签收时间',
+            'default'   => '',
+            'match'     => 'is_numeric',
+            'desc'      => '签收时间',
+        ),
+
         'state'     => array
         (
             'type'      => 'tinyint-1',
@@ -119,11 +173,12 @@ return array
         'cdate'     => array
         (
             'type'      => 'int-11',
-            'name'      => '创建时间',
+            'name'      => '发货时间',
             'match'     => array('is_numeric', time()),
             'desc'      => '',
             # 只有insert时才生效
             //'insert'    => true,
+            'update'    => 'date',
             'search'    => 'date',
             'list'      => 'date("Y-m-d H:i:s", {cdate})',
         ),
@@ -131,43 +186,11 @@ return array
 
     'manage' => array
     (
-        'insert' => false,
-        'delete' => false,
-        'page_list_table' => 'buy_order_goods',
+        
     ),
 
     'request' => array
     (
-        # 获取单条数据
-        'getIds' => array
-        (
-            # 匹配的正则或函数 选填项
-            'option' => array
-            (
-                'uid' => 'yes',
-                'shop_id' => 'yes',
-                'order_id' => 'yes',
-                'status' => 1,
-                'state' => 1,
-            ),
-            'type' => 'all',
-            'col' => '*|id',
-        ),
-
-        # 获取多条数据
-        'getDataByIds' => array
-        (
-            # 匹配的正则或函数 选填项
-            'option' => array
-            (
-                'ids' => array('yes-id', 'in'),
-                'uid' => 'yes',
-                'shop_id' => 'yes',
-                'order_id' => 'yes',
-                'state' => 1,
-            ),
-            'type' => 'all',
-            'col' => '*',
-        ),
+        
     ),
 );

+ 1 - 13
app/shop/database/buy_order_refund.php

@@ -24,7 +24,7 @@ return array
     # 表名
     'name' => 'buy_order_refund',
     # 显示给用户看的名称
-    'lang' => '采购退款申请',
+    'lang' => '缺货报损订单管理',
     'menu' => false,
     'status' => $status,
     'process' => $process,
@@ -44,18 +44,6 @@ return array
             //'list'        => true,
         ),
 
-        'shop_id'      => array
-        (
-            'type'      => 'int-11',
-            'name'      => '所属门店',
-            'default'   => '',
-            'desc'      => '所属门店',
-            'match'     => 'is_numeric',
-            'update'    => 'hidden',
-            'value'     => Dever::input('search_option_shop_id'),
-            'list'      => 'Dever::load("shop/info-find#name", {shop_id})',
-        ),
-
         'order_id'      => array
         (
             'type'      => 'int-11',

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

@@ -283,57 +283,6 @@ return array
             'update'    => 'textarea',
         ),
 
-        'area'       => array
-        (
-            'type'      => 'varchar-500',
-            'name'      => '所在地区',
-            'default'   => '',
-            'desc'      => '所在地区',
-            'match'     => 'option',
-            'search'    => 'linkage',
-            'option'    => Dever::url('api.get?level_total=4', 'area'),
-        ),
-
-        'province'      => array
-        (
-            'type'      => 'int-11',
-            'name'      => '省份',
-            'default'   => '',
-            'desc'      => '省份',
-            'match'     => 'option',
-            //'update'  => 'text',
-        ),
-
-        'city'      => array
-        (
-            'type'      => 'int-11',
-            'name'      => '城市',
-            'default'   => '',
-            'desc'      => '城市',
-            'match'     => 'option',
-            //'update'  => 'text',
-        ),
-
-        'county'      => array
-        (
-            'type'      => 'int-11',
-            'name'      => '县区',
-            'default'   => '',
-            'desc'      => '县区',
-            'match'     => 'option',
-            //'update'  => 'text',
-        ),
-
-        'town'      => array
-        (
-            'type'      => 'int-11',
-            'name'      => '街道',
-            'default'   => '',
-            'desc'      => '街道',
-            'match'     => 'option',
-            //'update'  => 'text',
-        ),
-
         'status'        => array
         (
             'type'      => 'tinyint-1',

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

@@ -31,36 +31,6 @@ return array
             //'list'        => true,
         ),
 
-        'uid'       => array
-        (
-            'type'      => 'int-11',
-            'name'      => '用户名',
-            'default'   => '0',
-            'desc'      => '请选择用户',
-            'match'     => 'is_numeric',
-            'update'    => 'text',
-            //'search'  => 'select',
-            'search'    => array
-            (
-                'api' => 'passport/user-all',
-                'col' => 'username',
-                'result' => 'id',
-            ),
-            'list'      => '{uid} > 0 ? Dever::load("passport/user-find#username", {uid}) : "匿名用户"',
-        ),
-
-        'shop_id'      => array
-        (
-            'type'      => 'int-11',
-            'name'      => '所属门店',
-            'default'   => '',
-            'desc'      => '所属门店',
-            'match'     => 'is_numeric',
-            'update'    => 'hidden',
-            'value'     => Dever::input('search_option_shop_id'),
-            'list'      => 'Dever::load("shop/info-find#name", {shop_id})',
-        ),
-
         'order_id'      => array
         (
             'type'      => 'int-11',

+ 26 - 49
app/shop/database/sell_order_ps.php

@@ -8,6 +8,12 @@ $status = array
     4 => '未配送',
 );
 
+$service = function()
+{
+    $info = Dever::db('shop/service')->select(array('type' => 2));
+    return $info;
+};
+
 return array
 (
     # 表名
@@ -32,36 +38,6 @@ return array
             //'list'        => true,
         ),
 
-        'uid'       => array
-        (
-            'type'      => 'int-11',
-            'name'      => '用户名',
-            'default'   => '0',
-            'desc'      => '请选择用户',
-            'match'     => 'is_numeric',
-            'update'    => 'text',
-            //'search'  => 'select',
-            'search'    => array
-            (
-                'api' => 'passport/user-all',
-                'col' => 'username',
-                'result' => 'id',
-            ),
-            'list'      => '{uid} > 0 ? Dever::load("passport/user-find#username", {uid}) : "匿名用户"',
-        ),
-
-        'shop_id'      => array
-        (
-            'type'      => 'int-11',
-            'name'      => '所属门店',
-            'default'   => '',
-            'desc'      => '所属门店',
-            'match'     => 'is_numeric',
-            'update'    => 'hidden',
-            'value'     => Dever::input('search_option_shop_id'),
-            'list'      => 'Dever::load("shop/info-find#name", {shop_id})',
-        ),
-
         'order_id'      => array
         (
             'type'      => 'int-11',
@@ -74,42 +50,43 @@ return array
         'service_id'        => array
         (
             'type'      => 'int-11',
-            'name'      => '配送服务商id',
+            'name'      => '配送服务商',
             'default'   => '-1',
-            'desc'      => '配送服务商id',
+            'desc'      => '配送服务商',
             'match'     => 'is_numeric',
-            //'update'    => 'select',
-            //'option'    => $ps_service,
+            'update'    => 'select',
+            'option'    => $service,
         ),
 
         'order_num'        => array
         (
-            'type'      => 'varchar-200',
-            'name'      => '配送订单号',
+            'type'      => 'varchar-800',
+            'name'      => '快递单号-多个用换行隔开',
             'default'   => '',
-            'desc'      => '配送订单号',
+            'desc'      => '快递单号',
             'match'     => 'is_string',
+            'update'    => 'textarea',
         ),
 
-        'price'      => array
+        'num'        => array
         (
-            'type'      => 'varchar-50',
-            'name'      => '配送金额',
+            'type'      => 'int-11',
+            'name'      => '包裹数量',
             'default'   => '',
-            'desc'      => '配送金额',
-            'match'     => 'option',
-            'update'    => 'text',
+            'desc'      => '包裹数量',
+            'match'     => 'is_numeric',
+            'search'    => 'select',
             'list'        => true,
         ),
 
-        'num'        => array
+        'price'      => array
         (
-            'type'      => 'int-11',
-            'name'      => '配送数量',
+            'type'      => 'varchar-50',
+            'name'      => '快递费用',
             'default'   => '',
-            'desc'      => '配送数量',
-            'match'     => 'is_numeric',
-            'search'    => 'select',
+            'desc'      => '快递费用',
+            'match'     => 'option',
+            'update'    => 'text',
             'list'        => true,
         ),
 

+ 0 - 12
app/shop/database/sell_order_refund.php

@@ -44,18 +44,6 @@ return array
             //'list'        => true,
         ),
 
-        'shop_id'      => array
-        (
-            'type'      => 'int-11',
-            'name'      => '所属门店',
-            'default'   => '',
-            'desc'      => '所属门店',
-            'match'     => 'is_numeric',
-            'update'    => 'hidden',
-            'value'     => Dever::input('search_option_shop_id'),
-            'list'      => 'Dever::load("shop/info-find#name", {shop_id})',
-        ),
-
         'order_id'      => array
         (
             'type'      => 'int-11',

+ 100 - 0
app/shop/database/service.php

@@ -0,0 +1,100 @@
+<?php
+# 配送服务商类型
+$type = array
+(
+    1 => '物流',
+    2 => '外卖',
+);
+
+return array
+(
+    # 表名
+    'name' => 'service',
+    # 显示给用户看的名称
+    'lang' => '配送服务商',
+    # 后台菜单排序
+    'order' => -1,
+    # 数据结构
+    'struct' => array
+    (
+        'id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            'search'    => 'order',
+            'list'      => true,
+            'order'     => 'desc',
+        ),
+        
+        'name'      => array
+        (
+            'type'      => 'varchar-200',
+            'name'      => '配送服务商名称',
+            'default'   => '',
+            'desc'      => '配送服务商名称',
+            'match'     => 'is_string',
+            'update'    => 'text',
+            'search'    => 'fulltext',
+            'list'      => true,
+        ),
+
+        'number'      => array
+        (
+            'type'      => 'varchar-100',
+            'name'      => '服务商代号-用来根据接口获取物流信息',
+            'default'   => '',
+            'desc'      => '服务商代号',
+            'match'     => 'option',
+            'update'    => 'text',
+            'search'    => 'fulltext',
+            'list'      => true,
+        ),
+
+        'type'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '服务商类型',
+            'default'   => '1',
+            'desc'      => '服务商类型',
+            'match'     => 'is_numeric',
+            'update'  => 'select',
+            'option'    => $type,
+            'search'    => 'select',
+            'list'      => true,
+            'edit'      => true,
+        ),
+
+        'state'     => array
+        (
+            'type'      => 'tinyint-1',
+            'name'      => '状态',
+            'default'   => '1',
+            'desc'      => '请选择状态',
+            'match'     => 'is_numeric',
+        ),
+        
+        'cdate'     => array
+        (
+            'type'      => 'int-11',
+            'name'      => '创建时间',
+            'match'     => array('is_numeric', time()),
+            'desc'      => '',
+            # 只有insert时才生效
+            'insert'    => true,
+            'list'      => 'date("Y-m-d H:i:s", {cdate})',
+        ),
+    ),
+
+    'manage' => array
+    (
+        
+    ),
+
+    'request' => array
+    (
+        
+    ),
+);

+ 29 - 6
app/shop/lib/Goods.php

@@ -31,7 +31,7 @@ class Goods
     }
 
     # 处理库存操作 1是增加,2是减少 1是总库存,2是销量
-    public function oper($type, $col, $data)
+    public function oper($order, $type, $col, $data)
     {
         if (!$data) {
             return;
@@ -54,22 +54,45 @@ class Goods
             $num = 'sell_num';
         }
 
+        $up = array();
+        $table = 'shop';
+        if (isset($order['shop_id'])) {
+            $up['where_shop_id'] = $order['shop_id'];
+        } else {
+            if ($order['type'] == 1) {
+                $up['where_shop_id'] = $order['type_id'];
+            } elseif ($order['type'] == 2) {
+                $table = 'store';
+                $up['where_store_id'] = $order['type_id'];
+            }
+        }
         foreach ($data as $k => $v) {
             if (!$v['sku_id']) {
                 $v['sku_id'] = -1;
             }
 
-            $up = array();
-            $up['where_shop_id'] = $v['shop_id'];
             $up['where_goods_id'] = $v['goods_id'];
             $up[$num] = $v['num'];
-            $state = Dever::db('shop/goods')->$method($up);
+            $state = Dever::db($table . '/goods')->$method($up);
             if ($state) {
                 $upSku = $up;
                 $upSku['where_sku_id'] = $v['sku_id'];
-                $state = Dever::db('shop/goods_sku')->$method($upSku);
+                $state = Dever::db($table . '/goods_sku')->$method($upSku);
                 if (!$state) {
-                    Dever::db('shop/goods')->$otherMethod($up);
+                    Dever::db($table . '/goods')->$otherMethod($up);
+                }
+
+                if (isset($order['source_type']) && $order['source_type'] == 2 && $type == 1 && $col == 1) {
+                    # 如果是仓库发货的,要减少仓库库存
+                    $sup['where_store_id'] = $order['source_id'];
+                    $sup['where_goods_id'] = $v['goods_id'];
+                    $sup[$num] = $v['num'];
+                    $state = Dever::db('store/goods')->$otherMethod($sup);
+                    if ($state) {
+                        $supSku = $sup;
+                        $supSku['where_sku_id'] = $v['sku_id'];
+                        $state = Dever::db('store/goods_sku')->$otherMethod($supSku);
+                    }
                 }
             }
         }

+ 32 - 0
app/shop/lib/Manage.php

@@ -217,4 +217,36 @@ class Manage
             }
         }
     }
+
+    # 获取供货商信息
+    public function buyInfo($type, $type_id)
+    {
+        if ($type == 1) {
+            $type_info = Dever::db('shop/info')->find($type_id);
+            return $type_info['name'] . '('.$type_info['mobile'].')';
+        } elseif ($type == 2) {
+            $type_info = Dever::db('store/info')->find($type_id);
+            return $type_info['name'] . '('.$type_info['mobile'].')';
+        } elseif ($type == 3) {
+            $type_info = Dever::db('factory/info')->find($type_id);
+            return $type_info['name'] . '('.$type_info['mobile'].')';
+        } else {
+            return '无';
+        }
+    }
+
+    /**
+     * 更新信息
+     *
+     * @return mixed
+     */
+    public function buyOrderPs($id, $name, $data)
+    {
+        $order_id = Dever::param('order_id', $data);
+        if ($order_id) {
+            $update['where_id'] = $order_id;
+            $update['set_status'] = 4;
+            Dever::db('shop/buy_order')->update($update);
+        }
+    }
 }

+ 15 - 16
app/shop/lib/Refund.php

@@ -18,14 +18,14 @@ class Refund
         } else {
             $this->lib = 'shop/lib/' . $type;
         }
-        
 
         return $this;
     }
 
     # 获取退款记录
-    public function getList($uid, $order_id)
+    public function getList($type, $id, $order_id)
     {
+        $data = Dever::load($this->lib)->set($type, 1)->getView($id, $order_id, false);
         $where['order_id'] = $order_id;
 
         $data = Dever::db($this->refund_table)->select_page($where);
@@ -52,9 +52,8 @@ class Refund
     }
 
     # 更新退款记录
-    public function up($shop_id, $order_id, $order_goods_id, $status, $price, $num = false, $desc = '', $pic = '', $process = 1)
+    public function up($order_id, $order_goods_id, $status, $price, $num = false, $desc = '', $pic = '', $process = 1)
     {
-        $data['shop_id'] = $shop_id;
         $data['order_id'] = $order_id;
         if (!$order_goods_id) {
             $where['order_id'] = $order_id;
@@ -104,7 +103,7 @@ class Refund
         $dec = $num;
         $data = Dever::load($this->lib)->set($type, 1)->getView($id, $order_id, false);
         $auth = false;
-        if ($type == 1) {
+        if ($this->type == 'sell' && $type == 1) {
             if ($data['status'] == 2) {
                 $auth = true;
             }
@@ -143,12 +142,12 @@ class Refund
             }
 
             if ($cash > 0) {
-                $log = $this->up($data['shop_id'], $data['id'], $order_goods_id, $status, $cash, $dec, $desc, $pic, $process);
+                $log = $this->up($data['id'], $order_goods_id, $status, $cash, $dec, $desc, $pic, $process);
 
                 if ($this->type == 'buy' && ($data['status'] == 5 || $data['status'] == 6)) {
                     # 如果是采购单,这里要把库存先减掉
                     $oper_data = Dever::db($this->goods_table)->getDataByIds(array('ids' => $log['order_goods_id']));
-                    Dever::load('shop/lib/goods')->oper(2, 1, $oper_data);
+                    Dever::load('shop/lib/goods')->oper($data, 2, 1, $oper_data);
                 }
 
                 $update = array();
@@ -212,14 +211,14 @@ class Refund
                     $this->notice($state, $order, $info['cash']);
                     # 检查这个订单下的商品是不是都退了
                     $total = Dever::db($this->goods_table)->total(array('order_id' => $order['id'], 'status' => 1));
-                    if ($total <= 0) {
-                        if ($order['status'] == 5) {
-                            $update['status'] = 6;
-                        } else {
-                            $update['operdate'] = time();
-                            $update['status'] = 8;
-                        }
+
+                    if ($order['status'] == 5) {
+                        $update['status'] = 6;
+                    } elseif ($total <= 0) {
+                        $update['operdate'] = time();
+                        $update['status'] = 8;
                     }
+
                     if ($update) {
                         $update['where_id'] = $order['id'];
                         $state = Dever::db($this->order_table)->update($update);
@@ -243,10 +242,10 @@ class Refund
         $data = Dever::db($this->goods_table)->getDataByIds(array('ids' => $info['order_goods_id']));
         if ($this->type == 'sell' && $process == 2) {
             # 如果是销售单,退款后要减少销量
-            Dever::load('shop/lib/goods')->oper(2, 2, $data);
+            Dever::load('shop/lib/goods')->oper($order, 2, 2, $data);
         } elseif ($this->type == 'buy' && $process == 3 && ($order['status'] == 5 || $order['status'] == 6)) {
             # 如果是采购单,退款后要恢复库存
-            Dever::load('shop/lib/goods')->oper(1, 1, $data);
+            Dever::load('shop/lib/goods')->oper($order, 1, 1, $data);
         }
 
         return 'ok';

+ 44 - 15
app/shop/lib/Sell.php

@@ -8,7 +8,7 @@ use Dever;
 
 class Sell
 {
-    # 1是用户自己看,2是门店
+    # 1是用户,2是门店
     public $type = 1;
     # 1是列表,2是详情
     public $view = 1;
@@ -517,12 +517,6 @@ class Sell
         $order_data['price'] = $price;
         $order_data['kou_cash'] = $cash;
 
-        $order_data['area'] = $shop['area'];
-        $order_data['province'] = $shop['province'];
-        $order_data['city'] = $shop['city'];
-        $order_data['county'] = $shop['county'];
-        $order_data['town'] = $shop['town'];
-
         $order_data['method'] = $method;
         $order_data['pay_method'] = $pay_method;
         $order_data['pay_type'] = $pay_type;
@@ -550,7 +544,6 @@ class Sell
         foreach($goods as $k => $v) {
             if ($v['ku_state'] == 1) {
                 $data['uid'] = $uid;
-                $data['shop_id'] = $shop['id'];
                 $data['order_id'] = $id;
                 $data['goods_id'] = $v['id'];
                 $data['sku_id'] = $v['sku_id'];
@@ -773,12 +766,10 @@ class Sell
 
         if (!$data) {
             $insert = $where;
-            $insert['uid'] = $order['uid'];
-            $insert['shop_id'] = $order['shop_id'];
             $insert['service_id'] = -1;
             $insert['price'] = 0;
             $insert['status'] = $status;
-            $insert['num'] = $order['num'];
+            $insert['num'] = 1;
             if ($status == 2) {
                 $insert['qu_date'] = time();
             }
@@ -805,7 +796,7 @@ class Sell
         $where['status'] = 1;
         $data = Dever::db('shop/sell_order_goods')->select($where);
         if ($data) {
-            Dever::load('shop/lib/goods')->oper($type, 2, $data);
+            Dever::load('shop/lib/goods')->oper($order, $type, 2, $data);
         }
     }
 
@@ -842,6 +833,13 @@ class Sell
 
         $info = Dever::db('shop/sell_order')->one($id);
 
+        $tk_status = Dever::db('shop/sell_order_refund')->config['status'];
+        $tk_process = Dever::db('shop/sell_order_refund')->config['process'];
+
+        $status = $config['status'][$info['status']];
+
+        $tk = Dever::db('shop/buy_order_refund')->find(array('order_id' => $info['id'], 'type' => 1));
+
         $shop = Dever::db('shop/info')->find($info['shop_id']);
 
         $user = Dever::db('passport/user')->find($info['uid']);
@@ -870,9 +868,27 @@ class Sell
           <td>'.$this->table(false, array(array('昵称:' . $user['username'], '联系电话:' . $user['mobile']))).'</td>
         </tr>';
 
+        if ($tk && $tk['process'] == 1) {
+            $status = '申请' . $tk_status[$tk['status']];
+            $process = $tk_process[$tk['process']];
+            $process = '';
+        }
+
+        if ($info['info']) {
+            $html .= '<tr>
+              <td>订单备注</td>
+              <td>'.$this->table(false, array(array($info['info']))).'</td>
+
+            </tr>';
+        }
+
+        if (!$info['refund_cash']) {
+            $info['refund_cash'] = 0;
+        }
+
         $html .= '<tr>
           <td>订单信息</td>
-          <td>'.$this->table(array('金额', '数量','支付方式', '配送方式', '订单状态'), array(array($info['price'], $info['num'],$config['pay_method'][$info['pay_method']], $config['method'][$info['method']], $config['status'][$info['status']]))).'</td>
+          <td>'.$this->table(array('金额', '退款金额', '数量', '支付方式', '配送方式', '订单状态'), array(array($info['price'], $info['refund_cash'], $info['num'],$config['pay_method'][$info['pay_method']], $config['method'][$info['method']], $status))).'</td>
         </tr>';
 
         if ($info['address_id'] > 0) {
@@ -897,18 +913,31 @@ class Sell
 
         $html .= '[商品清单]:';
 
-        $head = array('商品名称', '商品属性', '商品价格', '商品数量');
+        $head = array('名称', '属性', '价格', '数量', '状态');
 
         $body = array();
         $goods = Dever::db('shop/sell_order_goods')->select(array('order_id' => $info['id']));
+        $goods_status = Dever::db('shop/sell_order_goods')->config['status'];
         foreach ($goods as $k => $v) {
             $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v['goods_id'], $v['sku_id']);
+            $status = $goods_status[$v['status']];
+            $tk = Dever::db('shop/sell_order_refund')->find(array('order_id' => $info['id'], 'order_goods_id' => $v['id'], 'type' => 2));
+            if ($tk && $tk['process'] == 1) {
+                $status = '申请' . $tk_status[$tk['status']];
+                //$status .= '&nbsp;&nbsp;[' . $tk_process[$tk['process']] . ']';
+            }
+            if (isset($goods_info['sku'])) {
+                $sku = $goods_info['sku']['string'];
+            } else {
+                $sku = '无';
+            }
             $body[$k] = array
             (
                 $goods_info['name'],
-                $v['price'],
+                $sku,
                 $v['price'],
                 $v['num'],
+                $status,
             );
         }
         $html .= $this->table($head, $body);

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

@@ -198,7 +198,7 @@ class Buy extends Core
 	}
 
 	# 开始下单
-	public function pay()
+	public function pay_commit()
 	{
 		$refer = Dever::input('refer');
 		$cart = Dever::input('cart', 1);

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

@@ -160,7 +160,7 @@ class My extends Core
 	{
 		$order_id = Dever::input('order_id');
 
-        return Dever::load('shop/lib/refund')->set('sell')->getList($this->uid, $order_id);
+        return Dever::load('shop/lib/refund')->set('sell')->getList(1, $this->uid, $order_id);
 	}
 
 	# 我的消息列表

+ 1 - 1
app/store/database/info.php

@@ -319,7 +319,7 @@ return array
 
             'list1' => array('账号管理', '"member&search_option_store_id={id}&oper_table=info"'),
 
-            'list2' => array('订货单', '"order&search_option_store_id={id}&oper_table=info"'),
+            //'list2' => array('订货单', '"order&search_option_store_id={id}&oper_table=info"'),
         ),
     ),
 

+ 0 - 146
app/store/database/order.php

@@ -1,146 +0,0 @@
-<?php
-
-$pay_status = Dever::config('base', 'pay')->pay['status'];
-
-$status = array
-(
-    1 => '待支付',
-    2 => '待审核',
-    3 => '待发货',
-    4 => '待收货确认',
-    5 => '已完成',
-    6 => '已完成(有退款)',
-    7 => '已取消',
-);
-
-return array
-(
-    # 表名
-    'name' => 'order',
-    # 显示给用户看的名称
-    'lang' => '订货单',
-    'order' => 99,
-    'menu' => false,
-    # 数据结构
-    'struct' => array
-    (
-    
-        'id'        => array
-        (
-            'type'      => 'int-11',
-            'name'      => 'ID',
-            'default'   => '',
-            'desc'      => '',
-            'match'     => 'is_numeric',
-            'search'    => 'order',
-            //'list'      => true,
-        ), 
-
-        'store_id'      => array
-        (
-            'type'      => 'int-11',
-            'name'      => '所属仓库',
-            'default'   => '',
-            'desc'      => '所属仓库',
-            'match'     => 'is_numeric',
-            'update'    => 'hidden',
-            'value'     => Dever::input('search_option_store_id'),
-            'list'      => 'Dever::load("store/info-find#name", {store_id})',
-        ),
-
-        'shop_id'      => array
-        (
-            'type'      => 'int-11',
-            'name'      => '所属门店',
-            'default'   => '',
-            'desc'      => '所属门店',
-            'match'     => 'is_numeric',
-            'list'      => 'Dever::load("shop/info-find#name", {shop_id})',
-        ),
-
-        'shop_order_id' => array
-        (
-            'type'      => 'int-11',
-            'name'      => '门店订单id',
-            'default'   => '',
-            'desc'      => '门店订单id',
-            'match'     => 'is_numeric',
-        ),
-
-        'price'      => array
-        (
-            'type'      => 'varchar-50',
-            'name'      => '总价格',
-            'default'   => '',
-            'desc'      => '总价格',
-            'match'     => 'option',
-            'update'    => 'text',
-            'list'        => true,
-        ),
-
-        'num'        => array
-        (
-            'type'      => 'int-11',
-            'name'      => '总数量',
-            'default'   => '',
-            'desc'      => '总数量',
-            'match'     => 'is_numeric',
-            'search'    => 'select',
-            'list'        => true,
-        ),
-
-        'info'      => array
-        (
-            'type'      => 'varchar-300',
-            'name'      => '订单备注',
-            'default'   => '',
-            'desc'      => '订单备注',
-            'match'     => 'option',
-            'update'    => 'textarea',
-        ),
-        
-        '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})',
-            //'list'      => 'Dever::load("service/lib/manage.showOrderTime", "{id}")',
-        ),
-    ),
-
-    'manage' => array
-    (
-        'delete' => false,
-        'edit' => false,
-        'insert' => false,
-
-        'button' => array
-        (
-            //'导出订单' => array('location', 'user/lib/manage.out'),
-        ),
-
-        'list_button' => array(
-            //'edit' => array('退款', 'status,tk_time,tk_pic,tk_desc,tk_admin', '{status} == 2'),
-            //'delete' => array('删除', '', '{status} == 1'),
-        ),
-    ),
-
-    'request' => array
-    (
-        
-    ),
-);

+ 0 - 138
app/store/database/order_goods.php

@@ -1,138 +0,0 @@
-<?php
-
-$status = array
-(
-    1 => '正常',
-    2 => '缺货',
-    3 => '退款',
-);
-
-return array
-(
-    # 表名
-    'name' => 'order_goods',
-    # 显示给用户看的名称
-    'lang' => '订单商品表',
-    'menu' => false,
-    # 数据结构
-    'struct' => array
-    (
-    
-        'id'        => array
-        (
-            'type'      => 'int-11',
-            'name'      => 'ID',
-            'default'   => '',
-            'desc'      => '',
-            'match'     => 'is_numeric',
-            'search'    => 'order',
-            'update'    => 'hidden',
-            //'list'        => true,
-        ),
-
-        'store_id'      => array
-        (
-            'type'      => 'int-11',
-            'name'      => '所属仓库',
-            'default'   => '',
-            'desc'      => '所属仓库',
-            'match'     => 'is_numeric',
-            'list'      => 'Dever::load("store/info-find#name", {store_id})',
-        ),
-
-        'order_id'      => array
-        (
-            'type'      => 'int-11',
-            'name'      => '订单表id',
-            'default'   => '',
-            'desc'      => '订单表id',
-            'match'     => 'is_numeric',
-        ),
-
-        'goods_id'      => array
-        (
-            'type'      => 'int-11',
-            'name'      => '商品名称',
-            'default'   => '',
-            'desc'      => '商品名称',
-            'match'     => 'is_numeric',
-            'list'      => 'Dever::load("goods/info-find#name", {goods_id})',
-        ),
-
-        'sku_id'      => array
-        (
-            'type'      => 'int-11',
-            'name'      => 'sku_id',
-            'default'   => '',
-            'desc'      => 'sku_id',
-            'match'     => 'is_numeric',
-        ),
-
-        'price'      => array
-        (
-            'type'      => 'varchar-50',
-            'name'      => '价格',
-            'default'   => '',
-            'desc'      => '价格',
-            'match'     => 'option',
-            'update'    => 'text',
-            'list'        => true,
-        ),
-
-        'num'        => array
-        (
-            'type'      => 'int-11',
-            'name'      => '购买数量',
-            'default'   => '',
-            'desc'      => '购买数量',
-            'match'     => 'is_numeric',
-            'search'    => 'select',
-            'list'        => true,
-        ),
-
-        'status'        => array
-        (
-            'type'      => 'int-11',
-            'name'      => '状态',
-            'default'   => '1',
-            'desc'      => '状态',
-            'match'     => 'is_numeric',
-            //'update'  => 'select',
-            'option'    => $status,
-            'search'    => 'select',
-            'list'      => true,
-            'edit'      => true,
-        ),
-
-        'state'     => array
-        (
-            'type'      => 'tinyint-1',
-            'name'      => '状态',
-            'default'   => '1',
-            'desc'      => '请选择状态',
-            'match'     => 'is_numeric',
-        ),
-        
-        'cdate'     => array
-        (
-            'type'      => 'int-11',
-            'name'      => '创建时间',
-            'match'     => array('is_numeric', time()),
-            'desc'      => '',
-            # 只有insert时才生效
-            //'insert'    => true,
-            'search'    => 'date',
-            'list'      => 'date("Y-m-d H:i:s", {cdate})',
-        ),
-    ),
-
-    'manage' => array
-    (
-        
-    ),
-
-    'request' => array
-    (
-        
-    ),
-);

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

@@ -7,7 +7,7 @@ use Dever;
 class Goods
 {
     # 处理库存操作 1是增加,2是减少 1是总库存,2是销量
-    public function oper($type, $col, $data)
+    public function oper($store_id, $type, $col, $data)
     {
         if (!$data) {
             return;
@@ -36,7 +36,7 @@ class Goods
             }
 
             $up = array();
-            $up['where_store_id'] = $v['store_id'];
+            $up['where_store_id'] = $store_id;
             $up['where_goods_id'] = $v['goods_id'];
             $up[$num] = $v['num'];
             $state = Dever::db('store/goods')->$method($up);

+ 0 - 76
app/store/lib/Order.php

@@ -1,76 +0,0 @@
-<?php
-
-namespace Store\Lib;
-
-use Dever;
-
-class Order
-{
-	# 单个商品下单
-	public function pay($shop_order_id, $shop, $store_id, $price, $num, $goods_id, $sku_id)
-	{
-		# 先更新库存
-		$state = $this->updateSell($store_id, $goods_id, $sku_id, $num);
-
-		if (!$state) {
-			return false;
-		}
-
-		$where['order_num'] = $shop_order_id;
-		$where['shop_id'] = $shop['id'];
-		$where['type'] = 1;
-		$where['type_id'] = $store_id;
-		$info = Dever::db('shop/buy_order')->find($where);
-
-		if (!$info) {
-			$data = $where;
-			$data['name'] = $shop_order_id;
-			$data['mobile'] = $shop['mobile'];
-			$data['area'] = $shop['area'];
-			$data['province'] = $shop['province'];
-			$data['city'] = $shop['city'];
-			$data['county'] = $shop['county'];
-			$data['town'] = $shop['town'];
-			$data['operdate'] = time();
-			$data['status'] = 3;
-			$data['price'] = $price;
-			$data['num'] = $num;
-			$id = $state = Dever::db('shop/buy_order')->insert($data);
-		} else {
-			$id = $info['id'];
-
-			$data['where_id'] = $id;
-			$data['price'] = $info['price'] + $price;
-			$data['num'] = $info['num'] + $num;
-			$state = Dever::db('shop/buy_order')->update($data);
-		}
-
-		if ($state && $id > 0) {
-			$goods_info = Dever::db('shop/buy_order_goods')->find(array('order_id' => $id));
-			if (!$goods_info) {
-				$goods['order_id'] = $id;
-				$goods['shop_id'] = $shop['id'];
-				$goods['goods_id'] = $goods_id;
-				$goods['sku_id'] = $sku_id;
-				$goods['price'] = $price;
-				$goods['num'] = $num;
-				Dever::db('shop/buy_order_goods')->insert($goods);
-			}
-
-			return $id;
-		}
-
-		return false;
-	}
-
-	# 减少库存,增加销量
-    public function updateSell($store_id, $goods_id, $sku_id, $num)
-    {
-
-    	$data['store_id'] = $store_id;
-    	$data['goods_id'] = $goods_id;
-    	$data['sku_id'] = $sku_id;
-    	$data['num'] = $num;
-    	return Dever::load('store/lib/goods')->oper(1, 2, array($data));
-    }
-}