|
|
|
|
@ -148,27 +148,58 @@ 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 yhInvested($start_date = null, $end_date = null, $retList = false)
|
|
|
|
|
public static function yhInvested($start_date = null, $end_date = null, $course_ids = null, $retList = false)
|
|
|
|
|
{
|
|
|
|
|
$userIds = self::getStudentList($start_date, $end_date, 1, null)->get()->pluck('user_id');
|
|
|
|
|
$companies = Company::whereHas('users', fn($q) => $q->whereIn('id', $userIds))
|
|
|
|
|
->where('is_yh_invested', 1)->get();
|
|
|
|
|
// 判断是否使用默认时间
|
|
|
|
|
$isDefaultDate = empty($start_date) || $start_date == CourseType::START_DATE;
|
|
|
|
|
|
|
|
|
|
// 非默认时间:按 investDate 筛选
|
|
|
|
|
if ($start_date && $start_date != CourseType::START_DATE) {
|
|
|
|
|
// 获取学员ID列表
|
|
|
|
|
if ($isDefaultDate) {
|
|
|
|
|
// 默认时间:获取所有学员,不限制课程
|
|
|
|
|
$userIds = self::getStudentList($start_date, $end_date, 1, null)->get()->pluck('user_id');
|
|
|
|
|
} else {
|
|
|
|
|
// 自定义时间:按课程筛选学员
|
|
|
|
|
$userIds = self::getStudentList($start_date, $end_date, 1, $course_ids)->get()->pluck('user_id');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取这些学员所在的被投企业
|
|
|
|
|
$companies = Company::whereHas('users', function ($query) use ($userIds) {
|
|
|
|
|
$query->whereIn('id', $userIds);
|
|
|
|
|
})->where('is_yh_invested', 1)->get();
|
|
|
|
|
|
|
|
|
|
// 自定义时间:需要按被投时间筛选
|
|
|
|
|
if (!$isDefaultDate) {
|
|
|
|
|
$startDate = substr($start_date, 0, 10);
|
|
|
|
|
$endDate = substr($end_date, 0, 10);
|
|
|
|
|
$companies = $companies->filter(function ($company) use ($startDate, $endDate) {
|
|
|
|
|
return collect($company->project_users ?? [])->contains(function ($item) use ($startDate, $endDate) {
|
|
|
|
|
|
|
|
|
|
// 筛选出被投时间在范围内的企业
|
|
|
|
|
$filteredCompanies = [];
|
|
|
|
|
foreach ($companies as $company) {
|
|
|
|
|
$projectUsers = $company->project_users ?? [];
|
|
|
|
|
foreach ($projectUsers as $item) {
|
|
|
|
|
$investDate = $item['investDate'] ?? null;
|
|
|
|
|
return $investDate && $investDate >= $startDate && $investDate <= $endDate;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
// 检查被投时间是否在范围内
|
|
|
|
|
if ($investDate && $investDate >= $startDate && $investDate <= $endDate) {
|
|
|
|
|
$filteredCompanies[] = $company;
|
|
|
|
|
break; // 只要有一条满足就加入
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$companies = collect($filteredCompanies);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $retList ? $companies->values() : $companies->count();
|
|
|
|
|
// 返回结果
|
|
|
|
|
if ($retList) {
|
|
|
|
|
return $companies->values();
|
|
|
|
|
} else {
|
|
|
|
|
return $companies->count();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|