109 lines
2.8 KiB
PHP
109 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\Virtual\Exports;
|
|
|
|
use App\Core\AbstractExport;
|
|
use Dipper\Excel\Concerns\WithRows;
|
|
use Dipper\Excel\Concerns\WithHeadings;
|
|
use Dipper\Excel\Concerns\FromCollection;
|
|
use Dipper\Excel\Concerns\WithColumnFormatting;
|
|
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
|
use App\Domains\Virtual\Services\PropertyService;
|
|
use App\Domains\Virtual\Repositories\PropertySettingRepository;
|
|
|
|
class PropertyExport extends AbstractExport implements FromCollection, WithHeadings, WithRows, WithColumnFormatting
|
|
{
|
|
public $conditions;
|
|
public $settings;
|
|
|
|
public function __construct(array $conditions = [])
|
|
{
|
|
$this->conditions = $conditions;
|
|
$this->settings = app(PropertySettingRepository::class)->getAll();
|
|
parent::__construct();
|
|
}
|
|
|
|
public function collection()
|
|
{
|
|
return app(PropertyService::class)->index($this->conditions);
|
|
}
|
|
|
|
public function headings(): array
|
|
{
|
|
$provinces = $this->settings['province'] ?? [];
|
|
|
|
$headings = [
|
|
'*企业ID',
|
|
'企业名称',
|
|
'*套餐ID',
|
|
'套餐名称',
|
|
'月流量',
|
|
'销售数量',
|
|
'*公司类型',
|
|
'*产品类型',
|
|
'套餐类型',
|
|
'平台/API',
|
|
'*车辆类型',
|
|
'商用车分类',
|
|
'*客户类型',
|
|
];
|
|
|
|
foreach ($provinces as $province) {
|
|
array_push($headings, $province);
|
|
}
|
|
|
|
return $headings;
|
|
}
|
|
|
|
/**
|
|
* @param mixed $row
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function rows($rows)
|
|
{
|
|
$provinces = $this->settings['province'] ?? [];
|
|
|
|
$array = [];
|
|
|
|
foreach ($rows as $key => $value) {
|
|
$item = [
|
|
$value['company_id'],
|
|
$value['company_name'],
|
|
$value['package_id'],
|
|
$value['package_name'],
|
|
strval($value['flows'] ?: 0),
|
|
strval($value['counts']),
|
|
$value['company'],
|
|
$value['product'],
|
|
$value['package'],
|
|
$value['platform'],
|
|
$value['vehicle'],
|
|
$value['commercial_vehicle'],
|
|
$value['customer'],
|
|
];
|
|
|
|
foreach ($provinces as $province) {
|
|
$item[$province] = strval($value['province'][$province] ?: 0);
|
|
}
|
|
|
|
$array[] = $item;
|
|
}
|
|
|
|
return $array;
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function columnFormats(): array
|
|
{
|
|
return [
|
|
'A' => NumberFormat::FORMAT_NUMBER,
|
|
'C' => NumberFormat::FORMAT_NUMBER,
|
|
'E' => NumberFormat::FORMAT_NUMBER,
|
|
'F' => NumberFormat::FORMAT_NUMBER,
|
|
];
|
|
}
|
|
}
|