|
|
|
|
@ -110,27 +110,69 @@ class TeacherController extends BaseController
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})->orderBy($all['sort_name'] ?? 'id', $all['sort_type'] ?? 'desc');
|
|
|
|
|
// 应用与列表一致的筛选
|
|
|
|
|
if (isset($all['theme']) || isset($all['direction'])) {
|
|
|
|
|
$list = $list->whereHas('courseContents', function ($query) use ($all) {
|
|
|
|
|
if (isset($all['theme'])) {
|
|
|
|
|
$query->where('theme', $all['theme']);
|
|
|
|
|
}
|
|
|
|
|
if (isset($all['direction'])) {
|
|
|
|
|
$query->where('direction', $all['direction']);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (isset($all['keyword'])) {
|
|
|
|
|
$list = $list->where(function ($query) use ($all) {
|
|
|
|
|
$query->whereHas('courseContents', function ($query) use ($all) {
|
|
|
|
|
$query->where('direction', 'like', '%' . $all['keyword'] . '%');
|
|
|
|
|
})->orWhere('name', 'like', '%' . $all['keyword'] . '%');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (isset($all['is_export']) && !empty($all['is_export'])) {
|
|
|
|
|
$list = $list->limit(5000)->toArray();
|
|
|
|
|
return Excel::download(new CommonExport($list, $all['export_fields'] ?? ''), ($all['file_name'] ?? '') . date('YmdHis') . '.xlsx');
|
|
|
|
|
} else {
|
|
|
|
|
if (isset($all['theme']) || isset($all['direction'])) {
|
|
|
|
|
$list = $list->whereHas('courseContents', function ($query) use ($all) {
|
|
|
|
|
if (isset($all['theme'])) {
|
|
|
|
|
$query->where('theme', $all['theme']);
|
|
|
|
|
// 导出
|
|
|
|
|
// 取数并展开为“老师 x 课程”的多行
|
|
|
|
|
$teachers = $list->limit(5000)->get();
|
|
|
|
|
$rows = [];
|
|
|
|
|
foreach ($teachers as $teacher) {
|
|
|
|
|
$hasCourses = $teacher->courseContents && $teacher->courseContents->count() > 0;
|
|
|
|
|
if ($hasCourses) {
|
|
|
|
|
foreach ($teacher->courseContents as $content) {
|
|
|
|
|
$rows[] = [
|
|
|
|
|
'teacher_name' => $teacher->name ?? '',
|
|
|
|
|
'introduce' => $teacher->introduce ?? '',
|
|
|
|
|
'sex' => $teacher->sex ?? '',
|
|
|
|
|
'mobile' => $teacher->mobile ?? '',
|
|
|
|
|
'course_name' => optional($content->course)->name ?? '',
|
|
|
|
|
'theme' => $content->theme ?? '',
|
|
|
|
|
'direction' => $content->direction ?? '',
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
if (isset($all['direction'])) {
|
|
|
|
|
$query->where('direction', $all['direction']);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (isset($all['keyword'])) {
|
|
|
|
|
$list = $list->where(function ($query) use ($all) {
|
|
|
|
|
$query->whereHas('courseContents', function ($query) use ($all) {
|
|
|
|
|
$query->where('direction', 'like', '%' . $all['keyword'] . '%');
|
|
|
|
|
})->orWhere('name', 'like', '%' . $all['keyword'] . '%');
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
// 无课程时也导出一行,课程相关列留空
|
|
|
|
|
$rows[] = [
|
|
|
|
|
'teacher_name' => $teacher->name ?? '',
|
|
|
|
|
'introduce' => $teacher->introduce ?? '',
|
|
|
|
|
'sex' => $teacher->sex ?? '',
|
|
|
|
|
'mobile' => $teacher->mobile ?? '',
|
|
|
|
|
'course_name' => '',
|
|
|
|
|
'theme' => '',
|
|
|
|
|
'direction' => '',
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 列映射与顺序
|
|
|
|
|
$exportFields = [
|
|
|
|
|
'teacher_name' => '授课老师',
|
|
|
|
|
'introduce' => '老师简介',
|
|
|
|
|
'sex' => '性别',
|
|
|
|
|
'mobile' => '联系方式',
|
|
|
|
|
'course_name' => '课程名称',
|
|
|
|
|
'theme' => '课程主题',
|
|
|
|
|
'direction' => '课程方向',
|
|
|
|
|
];
|
|
|
|
|
$fileName = ($all['file_name'] ?? '老师课程_') . date('YmdHis') . '.xlsx';
|
|
|
|
|
return Excel::download(new CommonExport($rows, $exportFields), $fileName);
|
|
|
|
|
} else {
|
|
|
|
|
// 输出
|
|
|
|
|
$list = $list->paginate($all['page_size'] ?? 20);
|
|
|
|
|
}
|
|
|
|
|
|