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.
156 lines
5.5 KiB
156 lines
5.5 KiB
<?php |
|
|
|
|
|
namespace App\Admin\Extensions\Exporter; |
|
|
|
|
|
use App\Models\AdmissionNewStudents; |
|
use App\Models\BasicFamilyInformation; |
|
use App\Models\Config; |
|
use App\Models\Order; |
|
use App\Models\SecondaryCollege; |
|
use App\Models\Speciality; |
|
use App\Models\UserBasicInfo; |
|
use App\Models\UsersMember; |
|
use Dcat\Admin\Grid\Exporters\AbstractExporter; |
|
use Illuminate\Support\Facades\DB; |
|
use Maatwebsite\Excel\Concerns\Exportable; |
|
use Maatwebsite\Excel\Concerns\FromCollection; |
|
use Maatwebsite\Excel\Concerns\WithHeadings; |
|
use Maatwebsite\Excel\Concerns\WithMapping; |
|
|
|
class ImportUserBaseInfo extends AbstractExporter implements WithMapping, WithHeadings, FromCollection |
|
{ |
|
use Exportable; |
|
protected $fileName = '用户基本信息'; |
|
protected $titles = []; |
|
|
|
public function __construct() |
|
{ |
|
$this->fileName = $this->fileName.'_'.time().'.xlsx';//拼接下载文件名称 |
|
$this->titles = [ |
|
"family_name" => '联系人', |
|
"family_mobile" => '联系号码', |
|
"relationship" => '关系', |
|
"address" => '家庭住址', |
|
"postal_code" => '邮政编码', |
|
"native" => '籍贯', |
|
"email" => '邮箱', |
|
"name" => '学生姓名', |
|
"mobile" => '学生号码', |
|
"idcard" => '学生身份证', |
|
"sex" => '学生性别', |
|
"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. |
|
//取出当前年份 |
|
$config = Config::query()->where([ |
|
"unique_identification" => "annual_session" |
|
])->first(); |
|
|
|
//专业信息 |
|
$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"); |
|
|
|
$studentsList = AdmissionNewStudents::query()->where([ |
|
"annual_session" => $config->data, |
|
"is_new_student" => AdmissionNewStudents::IS_NEW_STUDENT_YES |
|
])->get()->toArray(); |
|
|
|
$userList = UsersMember::query()->whereIn("idcard", array_column($studentsList, "idCard"))->get()->toArray(); |
|
$userList = array_column($userList, null, "unique_number"); |
|
|
|
$basicFamilyInfoList = BasicFamilyInformation::query()->whereIn("unique_number", array_column($userList, "unique_number"))->get()->toArray(); |
|
if(empty($basicFamilyInfoList)){ |
|
return collect([]); |
|
} |
|
|
|
$userBasicInfoList = UserBasicInfo::query()->whereIn("unique_number", array_column($userList, "unique_number"))->get()->toArray(); |
|
if(empty($userBasicInfoList)){ |
|
return collect([]); |
|
} |
|
$userBasicInfoList = array_column($userBasicInfoList, null, "unique_number"); |
|
|
|
$addList = []; |
|
foreach($basicFamilyInfoList as $item){ |
|
$address = ""; |
|
$postal_code = ""; |
|
$native = ""; |
|
$email = ""; |
|
|
|
if(array_key_exists($item["unique_number"], $userBasicInfoList)){ |
|
$address = $userBasicInfoList[$item["unique_number"]]['province_city_area'].'--'.$userBasicInfoList[$item["unique_number"]]['address']; |
|
$postal_code = $userBasicInfoList[$item["unique_number"]]['postal_code']; |
|
$native = $userBasicInfoList[$item["unique_number"]]['native']; |
|
$email = $userBasicInfoList[$item["unique_number"]]['email']; |
|
} |
|
|
|
$arr = [ |
|
"family_name" => $item["name"], |
|
"family_mobile" => $item["mobile"], |
|
"relationship" => $item["relationship"], |
|
"address" => $address, |
|
"postal_code" => $postal_code, |
|
"native" => $native, |
|
"email" => $email, |
|
"name" => $userList[$item["unique_number"]]["name"], |
|
"mobile" => $userList[$item["unique_number"]]["mobile"], |
|
"idcard" => $userList[$item["unique_number"]]["idcard"], |
|
"sex" => $userList[$item["unique_number"]]["sex"] == 1 ? "男" : "女", |
|
"speciality_name" => $specialityList[$userList[$item["unique_number"]]["speciality_id"]]["speciality_name"], |
|
"conllege_name" => $secondary_college[$specialityList[$userList[$item["unique_number"]]["speciality_id"]]['secondary_college_id']]['name'], |
|
"annual_session" => $config->data, |
|
]; |
|
|
|
array_push($addList, $arr); |
|
} |
|
|
|
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["family_name"], |
|
$row["family_mobile"], |
|
$row["relationship"], |
|
$row["address"], |
|
$row["postal_code"], |
|
$row["native"], |
|
$row["email"], |
|
$row["name"], |
|
$row["mobile"], |
|
"'".$row['idcard'].'', |
|
$row["sex"], |
|
$row["speciality_name"], |
|
$row["conllege_name"], |
|
$row["annual_session"], |
|
]; |
|
} |
|
|
|
}
|
|
|