<?php
|
|
namespace app\operations\service\order;
|
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
|
/**
|
* 订单导出服务类
|
*/
|
class ExportService
|
{
|
/**
|
* 订单导出
|
*/
|
public function orderList($list)
|
{
|
$spreadsheet = new Spreadsheet();
|
$sheet = $spreadsheet->getActiveSheet();
|
|
//列宽
|
$sheet->getColumnDimension('B')->setWidth(30);
|
$sheet->getColumnDimension('P')->setWidth(30);
|
|
//设置工作表标题名称
|
$sheet->setTitle('订单明细');
|
|
$sheet->setCellValue('A1', '订单号');
|
$sheet->setCellValue('B1', '商品信息');
|
$sheet->setCellValue('C1', '订单总额');
|
$sheet->setCellValue('D1', '优惠券抵扣');
|
$sheet->setCellValue('E1', '积分抵扣');
|
$sheet->setCellValue('F1', '运费金额');
|
$sheet->setCellValue('G1', '后台改价');
|
$sheet->setCellValue('H1', '实付款金额');
|
$sheet->setCellValue('I1', '支付方式');
|
$sheet->setCellValue('J1', '下单时间');
|
$sheet->setCellValue('K1', '买家');
|
$sheet->setCellValue('L1', '买家留言');
|
$sheet->setCellValue('M1', '配送方式');
|
$sheet->setCellValue('N1', '自提门店名称');
|
$sheet->setCellValue('O1', '自提联系人');
|
$sheet->setCellValue('P1', '自提联系电话');
|
$sheet->setCellValue('Q1', '收货人姓名');
|
$sheet->setCellValue('R1', '联系电话');
|
$sheet->setCellValue('S1', '收货人地址');
|
$sheet->setCellValue('T1', '物流公司');
|
$sheet->setCellValue('U1', '物流单号');
|
$sheet->setCellValue('V1', '付款状态');
|
$sheet->setCellValue('W1', '付款时间');
|
$sheet->setCellValue('X1', '发货状态');
|
$sheet->setCellValue('Y1', '发货时间');
|
$sheet->setCellValue('Z1', '收货状态');
|
$sheet->setCellValue('AA1', '收货时间');
|
$sheet->setCellValue('AB1', '订单状态');
|
$sheet->setCellValue('AC1', '微信支付交易号');
|
$sheet->setCellValue('AD1', '是否已评价');
|
|
//填充数据
|
$index = 0;
|
foreach ($list as $order) {
|
$address = $order['address'];
|
$sheet->setCellValue('A' . ($index + 2), "\t" . $order['order_no'] . "\t");
|
$sheet->setCellValue('B' . ($index + 2), $this->filterProductInfo($order));
|
$sheet->setCellValue('C' . ($index + 2), $order['total_price']);
|
$sheet->setCellValue('D' . ($index + 2), $order['coupon_money']);
|
$sheet->setCellValue('E' . ($index + 2), $order['points_money']);
|
$sheet->setCellValue('F' . ($index + 2), $order['express_price']);
|
$sheet->setCellValue('G' . ($index + 2), "{$order['update_price']['symbol']}{$order['update_price']['value']}");
|
$sheet->setCellValue('H' . ($index + 2), $order['order_source'] == 70 ? round($order['pay_price'] + $order['advance']['pay_price'], 2) : $order['pay_price']);
|
$sheet->setCellValue('I' . ($index + 2), $order['pay_type']['text']);
|
$sheet->setCellValue('J' . ($index + 2), $order['create_time']);
|
$sheet->setCellValue('K' . ($index + 2), $order['user']['nickName']);
|
$sheet->setCellValue('L' . ($index + 2), $order['buyer_remark']);
|
$sheet->setCellValue('M' . ($index + 2), $order['delivery_type']['text']);
|
$sheet->setCellValue('N' . ($index + 2), !empty($order['extract_store']) ? $order['extract_store']['shop_name'] : '');
|
$sheet->setCellValue('O' . ($index + 2), !empty($order['extract']) ? $order['extract']['linkman'] : '');
|
$sheet->setCellValue('P' . ($index + 2), !empty($order['extract']) ? $order['extract']['phone'] : '');
|
$sheet->setCellValue('Q' . ($index + 2), !empty($order['address']) ? $order['address']['name']:'');
|
$sheet->setCellValue('R' . ($index + 2), !empty($order['address']) ? $order['address']['phone']: '');
|
$sheet->setCellValue('S' . ($index + 2), $address ? $address->getFullAddress() : '');
|
$sheet->setCellValue('T' . ($index + 2), !empty($order['express']) ? $order['express']['express_name']:'');
|
$sheet->setCellValue('U' . ($index + 2), $order['express_no']);
|
$sheet->setCellValue('V' . ($index + 2), $order['pay_status']['text']);
|
$sheet->setCellValue('W' . ($index + 2), $this->filterTime($order['pay_time']));
|
$sheet->setCellValue('X' . ($index + 2), $order['delivery_status']['text']);
|
$sheet->setCellValue('Y' . ($index + 2), $this->filterTime($order['delivery_time']));
|
$sheet->setCellValue('Z' . ($index + 2), $order['receipt_status']['text']);
|
$sheet->setCellValue('AA' . ($index + 2), $this->filterTime($order['receipt_time']));
|
$sheet->setCellValue('AB' . ($index + 2), $order['order_status']['text']);
|
$sheet->setCellValue('AC' . ($index + 2), $order['transaction_id']);
|
$sheet->setCellValue('AD' . ($index + 2), $order['is_comment'] ? '是' : '否');
|
$index++;
|
}
|
|
//保存文件
|
$writer = new Xlsx($spreadsheet);
|
$filename = iconv("UTF-8", "GB2312//IGNORE", '订单') . '-' . date('YmdHis') . '.xlsx';
|
|
|
header('Content-Type: application/vnd.ms-excel');
|
header('Content-Disposition: attachment;filename="' . $filename . '"');
|
header('Cache-Control: max-age=0');
|
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
|
$writer->save('php://output');
|
}
|
|
/**
|
* 分销订单导出
|
*/
|
public function agentOrderList($list)
|
{
|
$spreadsheet = new Spreadsheet();
|
$sheet = $spreadsheet->getActiveSheet();
|
|
//列宽
|
$sheet->getColumnDimension('B')->setWidth(30);
|
|
//设置工作表标题名称
|
$sheet->setTitle('分销订单明细');
|
|
$sheet->setCellValue('A1', '订单号');
|
$sheet->setCellValue('B1', '商品信息');
|
$sheet->setCellValue('C1', '订单总额');
|
$sheet->setCellValue('D1', '实付款金额');
|
$sheet->setCellValue('E1', '支付方式');
|
$sheet->setCellValue('F1', '下单时间');
|
$sheet->setCellValue('G1', '一级分销商');
|
$sheet->setCellValue('H1', '一级分销佣金');
|
$sheet->setCellValue('I1', '二级分销商');
|
$sheet->setCellValue('J1', '二级分销佣金');
|
$sheet->setCellValue('K1', '三级分销商');
|
$sheet->setCellValue('L1', '三级分销佣金');
|
$sheet->setCellValue('M1', '买家');
|
$sheet->setCellValue('N1', '付款状态');
|
$sheet->setCellValue('O1', '付款时间');
|
$sheet->setCellValue('P1', '发货状态');
|
$sheet->setCellValue('Q1', '发货时间');
|
$sheet->setCellValue('R1', '收货状态');
|
$sheet->setCellValue('S1', '收货时间');
|
$sheet->setCellValue('T1', '订单状态');
|
$sheet->setCellValue('U1', '佣金结算');
|
$sheet->setCellValue('V1', '结算时间');
|
//填充数据
|
$index = 0;
|
foreach ($list as $agent) {
|
$order = $agent['order_master'];
|
$sheet->setCellValue('A' . ($index + 2), "\t" . $order['order_no'] . "\t");
|
$sheet->setCellValue('B' . ($index + 2), $this->filterProductInfo($order));
|
$sheet->setCellValue('C' . ($index + 2), $order['total_price']);
|
$sheet->setCellValue('D' . ($index + 2), $order['pay_price']);
|
$sheet->setCellValue('E' . ($index + 2), $order['pay_type']['text']);
|
$sheet->setCellValue('F' . ($index + 2), $order['create_time']);
|
$sheet->setCellValue('G' . ($index + 2), isset($agent['agent_first'])?$agent['agent_first']['nickName']:'');
|
$sheet->setCellValue('H' . ($index + 2), $agent['first_money']);
|
$sheet->setCellValue('I' . ($index + 2), isset($agent['agent_second'])?$agent['agent_second']['nickName']:'');
|
$sheet->setCellValue('J' . ($index + 2), $agent['second_money']);
|
$sheet->setCellValue('K' . ($index + 2), isset($agent['agent_third'])?$agent['agent_third']['nickName']:'');
|
$sheet->setCellValue('L' . ($index + 2), $agent['third_money']);
|
$sheet->setCellValue('M' . ($index + 2), $order['user']['nickName']);
|
$sheet->setCellValue('N' . ($index + 2), $order['pay_status']['text']);
|
$sheet->setCellValue('O' . ($index + 2), $this->filterTime($order['pay_time']));
|
$sheet->setCellValue('P' . ($index + 2), $order['delivery_status']['text']);
|
$sheet->setCellValue('Q' . ($index + 2), $this->filterTime($order['delivery_time']));
|
$sheet->setCellValue('R' . ($index + 2), $order['receipt_status']['text']);
|
$sheet->setCellValue('S' . ($index + 2), $this->filterTime($order['receipt_time']));
|
$sheet->setCellValue('T' . ($index + 2), $order['order_status']['text']);
|
$sheet->setCellValue('U' . ($index + 2), $agent['is_settled'] == 1 ? '已结算' : '未结算');
|
$sheet->setCellValue('V' . ($index + 2), $this->filterTime($agent['settle_time']));
|
$index++;
|
}
|
|
//保存文件
|
$filename = iconv("UTF-8", "GB2312//IGNORE", '分销订单') . '-' . date('YmdHis') . '.xlsx';
|
header('Content-Type: application/vnd.ms-excel');
|
header('Content-Disposition: attachment;filename="' . $filename . '"');
|
header('Cache-Control: max-age=0');
|
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
|
$writer->save('php://output');
|
}
|
|
/**
|
* 提现订单导出
|
*/
|
public function cashList($list)
|
{
|
$spreadsheet = new Spreadsheet();
|
$sheet = $spreadsheet->getActiveSheet();
|
|
//列宽
|
$sheet->getColumnDimension('H')->setWidth(50);
|
|
//设置工作表标题名称
|
$sheet->setTitle('提现明细');
|
|
$sheet->setCellValue('A1', 'ID');
|
$sheet->setCellValue('B1', '分销商id');
|
$sheet->setCellValue('C1', '分销商姓名');
|
$sheet->setCellValue('D1', '微信昵称');
|
$sheet->setCellValue('E1', '手机号');
|
$sheet->setCellValue('F1', '提现金额');
|
$sheet->setCellValue('G1', '提现方式');
|
$sheet->setCellValue('H1', '提现信息');
|
$sheet->setCellValue('I1', '审核状态');
|
$sheet->setCellValue('J1', '申请时间');
|
$sheet->setCellValue('K1', '审核时间');
|
//填充数据
|
$index = 0;
|
foreach ($list as $cash) {
|
$sheet->setCellValue('A' . ($index + 2), $cash['id']);
|
$sheet->setCellValue('B' . ($index + 2), $cash['user_id']);
|
$sheet->setCellValue('C' . ($index + 2), $cash['real_name']);
|
$sheet->setCellValue('D' . ($index + 2), $cash['nickName']);
|
$sheet->setCellValue('E' . ($index + 2), "\t" . $cash['mobile'] . "\t");
|
$sheet->setCellValue('F' . ($index + 2), $cash['money']);
|
$sheet->setCellValue('G' . ($index + 2), $cash['pay_type']['text']);
|
$sheet->setCellValue('H' . ($index + 2), $this->cashInfo($cash));
|
$sheet->setCellValue('I' . ($index + 2), $cash['apply_status']['text']);
|
$sheet->setCellValue('J' . ($index + 2), $cash['create_time']);
|
$sheet->setCellValue('K' . ($index + 2), $cash['audit_time']);
|
$index++;
|
}
|
//保存文件
|
$filename = iconv("UTF-8", "GB2312//IGNORE", '提现明细') . '-' . date('YmdHis') . '.xlsx';
|
header('Content-Type: application/vnd.ms-excel');
|
header('Content-Disposition: attachment;filename="' . $filename . '"');
|
header('Cache-Control: max-age=0');
|
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
|
$writer->save('php://output');
|
}
|
|
/**
|
* 余额提现订单导出
|
*/
|
public function userCashList($list)
|
{
|
$spreadsheet = new Spreadsheet();
|
$sheet = $spreadsheet->getActiveSheet();
|
|
//列宽
|
$sheet->getColumnDimension('I')->setWidth(50);
|
|
//设置工作表标题名称
|
$sheet->setTitle('余额提现明细');
|
|
$sheet->setCellValue('A1', 'ID');
|
$sheet->setCellValue('B1', '用户ID');
|
$sheet->setCellValue('C1', '微信昵称');
|
$sheet->setCellValue('D1', '手机号');
|
$sheet->setCellValue('E1', '提现金额');
|
$sheet->setCellValue('F1', '实际到账');
|
$sheet->setCellValue('G1', '提现比例');
|
$sheet->setCellValue('H1', '提现方式');
|
$sheet->setCellValue('I1', '提现信息');
|
$sheet->setCellValue('J1', '审核状态');
|
$sheet->setCellValue('K1', '申请时间');
|
$sheet->setCellValue('L1', '审核时间');
|
//填充数据
|
$index = 0;
|
foreach ($list as $cash) {
|
$sheet->setCellValue('A' . ($index + 2), $cash['id']);
|
$sheet->setCellValue('B' . ($index + 2), $cash['user_id']);
|
$sheet->setCellValue('C' . ($index + 2), $cash['nickName']);
|
$sheet->setCellValue('D' . ($index + 2), "\t" . $cash['mobile'] . "\t");
|
$sheet->setCellValue('E' . ($index + 2), $cash['money']);
|
$sheet->setCellValue('F' . ($index + 2), $cash['real_money']);
|
$sheet->setCellValue('G' . ($index + 2), $cash['cash_ratio'] . '%');
|
$sheet->setCellValue('H' . ($index + 2), $cash['pay_type']['text']);
|
$sheet->setCellValue('I' . ($index + 2), $this->cashInfo($cash));
|
$sheet->setCellValue('J' . ($index + 2), $cash['apply_status']['text']);
|
$sheet->setCellValue('K' . ($index + 2), $cash['create_time']);
|
$sheet->setCellValue('L' . ($index + 2), $cash['audit_time']);
|
$index++;
|
}
|
//保存文件
|
$filename = iconv("UTF-8", "GB2312//IGNORE", '余额提现明细') . '-' . date('YmdHis') . '.xlsx';
|
header('Content-Type: application/vnd.ms-excel');
|
header('Content-Disposition: attachment;filename="' . $filename . '"');
|
header('Cache-Control: max-age=0');
|
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
|
$writer->save('php://output');
|
}
|
|
/**
|
* 核销订单导出
|
*/
|
public function orderStoreList($list)
|
{
|
$spreadsheet = new Spreadsheet();
|
$sheet = $spreadsheet->getActiveSheet();
|
|
//列宽
|
$sheet->getColumnDimension('B')->setWidth(30);
|
$sheet->getColumnDimension('D')->setWidth(30);
|
$sheet->getColumnDimension('E')->setWidth(20);
|
$sheet->getColumnDimension('F')->setWidth(20);
|
$sheet->getColumnDimension('G')->setWidth(20);
|
|
//设置工作表标题名称
|
$sheet->setTitle('核销订单明细');
|
|
$sheet->setCellValue('A1', '门店ID');
|
$sheet->setCellValue('B1', '核销门店');
|
$sheet->setCellValue('C1', '核销员');
|
$sheet->setCellValue('D1', '订单号');
|
$sheet->setCellValue('E1', '订单类型');
|
$sheet->setCellValue('F1', '配送类型');
|
$sheet->setCellValue('G1', '核销时间');
|
$sheet->setCellValue('H1', '订单金额');
|
$sheet->setCellValue('I1', '门店提成');
|
$sheet->setCellValue('J1', '配送费');
|
$sheet->setCellValue('K1', '实付金额');
|
|
//填充数据
|
$index = 0;
|
foreach ($list as $order) {
|
$sheet->setCellValue('A' . ($index + 2), $order['store_id']);
|
$sheet->setCellValue('B' . ($index + 2), $order["store"]['store_name']);
|
$sheet->setCellValue('C' . ($index + 2), $order["clerk"]['real_name']);
|
$sheet->setCellValue('D' . ($index + 2), "\t" . $order["order"]['order_no'] . "\t");
|
$sheet->setCellValue('E' . ($index + 2), $order['order_type']['text']);
|
$sheet->setCellValue('F' . ($index + 2), $order['order']['delivery_type']['text']);
|
$sheet->setCellValue('G' . ($index + 2), $order['create_time']);
|
$sheet->setCellValue('H' . ($index + 2), $order['order']['order_price']);
|
$sheet->setCellValue('I' . ($index + 2), $order['commission']);
|
$sheet->setCellValue('J' . ($index + 2), $order['delivery_fee']);
|
$sheet->setCellValue('K' . ($index + 2), $order['order']['pay_price']);
|
$index++;
|
}
|
|
//保存文件
|
$writer = new Xlsx($spreadsheet);
|
$filename = iconv("UTF-8", "GB2312//IGNORE", '核销订单') . '-' . date('YmdHis') . '.xlsx';
|
|
header('Content-Type: application/vnd.ms-excel');
|
header('Content-Disposition: attachment;filename="' . $filename . '"');
|
header('Cache-Control: max-age=0');
|
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
|
$writer->save('php://output');
|
}
|
|
/**
|
* 商户数据统计
|
*/
|
public function supplierStatisticsList($list)
|
{
|
$spreadsheet = new Spreadsheet();
|
$sheet = $spreadsheet->getActiveSheet();
|
|
//设置工作表标题名称
|
$sheet->setTitle('商户券数据统计');
|
|
$sheet->setCellValue('A1', '商户ID');
|
$sheet->setCellValue('B1', '商户名称');
|
$sheet->setCellValue('C1', '线上券金额');
|
$sheet->setCellValue('D1', '线上券数量');
|
$sheet->setCellValue('E1', '线下券金额');
|
$sheet->setCellValue('F1', '线下券数量');
|
$sheet->setCellValue('G1', '总金额');
|
//填充数据
|
$index = 0;
|
foreach ($list as $cash) {
|
$sheet->setCellValue('A' . ($index + 2), $cash['shop_supplier_id']);
|
$sheet->setCellValue('B' . ($index + 2), $cash['name']);
|
$sheet->setCellValue('C' . ($index + 2), $cash['coupon_money']);
|
$sheet->setCellValue('D' . ($index + 2), $cash['coupon_num']);
|
$sheet->setCellValue('E' . ($index + 2), $cash['store_coupon_money']);
|
$sheet->setCellValue('F' . ($index + 2), $cash['store_coupon_num']);
|
$sheet->setCellValue('G' . ($index + 2), $cash['total_coupon_money']);
|
$index++;
|
}
|
//保存文件
|
$filename = iconv("UTF-8", "GB2312//IGNORE", '商户券数据统计') . '-' . date('YmdHis') . '.xlsx';
|
header('Content-Type: application/vnd.ms-excel');
|
header('Content-Disposition: attachment;filename="' . $filename . '"');
|
header('Cache-Control: max-age=0');
|
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
|
$writer->save('php://output');
|
}
|
|
/**
|
* 商家收入明细导出
|
*/
|
public function supplierCapitalList($data)
|
{
|
$list = $data["list"];
|
$total_money = $data["total_money"];
|
$spreadsheet = new Spreadsheet();
|
$sheet = $spreadsheet->getActiveSheet();
|
|
//设置工作表标题名称
|
$sheet->setTitle('商家收支记录');
|
|
$sheet->setCellValue('A1', '所属商户');
|
$sheet->setCellValue('B1', '收支类型');
|
$sheet->setCellValue('C1', '金额');
|
$sheet->setCellValue('D1', '时间');
|
$sheet->setCellValue('E1', '说明');
|
$sheet->setCellValue('F1', '总金额');
|
|
//填充数据
|
$index = 0;
|
foreach ($list as $cash) {
|
$sheet->setCellValue('A' . ($index + 2), $cash['supplier']['name']);
|
$sheet->setCellValue('B' . ($index + 2), $cash['flow_type'] == 10 ? '收入' : '支出');
|
$sheet->setCellValue('C' . ($index + 2), $cash['money']);
|
$sheet->setCellValue('D' . ($index + 2), $cash['create_time']);
|
$sheet->setCellValue('E' . ($index + 2), $cash['describe']);
|
$index++;
|
}
|
$sheet->setCellValue('F2', $total_money);
|
//保存文件
|
$filename = iconv("UTF-8", "GB2312//IGNORE", '商家收支记录') . '-' . date('YmdHis') . '.xlsx';
|
header('Content-Type: application/vnd.ms-excel');
|
header('Content-Disposition: attachment;filename="' . $filename . '"');
|
header('Cache-Control: max-age=0');
|
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
|
$writer->save('php://output');
|
}
|
|
/**
|
* 商家收入提现记录导出
|
*/
|
public function supplierCashList($data)
|
{
|
$list = $data["list"];
|
$spreadsheet = new Spreadsheet();
|
$sheet = $spreadsheet->getActiveSheet();
|
|
//设置工作表标题名称
|
$sheet->setTitle('商家收支提现记录');
|
|
$sheet->setCellValue('A1', '所属商户');
|
$sheet->setCellValue('B1', '金额');
|
$sheet->setCellValue('C1', '时间');
|
$sheet->setCellValue('D1', '说明');
|
$sheet->setCellValue('E1', '状态');
|
|
//填充数据
|
$index = 0;
|
foreach ($list as $cash) {
|
if($cash["is_settled"] == 1){
|
$status = "提现中";
|
}elseif($cash["is_settled"] == 2){
|
$status = "已提现";
|
}else{
|
$status = "未提现";
|
}
|
$sheet->setCellValue('A' . ($index + 2), $cash['supplier']['name']);
|
$sheet->setCellValue('B' . ($index + 2), $cash['money']);
|
$sheet->setCellValue('C' . ($index + 2), $cash['create_time']);
|
$sheet->setCellValue('D' . ($index + 2), $cash['describe']);
|
$sheet->setCellValue('E' . ($index + 2), $status);
|
$index++;
|
}
|
|
//保存文件
|
$filename = iconv("UTF-8", "GB2312//IGNORE", '商家收支提现记录') . '-' . date('YmdHis') . '.xlsx';
|
header('Content-Type: application/vnd.ms-excel');
|
header('Content-Disposition: attachment;filename="' . $filename . '"');
|
header('Cache-Control: max-age=0');
|
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
|
$writer->save('php://output');
|
}
|
|
/**
|
* 收入统计导出
|
*/
|
public function incomeList($list)
|
{
|
$spreadsheet = new Spreadsheet();
|
$sheet = $spreadsheet->getActiveSheet();
|
|
//设置工作表标题名称
|
$sheet->setTitle('收入统计');
|
|
$sheet->setCellValue('A1', '日期');
|
$sheet->setCellValue('B1', '余额支付');
|
$sheet->setCellValue('C1', '付呗支付');
|
$sheet->setCellValue('D1', '线下支付');
|
$sheet->setCellValue('E1', '其他支付');
|
$sheet->setCellValue('F1', '优惠券');
|
$sheet->setCellValue('G1', '满减金额');
|
$sheet->setCellValue('H1', '积分金额');
|
$sheet->setCellValue('I1', '退款金额');
|
|
//填充数据
|
$index = 0;
|
foreach ($list as $item) {
|
$sheet->setCellValue('A' . ($index + 2), $item['day']);
|
$sheet->setCellValue('B' . ($index + 2), $item['pay_balance']);
|
$sheet->setCellValue('C' . ($index + 2), $item['pay_wx']);
|
$sheet->setCellValue('D' . ($index + 2), $item['pay_cash']);
|
$sheet->setCellValue('E' . ($index + 2), $item['pay_other']);
|
$sheet->setCellValue('F' . ($index + 2), $item['coupon']);
|
$sheet->setCellValue('G' . ($index + 2), $item['fullreduce']);
|
$sheet->setCellValue('H' . ($index + 2), $item['points']);
|
$sheet->setCellValue('I' . ($index + 2), $item['refund_money']);
|
$index++;
|
}
|
|
//保存文件
|
$writer = new Xlsx($spreadsheet);
|
$filename = iconv("UTF-8", "GB2312//IGNORE", '收入统计') . '-' . date('YmdHis') . '.xlsx';
|
|
header('Content-Type: application/vnd.ms-excel');
|
header('Content-Disposition: attachment;filename="' . $filename . '"');
|
header('Cache-Control: max-age=0');
|
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
|
$writer->save('php://output');
|
}
|
|
/**
|
* 用户导出
|
*/
|
public function userList($list)
|
{
|
$spreadsheet = new Spreadsheet();
|
$sheet = $spreadsheet->getActiveSheet();
|
|
//设置工作表标题名称
|
$sheet->setTitle('会员列表');
|
|
$sheet->setCellValue('A1', '用户id');
|
$sheet->setCellValue('B1', '昵称');
|
$sheet->setCellValue('C1', '姓名');
|
$sheet->setCellValue('D1', '会员等级');
|
$sheet->setCellValue('E1', '来源');
|
$sheet->setCellValue('F1', '积分');
|
$sheet->setCellValue('G1', '余额');
|
$sheet->setCellValue('H1', '推荐人');
|
$sheet->setCellValue('I1', '手机号');
|
$sheet->setCellValue('J1', '注册时间');
|
|
//填充数据
|
$index = 0;
|
foreach ($list as $item) {
|
$reg_source = '小程序';
|
if($item["reg_source"] == 'mp'){
|
$reg_source = '公众号';
|
}
|
$nickName = $item['nickName'];
|
if(!empty($nickName)){
|
$nickName = $this->cutStr($nickName,10);
|
}
|
$sheet->setCellValue('A' . ($index + 2), $item['user_id']);
|
$sheet->setCellValue('B' . ($index + 2), $nickName);
|
$sheet->setCellValue('C' . ($index + 2), $item['real_name']);
|
$sheet->setCellValue('D' . ($index + 2), empty($item['grade_id']) ? '无' : $item['grade']['name']);
|
$sheet->setCellValue('E' . ($index + 2), $reg_source);
|
$sheet->setCellValue('F' . ($index + 2), $item['points']);
|
$sheet->setCellValue('G' . ($index + 2), $item['balance']);
|
$sheet->setCellValue('H' . ($index + 2), $item['referee_name']);
|
$sheet->setCellValue('I' . ($index + 2), $item['mobile']);
|
$sheet->setCellValue('J' . ($index + 2), $item['create_time']);
|
$index++;
|
}
|
|
//保存文件
|
$writer = new Xlsx($spreadsheet);
|
$filename = iconv("UTF-8", "GB2312//IGNORE", '会员') . '-' . date('YmdHis') . '.xlsx';
|
|
|
header('Content-Type: application/vnd.ms-excel');
|
header('Content-Disposition: attachment;filename="' . $filename . '"');
|
header('Cache-Control: max-age=0');
|
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
|
$writer->save('php://output');
|
}
|
|
/**
|
* 连盟活动报名列表导出
|
*/
|
public function activityUserList($list)
|
{
|
$spreadsheet = new Spreadsheet();
|
$sheet = $spreadsheet->getActiveSheet();
|
$title = $list[0]['activity']['branch']['name'] . '-' . $list[0]['activity']['name'] . '-' . '活动报名记录表';
|
//设置工作表标题名称
|
$sheet->setTitle('活动报名记录表');
|
|
/*$sheet->setCellValue('A1', '用户id');
|
$sheet->setCellValue('B1', '昵称');*/
|
$sheet->setCellValue('A1', '姓名');
|
$sheet->setCellValue('B1', '手机号');
|
$sheet->setCellValue('C1', '邀请人');
|
$sheet->setCellValue('D1', '邀请人手机号');
|
$sheet->setCellValue('E1', '所属分会');
|
/*$sheet->setCellValue('F1', '微信支付交易号');
|
$sheet->setCellValue('G1', '积分抵扣金额');
|
$sheet->setCellValue('H1', '余额抵扣金额');
|
$sheet->setCellValue('I1', '在线支付金额');*//*
|
$sheet->setCellValue('F1', '报名状态');
|
$sheet->setCellValue('G1', '报名时间');
|
$sheet->setCellValue('H1', '活动ID');
|
$sheet->setCellValue('I1', '活动标题');*/
|
foreach(range('A','E') as $columnID) {
|
$sheet->getColumnDimension($columnID)->setAutoSize(true);
|
}
|
//填充数据
|
$index = 0;
|
foreach ($list as $item) {
|
$sheet->setCellValue('A' . ($index + 2), $item['real_name']);
|
$sheet->setCellValueExplicit('B' . ($index + 2), $item['mobile'] , \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING);
|
$sheet->setCellValue('C' . ($index + 2), $item['recommend_name']);
|
$sheet->setCellValueExplicit('D' . ($index + 2), $item['recommend_mobile'] , \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING);
|
|
$sheet->setCellValue('E' . ($index + 2), empty($item['branch']) ? '无' : $item['branch']['name']);
|
/* $sheet->setCellValue('F' . ($index + 2), $item['transaction_id']);
|
$sheet->setCellValue('G' . ($index + 2), $item['points_money']);
|
$sheet->setCellValue('H' . ($index + 2), $item['balance']);
|
$sheet->setCellValue('I' . ($index + 2), $item['online_money']);*//*
|
$sheet->setCellValue('F' . ($index + 2), $item['status_text']);
|
$sheet->setCellValue('G' . ($index + 2), $item['create_time']);
|
$sheet->setCellValue('H' . ($index + 2), $item['activity_id']);
|
$sheet->setCellValue('I' . ($index + 2), $item['activity']['name']);*/
|
$index++;
|
}
|
|
//保存文件
|
$writer = new Xlsx($spreadsheet);
|
$filename = iconv("UTF-8", "GB2312//IGNORE", $title) . '-' . date('YmdHis') . '.xlsx';
|
|
|
header('Content-Type: application/vnd.ms-excel');
|
header('Content-Disposition: attachment;filename="' . $filename . '"');
|
header('Cache-Control: max-age=0');
|
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
|
$writer->save('php://output');
|
}
|
|
public function cutStr($str, $maxLength) {
|
$str=$this->filterEmoji($str);
|
if(preg_match('/[\x{4e00}-\x{9fa5}]/u', $str)){
|
return $str;
|
};
|
|
$pattern = '/[\x{4e00}-\x{9fa5}]+|[a-zA-Z]+/u';
|
preg_match($pattern, $str, $matches, PREG_OFFSET_CAPTURE);
|
if(empty($matches[0])){
|
return '';
|
}
|
$start = $matches[0][1]; // 起始位置
|
if(empty($matches[0][0])){
|
return '';
|
}
|
$matchLength = strlen($matches[0][0]); // 匹配到的字符长度
|
|
|
$end = $start + $matchLength - 1;
|
$cutLength = 0;
|
|
for ($i = $start; $i <= $end; $i++) {
|
if (($maxLength - $cutLength) >= 2) {
|
// 对于非英文字符,长度为2(UTF-8下)
|
$cutLength += 2;
|
} else if (($maxLength - $cutLength) == 1) {
|
// 对于英文字符,长度为1
|
$cutLength += 1;
|
} else {
|
break;
|
}
|
}
|
$nickname = substr($str, 0, $i);
|
return $nickname;
|
}
|
|
public function filterEmoji($str)
|
{
|
$str = preg_replace_callback(
|
'/./u',
|
function (array $match) {
|
return strlen($match[0]) >= 4 ? '' : $match[0];
|
},
|
$str);
|
return $str;
|
}
|
|
|
/**
|
* 格式化提现信息
|
*/
|
private function cashInfo($cash)
|
{
|
$content = '';
|
if ($cash['pay_type']['value'] == 20) {
|
$content .= "支付宝姓名:{$cash['alipay_name']}\n";
|
$content .= " 支付宝账号:{$cash['alipay_account']}\n";
|
} elseif ($cash['pay_type']['value'] == 30) {
|
$content .= "开户行:{$cash['bank_name']}\n";
|
$content .= " 姓名:{$cash['bank_account']}\n";
|
$content .= " 卡号:{$cash['bank_account']}\n";
|
}
|
return $content;
|
}
|
|
/**
|
* 格式化商品信息
|
*/
|
private function filterProductInfo($order)
|
{
|
$content = '';
|
foreach ($order['product'] as $key => $product) {
|
$content .= ($key + 1) . ".商品名称:{$product['product_name']}\n";
|
!empty($product['product_attr']) && $content .= " 商品规格:{$product['product_attr']}\n";
|
$content .= " 购买数量:{$product['total_num']}\n";
|
$content .= " 商品总价:{$product['total_price']}元\n\n";
|
}
|
return $content;
|
}
|
|
|
/**
|
* 日期值过滤
|
*/
|
private function filterTime($value)
|
{
|
if (!$value) return '';
|
return date('Y-m-d H:i:s', $value);
|
}
|
|
}
|