diff --git a/app/admin/controller/beforehand_order/BeforehandOrderController.php b/app/admin/controller/beforehand_order/BeforehandOrderController.php index 9799a50d..9416f84a 100644 --- a/app/admin/controller/beforehand_order/BeforehandOrderController.php +++ b/app/admin/controller/beforehand_order/BeforehandOrderController.php @@ -239,13 +239,22 @@ class BeforehandOrderController extends BaseAdminController public function order_outbound() { $params = $this->request->post(); - if(!empty($params['type']) && $params['type'] == 2){ + if (!empty($params['type']) && $params['type'] == 2) { $file_path = BeforehandOrderLogic::OrderOutbound2($params); - }else{ + } else { $file_path = BeforehandOrderLogic::OrderOutbound($params); } return $this->success('导出成功', ['url' => $file_path]); } + /** + * 导出财务出库 + */ + public function order_outbound_finance() + { + $params = $this->request->post(); + $file_path = BeforehandOrderLogic::OrderOutboundFinance($params); + return $this->success('导出成功', ['url' => $file_path]); + } /** * 导出退库 */ diff --git a/app/admin/logic/beforehand_order/BeforehandOrderLogic.php b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php index a83d437d..66221909 100644 --- a/app/admin/logic/beforehand_order/BeforehandOrderLogic.php +++ b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php @@ -28,6 +28,7 @@ use app\common\service\xlsx\OrderAllocation; use app\common\service\xlsx\OrderInfo; use app\common\service\xlsx\OrderList; use app\common\service\xlsx\OrderOutbound; +use app\common\service\xlsx\OrderSupplyOutbound; use app\common\service\xlsx\ReturnSupplier; use app\common\service\xlsx\StockReturn; use DateTime; @@ -58,10 +59,10 @@ class BeforehandOrderLogic extends BaseLogic if ($order_type == 4) { throw new BusinessException('不能添加线上订单,线上订单只能转换'); } - if($order_type==7 ||$order_type==5){ - $is_buyer=1; - }else{ - $is_buyer=-1; + if ($order_type == 7 || $order_type == 5) { + $is_buyer = 1; + } else { + $is_buyer = -1; } Db::startTrans(); try { @@ -178,7 +179,7 @@ class BeforehandOrderLogic extends BaseLogic $pay_price = 0; $cost_price = 0; foreach ($cart_info as $k => $v) { - $total_prices=$v['total_price']; + $total_prices = $v['total_price']; $v['uid'] = $params['user_id']; $v['store_id'] = $params['store_id']; $find = StoreBranchProduct::where('store_id', $params['store_id'])->where('product_id', $v['product_id'])->find(); @@ -189,12 +190,12 @@ class BeforehandOrderLogic extends BaseLogic $cart_select[$k]['price'] = $v['price']; //判断如果采购价小于售价,则采购价等于售价 - if ($v['price']<$find['purchase'] && $find['purchase']!=0) { + if ($v['price'] < $find['purchase'] && $find['purchase'] != 0) { $cart_select[$k]['price'] = $find['purchase']; - } - if ($user['user_ship'] == 4 && $find['cost']!=0) { + } + if ($user['user_ship'] == 4 && $find['cost'] != 0) { $cart_select[$k]['price'] = $find['cost']; - $total_prices=bcmul($find['cost'], $v['cart_num'], 2); + $total_prices = bcmul($find['cost'], $v['cart_num'], 2); } $cart_select[$k]['cost'] = $find['cost']; $cart_select[$k]['purchase'] = $find['purchase']; @@ -636,7 +637,32 @@ class BeforehandOrderLogic extends BaseLogic $file_path = $order_info->export($data, $order, $other_data); return $file_path; } - + /** + * 导出出库 + */ + // public static function OrderOutboundFinance($params) + // { + // $order_info = new OrderOutboundFinance(); + // $order = BeforehandOrder::where('id', $params['id'])->find(); + // if ($order['outbound_id'] <= 0) { + // throw new BusinessException('订单未出库,不能导出出库单'); + // } + // $order['admin_name'] = Admin::where('id', $order['admin_id'])->value('name'); + // $data = WarehouseProduct::where('oid', $order['outbound_id'])->where('nums', '>', 0)->select()->each(function ($item) { + // $find = StoreProduct::where('id', $item['product_id'])->field('top_cate_id,store_name,unit')->withTrashed()->find(); + // $item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name'); + // $item['store_name'] = $find['store_name']; + // return $item; + // }); + // $order['system_store_name'] = SystemStore::where('id', $order['store_id'])->value('name'); + // $other_data = $order['other_data']; + // unset($order['other_data']); + // $find = WarehouseOrder::where('id', $order['outbound_id'])->find(); + // $order['order_id'] = $find['code']; + // $order['pay_price'] = $find['total_price']; + // $file_path = $order_info->export($data, $order, $other_data); + // return $file_path; + // } /** * 导出退库 */ @@ -687,12 +713,12 @@ class BeforehandOrderLogic extends BaseLogic return $file_path; } - /** + /** * 导出供货出库 */ public static function OrderOutbound2($params) { - $order_info = new OrderOutbound(); + $order_info = new OrderSupplyOutbound(); $order = BeforehandOrder::where('id', $params['id'])->find(); if ($order['outbound_id'] <= 0) { throw new BusinessException('订单未出库,不能导出出库单'); @@ -700,14 +726,17 @@ class BeforehandOrderLogic extends BaseLogic $order['admin_name'] = Admin::where('id', $order['admin_id'])->value('name'); $data = WarehouseProduct::where('oid', $order['outbound_id'])->where('nums', '>', 0)->select(); - $total_price=0; + $total_price = 0; + $total_profit = 0; foreach ($data as $k => &$v) { - $find = StoreProduct::where('id', $v['product_id'])->field('top_cate_id,store_name,unit')->withTrashed()->find(); + $find = StoreProduct::where('id', $v['product_id'])->field('top_cate_id,store_name,unit,after_sales')->withTrashed()->find(); $v['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name'); $v['store_name'] = $find['store_name']; - $v['total_price']=bcmul($v['purchase'],$v['nums'],2); - $v['price']=$v['purchase']; - $total_price=bcadd($total_price,$v['total_price'],2); + $v['mark'] = $find['after_sales']; + $v['total_price'] = bcmul($v['purchase'], $v['nums'], 2); + $v['profit']= bcsub($v['price'], $v['purchase'], 2); + // $total_profit = bcadd($total_profit, $v['profit'], 2); + $total_price = bcadd($total_price, $v['total_price'], 2); } $order['system_store_name'] = SystemStore::where('id', $order['store_id'])->value('name'); $other_data = $order['other_data']; @@ -715,7 +744,8 @@ class BeforehandOrderLogic extends BaseLogic $find = WarehouseOrder::where('id', $order['outbound_id'])->find(); $order['order_id'] = $find['code']; $order['pay_price'] = $total_price; - $file_path = $order_info->export($data, $order, $other_data,2); + // $order['total_profit'] = $total_profit; + $file_path = $order_info->export($data, $order, $other_data, 2); return $file_path; } } diff --git a/app/common/service/xlsx/OrderOutboundFinance.php b/app/common/service/xlsx/OrderOutboundFinance.php new file mode 100644 index 00000000..862c44ab --- /dev/null +++ b/app/common/service/xlsx/OrderOutboundFinance.php @@ -0,0 +1,152 @@ +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); + $url = '/export/' . date('Y-m') . '/' .$title2.date('Y-m-d H:i') . '.xlsx'; + $file_path = public_path() . $url; + // 保存文件到 public 下 + $writer->save($file_path); + return getenv('APP_URL').$url; + } +} diff --git a/app/common/service/xlsx/OrderSupplyOutbound.php b/app/common/service/xlsx/OrderSupplyOutbound.php new file mode 100644 index 00000000..1e1bf532 --- /dev/null +++ b/app/common/service/xlsx/OrderSupplyOutbound.php @@ -0,0 +1,150 @@ +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['nums']); + $sheet->setCellValue('E' . ($k + 4), $v['purchase']); + $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); + $url = '/export/' . date('Y-m') . '/' .$title2.date('Y-m-d H:i') . '.xlsx'; + $file_path = public_path() . $url; + // 保存文件到 public 下 + $writer->save($file_path); + return getenv('APP_URL').$url; + } +}