From 067f4183b8e4879d0fd94cad2bb573f275cd5acf Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Tue, 8 Oct 2024 17:06:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=A2=84=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=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 - 实现了预订单的导出功能,支持将预订单信息导出为标签 - 新增导出方法,处理导出逻辑,包括查询预订单信息、构建导出数据和调用导出服务 - 引入了相关模型和服务类,以支持导出功能的实现 --- .../BeforehandOrderController.php | 46 ++++++++++++++++--- app/common/service/xlsx/Beforehand.php | 41 +++++++++++++++++ 2 files changed, 80 insertions(+), 7 deletions(-) create mode 100644 app/common/service/xlsx/Beforehand.php diff --git a/app/admin/controller/beforehand_order/BeforehandOrderController.php b/app/admin/controller/beforehand_order/BeforehandOrderController.php index 0d4df0b6..099160da 100644 --- a/app/admin/controller/beforehand_order/BeforehandOrderController.php +++ b/app/admin/controller/beforehand_order/BeforehandOrderController.php @@ -8,7 +8,13 @@ use app\admin\lists\beforehand_order\BeforehandOrderLists; use app\admin\lists\beforehand_order\BeforehandOrderTwoLists; use app\admin\lists\beforehand_order\BeforehandOrderThreeLists; use app\admin\logic\beforehand_order\BeforehandOrderLogic; - +use app\common\model\beforehand_order\BeforehandOrder; +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\warehouse_order\WarehouseOrder; +use app\common\model\warehouse_product\WarehouseProduct; +use app\common\service\xlsx\Beforehand; /** * 预订单表控制器 @@ -57,10 +63,10 @@ class BeforehandOrderController extends BaseAdminController */ public function createOutboundOrder() { - $params=$this->request->post(); + $params = $this->request->post(); $params['admin_id'] = $this->adminId; $result = BeforehandOrderLogic::createOutboundOrder($params); - + return $this->success('出库成功', [], 1, 1); } @@ -68,10 +74,11 @@ class BeforehandOrderController extends BaseAdminController * @notes 订单转预定单 * @return \think\response\Json */ - public function orderTransferAdvanceOrder(){ - $params=$this->request->post(); - $params['admin_id']=$this->adminId; - $params['mark']='订单转预定单'; + public function orderTransferAdvanceOrder() + { + $params = $this->request->post(); + $params['admin_id'] = $this->adminId; + $params['mark'] = '订单转预定单'; $result = BeforehandOrderLogic::orderTransferAdvanceOrder($params); return $this->success('转单成功', [], 1, 1); } @@ -119,4 +126,29 @@ class BeforehandOrderController extends BaseAdminController $result = BeforehandOrderLogic::detail($params); return $this->data($result); } + + /** + * 导出标签 + */ + public function export() + { + $params = $this->request->post(); + $outbound_id = BeforehandOrder::where('id', $params['id'])->value('outbound_id'); + if(!$outbound_id){ + return $this->fail('未生成出库单'); + } + $warehouseOrder = WarehouseOrder::where('id', $outbound_id)->field('store_id,delivery_time')->find(); + $system_store = SystemStore::where('id', $warehouseOrder['store_id'])->value('name'); + $data = WarehouseProduct::where('oid', $outbound_id)->field('product_id,nums')->select() + ->each(function ($item) use ($system_store,$warehouseOrder) { + $item['system_store'] = $system_store; + $find = StoreProduct::where('id', $item['product_id'])->field('store_name,unit')->find(); + $item['store_name'] = $find['store_name']; + $unit_name = StoreProductUnit::where('id', $find['unit'])->value('name'); + $item['unit_name'] = $item['nums'].'/'.$unit_name.' '.date('m-d',$warehouseOrder['delivery_time']); + }) + ->toArray(); + $file_path=(new Beforehand())->export($data, $system_store); + return $this->success('导出成功', ['url' => $file_path]); + } } diff --git a/app/common/service/xlsx/Beforehand.php b/app/common/service/xlsx/Beforehand.php new file mode 100644 index 00000000..9d816e6f --- /dev/null +++ b/app/common/service/xlsx/Beforehand.php @@ -0,0 +1,41 @@ +getActiveSheet(); + + // 合并单元格A1到K1 + $sheet->mergeCells('A1:B1'); + $kk1=1; + $kk2=2; + $kk3=3; + $styleArray = [ + 'font' => [ + 'bold' => true, + 'size' => 16, + ], + ]; + foreach ($data as $k => $v) { + $sheet->setCellValue('A' . ($k + $kk1), $v['system_store'])->getStyle('A'. ($k + $kk1))->applyFromArray($styleArray); + $sheet->setCellValue('A' . ($k + $kk2), $v['store_name'])->getStyle('A'. ($k + $kk2))->applyFromArray($styleArray); + $sheet->setCellValue('A' . ($k + $kk3), $v['unit_name'])->getStyle('A'. ($k + $kk3))->applyFromArray($styleArray); + $kk1=$kk1+2; + $kk2=$kk2+2; + $kk3=$kk3+2; + } + $writer = new Xlsx($spreadsheet); + $url = '/export/' . date('Y-m') . '/' . $system_store.'标签单-'.date('Y-m-d H:i') . '.xlsx'; + $file_path = public_path() . $url; + // 保存文件到 public 下 + $writer->save($file_path); + return getenv('APP_URL').$url; + } +}