fileName = $this->fileName.'_'.time().'.xlsx';//拼接下载文件名称 $this->titles = [ 'mobile' => '手机号' , 'name'=>'姓名', 'idcard'=>'身份证', 'sex' => "性别", "college" => "二级学院", "speciality" => "专业", "create_time" => "注册时间", "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()); } public function headings(): array { // TODO: Implement headings() method. return $this->titles(); } public function map($row): array { $nameInfo = $this->getSpecialityAndCollegeNameById($row["speciality_id"]); $sex = $row['sex'] == 1 ? "男" : "女"; $test = $row['is_test'] == 1 ? "否" : "是"; // TODO: Implement map() method. return [ $row['mobile'], $row['name'], "'".$row['idcard'].'', $sex, $nameInfo["name"], $nameInfo["speciality_name"], date("Y-m-d H:i:s", $row['create_time']), $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(); } }