diff --git a/app/Http/Controllers/Admin/CompanyController.php b/app/Http/Controllers/Admin/CompanyController.php index 72aff74..6836bd6 100644 --- a/app/Http/Controllers/Admin/CompanyController.php +++ b/app/Http/Controllers/Admin/CompanyController.php @@ -9,6 +9,7 @@ use App\Models\AppointmentType; use App\Models\Book; use App\Models\Calendar; use App\Models\Company; +use App\Models\Course; use App\Models\CourseContentEvaluationAsk; use App\Models\CourseContentEvaluationForm; use App\Models\CourseSign; @@ -283,8 +284,14 @@ class CompanyController extends BaseController $start_date = $start_year ? $start_year . '-01-01' : date('Y-01-01'); $end_date = $end_year ? $end_year . '-12-31' : date('Y-m-d'); if ($start_date && $end_date) { - // 累计被投企业数(从起始日期到结束日期) - $investedCompanies = Company::yhInvestedTotal($end_date, true); + // 累计被投企业数(与 CourseSign::yhInvestedTotal / courses-home 口径一致:getStudentList 学员 + 被投企业) + $course_ids = null; + if (!empty($all['course_type_id'])) { + $tid = is_array($all['course_type_id']) ? $all['course_type_id'] : explode(',', (string) $all['course_type_id']); + $tid = array_filter(array_map('trim', $tid)); + $course_ids = $tid ? Course::whereIn('type', $tid)->pluck('id')->toArray() : null; + } + $investedCompanies = CourseSign::yhInvestedTotal(CourseType::START_DATE, $end_date, $course_ids, true); if ($investedCompanies) { $investedCompaniesCollection = collect($investedCompanies); $statistics['course_signs_invested'] = $investedCompaniesCollection->count(); diff --git a/app/Models/Company.php b/app/Models/Company.php index 745e3fc..8f2d463 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -73,53 +73,6 @@ 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::approvedStudents()->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 开始日期 diff --git a/app/Models/CourseSign.php b/app/Models/CourseSign.php index f4014d8..36d0a88 100755 --- a/app/Models/CourseSign.php +++ b/app/Models/CourseSign.php @@ -181,7 +181,7 @@ class CourseSign extends SoftDeletesModel */ public static function yhInvestedTotal($start_date = null, $end_date = null, $course_ids = null, $retList = false) { - // 默认时间:获取所有学员,不限制课程 + // 默认时间:获取所有学员 $userIds = self::getStudentList($start_date, $end_date, 1, $course_ids)->get()->pluck('user_id'); // 获取这些学员所在的被投企业