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.
143 lines
4.5 KiB
143 lines
4.5 KiB
<?php |
|
|
|
|
|
namespace App\Admin\Extensions\Exporter; |
|
|
|
|
|
use App\Models\CompletedOfflineStep; |
|
use App\Models\Config; |
|
use App\Models\SecondaryCollege; |
|
use App\Models\Speciality; |
|
use App\Models\UsersMember; |
|
use Dcat\Admin\Grid\Exporters\AbstractExporter; |
|
use Maatwebsite\Excel\Concerns\Exportable; |
|
use Maatwebsite\Excel\Concerns\FromCollection; |
|
use Maatwebsite\Excel\Concerns\WithHeadings; |
|
use Maatwebsite\Excel\Concerns\WithMapping; |
|
|
|
class ImportCompletedOfflineStep extends AbstractExporter implements WithMapping, WithHeadings, FromCollection |
|
{ |
|
use Exportable; |
|
protected $fileName = '线下报到明细'; |
|
protected $titles = []; |
|
|
|
public function __construct() |
|
{ |
|
$this->fileName = $this->fileName.'_'.time().'.xlsx';//拼接下载文件名称 |
|
$this->titles = [ |
|
"name" => '姓名', |
|
"mobile" => '手机', |
|
"idcard" => '身份证', |
|
"sex" => '性别', |
|
"zb" => '招办签到', |
|
"xy" => '二级学院签到', |
|
"sg" => '宿管办签到', |
|
"speciality_name" => '专业', |
|
"conllege_name" => '二级学院', |
|
"annual_session" => '年份', |
|
]; |
|
parent::__construct(); |
|
} |
|
|
|
public function export() |
|
{ |
|
// TODO: Implement export() method. |
|
$this->download($this->fileName)->prepare(request())->send(); |
|
exit; |
|
} |
|
|
|
public function collection() |
|
{ |
|
// TODO: Implement collection() method. |
|
// return collect($this->buildData()); |
|
|
|
//取出当前年份 |
|
$config = Config::query()->where([ |
|
"unique_identification" => "annual_session" |
|
])->first(); |
|
|
|
$list = CompletedOfflineStep::query()->where([ |
|
"annual_session" => $config->data, |
|
])->get()->toArray(); |
|
if(!empty($list)){ |
|
//专业信息 |
|
$specialityList = Speciality::query()->get()->toArray(); |
|
$specialityList = array_column($specialityList, null,"id"); |
|
|
|
//二级学院 |
|
$secondary_college = SecondaryCollege::query()->get()->toArray(); |
|
$secondary_college = array_column($secondary_college, null,"id"); |
|
|
|
$numberList = array_unique(array_column($list, "unique_number")); |
|
|
|
$userList = UsersMember::query()->whereIn("unique_number", $numberList)->get()->toArray(); |
|
$userList = array_column($userList, null, "unique_number"); |
|
|
|
$data = []; |
|
|
|
foreach($list as $item){ |
|
if(array_key_exists($item["unique_number"], $data)){ |
|
if(!in_array($item["step_id"], $data[$item["unique_number"]])){ |
|
array_push($data[$item["unique_number"]], $item["step_id"]); |
|
} |
|
}else{ |
|
$data[$item["unique_number"]][] = $item["step_id"]; |
|
} |
|
} |
|
|
|
$addList = []; |
|
|
|
foreach($data as $key => $item){ |
|
|
|
$zb = "否"; |
|
$xy = "否"; |
|
$sg = "否"; |
|
|
|
if(in_array(2, $item)) $zb = "是"; |
|
if(in_array(3, $item)) $xy = "是"; |
|
if(in_array(4, $item)) $sg = "是"; |
|
|
|
$add = [ |
|
"name" => $userList[$key]["name"], |
|
"mobile" => $userList[$key]["mobile"], |
|
"idcard" => $userList[$key]["idcard"], |
|
"sex" => $userList[$key]["sex"] == 1 ? "男" : "女", |
|
"zb" => $zb, |
|
"xy" => $xy, |
|
"sg" => $sg, |
|
"speciality_name" => $specialityList[$userList[$key]["speciality_id"]]["speciality_name"], |
|
"conllege_name" => $secondary_college[$specialityList[$userList[$key]["speciality_id"]]['secondary_college_id']]['name'], |
|
"annual_session" => $config->data, |
|
]; |
|
|
|
array_push($addList, $add); |
|
} |
|
|
|
return collect($addList); |
|
} |
|
|
|
} |
|
|
|
public function headings(): array |
|
{ |
|
// TODO: Implement headings() method. |
|
return $this->titles(); |
|
} |
|
|
|
public function map($row): array |
|
{ |
|
// TODO: Implement map() method. |
|
return [ |
|
$row["name"], |
|
$row["mobile"], |
|
"'".$row['idcard'].'', |
|
$row["sex"], |
|
$row["zb"], |
|
$row["xy"], |
|
$row["sg"], |
|
$row["speciality_name"], |
|
$row["conllege_name"], |
|
$row["annual_session"], |
|
]; |
|
} |
|
}
|
|
|