diff --git a/app/Http/Controllers/Admin/OtherController.php b/app/Http/Controllers/Admin/OtherController.php index 8d981a6..a2dd62c 100755 --- a/app/Http/Controllers/Admin/OtherController.php +++ b/app/Http/Controllers/Admin/OtherController.php @@ -894,78 +894,24 @@ class OtherController extends CommonController break; case 'company_market_year_total': - // 今年上市公司明细 - 所有今年上市公司,关联学员、课程信息 - // 数据结构:主表是公司,子数据是学员信息 - // 导出时:公司信息只在第一行显示,后续行公司信息为空 - $companiesData = CourseSign::companyMarketYear($start_date, $end_date, $course_ids->toArray(), true); + // 今年上市公司明细 - 从stock_companys表获取,与coursesHome统计逻辑保持一致 + $currentYear = date('Y'); + $stockCompanies = StockCompany::whereYear('stock_date', $currentYear)->get(); - foreach ($companiesData as $item) { - $company = $item['company']; - $users = $item['users'] ?? []; + foreach ($stockCompanies as $stockCompany) { + // 通过公司名称关联到Company表获取详细信息 + $company = Company::where('company_name', $stockCompany->company_name)->first(); - // 公司基本信息(只在第一行使用) - $companyInfo = [ - 'company_name' => $company->company_name, + $data[] = [ + 'company_name' => $stockCompany->company_name, 'company_legal_representative' => $company->company_legal_representative ?? '', 'company_date' => $company->company_date ?? '', - 'stock_date' => $company->stock_date ?? '', + 'stock_date' => $stockCompany->stock_date ?? '', 'company_address' => $company->company_address ?? '', 'company_city' => $company->company_city ?? '', 'company_area' => $company->company_area ?? '', 'company_tag' => $company->company_tag ?? '', ]; - - if (empty($users)) { - // 如果没有学员报名记录,仍然导出公司基本信息 - $data[] = array_merge($companyInfo, [ - 'user_name' => '', - 'course_name' => '', - 'course_type' => '', - ]); - } else { - // 每个学员一行,多个课程合并显示 - $isFirstRow = true; - foreach ($users as $userInfo) { - $courses = $userInfo['courses'] ?? []; - - // 合并同一学员的多个课程:格式为"课程体系-课程名称,课程体系-课程名称" - $courseList = []; - foreach ($courses as $courseInfo) { - $courseType = $courseInfo['course_type'] ?? ''; - $courseName = $courseInfo['course_name'] ?? ''; - if ($courseType && $courseName) { - $courseList[] = $courseType . '-' . $courseName; - } elseif ($courseName) { - $courseList[] = $courseName; - } - } - $courseDisplay = implode("\r\n", $courseList); - - if ($isFirstRow) { - // 第一行:显示公司信息 - $data[] = array_merge($companyInfo, [ - 'user_name' => $userInfo['user_name'] ?? '', - 'course_name' => $courseDisplay, - 'course_type' => '', // 课程类型已合并到课程名称中 - ]); - $isFirstRow = false; - } else { - // 后续行:公司信息为空 - $data[] = [ - 'company_name' => '', - 'company_legal_representative' => '', - 'company_date' => '', - 'stock_date' => '', - 'company_address' => '', - 'company_city' => '', - 'company_area' => '', - 'company_tag' => '', - 'user_name' => $userInfo['user_name'] ?? '', - 'course_name' => $courseDisplay, - ]; - } - } - } } $fields = [ 'company_name' => '企业名称', @@ -976,26 +922,24 @@ class OtherController extends CommonController 'company_city' => '所在城市', 'company_area' => '所在区域', 'company_tag' => '企业资质', - 'user_name' => '学员姓名', - 'course_name' => '课程信息', ]; $filename = '今年上市公司明细'; break; case 'company_market_after_enrollment_total': - // 入学后上市公司明细 - 使用模型方法 - $companiesAfterEnrollment = CourseSign::companyMarketAfterEnrollment($start_date, $end_date, $course_ids, true); + // 入学后上市公司明细 - 从stock_companys表获取,与coursesHome统计逻辑保持一致 + $stockCompanies = StockCompany::where('is_after_enrollment', 1)->get(); + + foreach ($stockCompanies as $stockCompany) { + // 通过公司名称关联到Company表获取详细信息 + $company = Company::where('company_name', $stockCompany->company_name)->first(); - foreach ($companiesAfterEnrollment as $item) { - $company = $item['company']; - $userNames = collect($item['users'])->pluck('name')->filter()->unique()->implode("\n\r"); $data[] = [ - 'company_name' => $company->company_name, + 'company_name' => $stockCompany->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, + 'stock_date' => $stockCompany->stock_date ?? '', + 'enrollment_date' => $stockCompany->enrollment_date ?? '', 'company_address' => $company->company_address ?? '', 'company_city' => $company->company_city ?? '', ]; @@ -1005,8 +949,7 @@ class OtherController extends CommonController 'company_legal_representative' => '法人', 'company_date' => '成立时间', 'stock_date' => '上市日期', - 'first_sign_date' => '首次报名时间', - 'user_names' => '学员姓名', + 'enrollment_date' => '入学时间', 'company_address' => '地址', 'company_city' => '所在城市', ];