|
|
|
|
@ -227,6 +227,8 @@ class CompanyController extends BaseController
|
|
|
|
|
})->orderBy($all['sort_name'] ?? 'id', $all['sort_type'] ?? 'desc');
|
|
|
|
|
if (isset($all['is_export']) && !empty($all['is_export'])) {
|
|
|
|
|
$list = $list->get()->toArray();
|
|
|
|
|
// 为每个公司添加"是否校友企业"字段(导出时)
|
|
|
|
|
$this->addIsSchoolmateCompanyField($list);
|
|
|
|
|
return Excel::download(new CommonExport($list, $all['export_fields'] ?? ''), $all['file_name'] ?? '' . date('YmdHis') . '.xlsx');
|
|
|
|
|
} else {
|
|
|
|
|
// 输出
|
|
|
|
|
@ -271,6 +273,16 @@ class CompanyController extends BaseController
|
|
|
|
|
|
|
|
|
|
// 将统计数据添加到返回结果中
|
|
|
|
|
$result = $list->toArray();
|
|
|
|
|
|
|
|
|
|
// 为每个公司添加"是否校友企业"字段
|
|
|
|
|
if (isset($result['data']) && is_array($result['data'])) {
|
|
|
|
|
// 分页数据,处理 data 数组
|
|
|
|
|
$this->addIsSchoolmateCompanyField($result['data']);
|
|
|
|
|
} elseif (is_array($result) && !isset($result['data'])) {
|
|
|
|
|
// 如果不是分页数据,直接处理数组
|
|
|
|
|
$this->addIsSchoolmateCompanyField($result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$result['statistics'] = $statistics;
|
|
|
|
|
return $this->success($result);
|
|
|
|
|
}
|
|
|
|
|
@ -398,4 +410,29 @@ class CompanyController extends BaseController
|
|
|
|
|
return parent::destroy();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 为公司数组添加"是否校友企业"字段
|
|
|
|
|
* @param array $companies 公司数组(引用传递)
|
|
|
|
|
*/
|
|
|
|
|
private function addIsSchoolmateCompanyField(&$companies)
|
|
|
|
|
{
|
|
|
|
|
foreach ($companies as &$company) {
|
|
|
|
|
if (!is_array($company)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
$isSchoolmateCompany = 0;
|
|
|
|
|
if (isset($company['users']) && is_array($company['users'])) {
|
|
|
|
|
// 检查该企业下的用户中是否有校友(is_schoolmate = 1)
|
|
|
|
|
foreach ($company['users'] as $user) {
|
|
|
|
|
if (isset($user['is_schoolmate']) && $user['is_schoolmate'] == 1) {
|
|
|
|
|
$isSchoolmateCompany = 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$company['is_schoolmate_company'] = $isSchoolmateCompany;
|
|
|
|
|
}
|
|
|
|
|
unset($company); // 释放引用
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|