diff --git a/app/Models/CourseSign.php b/app/Models/CourseSign.php index 66ac99a..5cb2a47 100755 --- a/app/Models/CourseSign.php +++ b/app/Models/CourseSign.php @@ -176,7 +176,7 @@ class CourseSign extends SoftDeletesModel * @param array|null $course_ids 课程ID(仅在自定义时间时生效) * @param bool $retList 是否返回列表 */ - public static function yhInvestedTotal($start_date, $end_date = null, $retList = false) + public static function yhInvestedTotal($start_date = null, $end_date = null, $retList = false) { // 默认时间:获取所有学员,不限制课程 $userIds = self::getStudentList($start_date, $end_date, 1, null)->get()->pluck('user_id'); @@ -190,14 +190,26 @@ class CourseSign extends SoftDeletesModel $filteredCompanies = []; foreach ($companies as $company) { $projectUsers = $company->project_users ?? []; + $hasValidInvestDate = false; + $allInvestDatesNull = true; + foreach ($projectUsers as $item) { $investDate = $item['investDate'] ?? null; - // 检查被投时间是否在范围内 - if ($investDate && $investDate <= $end_date) { - $filteredCompanies[] = $company; - break; // 只要有一条满足就加入 + // 检查是否有有效的被投时间 + if ($investDate) { + $allInvestDatesNull = false; + // 检查被投时间是否在范围内 + if ($investDate <= $end_date) { + $hasValidInvestDate = true; + break; // 只要有一条满足就加入 + } } } + + // 如果有有效的被投时间在范围内,或者所有被投时间都是null,则加入结果 + if ($hasValidInvestDate || $allInvestDatesNull) { + $filteredCompanies[] = $company; + } } $companies = collect($filteredCompanies);