From f526e60841cd7a79f92caf08f00fa634cc1c5404 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 17 Oct 2024 18:01:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=8A=9F=E8=83=BD=E5=92=8C?= =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=9A=201.=20=E5=9C=A8BeforehandOrderCont?= =?UTF-8?q?roller=E4=B8=AD=E6=B7=BB=E5=8A=A0=E4=BA=86export=5Forder?= =?UTF-8?q?=E6=96=B9=E6=B3=95=EF=BC=8C=E7=94=A8=E4=BA=8E=E5=AF=BC=E5=87=BA?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E4=BF=A1=E6=81=AF=E3=80=82=202.=20=E5=9C=A8P?= =?UTF-8?q?urchaseProductOfferController=E4=B8=AD=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E4=BA=86setStoreroomInfo=E6=96=B9=E6=B3=95=EF=BC=8C=E7=94=A8?= =?UTF-8?q?=E4=BA=8E=E8=AE=BE=E7=BD=AE=E5=BA=93=E6=88=BF=E9=AA=8C=E6=94=B6?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E3=80=82=203.=20=E5=9C=A8BeforehandOrderCart?= =?UTF-8?q?InfoLists=E4=B8=AD=E8=B0=83=E6=95=B4=E4=BA=86=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=EF=BC=8C=E7=A7=BB=E9=99=A4=E4=BA=86=E4=B8=8D?= =?UTF-8?q?=E5=BF=85=E8=A6=81=E7=9A=84=E5=AD=97=E6=AE=B5=E3=80=82=204.=20?= =?UTF-8?q?=E5=9C=A8BeforehandOrderLogic=E4=B8=AD=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E4=BA=86=E8=AE=A2=E5=8D=95=E5=88=9B=E5=BB=BA=E9=80=BB=E8=BE=91?= =?UTF-8?q?=EF=BC=8C=E5=A2=9E=E5=8A=A0=E4=BA=86=E7=94=A8=E6=88=B7=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E5=92=8C=E9=80=81=E8=B4=A7=E6=97=B6=E9=97=B4=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E3=80=82=205.=20=E5=9C=A8Beforehand=E7=B1=BB=E4=B8=AD?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86order=E6=96=B9=E6=B3=95=EF=BC=8C?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=E7=94=9F=E6=88=90=E8=AE=A2=E5=8D=95Excel?= =?UTF-8?q?=E6=96=87=E4=BB=B6=EF=BC=8C=E5=8C=85=E5=90=AB=E4=BA=86=E8=AF=A6?= =?UTF-8?q?=E7=BB=86=E7=9A=84=E8=AE=A2=E5=8D=95=E5=92=8C=E5=95=86=E5=93=81?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E3=80=82=206.=20=E5=9C=A8PurchaseProductOffe?= =?UTF-8?q?rLogic=E4=B8=AD=E5=AE=9E=E7=8E=B0=E4=BA=86=E5=BA=93=E6=88=BF?= =?UTF-8?q?=E9=AA=8C=E6=94=B6=E4=BF=A1=E6=81=AF=E7=9A=84=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BeforehandOrderController.php | 16 ++ .../PurchaseProductOfferController.php | 7 +- .../BeforehandOrderCartInfoLists.php | 2 +- .../beforehand_order/BeforehandOrderLogic.php | 4 + .../PurchaseProductOfferLogic.php | 26 ++++ app/common/service/xlsx/Beforehand.php | 144 +++++++++++++++++- 6 files changed, 196 insertions(+), 3 deletions(-) diff --git a/app/admin/controller/beforehand_order/BeforehandOrderController.php b/app/admin/controller/beforehand_order/BeforehandOrderController.php index b261894ef..6fd533e51 100644 --- a/app/admin/controller/beforehand_order/BeforehandOrderController.php +++ b/app/admin/controller/beforehand_order/BeforehandOrderController.php @@ -9,6 +9,7 @@ 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\beforehand_order_cart_info\BeforehandOrderCartInfo; use app\common\model\store_order\StoreOrder; use app\common\model\store_product\StoreProduct; use app\common\model\store_product_unit\StoreProductUnit; @@ -170,4 +171,19 @@ class BeforehandOrderController extends BaseAdminController $file_path=(new Beforehand())->export($data, $system_store); return $this->success('导出成功', ['url' => $file_path]); } + + + /** + * 导出订单 + */ + public function export_order() + { + $params = $this->request->post(); + $order = BeforehandOrder::where('id', $params['id'])->find(); + + $cart_info=BeforehandOrderCartInfo::where('bhoid',$params['id'])->select(); + + $file_path=(new Beforehand())->order($order, $cart_info); + return $this->success('导出成功', ['url' => $file_path]); + } } diff --git a/app/admin/controller/purchase_product_offer/PurchaseProductOfferController.php b/app/admin/controller/purchase_product_offer/PurchaseProductOfferController.php index c4a5ef6ab..a83f1c4eb 100644 --- a/app/admin/controller/purchase_product_offer/PurchaseProductOfferController.php +++ b/app/admin/controller/purchase_product_offer/PurchaseProductOfferController.php @@ -83,7 +83,12 @@ class PurchaseProductOfferController extends BaseAdminController PurchaseProductOfferLogic::setBatchProcureInfo($params); return $this->success('设置成功', [], 1, 1); } - + public function setStoreroomInfo() + { + $params = $this->request->post(); + PurchaseProductOfferLogic::setStoreroomInfo($params); + return $this->success('设置成功', [], 1, 1); + } /** * @notes 删除采购供应链商品 * @return \think\response\Json diff --git a/app/admin/lists/beforehand_order_cart_info/BeforehandOrderCartInfoLists.php b/app/admin/lists/beforehand_order_cart_info/BeforehandOrderCartInfoLists.php index e190a791f..838354948 100644 --- a/app/admin/lists/beforehand_order_cart_info/BeforehandOrderCartInfoLists.php +++ b/app/admin/lists/beforehand_order_cart_info/BeforehandOrderCartInfoLists.php @@ -57,7 +57,7 @@ class BeforehandOrderCartInfoLists extends BaseAdminDataLists implements ListsSe } } $list = BeforehandOrderCartInfo::where($this->searchWhere) - ->field(['id', 'bhoid', 'uid', 'is_buyer', 'buyer_uid', 'product_id', 'attr_value_id', 'is_pay', 'purchase', 'price', 'total_price', 'cart_num', 'mark']) + ->field(['id', 'bhoid', 'uid', 'is_buyer', 'buyer_uid', 'product_id', 'attr_value_id', 'purchase', 'price', 'total_price', 'cart_num', 'mark']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select()->each(function ($item) { diff --git a/app/admin/logic/beforehand_order/BeforehandOrderLogic.php b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php index 33b1908c7..c9d9798cc 100644 --- a/app/admin/logic/beforehand_order/BeforehandOrderLogic.php +++ b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php @@ -77,7 +77,11 @@ class BeforehandOrderLogic extends BaseLogic 'pay_type' => 0, 'deduction_price' => 0, 'paid' => 0, + 'nikename' => $params['nikename'] ?? '', + 'phone' => $params['phone'] ?? '', + 'address' => $params['address'] ?? '', 'mark' => $params['mark'] ?? '', + 'arrival_time' => strtotime($params['arrival_time']), 'order_type' => $order_type ]); foreach ($datas as $k => $v) { diff --git a/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php b/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php index b5ba90181..693eb9a43 100644 --- a/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php +++ b/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php @@ -161,6 +161,32 @@ class PurchaseProductOfferLogic extends BaseLogic throw new BusinessException($e->getMessage()); } } + + /** + * @notes 库房设置验收信息 + * @param array $params + * @return bool + * @author admin + * @date 2024/08/14 15:06 + */ + public static function setStoreroomInfo(array $params): bool + { + Db::startTrans(); + try { + PurchaseProductOffer::where('id',$params['id'])->update(['is_accept'=>1]); + $data=[ + 'gross_weight'=>$params['gross_weight']??0, + 'net_weight'=>$params['net_weight']??0, + 'accept_num'=>$params['accept_num']??0, + ]; + BeforehandOrderCartInfo::where(['bhoid'=>$params['bhoid'],'product_id'=>$params['product_id']])->update($data); + Db::commit(); + return true; + } catch (\Throwable $e) { + Db::rollback(); + throw new BusinessException($e->getMessage()); + } + } /** * 是否需采购 */ diff --git a/app/common/service/xlsx/Beforehand.php b/app/common/service/xlsx/Beforehand.php index 9c9e34e58..e21951e6f 100644 --- a/app/common/service/xlsx/Beforehand.php +++ b/app/common/service/xlsx/Beforehand.php @@ -4,7 +4,10 @@ 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; class Beforehand { public function export($data, $system_store) @@ -47,4 +50,143 @@ class Beforehand $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); + $url = '/export/' . date('Y-m') . '/' . $order['info'].'出库单-'.date('Y-m-d H:i') . '.xlsx'; + $file_path = public_path() . $url; + // 保存文件到 public 下 + $writer->save($file_path); + return getenv('APP_URL').$url; + } }