master
cody 3 weeks ago
parent 33d2e19787
commit dd18a91847

@ -240,6 +240,20 @@ class OtherController extends CommonController
$list['course_total'] = $calendar->count();
// 开课天数
$list['course_day_total'] = $calendar->sum('days');
// 上市公司数(所有上市公司)
$list['company_market_total'] = Company::companyMarket($start_date, $end_date);
// 跟班学员数在指定时间范围内报名的学员中from为'跟班学员'的数量)
$course_ids = $courses->pluck('id');
$list['ganbu_total'] = CourseSign::ganbu($start_date, $end_date, $course_ids);
// 今年上市公司数量stock_date在今年
$list['company_market_year_total'] = Company::companyMarketYear($start_date, $end_date, $course_ids);
// 入学后上市公司数量(在指定时间范围内报名的学员所在公司中,在入学后上市的公司数量)
$list['company_market_after_enrollment_total'] = CourseSign::companyMarketAfterEnrollment($start_date, $end_date, $course_ids);
// 课程分类明细统计
$courseTypesSum = [];
$courseTypes = CourseType::whereIn('id', $course_type_id)->get();
@ -273,7 +287,7 @@ class OtherController extends CommonController
* tags={"其他"},
* summary="课程统计明细导出",
* description="导出课程统计数据的明细",
* @OA\Parameter(name="export_type", in="query", @OA\Schema(type="string"), required=true, description="导出类型invested_companies-被投企业明细, course_signs_total-报名人数明细, course_signs_pass-审核通过人数明细, course_signs_pass_unique-审核通过人数去重明细, course_types-课程分类明细, areas-区域明细"),
* @OA\Parameter(name="export_type", in="query", @OA\Schema(type="string"), required=true, description="导出类型invested_companies-被投企业明细, course_signs_total-报名人数明细, course_signs_pass-审核通过人数明细, course_signs_pass_unique-审核通过人数去重明细, course_types-课程分类明细, areas-区域明细, company_market-上市公司明细, ganbu-跟班学员明细, company_market_year-今年上市公司明细, company_market_after_enrollment-入学后上市公司明细"),
* @OA\Parameter(name="start_date", in="query", @OA\Schema(type="string"), required=false, description="开始日期"),
* @OA\Parameter(name="end_date", in="query", @OA\Schema(type="string"), required=false, description="结束日期"),
* @OA\Parameter(name="course_type_id", in="query", @OA\Schema(type="string"), required=false, description="课程体系id多个英文逗号"),
@ -468,6 +482,128 @@ class OtherController extends CommonController
$filename = '区域明细';
break;
case 'company_market':
// 上市公司明细 - 所有上市公司
$companies = Company::companyMarket($start_date, $end_date, true);
foreach ($companies as $company) {
$data[] = [
'company_name' => $company->company_name,
'company_legal_representative' => $company->company_legal_representative ?? '',
'company_date' => $company->company_date ?? '',
'stock_date' => $company->stock_date ?? '',
'company_address' => $company->company_address ?? '',
'company_city' => $company->company_city ?? '',
'company_area' => $company->company_area ?? '',
];
}
$fields = [
'company_name' => '企业名称',
'company_legal_representative' => '法人',
'company_date' => '成立时间',
'stock_date' => '上市日期',
'company_address' => '地址',
'company_city' => '营业范围',
'company_area' => '联系电话',
];
$filename = '上市公司明细';
break;
case 'ganbu':
// 跟班学员明细 - 使用模型方法
$users = CourseSign::ganbu($start_date, $end_date, $course_ids, true);
foreach ($users as $user) {
$userCourseSigns = CourseSign::where('user_id', $user->id)
->whereDate('created_at', '>=', $start_date)
->whereDate('created_at', '<=', $end_date)
->where(function ($query) use ($course_ids) {
if ($course_ids->isNotEmpty()) {
$query->whereIn('course_id', $course_ids);
}
})->whereNotIn('status', [4, 5])
->with('course')
->get();
$courseNames = $userCourseSigns->pluck('course.name')->filter()->unique()->implode('、');
$data[] = [
'user_name' => $user->name ?? '',
'mobile' => $user->mobile ?? '',
'company_name' => $user->company_name ?? '',
'company_area' => $user->company_area ?? '',
'company_industry' => $user->company_industry ?? '',
'course_names' => $courseNames,
'course_count' => $userCourseSigns->count(),
];
}
$fields = [
'user_name' => '学员姓名',
'mobile' => '手机号',
'company_name' => '企业名称',
'company_area' => '所在区域',
'company_industry' => '所属行业',
'course_names' => '报名课程',
'course_count' => '报名课程数',
];
$filename = '跟班学员明细';
break;
case 'company_market_year':
// 今年上市公司明细 - 使用模型方法
$companies = Company::companyMarketYear($start_date, $end_date,null, true);
foreach ($companies as $company) {
$data[] = [
'company_name' => $company->company_name,
'company_legal_representative' => $company->company_legal_representative ?? '',
'company_date' => $company->company_date ?? '',
'stock_date' => $company->stock_date ?? '',
'company_address' => $company->company_address ?? '',
'company_city' => $company->company_city ?? '',
'company_area' => $company->company_area ?? '',
];
}
$fields = [
'company_name' => '企业名称',
'company_legal_representative' => '法人',
'company_date' => '成立时间',
'stock_date' => '上市日期',
'company_address' => '地址',
'company_city' => '营业范围',
'company_area' => '联系电话',
];
$filename = '今年上市公司明细';
break;
case 'company_market_after_enrollment':
// 入学后上市公司明细 - 使用模型方法
$companiesAfterEnrollment = CourseSign::companyMarketAfterEnrollment($start_date, $end_date, $course_ids->toArray(), true);
foreach ($companiesAfterEnrollment as $item) {
$company = $item['company'];
$userNames = collect($item['users'])->pluck('name')->filter()->unique()->implode('、');
$data[] = [
'company_name' => $company->company_name,
'company_legal_representative' => $company->company_legal_representative ?? '',
'company_date' => $company->company_date ?? '',
'stock_date' => $company->stock_date ?? '',
'first_sign_date' => $item['first_sign_date'],
'user_names' => $userNames,
'company_address' => $company->company_address ?? '',
'company_city' => $company->company_city ?? '',
];
}
$fields = [
'company_name' => '企业名称',
'company_legal_representative' => '法人',
'company_date' => '成立时间',
'stock_date' => '上市日期',
'first_sign_date' => '首次报名时间',
'user_names' => '学员姓名',
'company_address' => '地址',
'company_city' => '所在城市',
];
$filename = '入学后上市公司明细';
break;
default:
return $this->fail([ResponseCode::ERROR_PARAMETER, '不支持的导出类型']);
}

@ -48,5 +48,52 @@ 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();
}
}
}

@ -164,5 +164,81 @@ class CourseSign extends SoftDeletesModel
}
}
/**
* 跟班学员(统计或列表)
* @param string $start_date 开始日期
* @param string $end_date 结束日期
* @param array|null $course_ids 课程ID数组不传则统计所有课程
* @param bool $retList 是否返回列表false返回数量true返回列表
* @return int|\Illuminate\Database\Eloquent\Collection
*/
public static function ganbu($start_date, $end_date, $course_ids = null, $retList = false)
{
$courseSignsForGanbu = self::whereDate('created_at', '>=', $start_date)
->whereDate('created_at', '<=', $end_date)
->where(function ($query) use ($course_ids) {
if ($course_ids) {
$query->whereIn('course_id', $course_ids);
}
})->whereNotIn('status', [4, 5])
->whereHas('user', function ($query) {
$query->where('from', '跟班学员');
})->get();
if ($retList) {
return User::whereIn('id', $courseSignsForGanbu->pluck('user_id'))->get();
} else {
return User::whereIn('id', $courseSignsForGanbu->pluck('user_id'))->count();
}
}
/**
* 入学后上市公司数量(在指定时间范围内报名的学员所在公司中,在入学后上市的公司数量)
* @param string $start_date 开始日期
* @param string $end_date 结束日期
* @param array|null $course_ids 课程ID数组不传则统计所有课程
* @param bool $retList 是否返回列表false返回数量true返回列表
* @return int|array
*/
public static function companyMarketAfterEnrollment($start_date, $end_date, $course_ids = null, $retList = false)
{
$courseSignsForStock = self::whereDate('created_at', '>=', $start_date)
->whereDate('created_at', '<=', $end_date)
->where(function ($query) use ($course_ids) {
if ($course_ids) {
$query->whereIn('course_id', $course_ids);
}
})->whereNotIn('status', [4, 5])
->with('user.company')
->get();
$companiesAfterEnrollment = [];
foreach ($courseSignsForStock as $sign) {
if ($sign->user && $sign->user->company && $sign->user->company->company_market == 1) {
$signDate = \Carbon\Carbon::parse($sign->created_at)->format('Y-m-d');
$stockDate = $sign->user->company->stock_date;
if ($stockDate && $stockDate >= $signDate) {
$companyId = $sign->user->company->id;
if (!isset($companiesAfterEnrollment[$companyId])) {
$companiesAfterEnrollment[$companyId] = [
'company' => $sign->user->company,
'first_sign_date' => $signDate,
'users' => [],
];
}
if ($retList) {
$companiesAfterEnrollment[$companyId]['users'][] = $sign->user;
}
}
}
}
if ($retList) {
return $companiesAfterEnrollment;
} else {
return count($companiesAfterEnrollment);
}
}
}

Loading…
Cancel
Save