From f43f1b08867cb2143a9cf2d253920aacbcaf40d9 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 28 Nov 2024 14:26:30 +0800 Subject: [PATCH] =?UTF-8?q?feat(admin):=20=E5=A2=9E=E5=8A=A0=E4=BE=9B?= =?UTF-8?q?=E8=B4=A7=E5=87=BA=E5=BA=93=E5=AF=BC=E5=87=BA=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 OrderOutbound2 方法用于导出供货出库单 - 修改 order_outbound 方法,支持两种出库单类型的导出 - 更新 OrderOutbound 类,增加对供货出库单的支持 --- .../BeforehandOrderController.php | 6 +++- .../beforehand_order/BeforehandOrderLogic.php | 32 +++++++++++++++++++ app/common/service/xlsx/OrderOutbound.php | 13 ++++++-- 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/app/admin/controller/beforehand_order/BeforehandOrderController.php b/app/admin/controller/beforehand_order/BeforehandOrderController.php index 70822a82..9799a50d 100644 --- a/app/admin/controller/beforehand_order/BeforehandOrderController.php +++ b/app/admin/controller/beforehand_order/BeforehandOrderController.php @@ -239,7 +239,11 @@ class BeforehandOrderController extends BaseAdminController public function order_outbound() { $params = $this->request->post(); - $file_path = BeforehandOrderLogic::OrderOutbound($params); + if(!empty($params['type']) && $params['type'] == 2){ + $file_path = BeforehandOrderLogic::OrderOutbound2($params); + }else{ + $file_path = BeforehandOrderLogic::OrderOutbound($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 1a2c0304..3755bfd5 100644 --- a/app/admin/logic/beforehand_order/BeforehandOrderLogic.php +++ b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php @@ -680,4 +680,36 @@ class BeforehandOrderLogic extends BaseLogic $file_path = $order_info->export($data, $order, $other_data); return $file_path; } + + /** + * 导出供货出库 + */ + public static function OrderOutbound2($params) + { + $order_info = new OrderOutbound(); + $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(); + + $total_price=0; + foreach ($data as $k => &$v) { + $find = StoreProduct::where('id', $v['product_id'])->field('top_cate_id,store_name,unit')->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); + } + $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'] = $total_price; + $file_path = $order_info->export($data, $order, $other_data,2); + return $file_path; + } } diff --git a/app/common/service/xlsx/OrderOutbound.php b/app/common/service/xlsx/OrderOutbound.php index 3d2487be..52cf93c8 100644 --- a/app/common/service/xlsx/OrderOutbound.php +++ b/app/common/service/xlsx/OrderOutbound.php @@ -12,8 +12,15 @@ use PhpOffice\PhpSpreadsheet\Style\Border; */ class OrderOutbound { - public function export($data,$order,$other_data) + 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 @@ -25,7 +32,7 @@ class OrderOutbound $sheet->mergeCells('H3:I3'); - $sheet->setCellValue('A1', '供 投 里 海 农 特 产 品 出 库 结 算 单'); + $sheet->setCellValue('A1', $title); $sheet->setCellValue('A2', '姓名:'); $sheet->setCellValue('B2', $other_data->nickname??''); $sheet->getColumnDimension('B')->setWidth(16); @@ -134,7 +141,7 @@ class OrderOutbound // 保存文件到 public 下 $writer = new Xlsx($spreadsheet); - $url = '/export/' . date('Y-m') . '/' .'供投里海农特产品出库结算单-'.date('Y-m-d H:i') . '.xlsx'; + $url = '/export/' . date('Y-m') . '/' .$title2.date('Y-m-d H:i') . '.xlsx'; $file_path = public_path() . $url; // 保存文件到 public 下 $writer->save($file_path);