master
cody 1 week ago
parent 58eace66f5
commit 8992fb11ad

@ -274,7 +274,7 @@ class CourseSign extends SoftDeletesModel
} }
/** /**
* 今年被投企业统计(统计或列表) * 被投企业统计(统计或列表)- 按年份范围统计
* @param string|null $start_date 开始日期 * @param string|null $start_date 开始日期
* @param string|null $end_date 结束日期 * @param string|null $end_date 结束日期
* @param array|null $course_ids 课程ID数组不传则统计所有课程 * @param array|null $course_ids 课程ID数组不传则统计所有课程
@ -292,28 +292,42 @@ class CourseSign extends SoftDeletesModel
->unique() ->unique()
->toArray(); ->toArray();
$year = date('Y'); // 计算年份范围
$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::whereIn('id', $companyIds) $allInvestedCompanies = Company::whereIn('id', $companyIds)
->where('is_yh_invested', 1) ->where('is_yh_invested', 1)
->get(); ->get();
// 筛选出被投时间在今年的企业 // 筛选出被投时间在年份范围内的企业
$companies = []; $companies = [];
foreach ($allInvestedCompanies as $company) { foreach ($allInvestedCompanies as $company) {
$projectUsers = $company->project_users ?? []; $projectUsers = $company->project_users ?? [];
$hasInvestThisYear = false; $hasInvestInYears = false;
foreach ($projectUsers as $item) { foreach ($projectUsers as $item) {
$investDate = $item['investDate'] ?? null; $investDate = $item['investDate'] ?? null;
if ($investDate) { if ($investDate) {
$investYear = date('Y', strtotime($investDate)); $investYear = (int) date('Y', strtotime($investDate));
if ($investYear == $year) { if (in_array($investYear, $years)) {
$hasInvestThisYear = true; $hasInvestInYears = true;
break; break;
} }
} }
} }
if ($hasInvestThisYear) { if ($hasInvestInYears) {
$companies[$company->id] = $company; $companies[$company->id] = $company;
} }
} }
@ -328,7 +342,7 @@ class CourseSign extends SoftDeletesModel
} }
$companyId = $courseSign->user->company->id; $companyId = $courseSign->user->company->id;
// 只处理年被投企业的记录 // 只处理年份范围内被投企业的记录
if (!isset($companies[$companyId])) { if (!isset($companies[$companyId])) {
continue; continue;
} }

Loading…
Cancel
Save