调整出入库打印

This commit is contained in:
lewis 2025-03-12 11:19:42 +08:00
parent f7c6d681be
commit b05e8f651e
16 changed files with 2241 additions and 4 deletions

View File

@ -0,0 +1,201 @@
<?php
namespace app\common\service\xlsx;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\Converter;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use PhpOffice\PhpSpreadsheet\Style\Alignment;
use PhpOffice\PhpSpreadsheet\Style\Border;
use Webman\Exception\BusinessException;
class Beforehand
{
public function export($data, $system_store)
{
// 创建一个新的PHPWord文档
$phpWord = new PhpWord();
// 添加一个节
$section = $phpWord->addSection(array(
'pageSizeW' => Converter::cmToTwip(4), // 宽度转换为twips
'pageSizeH' => Converter::cmToTwip(2), // 高度转换为twips
'marginLeft' => Converter::cmToTwip(0.2),
'marginRight' => Converter::cmToTwip(0),
'marginTop' => Converter::cmToTwip(0.2),
'marginBottom' => Converter::cmToTwip(0),
));
$fontStyle = ['name' => 'Arial', 'size' => 10, 'bold' => true];
$fontStyle1 = ['name' => 'Arial', 'size' => 8, 'bold' => true];
$fontStyle2 = ['name' => 'Arial', 'size' => 8, 'bold' => true];
$fontStyle3 = ['name' => 'Arial', 'size' => 8, 'bold' => true];
$count = count($data);
foreach ($data as $k => $v) {
$textRun = $section->addTextRun();
$textRun->addText($v['system_store'], $fontStyle);
$textRun->addText(' ' . $v['subtitle'], $fontStyle1);
$section->addText($v['store_name'], $fontStyle2);
$section->addText($v['address'], $fontStyle3);
if($k+1!=$count){
$section->addPageBreak();
}
}
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$url = '/export/' . date('Y-m') . '/' . $system_store . '标签单-' . date('YmdHi') . '.docx';
$file_path = public_path() . $url;
// 保存文件到 public 下
$objWriter->save($file_path);
return getenv('APP_URL') . $url;
}
public function order($order, $cart_info)
{
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
// 合并单元格A1到K1
$sheet->mergeCells('A1:J1');
$sheet->mergeCells('B2:E2');
$sheet->mergeCells('G2:J2');
$sheet->mergeCells('G3:J3');
$sheet->mergeCells('B3:E3');
$sheet->mergeCells('B4:C4');
$sheet->mergeCells('D4:E4');
$sheet->setCellValue('A1', $this->company.'公司送货单');
$sheet->setCellValue('A2', '店铺名称');
$sheet->setCellValue('B2', $system_store);
$sheet->setCellValue('F2', '送货时间');
$sheet->setCellValue('G2', $order['delivery_time']??'');
$sheet->setCellValue('A3', '开单日期');
$sheet->setCellValue('B3', $order['pay_time']??'');
$sheet->setCellValue('F3', '单号');
$sheet->setCellValue('G3', $order['order_id']??'');
$sheet->setCellValue('A4', '序号');
$sheet->setCellValue('B4', '商品名称');
$sheet->setCellValue('D4', '规格');
$sheet->setCellValue('F4', '单位');
$sheet->setCellValue('G4', '单价');
$sheet->setCellValue('H4', '数量');
$sheet->setCellValue('I4', '总价');
$sheet->setCellValue('J4', '备注');
// 设置默认的单元格样式
$defaultStyle = [
'alignment' => [
'horizontal' => Alignment::HORIZONTAL_CENTER,
'vertical' => Alignment::VERTICAL_CENTER,
],
];
// 应用默认样式到整个工作表
$spreadsheet->getDefaultStyle()->applyFromArray($defaultStyle);
foreach ($data as $k => $v) {
$sheet->setCellValue('A' . ($k + 5), $k + 1);
$sheet->setCellValue('B' . ($k + 5), $v['store_name']);
$sheet->mergeCells('B' . ($k + 5) . ':C' . $k + 5);
$sheet->setCellValue('D' . ($k + 5), $v['store_info']);
$sheet->mergeCells('D' . ($k + 5) . ':E' . $k + 5);
$sheet->setCellValue('F' . ($k + 5), $v['unit_name']);
$sheet->setCellValue('G' . ($k + 5), $v['price']);
$sheet->setCellValue('H' . ($k + 5), $v['cart_num']);
$sheet->setCellValue('I' . ($k + 5), $v['total_price']);
}
$count = count($data);
$sheet->mergeCells('A' . ($count + 5) . ':J' . $count + 5);
$sheet->mergeCells('B' . ($count + 6) . ':E' . $count + 6);
$sheet->setCellValue('A' . $count + 6, '合计数量');
$sheet->setCellValue('B' . $count + 6,$order['total_num']);
$sheet->mergeCells('G' . ($count + 6) . ':J' . $count + 6);
$sheet->setCellValue('F' . $count + 6, '合计价格');
$sheet->setCellValue('G' . $count + 6, $order['total_price']);
$sheet->setCellValue('A' . ($count + 7), '备注');
$sheet->mergeCells('B' . ($count + 7) . ':J' . $count + 7);
$sheet->setCellValue('B' . ($count + 7), $order['mark']??'');
$sheet->mergeCells('A' . ($count + 8) . ':J' . $count + 8);
$sheet->mergeCells('A' . ($count + 9) . ':A' . $count + 10);
$sheet->setCellValue('A' . ($count + 9), '销售单位');
$sheet->setCellValue('B' . ($count + 9), '名称');
$sheet->setCellValue('C' . ($count + 9), $this->company);
$sheet->setCellValue('B' . ($count + 10), '地址');
$sheet->setCellValue('C' . ($count + 10), $this->address);
$sheet->setCellValue('G' . ($count + 9), '公司电话');
$sheet->setCellValue('H' . ($count + 9), $this->phone);
$sheet->setCellValue('G' . ($count + 10), '售后电话');
$sheet->setCellValue('H' . ($count + 10), $this->tel);
$sheet->mergeCells('C' . ($count + 9) . ':F' . $count + 9);
$sheet->mergeCells('C' . ($count + 10) . ':F' . $count + 10);
$sheet->mergeCells('H' . ($count + 9) . ':J' . ($count + 9));
$sheet->mergeCells('H' . ($count + 10) . ':J' . $count + 10);
$sheet->mergeCells('A' . ($count + 11) . ':J' . $count + 11);
$sheet->setCellValue('A' . $count + 12, '下单人',);
$sheet->mergeCells('B' . ($count + 12) . ':C' . $count + 12);
$sheet->setCellValue('B' . ($count + 12), $order['real_name']??'');
$sheet->setCellValue('D' . $count + 12, '电话');
$sheet->mergeCells('E' . ($count + 12) . ':F' . $count + 12);
$sheet->setCellValue('E' . ($count + 12), $order['user_phone']??'');
$sheet->setCellValue('G' . $count + 12, '地址');
$sheet->mergeCells('H' . ($count + 12) . ':J' . $count + 12);
$sheet->setCellValue('H' . ($count + 12), $order['user_address']??'');
$sheet->setCellValue('A' . $count + 13, '仓库',);
$sheet->mergeCells('B' . ($count + 13) . ':C' . $count + 13);
$sheet->setCellValue('D' . $count + 13, '送货');
$sheet->mergeCells('E' . ($count + 13) . ':F' . $count + 13);
$sheet->setCellValue('G' . $count + 13, '签收人');
$sheet->mergeCells('H' . ($count + 13) . ':J' . $count + 13);
// 设置单元格的样式
$styleArray = [
'font' => [
'bold' => true,
'size' => 16,
],
];
$sheet->getStyle('A1')->applyFromArray($styleArray);
// 定义线框样式
$styleArray = [
'borders' => [
'allBorders' => [
'borderStyle' => Border::BORDER_THIN, // 线框样式
'color' => ['argb' => '000000'], // 线框颜色
],
],
];
$sheet->getStyle('A1:J' . ($count + 13))->applyFromArray($styleArray);
// 保存文件到 public 下
$writer = new Xlsx($spreadsheet);
$dir=public_path().'/export/'.date('Y-m');
if (!file_exists($dir)) {
// 尝试创建目录
if (!mkdir($dir)) {
throw new BusinessException('创建目录失败:/export/' . date('Y-m'));
}
}
$file_path = $dir. '/' . $order['info'].'出库单-'.date('Y-m-d H:i') . '.xlsx';
$url = '/export/'.date('Y-m'). '/' . $order['info'].'出库单-'.date('Y-m-d H:i') . '.xlsx';
// 保存文件到 public 下
$writer->save($file_path);
return getenv('APP_URL').$url;
}
}

View File

@ -0,0 +1,185 @@
<?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;
use Webman\Exception\BusinessException;
/**
* 订单分配
*/
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->mergeCells('B4:E4');
$sheet->setCellValue('B4', '品名');
$sheet->setCellValue('F4', '数量');
// $sheet->setCellValue('D4', '包装');
// $sheet->setCellValue('E4', '毛重');
// $sheet->setCellValue('F4', '净重(约)');
$sheet->setCellValue('G4', '单位');
$sheet->mergeCells('H4:I4');
$sheet->setCellValue('H4', '销售单价');
// $sheet->setCellValue('I4', '型号');
$sheet->setCellValue('J4', '下单金额');
$sheet->setCellValue('K4', '发货量');
$sheet->setCellValue('L4', '实发量');
$sheet->setCellValue('M4', '结算金额');
$sheet->mergeCells('N4:P4');
// $sheet->setCellValue('N4', '售后');
// $sheet->setCellValue('O4', '正常损耗');
$sheet->setCellValue('N4', '备注');
// 设置默认的单元格样式
$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->mergeCells('B'. ($k + 5).':E'. ($k + 5));
$sheet->setCellValue('B' . ($k + 5), $v['store_name']);
$sheet->setCellValue('F' . ($k + 5), $v['cart_num']);
// $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->mergeCells('H'. ($k + 5).':I'. ($k + 5));
$sheet->setCellValue('H' . ($k + 5), $v['price']);
// $sheet->setCellValue('I' . ($k + 5), $v['marques']);
$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->mergeCells('N'. ($k + 5).':P'. ($k + 5));
$sheet->setCellValue('N' . ($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);
$dir=public_path().'/export/'.date('Y-m');
if (!file_exists($dir)) {
// 尝试创建目录
if (!mkdir($dir)) {
throw new BusinessException('创建目录失败:/export/' . date('Y-m'));
}
}
$file_path = $dir. '/' .'订单分配-'.date('Y-m-d H:i') . '.xlsx';
$url = '/export/'.date('Y-m'). '/' .'订单分配-'.date('Y-m-d H:i') . '.xlsx';
// 保存文件到 public 下
$writer->save($file_path);
return getenv('APP_URL').$url;
}
}

View File

@ -0,0 +1,165 @@
<?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;
use Webman\Exception\BusinessException;
class OrderDetail
{
public $warehouse='海吉星仓库';
public $company='供投里海';
public $address='泸州龙马潭区海吉星122栋';
public $phone='08302669767';
public $tel='17309099881';
public function export($data,$system_store,$order)
{
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
// 合并单元格A1到K1
$sheet->mergeCells('A1:J1');
$sheet->mergeCells('B2:E2');
$sheet->mergeCells('G2:J2');
$sheet->mergeCells('G3:J3');
$sheet->mergeCells('B3:E3');
$sheet->mergeCells('B4:C4');
$sheet->mergeCells('D4:E4');
$sheet->setCellValue('A1', $this->company.'公司送货单');
$sheet->setCellValue('A2', '店铺名称');
$sheet->setCellValue('B2', $system_store);
$sheet->setCellValue('F2', '送货时间');
$sheet->setCellValue('G2', $order['delivery_time']??'');
$sheet->setCellValue('A3', '开单日期');
$sheet->setCellValue('B3', $order['pay_time']??'');
$sheet->setCellValue('F3', '单号');
$sheet->setCellValue('G3', $order['order_id']??'');
$sheet->setCellValue('A4', '序号');
$sheet->setCellValue('B4', '商品名称');
$sheet->setCellValue('D4', '规格');
$sheet->setCellValue('F4', '单位');
$sheet->setCellValue('G4', '单价');
$sheet->setCellValue('H4', '数量');
$sheet->setCellValue('I4', '总价');
$sheet->setCellValue('J4', '备注');
// 设置默认的单元格样式
$defaultStyle = [
'alignment' => [
'horizontal' => Alignment::HORIZONTAL_CENTER,
'vertical' => Alignment::VERTICAL_CENTER,
],
];
// 应用默认样式到整个工作表
$spreadsheet->getDefaultStyle()->applyFromArray($defaultStyle);
foreach ($data as $k => $v) {
$sheet->setCellValue('A' . ($k + 5), $k + 1);
$sheet->setCellValue('B' . ($k + 5), $v['store_name']);
$sheet->mergeCells('B' . ($k + 5) . ':C' . $k + 5);
$sheet->setCellValue('D' . ($k + 5), $v['store_info']);
$sheet->mergeCells('D' . ($k + 5) . ':E' . $k + 5);
$sheet->setCellValue('F' . ($k + 5), $v['unit_name']);
$sheet->setCellValue('G' . ($k + 5), $v['price']);
$sheet->setCellValue('H' . ($k + 5), $v['cart_num']);
$sheet->setCellValue('I' . ($k + 5), $v['total_price']);
}
$count = count($data);
$sheet->mergeCells('A' . ($count + 5) . ':J' . $count + 5);
$sheet->mergeCells('B' . ($count + 6) . ':E' . $count + 6);
$sheet->setCellValue('A' . $count + 6, '合计数量');
$sheet->setCellValue('B' . $count + 6,$order['total_num']);
$sheet->mergeCells('G' . ($count + 6) . ':J' . $count + 6);
$sheet->setCellValue('F' . $count + 6, '合计价格');
$sheet->setCellValue('G' . $count + 6, $order['total_price']);
$sheet->setCellValue('A' . ($count + 7), '备注');
$sheet->mergeCells('B' . ($count + 7) . ':J' . $count + 7);
$sheet->setCellValue('B' . ($count + 7), $order['mark']??'');
$sheet->mergeCells('A' . ($count + 8) . ':J' . $count + 8);
$sheet->mergeCells('A' . ($count + 9) . ':A' . $count + 10);
$sheet->setCellValue('A' . ($count + 9), '销售单位');
$sheet->setCellValue('B' . ($count + 9), '名称');
$sheet->setCellValue('C' . ($count + 9), $this->company);
$sheet->setCellValue('B' . ($count + 10), '地址');
$sheet->setCellValue('C' . ($count + 10), $this->address);
$sheet->setCellValue('G' . ($count + 9), '公司电话');
$sheet->setCellValue('H' . ($count + 9), $this->phone);
$sheet->setCellValue('G' . ($count + 10), '售后电话');
$sheet->setCellValue('H' . ($count + 10), $this->tel);
$sheet->mergeCells('C' . ($count + 9) . ':F' . $count + 9);
$sheet->mergeCells('C' . ($count + 10) . ':F' . $count + 10);
$sheet->mergeCells('H' . ($count + 9) . ':J' . ($count + 9));
$sheet->mergeCells('H' . ($count + 10) . ':J' . $count + 10);
$sheet->mergeCells('A' . ($count + 11) . ':J' . $count + 11);
$sheet->setCellValue('A' . $count + 12, '下单人',);
$sheet->mergeCells('B' . ($count + 12) . ':C' . $count + 12);
$sheet->setCellValue('B' . ($count + 12), $order['real_name']??'');
$sheet->setCellValue('D' . $count + 12, '电话');
$sheet->mergeCells('E' . ($count + 12) . ':F' . $count + 12);
$sheet->setCellValue('E' . ($count + 12), $order['user_phone']??'');
$sheet->setCellValue('G' . $count + 12, '地址');
$sheet->mergeCells('H' . ($count + 12) . ':J' . $count + 12);
$sheet->setCellValue('H' . ($count + 12), $order['user_address']??'');
$sheet->setCellValue('A' . $count + 13, '仓库',);
$sheet->mergeCells('B' . ($count + 13) . ':C' . $count + 13);
$sheet->setCellValue('D' . $count + 13, '送货');
$sheet->mergeCells('E' . ($count + 13) . ':F' . $count + 13);
$sheet->setCellValue('G' . $count + 13, '签收人');
$sheet->mergeCells('H' . ($count + 13) . ':J' . $count + 13);
// 设置单元格的样式
$styleArray = [
'font' => [
'bold' => true,
'size' => 16,
],
];
$sheet->getStyle('A1')->applyFromArray($styleArray);
// 定义线框样式
$styleArray = [
'borders' => [
'allBorders' => [
'borderStyle' => Border::BORDER_THIN, // 线框样式
'color' => ['argb' => '000000'], // 线框颜色
],
],
];
$sheet->getStyle('A1:J' . ($count + 13))->applyFromArray($styleArray);
// 保存文件到 public 下
$writer = new Xlsx($spreadsheet);
$dir=public_path().'/export/'.date('Y-m');
if (!file_exists($dir)) {
// 尝试创建目录
if (!mkdir($dir)) {
throw new BusinessException('创建目录失败:/export/' . date('Y-m'));
}
}
$file_path = $dir . '/' . $system_store.'出库单-'.date('YmdHi') . '.xlsx';
$url = '/export/'.date('Y-m') . '/' . $system_store.'出库单-'.date('YmdHi') . '.xlsx';
// 保存文件到 public 下
$writer->save($file_path);
return getenv('APP_URL').$url;
}
}

View File

@ -0,0 +1,147 @@
<?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;
use Webman\Exception\BusinessException;
/**
* 采购信息
*/
class OrderInfo
{
public function export($data,$order,$other_data)
{
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
// 合并单元格A1到K1
$sheet->mergeCells('A1:R1');
$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->setCellValue('A1', '采 购 信 息');
$sheet->setCellValue('A2', '姓名:');
$sheet->setCellValue('B2', $other_data->nickname??'');
$sheet->getColumnDimension('B')->setAutoSize(true);
$sheet->getColumnDimension('Q')->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->mergeCells('B3:D3');
$sheet->setCellValue('B3', '品名');
// $sheet->setCellValue('C3', '毛重');
// $sheet->setCellValue('D3', '净重(约)');
$sheet->mergeCells('E3:F3');
$sheet->setCellValue('E3', '单位');
// $sheet->setCellValue('F3', '采购单价');
$sheet->setCellValue('G3', '下单数量');
// $sheet->setCellValue('H3', '实收量');
// $sheet->setCellValue('I3', '采购金额');
// $sheet->setCellValue('J3', '结算模式');
// $sheet->setCellValue('K3', '包装');
// $sheet->setCellValue('L3', '押金');
// $sheet->setCellValue('M3', '型号');
// $sheet->setCellValue('N3', '售后');
// $sheet->setCellValue('O3', '损耗');
// $sheet->setCellValue('P3', '供应商');
$sheet->mergeCells('H3:Q3');
$sheet->setCellValue('H3', '备注');
$sheet->setCellValue('R3', '采购人');
// 设置默认的单元格样式
$defaultStyle = [
'alignment' => [
'horizontal' => Alignment::HORIZONTAL_CENTER,
'vertical' => Alignment::VERTICAL_CENTER,
],
];
// 应用默认样式到整个工作表
$spreadsheet->getDefaultStyle()->applyFromArray($defaultStyle);
foreach ($data as $k => $v) {
$sheet->setCellValue('A' . ($k + 4), $v['product_id']);
$sheet->mergeCells('B'. ($k + 4).':D'. ($k + 4));
$sheet->setCellValue('B' . ($k + 4), $v['store_name']);
// $sheet->setCellValue('C' . ($k + 4), $v['gross_weight']);
// $sheet->setCellValue('D' . ($k + 4), $v['net_weight']);
$sheet->mergeCells('E'. ($k + 4).':F'. ($k + 4));
$sheet->setCellValue('E' . ($k + 4), $v['unit_name']);
// $sheet->setCellValue('F' . ($k + 4), $v['price']);
$sheet->setCellValue('G' . ($k + 4), $v['need_num']);
$sheet->mergeCells('H'. ($k + 4).':Q'. ($k + 4));
// $sheet->setCellValue('H' . ($k + 4), $v['buyer_nums']);
// $sheet->setCellValue('I' . ($k + 4), $v['total_price']);
// $sheet->setCellValue('J' . ($k + 4), '');
// $sheet->setCellValue('K' . ($k + 4), $v['package']);
// $sheet->setCellValue('L' . ($k + 4), $v['deposit']);
// $sheet->setCellValue('M' . ($k + 4), $v['marques']);
// $sheet->setCellValue('N' . ($k + 4), $v['after_sales']);
// $sheet->setCellValue('O' . ($k + 4), $v['loss']);
// $sheet->setCellValue('P' . ($k + 4), '');
$sheet->setCellValue('H' . ($k + 4), $v['mark']);
$sheet->setCellValue('R' . ($k + 4), $v['buyer_name']);
}
$count = count($data);
$sheet->setCellValue('A' . ($count + 5),'合计');
$sheet->setCellValue('C' . ($count + 5),$count);
$sheet->mergeCells('A' . ($count + 6).':B' . ($count + 6));
$sheet->setCellValue('A' . ($count + 6),'采购员接单确认:');
$sheet->mergeCells('E' . ($count + 6).':G' . ($count + 6));
$sheet->setCellValue('E' . ($count + 6),'数据入库时间:');
$sheet->mergeCells('M' . ($count + 6).':N' . ($count + 6));
$sheet->setCellValue('M' . ($count + 6),'采购员录入签字:');
// 设置单元格的样式
$styleArray = [
'font' => [
'bold' => true,
'size' => 28,
],
];
$sheet->getStyle('A1')->applyFromArray($styleArray);
// 定义线框样式
$styleArray = [
'borders' => [
'allBorders' => [
'borderStyle' => Border::BORDER_THIN, // 线框样式
'color' => ['argb' => '000000'], // 线框颜色
],
],
];
$sheet->getStyle('A1:R' . ($count + 6))->applyFromArray($styleArray);
// 保存文件到 public 下
$writer = new Xlsx($spreadsheet);
$dir=public_path().'/export/'.date('Y-m');
if (!file_exists($dir)) {
// 尝试创建目录
if (!mkdir($dir)) {
throw new BusinessException('创建目录失败:/export/' . date('Y-m'));
}
}
$file_path = $dir . '/' .'采购信息-'.date('Y-m-d H:i') . '.xlsx';
$url = '/export/'.date('Y-m') . '/' .'采购信息-'.date('Y-m-d H:i') . '.xlsx';
// 保存文件到 public 下
$writer->save($file_path);
return getenv('APP_URL').$url;
}
}

View File

@ -0,0 +1,176 @@
<?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;
use Webman\Exception\BusinessException;
/**
* 订单清单
*/
class OrderList
{
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('E3:F3');
$sheet->mergeCells('G3:H3');
$sheet->mergeCells('I3:K3');
$sheet->mergeCells('N3:O3');
$sheet->mergeCells('B4:C4');
$sheet->mergeCells('D4:E4');
$sheet->mergeCells('F4:G4');
$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', $other_data->chef??'');
$sheet->setCellValue('D3', '电话:');
$sheet->setCellValue('E3', $other_data->chef_phone??'');
$sheet->setCellValue('G3', '事由:');
$sheet->setCellValue('I3', $other_data->purpose??'');
$sheet->setCellValue('L3', '桌数:');
$sheet->setCellValue('M3', $other_data->tables??'');
$sheet->setCellValue('N3', '办事时间:');
$sheet->setCellValue('P3', $other_data->days??'');
$sheet->setCellValue('A4', '下单时间:');
$sheet->setCellValue('B4', $order['create_time']??'');
$sheet->setCellValue('D4', '送货时间:');
$sheet->setCellValue('F4', $other_data->arrival_time??'');
$sheet->setCellValue('A5', '编号');
$sheet->setCellValue('B5', '类别');
$sheet->setCellValue('C5', '品名');
$sheet->setCellValue('D5', '毛重');
$sheet->setCellValue('E5', '净重(约)');
$sheet->setCellValue('F5', '单位');
$sheet->setCellValue('G5', '单价/元');
$sheet->setCellValue('H5', '下单数量');
$sheet->setCellValue('I5', '下单金额');
$sheet->setCellValue('J5', '包装');
$sheet->setCellValue('K5', '押金');
$sheet->setCellValue('L5', '售后');
$sheet->setCellValue('M5', '正常损耗');
$sheet->setCellValue('N5', '产地');
$sheet->mergeCells('O5:P5');
$sheet->setCellValue('O5', '备注');
// 设置默认的单元格样式
$defaultStyle = [
'alignment' => [
'horizontal' => Alignment::HORIZONTAL_CENTER,
'vertical' => Alignment::VERTICAL_CENTER,
],
];
// 应用默认样式到整个工作表
$spreadsheet->getDefaultStyle()->applyFromArray($defaultStyle);
foreach ($data as $k => $v) {
$sheet->setCellValue('A' . ($k + 6), $v['product_id']);
$sheet->setCellValue('B' . ($k + 6), $v['top_cate_name']);
$sheet->setCellValue('C' . ($k + 6), $v['store_name']);
$sheet->setCellValue('D' . ($k + 6), $v['gross_weight']);
$sheet->setCellValue('E' . ($k + 6), $v['net_weight']);
$sheet->setCellValue('F' . ($k + 6), $v['unit_name']);
$sheet->setCellValue('G' . ($k + 6), $v['price']);
$sheet->setCellValue('H' . ($k + 6), $v['cart_num']);
$sheet->setCellValue('I' . ($k + 6), $v['total_price']);
$sheet->setCellValue('J' . ($k + 6), $v['package']);
$sheet->setCellValue('K' . ($k + 6),$v['deposit']);
$sheet->setCellValue('L' . ($k + 6),$v['after_sales']);
$sheet->setCellValue('M' . ($k + 6),$v['loss']);
$sheet->mergeCells('O'.($k + 6).':P'.($k + 6));
$sheet->setCellValue('O' . ($k + 6),$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['deposit']);
$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']??0,$order['total_price']).'元');
$sheet->setCellValue('L' . ($count + 7),'接单员');
$sheet->setCellValue('M' . ($count + 7),$order['admin_name']);
$sheet->setCellValue('O' . ($count + 7),'分单员');
$sheet->setCellValue('P' . ($count + 7),$other_data->splitting_officer??'');
$sheet->mergeCells('A' . ($count + 8) . ':P' . $count + 8);
$sheet->setCellValue('A' . $count + 8, '备注:数量金额最终以实际收货金额结算,多退少补。押金退框无利息退还。',);
// 设置单元格的样式
$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 + 8))->applyFromArray($styleArray);
// 保存文件到 public 下
$writer = new Xlsx($spreadsheet);
$dir=public_path().'/export/'.date('Y-m');
if (!file_exists($dir)) {
// 尝试创建目录
if (!mkdir($dir)) {
throw new BusinessException('创建目录失败:/export/' . date('Y-m'));
}
}
$file_path = $dir. '/' .'供投里海农特产品下单清单-'.date('Y-m-d H:i') . '.xlsx';
$url = '/export/' . date('Y-m') . '/' .'供投里海农特产品下单清单-'.date('Y-m-d H:i') . '.xlsx';
// 保存文件到 public 下
$writer->save($file_path);
return getenv('APP_URL').$url;
}
}

View File

@ -0,0 +1,328 @@
<?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;
use Webman\Exception\BusinessException;
/**
* 订单出库
*/
class OrderOutbound
{
public function export($data,$order,$other_data)
{
$title='供 投 里 海 农 特 产 品 出 库 结 算 单';
$title2='供投里海农特产品出库结算单-';
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
// 合并单元格A1到K1
$sheet->mergeCells('A1:I1');
$sheet->mergeCells('D2:E2');
$sheet->mergeCells('H2:I2');
$sheet->mergeCells('G2:I2');
$sheet->mergeCells('H3:I3');
$sheet->setCellValue('A1', $title);
$sheet->setCellValue('A2', '姓名:');
$sheet->setCellValue('B2', $other_data->nickname??'');
$sheet->getColumnDimension('B')->setWidth(16);
$sheet->getColumnDimension('H')->setAutoSize(true);
$sheet->setCellValue('C2', '电话:');
$sheet->setCellValue('D2', $other_data->phone??'');
$sheet->setCellValue('F2', '订单编号:');
$sheet->setCellValue('G2', $order['order_id']??'');
$sheet->setCellValue('A3', '编号');
$sheet->setCellValue('B3', '品名');
$sheet->setCellValue('C3', '单位');
$sheet->setCellValue('D3', '净重(约)');
$sheet->setCellValue('E3', '数量');
$sheet->setCellValue('F3', '单价');
$sheet->setCellValue('G3', '金额');
$sheet->setCellValue('H3', '备注');
// 设置默认的单元格样式
$defaultStyle = [
'alignment' => [
'horizontal' => Alignment::HORIZONTAL_CENTER,
'vertical' => Alignment::VERTICAL_CENTER,
],
];
// 应用默认样式到整个工作表
$spreadsheet->getDefaultStyle()->applyFromArray($defaultStyle);
foreach ($data as $k => $v) {
$sheet->setCellValue('A' . ($k + 4), $v['product_id']);
$sheet->setCellValue('B' . ($k + 4), $v['store_name']);
$sheet->setCellValue('C' . ($k + 4), $v['unit_name']);
$sheet->setCellValue('D' . ($k + 4), $v['gross_weight']);
$sheet->setCellValue('E' . ($k + 4), $v['nums']);
$sheet->setCellValue('F' . ($k + 4), $v['price']);
$sheet->setCellValue('G' . ($k + 4), $v['total_price']);
$sheet->mergeCells('H' . ($k + 4) . ':I' . $k + 4);
$sheet->setCellValue('H' . ($k + 4), $v['mark']);
}
$count = count($data);
$sheet->setCellValue('A' . ($count + 4),'合计');
$sheet->setCellValue('B' . ($count + 4),$count);
$sheet->setCellValue('A' . ($count + 5),'累计接单:');
$sheet->setCellValue('C' . ($count + 5),'预收金额:');
$sheet->setCellValue('D' . ($count + 5),0);
$sheet->setCellValue('E' . ($count + 5),'预收押金:');
$sheet->setCellValue('G' . ($count + 5),'合计预收:');
$sheet->setCellValue('H' . ($count + 5),0);
$sheet->setCellValue('A' . ($count + 6),'出库合计:');
$sheet->setCellValue('C' . ($count + 6),'出库金额:');
$sheet->setCellValue('D' . ($count + 6),$order['pay_price']==0?$order['total_price']:$order['pay_price']);
$sheet->setCellValue('E' . ($count + 6),'实收押金:');
$sheet->setCellValue('G' . ($count + 6),'合计:');
$sheet->setCellValue('H' . ($count + 6),$order['pay_price']==0?$order['total_price']:$order['pay_price']);
$sheet->setCellValue('A' . ($count + 7),'应收:');
$sheet->setCellValue('B' . ($count + 7),$order['pay_price']==0?$order['total_price']:$order['pay_price']);
$sheet->setCellValue('C' . ($count + 7),'应退:');
$sheet->setCellValue('F' . ($count + 7),'门店:');
$sheet->mergeCells('G' . ($count + 7) . ':I' . $count + 7);
$sheet->setCellValue('G' . ($count + 7),$order['system_store_name']);
$sheet->mergeCells('B' . ($count + 8) . ':C' . $count + 8);
$sheet->setCellValue('A'. ($count + 8), '收货地址:');
$sheet->mergeCells('E' . ($count + 8) . ':F' . $count + 8);
$sheet->setCellValue('D'. ($count + 8), '下单时间:');
$sheet->setCellValue('E'. ($count + 8), $order['create_time']);
$sheet->setCellValue('G'. ($count + 8), '送货时间:');
$sheet->mergeCells('H' . ($count + 8) . ':I' . $count + 8);
$sheet->setCellValue('H'. ($count + 8), $other_data->arrival_time??'');
$sheet->setCellValue('B'. ($count + 8), $other_data->address??'');
$sheet->mergeCells('B' . ($count + 9) . ':E' . $count + 9);
$sheet->setCellValue('A' . $count + 9, '销售地址:',);
$sheet->setCellValue('B' . $count + 9, '泸州市海吉星农产品商贸物流园122栋',);
$sheet->setCellValue('F' . $count + 9, '电话:',);
$sheet->setCellValue('G' . $count + 9, '08302669767',);
$sheet->setCellValue('H' . $count + 9, '签收:',);
$sheet->mergeCells('A' . ($count + 10) . ':I' . ($count + 10));
$sheet->setCellValue('A' . ($count + 10), '退货政策说明:');
$sheet->mergeCells('A' . ($count + 11) . ':I' . ($count + 11));
$title3 = '1、冻货、生鲜、散装农产品等商品:由于此类商品是客户专项订购、无法重复销售,';
$sheet->setCellValue('A' . ($count + 11), $title3);
$sheet->mergeCells('A' . ($count + 12) . ':I' . ($count + 12));
$title3 ='一旦出库,恕不退换货,请务必在购买前确认商品信息及需求。';
$sheet->setCellValue('A' . ($count + 12), $title3);
$sheet->mergeCells('A' . ($count + 13) . ':I' . ($count + 13));
$title4 = '2、其余商品出库之日起10日内退货数量不得超过该商品购买数量的30%';
$sheet->setCellValue('A' . ($count + 13), $title4);
$sheet->mergeCells('A' . ($count + 14) . ':I' . ($count + 14));
$title4 = '上述要求旨在保障库存管理及商品周转的合理性。';
$sheet->setCellValue('A' . ($count + 14), $title4);
// 设置单元格的样式
$styleArray = [
'font' => [
'bold' => true,
'size' => 16,
],
];
$sheet->getStyle('A1')->applyFromArray($styleArray);
// 定义线框样式
$styleArray = [
'borders' => [
'allBorders' => [
'borderStyle' => Border::BORDER_THIN, // 线框样式
'color' => ['argb' => '000000'], // 线框颜色
],
],
];
$sheet->getStyle('A1:I' . ($count + 14))->applyFromArray($styleArray);
// 保存文件到 public 下
$writer = new Xlsx($spreadsheet);
$dir=public_path().'/export/'.date('Y-m');
if (!file_exists($dir)) {
// 尝试创建目录
if (!mkdir($dir)) {
throw new BusinessException('创建目录失败:/export/' . date('Y-m'));
}
}
$file_path = $dir . '/' .$title2.date('Y-m-d H:i') . '.xlsx';
$url = '/export/' . date('Y-m') . '/' .$title2.date('Y-m-d H:i') . '.xlsx';
// 保存文件到 public 下
$writer->save($file_path);
return getenv('APP_URL').$url;
}
/**
* 无价格供货单
*/
public function exportWithoutPrice($data,$order,$other_data)
{
$title='供 投 里 海 农 特 产 品 出 库 供 货 单';
$title2='供投里海农特产品出库供货单-';
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
// 合并单元格
$sheet->mergeCells('A1:I1');
$sheet->mergeCells('D2:E2');
$sheet->mergeCells('G2:I2');
$sheet->mergeCells('F3:I3');
$sheet->setCellValue('A1', $title);
$sheet->setCellValue('A2', '姓名:');
$sheet->setCellValue('B2', $other_data->nickname??'');
$sheet->getColumnDimension('B')->setWidth(16);
$sheet->getColumnDimension('H')->setAutoSize(true);
$sheet->setCellValue('C2', '电话:');
$sheet->setCellValue('D2', $other_data->phone??'');
$sheet->setCellValue('F2', '订单编号:');
$sheet->setCellValue('G2', $order['order_id']??'');
$sheet->setCellValue('A3', '编号');
$sheet->setCellValue('B3', '品名');
$sheet->setCellValue('C3', '单位');
$sheet->setCellValue('D3', '净重(约)');
$sheet->setCellValue('E3', '数量');
$sheet->setCellValue('F3', '备注');
// 设置默认的单元格样式
$defaultStyle = [
'alignment' => [
'horizontal' => Alignment::HORIZONTAL_CENTER,
'vertical' => Alignment::VERTICAL_CENTER,
],
];
// 应用默认样式到整个工作表
$spreadsheet->getDefaultStyle()->applyFromArray($defaultStyle);
foreach ($data as $k => $v) {
$sheet->setCellValue('A' . ($k + 4), $v['product_id']);
$sheet->setCellValue('B' . ($k + 4), $v['store_name']);
$sheet->setCellValue('C' . ($k + 4), $v['unit_name']);
$sheet->setCellValue('D' . ($k + 4), $v['gross_weight']);
$sheet->setCellValue('E' . ($k + 4), $v['nums']);
$sheet->mergeCells('F' . ($k + 4) . ':I' . $k + 4);
$sheet->setCellValue('F' . ($k + 4), $v['mark']);
}
$count = count($data);
$sheet->setCellValue('A' . ($count + 4),'合计');
$sheet->setCellValue('B' . ($count + 4),$count);
$sheet->setCellValue('A' . ($count + 5),'累计接单:');
$sheet->setCellValue('C' . ($count + 5),'预收金额:');
$sheet->setCellValue('D' . ($count + 5),0);
$sheet->setCellValue('E' . ($count + 5),'预收押金:');
$sheet->setCellValue('G' . ($count + 5),'合计预收:');
$sheet->setCellValue('H' . ($count + 5),0);
$sheet->setCellValue('A' . ($count + 6),'出库合计:');
$sheet->setCellValue('C' . ($count + 6),'出库金额:');
$sheet->setCellValue('D' . ($count + 6),0);
$sheet->setCellValue('E' . ($count + 6),'实收押金:');
$sheet->setCellValue('G' . ($count + 6),'合计:');
$sheet->setCellValue('H' . ($count + 6),0);
$sheet->setCellValue('A' . ($count + 7),'应收:');
$sheet->setCellValue('B' . ($count + 7),0);
$sheet->setCellValue('C' . ($count + 7),'应退:');
$sheet->setCellValue('F' . ($count + 7),'门店:');
$sheet->mergeCells('G' . ($count + 7) . ':I' . $count + 7);
$sheet->setCellValue('G' . ($count + 7),$order['system_store_name']);
$sheet->mergeCells('B' . ($count + 8) . ':C' . $count + 8);
$sheet->setCellValue('A'. ($count + 8), '收货地址:');
$sheet->mergeCells('E' . ($count + 8) . ':F' . $count + 8);
$sheet->setCellValue('D'. ($count + 8), '下单时间:');
$sheet->setCellValue('E'. ($count + 8), $order['create_time']);
$sheet->setCellValue('G'. ($count + 8), '送货时间:');
$sheet->mergeCells('H' . ($count + 8) . ':I' . $count + 8);
$sheet->setCellValue('H'. ($count + 8), $other_data->arrival_time??'');
$sheet->setCellValue('B'. ($count + 8), $other_data->address??'');
$sheet->mergeCells('B' . ($count + 9) . ':E' . $count + 9);
$sheet->setCellValue('A' . $count + 9, '销售地址:',);
$sheet->setCellValue('B' . $count + 9, '泸州市海吉星农产品商贸物流园122栋',);
$sheet->setCellValue('F' . $count + 9, '电话:',);
$sheet->setCellValue('G' . $count + 9, '08302669767',);
$sheet->setCellValue('H' . $count + 9, '签收:',);
$sheet->mergeCells('A' . ($count + 10) . ':I' . ($count + 10));
$sheet->setCellValue('A' . ($count + 10), '退货政策说明:');
$sheet->mergeCells('A' . ($count + 11) . ':I' . ($count + 11));
$title3 = '1、冻货、生鲜、散装农产品等商品:由于此类商品是客户专项订购、无法重复销售,';
$sheet->setCellValue('A' . ($count + 11), $title3);
$sheet->mergeCells('A' . ($count + 12) . ':I' . ($count + 12));
$title3 ='一旦出库,恕不退换货,请务必在购买前确认商品信息及需求。';
$sheet->setCellValue('A' . ($count + 12), $title3);
$sheet->mergeCells('A' . ($count + 13) . ':I' . ($count + 13));
$title4 = '2、其余商品出库之日起10日内退货数量不得超过该商品购买数量的30%';
$sheet->setCellValue('A' . ($count + 13), $title4);
$sheet->mergeCells('A' . ($count + 14) . ':I' . ($count + 14));
$title4 = '上述要求旨在保障库存管理及商品周转的合理性。';
$sheet->setCellValue('A' . ($count + 14), $title4);
// 设置单元格的样式
$styleArray = [
'font' => [
'bold' => true,
'size' => 16,
],
];
$sheet->getStyle('A1')->applyFromArray($styleArray);
// 定义线框样式
$styleArray = [
'borders' => [
'allBorders' => [
'borderStyle' => Border::BORDER_THIN, // 线框样式
'color' => ['argb' => '000000'], // 线框颜色
],
],
];
$sheet->getStyle('A1:I' . ($count + 14))->applyFromArray($styleArray);
// 保存文件到 public 下
$writer = new Xlsx($spreadsheet);
$dir=public_path().'/export/'.date('Y-m');
if (!file_exists($dir)) {
// 尝试创建目录
if (!mkdir($dir)) {
throw new BusinessException('创建目录失败:/export/' . date('Y-m'));
}
}
$file_path = $dir . '/' .$title2.date('Y-m-d H:i') . '.xlsx';
$url = '/export/' . date('Y-m') . '/' .$title2.date('Y-m-d H:i') . '.xlsx';
// 保存文件到 public 下
$writer->save($file_path);
return getenv('APP_URL').$url;
}
}

View File

@ -0,0 +1,160 @@
<?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;
use Webman\Exception\BusinessException;
/**
* 财务订单出库
*/
class OrderOutboundFinance
{
public function export($data,$order,$other_data,$type=1)
{
if($type==1){
$title='供 投 里 海 农 特 产 品 出 库 结 算 单';
$title2='供投里海农特产品出库结算单-';
}else{
$title='供 投 里 海 农 特 产 品 出 库 供 货 单';
$title2='供投里海农特产品出库供货单-';
}
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
// 合并单元格A1到K1
$sheet->mergeCells('A1:I1');
$sheet->mergeCells('D2:E2');
$sheet->mergeCells('H2:I2');
$sheet->mergeCells('G2:I2');
$sheet->mergeCells('H3:I3');
$sheet->setCellValue('A1', $title);
$sheet->setCellValue('A2', '姓名:');
$sheet->setCellValue('B2', $other_data->nickname??'');
$sheet->getColumnDimension('B')->setWidth(16);
$sheet->getColumnDimension('H')->setAutoSize(true);
$sheet->setCellValue('C2', '电话:');
$sheet->setCellValue('D2', $other_data->phone??'');
$sheet->setCellValue('F2', '订单编号:');
$sheet->setCellValue('G2', $order['order_id']??'');
$sheet->setCellValue('A3', '编号');
$sheet->setCellValue('B3', '品名');
$sheet->setCellValue('C3', '单位');
$sheet->setCellValue('D3', '净重(约)');
$sheet->setCellValue('E3', '数量');
$sheet->setCellValue('F3', '单价');
$sheet->setCellValue('G3', '供货价');
$sheet->setCellValue('H3', '出库价');
$sheet->setCellValue('I3', '毛利');
$sheet->setCellValue('J3', '备注');
// 设置默认的单元格样式
$defaultStyle = [
'alignment' => [
'horizontal' => Alignment::HORIZONTAL_CENTER,
'vertical' => Alignment::VERTICAL_CENTER,
],
];
// 应用默认样式到整个工作表
$spreadsheet->getDefaultStyle()->applyFromArray($defaultStyle);
foreach ($data as $k => $v) {
$sheet->setCellValue('A' . ($k + 4), $v['product_id']);
$sheet->setCellValue('B' . ($k + 4), $v['store_name']);
$sheet->setCellValue('C' . ($k + 4), $v['unit_name']);
$sheet->setCellValue('D' . ($k + 4), $v['gross_weight']);
$sheet->setCellValue('E' . ($k + 4), $v['nums']);
$sheet->setCellValue('F' . ($k + 4), $v['price']);
$sheet->setCellValue('G' . ($k + 4), $v['total_price']);
$sheet->mergeCells('H' . ($k + 4) . ':I' . $k + 4);
$sheet->setCellValue('H' . ($k + 4), $v['mark']);
}
$count = count($data);
$sheet->setCellValue('A' . ($count + 4),'合计');
$sheet->setCellValue('B' . ($count + 4),$count);
$sheet->setCellValue('A' . ($count + 5),'累计接单:');
$sheet->setCellValue('C' . ($count + 5),'预收金额:');
$sheet->setCellValue('D' . ($count + 5),0);
$sheet->setCellValue('E' . ($count + 5),'预收押金:');
$sheet->setCellValue('G' . ($count + 5),'合计预收:');
$sheet->setCellValue('H' . ($count + 5),0);
$sheet->setCellValue('A' . ($count + 6),'出库合计:');
$sheet->setCellValue('C' . ($count + 6),'出库金额:');
$sheet->setCellValue('D' . ($count + 6),$order['pay_price']==0?$order['total_price']:$order['pay_price']);
$sheet->setCellValue('E' . ($count + 6),'实收押金:');
$sheet->setCellValue('G' . ($count + 6),'合计:');
$sheet->setCellValue('H' . ($count + 6),$order['pay_price']==0?$order['total_price']:$order['pay_price']);
$sheet->setCellValue('A' . ($count + 7),'应收:');
$sheet->setCellValue('B' . ($count + 7),$order['pay_price']==0?$order['total_price']:$order['pay_price']);
$sheet->setCellValue('C' . ($count + 7),'应退:');
$sheet->setCellValue('F' . ($count + 7),'门店:');
$sheet->mergeCells('G' . ($count + 7) . ':I' . $count + 7);
$sheet->setCellValue('G' . ($count + 7),$order['system_store_name']);
$sheet->mergeCells('B' . ($count + 8) . ':C' . $count + 8);
$sheet->setCellValue('A'. ($count + 8), '收货地址:');
$sheet->mergeCells('E' . ($count + 8) . ':F' . $count + 8);
$sheet->setCellValue('D'. ($count + 8), '下单时间:');
$sheet->setCellValue('E'. ($count + 8), $order['create_time']);
$sheet->setCellValue('G'. ($count + 8), '送货时间:');
$sheet->mergeCells('H' . ($count + 8) . ':I' . $count + 8);
$sheet->setCellValue('H'. ($count + 8), $other_data->arrival_time??'');
$sheet->setCellValue('B'. ($count + 8), $other_data->address??'');
$sheet->mergeCells('B' . ($count + 9) . ':E' . $count + 9);
$sheet->setCellValue('A' . $count + 9, '销售地址:',);
$sheet->setCellValue('B' . $count + 9, '泸州市海吉星农产品商贸物流园122栋',);
$sheet->setCellValue('F' . $count + 9, '电话:',);
$sheet->setCellValue('G' . $count + 9, '08302669767',);
$sheet->setCellValue('H' . $count + 9, '签收:',);
// 设置单元格的样式
$styleArray = [
'font' => [
'bold' => true,
'size' => 16,
],
];
$sheet->getStyle('A1')->applyFromArray($styleArray);
// 定义线框样式
$styleArray = [
'borders' => [
'allBorders' => [
'borderStyle' => Border::BORDER_THIN, // 线框样式
'color' => ['argb' => '000000'], // 线框颜色
],
],
];
$sheet->getStyle('A1:I' . ($count + 9))->applyFromArray($styleArray);
// 保存文件到 public 下
$writer = new Xlsx($spreadsheet);
$dir=public_path().'/export/'.date('Y-m');
if (!file_exists($dir)) {
// 尝试创建目录
if (!mkdir($dir)) {
throw new BusinessException('创建目录失败:/export/' . date('Y-m'));
}
}
$file_path = $dir . '/' .$title2.date('Y-m-d H:i') . '.xlsx';
$url = '/export/' . date('Y-m') . '/' .$title2.date('Y-m-d H:i') . '.xlsx';
// 保存文件到 public 下
$writer->save($file_path);
return getenv('APP_URL').$url;
}
}

View File

@ -0,0 +1,185 @@
<?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;
use Webman\Exception\BusinessException;
/**
* 订单出库
*/
class OrderSupplyOutbound
{
public function export($data,$order,$other_data,$type=1)
{
if($type==1){
$title='供 投 里 海 农 特 产 品 出 库 结 算 单';
$title2='供投里海农特产品出库结算单-';
}else{
$title='供 投 里 海 农 特 产 品 出 库 供 货 单';
$title2='供投里海农特产品出库供货单-';
}
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
// 合并单元格A1到K1
$sheet->mergeCells('A1:K1');
$sheet->mergeCells('D2:E2');
$sheet->mergeCells('H2:I2');
$sheet->mergeCells('G2:I2');
$sheet->mergeCells('J3:K3');
$sheet->setCellValue('A1', $title);
$sheet->setCellValue('A2', '姓名:');
$sheet->setCellValue('B2', $other_data->nickname??'');
$sheet->getColumnDimension('B')->setWidth(16);
$sheet->getColumnDimension('H')->setAutoSize(true);
$sheet->setCellValue('C2', '电话:');
$sheet->setCellValue('D2', $other_data->phone??'');
$sheet->setCellValue('F2', '订单编号:');
$sheet->setCellValue('G2', $order['order_id']??'');
$sheet->setCellValue('A3', '编号');
$sheet->setCellValue('B3', '品名');
$sheet->setCellValue('C3', '单位');
$sheet->setCellValue('D3', '数量');
$sheet->setCellValue('E3', '出库单价');
$sheet->setCellValue('F3', '出库总价');
$sheet->setCellValue('G3', '供货价');
$sheet->setCellValue('H3', '供货总价');
$sheet->setCellValue('I3', '利润');
$sheet->setCellValue('J3', '备注');
// 设置默认的单元格样式
$defaultStyle = [
'alignment' => [
'horizontal' => Alignment::HORIZONTAL_CENTER,
'vertical' => Alignment::VERTICAL_CENTER,
],
];
// 应用默认样式到整个工作表
$spreadsheet->getDefaultStyle()->applyFromArray($defaultStyle);
foreach ($data as $k => $v) {
$sheet->setCellValue('A' . ($k + 4), $v['product_id']);
$sheet->setCellValue('B' . ($k + 4), $v['store_name']);
$sheet->setCellValue('C' . ($k + 4), $v['unit_name']);
$sheet->setCellValue('D' . ($k + 4), $v['nums']);
$sheet->setCellValue('E' . ($k + 4), $v['price']);
$sheet->setCellValue('F' . ($k + 4), $v['total_price']);
$sheet->setCellValue('G' . ($k + 4), $v['purchase']);
$sheet->setCellValue('H' . ($k + 4), $v['pay_price']);
$sheet->setCellValue('I' . ($k + 4), $v['profit']);
$sheet->mergeCells('J' . ($k + 4) . ':K' . $k + 4);
$sheet->setCellValue('J' . ($k + 4), $v['mark']);
}
$count = count($data);
$sheet->setCellValue('A' . ($count + 4),'合计');
$sheet->setCellValue('B' . ($count + 4),$count);
$sheet->setCellValue('J' . ($count + 4),$order['group_title']??'');
$sheet->setCellValue('A' . ($count + 5),'累计接单:');
$sheet->setCellValue('C' . ($count + 5),'预收金额:');
$sheet->setCellValue('D' . ($count + 5),0);
$sheet->setCellValue('E' . ($count + 5),'预收押金:');
$sheet->setCellValue('G' . ($count + 5),'合计预收:');
$sheet->setCellValue('H' . ($count + 5),0);
$sheet->setCellValue('A' . ($count + 6),'出库合计:');
$sheet->setCellValue('C' . ($count + 6),'出库金额:');
$sheet->setCellValue('D' . ($count + 6),$order['total_price']);
$sheet->setCellValue('E' . ($count + 6),'实收押金:');
$sheet->setCellValue('G' . ($count + 6),'供货总价:');
$sheet->setCellValue('H' . ($count + 6),$order['pay_price']);
$sheet->setCellValue('I' . ($count + 6),'总利润:');
$sheet->setCellValue('J' . ($count + 6),$order['total_profit']);
$sheet->setCellValue('A' . ($count + 7),'应收:');
$sheet->setCellValue('B' . ($count + 7),$order['pay_price']);
$sheet->setCellValue('C' . ($count + 7),'应退:');
$sheet->setCellValue('F' . ($count + 7),'门店:');
$sheet->mergeCells('G' . ($count + 7) . ':I' . $count + 7);
$sheet->setCellValue('G' . ($count + 7),$order['system_store_name']);
$sheet->mergeCells('B' . ($count + 8) . ':C' . $count + 8);
$sheet->setCellValue('A'. ($count + 8), '收货地址:');
$sheet->mergeCells('E' . ($count + 8) . ':F' . $count + 8);
$sheet->setCellValue('D'. ($count + 8), '下单时间:');
$sheet->setCellValue('E'. ($count + 8), $order['create_time']);
$sheet->setCellValue('G'. ($count + 8), '送货时间:');
$sheet->mergeCells('H' . ($count + 8) . ':I' . $count + 8);
$sheet->setCellValue('H'. ($count + 8), $other_data->arrival_time??'');
$sheet->setCellValue('B'. ($count + 8), $other_data->address??'');
$sheet->mergeCells('B' . ($count + 9) . ':E' . $count + 9);
$sheet->setCellValue('A' . $count + 9, '销售地址:',);
$sheet->setCellValue('B' . $count + 9, '泸州市海吉星农产品商贸物流园122栋',);
$sheet->setCellValue('F' . $count + 9, '电话:',);
$sheet->setCellValue('G' . $count + 9, '08302669767',);
$sheet->setCellValue('H' . $count + 9, '签收:',);
$sheet->mergeCells('A' . ($count + 10) . ':K' . ($count + 10));
$sheet->setCellValue('A' . ($count + 10), '退货政策说明:');
$sheet->mergeCells('A' . ($count + 11) . ':K' . ($count + 11));
$title3 = '1、冻货、生鲜、散装农产品等商品:由于此类商品是客户专项订购、无法重复销售,';
$sheet->setCellValue('A' . ($count + 11), $title3);
$sheet->mergeCells('A' . ($count + 12) . ':K' . ($count + 12));
$title3 ='一旦出库,恕不退换货,请务必在购买前确认商品信息及需求。';
$sheet->setCellValue('A' . ($count + 12), $title3);
$sheet->mergeCells('A' . ($count + 13) . ':K' . ($count + 13));
$title4 = '2、其余商品出库之日起10日内退货数量不得超过该商品购买数量的30%';
$sheet->setCellValue('A' . ($count + 13), $title4);
$sheet->mergeCells('A' . ($count + 14) . ':K' . ($count + 14));
$title4 = '上述要求旨在保障库存管理及商品周转的合理性。';
$sheet->setCellValue('A' . ($count + 14), $title4);
// 设置单元格的样式
$styleArray = [
'font' => [
'bold' => true,
'size' => 16,
],
];
$sheet->getStyle('A1')->applyFromArray($styleArray);
// 定义线框样式
$styleArray = [
'borders' => [
'allBorders' => [
'borderStyle' => Border::BORDER_THIN, // 线框样式
'color' => ['argb' => '000000'], // 线框颜色
],
],
];
$sheet->getStyle('A1:K' . ($count + 14))->applyFromArray($styleArray);
// 保存文件到 public 下
$writer = new Xlsx($spreadsheet);
$dir=public_path().'/export/'.date('Y-m');
if (!file_exists($dir)) {
// 尝试创建目录
if (!mkdir($dir)) {
throw new BusinessException('创建目录失败:/export/' . date('Y-m'));
}
}
$file_path = $dir . '/' .$title2.date('Y-m-d H:i') . '.xlsx';
$url = '/export/' . date('Y-m') . '/' .$title2.date('Y-m-d H:i') . '.xlsx';
// 保存文件到 public 下
$writer->save($file_path);
return getenv('APP_URL').$url;
}
}

View File

@ -0,0 +1,128 @@
<?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;
use Webman\Exception\BusinessException;
/**
* 订单退供应商
*/
class ReturnSupplier
{
public function export($data,$order,$other_data)
{
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
// 合并单元格A1到K1
$sheet->mergeCells('A1:I1');
$sheet->mergeCells('D2:E2');
$sheet->mergeCells('H2:I2');
$sheet->mergeCells('G2:I2');
$sheet->mergeCells('H3:I3');
$sheet->setCellValue('A1', '供 投 里 海 农 特 产 品 退 供 应 商 结 算 单');
$sheet->setCellValue('A2', '姓名:');
$sheet->setCellValue('B2', '供 投 里 海');
$sheet->getColumnDimension('B')->setWidth(16);
$sheet->getColumnDimension('H')->setAutoSize(true);
$sheet->setCellValue('C2', '电话:');
$sheet->setCellValue('D2', '08302669767');
$sheet->setCellValue('F2', '订单编号:');
$sheet->setCellValue('G2', $order['order_id']??'');
$sheet->setCellValue('A3', '编号');
$sheet->setCellValue('B3', '品名');
$sheet->setCellValue('C3', '单位');
$sheet->setCellValue('D3', '净重(约)');
$sheet->setCellValue('E3', '数量');
$sheet->setCellValue('F3', '单价');
$sheet->setCellValue('G3', '金额');
$sheet->setCellValue('H3', '备注');
// 设置默认的单元格样式
$defaultStyle = [
'alignment' => [
'horizontal' => Alignment::HORIZONTAL_CENTER,
'vertical' => Alignment::VERTICAL_CENTER,
],
];
// 应用默认样式到整个工作表
$spreadsheet->getDefaultStyle()->applyFromArray($defaultStyle);
foreach ($data as $k => $v) {
$sheet->setCellValue('A' . ($k + 4), $v['product_id']);
$sheet->setCellValue('B' . ($k + 4), $v['store_name']);
$sheet->setCellValue('C' . ($k + 4), $v['unit_name']);
$sheet->setCellValue('D' . ($k + 4), $v['gross_weight']);
$sheet->setCellValue('E' . ($k + 4), $v['nums']);
$sheet->setCellValue('F' . ($k + 4), $v['price']);
$sheet->setCellValue('G' . ($k + 4), $v['total_price']);
$sheet->mergeCells('H' . ($k + 4) . ':I' . $k + 4);
$sheet->setCellValue('H' . ($k + 4), $v['mark']);
}
$count = count($data);
$sheet->setCellValue('A' . ($count + 4),'合计');
$sheet->setCellValue('B' . ($count + 4),$count);
$sheet->setCellValue('A' . ($count + 6),'退单合计:');
$sheet->setCellValue('C' . ($count + 6),'退单金额:');
$sheet->setCellValue('D' . ($count + 6),$order['total_price']);
$sheet->setCellValue('E' . ($count + 6),'退单押金:');
$sheet->setCellValue('G' . ($count + 6),'合计:');
$sheet->setCellValue('H' . ($count + 6),$order['total_price']);
$sheet->setCellValue('A' . ($count + 7),'应收:');
$sheet->setCellValue('C' . ($count + 7),'应退:');
$sheet->setCellValue('D' . ($count + 7),$order['total_price']);
$sheet->mergeCells('B' . ($count + 9) . ':E' . $count + 9);
$sheet->setCellValue('A' . $count + 9, '销售地址:',);
$sheet->setCellValue('B' . $count + 9, '',);
$sheet->setCellValue('F' . $count + 9, '电话:',);
$sheet->setCellValue('G' . $count + 9, '',);
$sheet->setCellValue('H' . $count + 9, '签收:',);
// 设置单元格的样式
$styleArray = [
'font' => [
'bold' => true,
'size' => 16,
],
];
$sheet->getStyle('A1')->applyFromArray($styleArray);
// 定义线框样式
$styleArray = [
'borders' => [
'allBorders' => [
'borderStyle' => Border::BORDER_THIN, // 线框样式
'color' => ['argb' => '000000'], // 线框颜色
],
],
];
$sheet->getStyle('A1:I' . ($count + 9))->applyFromArray($styleArray);
// 保存文件到 public 下
$writer = new Xlsx($spreadsheet);
$dir=public_path().'/export/'.date('Y-m');
if (!file_exists($dir)) {
// 尝试创建目录
if (!mkdir($dir)) {
throw new BusinessException('创建目录失败:/export/' . date('Y-m'));
}
}
$file_path = $dir . '/' .'供投里海农特产品退供应商结算单-'.date('Y-m-d H:i') . '.xlsx';
$url = '/export/' . date('Y-m') . '/' .'供投里海农特产品退供应商结算单-'.date('Y-m-d H:i') . '.xlsx';
// 保存文件到 public 下
$writer->save($file_path);
return getenv('APP_URL').$url;
}
}

View File

@ -0,0 +1,144 @@
<?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;
use Webman\Exception\BusinessException;
/**
* 订单退库
*/
class StockReturn
{
public function export($data,$order,$other_data)
{
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
// 合并单元格A1到K1
$sheet->mergeCells('A1:I1');
$sheet->mergeCells('D2:E2');
$sheet->mergeCells('H2:I2');
$sheet->mergeCells('G2:I2');
$sheet->mergeCells('H3:I3');
$sheet->setCellValue('A1', '供 投 里 海 农 特 产 品 退 库 结 算 单');
$sheet->setCellValue('A2', '姓名:');
$sheet->setCellValue('B2', $other_data->nickname??'');
$sheet->getColumnDimension('B')->setWidth(16);
$sheet->getColumnDimension('H')->setAutoSize(true);
$sheet->setCellValue('C2', '电话:');
$sheet->setCellValue('D2', $other_data->phone??'');
$sheet->setCellValue('F2', '订单编号:');
$sheet->setCellValue('G2', $order['order_id']??'');
$sheet->setCellValue('A3', '编号');
$sheet->setCellValue('B3', '品名');
$sheet->setCellValue('C3', '单位');
$sheet->setCellValue('D3', '净重(约)');
$sheet->setCellValue('E3', '数量');
$sheet->setCellValue('F3', '单价');
$sheet->setCellValue('G3', '金额');
$sheet->setCellValue('H3', '备注');
// 设置默认的单元格样式
$defaultStyle = [
'alignment' => [
'horizontal' => Alignment::HORIZONTAL_CENTER,
'vertical' => Alignment::VERTICAL_CENTER,
],
];
// 应用默认样式到整个工作表
$spreadsheet->getDefaultStyle()->applyFromArray($defaultStyle);
foreach ($data as $k => $v) {
$sheet->setCellValue('A' . ($k + 4), $v['product_id']);
$sheet->setCellValue('B' . ($k + 4), $v['store_name']);
$sheet->setCellValue('C' . ($k + 4), $v['unit_name']);
$sheet->setCellValue('D' . ($k + 4), $v['gross_weight']);
$sheet->setCellValue('E' . ($k + 4), $v['nums']);
$sheet->setCellValue('F' . ($k + 4), $v['price']);
$sheet->setCellValue('G' . ($k + 4), $v['total_price']);
$sheet->mergeCells('H' . ($k + 4) . ':I' . $k + 4);
$sheet->setCellValue('H' . ($k + 4), $v['mark']);
}
$count = count($data);
$sheet->setCellValue('A' . ($count + 4),'合计');
$sheet->setCellValue('B' . ($count + 4),$count);
$sheet->setCellValue('A' . ($count + 6),'退库合计:');
$sheet->setCellValue('C' . ($count + 6),'退库金额:');
$sheet->setCellValue('D' . ($count + 6),$order['total_price']);
$sheet->setCellValue('E' . ($count + 6),'退库押金:');
$sheet->setCellValue('G' . ($count + 6),'合计:');
$sheet->setCellValue('H' . ($count + 6),$order['total_price']);
$sheet->setCellValue('A' . ($count + 7),'应收:');
$sheet->setCellValue('C' . ($count + 7),'应退:');
$sheet->setCellValue('D' . ($count + 7),$order['total_price']);
$sheet->setCellValue('F' . ($count + 7),'门店:');
$sheet->mergeCells('G' . ($count + 7) . ':I' . $count + 7);
$sheet->setCellValue('G' . ($count + 7),$order['system_store_name']);
$sheet->mergeCells('B' . ($count + 8) . ':C' . $count + 8);
$sheet->setCellValue('A'. ($count + 8), '收货地址:');
$sheet->mergeCells('E' . ($count + 8) . ':F' . $count + 8);
$sheet->setCellValue('D'. ($count + 8), '下单时间:');
$sheet->setCellValue('E'. ($count + 8), $order['create_time']);
$sheet->setCellValue('G'. ($count + 8), '送货时间:');
$sheet->mergeCells('H' . ($count + 8) . ':I' . $count + 8);
$sheet->setCellValue('H'. ($count + 8), $other_data->arrival_time??'');
$sheet->setCellValue('B'. ($count + 8), $other_data->address??'');
$sheet->mergeCells('B' . ($count + 9) . ':E' . $count + 9);
$sheet->setCellValue('A' . $count + 9, '销售地址:',);
$sheet->setCellValue('B' . $count + 9, '泸州市海吉星农产品商贸物流园122栋',);
$sheet->setCellValue('F' . $count + 9, '电话:',);
$sheet->setCellValue('G' . $count + 9, '08302669767',);
$sheet->setCellValue('H' . $count + 9, '签收:',);
// 设置单元格的样式
$styleArray = [
'font' => [
'bold' => true,
'size' => 16,
],
];
$sheet->getStyle('A1')->applyFromArray($styleArray);
// 定义线框样式
$styleArray = [
'borders' => [
'allBorders' => [
'borderStyle' => Border::BORDER_THIN, // 线框样式
'color' => ['argb' => '000000'], // 线框颜色
],
],
];
$sheet->getStyle('A1:I' . ($count + 9))->applyFromArray($styleArray);
// 保存文件到 public 下
$writer = new Xlsx($spreadsheet);
$dir=public_path().'/export/'.date('Y-m');
if (!file_exists($dir)) {
// 尝试创建目录
if (!mkdir($dir)) {
throw new BusinessException('创建目录失败:/export/' . date('Y-m'));
}
}
$file_path = $dir . '/' .'供投里海农特产品退库结算单-'.date('Y-m-d H:i') . '.xlsx';
$url = '/export/' . date('Y-m') . '/' .'供投里海农特产品退库结算单-'.date('Y-m-d H:i') . '.xlsx';
// 保存文件到 public 下
$writer->save($file_path);
return getenv('APP_URL').$url;
}
}

View File

@ -0,0 +1,65 @@
<?php
namespace app\common\service\xlsx;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\Border;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use PhpOffice\PhpSpreadsheet\Style\Alignment;
class StoreFinanceFlowXlsx
{
public function export($data, $type)
{
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', '交易单号');
$sheet->setCellValue('B1', '交易时间');
$sheet->setCellValue('C1', '金额');
$sheet->setCellValue('D1', '门店');
$sheet->setCellValue('E1', '用户');
$sheet->setCellValue('F1', '流水类型');
// 设置默认的单元格样式
$defaultStyle = [
'alignment' => [
'horizontal' => Alignment::HORIZONTAL_CENTER,
'vertical' => Alignment::VERTICAL_CENTER,
],
];
// 应用默认样式到整个工作表
$spreadsheet->getDefaultStyle()->applyFromArray($defaultStyle);
$column = 2;
foreach ($data as $k => $item) {
$sheet->setCellValue("A$column", $item['order_sn']);
$sheet->setCellValue("B$column", $item['create_time']);
$sheet->setCellValue("C$column", $item['number']);
$sheet->setCellValue("D$column", $item['store_name']);
$sheet->setCellValue("E$column", $item['nickname']);
$sheet->setCellValue("F$column", $type);
$column++;
}
// 定义线框样式
$styleArray = [
'borders' => [
'allBorders' => [
'borderStyle' => Border::BORDER_THIN, // 线框样式
'color' => ['argb' => '000000'], // 线框颜色
],
],
];
$sheet->getStyle('A1:F' . $column)->applyFromArray($styleArray);
$writer = new Xlsx($spreadsheet);
$url = '/export/' . "门店财务流水 - $type " . date('YmdHi') . '.xlsx';
$file_path = public_path() . $url;
if (!is_dir(dirname($file_path))) {
mkdir(dirname($file_path), 0777, true);
}
$writer->save($file_path);
return getenv('APP_URL') . $url;
}
}

View File

@ -0,0 +1,78 @@
<?php
namespace app\common\service\xlsx;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\Border;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use PhpOffice\PhpSpreadsheet\Style\Alignment;
class StoreProductPriceXlsx
{
public function export($data)
{
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$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', '零售价');
$sheet->setCellValue('L1', '时间');
// 设置默认的单元格样式
$defaultStyle = [
'alignment' => [
'horizontal' => Alignment::HORIZONTAL_CENTER,
'vertical' => Alignment::VERTICAL_CENTER,
],
];
// 应用默认样式到整个工作表
$spreadsheet->getDefaultStyle()->applyFromArray($defaultStyle);
$column = 2;
foreach ($data as $k => $item) {
$sheet->setCellValue("A$column", $item['product_id']);
$sheet->setCellValue("B$column", $item['store_name']);
$sheet->setCellValue("C$column", $item['purchase_price']);
$sheet->setCellValue("D$column", $item['purchase_lv']);
$sheet->setCellValue("E$column", $item['purchase']);
$sheet->setCellValue("F$column", $item['cost_lv']);
$sheet->setCellValue("I$column", $item['cost']);
$sheet->setCellValue("J$column", $item['vip_lv']);
$sheet->setCellValue("G$column", $item['vip_price']);
$sheet->setCellValue("H$column", $item['price_lv']);
$sheet->setCellValue("K$column", $item['price']);
$sheet->setCellValue("L$column", $item['create_time']);
$column++;
}
// 定义线框样式
$styleArray = [
'borders' => [
'allBorders' => [
'borderStyle' => Border::BORDER_THIN, // 线框样式
'color' => ['argb' => '000000'], // 线框颜色
],
],
];
$sheet->getStyle('A1:L' . $column)->applyFromArray($styleArray);
$writer = new Xlsx($spreadsheet);
$url = '/export/' . "商品价格更改列表 " . date('YmdHi') . '.xlsx';
$file_path = public_path() . $url;
if (!is_dir(dirname($file_path))) {
mkdir(dirname($file_path), 0777, true);
}
$writer->save($file_path);
return getenv('APP_URL') . $url;
}
}

View File

@ -0,0 +1,137 @@
<?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;
use Webman\Exception\BusinessException;
class WarehouseOrderEntry
{
public $warehouse='海吉星仓库';
public $company='供投里海';
public $address='泸州龙马潭区海吉星122栋';
public $phone='08302669767';
public $tel='17309099881';
public function export($data,$order)
{
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
// 合并单元格A1到K1
$sheet->mergeCells('A1:J1');//标题
$sheet->mergeCells('B2:E2');//开单日期
$sheet->mergeCells('G2:J2');//单号
$sheet->mergeCells('B3:C3');
$sheet->mergeCells('D3:E3');
$sheet->setCellValue('A1', $this->company.'公司入库单');
$sheet->setCellValue('A2', '入库时间');
$sheet->setCellValue('B2', $order['create_time']??'');
$sheet->setCellValue('F2', '单号');
$sheet->setCellValue('G2', $order['code']??'');
$sheet->setCellValue('A3', '序号');
$sheet->setCellValue('B3', '商品名称');
$sheet->setCellValue('D3', '供应商');
$sheet->setCellValue('F3', '单位');
$sheet->setCellValue('G3', '单价');
$sheet->setCellValue('H3', '数量');
$sheet->setCellValue('I3', '总价');
$sheet->setCellValue('J3', '支付方式');
// 设置默认的单元格样式
$defaultStyle = [
'alignment' => [
'horizontal' => Alignment::HORIZONTAL_CENTER,
'vertical' => Alignment::VERTICAL_CENTER,
],
];
// 应用默认样式到整个工作表
$spreadsheet->getDefaultStyle()->applyFromArray($defaultStyle);
foreach ($data as $k => $v) {
$sheet->setCellValue('A' . ($k + 4), $v['product_id'] );
$sheet->setCellValue('B' . ($k + 4), $v['store_name']);
$sheet->mergeCells('B' . ($k + 4) . ':C' . $k + 4);
$sheet->setCellValue('D' . ($k + 4), $v['supplier_name']);
$sheet->mergeCells('D' . ($k + 4) . ':E' . $k + 4);
$sheet->setCellValue('F' . ($k + 4), $v['unit_name']);
$sheet->setCellValue('G' . ($k + 4), $v['purchase']);
$sheet->setCellValue('H' . ($k + 4), $v['nums']);
$sheet->setCellValue('I' . ($k + 4), $v['total_price']);
$sheet->setCellValue('J' . ($k + 4), $v['pay_type_name']??'');
}
$count = count($data);
$sheet->mergeCells('A' . ($count + 4) . ':J' . $count + 4);
$sheet->mergeCells('B' . ($count + 5) . ':E' . $count + 5);
$sheet->setCellValue('A' . $count + 5, '赊账金额');
$sheet->setCellValue('B' . $count + 5,$order['credit_pay']);
$sheet->mergeCells('G' . ($count + 5) . ':J' . $count + 5);
$sheet->setCellValue('F' . $count + 5, '现金金额');
$sheet->setCellValue('G' . $count + 5, $order['cash_pay']);
$sheet->mergeCells('B' . ($count + 6) . ':E' . $count + 6);
$sheet->setCellValue('A' . $count + 6, '合计数量');
$sheet->setCellValue('B' . $count + 6,$order['total_num']);
$sheet->mergeCells('G' . ($count + 6) . ':J' . $count + 6);
$sheet->setCellValue('F' . $count + 6, '合计价格');
$sheet->setCellValue('G' . $count + 6, $order['total_price']);
// $sheet->mergeCells('C' . ($count + 7) . ':F' . $count + 7);
// $sheet->mergeCells('C' . ($count + 8) . ':F' . $count + 8);
// $sheet->mergeCells('H' . ($count + 7) . ':J' . ($count + 7));
// $sheet->mergeCells('H' . ($count + 8) . ':J' . $count + 8);
$sheet->mergeCells('A' . ($count + 7) . ':J' . $count + 7);
$sheet->setCellValue('A' . $count + 8, '录入人',);
// $sheet->setCellValue('B' . $count + 11, $this->warehouse);
$sheet->mergeCells('B' . ($count + 8) . ':C' . $count + 8);
$sheet->setCellValue('D' . $count + 8, '采购人');
$sheet->mergeCells('E' . ($count + 8) . ':F' . $count + 8);
$sheet->setCellValue('G' . $count + 8, '审核人');
$sheet->mergeCells('H' . ($count + 8) . ':J' . $count + 8);
// 设置单元格的样式
$styleArray = [
'font' => [
'bold' => true,
'size' => 16,
],
];
$sheet->getStyle('A1')->applyFromArray($styleArray);
// 定义线框样式
$styleArray = [
'borders' => [
'allBorders' => [
'borderStyle' => Border::BORDER_THIN, // 线框样式
'color' => ['argb' => '000000'], // 线框颜色
],
],
];
$sheet->getStyle('A1:J' . ($count + 8))->applyFromArray($styleArray);
// 保存文件到 public 下
$writer = new Xlsx($spreadsheet);
$dir=public_path().'/export/'.date('Y-m');
if (!file_exists($dir)) {
// 尝试创建目录
if (!mkdir($dir)) {
throw new BusinessException('创建目录失败:/export/' . date('Y-m'));
}
}
$file_path = $dir . '/' .$this->company.'公司入库单-'.date('Y年m月d日H时i分') . '.xlsx';
$url = '/export/' . date('Y-m') . '/' .$this->company.'公司入库单-'.date('Y年m月d日H时i分') . '.xlsx';
// 保存文件到 public 下
$writer->save($file_path);
return getenv('APP_URL').$url;
}
}

View File

@ -3,6 +3,15 @@
namespace app\psi\controller;
use app\admin\controller\BaseAdminController;
use app\common\model\OutboundOrder;
use app\common\model\OutboundProduct;
use app\common\model\store_product\StoreProduct;
use app\common\model\store_product_unit\StoreProductUnit;
use app\common\model\system_store\SystemStore;
use app\common\model\WarehouseOrder;
use app\common\model\WarehouseProduct;
use app\common\service\xlsx\Beforehand;
use app\common\service\xlsx\OrderDetail;
use app\psi\lists\OutboundOrderLists;
use app\psi\logic\OutboundOrderLogic;
use app\psi\validate\OutboundOrderValidate;
@ -80,4 +89,90 @@ class OutboundOrderController extends BaseAdminController
return $this->data($result);
}
/**
* 出库表格
*/
public function export()
{
$id = $this->request->post('id');
$type = $this->request->post('type');
if (in_array($type, [2, 3])) {
return $this->fail('暂不支持此操作');
}
$xlsx = new OrderDetail();
$order = OutboundOrder::where('id', $id)->findOrEmpty();
$system_store = SystemStore::where('id', $order['store_id'])->value('name');
$data = OutboundProduct::where('oid', $id)->select();
$order['total_num'] = 0;
$total_price = 0;
foreach ($data as $value) {
if (in_array($order['store_id'], [17, 18])) {
$find = StoreBranchProduct::where('product_id', $value->product_id)->where('store_id', $order['store_id'])->withTrashed()->find();
} else {
$find = StoreProduct::where('id', $value->product_id)->withTrashed()->find();
}
$value->store_name = $find['store_name'] ?? '';
$value->store_info = $find['store_info'] ?? '';
if ($type == 1) {
$value->price = $value['purchase'];
$value->total_price = bcmul($value['purchase'], $value['nums'], 2);
$total_price += $value->total_price;
}
$value->cart_num = $value['nums'];
if (!empty($find['unit'])) {
$value->unit_name = StoreProductUnit::where('id', $find['unit'])->value('name');
} else {
$value->unit_name = '';
}
$order['total_num'] += $value->nums;
}
if ($type == 2) {
$order['total_price'] = $total_price;
}
$order['delivery_time'] = date('Y-m-d H:i:s', $order['delivery_time']);
$order['pay_time'] = $order['create_time'];
$order['order_id'] = $order['code'];
if ($order['oid'] > 0) {
$orders = StoreOrder::where('id', $order['oid'])->findOrEmpty();
$order['real_name'] = $orders['real_name'];
$order['user_phone'] = $orders['user_phone'];
$order['user_address'] = $orders['user_address'];
}
$file_path = $xlsx->export($data, $system_store, $order);
return $this->success('导出成功', ['url' => $file_path]);
}
/**
* 导出标签
*/
public function export_tags()
{
$id = $this->request->post('id');
$warehouseOrder = OutboundOrder::where('id', $id)->field('oid,store_id')->find();
$system_store = SystemStore::where('id', $warehouseOrder['store_id'])->value('introduction');
$data = OutboundProduct::where('oid', $id)->field('oid,product_id,nums')->select()
->each(function ($item) use ($system_store, $warehouseOrder) {
$find = StoreProduct::where('id', $item['product_id'])->field('store_name,unit')->withTrashed()->find();
$unit_name = StoreProductUnit::where('id', $find['unit'])->value('name');
$item['system_store'] = $system_store;
$item['subtitle'] = $item['oid'] . ' ' . convertStringToNumber($item['nums']) . '/' . $unit_name;
$item['store_name'] = $find['store_name'];
if ($warehouseOrder['oid']) {
$find = StoreOrder::where('id', $warehouseOrder['oid'])->field('real_name,user_address')->find();
if ($find) {
$item['address'] = $find['real_name'] . ' ' . $find['user_address'];
} else {
$item['address'] = '无地址';
}
} else {
$item['address'] = '无地址';
}
})
->toArray();
$file_path = (new Beforehand())->export($data, $system_store);
return $this->success('导出成功', ['url' => $file_path]);
}
}

View File

@ -3,12 +3,18 @@
namespace app\psi\controller;
use app\admin\controller\BaseAdminController;
use app\common\model\store_product\StoreProduct;
use app\common\model\store_product_unit\StoreProductUnit;
use app\common\model\supplier\Supplier;
use app\common\model\system_store\SystemStore;
use app\common\model\WarehouseOrder;
use app\common\model\WarehouseProduct;
use app\common\service\xlsx\OrderDetail;
use app\common\service\xlsx\WarehouseOrderEntry;
use app\psi\lists\WarehouseOrderLists;
use app\psi\logic\WarehouseOrderLogic;
use app\psi\validate\WarehouseOrderValidate;
/**
* PsiWarehouseOrder控制器
* Class WarehouseOrderController
@ -17,7 +23,6 @@ use app\psi\validate\WarehouseOrderValidate;
class WarehouseOrderController extends BaseAdminController
{
/**
* @notes 获取列表
* @author admin
@ -96,5 +101,43 @@ class WarehouseOrderController extends BaseAdminController
return $this->data($result);
}
/**
* 入库表格
*/
public function export()
{
$id = $this->request->post('id');
$xlsx = new WarehouseOrderEntry();
$order = WarehouseOrder::where('id', $id)->findOrEmpty();
$data = WarehouseProduct::where('oid', $id)->select();
$order['total_num'] = 0;
$credit_pay = 0;
$cash_pay = 0;
foreach ($data as $value) {
$find = StoreProduct::where('id', $value->product_id)->withTrashed()->find();
$value->store_name = $find['store_name'] ?? '';
$value->store_info = $find['store_info'] ?? '';
if (!empty($find['unit'])) {
$value->unit_name = StoreProductUnit::where('id', $find['unit'])->value('name');
} else {
$value->unit_name = '';
}
$order['total_num'] += $value->nums;
$value->supplier_name = Supplier::where('id', $value->supplier_id)->value('name');
if ($value->pay_type == 1) {
$credit_pay += $value->total_price;
$value->pay_type_name = '赊账';
} elseif ($value->pay_type == 2) {
$cash_pay += $value->total_price;
$value->pay_type_name = '现款';
} else {
$value->pay_type_name = '未设置';
}
}
$order['credit_pay'] = $credit_pay;
$order['cash_pay'] = $cash_pay;
$file_path = $xlsx->export($data, $order);
return $this->success('导出成功', ['url' => $file_path]);
}
}

View File

@ -18,7 +18,7 @@ use app\common\model\warehouse_order\WarehouseOrder;
use app\common\model\warehouse_product\WarehouseProduct;
use app\common\service\xlsx\Beforehand;
use app\common\service\xlsx\OrderDetail;
use app\common\service\xlsx\WarehouseOrdeRentry;
use app\common\service\xlsx\WarehouseOrderEntry;
use app\psi\lists\purchase_order\PurchaseOrderLists;
use support\exception\BusinessException;
use support\Log;
@ -127,7 +127,7 @@ class PurchaseOrderController extends BaseAdminController
public function rentry_export()
{
$id = $this->request->post('id');
$xlsx = new WarehouseOrdeRentry();
$xlsx = new WarehouseOrderEntry();
$order = WarehouseOrder::where('id', $id)->findOrEmpty();
$data = WarehouseProduct::where('oid', $id)->select();
$order['total_num'] = 0;