Ejemplo n.º 1
0
 /**
  * 订单导出
  */
 function export()
 {
     $this->response->addHeader('cache-control', 'nocache');
     $roleModel = $this->model('role');
     if (login::admin() && $roleModel->checkPower($this->session->role, 'orderlist', roleModel::POWER_SELECT)) {
         if (!empty($this->get->id)) {
             $id = json_decode($this->get->id);
         } else {
             $id = array();
         }
         $filter = array('status' => $this->get->status);
         $select_field = 'orderno,paytype,paynumber,ordertotalamount,ordertaxamount,ordergoodsamount,feeamount,tradetime,totalamount,consigneetel,consignee,zipcode,consigneeprovince,consigneecity,consigneecounty,consigneeaddress,postmode,username,pid,sku,productname,unitprice,num';
         $filename = '订单报表 ' . date('Y-m-d H:i:s');
         if ($filter['status'] == 1) {
             $filename = '报关报表 ' . date('Y-m-d H:i:s');
             $select_field = 'orderno,paytype,paynumber,ordertotalamount,tradetime,consigneetel,consignee,zipcode,consigneeprovince,consigneecity,consigneecounty,consigneeaddress,postmode,username,pid,sku,productname,unitprice,num';
         }
         $orderModel = $this->model('orderlist');
         $order = $orderModel->export($select_field, $id, $filter);
         foreach ($order as &$item) {
             $item['img'] = $this->model('productimg')->getByPid($item['pid'], '*', 'path');
             $item['tradetime'] = date("Y-m-d H:i:s", $item['tradetime']);
             switch ($item['paytype']) {
                 case 'alipay':
                     $item['paytype'] = 2;
                     break;
                 default:
             }
         }
         //生成excel文件
         $excel = new excel();
         if ($this->get->status == 1) {
             $filepath = $excel->phpexcel($order);
         } else {
             $title = array('订单号', '支付方式', '支付单号', '订单总金额', '订单税费', '订单货款', '运费', '交易时间', '已支付', '收件人手机号', '收件人', '邮编', '省份', '城市', '地区', '地址', '配送方式', '购买人id', '商品编码', '商品名称', '单价', '购买数量');
             $filepath = $excel->orderexcel($order, $title);
         }
         //excel文件下载
         header("Accept-Ranges:bytes");
         header("Content-type:application/vnd.ms-excel");
         header("Content-Disposition:attachment;filename=" . $filename . ".xls");
         header("Pragma: no-cache");
         readfile($filepath);
         (new filesystem())->unlink($filepath);
         //$excel->xls($order,$select_name,$filename);
     } else {
         $this->response->setCode(302);
         $this->response->addHeader('Location', $this->http->url('admin', 'index'));
     }
 }