public function download()
    {

        $express_list = $this->Delivery_company_model->get_list();

        // Starting the PHPExcel library
        $this->load->library('PHPExcel');
        $this->load->library('PHPExcel/IOFactory');

        $objPHPExcel = new PHPExcel();

        $objPHPExcel->getProperties()->setTitle("export")->setDescription("none");

        $objPHPExcel->setActiveSheetIndex(0);

        // Field names in the first row
        //$fields = $query->list_fields();
        $col = 0;
        $row = 1;

        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, 'ID');
        $col++;
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, '代码');
        $col++;
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, '快递公司');
        $col++;
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, '联系人');
        $col++;
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, '联系电话');
       

        // Fetching the table data
        $row = 2;

        foreach($express_list as $key=>$val)
        {
            $col = 0;
            //$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $product_info['order_no']);
             $objPHPExcel->getActiveSheet()->getCell('A'. $row)->setValueExplicit($val['id'], PHPExcel_Cell_DataType::TYPE_STRING);
            $col++;
            $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $val['code']);
            $col++;
            $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $val['company_name']);
            $col++;
            $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $val['relation']);
            $col++;
            $objPHPExcel->getActiveSheet()->getCell('E'. $row)->setValueExplicit($val['mobile'], PHPExcel_Cell_DataType::TYPE_STRING);
            
            $row++;

        }

        $objPHPExcel->getActiveSheet()->freezePane('A2');
        $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setAutoSize(true);
        $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(30);
        $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(15);

        $objPHPExcel->setActiveSheetIndex(0);

        $objWriter = IOFactory::createWriter($objPHPExcel, 'Excel5');

        // Sending headers to force the user to download the file
        header('Content-Type: application/vnd.ms-excel');
        header('Content-Disposition: attachment;filename="快递公司列表_' . date('YmdHis').'.xls"');
        header('Cache-Control: max-age=0');

        $objWriter->save('php://output');
    }
 public function uploadorder() {
        $file_id = $this->input->post('id');
        $file_path = dirname ( dirname ( dirname ( dirname ( __FILE__ ) ) ) ) . '/upload/order/';

        //TODO 安全问题
        $error = "";
        $fileElementName = $file_id;

        if (! empty ( $_FILES [$fileElementName] ['error'] )) {
            $error=$this->trans_error($_FILES [$fileElementName] ['error']);
        } elseif (empty ( $_FILES [$fileElementName] ['tmp_name'] ) || $_FILES [$fileElementName] ['tmp_name'] == 'none' ) {
            $error = 'No file was uploaded..';
        }

        if($_FILES [$fileElementName] ['size'] > 1024*1024*4){
            $error = '图片最大支持4M';
        }
        if($error) {
            $this->ajax_output_model('-1','文件信息错误');
        }

        $tmp_file = $_FILES [$fileElementName] ['tmp_name'];
        $file_types = explode ( ".", $_FILES [$fileElementName] ['name'] );
        $file_type = $file_types [count ( $file_types ) - 1];
        /*判别是不是.xls文件,判别是不是excel文件*/
        if (strtolower ( $file_type ) != "xls" && strtolower ( $file_type ) != "xlsx")
        {
            $this->ajax_output_model('-2','格式不正确');
        }

        $upload_file = $file_path . time () . '.' . $file_type;
        @move_uploaded_file ( $_FILES [$fileElementName] ['tmp_name'], $upload_file);

        $this->load->library('PHPExcel');
        $this->load->library('PHPExcel/IOFactory');

        $objPHPExcel = new PHPExcel();

        $excelData = array();

        $objReader = IOFactory::createReader('Excel5');
        $objReader->setReadDataOnly(true);
        try{
            $objPHPExcel = $objReader->load($upload_file);
            $objWorksheet = $objPHPExcel->getActiveSheet();
            $highestRow = $objWorksheet->getHighestRow();
            $highestColumn = $objWorksheet->getHighestColumn();
            $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);

            for ($row = 1; $row <= $highestRow; $row++) {
                for ($col = 0; $col < $highestColumnIndex; $col++) {
                    $excelData[$row][] =(string)$objWorksheet->getCellByColumnAndRow($col, $row)->getValue();
                }
            }
        }catch (Exception $e)
        {
            $this->ajax_output_model('-3',$e->getMessage());
        }
foreach($excelData as $id=>$arr_data)
        {
            if($id <= 1)
            {
                continue;
            }

            $order_no = $arr_data['0'];
            $delivery_company = $arr_data['12'];
            $delivery_no = $arr_data['13'];

            $delivery_company_id = 0;

            $order_info = $this->Order_list_model->get_basic_info($order_no);

            if (empty($order_info['delivery_no'])) {
                $this->Order_list_model->update_delivery($order_no, $delivery_company, $delivery_no,ORDER_STATUS_SENT_GOODS);
                $product_list = $this->Order_product_list_model->get_product_list_by_order($order_no);
                foreach ($product_list as $id => $info) {
                    $this->Order_product_list_model->update_delivery($order_no,$info['id'],$delivery_company,$delivery_no,ORDER_PRODUCT_STATUS_SENT);
                    
                    $product_info = $this->Product_list_model->get_info($info['product_id']);
                    $spec_info = $this->Product_specification_model->get_info($info['spec_id']);
                    $update_num = $info['order_num'];
                    
                    $this->Place_product_list_model->update_pre_deliver($product_info['place_id'],$info['product_id'],$info['spec_id'],$info['order_num']*-1);
                    $this->Place_product_list_model->update_deliver_num($product_info['place_id'],$info['product_id'],$info['spec_id'],$info['order_num']);
                    $this->Place_product_flow_list_model->add_info($product_info['place_id'],$info['spec_id'],$product_info['brand_id'],$info['product_id'],PRODUCT_FLOW_TYPE_SEND,$info['order_num'],$this->shop_user_id);
                    
                }
                $count_update_order++;
            }else{

                $this->Order_list_model->update_delivery($order_no, $delivery_company, $delivery_no,$order_info['order_status']);
                $product_list = $this->Order_product_list_model->get_product_list_by_order($order_no);

                foreach ($product_list as $id => $info) {
                    $this->Order_product_list_model->update_delivery($order_no,$info['id'],$delivery_company,$delivery_no,$info['product_status']);
                }

                $count_update_order++;
            }

            $count_update_product++;
        }

        $result = array('errno'=>'0','msg'=>'上传成功','line'=>count($excelData)-1,
                        'product'=>$count_update_product,'order'=>$count_update_order);
        echo json_encode($result);
        exit;
    }