74 lines
2.0 KiB
PHP
74 lines
2.0 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Exports;
|
||
|
|
|
||
|
|
use CommonUtilsService;
|
||
|
|
use Maatwebsite\Excel\Concerns\FromCollection;
|
||
|
|
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||
|
|
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
|
||
|
|
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||
|
|
use Maatwebsite\Excel\Concerns\WithStrictNullComparison;
|
||
|
|
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
||
|
|
use Maatwebsite\Excel\Concerns\WithTitle;
|
||
|
|
|
||
|
|
class CityUsersExport implements FromCollection ,WithHeadings,WithColumnFormatting,ShouldAutoSize,WithTitle
|
||
|
|
{
|
||
|
|
private $data, $index;
|
||
|
|
public function __construct($data, $index)
|
||
|
|
{
|
||
|
|
$this->data = $data;
|
||
|
|
$this->index =$index;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function headings(): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'id',
|
||
|
|
'姓名',
|
||
|
|
'昵称',
|
||
|
|
"手机号",
|
||
|
|
'性别',
|
||
|
|
'年龄',
|
||
|
|
'学历',
|
||
|
|
'省-市',
|
||
|
|
'行业',
|
||
|
|
'信仰',
|
||
|
|
"情感状态",
|
||
|
|
"收入"
|
||
|
|
];
|
||
|
|
}
|
||
|
|
//设置列格式
|
||
|
|
public function columnFormats(): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'A' => NumberFormat::FORMAT_TEXT,
|
||
|
|
];
|
||
|
|
}
|
||
|
|
public function collection()
|
||
|
|
{
|
||
|
|
$arr = [];
|
||
|
|
foreach ($this->data as $data) {
|
||
|
|
if ($data->sex > 0 ) {
|
||
|
|
$sex = $data->sex == 1?"男":"女";
|
||
|
|
}else {
|
||
|
|
$sex ="未知";
|
||
|
|
}
|
||
|
|
$age = CommonUtilsService::getAge($data->profileCourtship->birthday);
|
||
|
|
$arr[] = [
|
||
|
|
$data->id, $data->name, $data->nickname, $data->mobile, $sex, $age, $data->profileCourtship->degree, $data->profileCourtship->province."-".$data->profileCourtship->city,
|
||
|
|
$data->industry."/".$data->industry_sub, $data->profileCourtship->belief, $data->profileCourtship->state, $data->profileCourtship->income
|
||
|
|
];
|
||
|
|
}
|
||
|
|
$arr = collect($arr);
|
||
|
|
return $arr;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @return string
|
||
|
|
*/
|
||
|
|
public function title(): string
|
||
|
|
{
|
||
|
|
return $this->index. "-用户列表";
|
||
|
|
}
|
||
|
|
}
|