diff --git a/app/Http/Controllers/Admin/CompanyController.php b/app/Http/Controllers/Admin/CompanyController.php index 6836bd6..745878c 100644 --- a/app/Http/Controllers/Admin/CompanyController.php +++ b/app/Http/Controllers/Admin/CompanyController.php @@ -298,16 +298,16 @@ class CompanyController extends BaseController $statistics['course_signs_invested_companies'] = $investedCompaniesCollection->pluck('company_name')->filter()->unique()->values()->toArray(); } - // 今年年份范围内被投企业数 - $yearInvestedCompanies = Company::companyInvestedYear($start_date, $end_date, true); + // 当前周期被投企业数(与 courses-home 的 course_signs_invested_current 口径一致) + $yearInvestedCompanies = CourseSign::yhInvestedTotal($start_date, $end_date, $course_ids, true); if ($yearInvestedCompanies) { $yearInvestedCompaniesCollection = collect($yearInvestedCompanies); $statistics['company_invested_year_total'] = $yearInvestedCompaniesCollection->count(); $statistics['company_invested_year_companies'] = $yearInvestedCompaniesCollection->pluck('company_name')->filter()->unique()->values()->toArray(); } - // 入学后被投企业数量(在指定时间范围内报名的学员所在公司中,在入学后被投的公司数量) - $afterEnrollmentCompanies = CourseSign::companyInvestedAfterEnrollment($start_date, $end_date, null, true); + // 入学后被投企业数量(与 courses-home 的 company_invested_after_enrollment_total_cumulative 口径一致) + $afterEnrollmentCompanies = CourseSign::companyInvestedAfterEnrollment(CourseType::START_DATE, $end_date, $course_ids, true); if ($afterEnrollmentCompanies) { $statistics['company_invested_after_enrollment_total'] = count($afterEnrollmentCompanies); $statistics['company_invested_after_enrollment_companies'] = collect($afterEnrollmentCompanies)->pluck('company.company_name')->filter()->unique()->values()->toArray(); diff --git a/app/Models/Company.php b/app/Models/Company.php index 8f2d463..28990b5 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -73,61 +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 是否返回列表,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::approvedStudents()->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(); - } - } - /** * 根据用户信息更新/同步公司信息 * @param User $user 用户对象 diff --git a/app/Models/CourseSign.php b/app/Models/CourseSign.php index 36d0a88..13fcb7b 100755 --- a/app/Models/CourseSign.php +++ b/app/Models/CourseSign.php @@ -383,58 +383,6 @@ class CourseSign extends SoftDeletesModel } } - /** - * 入学后上市公司数量(在指定时间范围内报名的学员所在公司中,在入学后上市的公司数量) - * @param string $start_date 开始日期 - * @param string $end_date 结束日期 - * @param array|null $course_ids 课程ID数组,不传则统计所有课程 - * @param bool $retList 是否返回列表,false返回数量,true返回列表 - * @return int|array - */ - public static function companyMarketAfterEnrollment($start_date, $end_date, $course_ids = null, $retList = false) - { - $courseSignsQuery = self::getStudentList($start_date, $end_date, null, $course_ids); - $courseSignsForStock = $courseSignsQuery->with(['user.company', 'course'])->get(); - $companiesAfterEnrollment = []; - foreach ($courseSignsForStock as $sign) { - if ($sign->user && $sign->user->company && $sign->user->company->company_market == 1) { - // 入学时间:使用参与课程的课程开始时间(course->start_date),不使用报名时间(created_at) - $enrollmentDate = null; - if ($sign->course && $sign->course->start_date) { - $enrollmentDate = \Carbon\Carbon::parse($sign->course->start_date)->format('Y-m-d'); - } - - // 如果没有课程开始时间,跳过这条记录 - if (!$enrollmentDate) { - continue; - } - - $stockDate = $sign->user->company->stock_date; - // 上市时间 >= 课程开始时间(入学时间),说明是入学后上市 - if ($stockDate && $stockDate >= $enrollmentDate) { - $companyId = $sign->user->company->id; - if (!isset($companiesAfterEnrollment[$companyId])) { - $companiesAfterEnrollment[$companyId] = [ - 'company' => $sign->user->company, - 'first_enrollment_date' => $enrollmentDate, // 首次入学时间(课程开始时间) - 'stock_date' => $stockDate, - 'users' => [], - ]; - } - if ($retList) { - $companiesAfterEnrollment[$companyId]['users'][] = $sign->user; - } - } - } - } - - if ($retList) { - return $companiesAfterEnrollment; - } else { - return count($companiesAfterEnrollment); - } - } - /** * 当前入学后被投企业数量(被投时间在指定时间范围内,且学员入学时间小于等于被投时间的公司数量) * @param string $start_date 开始日期