123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- <?php
- namespace App\Exports\School;
- use App\Repositories\Enums\ModelStatusEnum;
- use App\Repositories\Enums\School\LessonScheduleApproveStatusEnum;
- use App\Repositories\Enums\School\ScheduleRecordTypeEnum;
- use App\Repositories\Models\School\LessonSchedule;
- use App\Repositories\Models\School\Room;
- use App\Repositories\Models\School\ScheduleApproveLog;
- use App\Repositories\Models\School\ScheduleApproveRecord;
- use Maatwebsite\Excel\Concerns\Exportable;
- use Maatwebsite\Excel\Concerns\FromQuery;
- use Maatwebsite\Excel\Concerns\ShouldAutoSize;
- use Maatwebsite\Excel\Concerns\WithColumnWidths;
- use Maatwebsite\Excel\Concerns\WithHeadings;
- use Maatwebsite\Excel\Concerns\WithMapping;
- use Maatwebsite\Excel\Concerns\WithStyles;
- use PhpOffice\PhpSpreadsheet\Style\Alignment;
- use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
- use function Symfony\Component\String\b;
- class ApproveRecordExport implements FromQuery, WithMapping, WithHeadings, ShouldAutoSize, WithColumnWidths, WithStyles
- {
- use Exportable;
- protected $rowNums = 0;
- protected $room_id = 0;
- protected $term_id = 0;
- protected $status = 0;
- protected $type = 0;
- protected $fields = [];
- public function __construct($term_id, $room_id, $status, $type)
- {
- $this->room_id = $room_id;
- $this->term_id = $term_id;
- $this->status = $status;
- $this->type = $type;
- }
- public function query()
- {
- $room_id = $this->room_id;
- $status = $this->status;
- $type = $this->type;
- return ScheduleApproveRecord::query()
- ->with(['room'])
- ->where('term_id', $this->term_id)
- ->when($room_id, function ($query) use ($room_id) {
- return $query->where('room_id', $room_id);
- })->when($status, function ($query) use ($status) {
- return $query->where('status', $status);
- })
- ->when($type, function ($query) use ($type) {
- return $query->where('type', $type);
- })
- ->orderBy('id');
- // ->orderBy('time_id');
- }
- public function headingRow(): int
- {
- return 2;
- }
- public function headings(): array
- {
- $room_name = '停调补课记录';
- if ($this->room_id) {
- $room_name = Room::query()->where('id', $this->room_id)->value('name') . '-停调补课记录';
- }
- $data[] = [$room_name];
- $bases = [
- '序号',
- '类型',
- '课程名称',
- '任课教师',
- '班级',
- '分组',
- '人数',
- '原上课时间',
- '现上课时间',
- '申请时间',
- '实验中心审批状态',
- '院系审批意见',
- '状态',
- ];
- // $data[1] = '序号';
- // foreach ($this->fields as $field) {
- // $data[1] = $bases[$field];
- // }
- $data[] = $bases;
- return $data;
- }
- public function columnWidths(): array
- {
- $bases = [
- 'A' => 8,
- 'B' => 8,
- 'C' => 30,
- 'D' => 12,
- 'E' => 30,
- 'F' => 8,
- 'G' => 8,
- 'H' => 50,
- 'I' => 50,
- 'J' => 20,
- 'K' => 35,
- 'L' => 35,
- 'M' => 15,
- ];
- // $data['A'] = 8;
- // $values = array_values($bases);
- // $keys = array_keys($bases);
- // foreach ($this->fields as $field) {
- // $key = $keys[$field];
- // $data["{$key}"] = $values[$field];
- // }
- $data = $bases;
- return $data;
- }
- public function styles(Worksheet $sheet)
- {
- $cellRange = 'A1:M1';
- $sheet->getStyle($cellRange)->getFont()->setSize(12);
- $sheet->getDefaultRowDimension()->setRowHeight(40);//设置行高
- // 文字居中
- $lastrow = $sheet->getHighestRow();
- $sheet->getStyle('A1:M' . $lastrow)->getAlignment()->setVertical(Alignment::VERTICAL_CENTER);//垂直居中
- $sheet->getStyle('A1:M' . $lastrow)->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
- $sheet->getStyle('A1:M' . $lastrow)->getAlignment()->setWrapText(true);
- $sheet->mergeCells('A1:M1'); //合并
- $sheet->getStyle('A1:M1')->getFont()->setSize(16);
- }
- public function map($row): array
- {
- $this->rowNums++;
- $data = [];
- $teach_lesson = LessonSchedule::query()->where('id', $row['lesson_schedule_id'])->with(['lesson', 'teacher', 'grade', 'time', 'room'])->first();
- if ($teach_lesson) {
- $old_times = [
- $teach_lesson['room']['name'],
- '第' . $teach_lesson['week'] . '周',
- '星期' . LessonSchedule::weekInt2name($teach_lesson['week_index']) . "(" . $teach_lesson['day'] . ")",
- $teach_lesson['time']['name']
- ];
- $old_week_name = arr2str($old_times, ' | ');
- $group_name = LessonSchedule::groupInt2Name($teach_lesson['group']);
- $new_week_name = '';
- if (in_array($row['type'], [ScheduleRecordTypeEnum::BK, ScheduleRecordTypeEnum::TK]) && is_array($row['migrate_data'])) {
- $new_times = [
- isset($row['migrate_data']['room_name']) ? $row['migrate_data']['room_name'] : '',
- '第' . $row['migrate_data']['week'] . '周',
- '星期' . LessonSchedule::weekInt2name($row['migrate_data']['week_index']) . "(" . $row['migrate_data']['day'] . ")",
- $row['migrate_data']['time']['name']
- ];
- $new_week_name = arr2str($new_times, ' | ');
- }
- $yxyj = $syzxyj = '';
- $yx = ScheduleApproveLog::query()->where('status', ModelStatusEnum::OK)->where('schedule_approve_id', $row['id'])->where('type', ScheduleApproveLog::TYPE_YX)->with(['check_admin'])->select(['id', 'check_admin_id', 'check_time', 'check_status', 'check_result'])->orderByDesc('id')->first();
- if ($yx) {
- $yxyj = arr2str([
- $yx['check_status'] == 1 ? '审核通过' : '审核未通过',
- $yx['check_admin']['name'],
- $yx['check_time'],
- ], '|');
- }
- $syzx = ScheduleApproveLog::query()->where('status', ModelStatusEnum::OK)->where('schedule_approve_id', $row['id'])->where('type', ScheduleApproveLog::TYPE_SYZX)->with(['check_admin'])->select(['id', 'check_admin_id', 'check_time', 'check_status', 'check_result'])->orderByDesc('id')->first();
- if ($syzx) {
- $syzxyj = arr2str([
- $syzx['check_status'] == 1 ? '审核通过' : '审核未通过',
- $syzx['check_admin']['name'],
- $syzx['check_time'],
- ], '|');
- }
- $type_name = '';
- switch ($row['type']) {
- case ScheduleRecordTypeEnum::SK:
- $type_name = '停课';
- break;
- case ScheduleRecordTypeEnum::TK:
- $type_name = '调课';
- break;
- case ScheduleRecordTypeEnum::BK:
- $type_name = '补课';
- break;
- }
- $bases = [
- $this->rowNums,
- $type_name,
- $teach_lesson['lesson']['name'],
- $teach_lesson['teacher']['name'],
- $teach_lesson['grade']['name'],
- $group_name,
- $teach_lesson['student_nums'],
- $old_week_name,
- $new_week_name,
- $row['created_at'],
- $syzxyj,
- $yxyj,
- LessonScheduleApproveStatusEnum::getDescription($row['status'])
- ];
- $data = $bases;
- }
- // foreach ($this->fields as $field) {
- // $data[] = $bases[$field];
- // }
- return $data;
- }
- }
|