master
cody 3 months ago
parent cd07a34823
commit 3dce1e17d6

@ -17,6 +17,7 @@ use App\Models\CourseTypeDataOverviewConfig;
use App\Models\CustomFormField;
use App\Models\Department;
use App\Models\HistoryCourse;
use App\Models\EmployeeParticipation;
use App\Models\ParameterDetail;
use App\Models\StockCompany;
use App\Models\SupplyDemand;
@ -671,6 +672,9 @@ class OtherController extends CommonController
$users = CourseSign::courseSignsTotalByUnique($start_date, $end_date, 1, $course_ids, true);
// 预加载 company 关系,避免 N+1 查询问题
$users->load('company');
// 当前课程数据(已去重)
$currentData = [];
foreach ($users as $user) {
// 获取该学员报名的课程列表 - 使用与getStudentList完全一致的逻辑
$userCourseSigns = CourseSign::where(function ($query) use ($course_ids) {
@ -721,7 +725,7 @@ class OtherController extends CommonController
? $user->company->company_industry
: ($user->company_industry ?? '');
$data[] = [
$currentData[] = [
'user_name' => $user->name ?? '',
'mobile' => $user->mobile ?? '',
'qcc_company_name' => $qccCompanyName,
@ -734,7 +738,7 @@ class OtherController extends CommonController
'course_count' => $userCourseSigns->count(),
];
}
$fields = [
$currentFields = [
'user_name' => '学员姓名',
'mobile' => '手机号',
'qcc_company_name' => '企查查企业',
@ -746,7 +750,59 @@ class OtherController extends CommonController
'course_names' => '报名课程',
'course_count' => '报名课程数',
];
// 历史课程数据
$historyData = [];
$course_type_id_array = $course_type_id ? (is_array($course_type_id) ? $course_type_id : explode(',', $course_type_id)) : [];
$historyCourses = HistoryCourse::whereHas('calendar', function ($query) {
$query->where('is_count_people', 1);
})->whereHas('typeDetail', function ($query) {
$query->where('is_history', 1);
})->where(function ($query) use ($start_date, $end_date) {
if ($start_date && $end_date) {
$query->whereBetween('start_time', [$start_date, $end_date])
->orWhereBetween('end_time', [$start_date, $end_date]);
}
})->where(function ($query) use ($course_type_id_array) {
if (!empty($course_type_id_array)) {
$query->whereIn('type', $course_type_id_array);
}
})->with('typeDetail')->get();
foreach ($historyCourses as $historyCourse) {
$historyData[] = [
'course_type' => $historyCourse->typeDetail->name ?? '',
'course_name' => $historyCourse->course_name ?? '',
'start_time' => $historyCourse->start_time ?? '',
'end_time' => $historyCourse->end_time ?? '',
'course_type_signs_pass' => $historyCourse->course_type_signs_pass ?? 0,
'course_type_signs_pass_unique' => $historyCourse->course_type_signs_pass_unique ?? 0,
'course_signs_pass' => $historyCourse->course_signs_pass ?? 0,
];
}
$historyFields = [
'course_type' => '课程体系',
'course_name' => '课程名称',
'start_time' => '开始时间',
'end_time' => '结束时间',
'course_type_signs_pass' => '培养人数未去重',
'course_type_signs_pass_unique' => '培养人数去重',
'course_signs_pass' => '课程培养人数',
];
// 创建多 sheet 导出
$sheets = [
new SheetExport($currentData, $currentFields, '当前课程数据'),
new SheetExport($historyData, $historyFields, '历史课程数据'),
];
$filename = '审核通过人数去重明细';
// 直接返回多 sheet 导出
return Excel::download(
new MultiSheetExport($sheets),
$filename . '_' . date('YmdHis') . '.xlsx'
);
break;
case 'courseTypesSum':
@ -1483,8 +1539,11 @@ class OtherController extends CommonController
case 'company_ganbu_total':
// 全市干部参与企业明细 - 使用模型方法
$users = CourseSign::ganbu($start_date, $end_date, $course_ids, true);
// 当前学员数据
$currentData = [];
foreach ($users as $user) {
$data[] = [
$currentData[] = [
'user_name' => $user->name ?? '',
'mobile' => $user->mobile ?? '',
'company_name' => $user->company->company_name ?? '',
@ -1493,7 +1552,7 @@ class OtherController extends CommonController
'company_position' => $user->company_position ?? '',
];
}
$fields = [
$currentFields = [
'user_name' => '学员姓名',
'mobile' => '手机号',
'company_name' => '企业名称',
@ -1501,7 +1560,47 @@ class OtherController extends CommonController
'company_city' => '所在城市',
'company_position' => '职位',
];
// 自定义数据EmployeeParticipation type=2 干部培训数)
$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', 2)->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 = '全市干部参与企业明细';
// 直接返回多 sheet 导出
return Excel::download(
new MultiSheetExport($sheets),
$filename . '_' . date('YmdHis') . '.xlsx'
);
break;
case 'cover_head_total':

Loading…
Cancel
Save