master
cody 1 week ago
parent 5634c27875
commit 29c7a5fb2f

@ -213,13 +213,11 @@ class CompanyController extends BaseController
$end_date = $end_year ? $end_year . '-12-31' : date('Y-m-d'); $end_date = $end_year ? $end_year . '-12-31' : date('Y-m-d');
if ($start_date && $end_date) { if ($start_date && $end_date) {
// 累计被投企业数(从起始日期到结束日期) // 累计被投企业数(从起始日期到结束日期)
$statistics['course_signs_invested'] = CourseSign::yhInvestedTotal(CourseType::START_DATE, $end_date, null); $statistics['course_signs_invested'] = Company::yhInvestedTotal($end_date);
// 入学后被投企业数量(在指定时间范围内报名的学员所在公司中,在入学后被投的公司数量)
$statistics['company_invested_after_enrollment_total'] = CourseSign::companyInvestedAfterEnrollment($start_date, $end_date, null);
// 年份范围内被投企业数(在指定时间范围内报名的学员所在公司中,被投时间在年份范围内的公司数量) // 年份范围内被投企业数(在指定时间范围内报名的学员所在公司中,被投时间在年份范围内的公司数量)
$statistics['company_invested_year_total'] = CourseSign::companyInvestedYear($start_date, $end_date, null); $statistics['company_invested_year_total'] = Company::yhInvested($start_date, $end_date);
// 入学后被投企业数量(在指定时间范围内报名的学员所在公司中,在入学后被投的公司数量)
$statistics['company_invested_after_enrollment_total'] = Company::companyInvestedYear($start_date, $end_date);
} }
// 将统计数据添加到返回结果中 // 将统计数据添加到返回结果中

@ -58,4 +58,141 @@ class Company extends SoftDeletesModel
} }
} }
/**
* 累计被投企业统计
* @param string|null $start_date 开始日期
* @param string|null $end_date 结束日期
* @param array|null $course_ids 课程ID仅在自定义时间时生效
* @param bool $retList 是否返回列表
*/
public static function yhInvestedTotal($end_date = null, $retList = false)
{
// 获取这些学员所在的被投企业
$companies = Company::where('is_yh_invested', 1)->get();
// 自定义时间:需要按被投时间筛选
// 筛选出被投时间在范围内的企业
$filteredCompanies = [];
foreach ($companies as $company) {
$projectUsers = $company->project_users ?? [];
$hasValidInvestDate = false;
$allInvestDatesNull = true;
foreach ($projectUsers as $item) {
$investDate = $item['investDate'] ?? null;
// 检查是否有有效的被投时间
if ($investDate) {
$allInvestDatesNull = false;
// 检查被投时间是否在范围内
if ($investDate <= $end_date) {
$hasValidInvestDate = true;
break; // 只要有一条满足就加入
}
}
}
// 如果有有效的被投时间在范围内或者所有被投时间都是null则加入结果
if ($hasValidInvestDate || $allInvestDatesNull) {
$filteredCompanies[] = $company;
}
}
$companies = collect($filteredCompanies);
// 返回结果
if ($retList) {
return $companies->values();
} else {
return $companies->count();
}
}
/**
* 被投企业统计
* @param string|null $start_date 开始日期
* @param string|null $end_date 结束日期
* @param array|null $course_ids 课程ID仅在自定义时间时生效
* @param bool $retList 是否返回列表
*/
public static function yhInvested($startDate = null, $endDate = null, $retList = false)
{
// 获取这些学员所在的被投企业
$companies = Company::where('is_yh_invested', 1)->get();
// 筛选出被投时间在范围内的企业
$filteredCompanies = [];
foreach ($companies as $company) {
$projectUsers = $company->project_users ?? [];
foreach ($projectUsers as $item) {
$investDate = $item['investDate'] ?? null;
// 检查被投时间是否在范围内
if ($investDate && $investDate >= $startDate && $investDate <= $endDate) {
$filteredCompanies[] = $company;
break; // 只要有一条满足就加入
}
}
}
$companies = collect($filteredCompanies);
// 返回结果
if ($retList) {
return $companies->values();
} else {
return $companies->count();
}
}
/**
* 被投企业统计(统计或列表)- 按年份范围统计
* @param string|null $start_date 开始日期
* @param string|null $end_date 结束日期
* @param array|null $course_ids 课程ID数组不传则统计所有课程
* @param bool $retList 是否返回列表false返回数量true返回列表包含学员、课程信息
* @return int|array
*/
public static function companyInvestedYear($start_date = null, $end_date = null, $retList = false)
{
// 计算年份范围
$years = [];
if ($start_date && $end_date) {
// 从开始和结束日期中提取年份范围
$startYear = (int)date('Y', strtotime($start_date));
$endYear = (int)date('Y', strtotime($end_date));
// 生成所有年份的数组
for ($year = $startYear; $year <= $endYear; $year++) {
$years[] = $year;
}
} else {
// 如果没有提供日期,使用当前年份
$years[] = (int)date('Y');
}
// 获取这些公司中标记为被投的公司
$allInvestedCompanies = Company::where('is_yh_invested', 1)->get();
// 筛选出被投时间在年份范围内的企业
$companies = [];
foreach ($allInvestedCompanies as $company) {
$projectUsers = $company->project_users ?? [];
$hasInvestInYears = false;
foreach ($projectUsers as $item) {
$investDate = $item['investDate'] ?? null;
if ($investDate) {
$investYear = (int)date('Y', strtotime($investDate));
if (in_array($investYear, $years)) {
$hasInvestInYears = true;
break;
}
}
}
if ($hasInvestInYears) {
$companies[$company->id] = $company;
}
}
$companies = collect($companies);
// 返回结果
if ($retList) {
return $companies->values();
} else {
return $companies->count();
}
}
} }

Loading…
Cancel
Save