master
cody 3 months ago
parent 3dce1e17d6
commit 85b2ae9960

@ -1483,6 +1483,9 @@ class OtherController extends CommonController
$users = CourseSign::companyJoin($start_date, $end_date, $course_ids, true, true); $users = CourseSign::companyJoin($start_date, $end_date, $course_ids, true, true);
// 加载关联关系 // 加载关联关系
$users->load('company'); $users->load('company');
// 当前学员数据
$currentData = [];
foreach ($users as $user) { foreach ($users as $user) {
// 获取该学员的课程报名记录 // 获取该学员的课程报名记录
// 使用与 companyJoin 方法完全相同的 getStudentList 逻辑,确保数据一致 // 使用与 companyJoin 方法完全相同的 getStudentList 逻辑,确保数据一致
@ -1504,7 +1507,7 @@ class OtherController extends CommonController
// 报名课程数 // 报名课程数
$courseCount = $userCourseSigns->count(); $courseCount = $userCourseSigns->count();
$data[] = [ $currentData[] = [
'user_name' => $user->name ?? '', 'user_name' => $user->name ?? '',
'mobile' => $user->mobile ?? '', 'mobile' => $user->mobile ?? '',
'company_name' => $user->company->company_name ?? $user->company_name, 'company_name' => $user->company->company_name ?? $user->company_name,
@ -1519,7 +1522,7 @@ class OtherController extends CommonController
'course_count' => $courseCount, 'course_count' => $courseCount,
]; ];
} }
$fields = [ $currentFields = [
'user_name' => '学员姓名', 'user_name' => '学员姓名',
'mobile' => '手机号', 'mobile' => '手机号',
'company_name' => '企业名称', 'company_name' => '企业名称',
@ -1533,7 +1536,47 @@ class OtherController extends CommonController
'course_types' => '课程体系', 'course_types' => '课程体系',
'course_count' => '报名课程数', 'course_count' => '报名课程数',
]; ];
// 自定义数据EmployeeParticipation type=1 员工参与数)
$customData = [];
$employeeParticipations = EmployeeParticipation::where(function ($query) use ($start_date, $end_date) {
// 开始结束日期的筛选。or查询
if ($start_date && $end_date) {
$query->whereBetween('start_date', [$start_date, $end_date])
->orWhereBetween('end_date', [$start_date, $end_date]);
}
})->where('type', 1)->with('courseType')->get();
foreach ($employeeParticipations as $participation) {
$customData[] = [
'course_type' => $participation->courseType->name ?? '',
'course_name' => $participation->course_name ?? '',
'start_date' => $participation->start_date ?? '',
'end_date' => $participation->end_date ?? '',
'total' => $participation->total ?? 0,
];
}
$customFields = [
'course_type' => '课程体系',
'course_name' => '课程名称',
'start_date' => '开始日期',
'end_date' => '结束日期',
'total' => '参与数量',
];
// 创建多 sheet 导出
$sheets = [
new SheetExport($currentData, $currentFields, '学员数据'),
new SheetExport($customData, $customFields, '自定义数据'),
];
$filename = '元和员工参与企业明细'; $filename = '元和员工参与企业明细';
// 直接返回多 sheet 导出
return Excel::download(
new MultiSheetExport($sheets),
$filename . '_' . date('YmdHis') . '.xlsx'
);
break; break;
case 'company_ganbu_total': case 'company_ganbu_total':

Loading…
Cancel
Save