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.
149 lines
4.9 KiB
149 lines
4.9 KiB
<?php |
|
|
|
|
|
namespace App\Admin\Extensions\Exporter; |
|
|
|
|
|
use App\Models\CompletedOfflineStep; |
|
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 ImportStudentExporter extends AbstractExporter implements WithMapping, WithHeadings, FromCollection |
|
{ |
|
use Exportable; |
|
protected $fileName = '导入学生名单'; |
|
protected $titles = []; |
|
|
|
public function __construct() |
|
{ |
|
$this->fileName = $this->fileName.'_'.time().'.xlsx';//拼接下载文件名称 |
|
$this->titles = [ |
|
'mobile' => '手机号' , |
|
'name'=>'姓名', |
|
'idCard'=>'身份证', |
|
'sex' => "性别", |
|
"admission_code" => "录取编码", |
|
"admission_college" => "二级学院", |
|
"admitted_major" => "录取专业", |
|
"resuming_school" => "复学类型", |
|
"annual_session" => "年份", |
|
"create_time" => "导入时间", |
|
"zhaoshengban" => "招生办报到", |
|
"erjixueyuan" => "二级学院报到", |
|
"suguan" => "宿管办报到", |
|
"is_test" => "测试账号" |
|
]; |
|
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()); |
|
$chunk_list = array_chunk($this->buildData(), 1000); |
|
$newList = []; |
|
|
|
$userList = UsersMember::query()->get()->toArray(); |
|
$userList = array_column($userList, null, "idcard"); |
|
|
|
foreach($chunk_list as $value){ |
|
foreach ($value as $item){ |
|
$resuming_school = "普通学生"; |
|
if($item["resuming_school"] == 1) $resuming_school = "退伍复学"; |
|
if($item["resuming_school"] == 2) $resuming_school = "普通复学"; |
|
$is_test = "否"; |
|
if($item["is_test"] == 2) $is_test = "是"; |
|
|
|
$zhaoshengban = "否"; |
|
$erjixueyuan = "否"; |
|
$suguan = "否"; |
|
|
|
if(array_key_exists($item["idCard"], $userList)){ |
|
$step = CompletedOfflineStep::query()->where("unique_number", $userList[$item["idCard"]]["unique_number"])->get()->toArray(); |
|
if(!empty($step)){ |
|
$step = array_column($step, null, "step_id"); |
|
if(array_key_exists(2, $step)) $zhaoshengban = "是"; |
|
if(array_key_exists(3, $step)) $erjixueyuan = "是"; |
|
if(array_key_exists(4, $step)) $suguan = "是"; |
|
} |
|
} |
|
|
|
$arr = [ |
|
"sex" => $item['sex'] == 1 ? "男" : "女", |
|
"resuming_school" => $resuming_school, |
|
"is_test" => $is_test, |
|
"zhaoshengban" => $zhaoshengban, |
|
"erjixueyuan" => $erjixueyuan, |
|
"suguan" => $suguan, |
|
"mobile" => $item["mobile"], |
|
"name" => $item["name"], |
|
"idCard" => $item["idCard"], |
|
"admission_code" => $item["admission_code"], |
|
"admission_college" => $item["admission_college"], |
|
"admitted_major" => $item["admitted_major"], |
|
"annual_session" => $item["annual_session"], |
|
"create_time" => date("Y-m-d H:i:s", $item['create_time']), |
|
]; |
|
array_push($newList, $arr); |
|
} |
|
} |
|
|
|
return collect($newList); |
|
} |
|
|
|
public function headings(): array |
|
{ |
|
// TODO: Implement headings() method. |
|
return $this->titles(); |
|
} |
|
|
|
public function map($row): array |
|
{ |
|
|
|
// TODO: Implement map() method. |
|
return [ |
|
$row['mobile'], |
|
$row['name'], |
|
"'".$row['idCard'].'', |
|
$row['sex'], |
|
$row['admission_code'], |
|
$row['admission_college'], |
|
$row['admitted_major'], |
|
$row['resuming_school'], |
|
$row['annual_session'], |
|
$row['create_time'], |
|
$row["zhaoshengban"], |
|
$row["erjixueyuan"], |
|
$row["suguan"], |
|
$row["is_test"], |
|
]; |
|
} |
|
|
|
public function getSpecialityAndCollegeNameById($id) |
|
{ |
|
$nameInfo = Speciality::query()->where("speciality.id", $id)->leftJoin("secondary_college as b", "speciality.secondary_college_id", "=", "b.id")->first(); |
|
|
|
if(empty($nameInfo)){ |
|
return [ |
|
"name" => "", |
|
"speciality_name" => "" |
|
]; |
|
} |
|
|
|
return $nameInfo->toArray(); |
|
} |
|
|
|
}
|
|
|