Merge pull request 'dev' (#403) from dev into main

Reviewed-on: #403
This commit is contained in:
mkm 2024-12-21 23:38:37 +08:00
commit c7b7c93a4e
4 changed files with 151 additions and 1 deletions

View File

@ -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]);
}
}

View File

@ -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']);
}
}

View File

@ -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'],

View File

@ -0,0 +1,115 @@
<?php
namespace app\common\service\xlsx;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\Border;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use PhpOffice\PhpSpreadsheet\Style\Alignment;
class ActivityZoneService
{
public function export($data, $typeName, $remark)
{
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->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;
}
}