diff --git a/app/Http/Controllers/Admin/OtherController.php b/app/Http/Controllers/Admin/OtherController.php index ffa36b1..3255264 100755 --- a/app/Http/Controllers/Admin/OtherController.php +++ b/app/Http/Controllers/Admin/OtherController.php @@ -275,7 +275,7 @@ class OtherController extends CommonController $list['company_market_after_enrollment_total'] = CourseSign::companyMarketAfterEnrollment($start_date, $end_date, $course_ids); // 累计被投企业数 - $list['course_signs_invested'] = CourseSign::yhInvested(CourseType::START_DATE, $end_date); + $list['course_signs_invested'] = CourseSign::yhInvestedTotal(CourseType::START_DATE, $end_date); dd(1); // 入学后被投企业数量(在指定时间范围内报名的学员所在公司中,在入学后被投的公司数量) $list['company_invested_after_enrollment_total'] = CourseSign::companyInvestedAfterEnrollment($start_date, $end_date, $course_ids); diff --git a/app/Models/CourseSign.php b/app/Models/CourseSign.php index a42bd54..f6efb19 100755 --- a/app/Models/CourseSign.php +++ b/app/Models/CourseSign.php @@ -169,6 +169,51 @@ class CourseSign 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($start_date, $end_date = null, $retList = false) + { + // 默认时间:获取所有学员,不限制课程 + $userIds = self::getStudentList($start_date, $end_date, 1, null)->get()->pluck('user_id'); + + // 获取这些学员所在的被投企业 + $companies = Company::whereHas('users', function ($query) use ($userIds) { + $query->whereIn('id', $userIds); + })->where('is_yh_invested', 1)->get(); + // 自定义时间:需要按被投时间筛选 + + $startDate = substr($start_date, 0, 10); + $endDate = substr($end_date, 0, 10); + dd($startDate, $endDate); + // 筛选出被投时间在范围内的企业 + $filteredCompanies = []; + foreach ($companies as $company) { + $projectUsers = $company->project_users ?? []; + foreach ($projectUsers as $item) { + $investDate = $item['investDate'] ?? null; + // 检查被投时间是否在范围内 + if ($investDate && $investDate >= $startDate && $investDate <= $endDate) { + $filteredCompanies[] = $company; + break; // 只要有一条满足就加入 + } + } + } + $companies = collect($filteredCompanies); + + + // 返回结果 + if ($retList) { + return $companies->values(); + } else { + return $companies->count(); + } + } + /** * 被投企业统计 * @param string|null $start_date 开始日期 @@ -195,8 +240,8 @@ class CourseSign extends SoftDeletesModel })->where('is_yh_invested', 1)->get(); // 自定义时间:需要按被投时间筛选 if (!$isDefaultDate) { - // $startDate = substr($start_date, 0, 10); - // $endDate = substr($end_date, 0, 10); + // $startDate = substr($start_date, 0, 10); + // $endDate = substr($end_date, 0, 10); dd($start_date, $end_date); // 筛选出被投时间在范围内的企业 $filteredCompanies = [];