lion 3 months ago
commit 264d2c0385

@ -127,7 +127,7 @@ class CompanyController extends BaseController
$start_year = $all['start_year'] ?? null;
$end_year = $all['end_year'] ?? null;
$list = $this->model->with([
$list = $this->model->approvedStudents()->with([
'users' => function ($query) use ($all) {
$query->whereHas('courseSigns', function ($q) {
$q->where('status', 1);

@ -72,9 +72,9 @@ class OtherController extends CommonController
});
// 校友企业总融资额
$company['company_fund'] = Company::where('is_schoolmate', 1)->sum('company_fund');
$company['company_fund'] = Company::approvedStudents()->where('is_schoolmate', 1)->sum('company_fund');
// 校友企业总估值
$company['valuation'] = Company::where('is_schoolmate', 1)->sum('valuation');
$company['valuation'] = Company::approvedStudents()->where('is_schoolmate', 1)->sum('valuation');
// 校友企业所属领域
$industryTotal = [];
@ -95,13 +95,13 @@ class OtherController extends CommonController
->count();
}
// 苏州区域数据
$suzhou = Company::where('company_city', '苏州市')
$suzhou = Company::approvedStudents()->where('company_city', '苏州市')
// 根据company_area分组查询公司数量
->select('company_area', DB::raw('count(*) as company_total'))
->groupBy('company_area')
->get();
// 全国数据
$country = Company::select('company_city', DB::raw('count(*) as company_total'))
$country = Company::approvedStudents()->select('company_city', DB::raw('count(*) as company_total'))
->groupBy('company_city')
->get();
return $this->success(compact('courseTypes', 'schoolmate', 'company', 'industryTotal', 'suzhou', 'country'));
@ -190,7 +190,7 @@ class OtherController extends CommonController
// 苏州区域数据
$suzhouArea = Company::where('company_city', '苏州市')->groupBy('company_area')
$suzhouArea = Company::approvedStudents()->where('company_city', '苏州市')->groupBy('company_area')
->whereNotNull('company_area')
->get(['company_area']);
$suzhou = [];
@ -204,7 +204,7 @@ class OtherController extends CommonController
}
// 全国数据
$countryArea = Company::groupBy('company_city')->whereNotNull('company_city')->get(['company_city']);
$countryArea = Company::approvedStudents()->groupBy('company_city')->whereNotNull('company_city')->get(['company_city']);
$country = [];
foreach ($countryArea as $item) {
$total = User::whereHas('company', function ($query) use ($item) {
@ -494,31 +494,69 @@ class OtherController extends CommonController
break;
case 'course_signs_pass_unique':
// 审核通过人数去重明细 - 使用courseSignsTotalByUnique方法获取列表
// 审核通过人数去重明细 - 使用courseSignsTotalByUnique方法获取列表与coursesHome保持一致
$users = CourseSign::courseSignsTotalByUnique($start_date, $end_date, 1, $course_ids, true);
// 预加载 company 关系,避免 N+1 查询问题
$users->load('company');
foreach ($users as $user) {
// 获取该学员报名的课程列表与coursesHome逻辑保持一致
$userCourseSigns = CourseSign::where('user_id', $user->id)
// 获取该学员报名的课程列表 - 使用与getStudentList完全一致的逻辑
$userCourseSigns = CourseSign::where(function ($query) use ($course_ids) {
// status = 1
$query->where('status', 1);
// course_ids筛选
if ($course_ids && $course_ids->isNotEmpty()) {
$query->whereIn('course_id', $course_ids);
}
})
->whereHas('course', function ($query) use ($start_date, $end_date) {
$query->where('is_chart', 1);
// 开始结束日期的筛选。or查询
$query->whereBetween('start_date', [$start_date, $end_date])
->whereBetween('end_date', [$start_date, $end_date]);
})->where('status', 1)
->where(function ($query) use ($course_ids) {
if ($course_ids->isNotEmpty()) {
$query->whereIn('course_id', $course_ids);
if ($start_date && $end_date) {
$query->where(function ($q) use ($start_date, $end_date) {
$q->whereBetween('start_date', [$start_date, $end_date])
->orWhereBetween('end_date', [$start_date, $end_date]);
});
}
})->whereNotIn('status', [4, 5])
->with('course')
})
->whereNotIn('status', [4, 5, 6])
->where('user_id', $user->id)
->with(['course.typeDetail'])
->get();
$courseNames = $userCourseSigns->pluck('course.name')->filter()->unique()->implode("\n\r");
// 获取课程名称列表,用中文顿号分隔
$courseNames = $userCourseSigns->pluck('course.name')->filter()->unique()->values()->implode('、');
// 获取课程体系列表,用中文顿号分隔
$courseTypes = $userCourseSigns->pluck('course.typeDetail.name')
->filter()
->unique()
->values()
->implode('、');
// 企查查企业(来自 company 表)
$qccCompanyName = $user->company && $user->company->company_name
? $user->company->company_name
: '';
// 用户填写企业(来自 user 表)
$userCompanyName = $user->company_name ?? '';
// 优先使用 company 关系的企业信息,如果不存在则使用 User 表的字段
$companyArea = $user->company && $user->company->company_area
? $user->company->company_area
: ($user->company_area ?? '');
$companyIndustry = $user->company && $user->company->company_industry
? $user->company->company_industry
: ($user->company_industry ?? '');
$data[] = [
'user_name' => $user->name ?? '',
'mobile' => $user->mobile ?? '',
'company_name' => $user->company->company_name ?? '',
'company_area' => $user->company->company_area ?? '',
'company_industry' => $user->company->company_industry ?? '',
'qcc_company_name' => $qccCompanyName,
'user_company_name' => $userCompanyName,
'company_position' => $user->company_position ?? '',
'company_area' => $companyArea,
'company_industry' => $companyIndustry,
'course_types' => $courseTypes,
'course_names' => $courseNames,
'course_count' => $userCourseSigns->count(),
];
@ -526,9 +564,12 @@ class OtherController extends CommonController
$fields = [
'user_name' => '学员姓名',
'mobile' => '手机号',
'company_name' => '企业名称',
'qcc_company_name' => '企查查企业',
'user_company_name' => '用户填写企业',
'company_position' => '职务',
'company_area' => '所在区域',
'company_industry' => '所属行业',
'course_types' => '课程体系',
'course_names' => '报名课程',
'course_count' => '报名课程数',
];

@ -181,7 +181,7 @@ class OtherController extends CommonController
$sortType = $all['sort_type'] ?? 'asc';
// 构建基础查询
$query = Company::select('id', 'company_name', 'company_longitude', 'company_latitude', 'company_address')
$query = Company::approvedStudents()->select('id', 'company_name', 'company_longitude', 'company_latitude', 'company_address')
->where(function ($query) use ($all) {
if (isset($all['company_name'])) {
$query->where('company_name', 'like', '%' . $all['company_name'] . '%');

@ -24,6 +24,20 @@ class Company extends SoftDeletesModel
return $this->hasMany(User::class, 'company_id', 'id');
}
/**
* 限制只返回有关联学员且至少有一条审核通过的报名记录的公司
* 用于列表查询和统计查询
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeApprovedStudents($query)
{
return $query->whereHas('users', function ($q) {
$q->whereHas('courseSigns', function ($signQuery) {
$signQuery->where('status', 1);
});
});
}
/**
* 地址转经纬度
@ -70,7 +84,7 @@ class Company extends SoftDeletesModel
public static function yhInvestedTotal($end_date = null, $retList = false)
{
// 获取这些学员所在的被投企业
$companies = Company::where('is_yh_invested', 1)->get();
$companies = Company::approvedStudents()->where('is_yh_invested', 1)->get();
// 自定义时间:需要按被投时间筛选
// 筛选出被投时间在范围内的企业
$filteredCompanies = [];
@ -133,7 +147,7 @@ class Company extends SoftDeletesModel
}
// 获取这些公司中标记为被投的公司
$allInvestedCompanies = Company::where('is_yh_invested', 1)->get();
$allInvestedCompanies = Company::approvedStudents()->where('is_yh_invested', 1)->get();
// 筛选出被投时间在年份范围内的企业
$companies = [];
foreach ($allInvestedCompanies as $company) {

@ -185,7 +185,7 @@ class CourseSign extends SoftDeletesModel
$userIds = self::getStudentList($start_date, $end_date, 1, $course_ids)->get()->pluck('user_id');
// 获取这些学员所在的被投企业
$companies = Company::whereHas('users', function ($query) use ($userIds) {
$companies = Company::approvedStudents()->whereHas('users', function ($query) use ($userIds) {
$query->whereIn('id', $userIds);
})->where('is_yh_invested', 1)->get();
// 自定义时间:需要按被投时间筛选
@ -245,7 +245,7 @@ class CourseSign extends SoftDeletesModel
}
// 获取这些学员所在的被投企业
$companies = Company::whereHas('users', function ($query) use ($userIds) {
$companies = Company::approvedStudents()->whereHas('users', function ($query) use ($userIds) {
$query->whereIn('id', $userIds);
})->where('is_yh_invested', 1)->get();
// 自定义时间:需要按被投时间筛选
@ -311,7 +311,7 @@ class CourseSign extends SoftDeletesModel
}
// 获取这些公司中标记为被投的公司
$allInvestedCompanies = Company::whereIn('id', $companyIds)
$allInvestedCompanies = Company::approvedStudents()->whereIn('id', $companyIds)
->where('is_yh_invested', 1)
->get();
@ -542,7 +542,7 @@ class CourseSign extends SoftDeletesModel
$courseSignList = self::getStudentList($start_date, $end_date, $status, $course_ids);
// 地区
$suzhouArea = Company::where('company_city', '苏州市')->pluck('company_area')->unique();
$suzhouArea = Company::approvedStudents()->where('company_city', '苏州市')->pluck('company_area')->unique();
$list = [];
foreach ($suzhouArea as $area) {
$sourseSignList2 = (clone $courseSignList)->whereHas('user', function ($query) use ($area) {
@ -684,7 +684,7 @@ class CourseSign extends SoftDeletesModel
{
$courseSignsQuery = self::getStudentList($start_date, $end_date, 1, $course_ids);
$courseSignByType = $courseSignsQuery->get();
$list = Company::whereHas('users', function ($query) use ($courseSignByType) {
$list = Company::approvedStudents()->whereHas('users', function ($query) use ($courseSignByType) {
$query->whereIn('id', $courseSignByType->pluck('user_id'));
})->where('company_tag', 'like', '%' . '高新技术企业' . '%')->get();
if ($retList) {
@ -758,7 +758,7 @@ class CourseSign extends SoftDeletesModel
->toArray();
// 获取这些公司中标记为上市的公司
$companies = Company::whereIn('id', $companyIds)
$companies = Company::approvedStudents()->whereIn('id', $companyIds)
->where('company_market', 1)
->get()
->keyBy('id');

Loading…
Cancel
Save