Closed xushenjie closed 3 years ago
use Illuminate\Database\Eloquent\Collection; use Maatwebsite\Excel\Concerns\FromCollection; use Maatwebsite\Excel\Concerns\WithEvents; use Maatwebsite\Excel\Concerns\WithStrictNullComparison; use Maatwebsite\Excel\Events\AfterSheet; use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Cell\DataType; use PhpOffice\PhpSpreadsheet\Cell\DefaultValueBinder; use Maatwebsite\Excel\Concerns\WithCustomValueBinder; class OrderExport extends DefaultValueBinder implements FromCollection, WithEvents, WithStrictNullComparison, WithCustomValueBinder { protected $data; public function __construct($data) { $this->data = $data; } public function collection() { return new Collection($this->handlerData()); } public function handlerData() { // 表头 $header[] = ['订单编号', '主分订单', '用户名', '商品ID', '商品名称', '多规格商品名', '商品货号', '商品条形码', '商品数量' ]; $exportData = []; foreach ($orders as $item) { $orderItem = [ 'order_sn' => $item->order_sn, 'main_order' => $item->main_order == 1 ? '是' : '否', 'user_name' => $item->userInfo->user_name, 'shop_name' => $item->shopInfo->shop_name, 'address' => $item->province_name . $item->city_name . $item->district_name . $item->address, 'mobile' => $item->mobile 'pay_name' => $item->pay_name, ]; $orderGoods = []; if (count($item->order_goods) > 1) { foreach ($item['order_goods'] as $goods) { $goodsItem = [id, 'goods_name' => $goods->goods_name, 'product_name' => $this->getProductName($goods->product_id), 'goods_sn' => $goods->goods_sn, 'goods_number' => $goods->goods_number, 'goods_price' => $goods->goods_price, 'shop_name' => $item->shopInfo->shop_name, ]; $orderGoods[] = $goodsItem; } } $exportData[] = array_merge([$orderItem], $orderGoods); } $exportData = array3_to_array2($exportData); return array_merge($header, $exportData); }
map()
Prerequisites
Versions
Description
Hello Sir, I have a question,
Queued Export By using the FromQuery , How to handler query result ?
because i need to additional handler the query result .
Not used Queue ,This is how I deal with it
but queued export by using the FromQuery , I don't know how to deal with it,Look forward to your reply!