Merge branch 'master' of ssh://47.101.48.251:/data/git/wx.sstbc.com

master
lion 3 months ago
commit 5cb55cf590

@ -9,6 +9,7 @@ use App\Models\AppointmentType;
use App\Models\Book; use App\Models\Book;
use App\Models\Calendar; use App\Models\Calendar;
use App\Models\Company; use App\Models\Company;
use App\Models\Course;
use App\Models\CourseContentEvaluationAsk; use App\Models\CourseContentEvaluationAsk;
use App\Models\CourseContentEvaluationForm; use App\Models\CourseContentEvaluationForm;
use App\Models\CourseSign; use App\Models\CourseSign;
@ -117,6 +118,7 @@ class CompanyController extends BaseController
* @OA\Parameter(name="is_schoolmate", in="query", @OA\Schema(type="string"), required=false, description="是否校友0否1是"), * @OA\Parameter(name="is_schoolmate", in="query", @OA\Schema(type="string"), required=false, description="是否校友0否1是"),
* @OA\Parameter(name="course_start_date", in="query", @OA\Schema(type="string"), required=false, description="课程开始日期(筛选课程起止时间在范围内的企业)"), * @OA\Parameter(name="course_start_date", in="query", @OA\Schema(type="string"), required=false, description="课程开始日期(筛选课程起止时间在范围内的企业)"),
* @OA\Parameter(name="course_end_date", in="query", @OA\Schema(type="string"), required=false, description="课程结束日期(筛选课程起止时间在范围内的企业)"), * @OA\Parameter(name="course_end_date", in="query", @OA\Schema(type="string"), required=false, description="课程结束日期(筛选课程起止时间在范围内的企业)"),
* @OA\Parameter(name="is_chart", in="query", @OA\Schema(type="string"), required=false, description="课程是否参与统计0否1是按公司下用户关联的课程筛选"),
* @OA\Response( * @OA\Response(
* response="200", * response="200",
* description="暂无" * description="暂无"
@ -136,35 +138,44 @@ class CompanyController extends BaseController
})->with('courseSigns.course'); })->with('courseSigns.course');
} }
])->whereHas('users', function ($query) use ($all) { ])->whereHas('users', function ($query) use ($all) {
if (isset($all['course_type_id']) && !empty($all['course_type_id'])) { // 课程筛选:与 courses-home / getStudentList 口径一致,仅 status=1 的报名,且由同一条 courseSign 满足 type/name/日期/is_chart
$query->whereHas('courses', function ($q) use ($all) { $hasCourseFilter = (isset($all['course_type_id']) && $all['course_type_id'] !== '') ||
$q->where('type', $all['course_type_id']); (isset($all['course_name']) && $all['course_name'] !== '') ||
}); (isset($all['course_start_date']) && $all['course_start_date'] !== '') ||
(isset($all['course_end_date']) && $all['course_end_date'] !== '') ||
(isset($all['is_chart']) && $all['is_chart'] !== '');
if ($hasCourseFilter) {
$query->whereHas('courseSigns', function ($q) use ($all) {
$q->where('status', 1);
$q->whereHas('course', function ($c) use ($all) {
if (isset($all['course_type_id']) && $all['course_type_id'] !== '') {
$c->where('type', $all['course_type_id']);
} }
if (isset($all['course_name']) && !empty($all['course_name'])) { if (isset($all['course_name']) && $all['course_name'] !== '') {
$query->whereHas('courses', function ($q) use ($all) { $c->where('name', 'like', '%' . $all['course_name'] . '%');
$q->where('name', 'like', '%' . $all['course_name'] . '%');
});
} }
// 课程起止时间筛选 if (
if ((isset($all['course_start_date']) && !empty($all['course_start_date'])) || (isset($all['course_start_date']) && $all['course_start_date'] !== '') ||
(isset($all['course_end_date']) && !empty($all['course_end_date']))) { (isset($all['course_end_date']) && $all['course_end_date'] !== '')
$query->whereHas('courses', function ($q) use ($all) { ) {
$course_start_date = $all['course_start_date'] ?? null; $course_start_date = $all['course_start_date'] ?? null;
$course_end_date = $all['course_end_date'] ?? null; $course_end_date = $all['course_end_date'] ?? null;
if ($course_start_date && $course_end_date) { if ($course_start_date && $course_end_date) {
// 课程开始时间或结束时间在指定时间范围内 $c->where(function ($sub) use ($course_start_date, $course_end_date) {
$q->where(function ($subQuery) use ($course_start_date, $course_end_date) { $sub->whereBetween('start_date', [$course_start_date, $course_end_date])
$subQuery->whereBetween('start_date', [$course_start_date, $course_end_date])
->orWhereBetween('end_date', [$course_start_date, $course_end_date]); ->orWhereBetween('end_date', [$course_start_date, $course_end_date]);
}); });
} elseif ($course_start_date) { } elseif ($course_start_date) {
// 只指定开始日期,筛选课程结束时间 >= 开始日期 $c->where('end_date', '>=', $course_start_date);
$q->where('end_date', '>=', $course_start_date);
} elseif ($course_end_date) { } elseif ($course_end_date) {
// 只指定结束日期,筛选课程开始时间 <= 结束日期 $c->where('start_date', '<=', $course_end_date);
$q->where('start_date', '<=', $course_end_date);
} }
}
if (isset($all['is_chart']) && $all['is_chart'] !== '') {
$c->where('is_chart', $all['is_chart']);
}
});
}); });
} }
if (isset($all['user_name']) && !empty($all['user_name'])) { if (isset($all['user_name']) && !empty($all['user_name'])) {
@ -273,8 +284,14 @@ class CompanyController extends BaseController
$start_date = $start_year ? $start_year . '-01-01' : date('Y-01-01'); $start_date = $start_year ? $start_year . '-01-01' : date('Y-01-01');
$end_date = $end_year ? $end_year . '-12-31' : date('Y-m-d'); $end_date = $end_year ? $end_year . '-12-31' : date('Y-m-d');
if ($start_date && $end_date) { if ($start_date && $end_date) {
// 累计被投企业数(从起始日期到结束日期) // 累计被投企业数(与 CourseSign::yhInvestedTotal / courses-home 口径一致getStudentList 学员 + 被投企业)
$investedCompanies = Company::yhInvestedTotal($end_date, true); $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) { if ($investedCompanies) {
$investedCompaniesCollection = collect($investedCompanies); $investedCompaniesCollection = collect($investedCompanies);
$statistics['course_signs_invested'] = $investedCompaniesCollection->count(); $statistics['course_signs_invested'] = $investedCompaniesCollection->count();

@ -318,7 +318,7 @@ class OtherController extends CommonController
$course_ids = $courses->pluck('id'); $course_ids = $courses->pluck('id');
// 上市公司数(所有上市公司) // 上市公司覆盖数(所有上市公司)
$list['company_market_total'] = CourseSign::shangshi($start_date, $end_date, $course_ids); $list['company_market_total'] = CourseSign::shangshi($start_date, $end_date, $course_ids);
// 跟班学员数在指定时间范围内报名的学员中from为'跟班学员'的数量) // 跟班学员数在指定时间范围内报名的学员中from为'跟班学员'的数量)
$list['ganbu_total'] = CourseSign::genban($start_date, $end_date, $course_ids); $list['ganbu_total'] = CourseSign::genban($start_date, $end_date, $course_ids);

@ -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 开始日期 * @param string|null $start_date 开始日期

@ -181,7 +181,7 @@ class CourseSign extends SoftDeletesModel
*/ */
public static function yhInvestedTotal($start_date = null, $end_date = null, $course_ids = null, $retList = false) 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'); $userIds = self::getStudentList($start_date, $end_date, 1, $course_ids)->get()->pluck('user_id');
// 获取这些学员所在的被投企业 // 获取这些学员所在的被投企业

Loading…
Cancel
Save