diff --git a/app/Http/Controllers/Admin/OtherController.php b/app/Http/Controllers/Admin/OtherController.php index fa52e88..ee2cea3 100755 --- a/app/Http/Controllers/Admin/OtherController.php +++ b/app/Http/Controllers/Admin/OtherController.php @@ -245,14 +245,14 @@ class OtherController extends CommonController $list['course_day_total'] = (clone $calendar)->where('is_count_days', 1)->sum('days'); // 上市公司数(所有上市公司) - $list['company_market_total'] = Company::companyMarket($start_date, $end_date); + $list['company_market_total'] = CourseSign::shangshi($start_date, $end_date); // 跟班学员数(在指定时间范围内报名的学员中,from为'跟班学员'的数量) $course_ids = $courses->pluck('id'); $list['ganbu_total'] = CourseSign::genban($start_date, $end_date, $course_ids); // 今年上市公司数量(stock_date在今年) - $list['company_market_year_total'] = Company::companyMarketYear($start_date, $end_date, $course_ids); + $list['company_market_year_total'] = CourseSign::companyMarketYear($start_date, $end_date, $course_ids); // 入学后上市公司数量(在指定时间范围内报名的学员所在公司中,在入学后上市的公司数量) $list['company_market_after_enrollment_total'] = CourseSign::companyMarketAfterEnrollment($start_date, $end_date, $course_ids); @@ -657,7 +657,7 @@ class OtherController extends CommonController case 'company_market_year_total': // 今年上市公司明细 - 使用模型方法 - $companies = Company::companyMarketYear($start_date, $end_date, $course_ids, true); + $companies = CourseSign::companyMarketYear($start_date, $end_date, $course_ids, true); foreach ($companies as $company) { $data[] = [ 'company_name' => $company->company_name, diff --git a/app/Models/Company.php b/app/Models/Company.php index a9feda8..e5a10b2 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -58,52 +58,4 @@ class Company extends SoftDeletesModel } } - /** - * 上市公司(统计或列表) - * @param bool $retList 是否返回列表,false返回数量,true返回列表 - * @return int|\Illuminate\Database\Eloquent\Collection - */ - public static function companyMarket($start_date, $end_date, $retList = false) - { - $courseSignByType = CourseSign::whereDate('created_at', '>=', $start_date) - ->whereDate('created_at', '<=', $end_date) - ->whereNotIn('status', [4, 5]) - ->get(); - $list = Company::whereHas('users', function ($query) use ($courseSignByType) { - $query->whereIn('id', $courseSignByType->pluck('user_id')); - })->where('company_market', 1)->get(); - if ($retList) { - // 返回列表 - return $list; - } else { - // 返回统计数据 - return $list->count(); - } - } - - /** - * 今年上市公司(统计或列表) - * @param int|null $year 年份,不传则使用当前年份 - * @param bool $retList 是否返回列表,false返回数量,true返回列表 - * @return int|\Illuminate\Database\Eloquent\Collection - */ - public static function companyMarketYear($start_date, $end_date, $course_ids, $retList = false) - { - $year = date('Y'); - $courseSignByType = CourseSign::whereDate('created_at', '>=', $start_date) - ->whereDate('created_at', '<=', $end_date) - ->whereNotIn('status', [4, 5]) - ->get(); - $list = Company::whereHas('users', function ($query) use ($courseSignByType) { - $query->whereIn('id', $courseSignByType->pluck('user_id')); - })->where('company_market', 1)->whereYear('stock_date', $year)->get(); - if ($retList) { - // 返回列表 - return $list; - } else { - // 返回统计数据 - return $list->count(); - } - } - } diff --git a/app/Models/CourseSign.php b/app/Models/CourseSign.php index d6a47c7..731a1ad 100755 --- a/app/Models/CourseSign.php +++ b/app/Models/CourseSign.php @@ -511,5 +511,27 @@ class CourseSign extends SoftDeletesModel } + /** + * 今年上市公司(统计或列表) + * @param int|null $year 年份,不传则使用当前年份 + * @param bool $retList 是否返回列表,false返回数量,true返回列表 + * @return int|\Illuminate\Database\Eloquent\Collection + */ + public static function companyMarketYear($start_date, $end_date, $course_ids, $retList = false) + { + $courseSignsQuery = self::getStudentList($start_date, $end_date, 1, $course_ids); + $year = date('Y'); + $list = Company::whereHas('users', function ($query) use ($courseSignsQuery) { + $query->whereIn('id', $courseSignsQuery->get()->pluck('user_id')); + })->where('company_market', 1)->whereYear('stock_date', $year)->get(); + if ($retList) { + // 返回列表 + return $list; + } else { + // 返回统计数据 + return $list->count(); + } + } + }