From aa2d91441be84031258f5ac7098eb31477c0f563 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Fri, 15 Nov 2024 15:24:46 +0800 Subject: [PATCH] =?UTF-8?q?feat(admin):=20=E6=B7=BB=E5=8A=A0=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E9=80=80=E5=BA=93=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 BeforehandOrderController 中添加 stock_return 方法处理导出退库请求 - 在 BeforehandOrderLogic 中实现 StockReturn 方法导出退库单 - 新增 ReturnSupplier 方法处理供应商退库导出 - 优化采购信息设置逻辑,暂时移除权限验证 - 修复仓库产品退货逻辑,增加库存数量校验 --- .../BeforehandOrderController.php | 9 ++ .../beforehand_order/BeforehandOrderLogic.php | 54 +++++++ .../PurchaseProductOfferLogic.php | 12 +- .../WarehouseProductReturnLogic.php | 11 +- app/common/service/xlsx/ReturnSupplier.php | 120 ++++++++++++++++ app/common/service/xlsx/StockReturn.php | 136 ++++++++++++++++++ 6 files changed, 334 insertions(+), 8 deletions(-) create mode 100644 app/common/service/xlsx/ReturnSupplier.php create mode 100644 app/common/service/xlsx/StockReturn.php diff --git a/app/admin/controller/beforehand_order/BeforehandOrderController.php b/app/admin/controller/beforehand_order/BeforehandOrderController.php index f4834238..bca801f3 100644 --- a/app/admin/controller/beforehand_order/BeforehandOrderController.php +++ b/app/admin/controller/beforehand_order/BeforehandOrderController.php @@ -242,4 +242,13 @@ class BeforehandOrderController extends BaseAdminController $file_path = BeforehandOrderLogic::OrderOutbound($params); return $this->success('导出成功', ['url' => $file_path]); } + /** + * 导出退库 + */ + public function stock_return() + { + $params = $this->request->post(); + $file_path = BeforehandOrderLogic::StockReturn($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 122531f7..6a938b45 100644 --- a/app/admin/logic/beforehand_order/BeforehandOrderLogic.php +++ b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php @@ -23,10 +23,12 @@ use app\common\model\user\User; use app\common\model\user\UserAddress; use app\common\model\warehouse_order\WarehouseOrder; use app\common\model\warehouse_product\WarehouseProduct; +use app\common\model\warehouse_product_return\WarehouseProductReturn; 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\StockReturn; use DateTime; use support\exception\BusinessException; use think\facade\Db; @@ -628,6 +630,58 @@ class BeforehandOrderLogic extends BaseLogic $order['system_store_name'] = SystemStore::where('id', $order['store_id'])->value('name'); $other_data = $order['other_data']; unset($order['other_data']); + $code=WarehouseOrder::where('id', $order['outbound_id'])->value('code'); + $order['order_id']=$code??$order['order_id']; + $file_path = $order_info->export($data, $order, $other_data); + return $file_path; + } + + /** + * 导出退库 + */ + public static function StockReturn($params) + { + $order_info = new StockReturn(); + $order = BeforehandOrder::where('id', $params['id'])->find(); + + $data= WarehouseProductReturn::where('bhoid',$order['id'])->select()->each(function ($item) { + $find = StoreProduct::where('id', $item['product_id'])->field('top_cate_id,store_name,unit')->find(); + $item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name'); + $item['store_name'] = $find['store_name']; + return $item; + }); + if(empty($data)){ + throw new BusinessException('退库商品为空,不能导出退库单'); + } + $order['system_store_name'] = SystemStore::where('id', $order['store_id'])->value('name'); + $order['total_price'] =WarehouseProductReturn::where('bhoid',$order['id'])->sum('total_price'); + $other_data = $order['other_data']; + unset($order['other_data']); + $file_path = $order_info->export($data, $order, $other_data); + return $file_path; + } + + /** + * 导出退库 + */ + public static function return_supplier($params) + { + $order_info = new ReturnSupplier(); + $order = BeforehandOrder::where('id', $params['id'])->find(); + + $data= WarehouseProductReturn::where('bhoid',$order['id'])->select()->each(function ($item) { + $find = StoreProduct::where('id', $item['product_id'])->field('top_cate_id,store_name,unit')->find(); + $item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name'); + $item['store_name'] = $find['store_name']; + return $item; + }); + if(empty($data)){ + throw new BusinessException('退库商品为空,不能导出退库单'); + } + $order['system_store_name'] = SystemStore::where('id', $order['store_id'])->value('name'); + $order['total_price'] =WarehouseProductReturn::where('bhoid',$order['id'])->sum('total_price'); + $other_data = $order['other_data']; + unset($order['other_data']); $file_path = $order_info->export($data, $order, $other_data); return $file_path; } diff --git a/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php b/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php index df4a11ef..398e1649 100644 --- a/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php +++ b/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php @@ -114,12 +114,12 @@ class PurchaseProductOfferLogic extends BaseLogic public static function setProcureInfo(array $params): bool { $offer = PurchaseProductOffer::where(['id' => $params['id']])->find(); - $uid=Admin::where('id',$params['admin_id'])->value('uid'); - if($params['admin_id']!=1){ - if($offer['buyer_id']!=$uid){ - throw new BusinessException('您不是当事采购员,无法设置采购信息'); - } - } + // $uid=Admin::where('id',$params['admin_id'])->value('uid'); + // if($params['admin_id']!=1){ + // if($offer['buyer_id']!=$uid){ + // throw new BusinessException('您不是当事采购员,无法设置采购信息'); + // } + // } Db::startTrans(); try { $offer->save([ diff --git a/app/admin/logic/warehouse_product_return/WarehouseProductReturnLogic.php b/app/admin/logic/warehouse_product_return/WarehouseProductReturnLogic.php index e16e5e76..de2f3fbb 100644 --- a/app/admin/logic/warehouse_product_return/WarehouseProductReturnLogic.php +++ b/app/admin/logic/warehouse_product_return/WarehouseProductReturnLogic.php @@ -6,6 +6,7 @@ namespace app\admin\logic\warehouse_product_return; use app\common\model\warehouse_product_return\WarehouseProductReturn; use app\common\logic\BaseLogic; use app\common\model\beforehand_order\BeforehandOrder; +use app\common\model\warehouse_order\WarehouseOrder; use app\common\model\warehouse_product\WarehouseProduct; use app\common\model\warehouse_product_storege\WarehouseProductStorege; use support\exception\BusinessException; @@ -30,14 +31,19 @@ class WarehouseProductReturnLogic extends BaseLogic */ public static function add(array $params): bool { + if(empty($params['bhoid'])||$params['bhoid']==0){ + throw new BusinessException('订单id不能为空'); + } Db::startTrans(); try { $find=WarehouseProduct::where('id',$params['id'])->find(); if($find){ - $id=BeforehandOrder::where('id',$find['oid'])->value('id'); + if($find['nums']<$params['nums']){ + throw new BusinessException('退货数量不能大于库存数量'); + } WarehouseProductReturn::create([ 'source_id'=>$params['id'], - 'bhoid'=>$id??0, + 'bhoid'=>$params['bhoid']??0, 'warehouse_id'=>$find['warehouse_id'], 'supplier_id'=>$find['supplier_id'], 'store_id'=>$find['store_id'], @@ -52,6 +58,7 @@ class WarehouseProductReturnLogic extends BaseLogic 'total_price'=>bcmul($params['nums'],$find['price'],2), ]); if($params['financial_pm']==1 &&$params['return_type']==1){ + $find->dec('nums',$params['nums'])->update(); WarehouseProductStorege::where(['product_id'=>$find['product_id'],'warehouse_id'=>$find['warehouse_id']])->inc('nums',$params['nums'])->update(); }elseif($params['financial_pm']==0 &&$params['return_type']==2){ WarehouseProductStorege::where(['product_id'=>$find['product_id'],'warehouse_id'=>$find['warehouse_id']])->dec('nums',$params['nums'])->update(); diff --git a/app/common/service/xlsx/ReturnSupplier.php b/app/common/service/xlsx/ReturnSupplier.php new file mode 100644 index 00000000..cfd73475 --- /dev/null +++ b/app/common/service/xlsx/ReturnSupplier.php @@ -0,0 +1,120 @@ +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, '泸州市海吉星农产品商贸物流园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') . '/' .'供投里海农特产品退库结算单-'.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/StockReturn.php b/app/common/service/xlsx/StockReturn.php new file mode 100644 index 00000000..178b63c3 --- /dev/null +++ b/app/common/service/xlsx/StockReturn.php @@ -0,0 +1,136 @@ +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); + $url = '/export/' . date('Y-m') . '/' .'供投里海农特产品退库结算单-'.date('Y-m-d H:i') . '.xlsx'; + $file_path = public_path() . $url; + // 保存文件到 public 下 + $writer->save($file_path); + return getenv('APP_URL').$url; + } +}