dever 3 年之前
父節點
當前提交
a41631519c
共有 1 個文件被更改,包括 404 次插入402 次删除
  1. 404 402
      app/mshop/lib/Buy.php

+ 404 - 402
app/mshop/lib/Buy.php

@@ -656,25 +656,57 @@ class Buy
         $type = Dever::input('search_option_type', $type);
         $type = Dever::input('type', $type);
 
-        $noprice = Dever::input('noprice', 2);
-        if ($type == 3) {
-            $noprice = 1;
-        }
+        $info = Dever::db('shop/buy_order')->one($id);
 
-        $cash_type = Dever::input('cash', 1);
+        $result = array();
 
-        $config = Dever::db('shop/buy_order')->config;
+        $type_info = $this->show_base($info, $result, $type);
 
-        $info = Dever::db('shop/buy_order')->one($id);
+        $parent_order = $this->show_address($info, $result, $type, $type_info);
 
-        $tk_status = Dever::db('shop/buy_order_refund')->config['status'];
-        $tk_process = Dever::db('shop/buy_order_refund')->config['process'];
+        $button = $this->show_button($info, $type, $parent_order);
 
-        $status = $config['status'][$info['status']];
+        $audit = Dever::input('audit');
+        if ($audit == 1) {
+            # 审核信息
+            $this->show_audit($info, $result);
+        } else {
+            # 退款信息
+            $this->show_refund($info, $result);
+            
+            # 配送信息
+            $this->show_ps($info, $result);
 
-        $tk = Dever::db('shop/buy_order_refund')->find(array('order_id' => $info['id'], 'type' => 1));
+            $noprice = Dever::input('noprice', 2);
+            if ($type == 3) {
+                $noprice = 1;
+            }
+
+            # 商品信息
+            $this->show_goods($info, $result, $type, $noprice);
+
+            # 对账信息
+            $this->show_dz($info, $result, $noprice);
+        }
+
+        $head = array
+        (
+            'name' => '基本信息',
+            'btn' => $button,
+        );
+        $html = Dever::show($head, $result);
+
+        return $html;
+    }
+
+    private function show_base($info, &$result, $type)
+    {
+        $config = Dever::db('shop/buy_order')->config;
+
+        $status = $config['status'][$info['status']];
 
         $cdate = date('Y-m-d H:i', $info['cdate']);
+
         if ($info['operdate']) {
             $operdate = date('Y-m-d H:i', $info['operdate']);
         } else {
@@ -715,8 +747,6 @@ class Buy
             $type_info = Dever::db('store/info')->find($info['type_id']);
         }
 
-        $result = array();
-
         $result[$info['order_num']] = array
         (
             'type' => 'info',
@@ -731,13 +761,17 @@ class Buy
             )
         );
 
+        return $type_info;
+    }
+
+    private function show_address($info, &$result, $type, $type_info)
+    {
         $parent_order = array();
         if ($info['parent_type'] == 2) {
             $parent_order = Dever::db('shop/sell_order')->find($info['parent_order_id']);
         } elseif ($info['parent_type'] == 3) {
             $parent_order = Dever::db('agent/dh_order')->find($info['parent_order_id']);
         }
-
         if ($parent_order && isset($parent_order['uid']) && $parent_order['uid']) {
             if ($parent_order['address_id']) {
                 $address = Dever::load('passport/address')->getOne($parent_order['uid'], $parent_order['address_id']);
@@ -814,6 +848,11 @@ class Buy
             );
         }
 
+        return $parent_order;
+    }
+
+    private function show_button($info, $type, $parent_order)
+    {
         $button = array();
         if ($type == 2) {
             $config = Dever::load('factory/admin/auth.config');
@@ -907,464 +946,427 @@ class Buy
             );
         }
 
-        $audit = Dever::input('audit');
-        if ($audit == 1) {
-            $order['type'] = 1;
+        return $button;
+    }
 
-            $goods = Dever::db('shop/buy_order_goods')->select(array('order_id' => $info['id']));
+    private function getSelect($source_id, $goods_id)
+    {
+        $select = '<select class="audit">';
+        foreach ($source as $k => $v) {
+            $yes = '';
+            if ($source_id && $v['id'] == $source_id) {
+                $yes = 'selected';
+            }
+            $select .= '<option value="'.$v['type'] . '_' . $v['id'] . '_' . $goods_id.'" '.$yes.'>'.$v['name'].'</option>';
+        }
+        $select .= '</select>';
 
-            $shop = Dever::db('shop/info')->find($info['type_id']);
+        return $select;
+    }
 
-            list($data, $source) = $this->assign($goods, $info, $shop, true);
+    private function show_audit($info, &$result)
+    {
+        $order['type'] = 1;
 
-            if ($data) {
-                $head = array('序号', '商品编号', '商品名称', '供货商', '订货总数量', '商品计量单位', '订货单总金额');
-                $body = array();
-                $i = 0;
-                foreach ($data as $k => $v) {
-                    foreach ($v as $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
-                        (
-                            $i+1,
-                            $goods_info['code'],
-                            $goods_info['name'] . $sku,
-                            $v1['source_name'],
-                            $v1['num'],
-                            $goods_info['unit'],
-                            $v1['p_price'] * $v1['num'],
-                        );
+        $goods = Dever::db('shop/buy_order_goods')->select(array('order_id' => $info['id']));
 
-                        $body[] = $d;
+        $shop = Dever::db('shop/info')->find($info['type_id']);
 
-                        $i++;
-                    }
-                }
-                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 = '';
-                        }
-                        $d = array
-                        (
-                            $i+1,
-                            $goods_info['code'],
-                            $goods_info['name'] . $sku,
-                            '无',
-                            $v['num'],
-                            $goods_info['unit'],
-                            $v['p_price'] * $v['num'],
-                        );
+        list($data, $source) = $this->assign($goods, $info, $shop, true);
 
-                        $body[] = $d;
+        if ($data) {
 
-                        $i++;
+            $head = array('序号', '商品编号', '商品名称', '供货商', '订货总数量', '商品计量单位', '订货单总金额');
+            $body = array();
+            $i = 0;
+            foreach ($data as $k => $v) {
+                foreach ($v as $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 = '';
                     }
-                }
-                $result['商品拆单'] = array
-                (
-                    'type' => 'table',
-                    'content' => array
+                    $d = array
                     (
-                        'head' => $head,
-                        'body' => $body,
-                    )
-                );
-            }
-        } else {
-            $url = Dever::url('lib/buy.refund_commit?json=1', 'mshop');
-            if (!$info['refund_cash']) {
-                $info['refund_cash'] = 0;
-            }
+                        $i+1,
+                        $goods_info['code'],
+                        $goods_info['name'] . $sku,
+                        $this->getSelect($v1['source_id'], $v1['order_goods_id']),
+                        $v1['num'],
+                        $goods_info['unit'],
+                        $v1['p_price'] * $v1['num'],
+                    );
 
-            if ($info['refund_cash'] > 0 && $tk) {
-                
-                if ($type == 2) {
-                    $info['refund_cash'] = $info['refund_p_cash'];
-                }
-                if ($tk['process'] == 1) {
-                    $process = '<a href="javascript:;" onclick="audit('.$tk['id'].', 2, \''.$url.'\')" class="layui-btn layui-btn-primary">通过</a><a href="javascript:;" onclick="audit('.$tk['id'].', 3, \''.$url.'\')" class="layui-btn layui-btn-danger">驳回</a>';
-                } else {
-                    $process = $tk_process[$tk['process']];
+                    $body[] = $d;
+
+                    $i++;
                 }
-                $desc = array();
-                $desc['退款原因'] = $tk['desc'];
-                $desc['退款图片'] = '暂无';
-                if ($tk['pic']) {
-                    $pic = explode(',', $tk['pic']);
-                    $tk['pic'] = '';
-                    foreach ($pic as $k => $v) {
-                        $tk['pic'] .= '<a href="'.$v.'" target="_blank"><img src="'.$v.'" width="100"/></a>';
+            }
+            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 = '';
                     }
-                }
-    ;
-                $tk['cdate'] = date('Y-m-d H:i', $tk['cdate']);
-                $result['退款信息'] = array
-                (
-                    'type' => 'info',
-                    'content' => array
+                    $d = array
                     (
-                        array
-                        (
-                            array('退款金额', $info['refund_cash']),
-                            array('数量', $info['num']),
-                            array('退款进度', $process),
-                        ),
+                        $i+1,
+                        $goods_info['code'],
+                        $goods_info['name'] . $sku,
+                        $this->getSelect(false, $v['id']),
+                        $v['num'],
+                        $goods_info['unit'],
+                        $v['p_price'] * $v['num'],
+                    );
 
-                        array
-                        (
-                            array('申请时间', $tk['cdate']),
-                            array('申请原因', $tk['desc']),
-                            array('图片', $tk['pic']),
-                        ),
-                    ),
-                );
-            }
+                    $body[] = $d;
 
-            $info['ps_info'] = Dever::db('shop/buy_order_ps')->find(array('order_id' => $info['id']));
-            if ($info['ps_info']) {
-                $info['ps_info']['service'] = Dever::array_decode($info['ps_info']['service']);
-                $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']);
-                } else {
-                    $info['ps_info']['ydate'] = '无';
+                    $i++;
                 }
+            }
+            $result['商品拆单'] = array
+            (
+                'type' => 'table',
+                'content' => array
+                (
+                    'head' => $head,
+                    'body' => $body,
+                )
+            );
+        }
+    }
 
-                $status = Dever::db('shop/buy_order_ps')->config['status'];
-                $info['ps_info']['status_name'] = $status[$info['ps_info']['status']];
-                
-                $service = array();
-                if ($info['ps_info']['service']) {
-                    foreach ($info['ps_info']['service'] as $k => $v) {
-                        if (isset($v['order_num']) && $v['order_num']) {
-                            $info['ps_info']['service'][$k]['service_name'] = '供应商自送';
-                            if ($v['service_id'] > 0) {
-                                $service_info = Dever::db('shop/service')->find($v['service_id']);
-                                $info['ps_info']['service'][$k]['service_name'] = $service_info['name'];
-                            }
+    private function show_refund($info, &$result)
+    {
+        $tk = Dever::db('shop/buy_order_refund')->find(array('order_id' => $info['id'], 'type' => 1));
+        $url = Dever::url('lib/buy.refund_commit?json=1', 'mshop');
+        if (!$info['refund_cash']) {
+            $info['refund_cash'] = 0;
+        }
 
-                            $service[] = array
-                            (
-                                array('名称', $info['ps_info']['service'][$k]['service_name']),
-                                array('单号', isset($v['order_num']) ? $v['order_num'] : ''),
-                            );
-                        }
-                    }
+        if ($info['refund_cash'] > 0 && $tk) {
+            
+            if ($type == 2) {
+                $info['refund_cash'] = $info['refund_p_cash'];
+            }
+            if ($tk['process'] == 1) {
+                $process = '<a href="javascript:;" onclick="audit('.$tk['id'].', 2, \''.$url.'\')" class="layui-btn layui-btn-primary">通过</a><a href="javascript:;" onclick="audit('.$tk['id'].', 3, \''.$url.'\')" class="layui-btn layui-btn-danger">驳回</a>';
+            } else {
+                $tk_process = Dever::db('shop/buy_order_refund')->config['process'];
+                $process = $tk_process[$tk['process']];
+            }
+            $desc = array();
+            $desc['退款原因'] = $tk['desc'];
+            $desc['退款图片'] = '暂无';
+            if ($tk['pic']) {
+                $pic = explode(',', $tk['pic']);
+                $tk['pic'] = '';
+                foreach ($pic as $k => $v) {
+                    $tk['pic'] .= '<a href="'.$v.'" target="_blank"><img src="'.$v.'" width="100"/></a>';
                 }
-
-                $result['物流信息'] = array
+            }
+;
+            $tk['cdate'] = date('Y-m-d H:i', $tk['cdate']);
+            $result['退款信息'] = array
+            (
+                'type' => 'info',
+                'content' => array
                 (
-                    'type' => 'info',
-                    'content' => array
+                    array
                     (
-                        array
-                        (
-                            array('发货时间', $info['ps_info']['cdate']),
-                            array('收货时间', $info['ps_info']['ydate']),
-                            array('查单', '<a href="https://www.kuaidi100.com/?from=openv" target="_blank">点此手动查单</a>'),
-                        ),
+                        array('退款金额', $info['refund_cash']),
+                        array('数量', $info['num']),
+                        array('退款进度', $process),
                     ),
-                );
-                $result['物流信息']['content'] = array_merge($result['物流信息']['content'], $service);
-                /*
-                if ($noprice == 1) {
-                    $result['物流信息'] = array
-                    (
-                        'type' => 'info',
-                        'content' => array
-                        (
-                            array
-                            (
-                                array('名称', $info['ps_info']['service_name']),
-                                array('单号', $info['ps_info']['order_num']),
-                            ),
-
-                            array
-                            (
-                                array('数量', $info['ps_info']['num']),
-                                array('重量', $info['ps_info']['zl']),
-                                array('体积', $info['ps_info']['tj']),
-                            ),
-
-                            array
-                            (
-                                array('发货时间', $info['ps_info']['cdate']),
-                                array('收货时间', $info['ps_info']['ydate']),
-                            ),
-                        ),
-                    );
-                } else {
 
-                    $result['物流信息'] = array
+                    array
                     (
-                        'type' => 'info',
-                        'content' => array
-                        (
-                            array
-                            (
-                                array('名称', $info['ps_info']['service_name']),
-                                array('单号', $info['ps_info']['order_num']),
-                                array('费用', $info['ps_info']['price']),
-                            ),
-
-                            array
-                            (
-                                array('配货员', $info['ps_info']['phy']),
-                                array('打包员', $info['ps_info']['dby']),
-                            ),
-
-                            array
-                            (
-                                array('数量', $info['ps_info']['num']),
-                                array('重量', $info['ps_info']['zl']),
-                                array('体积', $info['ps_info']['tj']),
-                            ),
-
-                            array
-                            (
-                                array('发货时间', $info['ps_info']['cdate']),
-                                array('收货时间', $info['ps_info']['ydate']),
-                            ),
-                        ),
-                    );
-                }
-                */
+                        array('申请时间', $tk['cdate']),
+                        array('申请原因', $tk['desc']),
+                        array('图片', $tk['pic']),
+                    ),
+                ),
+            );
+        }
+    }
+
+    # 获取配送信息
+    private function show_ps($info, &$result)
+    {
+        $info['ps_info'] = Dever::db('shop/buy_order_ps')->find(array('order_id' => $info['id']));
+        if ($info['ps_info']) {
+            $info['ps_info']['service'] = Dever::array_decode($info['ps_info']['service']);
+            $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']);
+            } else {
+                $info['ps_info']['ydate'] = '无';
             }
 
+            $status = Dever::db('shop/buy_order_ps')->config['status'];
+            $info['ps_info']['status_name'] = $status[$info['ps_info']['status']];
             
-            $body = array();
-            $body_total = array();
-            $body_total['price'] = 0;
-            $body_total['num'] = 0;
-            $goods = Dever::db('shop/buy_order_goods')->select(array('order_id' => $info['id']));
-            $goods_status = Dever::db('shop/buy_order_goods')->config['status'];
-
-            $refund_body = array();
-            $refund_body_total = array();
-            $refund_body_total['price'] = 0;
-            $refund_body_total['num'] = 0;
-            foreach ($goods as $k => $v) {
-                if ($type == 2) {
-                    $v['price'] = $v['p_price'];
-                }
-                $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v['goods_id'], $v['sku_id']);
-                $status = $goods_status[$v['status']];
+            $service = array();
+            if ($info['ps_info']['service']) {
+                foreach ($info['ps_info']['service'] as $k => $v) {
+                    if (isset($v['order_num']) && $v['order_num']) {
+                        $info['ps_info']['service'][$k]['service_name'] = '供应商自送';
+                        if ($v['service_id'] > 0) {
+                            $service_info = Dever::db('shop/service')->find($v['service_id']);
+                            $info['ps_info']['service'][$k]['service_name'] = $service_info['name'];
+                        }
 
-                $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) {
-                    if ($type == 1) {
-                        $status = '申请' . $tk_status[$tk['status']];
-                    } else {
-                        $status = '已上报';
+                        $service[] = array
+                        (
+                            array('名称', $info['ps_info']['service'][$k]['service_name']),
+                            array('单号', isset($v['order_num']) ? $v['order_num'] : ''),
+                        );
                     }
+                }
+            }
 
-                    if ($type == 1) {
-                        $desc = array();
-                        $desc['退款原因'] = $tk['desc'];
-                        $desc['退款图片'] = '暂无';
-                        if ($tk['pic']) {
-                            $desc['退款图片'] = '';
-                            $pic = explode(',', $tk['pic']);
-                            foreach ($pic as $k1 => $v1) {
-                                $desc['退款图片'] .= '<a href="'.$v1.'" target="_blank"><img src="'.$v1.'" width="100"/></a>';
-                            }
-                        }
-                        $status .= '<div style="width:300px"><table><tr><td><a href="javascript:showAlert($(\'#desc_content\').html());">点此查看原因</a><span id="desc_content" style="display:none">'.Dever::table($desc).'</span><td>';
+            $result['物流信息'] = array
+            (
+                'type' => 'info',
+                'content' => array
+                (
+                    array
+                    (
+                        array('发货时间', $info['ps_info']['cdate']),
+                        array('收货时间', $info['ps_info']['ydate']),
+                        array('查单', '<a href="https://www.kuaidi100.com/?from=openv" target="_blank">点此手动查单</a>'),
+                    ),
+                ),
+            );
+            $result['物流信息']['content'] = array_merge($result['物流信息']['content'], $service);
+        }
+    }
 
-                        $status .= '<td><button href="javascript:;" style="width:80px" onclick="audit('.$tk['id'].', 2, \''.$url.'\')" class="layui-btn layui-btn-primary">通过</button></td><td><button href="javascript:;" onclick="audit('.$tk['id'].', 3, \''.$url.'\')"  style="width:80px" class="layui-btn layui-btn-danger">驳回</button></td></tr></table></div>';
-                    }
-                } elseif ($type > 1 && (!$tk || ($tk && $tk['process'] == 3))) {
+    # 获取商品清单
+    private function show_goods($info, &$result, $type, $noprice)
+    {
+        $body = array();
+        $body_total = array();
+        $body_total['price'] = 0;
+        $body_total['num'] = 0;
+        $goods = Dever::db('shop/buy_order_goods')->select(array('order_id' => $info['id']));
+        $goods_status = Dever::db('shop/buy_order_goods')->config['status'];
+        $tk_status = Dever::db('shop/buy_order_refund')->config['status'];
 
-                    //$tui = Dever::url('lib/buy.refund_apply_info_one_commit?json=1', 'mshop');
-                    if ($type == 2) {
-                        $tui = Dever::url('order_tui?order_goods_id=' . $v['id'] . '&order_id=' . $info['id'] . '&type=13&type_id=' . $info['source_id'], 'factory');
-                    } else {
-                        if ($info['source_type'] == 3) {
-                            $tui = Dever::url('order_tui?order_goods_id=' . $v['id'] . '&order_id=' . $info['id'] . '&type=13&type_id=' . $info['source_id'], 'store');
-                        } else {
-                            $tui = Dever::url('order_tui?order_goods_id=' . $v['id'] . '&order_id=' . $info['id'] . '&type=12&type_id=' . $info['source_id'], 'store');
-                        }
-                        
-                    }
-                    if ($info['status'] == 3) {
-                        $status = '<a href="javascript:;" onclick="fastEdit($(this), \''.$tui.'\', \'缺货退款\', \'\', 1)" class="layui-btn">缺货退款</a>';
-                    } elseif ($info['status'] == 4) {
-                        $status = '<a href="javascript:;" onclick="fastEdit($(this), \''.$tui.'\', \'报损退款\', \'\', 1)" class="layui-btn">报损退款</a>';
-                    }
-                }
+        $refund_body = array();
+        $refund_body_total = array();
+        $refund_body_total['price'] = 0;
+        $refund_body_total['num'] = 0;
+        foreach ($goods as $k => $v) {
+            if ($type == 2) {
+                $v['price'] = $v['p_price'];
+            }
+            $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v['goods_id'], $v['sku_id']);
+            $status = $goods_status[$v['status']];
 
-                if (isset($goods_info['sku'])) {
-                    $sku = '[' . $goods_info['sku']['string'] . ']';
+            $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) {
+                if ($type == 1) {
+                    $status = '申请' . $tk_status[$tk['status']];
                 } else {
-                    $sku = '';
+                    $status = '已上报';
                 }
 
-                $d = array
-                (
-                    'pic' => $goods_info['cover'],
-                    'name' => $goods_info['name'],
-                    'sku' => $sku,
-                    'price' => $v['price'],
-                    'num' => $v['num'] . $goods_info['unit'],
-                    'status' => $status,
-                );
+                if ($type == 1) {
+                    $desc = array();
+                    $desc['退款原因'] = $tk['desc'];
+                    $desc['退款图片'] = '暂无';
+                    if ($tk['pic']) {
+                        $desc['退款图片'] = '';
+                        $pic = explode(',', $tk['pic']);
+                        foreach ($pic as $k1 => $v1) {
+                            $desc['退款图片'] .= '<a href="'.$v1.'" target="_blank"><img src="'.$v1.'" width="100"/></a>';
+                        }
+                    }
+                    $status .= '<div style="width:300px"><table><tr><td><a href="javascript:showAlert($(\'#desc_content\').html());">点此查看原因</a><span id="desc_content" style="display:none">'.Dever::table($desc).'</span><td>';
 
-                if ($goods_info['price_type'] > 2) {
-                    $d['goods'] = $goods_info['goods'];
+                    $status .= '<td><button href="javascript:;" style="width:80px" onclick="audit('.$tk['id'].', 2, \''.$url.'\')" class="layui-btn layui-btn-primary">通过</button></td><td><button href="javascript:;" onclick="audit('.$tk['id'].', 3, \''.$url.'\')"  style="width:80px" class="layui-btn layui-btn-danger">驳回</button></td></tr></table></div>';
                 }
+            } elseif ($type > 1 && (!$tk || ($tk && $tk['process'] == 3))) {
 
-                if ($tk && $v['status'] == 3 && $tk['status'] != 3) {
-                    $d['status'] = $tk_status[$tk['status']];
-                    if ($noprice == 1) {
-                        unset($d['price']);
-                    }
-                    $refund_body[] = $d;
-                    $price = $v['price']*$v['num'];
-                    $refund_body_total['price'] += $price;
-                    $refund_body_total['num'] += $v['num'];
+                //$tui = Dever::url('lib/buy.refund_apply_info_one_commit?json=1', 'mshop');
+                if ($type == 2) {
+                    $tui = Dever::url('order_tui?order_goods_id=' . $v['id'] . '&order_id=' . $info['id'] . '&type=13&type_id=' . $info['source_id'], 'factory');
                 } else {
-                    if ($noprice == 1) {
-                        unset($d['price']);
+                    if ($info['source_type'] == 3) {
+                        $tui = Dever::url('order_tui?order_goods_id=' . $v['id'] . '&order_id=' . $info['id'] . '&type=13&type_id=' . $info['source_id'], 'store');
+                    } else {
+                        $tui = Dever::url('order_tui?order_goods_id=' . $v['id'] . '&order_id=' . $info['id'] . '&type=12&type_id=' . $info['source_id'], 'store');
                     }
-                    $body[] = $d;
-                    $price = $v['price']*$v['num'];
-                    $body_total['price'] += $price;
-                    $body_total['num'] += $v['num'];
+                    
+                }
+                if ($info['status'] == 3) {
+                    $status = '<a href="javascript:;" onclick="fastEdit($(this), \''.$tui.'\', \'缺货退款\', \'\', 1)" class="layui-btn">缺货退款</a>';
+                } elseif ($info['status'] == 4) {
+                    $status = '<a href="javascript:;" onclick="fastEdit($(this), \''.$tui.'\', \'报损退款\', \'\', 1)" class="layui-btn">报损退款</a>';
                 }
             }
 
-            if ($body) {
+            if (isset($goods_info['sku'])) {
+                $sku = '[' . $goods_info['sku']['string'] . ']';
+            } else {
+                $sku = '';
+            }
+
+            $d = array
+            (
+                'pic' => $goods_info['cover'],
+                'name' => $goods_info['name'],
+                'sku' => $sku,
+                'price' => $v['price'],
+                'num' => $v['num'] . $goods_info['unit'],
+                'status' => $status,
+            );
 
-                if ($refund_body_total['price']) {
-                    $body_total['set_price'] = $body_total['price'] - $refund_body_total['price'];
-                }
-                if ($refund_body_total['num']) {
-                    $body_total['set_num'] = $body_total['num'] - $refund_body_total['num'];
-                }
+            if ($goods_info['price_type'] > 2) {
+                $d['goods'] = $goods_info['goods'];
+            }
 
+            if ($tk && $v['status'] == 3 && $tk['status'] != 3) {
+                $d['status'] = $tk_status[$tk['status']];
                 if ($noprice == 1) {
-                    unset($body_total['price']);
-                    unset($body_total['set_price']);
+                    unset($d['price']);
                 }
-                
-                $result['商品清单'] = array
-                (
-                    'type' => 'list',
-                    'content' => $body,
-                    'total' => $body_total,
-                );
+                $refund_body[] = $d;
+                $price = $v['price']*$v['num'];
+                $refund_body_total['price'] += $price;
+                $refund_body_total['num'] += $v['num'];
+            } else {
+                if ($noprice == 1) {
+                    unset($d['price']);
+                }
+                $body[] = $d;
+                $price = $v['price']*$v['num'];
+                $body_total['price'] += $price;
+                $body_total['num'] += $v['num'];
             }
+        }
 
-            if ($refund_body) {
+        if ($body) {
 
-                if ($noprice == 1) {
-                    unset($refund_body_total['price']);
-                }
+            if ($refund_body_total['price']) {
+                $body_total['set_price'] = $body_total['price'] - $refund_body_total['price'];
+            }
+            if ($refund_body_total['num']) {
+                $body_total['set_num'] = $body_total['num'] - $refund_body_total['num'];
+            }
 
-                $result['缺货与报损商品'] = array
-                (
-                    'type' => 'list',
-                    'content' => $refund_body,
-                    'total' => $refund_body_total,
-                );
+            if ($noprice == 1) {
+                unset($body_total['price']);
+                unset($body_total['set_price']);
             }
+            
+            $result['商品清单'] = array
+            (
+                'type' => 'list',
+                'content' => $body,
+                'total' => $body_total,
+            );
+        }
 
-            $search_option_type = Dever::input('search_option_type');
-            if ($cash_type == 1) {
-                if ($search_option_type == 1) {
-                    # 门店结算单
-                    $cash_order = Dever::db('cash/order')->select(array('type' => $info['type'], 'type_id' => $info['type_id'], 'source_order_id' => $info['id']));
+        if ($refund_body) {
 
-                    $col = 'cash';
+            if ($noprice == 1) {
+                unset($refund_body_total['price']);
+            }
 
-                } elseif ($search_option_type == 2) {
-                    # 工厂结算单
-                    $cash_order = Dever::db('cash/order')->select(array('source_type' => $info['source_type'], 'source_id' => $info['source_id'], 'source_order_id' => $info['id']));
+            $result['缺货与报损商品'] = array
+            (
+                'type' => 'list',
+                'content' => $refund_body,
+                'total' => $refund_body_total,
+            );
+        }
+    }
 
-                    $col = 'p_cash';
-                } elseif ($search_option_type == 3) {
-                    # 仓库结算单
-                    $cash_order = Dever::db('cash/order')->select(array('source_type' => $info['source_type'], 'source_id' => $info['source_id'], 'source_order_id' => $info['id']));
+    # 获取对账清单
+    private function show_dz($info, &$result, $noprice)
+    {
+        $cash_type = Dever::input('cash', 1);
+        $search_option_type = Dever::input('search_option_type');
+        if ($cash_type == 1) {
+            if ($search_option_type == 1) {
+                # 门店结算单
+                $cash_order = Dever::db('cash/order')->select(array('type' => $info['type'], 'type_id' => $info['type_id'], 'source_order_id' => $info['id']));
 
-                    $col = 'num';
-                }
-            }
-            
+                $col = 'cash';
 
-            if (isset($cash_order) && $cash_order) {
-                $head = array('序号', '结算单号', '数量', '金额', '结算类型', '入账状态', '审核状态', '结算时间', '审核备注', '管理');
+            } elseif ($search_option_type == 2) {
+                # 工厂结算单
+                $cash_order = Dever::db('cash/order')->select(array('source_type' => $info['source_type'], 'source_id' => $info['source_id'], 'source_order_id' => $info['id']));
 
-                if ($search_option_type == 3 || $noprice == 1) {
-                    unset($head[3]);
-                }
+                $col = 'p_cash';
+            } elseif ($search_option_type == 3) {
+                # 仓库结算单
+                $cash_order = Dever::db('cash/order')->select(array('source_type' => $info['source_type'], 'source_id' => $info['source_id'], 'source_order_id' => $info['id']));
 
-                $body = array();
-                $config = Dever::db('cash/order')->config;
-                foreach ($cash_order as $k => $v) {
-                    $cdate = date('Y-m-d H:i', $v['cdate']);
-                    $fdate = $v['fdate'] ? date('Y-m-d H:i', $v['fdate']) : '';
-                    $operdate = $v['operdate'] ? date('Y-m-d H:i', $v['operdate']) : '';
-                    $cash = $v[$col];
-
-                    $url = Dever::url('project/database/list?project=shop&table=buy_order_goods&order_id='.$v['source_order_id'].'&page_type=1', 'manage');
-                    $v['source_order_num'] = '<a href="'.$url.'" style="color:blue">'.$v['source_order_num'].'</a>';
-
-                    $m = '';
-                    if ($v['audit'] == 1 && $v['audit_type'] == 2) {
-                        $url = Dever::url('project/database/update?project=cash&table=order&where_id='.$v['id'].'&col=audit,desc', 'manage');
-                        $m = '<a href="javascript:;" onclick="fastEdit($(this), \''.$url.'\', \'审核\', \'\', 1)" class="layui-btn">审核</a>';
-                    }
+                $col = 'num';
+            }
+        }
+        
 
-                    $d = array
-                    (
-                        $k+1,
-                        $v['order_num'],
-                        $v['num'],
-                        $cash,
-                        $config['config_jstype'][$v['jstype']],
-                        $config['config_status'][$v['status']],
-                        $config['config_audit'][$v['audit']],
-                        $operdate,
-                        $v['desc'],
-                        $m,
-                    );
+        if (isset($cash_order) && $cash_order) {
+            $head = array('序号', '结算单号', '数量', '金额', '结算类型', '入账状态', '审核状态', '结算时间', '审核备注', '管理');
 
-                    if ($search_option_type == 3 || $noprice == 1) {
-                        unset($d[3]);
-                    }
-                    $body[] = $d;
+            if ($search_option_type == 3 || $noprice == 1) {
+                unset($head[3]);
+            }
+
+            $body = array();
+            $config = Dever::db('cash/order')->config;
+            foreach ($cash_order as $k => $v) {
+                $cdate = date('Y-m-d H:i', $v['cdate']);
+                $fdate = $v['fdate'] ? date('Y-m-d H:i', $v['fdate']) : '';
+                $operdate = $v['operdate'] ? date('Y-m-d H:i', $v['operdate']) : '';
+                $cash = $v[$col];
+
+                $url = Dever::url('project/database/list?project=shop&table=buy_order_goods&order_id='.$v['source_order_id'].'&page_type=1', 'manage');
+                $v['source_order_num'] = '<a href="'.$url.'" style="color:blue">'.$v['source_order_num'].'</a>';
+
+                $m = '';
+                if ($v['audit'] == 1 && $v['audit_type'] == 2) {
+                    $url = Dever::url('project/database/update?project=cash&table=order&where_id='.$v['id'].'&col=audit,desc', 'manage');
+                    $m = '<a href="javascript:;" onclick="fastEdit($(this), \''.$url.'\', \'审核\', \'\', 1)" class="layui-btn">审核</a>';
                 }
 
-                $result['对账清单'] = array
+                $d = array
                 (
-                    'type' => 'table',
-                    'content' => array
-                    (
-                        'head' => $head,
-                        'body' => $body,
-                    )
+                    $k+1,
+                    $v['order_num'],
+                    $v['num'],
+                    $cash,
+                    $config['config_jstype'][$v['jstype']],
+                    $config['config_status'][$v['status']],
+                    $config['config_audit'][$v['audit']],
+                    $operdate,
+                    $v['desc'],
+                    $m,
                 );
-                    
-            }
-        }
 
-        $head = array
-        (
-            'name' => '基本信息',
-            'btn' => $button,
-        );
-        $html = Dever::show($head, $result);
+                if ($search_option_type == 3 || $noprice == 1) {
+                    unset($d[3]);
+                }
+                $body[] = $d;
+            }
 
-        return $html;
+            $result['对账清单'] = array
+            (
+                'type' => 'table',
+                'content' => array
+                (
+                    'head' => $head,
+                    'body' => $body,
+                )
+            );
+        }
     }
 
     # 发货