|
|
|
|
@ -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;
|
|
|
|
|
@ -32,6 +33,8 @@ use EasyWeChat\Factory;
|
|
|
|
|
use Illuminate\Filesystem\Filesystem;
|
|
|
|
|
use Maatwebsite\Excel\Facades\Excel;
|
|
|
|
|
use App\Exports\CommonExport;
|
|
|
|
|
use App\Exports\MultiSheetExport;
|
|
|
|
|
use App\Exports\SheetExport;
|
|
|
|
|
|
|
|
|
|
class OtherController extends CommonController
|
|
|
|
|
{
|
|
|
|
|
@ -312,7 +315,6 @@ class OtherController extends CommonController
|
|
|
|
|
|
|
|
|
|
// 上市公司数(所有上市公司)
|
|
|
|
|
$list['company_market_total'] = CourseSign::shangshi($start_date, $end_date, $course_ids);
|
|
|
|
|
|
|
|
|
|
// 跟班学员数(在指定时间范围内报名的学员中,from为'跟班学员'的数量)
|
|
|
|
|
$list['ganbu_total'] = CourseSign::genban($start_date, $end_date, $course_ids);
|
|
|
|
|
|
|
|
|
|
@ -338,10 +340,10 @@ class OtherController extends CommonController
|
|
|
|
|
$list['company_ganbu_total'] = CourseSign::ganbu($start_date, $end_date, $course_ids);
|
|
|
|
|
// 苏州头部企业
|
|
|
|
|
$list['cover_head_total'] = CourseSign::toubuqiye($start_date, $end_date, $course_ids);
|
|
|
|
|
// 高层次人才
|
|
|
|
|
// 苏州高层次人才
|
|
|
|
|
$list['cover_rencai_total'] = CourseSign::rencai($start_date, $end_date, $course_ids);
|
|
|
|
|
// 重点上市公司
|
|
|
|
|
$list['cover_stock_total'] = CourseSign::shangshi($start_date, $end_date, $course_ids);
|
|
|
|
|
// 苏州重点上市公司
|
|
|
|
|
$list['cover_stock_total'] = CourseSign::suzhoushangshi($start_date, $end_date, $course_ids);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 课程分类明细统计
|
|
|
|
|
@ -462,12 +464,27 @@ class OtherController extends CommonController
|
|
|
|
|
// 直接通过公司ID查询学员
|
|
|
|
|
$userIds = User::where('company_id', $company->id)->pluck('id')->toArray();
|
|
|
|
|
|
|
|
|
|
// 公司基本信息
|
|
|
|
|
$companyInfo = [
|
|
|
|
|
'company_name' => $company->company_name,
|
|
|
|
|
'company_legal_representative' => $company->company_legal_representative ?? '',
|
|
|
|
|
'company_date' => $company->company_date ?? '',
|
|
|
|
|
'company_address' => $company->company_address ?? '',
|
|
|
|
|
'business_scope' => $company->business_scope ?? '',
|
|
|
|
|
'contact_phone' => $company->contact_phone ?? '',
|
|
|
|
|
'contact_mail' => $company->contact_mail ?? '',
|
|
|
|
|
'company_tag' => $company->company_tag ?? '',
|
|
|
|
|
// 'credit_code' => ($company->credit_code ? ' ' . $company->credit_code : ''),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
if (empty($userIds)) {
|
|
|
|
|
// 如果没有学员,设置空值
|
|
|
|
|
$userNamesStr = '';
|
|
|
|
|
$courseNamesStr = '';
|
|
|
|
|
$courseTypesStr = '';
|
|
|
|
|
$totalCourseCount = 0;
|
|
|
|
|
// 如果没有学员,仍然导出公司基本信息
|
|
|
|
|
$data[] = array_merge($companyInfo, [
|
|
|
|
|
'user_name' => '',
|
|
|
|
|
'course_names' => '',
|
|
|
|
|
'course_types' => '',
|
|
|
|
|
'course_count' => 0,
|
|
|
|
|
]);
|
|
|
|
|
} else {
|
|
|
|
|
$userCourseSigns = CourseSign::getStudentList(CourseType::START_DATE, $end_date, 1, $courseIdsArray)
|
|
|
|
|
->whereIn('user_id', $userIds)
|
|
|
|
|
@ -490,57 +507,56 @@ class OtherController extends CommonController
|
|
|
|
|
$usersData[$userId]['courseSigns'][] = $sign;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 收集所有学员的姓名、课程名称、课程体系
|
|
|
|
|
$userNames = [];
|
|
|
|
|
$allCourseNames = [];
|
|
|
|
|
$allCourseTypes = [];
|
|
|
|
|
$totalCourseCount = 0;
|
|
|
|
|
|
|
|
|
|
// 每个学员一行,公司信息只在第一行显示,后续行公司信息为空
|
|
|
|
|
$isFirstRow = true;
|
|
|
|
|
foreach ($usersData as $userData) {
|
|
|
|
|
$user = $userData['user'];
|
|
|
|
|
$courseSigns = collect($userData['courseSigns']);
|
|
|
|
|
|
|
|
|
|
if ($courseSigns->isNotEmpty()) {
|
|
|
|
|
$userNames[] = $user->name ?? '';
|
|
|
|
|
|
|
|
|
|
// 收集课程名称
|
|
|
|
|
$courseNames = $courseSigns->pluck('course.name')->filter()->unique()->values()->toArray();
|
|
|
|
|
$allCourseNames = array_merge($allCourseNames, $courseNames);
|
|
|
|
|
// 获取课程名称列表,用中文顿号分隔
|
|
|
|
|
$courseNames = $courseSigns->pluck('course.name')->filter()->unique()->values()->implode('、');
|
|
|
|
|
|
|
|
|
|
// 收集课程体系
|
|
|
|
|
// 获取课程体系列表,用中文顿号分隔
|
|
|
|
|
$courseTypes = $courseSigns->pluck('course.typeDetail.name')
|
|
|
|
|
->filter()
|
|
|
|
|
->unique()
|
|
|
|
|
->values()
|
|
|
|
|
->toArray();
|
|
|
|
|
$allCourseTypes = array_merge($allCourseTypes, $courseTypes);
|
|
|
|
|
->implode('、');
|
|
|
|
|
|
|
|
|
|
// 报名课程数
|
|
|
|
|
$courseCount = $courseSigns->count();
|
|
|
|
|
|
|
|
|
|
// 累计报名课程数
|
|
|
|
|
$totalCourseCount += $courseSigns->count();
|
|
|
|
|
if ($isFirstRow) {
|
|
|
|
|
// 第一行:显示公司信息
|
|
|
|
|
$data[] = array_merge($companyInfo, [
|
|
|
|
|
'user_name' => $user->name ?? '',
|
|
|
|
|
'course_names' => $courseNames,
|
|
|
|
|
'course_types' => $courseTypes,
|
|
|
|
|
'course_count' => $courseCount,
|
|
|
|
|
]);
|
|
|
|
|
$isFirstRow = false;
|
|
|
|
|
} else {
|
|
|
|
|
// 后续行:公司信息为空
|
|
|
|
|
$data[] = [
|
|
|
|
|
'company_name' => '',
|
|
|
|
|
'company_legal_representative' => '',
|
|
|
|
|
'company_date' => '',
|
|
|
|
|
'company_address' => '',
|
|
|
|
|
'business_scope' => '',
|
|
|
|
|
'contact_phone' => '',
|
|
|
|
|
'contact_mail' => '',
|
|
|
|
|
'company_tag' => '',
|
|
|
|
|
'credit_code' => '',
|
|
|
|
|
'user_name' => $user->name ?? '',
|
|
|
|
|
'course_names' => $courseNames,
|
|
|
|
|
'course_types' => $courseTypes,
|
|
|
|
|
'course_count' => $courseCount,
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 去重并合并
|
|
|
|
|
$userNamesStr = implode('、', array_filter(array_unique($userNames)));
|
|
|
|
|
$courseNamesStr = implode('、', array_filter(array_unique($allCourseNames)));
|
|
|
|
|
$courseTypesStr = implode('、', array_filter(array_unique($allCourseTypes)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$data[] = [
|
|
|
|
|
'company_name' => $company->company_name,
|
|
|
|
|
'company_legal_representative' => $company->company_legal_representative ?? '',
|
|
|
|
|
'company_date' => $company->company_date ?? '',
|
|
|
|
|
'company_address' => $company->company_address ?? '',
|
|
|
|
|
'business_scope' => $company->business_scope ?? '',
|
|
|
|
|
'contact_phone' => $company->contact_phone ?? '',
|
|
|
|
|
'contact_mail' => $company->contact_mail ?? '',
|
|
|
|
|
'company_tag' => $company->company_tag ?? '',
|
|
|
|
|
'credit_code' => ' ' . $company->credit_code ?? '',
|
|
|
|
|
'user_names' => $userNamesStr,
|
|
|
|
|
'course_names' => $courseNamesStr,
|
|
|
|
|
'course_types' => $courseTypesStr,
|
|
|
|
|
'course_count' => $totalCourseCount,
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
$fields = [
|
|
|
|
|
'company_name' => '企业名称',
|
|
|
|
|
@ -551,8 +567,8 @@ class OtherController extends CommonController
|
|
|
|
|
'contact_phone' => '联系电话',
|
|
|
|
|
'contact_mail' => '联系邮箱',
|
|
|
|
|
'company_tag' => '企业资质',
|
|
|
|
|
'credit_code' => '统一社会信用代码',
|
|
|
|
|
'user_names' => '学员姓名',
|
|
|
|
|
// 'credit_code' => '统一社会信用代码',
|
|
|
|
|
'user_name' => '学员姓名',
|
|
|
|
|
'course_names' => '课程名称',
|
|
|
|
|
'course_types' => '课程体系',
|
|
|
|
|
'course_count' => '报名课程数',
|
|
|
|
|
@ -593,10 +609,12 @@ class OtherController extends CommonController
|
|
|
|
|
// 审核通过人数明细 - 使用courseSignsTotal方法获取列表(与coursesHome算法一致)
|
|
|
|
|
$courseSigns = CourseSign::courseSignsTotal($start_date, $end_date, 1, $course_ids, true);
|
|
|
|
|
// 加载关联关系
|
|
|
|
|
$courseSigns->load(['user', 'course']);
|
|
|
|
|
$courseSigns->load(['user.company', 'course.typeDetail']);
|
|
|
|
|
|
|
|
|
|
// 当前课程数据
|
|
|
|
|
$currentData = [];
|
|
|
|
|
foreach ($courseSigns as $sign) {
|
|
|
|
|
$data[] = [
|
|
|
|
|
$currentData[] = [
|
|
|
|
|
'user_name' => $sign->user->name ?? '',
|
|
|
|
|
'mobile' => $sign->user->mobile ?? '',
|
|
|
|
|
'company_name' => $sign->user->company->company_name ?? '',
|
|
|
|
|
@ -604,19 +622,70 @@ class OtherController extends CommonController
|
|
|
|
|
'company_industry' => $sign->user->company->company_industry ?? '',
|
|
|
|
|
'course_name' => $sign->course->name ?? '',
|
|
|
|
|
'course_type' => $sign->course->typeDetail->name ?? '',
|
|
|
|
|
// 'created_at' => $sign->created_at ? $sign->created_at->format('Y-m-d H:i:s') : '',
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
$fields = [
|
|
|
|
|
$currentFields = [
|
|
|
|
|
'user_name' => '学员姓名',
|
|
|
|
|
'mobile' => '手机号',
|
|
|
|
|
'company_name' => '企业名称',
|
|
|
|
|
'company_area' => '所在区域',
|
|
|
|
|
'company_industry' => '所在行业',
|
|
|
|
|
'course_name' => '课程名称',
|
|
|
|
|
'course_type' => '课程类型',
|
|
|
|
|
// 'created_at' => '报名时间',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// 历史课程数据
|
|
|
|
|
$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 'course_signs_pass_unique':
|
|
|
|
|
@ -624,6 +693,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) {
|
|
|
|
|
@ -674,7 +746,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,
|
|
|
|
|
@ -687,7 +759,7 @@ class OtherController extends CommonController
|
|
|
|
|
'course_count' => $userCourseSigns->count(),
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
$fields = [
|
|
|
|
|
$currentFields = [
|
|
|
|
|
'user_name' => '学员姓名',
|
|
|
|
|
'mobile' => '手机号',
|
|
|
|
|
'qcc_company_name' => '企查查企业',
|
|
|
|
|
@ -699,7 +771,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':
|
|
|
|
|
@ -802,21 +926,30 @@ class OtherController extends CommonController
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'company_market_total':
|
|
|
|
|
// 上市公司明细 - 所有上市公司,关联学员、课程信息
|
|
|
|
|
// 数据结构:主表是公司,子数据是学员信息
|
|
|
|
|
// 导出时:公司信息只在第一行显示,后续行公司信息为空
|
|
|
|
|
$companiesData = CourseSign::shangshi($start_date, $end_date, $course_ids->toArray(), true);
|
|
|
|
|
// 上市公司明细 - 与coursesHome统计逻辑保持一致
|
|
|
|
|
// 使用CourseSign::shangshi方法获取数据,确保与统计逻辑一致
|
|
|
|
|
$shangshiList = CourseSign::shangshi($start_date, $end_date, $course_ids, true);
|
|
|
|
|
|
|
|
|
|
foreach ($companiesData as $item) {
|
|
|
|
|
$company = $item['company'];
|
|
|
|
|
foreach ($shangshiList as $item) {
|
|
|
|
|
$company = $item['company'] ?? null;
|
|
|
|
|
$users = $item['users'] ?? [];
|
|
|
|
|
|
|
|
|
|
// 公司基本信息(只在第一行使用)
|
|
|
|
|
if (!$company) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取StockCompany信息(如果有)
|
|
|
|
|
$stockCompany = StockCompany::where('company_id', $company->id)
|
|
|
|
|
->orWhere('company_name', $company->company_name)
|
|
|
|
|
->first();
|
|
|
|
|
|
|
|
|
|
// 公司基本信息
|
|
|
|
|
$companyInfo = [
|
|
|
|
|
'company_name' => $company->company_name,
|
|
|
|
|
'company_name' => $company->company_name ?? '',
|
|
|
|
|
'company_legal_representative' => $company->company_legal_representative ?? '',
|
|
|
|
|
'company_date' => $company->company_date ?? '',
|
|
|
|
|
'stock_date' => $company->stock_date ?? '',
|
|
|
|
|
'stock_date' => $stockCompany->stock_date ?? '',
|
|
|
|
|
'is_after_enrollment' => $stockCompany && $stockCompany->is_after_enrollment == 1 ? '是' : '否',
|
|
|
|
|
'company_address' => $company->company_address ?? '',
|
|
|
|
|
'company_city' => $company->company_city ?? '',
|
|
|
|
|
'company_area' => $company->company_area ?? '',
|
|
|
|
|
@ -824,40 +957,29 @@ class OtherController extends CommonController
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
if (empty($users)) {
|
|
|
|
|
// 如果没有学员报名记录,仍然导出公司基本信息
|
|
|
|
|
// 如果没有学员,仍然导出公司基本信息
|
|
|
|
|
$data[] = array_merge($companyInfo, [
|
|
|
|
|
'user_name' => '',
|
|
|
|
|
'course_name' => '',
|
|
|
|
|
'course_type' => '',
|
|
|
|
|
'course_names' => '',
|
|
|
|
|
'course_types' => '',
|
|
|
|
|
'course_count' => 0,
|
|
|
|
|
]);
|
|
|
|
|
} else {
|
|
|
|
|
// 每个学员一行,多个课程合并显示
|
|
|
|
|
// 每个学员一行,公司信息只在第一行显示,后续行公司信息为空
|
|
|
|
|
$isFirstRow = true;
|
|
|
|
|
foreach ($users as $userInfo) {
|
|
|
|
|
$courses = $userInfo['courses'] ?? [];
|
|
|
|
|
foreach ($users as $userData) {
|
|
|
|
|
$user = $userData['user'] ?? null;
|
|
|
|
|
$courses = $userData['courses'] ?? [];
|
|
|
|
|
|
|
|
|
|
// 合并同一学员的多个课程:格式为"课程体系-课程名称,课程体系-课程名称"
|
|
|
|
|
$courseList = [];
|
|
|
|
|
foreach ($courses as $courseInfo) {
|
|
|
|
|
$courseType = $courseInfo['course_type'] ?? '';
|
|
|
|
|
$courseName = $courseInfo['course_name'] ?? '';
|
|
|
|
|
if ($courseType && $courseName) {
|
|
|
|
|
$courseList[] = $courseType . '-' . $courseName;
|
|
|
|
|
} elseif ($courseName) {
|
|
|
|
|
$courseList[] = $courseName;
|
|
|
|
|
}
|
|
|
|
|
if (!$user) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
$courseDisplay = implode("\r\n", $courseList);
|
|
|
|
|
|
|
|
|
|
// 获取课程名称列表,用中文顿号分隔
|
|
|
|
|
$courseNames = collect($courses)->pluck('course_name')->filter()->unique()->values()->implode('、');
|
|
|
|
|
|
|
|
|
|
// 获取课程体系列表,用中文顿号分隔
|
|
|
|
|
$courseTypes = collect($courses)
|
|
|
|
|
->pluck('course_type')
|
|
|
|
|
->filter()
|
|
|
|
|
->unique()
|
|
|
|
|
->values()
|
|
|
|
|
->implode('、');
|
|
|
|
|
$courseTypes = collect($courses)->pluck('course_type')->filter()->unique()->values()->implode('、');
|
|
|
|
|
|
|
|
|
|
// 报名课程数
|
|
|
|
|
$courseCount = count($courses);
|
|
|
|
|
@ -865,9 +987,8 @@ class OtherController extends CommonController
|
|
|
|
|
if ($isFirstRow) {
|
|
|
|
|
// 第一行:显示公司信息
|
|
|
|
|
$data[] = array_merge($companyInfo, [
|
|
|
|
|
'user_name' => $userInfo['user_name'] ?? '',
|
|
|
|
|
'course_name' => $courseDisplay,
|
|
|
|
|
'course_type' => '', // 课程类型已合并到课程名称中
|
|
|
|
|
'user_name' => $userData['user_name'] ?? $user->name ?? '',
|
|
|
|
|
'course_names' => $courseNames,
|
|
|
|
|
'course_types' => $courseTypes,
|
|
|
|
|
'course_count' => $courseCount,
|
|
|
|
|
]);
|
|
|
|
|
@ -879,12 +1000,13 @@ class OtherController extends CommonController
|
|
|
|
|
'company_legal_representative' => '',
|
|
|
|
|
'company_date' => '',
|
|
|
|
|
'stock_date' => '',
|
|
|
|
|
'is_after_enrollment' => '',
|
|
|
|
|
'company_address' => '',
|
|
|
|
|
'company_city' => '',
|
|
|
|
|
'company_area' => '',
|
|
|
|
|
'company_tag' => '',
|
|
|
|
|
'user_name' => $userInfo['user_name'] ?? '',
|
|
|
|
|
'course_name' => $courseDisplay,
|
|
|
|
|
'user_name' => $userData['user_name'] ?? $user->name ?? '',
|
|
|
|
|
'course_names' => $courseNames,
|
|
|
|
|
'course_types' => $courseTypes,
|
|
|
|
|
'course_count' => $courseCount,
|
|
|
|
|
];
|
|
|
|
|
@ -897,12 +1019,13 @@ class OtherController extends CommonController
|
|
|
|
|
'company_legal_representative' => '法人',
|
|
|
|
|
'company_date' => '成立时间',
|
|
|
|
|
'stock_date' => '上市日期',
|
|
|
|
|
'is_after_enrollment' => '是否入学后上市',
|
|
|
|
|
'company_address' => '地址',
|
|
|
|
|
'company_city' => '所在城市',
|
|
|
|
|
'company_area' => '所在区域',
|
|
|
|
|
'company_tag' => '企业资质',
|
|
|
|
|
'user_name' => '学员姓名',
|
|
|
|
|
'course_name' => '课程信息',
|
|
|
|
|
'course_names' => '课程名称',
|
|
|
|
|
'course_types' => '课程体系',
|
|
|
|
|
'course_count' => '报名课程数',
|
|
|
|
|
];
|
|
|
|
|
@ -1232,7 +1355,7 @@ class OtherController extends CommonController
|
|
|
|
|
'company_legal_representative' => $company->company_legal_representative ?? '',
|
|
|
|
|
'company_date' => $company->company_date ?? '',
|
|
|
|
|
'invest_date' => $item['invest_date'] ?? '',
|
|
|
|
|
'first_sign_date' => $item['first_sign_date'],
|
|
|
|
|
'first_sign_date' => $item['first_enrollment_date'] ?? '',
|
|
|
|
|
'user_names' => $userNames,
|
|
|
|
|
'company_address' => $company->company_address ?? '',
|
|
|
|
|
'company_city' => $company->company_city ?? '',
|
|
|
|
|
@ -1402,6 +1525,9 @@ class OtherController extends CommonController
|
|
|
|
|
$users = CourseSign::companyJoin($start_date, $end_date, $course_ids, true, true);
|
|
|
|
|
// 加载关联关系
|
|
|
|
|
$users->load('company');
|
|
|
|
|
|
|
|
|
|
// 当前学员数据
|
|
|
|
|
$currentData = [];
|
|
|
|
|
foreach ($users as $user) {
|
|
|
|
|
// 获取该学员的课程报名记录
|
|
|
|
|
// 使用与 companyJoin 方法完全相同的 getStudentList 逻辑,确保数据一致
|
|
|
|
|
@ -1423,7 +1549,7 @@ class OtherController extends CommonController
|
|
|
|
|
// 报名课程数
|
|
|
|
|
$courseCount = $userCourseSigns->count();
|
|
|
|
|
|
|
|
|
|
$data[] = [
|
|
|
|
|
$currentData[] = [
|
|
|
|
|
'user_name' => $user->name ?? '',
|
|
|
|
|
'mobile' => $user->mobile ?? '',
|
|
|
|
|
'company_name' => $user->company->company_name ?? $user->company_name,
|
|
|
|
|
@ -1438,7 +1564,7 @@ class OtherController extends CommonController
|
|
|
|
|
'course_count' => $courseCount,
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
$fields = [
|
|
|
|
|
$currentFields = [
|
|
|
|
|
'user_name' => '学员姓名',
|
|
|
|
|
'mobile' => '手机号',
|
|
|
|
|
'company_name' => '企业名称',
|
|
|
|
|
@ -1452,14 +1578,57 @@ class OtherController extends CommonController
|
|
|
|
|
'course_types' => '课程体系',
|
|
|
|
|
'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 = '元和员工参与企业明细';
|
|
|
|
|
|
|
|
|
|
// 直接返回多 sheet 导出
|
|
|
|
|
return Excel::download(
|
|
|
|
|
new MultiSheetExport($sheets),
|
|
|
|
|
$filename . '_' . date('YmdHis') . '.xlsx'
|
|
|
|
|
);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
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 ?? '',
|
|
|
|
|
@ -1468,7 +1637,7 @@ class OtherController extends CommonController
|
|
|
|
|
'company_position' => $user->company_position ?? '',
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
$fields = [
|
|
|
|
|
$currentFields = [
|
|
|
|
|
'user_name' => '学员姓名',
|
|
|
|
|
'mobile' => '手机号',
|
|
|
|
|
'company_name' => '企业名称',
|
|
|
|
|
@ -1476,7 +1645,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':
|
|
|
|
|
@ -1701,8 +1910,8 @@ class OtherController extends CommonController
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'cover_stock_total':
|
|
|
|
|
// 重点上市公司明细 - 使用模型方法
|
|
|
|
|
$companiesData = CourseSign::shangshi($start_date, $end_date, $course_ids, true);
|
|
|
|
|
// 重点上市公司明细 - 使用模型方法,与统计逻辑保持一致
|
|
|
|
|
$companiesData = CourseSign::suzhoushangshi($start_date, $end_date, $course_ids, true);
|
|
|
|
|
foreach ($companiesData as $item) {
|
|
|
|
|
$company = $item['company'];
|
|
|
|
|
$users = $item['users'] ?? [];
|
|
|
|
|
|