<?php

namespace Shop\Src;

use Dever;

class Excel
{
    # 门店零售单
    public function sell_order($data)
    {
        if (!$data) {
            Dever::alert('无导出数据');
        }
        $file = Dever::input('excel_name');

        $header = array('门店编号', '门店名称', '门店类型', '订单号', '购买人', '商品编码', '商品名称', '规格型号', '商品单价', '购买数量', '商品合计金额', '配送类型', '订单类型', '下单时间', '付款时间', '发货时间', '订单合计金额', '订单实付金额', '已退订单金额', '支付渠道', '订单状态');

        $table = 'shop/info';

        $body = array();
        $status = Dever::db('shop/sell_order')->config['status_manage'];
        $method = Dever::db('shop/sell_order')->config['method'];
        $pay_method = Dever::db('shop/sell_order')->config['pay_method'];
        $pay_type = Dever::db('shop/sell_order')->config['pay_type'];

        $info_type = Dever::db($table)->config['config_type'];
        foreach ($data as $k => $v) {
            if (!is_array($v)) {
                continue;
            }
            $info = Dever::db($table)->find($v['shop_id']);
            $goods = Dever::db('shop/sell_order_goods')->select(array('order_id' => $v['id']));
            $ps = Dever::db('shop/sell_order_ps')->find(array('order_id' => $v['id']));
            $cdate = strstr($v['cdate'], '-') ? $v['cdate'] : date('Y-m-d H:i', $v['cdate']);
            $paydate = isset($v['paydate']) && $v['paydate'] ? date('Y-m-d H:i', $v['paydate']) : '-';
            $operdate = ($ps && $ps['cdate']) ? date('Y-m-d H:i', $ps['cdate']) : '-';

            $total_cash = Dever::load("shop/lib/manage.getTotalCash", $v['id']);
            $v['refund_cash'] = $v['refund_cash'] ? $v['refund_cash'] : 0;
            
            $user = Dever::load("shop/lib/manage.user", $v['id']);
            foreach ($goods as $k1 => $v1) {

                $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v1['goods_id'], $v1['sku_id']);
                if (isset($goods_info['sku'])) {
                    $sku = $goods_info['sku']['string'];
                } else {
                    $sku = '';
                }

                if ($v['status'] == 8 || $v1['status'] == 3) {
                    $num = $v1['num'];
                    $v['refund_cash'] = $v1['price']*$v1['num'];
                    $refund_status = '已退款';
                } else {
                    $num = '0';
                    $v['refund_cash'] = '0';
                    $refund_status = '未退款';
                }

                $d = array
                (
                    $info['sid'],
                    $info['name'],
                    $info_type[$info['type']],

                    $v['order_num'],
                    $user,

                    $goods_info['code'],
                    $goods_info['name'],
                    $sku,
                    $v1['price'],
                    $v1['num'],
                    $v1['price']*$v1['num'],


                    $method[$v['method']],
                    $pay_method[$v['pay_method']],
                    $cdate,
                    $paydate,
                    $operdate,

                    $total_cash,
                    $v['price'],
                    $v['refund_cash'],
                    $pay_type[$v['pay_type']],
                    $status[$v['status']],
                );

                $body[] = $d;
            }
        }

        Dever::excelExport($body, $header, $file);
    }

    # 平台零售订单
    public function p_sell_order($data)
    {
        if (!$data) {
            Dever::alert('无导出数据');
        }
        $file = Dever::input('excel_name');

        $header = array('订单号', '收件人', '收件人手机', '收件人地址', '发货仓库', '商品编码', '商品名称', '规格型号', '商品单价', '购买数量', '商品合计金额', '下单时间', '付款时间', '发货时间', '订单总数量', '订单总金额', '订单状态', '退款状态', '退款金额');

        $table = 'shop/info';

        $body = array();
        $status = Dever::db('shop/sell_order')->config['status_manage'];

        $info_type = Dever::db($table)->config['config_type'];
        foreach ($data as $k => $v) {
            if (!is_array($v)) {
                continue;
            }
            $info = Dever::db($table)->find($v['shop_id']);
            if ($v['store_id']) {
                $store = Dever::db('store/info')->find($v['store_id']);
            } else {
                $store['name'] = '';
            }
            
            $goods = Dever::db('shop/sell_order_goods')->select(array('order_id' => $v['id']));
            $ps = Dever::db('shop/sell_order_ps')->find(array('order_id' => $v['id']));
            $cdate = strstr($v['cdate'], '-') ? $v['cdate'] : date('Y-m-d H:i', $v['cdate']);
            $paydate = isset($v['paydate']) && $v['paydate'] ? date('Y-m-d H:i', $v['paydate']) : '-';
            $operdate = ($ps && $ps['cdate']) ? date('Y-m-d H:i', $ps['cdate']) : '-';
            
            $refund_status = Dever::load("shop/lib/manage.buyInfoRefundStatus", $v['id'], 'sell_order');
            $v['refund_cash'] = $v['refund_cash'] ? $v['refund_cash'] : 0;
            $address = Dever::load('passport/address')->getOne($v['uid'], $v['address_id']);
            foreach ($goods as $k1 => $v1) {

                $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v1['goods_id'], $v1['sku_id']);
                if (isset($goods_info['sku'])) {
                    $sku = $goods_info['sku']['string'];
                } else {
                    $sku = '';
                }

                if ($v['status'] == 8 || $v1['status'] == 3) {
                    $num = $v1['num'];
                    $v['refund_cash'] = $v1['price']*$v1['num'];
                    $refund_status = '已退款';
                } else {
                    $num = '0';
                    $v['refund_cash'] = '0';
                    $refund_status = '未退款';
                }

                $d = array
                (
                    $v['order_num'],
                    isset($address['contact']) ? $address['contact'] : '',
                    isset($address['mobile']) ? $address['mobile'] : '',
                    isset($address['address_info']) ? $address['address_info'] : '',
                    $store['name'],

                    $goods_info['code'],
                    $goods_info['name'],
                    $sku,
                    $v1['price'],
                    $v1['num'],
                    $v1['price']*$v1['num'],

                    $cdate,
                    $paydate,
                    $operdate,

                    $v['num'],
                    $v['price'],
                    $status[$v['status']],
                    $refund_status,
                    $v['refund_cash'],
                );

                $body[] = $d;
            }
        }

        Dever::excelExport($body, $header, $file);
    }

    # 门店订货单
    public function buy_order($data)
    {
        if (!$data) {
            Dever::alert('无导出数据');
        }
        $file = Dever::input('excel_name');


        $header = array('门店编号', '门店名称', '门店类型', '供货商', '订货单号', '订货总数量', '订货单总金额', '商品编码', '商品名称', '规格型号', '订货单价', '订货数量', '商品合计金额', '订货日期', '订货单状态', '退款状态', '退款金额');

        $table = 'shop/info';

        $body = array();
        $status = Dever::db('shop/buy_order')->config['status'];
        //$refund_status = Dever::db('shop/buy_order')->config['refund_status'];
        $info_type = Dever::db($table)->config['config_type'];

        foreach ($data as $k => $v) {
            if (!is_array($v)) {
                continue;
            }
            $info = Dever::db($table)->find($v['type_id']);
            $goods = Dever::db('shop/buy_order_goods')->select(array('order_id' => $v['id']));
            $cdate = strstr($v['cdate'], '-') ? $v['cdate'] : date('Y-m-d H:i', $v['cdate']);
            $refund_status = Dever::load("shop/lib/manage.buyInfoRefundStatus", $v['id']);

            $source = Dever::load("shop/lib/manage.buyInfo", $v['source_type'], $v['source_id']);
            foreach ($goods as $k1 => $v1) {

                $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v1['goods_id'], $v1['sku_id']);
                if (isset($goods_info['sku'])) {
                    $sku = $goods_info['sku']['string'];
                } else {
                    $sku = '';
                }

                if ($v['status'] == 8 || $v1['status'] == 3) {
                    $num = $v1['num'];
                    $v['refund_cash'] = $v1['price']*$v1['num'];
                    $refund_status = '已退款';
                } else {
                    $num = '0';
                    $v['refund_cash'] = '0';
                    $refund_status = '未退款';
                }

                $d = array
                (
                    $info['sid'],
                    $info['name'],
                    $info_type[$info['type']],

                    $source,
                    $v['order_num'],
                    $v['num'],
                    $v['price'],

                    $goods_info['code'],
                    $goods_info['name'],
                    $sku,
                    $v1['price'],
                    $v1['num'],
                    $v1['price']*$v1['num'],

                    $cdate,
                    $status[$v['status']],
                    $refund_status,
                    $v['refund_cash'],
                );

                $body[] = $d;
            }
        }

        Dever::excelExport($body, $header, $file);
    }

    # 仓库订货单
    public function store_buy_order($data)
    {
        if (!$data) {
            Dever::alert('无导出数据');
        }
        $file = Dever::input('excel_name');


        $header = array('仓库名称', '供货商', '订货单号', '订货总数量', '入库单价', '商品编码', '商品名称', '规格型号', '商品订货数量', '订货日期', '发货日期', '收货日期', '订货单状态', '已退商品数量');

        $table = 'store/info';

        $body = array();
        $status = Dever::db('shop/buy_order')->config['status'];
        //$refund_status = Dever::db('shop/buy_order')->config['refund_status'];

        foreach ($data as $k => $v) {
            if (!is_array($v)) {
                continue;
            }
            $info = Dever::db($table)->find($v['type_id']);
            $goods = Dever::db('shop/buy_order_goods')->select(array('order_id' => $v['id']));
            $ps = Dever::db('shop/buy_order_ps')->find(array('order_id' => $v['id']));
            $cdate = strstr($v['cdate'], '-') ? $v['cdate'] : date('Y-m-d H:i', $v['cdate']);
            $fdate = ($ps && $ps['cdate']) ? date('Y-m-d H:i', $ps['cdate']) : '-';
            $ydate = ($ps && $ps['ydate']) ? date('Y-m-d H:i', $ps['ydate']) : '-';
            $num = Dever::load("shop/lib/manage.buyInfoRefundNum", $v['id']);
            $refund_status = Dever::load("shop/lib/manage.buyInfoRefundStatus", $v['id']);
            $v['refund_cash'] = $v['refund_cash'] ? $v['refund_cash'] : 0;

            $source = Dever::load("shop/lib/manage.buyInfo", $v['source_type'], $v['source_id']);
            foreach ($goods as $k1 => $v1) {

                $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v1['goods_id'], $v1['sku_id']);
                if (isset($goods_info['sku'])) {
                    $sku = $goods_info['sku']['string'];
                } else {
                    $sku = '';
                }

                if ($v['status'] == 8 || $v1['status'] == 3) {
                    $num = $v1['num'];
                    $refund_status = '已退款';
                } else {
                    $num = '0';
                    $refund_status = '未退款';
                }

                if ($v['source_type'] == 2) {
                    $v1['p_price'] = 0;
                }

                $d = array
                (
                    $info['name'],
                    $source,
                    $v['order_num'],
                    $v['num'],
                    $v1['p_price'],

                    $goods_info['code'],
                    $goods_info['name'],
                    $sku,
                    $v1['num'],

                    $cdate,
                    $fdate,
                    $ydate,
                    $status[$v['status']],
                    $num,
                );

                $body[] = $d;
            }
        }

        Dever::excelExport($body, $header, $file);
    }

    # 仓库发货单
    public function store_buy_order_fa($data)
    {
        if (!$data) {
            Dever::alert('无导出数据');
        }
        $file = Dever::input('excel_name');


        $header = array('仓库名称', '门店编号', '门店名称', '门店类型', '订货单号', '订货总数量', '订货单总金额', '商品编码', '商品名称', '规格型号', '订货单价', '订货数量', '商品合计金额', '订货日期', '发货日期', '订货单状态', '退款状态', '已退商品数量', '退款金额');

        $table = 'shop/info';

        $body = array();
        $status = Dever::db('shop/buy_order')->config['status'];
        //$refund_status = Dever::db('shop/buy_order')->config['refund_status'];
        $info_type = Dever::db($table)->config['config_type'];

        foreach ($data as $k => $v) {
            if (!is_array($v)) {
                continue;
            }
            $info = Dever::db($table)->find($v['type_id']);
            $goods = Dever::db('shop/buy_order_goods')->select(array('order_id' => $v['id']));
            $ps = Dever::db('shop/buy_order_ps')->find(array('order_id' => $v['id']));
            $cdate = strstr($v['cdate'], '-') ? $v['cdate'] : date('Y-m-d H:i', $v['cdate']);
            $fdate = ($ps && $ps['cdate']) ? date('Y-m-d H:i', $ps['cdate']) : '-';
            $ydate = ($ps && $ps['ydate']) ? date('Y-m-d H:i', $ps['ydate']) : '-';
            $num = Dever::load("shop/lib/manage.buyInfoRefundNum", $v['id']);
            $refund_status = Dever::load("shop/lib/manage.buyInfoRefundStatus", $v['id']);
            $v['refund_cash'] = $v['refund_cash'] ? $v['refund_cash'] : 0;

            $source = Dever::load("shop/lib/manage.buyInfo", $v['source_type'], $v['source_id']);
            foreach ($goods as $k1 => $v1) {

                $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v1['goods_id'], $v1['sku_id']);
                if (isset($goods_info['sku'])) {
                    $sku = $goods_info['sku']['string'];
                } else {
                    $sku = '';
                }

                if ($v['status'] == 8 || $v1['status'] == 3) {
                    $num = $v1['num'];
                    $v['refund_cash'] = $v1['price']*$v1['num'];
                    $refund_status = '已退款';
                } else {
                    $num = '0';
                    $v['refund_cash'] = '0';
                    $refund_status = '未退款';
                }

                $d = array
                (
                    $source,
                    $info['sid'],
                    $info['name'],
                    $info_type[$info['type']],

                    $v['order_num'],
                    $v['num'],
                    $v['price'],

                    $goods_info['code'],
                    $goods_info['name'],
                    $sku,
                    $v1['price'],
                    $v1['num'],
                    $v1['price']*$v1['num'],

                    $cdate,
                    $fdate,
                    $status[$v['status']],
                    $refund_status,
                    $num,
                    $v['refund_cash'],
                );

                $body[] = $d;
            }
        }

        Dever::excelExport($body, $header, $file);
    }

    # 仓库调拨单
    public function store_buy_order_diao($data)
    {
        if (!$data) {
            Dever::alert('无导出数据');
        }
        $file = Dever::input('excel_name');


        $header = array('发货仓库名称', '收货仓库名称', '订货单号', '订货总数量', '商品编码', '商品名称', '规格型号', '订货数量', '订货日期', '发货日期', '订货单状态', '退款状态', '已退商品数量');

        $table = 'store/info';

        $body = array();
        $status = Dever::db('shop/buy_order')->config['status'];
        //$refund_status = Dever::db('shop/buy_order')->config['refund_status'];

        foreach ($data as $k => $v) {
            if (!is_array($v)) {
                continue;
            }
            $info = Dever::db($table)->find($v['type_id']);
            $goods = Dever::db('shop/buy_order_goods')->select(array('order_id' => $v['id']));
            $ps = Dever::db('shop/buy_order_ps')->find(array('order_id' => $v['id']));
            $cdate = strstr($v['cdate'], '-') ? $v['cdate'] : date('Y-m-d H:i', $v['cdate']);
            $fdate = ($ps && $ps['cdate']) ? date('Y-m-d H:i', $ps['cdate']) : '-';
            $ydate = ($ps && $ps['ydate']) ? date('Y-m-d H:i', $ps['ydate']) : '-';
            $num = Dever::load("shop/lib/manage.buyInfoRefundNum", $v['id']);
            $refund_status = Dever::load("shop/lib/manage.buyInfoRefundStatus", $v['id']);
            $v['refund_cash'] = $v['refund_cash'] ? $v['refund_cash'] : 0;

            $source = Dever::load("shop/lib/manage.buyInfo", $v['source_type'], $v['source_id']);
            foreach ($goods as $k1 => $v1) {

                $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v1['goods_id'], $v1['sku_id']);
                if (isset($goods_info['sku'])) {
                    $sku = $goods_info['sku']['string'];
                } else {
                    $sku = '';
                }

                if ($v['status'] == 8 || $v1['status'] == 3) {
                    $num = $v1['num'];
                    $v['refund_cash'] = $v1['price']*$v1['num'];
                    $refund_status = '已退款';
                } else {
                    $num = '0';
                    $v['refund_cash'] = '0';
                    $refund_status = '未退款';
                }

                $d = array
                (
                    $source,
                    $info['name'],

                    $v['order_num'],
                    $v['num'],

                    $goods_info['code'],
                    $goods_info['name'],
                    $sku,
                    $v1['num'],

                    $cdate,
                    $fdate,
                    $status[$v['status']],
                    $refund_status,
                    $num,
                );

                $body[] = $d;
            }
        }

        Dever::excelExport($body, $header, $file);
    }

    # 工厂发货单
    public function factory_buy_order_fa($data)
    {
        if (!$data) {
            Dever::alert('无导出数据');
        }
        $file = Dever::input('excel_name');


        $header = array('工厂名称', '收件人名称', '收件人类型', '订货单号', '订货总数量', '订货单总金额', '商品编码', '商品名称', '规格型号', '商品进货单价', '订货数量', '商品合计金额', '订货日期', '发货日期', '订货单状态', '已退商品数量', '退款金额');

        $table = 'shop/info';

        $body = array();
        $status = Dever::db('shop/buy_order')->config['status'];
        //$refund_status = Dever::db('shop/buy_order')->config['refund_status'];
        $info_type = Dever::db($table)->config['config_type'];
        $order_type = Dever::db('shop/buy_order')->config['config_type'];

        foreach ($data as $k => $v) {
            if (!is_array($v)) {
                continue;
            }
            if ($v['type'] == 1) {
                $info = Dever::db('shop/info')->find($v['type_id']);
            } elseif ($v['type'] == 2) {
                $info = Dever::db('store/info')->find($v['type_id']);
            }
            
            $goods = Dever::db('shop/buy_order_goods')->select(array('order_id' => $v['id']));
            $ps = Dever::db('shop/buy_order_ps')->find(array('order_id' => $v['id']));
            $cdate = strstr($v['cdate'], '-') ? $v['cdate'] : date('Y-m-d H:i', $v['cdate']);
            $fdate = ($ps && $ps['cdate']) ? date('Y-m-d H:i', $ps['cdate']) : '-';
            $ydate = ($ps && $ps['ydate']) ? date('Y-m-d H:i', $ps['ydate']) : '-';
            $num = Dever::load("shop/lib/manage.buyInfoRefundNum", $v['id']);
            $refund_status = Dever::load("shop/lib/manage.buyInfoRefundStatus", $v['id']);
            $v['refund_p_cash'] = $v['refund_p_cash'] ? $v['refund_p_cash'] : 0;

            $source = Dever::load("shop/lib/manage.buyInfo", $v['source_type'], $v['source_id']);
            foreach ($goods as $k1 => $v1) {

                $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v1['goods_id'], $v1['sku_id']);
                if (isset($goods_info['sku'])) {
                    $sku = $goods_info['sku']['string'];
                } else {
                    $sku = '';
                }

                if ($v['status'] == 8 || $v1['status'] == 3) {
                    $num = $v1['num'];
                    $v['refund_p_cash'] = $v1['p_price']*$v1['num'];
                } else {
                    $num = '0';
                    $v['refund_p_cash'] = '0';
                }

                $d = array
                (
                    $source,
                    $info['name'],
                    $order_type[$v['type']],

                    $v['order_num'],
                    $v['num'],
                    $v['p_price'],

                    $goods_info['code'],
                    $goods_info['name'],
                    $sku,
                    $v1['p_price'],
                    $v1['num'],
                    $v1['p_price']*$v1['num'],

                    $cdate,
                    $fdate,
                    $status[$v['status']],
                    $num,
                    $v['refund_p_cash'],
                );

                $body[] = $d;
            }
        }

        Dever::excelExport($body, $header, $file);
    }

    # 门店出库单
    public function out_order($data)
    {
        if (!$data) {
            Dever::alert('无导出数据');
        }
        $file = Dever::input('excel_name');


        $header = array('门店编号', '门店名称', '门店类型', '出库单号', '出库总数量', '出库总金额', '商品编码', '商品名称', '规格型号', '订货单价', '订货数量', '商品合计金额', '出库日期', '出库类型', '出库状态');

        $table = 'shop/info';

        $body = array();
        $status = Dever::db('shop/out_order')->config['config_status'];
        $config_type = Dever::db('shop/out_order')->config['config_type'];
        $config_type = $config_type();
        $info_type = Dever::db($table)->config['config_type'];

        foreach ($data as $k => $v) {
            if (!is_array($v)) {
                continue;
            }
            $info = Dever::db($table)->find($v['type_id']);
            $goods = Dever::db('shop/out_order_goods')->select(array('order_id' => $v['id']));
            $cdate = strstr($v['cdate'], '-') ? $v['cdate'] : date('Y-m-d H:i', $v['cdate']);

            foreach ($goods as $k1 => $v1) {

                $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v1['goods_id'], $v1['sku_id']);
                if (isset($goods_info['sku'])) {
                    $sku = $goods_info['sku']['string'];
                } else {
                    $sku = '';
                }

                $d = array
                (
                    $info['sid'],
                    $info['name'],
                    $info_type[$info['type']],

                    $v['order_num'],
                    $v['num'],
                    $v['price'],

                    $goods_info['code'],
                    $goods_info['name'],
                    $sku,
                    $v1['price'],
                    $v1['num'],
                    $v1['price']*$v1['num'],

                    $cdate,
                    $config_type[$v['out_type']]['name'],
                    $status[$v['status']],
                );

                $body[] = $d;
            }
        }

        Dever::excelExport($body, $header, $file);
    }

    # 仓库出库单
    public function store_out_order($data)
    {
        if (!$data) {
            Dever::alert('无导出数据');
        }
        $file = Dever::input('excel_name');


        $header = array('仓库名称', '出库单号', '出库总数量', '出库总金额', '商品编码', '商品名称', '规格型号', '门店进货单价', '订货数量', '商品合计金额', '出库日期', '出库类型', '出库状态');

        $table = 'store/info';

        $body = array();
        $status = Dever::db('shop/out_order')->config['config_status'];
        $config_type = Dever::db('shop/out_order')->config['config_type'];
        $config_type = $config_type();

        foreach ($data as $k => $v) {
            if (!is_array($v)) {
                continue;
            }
            $info = Dever::db($table)->find($v['type_id']);
            $goods = Dever::db('shop/out_order_goods')->select(array('order_id' => $v['id']));
            $cdate = strstr($v['cdate'], '-') ? $v['cdate'] : date('Y-m-d H:i', $v['cdate']);

            foreach ($goods as $k1 => $v1) {

                $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v1['goods_id'], $v1['sku_id']);
                if (isset($goods_info['sku'])) {
                    $sku = $goods_info['sku']['string'];
                } else {
                    $sku = '';
                }

                $d = array
                (
                    $info['name'],
                    $v['order_num'],
                    $v['num'],
                    $v['price'],

                    $goods_info['code'],
                    $goods_info['name'],
                    $sku,
                    $v1['price'],
                    $v1['num'],
                    $v1['price']*$v1['num'],

                    $cdate,
                    $config_type[$v['out_type']]['name'],
                    $status[$v['status']],
                );

                $body[] = $d;
            }
        }

        Dever::excelExport($body, $header, $file);
    }

    public function goods_log()
    {
        //Array ( [search_option_state] => 1 [search_api_goods_id] => 猪肉 [search_api_goods-info-code] => [search_option_status] => 0 [search_option_store_id] => 6 [search_option_start_cdate] => [search_option_end_cdate] => [search_option_sday] => 0 )
        $data = Dever::input();

        $where = array();
        if (isset($data['search_option_store_id']) && $data['search_option_store_id']) {
            $where['store_id'] = $data['search_option_store_id'];
        }

        if (isset($data['search_option_status']) && $data['search_option_status']) {
            $where['status'] = $data['search_option_status'];
        }

        if (isset($data['search_option_start_cdate']) && $data['search_option_start_cdate']) {
            $where['start'] = $data['search_option_start_cdate'];
        }

        if (isset($data['search_option_end_cdate']) && $data['search_option_end_cdate']) {
            $where['end'] = $data['search_option_end_cdate'];
        }

        if (isset($data['search_api_goods_id']) && $data['search_api_goods_id']) {
            $goods_info = Dever::db('goods/info')->like(array('name' => $data['search_api_goods_id']));
            if ($goods_info) {
                $where['goods_id'] = array_keys($goods_info);
            }
        }

        if (isset($data['search_api_goods-info-code']) && $data['search_api_goods-info-code']) {
            $goods_sku = Dever::db('goods/info_sku')->like(array('code' => $data['search_api_goods-info-code']));
            if ($goods_sku) {
                $where['sku_id'] = array_keys($goods_sku);
            }
        }

        $goods = Dever::db('store/goods_log')->getDataByDate($where);

        $file = '仓库调整明细';
        $header = array('仓库名称', '商品编码', '商品名称', '规格型号', '当前库存', '占用库存', '在途库存', '总库存', '调整数量', '调整后库存', '调整后总库存', '调整时间');

        $body = array();
        if ($goods) {
            foreach ($goods as $k => $v) {
                $info = Dever::db('store/info')->find($v['store_id']);
                $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v['goods_id'], $v['sku_id']);
                if (isset($goods_info['sku'])) {
                    $sku = $goods_info['sku']['string'];
                } else {
                    $sku = '';
                }

                $cdate = date('Y-m-d H:i', $v['cdate']);
                $d = array
                (
                    $info['name'],
                    $goods_info['code'],
                    $goods_info['name'],
                    $sku,

                    $v['cur_num'],
                    $v['sell_num'],
                    $v['online_num'],
                    $v['total_num'],

                    $v['num'],
                    $v['after_cur_num'],
                    $v['after_total_num'],
                    $cdate,
                );

                $body[] = $d;
            }
        } else {
            Dever::alert('无导出数据');
        }

        Dever::excelExport($body, $header, $file);
    }
}