From 8992fb11ad97580b4412f5b58ac7acd53da9d785 Mon Sep 17 00:00:00 2001 From: cody <648753004@qq.com> Date: Fri, 28 Nov 2025 23:09:50 +0800 Subject: [PATCH] update --- app/Models/CourseSign.php | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/app/Models/CourseSign.php b/app/Models/CourseSign.php index 5cb2a47..d7c7c1b 100755 --- a/app/Models/CourseSign.php +++ b/app/Models/CourseSign.php @@ -274,7 +274,7 @@ class CourseSign extends SoftDeletesModel } /** - * 今年被投企业统计(统计或列表) + * 被投企业统计(统计或列表)- 按年份范围统计 * @param string|null $start_date 开始日期 * @param string|null $end_date 结束日期 * @param array|null $course_ids 课程ID数组,不传则统计所有课程 @@ -292,28 +292,42 @@ class CourseSign extends SoftDeletesModel ->unique() ->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) ->where('is_yh_invested', 1) ->get(); - // 筛选出被投时间在今年的企业 + // 筛选出被投时间在年份范围内的企业 $companies = []; foreach ($allInvestedCompanies as $company) { $projectUsers = $company->project_users ?? []; - $hasInvestThisYear = false; + $hasInvestInYears = false; foreach ($projectUsers as $item) { $investDate = $item['investDate'] ?? null; if ($investDate) { - $investYear = date('Y', strtotime($investDate)); - if ($investYear == $year) { - $hasInvestThisYear = true; + $investYear = (int) date('Y', strtotime($investDate)); + if (in_array($investYear, $years)) { + $hasInvestInYears = true; break; } } } - if ($hasInvestThisYear) { + if ($hasInvestInYears) { $companies[$company->id] = $company; } } @@ -328,7 +342,7 @@ class CourseSign extends SoftDeletesModel } $companyId = $courseSign->user->company->id; - // 只处理今年被投企业的记录 + // 只处理年份范围内被投企业的记录 if (!isset($companies[$companyId])) { continue; }