|
|
|
|
@ -896,62 +896,243 @@ class OtherController extends CommonController
|
|
|
|
|
case 'company_market_year_total':
|
|
|
|
|
// 今年上市公司明细 - 从stock_companys表获取,与coursesHome统计逻辑保持一致
|
|
|
|
|
$currentYear = date('Y');
|
|
|
|
|
$stockCompanies = StockCompany::whereYear('stock_date', $currentYear)->get();
|
|
|
|
|
$stockCompanies = StockCompany::with('company')->whereYear('stock_date', $currentYear)->get();
|
|
|
|
|
|
|
|
|
|
foreach ($stockCompanies as $stockCompany) {
|
|
|
|
|
// 通过公司名称关联到Company表获取详细信息
|
|
|
|
|
// 通过company_id关联到Company表获取详细信息
|
|
|
|
|
$company = $stockCompany->company_id ? $stockCompany->company : null;
|
|
|
|
|
if (!$company) {
|
|
|
|
|
// 如果没有company_id,尝试通过公司名称关联
|
|
|
|
|
$company = Company::where('company_name', $stockCompany->company_name)->first();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$data[] = [
|
|
|
|
|
// 公司基本信息(只在第一行使用)
|
|
|
|
|
$companyInfo = [
|
|
|
|
|
'company_name' => $stockCompany->company_name,
|
|
|
|
|
'company_legal_representative' => $company->company_legal_representative ?? '',
|
|
|
|
|
'company_date' => $company->company_date ?? '',
|
|
|
|
|
'stock_date' => $stockCompany->stock_date ?? '',
|
|
|
|
|
'is_after_enrollment' => $stockCompany->is_after_enrollment == 1 ? '是' : '否',
|
|
|
|
|
'company_address' => $company->company_address ?? '',
|
|
|
|
|
'company_city' => $company->company_city ?? '',
|
|
|
|
|
'company_area' => $company->company_area ?? '',
|
|
|
|
|
'company_tag' => $company->company_tag ?? '',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// 获取该公司的学员信息
|
|
|
|
|
if ($company) {
|
|
|
|
|
$users = $company->users()
|
|
|
|
|
->whereHas('courseSigns', function ($q) {
|
|
|
|
|
$q->where('status', 1);
|
|
|
|
|
})
|
|
|
|
|
->with([
|
|
|
|
|
'courseSigns' => function ($query) {
|
|
|
|
|
$query->where('status', 1)
|
|
|
|
|
->with(['course.typeDetail']);
|
|
|
|
|
}
|
|
|
|
|
])
|
|
|
|
|
->get();
|
|
|
|
|
|
|
|
|
|
if ($users->isEmpty()) {
|
|
|
|
|
// 如果没有学员,仍然导出公司基本信息
|
|
|
|
|
$data[] = array_merge($companyInfo, [
|
|
|
|
|
'user_name' => '',
|
|
|
|
|
'course_names' => '',
|
|
|
|
|
'course_types' => '',
|
|
|
|
|
'course_count' => 0,
|
|
|
|
|
]);
|
|
|
|
|
} else {
|
|
|
|
|
// 每个学员一行
|
|
|
|
|
$isFirstRow = true;
|
|
|
|
|
foreach ($users as $user) {
|
|
|
|
|
$courseSigns = $user->courseSigns ?? collect([]);
|
|
|
|
|
|
|
|
|
|
// 获取课程名称列表,用中文顿号分隔
|
|
|
|
|
$courseNames = $courseSigns->pluck('course.name')->filter()->unique()->values()->implode('、');
|
|
|
|
|
|
|
|
|
|
// 获取课程体系列表,用中文顿号分隔
|
|
|
|
|
$courseTypes = $courseSigns->pluck('course.typeDetail.name')
|
|
|
|
|
->filter()
|
|
|
|
|
->unique()
|
|
|
|
|
->values()
|
|
|
|
|
->implode('、');
|
|
|
|
|
|
|
|
|
|
// 报名课程数
|
|
|
|
|
$courseCount = $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' => '',
|
|
|
|
|
'stock_date' => '',
|
|
|
|
|
'is_after_enrollment' => '',
|
|
|
|
|
'company_address' => '',
|
|
|
|
|
'company_city' => '',
|
|
|
|
|
'company_area' => '',
|
|
|
|
|
'company_tag' => '',
|
|
|
|
|
'user_name' => $user->name ?? '',
|
|
|
|
|
'course_names' => $courseNames,
|
|
|
|
|
'course_types' => $courseTypes,
|
|
|
|
|
'course_count' => $courseCount,
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// 如果没有关联的公司,只导出基本信息
|
|
|
|
|
$data[] = array_merge($companyInfo, [
|
|
|
|
|
'user_name' => '',
|
|
|
|
|
'course_names' => '',
|
|
|
|
|
'course_types' => '',
|
|
|
|
|
'course_count' => 0,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$fields = [
|
|
|
|
|
'company_name' => '企业名称',
|
|
|
|
|
'company_legal_representative' => '法人',
|
|
|
|
|
'company_date' => '成立时间',
|
|
|
|
|
'stock_date' => '上市日期',
|
|
|
|
|
'is_after_enrollment' => '是否入学后上市',
|
|
|
|
|
'company_address' => '地址',
|
|
|
|
|
'company_city' => '所在城市',
|
|
|
|
|
'company_area' => '所在区域',
|
|
|
|
|
'company_tag' => '企业资质',
|
|
|
|
|
'user_name' => '学员姓名',
|
|
|
|
|
'course_names' => '课程名称',
|
|
|
|
|
'course_types' => '课程体系',
|
|
|
|
|
'course_count' => '报名课程数',
|
|
|
|
|
];
|
|
|
|
|
$filename = '今年上市公司明细';
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'company_market_after_enrollment_total':
|
|
|
|
|
// 入学后上市公司明细 - 从stock_companys表获取,与coursesHome统计逻辑保持一致
|
|
|
|
|
$stockCompanies = StockCompany::where('is_after_enrollment', 1)->get();
|
|
|
|
|
$stockCompanies = StockCompany::with('company')->where('is_after_enrollment', 1)->get();
|
|
|
|
|
|
|
|
|
|
foreach ($stockCompanies as $stockCompany) {
|
|
|
|
|
// 通过公司名称关联到Company表获取详细信息
|
|
|
|
|
// 通过company_id关联到Company表获取详细信息
|
|
|
|
|
$company = $stockCompany->company_id ? $stockCompany->company : null;
|
|
|
|
|
if (!$company) {
|
|
|
|
|
// 如果没有company_id,尝试通过公司名称关联
|
|
|
|
|
$company = Company::where('company_name', $stockCompany->company_name)->first();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$data[] = [
|
|
|
|
|
// 公司基本信息(只在第一行使用)
|
|
|
|
|
$companyInfo = [
|
|
|
|
|
'company_name' => $stockCompany->company_name,
|
|
|
|
|
'company_legal_representative' => $company->company_legal_representative ?? '',
|
|
|
|
|
'company_date' => $company->company_date ?? '',
|
|
|
|
|
'stock_date' => $stockCompany->stock_date ?? '',
|
|
|
|
|
'enrollment_date' => $stockCompany->enrollment_date ?? '',
|
|
|
|
|
'is_after_enrollment' => $stockCompany->is_after_enrollment == 1 ? '是' : '否',
|
|
|
|
|
'company_address' => $company->company_address ?? '',
|
|
|
|
|
'company_city' => $company->company_city ?? '',
|
|
|
|
|
'company_area' => $company->company_area ?? '',
|
|
|
|
|
'company_tag' => $company->company_tag ?? '',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// 获取该公司的学员信息
|
|
|
|
|
if ($company) {
|
|
|
|
|
$users = $company->users()
|
|
|
|
|
->whereHas('courseSigns', function ($q) {
|
|
|
|
|
$q->where('status', 1);
|
|
|
|
|
})
|
|
|
|
|
->with([
|
|
|
|
|
'courseSigns' => function ($query) {
|
|
|
|
|
$query->where('status', 1)
|
|
|
|
|
->with(['course.typeDetail']);
|
|
|
|
|
}
|
|
|
|
|
])
|
|
|
|
|
->get();
|
|
|
|
|
|
|
|
|
|
if ($users->isEmpty()) {
|
|
|
|
|
// 如果没有学员,仍然导出公司基本信息
|
|
|
|
|
$data[] = array_merge($companyInfo, [
|
|
|
|
|
'user_name' => '',
|
|
|
|
|
'course_names' => '',
|
|
|
|
|
'course_types' => '',
|
|
|
|
|
'course_count' => 0,
|
|
|
|
|
]);
|
|
|
|
|
} else {
|
|
|
|
|
// 每个学员一行
|
|
|
|
|
$isFirstRow = true;
|
|
|
|
|
foreach ($users as $user) {
|
|
|
|
|
$courseSigns = $user->courseSigns ?? collect([]);
|
|
|
|
|
|
|
|
|
|
// 获取课程名称列表,用中文顿号分隔
|
|
|
|
|
$courseNames = $courseSigns->pluck('course.name')->filter()->unique()->values()->implode('、');
|
|
|
|
|
|
|
|
|
|
// 获取课程体系列表,用中文顿号分隔
|
|
|
|
|
$courseTypes = $courseSigns->pluck('course.typeDetail.name')
|
|
|
|
|
->filter()
|
|
|
|
|
->unique()
|
|
|
|
|
->values()
|
|
|
|
|
->implode('、');
|
|
|
|
|
|
|
|
|
|
// 报名课程数
|
|
|
|
|
$courseCount = $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' => '',
|
|
|
|
|
'stock_date' => '',
|
|
|
|
|
'enrollment_date' => '',
|
|
|
|
|
'is_after_enrollment' => '',
|
|
|
|
|
'company_address' => '',
|
|
|
|
|
'company_city' => '',
|
|
|
|
|
'company_area' => '',
|
|
|
|
|
'company_tag' => '',
|
|
|
|
|
'user_name' => $user->name ?? '',
|
|
|
|
|
'course_names' => $courseNames,
|
|
|
|
|
'course_types' => $courseTypes,
|
|
|
|
|
'course_count' => $courseCount,
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// 如果没有关联的公司,只导出基本信息
|
|
|
|
|
$data[] = array_merge($companyInfo, [
|
|
|
|
|
'user_name' => '',
|
|
|
|
|
'course_names' => '',
|
|
|
|
|
'course_types' => '',
|
|
|
|
|
'course_count' => 0,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$fields = [
|
|
|
|
|
'company_name' => '企业名称',
|
|
|
|
|
'company_legal_representative' => '法人',
|
|
|
|
|
'company_date' => '成立时间',
|
|
|
|
|
'stock_date' => '上市日期',
|
|
|
|
|
'enrollment_date' => '入学时间',
|
|
|
|
|
'is_after_enrollment' => '是否入学后上市',
|
|
|
|
|
'company_address' => '地址',
|
|
|
|
|
'company_city' => '所在城市',
|
|
|
|
|
'company_area' => '所在区域',
|
|
|
|
|
'company_tag' => '企业资质',
|
|
|
|
|
'user_name' => '学员姓名',
|
|
|
|
|
'course_names' => '课程名称',
|
|
|
|
|
'course_types' => '课程体系',
|
|
|
|
|
'course_count' => '报名课程数',
|
|
|
|
|
];
|
|
|
|
|
$filename = '入学后上市公司明细';
|
|
|
|
|
break;
|
|
|
|
|
|