|
|
|
|
@ -146,24 +146,32 @@ class OtherController extends CommonController
|
|
|
|
|
->get();
|
|
|
|
|
// 课程统计
|
|
|
|
|
$courseTypes = CourseType::where('is_chart', 1)->where('is_history', 0)->get();
|
|
|
|
|
// 默认开始时间
|
|
|
|
|
$start_date = CourseType::START_DATE;
|
|
|
|
|
$end_date = date('Y-m-d');
|
|
|
|
|
// 默认结束日期一年以后
|
|
|
|
|
$end_date = date('Y-m-d', strtotime('+10 year'));
|
|
|
|
|
|
|
|
|
|
foreach ($courseTypes as $courseType) {
|
|
|
|
|
// 历史已开设期数
|
|
|
|
|
$historyCourse = HistoryCourse::whereHas('typeDetail', function ($query) use ($courseType) {
|
|
|
|
|
$query->where('name', 'like', '%' . $courseType->name . '%');
|
|
|
|
|
})->get();
|
|
|
|
|
// 课程
|
|
|
|
|
$courses = Course::where('type', $courseType->id)->get();
|
|
|
|
|
// 历史课程期数
|
|
|
|
|
$courseType->history_course_periods_total = $historyCourse->count();
|
|
|
|
|
// 现在课程数据
|
|
|
|
|
$courseType->now_course_periods_total = Course::where('type', $courseType->id)->count();
|
|
|
|
|
|
|
|
|
|
// 历史课程培养人数去重
|
|
|
|
|
$courseType->history_course_signs_total = $historyCourse->sum('course_type_signs_pass_unique');
|
|
|
|
|
// 现在课程培养人数
|
|
|
|
|
$courseType->now_course_signs_total = CourseSign::courseSignsTotalByUnique($start_date, $end_date, 1, $courses->pluck('id'), false, false);
|
|
|
|
|
|
|
|
|
|
// 课程
|
|
|
|
|
$courses = Course::where('type', $courseType->id)->get();
|
|
|
|
|
// 已开设期数
|
|
|
|
|
$courseType->course_periods_total = Course::where('type', $courseType->id)->count() + $courseType->history_course_periods_total;
|
|
|
|
|
$courseType->course_periods_total = $courseType->now_course_periods_total + $courseType->history_course_periods_total;
|
|
|
|
|
// 培养人数去重
|
|
|
|
|
$courseType->course_signs_total = $courseType->history_course_signs_total + CourseSign::courseSignsTotalByUnique($start_date, $end_date, 1, $courses->pluck('id'), null);
|
|
|
|
|
$courseType->course_signs_total = $courseType->history_course_signs_total + $courseType->now_course_signs_total;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -240,36 +248,9 @@ class OtherController extends CommonController
|
|
|
|
|
// 审核通过人数去重
|
|
|
|
|
$list['course_signs_pass_unique'] = CourseSign::courseSignsTotalByUnique($start_date, $end_date, 1, $courses->pluck('id'), null);
|
|
|
|
|
// 开课场次
|
|
|
|
|
// 开课场次
|
|
|
|
|
$calendar = Calendar::where(function ($query) use ($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) {
|
|
|
|
|
// 条件1:有 course_id 的数据,通过 course.type 匹配课程体系
|
|
|
|
|
// 条件2:没有 course_id 的数据,直接用 course_type_id 字段匹配
|
|
|
|
|
// 两个条件是或关系
|
|
|
|
|
|
|
|
|
|
if ($course_type_id) {
|
|
|
|
|
$course_type_id_array = is_array($course_type_id) ? $course_type_id : explode(',', $course_type_id);
|
|
|
|
|
|
|
|
|
|
// 条件1:有 course_id 时,通过关联的 course.type 匹配
|
|
|
|
|
$query->where(function ($q) use ($course_type_id_array) {
|
|
|
|
|
|
|
|
|
|
$q->whereHas('course', function ($subQ) use ($course_type_id_array) {
|
|
|
|
|
$subQ->whereIn('type', $course_type_id_array);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 条件2:没有 course_id 时,直接用 course_type_id 字段匹配(或关系)
|
|
|
|
|
$query->orWhere(function ($q) use ($course_type_id_array) {
|
|
|
|
|
$q->whereIn('course_type_id', $course_type_id_array);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
})->get();
|
|
|
|
|
|
|
|
|
|
$list['course_total'] = (clone $calendar)->count();
|
|
|
|
|
$list['course_total'] = Calendar::getCourseTotal($start_date, $end_date, $course_type_id);
|
|
|
|
|
// 开课天数
|
|
|
|
|
$list['course_day_total'] = (clone $calendar)->where('is_count_days', 1)->sum('days');
|
|
|
|
|
$list['course_day_total'] = Calendar::getCourseDayTotal($start_date, $end_date, $course_type_id);
|
|
|
|
|
|
|
|
|
|
$course_ids = $courses->pluck('id');
|
|
|
|
|
|
|
|
|
|
@ -411,7 +392,7 @@ class OtherController extends CommonController
|
|
|
|
|
switch ($export_type) {
|
|
|
|
|
case 'course_signs_invested':
|
|
|
|
|
// 被投企业明细 - 使用与coursesHome相同的算法
|
|
|
|
|
$companies = CourseSign::yhInvestedTotal($start_date, $end_date, $course_ids, true);
|
|
|
|
|
$companies = CourseSign::yhInvestedTotal(CourseType::START_DATE, $end_date, $course_ids, true);
|
|
|
|
|
foreach ($companies as $company) {
|
|
|
|
|
$data[] = [
|
|
|
|
|
'company_name' => $company->company_name,
|
|
|
|
|
@ -543,20 +524,57 @@ class OtherController extends CommonController
|
|
|
|
|
// 课程分类明细 - 与coursesHome中的courseTypesSum逻辑保持一致
|
|
|
|
|
$courseTypes = CourseType::whereIn('id', $course_type_id)->get();
|
|
|
|
|
foreach ($courseTypes as $courseType) {
|
|
|
|
|
$courses2 = Course::where('type', $courseType->id)->get();
|
|
|
|
|
// 获取课程 - 添加日期筛选逻辑
|
|
|
|
|
$courses2 = Course::where('type', $courseType->id)
|
|
|
|
|
->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]);
|
|
|
|
|
}
|
|
|
|
|
})->orderBy('start_date', 'asc')->get();
|
|
|
|
|
foreach ($courses2 as $course) {
|
|
|
|
|
$data[] = [
|
|
|
|
|
'course_type' => $courseType->name,
|
|
|
|
|
'course_name' => $course->name,
|
|
|
|
|
'course_type_signs_pass' => CourseSign::courseSignsTotal($start_date, $end_date, 1, $courses2->pluck('id')),
|
|
|
|
|
'course_type_signs_pass_unique' => CourseSign::courseSignsTotalByUnique($start_date, $end_date, 1, $courses2->pluck('id'), null),
|
|
|
|
|
'course_signs_pass' => CourseSign::courseSignsTotal($start_date, $end_date, 1, [$course->id]),
|
|
|
|
|
'course_type_signs_pass' => CourseSign::courseSignsTotal($start_date, $end_date, 1, $courses2->pluck('id'), false, false),
|
|
|
|
|
'course_type_signs_pass_unique' => CourseSign::courseSignsTotalByUnique($start_date, $end_date, 1, $courses2->pluck('id'), false, false),
|
|
|
|
|
'course_signs_pass' => CourseSign::courseSignsTotal($start_date, $end_date, 1, [$course->id], false, false),
|
|
|
|
|
'genban_total' => CourseSign::genban($start_date, $end_date, [$course->id]),
|
|
|
|
|
'yh_invested_total' => CourseSign::yhInvested($start_date, $end_date, [$course->id]),
|
|
|
|
|
'company_join_total' => CourseSign::companyJoin($start_date, $end_date, [$course->id]),
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 附加历史课程数据
|
|
|
|
|
$courseTypesHistory = CourseType::where('is_history', 1)->whereIn('id', $course_type_id)->get();
|
|
|
|
|
foreach ($courseTypesHistory as $historyCourse) {
|
|
|
|
|
$courses3 = HistoryCourse::whereHas('calendar', function ($query) {
|
|
|
|
|
$query->where('is_count_people', 1);
|
|
|
|
|
})->where(function ($query) use ($start_date, $end_date) {
|
|
|
|
|
// 开始结束日期的筛选。or查询
|
|
|
|
|
$query->whereBetween('start_time', [$start_date, $end_date])
|
|
|
|
|
->orWhereBetween('end_time', [$start_date, $end_date]);
|
|
|
|
|
})->where('type', $historyCourse->id)->get();
|
|
|
|
|
foreach ($courses3 as $course) {
|
|
|
|
|
$data[] = [
|
|
|
|
|
'course_type' => $historyCourse->name,
|
|
|
|
|
'course_name' => $course->course_name,
|
|
|
|
|
// 课程类型培养人数
|
|
|
|
|
'course_type_signs_pass' => $courses3->sum('course_type_signs_pass'),
|
|
|
|
|
// 课程类型去重培养人数
|
|
|
|
|
'course_type_signs_pass_unique' => $courses3->sum('course_type_signs_pass_unique'),
|
|
|
|
|
// 课程人数
|
|
|
|
|
'course_signs_pass' => $course->course_signs_pass,
|
|
|
|
|
// 跟班学员数量
|
|
|
|
|
'genban_total' => 0,
|
|
|
|
|
// 被投企业数
|
|
|
|
|
'yh_invested_total' => 0,
|
|
|
|
|
// 元禾同事数
|
|
|
|
|
'company_join_total' => 0,
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$fields = [
|
|
|
|
|
'course_type' => '课程体系',
|
|
|
|
|
'course_name' => '课程名称',
|
|
|
|
|
@ -871,7 +889,7 @@ class OtherController extends CommonController
|
|
|
|
|
// 年份范围内被投企业明细 - 所有年份范围内被投企业,关联学员、课程信息
|
|
|
|
|
// 数据结构:主表是公司,子数据是学员信息
|
|
|
|
|
// 导出时:公司信息只在第一行显示,后续行公司信息为空
|
|
|
|
|
$companiesData = CourseSign::companyInvestedYear($start_date, $end_date, $course_ids->toArray(), true);
|
|
|
|
|
$companiesData = CourseSign::companyInvestedYear($start_date, $end_date, $course_ids, true);
|
|
|
|
|
|
|
|
|
|
foreach ($companiesData as $item) {
|
|
|
|
|
$company = $item['company'];
|
|
|
|
|
@ -955,14 +973,8 @@ class OtherController extends CommonController
|
|
|
|
|
|
|
|
|
|
case 'course_total':
|
|
|
|
|
// 开课场次明细 - 与coursesHome算法一致
|
|
|
|
|
$calendars = Calendar::whereBetween('date', [$start_date, $end_date])
|
|
|
|
|
->where(function ($query) use ($course_ids) {
|
|
|
|
|
$course_type_id = request('course_type_id');
|
|
|
|
|
if ($course_type_id) {
|
|
|
|
|
$course_type_id = explode(',', $course_type_id);
|
|
|
|
|
$query->whereIn('course_type_id', $course_type_id);
|
|
|
|
|
}
|
|
|
|
|
})->with('course')
|
|
|
|
|
$calendars = Calendar::getCalendarsByDateRange($start_date, $end_date, $course_type_id)
|
|
|
|
|
->with('course')
|
|
|
|
|
->get();
|
|
|
|
|
|
|
|
|
|
foreach ($calendars as $calendar) {
|
|
|
|
|
@ -988,14 +1000,8 @@ class OtherController extends CommonController
|
|
|
|
|
|
|
|
|
|
case 'course_day_total':
|
|
|
|
|
// 开课天数明细 - 与coursesHome算法一致
|
|
|
|
|
$calendars = Calendar::whereBetween('date', [$start_date, $end_date])
|
|
|
|
|
->where(function ($query) use ($course_ids) {
|
|
|
|
|
$course_type_id = request('course_type_id');
|
|
|
|
|
if ($course_type_id) {
|
|
|
|
|
$course_type_id = explode(',', $course_type_id);
|
|
|
|
|
$query->whereIn('course_type_id', $course_type_id);
|
|
|
|
|
}
|
|
|
|
|
})->where('is_count_days', 1)
|
|
|
|
|
$calendars = Calendar::getCalendarsByDateRange($start_date, $end_date, $course_type_id)
|
|
|
|
|
->where('is_count_days', 1)
|
|
|
|
|
->with('course')
|
|
|
|
|
->get();
|
|
|
|
|
|
|
|
|
|
@ -1140,8 +1146,9 @@ class OtherController extends CommonController
|
|
|
|
|
|
|
|
|
|
case 'cover_stock_total':
|
|
|
|
|
// 重点上市公司明细 - 使用模型方法
|
|
|
|
|
$companies = CourseSign::shangshi($start_date, $end_date, $course_ids, true);
|
|
|
|
|
foreach ($companies as $company) {
|
|
|
|
|
$companiesData = CourseSign::shangshi($start_date, $end_date, $course_ids, true);
|
|
|
|
|
foreach ($companiesData as $item) {
|
|
|
|
|
$company = $item['company'];
|
|
|
|
|
$data[] = [
|
|
|
|
|
'company_name' => $company->company_name,
|
|
|
|
|
'company_legal_representative' => $company->company_legal_representative ?? '',
|
|
|
|
|
|