From 50b1a06ac3104259a1132902be452e6ff30ad108 Mon Sep 17 00:00:00 2001 From: cody <648753004@qq.com> Date: Thu, 8 Jan 2026 09:21:26 +0800 Subject: [PATCH] update --- .../Controllers/Admin/CompanyController.php | 2 +- app/Http/Controllers/Admin/OtherController.php | 12 ++++++------ .../Controllers/Mobile/OtherController.php | 2 +- app/Models/Company.php | 18 ++++++++++++++++-- app/Models/CourseSign.php | 12 ++++++------ 5 files changed, 30 insertions(+), 16 deletions(-) diff --git a/app/Http/Controllers/Admin/CompanyController.php b/app/Http/Controllers/Admin/CompanyController.php index ce6e261..3251dda 100644 --- a/app/Http/Controllers/Admin/CompanyController.php +++ b/app/Http/Controllers/Admin/CompanyController.php @@ -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); diff --git a/app/Http/Controllers/Admin/OtherController.php b/app/Http/Controllers/Admin/OtherController.php index 2c3738a..a3713ab 100755 --- a/app/Http/Controllers/Admin/OtherController.php +++ b/app/Http/Controllers/Admin/OtherController.php @@ -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) { diff --git a/app/Http/Controllers/Mobile/OtherController.php b/app/Http/Controllers/Mobile/OtherController.php index 58cb21c..03d6413 100755 --- a/app/Http/Controllers/Mobile/OtherController.php +++ b/app/Http/Controllers/Mobile/OtherController.php @@ -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'] . '%'); diff --git a/app/Models/Company.php b/app/Models/Company.php index c45044b..c817f36 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -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) { diff --git a/app/Models/CourseSign.php b/app/Models/CourseSign.php index 6db8b29..c2fe834 100755 --- a/app/Models/CourseSign.php +++ b/app/Models/CourseSign.php @@ -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');