From 325dee018187ff742464ffeccd6f1b349105fdf1 Mon Sep 17 00:00:00 2001 From: "DESKTOP-GMUNQ1B\\Administrator" <604446095@qq.com> Date: Sat, 21 Dec 2024 16:59:52 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B4=BB=E5=8A=A8?= =?UTF-8?q?=E4=B8=93=E5=8C=BA=E5=95=86=E5=93=81=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ActivityZoneController.php | 6 + app/admin/logic/ActivityZoneLogic.php | 24 ++++ .../service/xlsx/ActivityZoneService.php | 115 ++++++++++++++++++ 3 files changed, 145 insertions(+) create mode 100644 app/common/service/xlsx/ActivityZoneService.php diff --git a/app/admin/controller/ActivityZoneController.php b/app/admin/controller/ActivityZoneController.php index 75e3464ec..54f92700b 100644 --- a/app/admin/controller/ActivityZoneController.php +++ b/app/admin/controller/ActivityZoneController.php @@ -91,5 +91,11 @@ class ActivityZoneController extends BaseAdminController return $this->data($result); } + public function export() + { + $params = $this->request->get(); + $file_path = ActivityZoneLogic::export($params); + return $this->success('导出成功', ['url' => $file_path]); + } } \ No newline at end of file diff --git a/app/admin/logic/ActivityZoneLogic.php b/app/admin/logic/ActivityZoneLogic.php index 9cc018d58..a5425ee0a 100644 --- a/app/admin/logic/ActivityZoneLogic.php +++ b/app/admin/logic/ActivityZoneLogic.php @@ -5,6 +5,8 @@ namespace app\admin\logic; use app\common\model\ActivityZone; use app\common\logic\BaseLogic; +use app\common\model\store_product_unit\StoreProductUnit; +use app\common\service\xlsx\ActivityZoneService; use support\exception\BusinessException; use think\facade\Db; @@ -99,4 +101,26 @@ class ActivityZoneLogic extends BaseLogic { return ActivityZone::findOrEmpty($params['id'])->toArray(); } + + public static function export($params) + { + $service = new ActivityZoneService(); + $products = ActivityZone::with('product')->field('id,product_id,type')->where('type', $params['type'])->select()->toArray(); + $unitIds = array_unique(array_column($products, 'unit')); + $unit = StoreProductUnit::whereIn('id', $unitIds)->field('id,name')->withTrashed()->select()->toArray(); + $unit = reset_index($unit, 'id'); + foreach ($products as &$item) { + $item['unit_name'] = $unit[$item['unit']]['name'] ?? ''; + unset($item['unit'], $item['product_id']); + } + $data = ConfigLogic::getDictByType('activity_zone'); + foreach ($data['activity_zone'] as $value) { + if ($value['value'] == $params['type']) { + $typeName = $value['remark']; + break; + } + } + return $service->export($products, $typeName ?? '', $params['remark']); + } + } \ No newline at end of file diff --git a/app/common/service/xlsx/ActivityZoneService.php b/app/common/service/xlsx/ActivityZoneService.php new file mode 100644 index 000000000..29bbab23a --- /dev/null +++ b/app/common/service/xlsx/ActivityZoneService.php @@ -0,0 +1,115 @@ +getActiveSheet(); + $sheet->mergeCells('A1:F1'); + $sheet->mergeCells('A2:B2'); + $sheet->mergeCells('C2:D2'); + $sheet->mergeCells('E2:F2'); + $sheet->mergeCells('A3:B3'); + $sheet->mergeCells('C3:D3'); + $sheet->mergeCells('E3:F3'); + $sheet->mergeCells('A4:B4'); + $sheet->mergeCells('C4:D4'); + $sheet->mergeCells('E4:F4'); + $sheet->mergeCells('A5:F5'); + $sheet->mergeCells('B6:C6'); + + $sheet->setCellValue('A1', "供 投 里 海 农 特 产 品 下 单 清 单({$typeName})"); + $sheet->setCellValue('A2', '姓名:'); + $sheet->setCellValue('C2', '电话:'); + $sheet->setCellValue('E2', '会员角色:'); + $sheet->setCellValue('A3', '下单时间:'); + $sheet->setCellValue('C3', '到货时间:'); + $sheet->setCellValue('E3', '订单编号:'); + $sheet->setCellValue('A4', '办事时间:'); + $sheet->setCellValue('C4', '寿宴当日桌数:'); + $sheet->setCellValue('E4', '厨师:'); + $sheet->setCellValue('A5', '收货地址:'); + $sheet->setCellValue('A6', '编号'); + $sheet->setCellValue('B6', '品名'); + $sheet->setCellValue('D6', '单位'); + $sheet->setCellValue('E6', '下单数量'); + $sheet->setCellValue('F6', '客户备注'); + + // 设置默认的单元格样式 + $defaultStyle = [ + 'alignment' => [ + 'horizontal' => Alignment::HORIZONTAL_CENTER, + 'vertical' => Alignment::VERTICAL_CENTER, + ], + ]; + + // 应用默认样式到整个工作表 + $spreadsheet->getDefaultStyle()->applyFromArray($defaultStyle); + + // 设置默认的单元格样式 + $leftStyle = [ + 'alignment' => [ + 'horizontal' => Alignment::HORIZONTAL_LEFT, + 'vertical' => Alignment::VERTICAL_CENTER, + ], + ]; + + // 应用默认样式到A2:F5 + $sheet->getStyle('A2:F5')->applyFromArray($leftStyle); + + foreach ($data as $k => $v) { + $column = $k + 7; + $sheet->mergeCells("B{$column}:C{$column}"); + $sheet->setCellValue('A' . ($k + 7), $v['id']); + $sheet->setCellValue("B{$column}", $v['store_name']); + $sheet->setCellValue("D{$column}", $v['unit_name']); + } + $count = count($data); + $sheet->mergeCells('A' . ($count + 7) . ':F' . ($count + 7)); + $sheet->setCellValue('A' . ($count + 7), "专区类型:{$typeName}"); + $sheet->mergeCells('A' . ($count + 8) . ':F' . ($count + 8)); + $sheet->setCellValue('A' . ($count + 8), ""); + $sheet->mergeCells('A' . ($count + 9) . ':F' . ($count + 9)); + $sheet->setCellValue('A' . ($count + 9), "备注:{$remark}"); + $sheet->getRowDimension($count + 9)->setRowHeight(50); + $sheet->getStyle('A' . ($count + 9))->getAlignment()->setWrapText(true); + $sheet->getStyle('A' . ($count + 7). ':' . 'F' . ($count + 9))->applyFromArray($leftStyle); + + // 设置单元格的样式 + $styleArray = [ + 'font' => [ + 'bold' => true, + 'size' => 28, + ], + ]; + $sheet->getStyle('A1')->applyFromArray($styleArray); + // 定义线框样式 + $styleArray = [ + 'borders' => [ + 'allBorders' => [ + 'borderStyle' => Border::BORDER_THIN, // 线框样式 + 'color' => ['argb' => '000000'], // 线框颜色 + ], + ], + ]; + $sheet->getStyle('A1:F' . ($count + 9))->applyFromArray($styleArray); + + $writer = new Xlsx($spreadsheet); + $url = '/export/' . date('Y-m') . "/供投里海农特产品下单清单({$typeName})" . date('YmdHi') . '.xlsx'; + $file_path = public_path() . $url; + if (!is_dir(dirname($file_path))) { + mkdir(dirname($file_path), 0777, true); + } + $writer->save($file_path); + return getenv('APP_URL') . $url; + } + +} From 37107288069a82a014f1ba63b9e877b6cac0e9c2 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sat, 21 Dec 2024 23:37:35 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix(admin):=20=E4=BF=AE=E5=A4=8D=E5=90=8E?= =?UTF-8?q?=E5=8F=B0=E9=A2=84=E8=AE=A2=E5=8D=95=E5=95=86=E5=93=81=E4=BB=B7?= =?UTF-8?q?=E6=A0=BC=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 增加用户非会员价格判断,避免非会员显示会员价格 - 优化价格查询逻辑,提高代码可读性和性能 --- app/admin/logic/beforehand_order/BeforehandOrderLogic.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/admin/logic/beforehand_order/BeforehandOrderLogic.php b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php index 455d9a580..e8941155d 100644 --- a/app/admin/logic/beforehand_order/BeforehandOrderLogic.php +++ b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php @@ -371,6 +371,7 @@ class BeforehandOrderLogic extends BaseLogic if ($count > 0) { throw new BusinessException('订单中有数量为0的商品,请先处理'); } + $user_ship=0; if($order['uid']>0){ $user_ship=User::where('id', $order['uid'])->value('user_ship')??0; } @@ -390,7 +391,11 @@ class BeforehandOrderLogic extends BaseLogic $arr['delivery_time'] = strtotime($delivery_time); $res = WarehouseOrder::create($arr); foreach ($info as $key => $arr) { - $price=StoreProductGroupPrice::where('product_id',$arr['product_id'])->where('group_id',$user_ship)->value('price')??0; + if($user_ship==0){ + $price=0; + }else{ + $price=StoreProductGroupPrice::where('product_id',$arr['product_id'])->where('group_id',$user_ship)->value('price')??0; + } $data = [ 'warehouse_id' => $warehouse_id, 'product_id' => $arr['product_id'],