| 
						 | 
						<?php
namespace App\Exports;
use App\Common\ProductStatus;use App\Models\Product;use Maatwebsite\Excel\Concerns\FromQuery;use Maatwebsite\Excel\Concerns\WithColumnFormatting;use Maatwebsite\Excel\Concerns\WithHeadings;use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
class ProductExport implements FromQuery, WithHeadings, WithColumnFormatting{	private int $supplier_id;
	public function __construct(int $supplier_id)	{		$this->supplier_id = $supplier_id;	}
	public function query()	{		return Product::with('category:id,name')->where('supplier_id', $this->supplier_id);	}
	public function prepareRows($rows)	{		return $rows->transform(function ($row) {			return [				'id' => $row->id,				'status' => ProductStatus::array()[$row->status] ?? '',				'category_name' => $row->category?->name ?? '',				'title' => $row->title,				'price' => $row->price,				'original_price' => $row->original_price,				'stock' => $row->stock,				'know' => $row->know,				'content' => $row->content,				'verify_mobile' => $row->verify_mobile,				'diy_form_id' => $row->diy_form_id,				'出发地' => $row->extends['field_0_departure_place'] ?? '',				'出发地经度' => $row->extends['field_0_departure_place_longitude'] ?? '',				'出发地纬度' => $row->extends['field_0_departure_place_latitude'] ?? '',				'目的地' => $row->extends['field_0_destination'] ?? '',				'目的地经度' => $row->extends['field_0_destination_longitude'] ?? '',				'目的地纬度' => $row->extends['field_0_destination_latitude'] ?? '',				'行程起始时间' => $row->extends['field_0_date?->start'] ?? '',				'行程结束时间' => $row->extends['field_0_date?->end'] ?? '',				'酒店名' => $row->extends['field_1_name'] ?? '',				'酒店地址' => $row->extends['field_1_address'] ?? '',				'酒店经度' => $row->extends['field_1_longitude'] ?? '',				'酒店纬度' => $row->extends['field_1_latitude'] ?? '',				'景区名' => $row->extends['field_2_name'] ?? '',				'景区地址' => $row->extends['field_2_address'] ?? '',				'景区经度' => $row->extends['field_2_longitude'] ?? '',				'景区纬度' => $row->extends['field_2_latitude'] ?? '',				'餐厅名' => $row->extends['field_3_name'] ?? '',				'餐厅地址' => $row->extends['field_3_address'] ?? '',				'餐厅经度' => $row->extends['field_3_longitude'] ?? '',				'餐厅纬度' => $row->extends['field_3_latitude'] ?? '',				'交通地址' => $row->extends['field_4_address'] ?? '',				'交通经度' => $row->extends['field_4_longitude'] ?? '',				'交通纬度' => $row->extends['field_4_latitude'] ?? '',				'购物地址' => $row->extends['field_5_address'] ?? '',				'购物经度' => $row->extends['field_5_longitude'] ?? '',				'购物纬度' => $row->extends['field_5_latitude'] ?? '',			];		});	}
	public function map($row): array	{		return [			$row->id,			$row->category->name,
		];	}
	public function headings(): array	{		return [			'ID', '状态', '分类', '产品标题', '销售价', '市场价', '库存', '旅客须知', '产品详情', '核销手机号', '信息收集表单ID',			'出发地', '出发地经度', '出发地纬度', '目的地', '目的地经度', '目的地纬度', '行程起始时间', '行程结束时间',			'酒店名', '酒店地址', '酒店经度', '酒店纬度',			'景区名', '景区地址', '景区经度', '景区纬度',			'餐厅名', '餐厅地址', '餐厅经度', '餐厅纬度',			'交通地址', '交通经度', '交通纬度',			'购物地址', '购物经度', '购物纬度',		];	}
	public function columnFormats(): array	{		for ($i = 65; $i <= 90; $i++) {			$format[chr($i)] = NumberFormat::FORMAT_TEXT;		}		return $format;	}}
  |