/** * 订单导出 */ 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')); } }
/** * 导出用户数据 */ function export() { $roleModel = $this->model('role'); if (login::admin() && $roleModel->checkPower($this->session->role, 'user', roleModel::POWER_SELECT)) { $userModel = $this->model('user'); $addressModel = $this->model('address'); if (!empty($this->get->data)) { $data = json_decode(htmlspecialchars_decode($this->get->data)); $userModel->where('id in (?)', array(implode(',', $data))); } $result = $userModel->select('id,telephone,email,username,regtime,logtime,money,score,ordernum,cost'); foreach ($result as &$user) { $user['regtime'] = date("Y-m-d H:i:s", $user['regtime']); $user['logtime'] = date("Y-m-d H:i:s", $user['logtime']); $address = $addressModel->getHost($user['id']); if (empty($address)) { $addstr = ''; } else { $addstr = "省份:" . $address['province'] . " 城市:" . $address['city'] . " 详细地址:" . $address['address'] . " 邮编:" . $address['zcode']; } $user['address'] = $addstr; } $excel = new excel(); $excel->xls($result, array('会员ID', '手机号', 'Email', '昵称', '注册时间', '最近登陆时间', '余额', '积分', '订单数', '消费金额', '会员收货地址信息'), 'user.xls'); } else { $this->response->setCode(302); $this->response->addHeader('Location', $this->http->url('admin', 'index')); } }
/** * 导出商品数据 */ function export() { $data = json_decode(htmlspecialchars_decode($this->get->data)); $productModel = $this->model('product'); if (!empty($data)) { $productModel->where('id in (?)', array(implode(',', $data))); } $product = $productModel->select('id,sku,name,category,price,oldprice,stock,short_description,time'); foreach ($product as &$good) { $good['time'] = date('Y-m-d H:i:s', $good['time']); $good['category'] = $this->model('category')->get($good['id'], 'name'); unset($good['id']); } $excel = new excel(); $excel->xls($product, array('商品货号', '商品名称', '分类', '标价', '市场价', '库存', '描述', '添加时间')); }