master
cody 3 months ago
parent 0fc587be15
commit 50b1a06ac3

@ -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) {

@ -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