diff --git a/app/Http/Controllers/Admin/OtherController.php b/app/Http/Controllers/Admin/OtherController.php index b73a9a7..1979528 100755 --- a/app/Http/Controllers/Admin/OtherController.php +++ b/app/Http/Controllers/Admin/OtherController.php @@ -343,7 +343,7 @@ class OtherController extends CommonController // 苏州高层次人才 $list['cover_rencai_total'] = CourseSign::rencai($start_date, $end_date, $course_ids); // 苏州重点上市公司 - $list['cover_stock_total'] = CourseSign::shangshi($start_date, $end_date, $course_ids); + $list['cover_stock_total'] = CourseSign::suzhoushangshi($start_date, $end_date, $course_ids); // 课程分类明细统计 diff --git a/app/Models/CourseSign.php b/app/Models/CourseSign.php index 4bd5c41..7836291 100755 --- a/app/Models/CourseSign.php +++ b/app/Models/CourseSign.php @@ -848,6 +848,88 @@ class CourseSign extends SoftDeletesModel $courseSignsQuery = self::getStudentList($start_date, $end_date, 1, $course_ids); $courseSigns = $courseSignsQuery->with(['user.company', 'course.typeDetail'])->get(); + // 获取所有上市公司的ID + $companyIds = $courseSigns->pluck('user.company.id') + ->filter() + ->unique() + ->toArray(); + + // 获取这些公司中标记为上市的公司 + $companies = Company::approvedStudents()->whereIn('id', $companyIds) + ->where('company_market', 1) + ->get() + ->keyBy('id'); + + if ($retList) { + // 返回详细列表:主表是公司,子数据是学员信息 + $result = []; + foreach ($courseSigns as $courseSign) { + if (!$courseSign->user || !$courseSign->user->company) { + continue; + } + + $companyId = $courseSign->user->company->id; + // 只处理上市公司的记录 + if (!isset($companies[$companyId])) { + continue; + } + + $company = $companies[$companyId]; + + // 如果公司还没有在结果中,初始化 + if (!isset($result[$companyId])) { + $result[$companyId] = [ + 'company' => $company, + 'users' => [], + ]; + } + + // 按学员分组,收集每个学员的课程信息 + $userId = $courseSign->user->id; + if (!isset($result[$companyId]['users'][$userId])) { + $result[$companyId]['users'][$userId] = [ + 'user' => $courseSign->user, + 'user_name' => $courseSign->user->name ?? '', + 'mobile' => $courseSign->user->mobile ?? '', + 'courses' => [], + ]; + } + + // 添加该学员的课程信息 + $result[$companyId]['users'][$userId]['courses'][] = [ + 'course_name' => $courseSign->course->name ?? '', + 'course_type' => $courseSign->course->typeDetail->name ?? '', + 'course_sign' => $courseSign, + ]; + } + + // 将 users 转换为数组(去掉 user_id 作为 key) + foreach ($result as $companyId => $item) { + $result[$companyId]['users'] = array_values($item['users']); + } + + // 转换为数组并返回 + return array_values($result); + } else { + // 返回统计数据 + return $companies->count(); + } + } + + + /** + * 苏州上市公司(统计或列表) + * @param string|null $start_date 开始日期 + * @param string|null $end_date 结束日期 + * @param array|null $course_ids 课程ID数组,不传则统计所有课程 + * @param bool $retList 是否返回列表,false返回数量,true返回列表(包含学员、课程信息) + * @return int|array + */ + public static function suzhoushangshi($start_date = null, $end_date = null, $course_ids = null, $retList = false) + { + $courseSignsQuery = self::getStudentList($start_date, $end_date, 1, $course_ids); + $courseSigns = $courseSignsQuery->with(['user.company', 'course.typeDetail'])->get(); + // 获取所有上市公司的ID $companyIds = $courseSigns->pluck('user.company.id') ->filter()