master
cody 3 weeks ago
parent e50b733bd2
commit 33d2e19787

@ -230,7 +230,7 @@ class OtherController extends CommonController
// 被投企业数
$list['course_signs_invested'] = CourseSign::yhInvested($start_date, $end_date);
// 报名人数
$list['course_signs_total'] = CourseSign::courseSignsTotal($start_date, $end_date);
$list['course_signs_total'] = CourseSign::courseSignsTotal($start_date, $end_date, null, $courses->pluck('id'));
// 审核通过人数
$list['course_signs_pass'] = CourseSign::courseSignsTotal($start_date, $end_date, 1, $courses->pluck('id'));
// 审核通过人数去重
@ -245,8 +245,7 @@ class OtherController extends CommonController
$courseTypes = CourseType::whereIn('id', $course_type_id)->get();
foreach ($courseTypes as $courseType) {
// 获取课程
$courses2 = Course::where('type', $courseType->id)
->get();
$courses2 = Course::where('type', $courseType->id)->get();
foreach ($courses2 as $course) {
$courseTypesSum[] = [
'course_type' => $courseType->name,
@ -307,39 +306,31 @@ class OtherController extends CommonController
switch ($export_type) {
case 'invested_companies':
// 被投企业明细 - 使用与coursesHome相同的算法
$courseSigns = CourseSign::whereDate('created_at', '>=', $start_date)
->whereDate('created_at', '<=', $end_date)
->whereNotIn('status', [4, 5])
->get();
$userIds = $courseSigns->pluck('user_id');
$companies = Company::whereHas('users', function ($query) use ($userIds) {
$query->whereIn('id', $userIds);
})->where('is_yh_invested', 1)->get();
$companies = CourseSign::yhInvested($start_date, $end_date, true);
foreach ($companies as $company) {
$data[] = [
'company_name' => $company->company_name,
'company_city' => $company->company_city ?? '',
'company_area' => $company->company_area ?? '',
'company_industry' => $company->company_industry ?? '',
'company_fund' => $company->company_fund ?? 0,
'valuation' => $company->valuation ?? 0,
'company_legal_representative' => $company->company_legal_representative ?? '',
'company_date' => $company->company_date ?? '',
'company_address' => $company->company_address ?? '',
'business_scope' => $company->business_scope ?? '',
'contact_phone' => $company->contact_phone ?? '',
];
}
$fields = [
'company_name' => '企业名称',
'company_city' => '所在城市',
'company_area' => '所在区域',
'company_industry' => '所属行业',
'company_fund' => '融资额',
'valuation' => '估值',
'company_legal_representative' => '法人',
'company_date' => '成立时间',
'company_address' => '地址',
'business_scope' => '营业范围',
'contact_phone' => '联系电话',
];
$filename = '被投企业明细';
break;
case 'course_signs_total':
// 报名人数明细 - 使用courseSignsTotal方法获取列表与coursesHome算法一致
$courseSigns = CourseSign::courseSignsTotal($start_date, $end_date, null, $course_ids->isNotEmpty() ? $course_ids : null, null, true);
$courseSigns = CourseSign::courseSignsTotal($start_date, $end_date, null, $course_ids, null, true);
// 加载关联关系
$courseSigns->load(['user', 'course']);
@ -368,7 +359,7 @@ class OtherController extends CommonController
case 'course_signs_pass':
// 审核通过人数明细 - 使用courseSignsTotal方法获取列表与coursesHome算法一致
$courseSigns = CourseSign::courseSignsTotal($start_date, $end_date, 1, $course_ids->isNotEmpty() ? $course_ids : null, null, true);
$courseSigns = CourseSign::courseSignsTotal($start_date, $end_date, 1, $course_ids, null, true);
// 加载关联关系
$courseSigns->load(['user', 'course']);
@ -395,7 +386,7 @@ class OtherController extends CommonController
case 'course_signs_pass_unique':
// 审核通过人数去重明细 - 使用courseSignsTotalByUnique方法获取列表
$users = CourseSign::courseSignsTotalByUnique($start_date, $end_date, 1, $course_ids->isNotEmpty() ? $course_ids : null, null, true);
$users = CourseSign::courseSignsTotalByUnique($start_date, $end_date, 1, $course_ids, null, true);
foreach ($users as $user) {
// 获取该学员报名的课程列表与coursesHome逻辑保持一致
@ -407,8 +398,7 @@ class OtherController extends CommonController
if ($course_ids->isNotEmpty()) {
$query->whereIn('course_id', $course_ids);
}
})
->whereNotIn('status', [4, 5])
})->whereNotIn('status', [4, 5])
->with('course')
->get();
$courseNames = $userCourseSigns->pluck('course.name')->filter()->unique()->implode('、');

@ -146,15 +146,22 @@ class CourseSign extends SoftDeletesModel
/**
* 指定时间内的被投企业
*/
public static function yhInvested($start_date, $end_date)
public static function yhInvested($start_date, $end_date, $retList = false)
{
$courseSignByType = CourseSign::whereDate('created_at', '>=', $start_date)
->whereDate('created_at', '<=', $end_date)
->whereNotIn('status', [4, 5])
->get();
return Company::whereHas('users', function ($query) use ($courseSignByType) {
$list = Company::whereHas('users', function ($query) use ($courseSignByType) {
$query->whereIn('id', $courseSignByType->pluck('user_id'));
})->where('is_yh_invested', 1)->count();
})->where('is_yh_invested', 1)->get();
if ($retList) {
// 返回列表
return $list;
} else {
// 返回统计数据
return $list->count();
}
}
}

Loading…
Cancel
Save