- 在 BeforehandOrderLists 中添加 file 字段 - 在 BeforehandOrderLogic 中: - 优化订单创建逻辑,添加审批记录 - 调整订单更新逻辑,仅更新必要的字段 - 重构订单详情获取方法 - 添加时间判断逻辑,计算存储和配送时间 - 在 WarehouseProductReturnLogic 中关联前置订单 ID - 在 OrderAllocation 中更新订单时间相关逻辑 - 在 functions.php 中注释掉未使用的 getNewOrderSn 函数
171 lines
7.3 KiB
PHP
171 lines
7.3 KiB
PHP
<?php
|
|
|
|
namespace app\common\service\xlsx;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
|
use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
|
use PhpOffice\PhpSpreadsheet\Style\Border;
|
|
|
|
/**
|
|
* 订单分配
|
|
*/
|
|
class OrderAllocation
|
|
{
|
|
public function export($data,$order,$other_data)
|
|
{
|
|
$spreadsheet = new Spreadsheet();
|
|
$sheet = $spreadsheet->getActiveSheet();
|
|
// 合并单元格A1到K1
|
|
$sheet->mergeCells('A1:P1');
|
|
|
|
$sheet->mergeCells('B2:C2');
|
|
$sheet->mergeCells('E2:F2');
|
|
$sheet->mergeCells('G2:H2');
|
|
$sheet->mergeCells('I2:L2');
|
|
$sheet->mergeCells('M2:N2');
|
|
$sheet->mergeCells('O2:P2');
|
|
|
|
$sheet->mergeCells('B3:C3');
|
|
$sheet->mergeCells('D3:E3');
|
|
$sheet->mergeCells('F3:G3');
|
|
|
|
$sheet->setCellValue('A1', '订 单 分 配');
|
|
$sheet->setCellValue('A2', '姓名:');
|
|
$sheet->setCellValue('B2', $other_data->nickname);
|
|
$sheet->getColumnDimension('C')->setAutoSize(true);
|
|
|
|
$sheet->setCellValue('D2', '电话:');
|
|
$sheet->setCellValue('E2', $other_data->phone);
|
|
$sheet->setCellValue('G2', '收货地址:');
|
|
$sheet->setCellValue('I2', $other_data->address);
|
|
$sheet->setCellValue('M2', '订单编号:');
|
|
$sheet->setCellValue('O2', $order['order_id']??'');
|
|
|
|
$sheet->setCellValue('A3', '下单时间:');
|
|
$sheet->setCellValue('B3', $order['create_time']??'');
|
|
$sheet->setCellValue('D3', '送货时间:');
|
|
$sheet->setCellValue('F3', $other_data->arrival_time);
|
|
|
|
|
|
$sheet->setCellValue('A4', '编号');
|
|
$sheet->setCellValue('B4', '品名');
|
|
$sheet->setCellValue('C4', '型号');
|
|
$sheet->setCellValue('D4', '包装');
|
|
$sheet->setCellValue('E4', '毛重');
|
|
$sheet->setCellValue('F4', '净重(约)');
|
|
$sheet->setCellValue('G4', '单位');
|
|
$sheet->setCellValue('H4', '销售单价');
|
|
$sheet->setCellValue('I4', '下单数量');
|
|
$sheet->setCellValue('J4', '下单金额');
|
|
$sheet->setCellValue('K4', '发货量');
|
|
$sheet->setCellValue('L4', '实发量');
|
|
$sheet->setCellValue('M4', '结算金额');
|
|
$sheet->setCellValue('N4', '售后');
|
|
$sheet->setCellValue('O4', '正常损耗');
|
|
$sheet->setCellValue('P4', '备注');
|
|
|
|
// 设置默认的单元格样式
|
|
$defaultStyle = [
|
|
'alignment' => [
|
|
'horizontal' => Alignment::HORIZONTAL_CENTER,
|
|
'vertical' => Alignment::VERTICAL_CENTER,
|
|
],
|
|
];
|
|
|
|
// 应用默认样式到整个工作表
|
|
$spreadsheet->getDefaultStyle()->applyFromArray($defaultStyle);
|
|
|
|
foreach ($data as $k => $v) {
|
|
$sheet->setCellValue('A' . ($k + 5), $v['product_id']);
|
|
$sheet->setCellValue('B' . ($k + 5), $v['store_name']);
|
|
$sheet->setCellValue('C' . ($k + 5), $v['marques']);
|
|
$sheet->setCellValue('D' . ($k + 5), $v['package']);
|
|
$sheet->setCellValue('E' . ($k + 5), $v['gross_weight']);
|
|
$sheet->setCellValue('F' . ($k + 5), $v['net_weight']);
|
|
$sheet->setCellValue('G' . ($k + 5), $v['unit_name']);
|
|
$sheet->setCellValue('H' . ($k + 5), $v['price']);
|
|
$sheet->setCellValue('I' . ($k + 5), $v['cart_num']);
|
|
$sheet->setCellValue('J' . ($k + 5), $v['total_price']);
|
|
$sheet->setCellValue('K' . ($k + 5), $v['accept_num']);
|
|
$sheet->setCellValue('L' . ($k + 5),$v['accept_num']);
|
|
$sheet->setCellValue('M' . ($k + 5),$v['pay_price']);
|
|
$sheet->setCellValue('N' . ($k + 5),$v['after_sales']);
|
|
$sheet->setCellValue('O' . ($k + 5),$v['loss']);
|
|
$sheet->setCellValue('P' . ($k + 5),$v['mark']);
|
|
|
|
}
|
|
|
|
$count = count($data);
|
|
$sheet->setCellValue('A' . ($count + 6),'合计');
|
|
$sheet->setCellValue('C' . ($count + 6),$count);
|
|
$sheet->setCellValue('I' . ($count + 6),$order['total_price'].'元');
|
|
$sheet->setCellValue('K' . ($count + 6),$order['pay_price'].'元');
|
|
|
|
$sheet->setCellValue('A' . ($count + 7),'累计接单');
|
|
$sheet->setCellValue('B' . ($count + 7),$count);
|
|
|
|
$sheet->setCellValue('C' . ($count + 7),'采购预收金额');
|
|
$sheet->setCellValue('D' . ($count + 7),$order['total_price'].'元');
|
|
$sheet->setCellValue('G' . ($count + 7),'预收押金');
|
|
$sheet->setCellValue('H' . ($count + 7),$order['deposit'].'元');
|
|
$sheet->setCellValue('I' . ($count + 7),'合计预收');
|
|
$sheet->setCellValue('J' . ($count + 7),bcadd($order['deposit'],$order['total_price']).'元');
|
|
|
|
$sheet->setCellValue('A' . ($count + 8),'接单员');
|
|
$sheet->setCellValue('B' . ($count + 8),$order['admin_name']);
|
|
$sheet->setCellValue('C' . ($count + 8),'分单员');
|
|
$sheet->setCellValue('D' . ($count + 8),$other_data->splitting_officer??'');
|
|
$sheet->setCellValue('E' . ($count + 8),'跟单员');
|
|
$sheet->setCellValue('F' . ($count + 8),$other_data->merchandiser??'');
|
|
$sheet->setCellValue('G' . ($count + 8),'配货员');
|
|
$sheet->setCellValue('H' . ($count + 8),$other_data->distribution_personnel??'');
|
|
$sheet->setCellValue('I' . ($count + 8),'运输员');
|
|
$sheet->setCellValue('J' . ($count + 8),$other_data->transporter??'');
|
|
$sheet->setCellValue('K' . ($count + 8),'门店');
|
|
$sheet->setCellValue('L' . ($count + 8),$other_data->system_store_name??'');
|
|
$sheet->setCellValue('M' . ($count + 8),'区域经理');
|
|
$sheet->setCellValue('N' . ($count + 8),$other_data->regional_manager??'');
|
|
|
|
$sheet->setCellValue('A' . ($count + 9),'接单时间');
|
|
$sheet->setCellValue('B' . ($count + 9),$order['create_time']??'');
|
|
$sheet->setCellValue('C' . ($count + 9),'分单时间');
|
|
$sheet->setCellValue('D' . ($count + 9),$order['split_time']??'');
|
|
$sheet->setCellValue('E' . ($count + 9),'入库时间');
|
|
$sheet->setCellValue('F' . ($count + 9),$order['storage_time']??'');
|
|
$sheet->setCellValue('G' . ($count + 9),' 分拣时间');
|
|
$sheet->setCellValue('H' . ($count + 9),$order['delivery_time']??'');
|
|
$sheet->setCellValue('I' . ($count + 9),' 到门店时间');
|
|
$sheet->setCellValue('J' . ($count + 9),'');
|
|
$sheet->setCellValue('K' . ($count + 9),' 下单到货时间');
|
|
$sheet->setCellValue('L' . ($count + 9),'');
|
|
// 设置单元格的样式
|
|
$styleArray = [
|
|
'font' => [
|
|
'bold' => true,
|
|
'size' => 28,
|
|
],
|
|
];
|
|
$sheet->getStyle('A1')->applyFromArray($styleArray);
|
|
// 定义线框样式
|
|
$styleArray = [
|
|
'borders' => [
|
|
'allBorders' => [
|
|
'borderStyle' => Border::BORDER_THIN, // 线框样式
|
|
'color' => ['argb' => '000000'], // 线框颜色
|
|
],
|
|
],
|
|
];
|
|
$sheet->getStyle('A1:P' . ($count + 9))->applyFromArray($styleArray);
|
|
|
|
// 保存文件到 public 下
|
|
|
|
$writer = new Xlsx($spreadsheet);
|
|
$url = '/export/' . date('Y-m') . '/' .'订单分配-'.date('Y-m-d H:i') . '.xlsx';
|
|
$file_path = public_path() . $url;
|
|
// 保存文件到 public 下
|
|
$writer->save($file_path);
|
|
return getenv('APP_URL').$url;
|
|
}
|
|
}
|