diff --git a/app/admin/controller/beforehand_order/BeforehandOrderController.php b/app/admin/controller/beforehand_order/BeforehandOrderController.php index b261894e..6fd533e5 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 c4a5ef6a..a83f1c4e 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 e190a791..83835494 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 33b1908c..c9d9798c 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 b5ba9018..693eb9a4 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 9c9e34e5..e21951e6 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; + } }