停车场管理系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

66 lines
1.8 KiB

<?php
namespace App\Exports;
use App\Models\ParkingSpaceType;
use App\Services\OperationLogService;
use App\Services\ParkingOccupancyRateService;
use Maatwebsite\Excel\Concerns\FromArray;
use Maatwebsite\Excel\Concerns\WithHeadings;
class OccupancyRateExport implements FromArray, WithHeadings
{
public array $parents = [];
public ParkingOccupancyRateService $service;
public array $parkingSpaceType;
public function __construct($parents)
{
$this->parents = $parents;
$this->service = new ParkingOccupancyRateService(
new OperationLogService()
);
$this->parkingSpaceType = ParkingSpaceType::getData();
}
public function array(): array
{
$data = [];
$index = 1;
$parkingSpaceType = $this->parkingSpaceType;
$query = $this->service->queryList($this->parents);
$list = $query->select()->get()->toArray();
foreach ($list as $item) {
$item = $this->service->getItem($item, $parkingSpaceType);
$value = [
'index' => $index,
'time' => $item['time'],
'floor' => $item['floor']
];
foreach ($parkingSpaceType as $type) {
$type_id = $type['id'];
$key = 'type' . $type_id;
$value[$key] = $item[$key];
}
$data[] = $value;
$index += 1;
}
return $data;
}
/**
* @return array
*/
public function headings(): array
{
$header = [
__('exports.global.index'),
__('exports.occupancy_rate.time'),
__('exports.occupancy_rate.floor'),
];
foreach ($this->parkingSpaceType as $value) {
$header[] = $value['name'];
}
return $header;
}
}