master
cody 3 months ago
parent 3fafb5885a
commit 08fe80fa41

@ -1502,14 +1502,29 @@ class OtherController extends CommonController
// 获取该公司的学员信息(只包含有课程报名的学员) // 获取该公司的学员信息(只包含有课程报名的学员)
$userCourseSigns = collect($companyCourseSigns[$company->id] ?? []); $userCourseSigns = collect($companyCourseSigns[$company->id] ?? []);
// 公司基本信息(只在第一行使用)
$companyInfo = [
'company_name' => $company->company_name,
'company_legal_representative' => $company->company_legal_representative ?? '',
'company_date' => $company->company_date ?? '',
'company_address' => $company->company_address ?? '',
'company_city' => $company->company_city ?? '',
'company_area' => $company->company_area ?? '',
'company_tag' => $company->company_tag ?? '',
'business_scope' => $company->business_scope ?? '',
'contact_phone' => $company->contact_phone ?? '',
'contact_mail' => $company->contact_mail ?? '',
];
if ($userCourseSigns->isEmpty()) { if ($userCourseSigns->isEmpty()) {
// 如果没有学员,设置空值 // 如果没有学员,仍然导出公司基本信息
$userNamesStr = ''; $data[] = array_merge($companyInfo, [
$courseNamesStr = ''; 'user_name' => '',
$courseTypesStr = ''; 'course_names' => '',
$totalCourseCount = 0; 'course_types' => '',
'course_count' => 0,
]);
} else { } else {
// 按学员分组 // 按学员分组
$usersData = []; $usersData = [];
foreach ($userCourseSigns as $sign) { foreach ($userCourseSigns as $sign) {
@ -1526,59 +1541,60 @@ class OtherController extends CommonController
$usersData[$userId]['courseSigns'][] = $sign; $usersData[$userId]['courseSigns'][] = $sign;
} }
// 收集所有学员的姓名、课程名称、课程体系 // 每个学员一行
$userNames = []; $isFirstRow = true;
$allCourseNames = [];
$allCourseTypes = [];
$totalCourseCount = 0;
foreach ($usersData as $userData) { foreach ($usersData as $userData) {
$user = $userData['user']; $user = $userData['user'];
$courseSigns = collect($userData['courseSigns']); $courseSigns = collect($userData['courseSigns']);
if ($courseSigns->isNotEmpty()) { if ($courseSigns->isEmpty()) {
$userNames[] = $user->name ?? ''; continue;
}
// 收集课程名称 // 获取课程名称列表,用中文顿号分隔
$courseNames = $courseSigns->pluck('course.name')->filter()->unique()->values()->toArray(); $courseNames = $courseSigns->pluck('course.name')->filter()->unique()->values()->implode('、');
$allCourseNames = array_merge($allCourseNames, $courseNames);
// 收集课程体系 // 获取课程体系列表,用中文顿号分隔
$courseTypes = $courseSigns->pluck('course.typeDetail.name') $courseTypes = $courseSigns->pluck('course.typeDetail.name')
->filter() ->filter()
->unique() ->unique()
->values() ->values()
->toArray(); ->implode('、');
$allCourseTypes = array_merge($allCourseTypes, $courseTypes);
// 累计报名课程数
$totalCourseCount += $courseSigns->count();
}
}
// 去重并合并 // 报名课程数
$userNamesStr = implode('、', array_filter(array_unique($userNames))); $courseCount = $courseSigns->count();
$courseNamesStr = implode('、', array_filter(array_unique($allCourseNames)));
$courseTypesStr = implode('、', array_filter(array_unique($allCourseTypes)));
}
if ($isFirstRow) {
// 第一行:显示公司信息
$data[] = array_merge($companyInfo, [
'user_name' => $user->name ?? '',
'course_names' => $courseNames,
'course_types' => $courseTypes,
'course_count' => $courseCount,
]);
$isFirstRow = false;
} else {
// 后续行:公司信息为空
$data[] = [ $data[] = [
'company_name' => $company->company_name, 'company_name' => '',
'company_legal_representative' => $company->company_legal_representative ?? '', 'company_legal_representative' => '',
'company_date' => $company->company_date ?? '', 'company_date' => '',
'company_address' => $company->company_address ?? '', 'company_address' => '',
'company_city' => $company->company_city ?? '', 'company_city' => '',
'company_area' => $company->company_area ?? '', 'company_area' => '',
'company_tag' => $company->company_tag ?? '', 'company_tag' => '',
'business_scope' => $company->business_scope ?? '', 'business_scope' => '',
'contact_phone' => $company->contact_phone ?? '', 'contact_phone' => '',
'contact_mail' => $company->contact_mail ?? '', 'contact_mail' => '',
'user_names' => $userNamesStr, 'user_name' => $user->name ?? '',
'course_names' => $courseNamesStr, 'course_names' => $courseNames,
'course_types' => $courseTypesStr, 'course_types' => $courseTypes,
'course_count' => $totalCourseCount, 'course_count' => $courseCount,
]; ];
} }
}
}
}
$fields = [ $fields = [
'company_name' => '企业名称', 'company_name' => '企业名称',
'company_legal_representative' => '法人', 'company_legal_representative' => '法人',
@ -1590,7 +1606,7 @@ class OtherController extends CommonController
'business_scope' => '营业范围', 'business_scope' => '营业范围',
'contact_phone' => '联系电话', 'contact_phone' => '联系电话',
'contact_mail' => '联系邮箱', 'contact_mail' => '联系邮箱',
'user_names' => '学员姓名', 'user_name' => '学员姓名',
'course_names' => '课程名称', 'course_names' => '课程名称',
'course_types' => '课程体系', 'course_types' => '课程体系',
'course_count' => '报名课程数', 'course_count' => '报名课程数',

@ -122,80 +122,6 @@ execute_git_operations() {
done done
fi fi
# 执行 git pull 的函数
do_git_pull() {
local password="$1"
local remote="$2"
local branch="$3"
local temp_output=$(mktemp)
# 使用 tee 同时输出到终端和文件,以便后续检查错误
expect << EOF 2>&1 | tee "$temp_output"
set timeout 30
spawn git pull $remote $branch
expect {
"Password:" {
send "$password\r"
exp_continue
}
"password:" {
send "$password\r"
exp_continue
}
"passphrase:" {
send "$password\r"
exp_continue
}
"Username:" {
exp_continue
}
"Authentication failed" {
exp_continue
}
"Permission denied" {
exp_continue
}
"Merge conflict" {
exp_continue
}
"CONFLICT" {
exp_continue
}
eof {
catch wait result
set exit_code [lindex \$result 3]
exit \$exit_code
}
timeout {
exit 1
}
}
EOF
local exit_code=$?
local output=$(cat "$temp_output" 2>/dev/null)
rm -f "$temp_output"
# 检查退出码和输出中的错误信息
if [ $exit_code -ne 0 ]; then
return 1
fi
# 检查是否有合并冲突
if echo "$output" | grep -qiE "(CONFLICT|merge conflict|Automatic merge failed)"; then
echo ""
echo "⚠️ 检测到合并冲突,请手动解决冲突后再执行脚本"
return 2
fi
# 检查输出中是否包含认证失败相关的错误
if echo "$output" | grep -qiE "(Authentication failed|Permission denied|fatal:.*authentication|error:.*authentication)"; then
return 1
fi
return 0
}
# 执行 git push 的函数 # 执行 git push 的函数
do_git_push() { do_git_push() {
local password="$1" local password="$1"
@ -264,80 +190,29 @@ EOF
return 0 return 0
} }
# 先执行 pull执行 push # 执行 push
echo "" echo ""
echo "==========================================" echo "=========================================="
echo "步骤 1: 执行 git pull" echo "执行 git push"
echo "==========================================" echo "=========================================="
echo "" echo ""
# 使用局部变量保存当前使用的密码 # 使用局部变量保存当前使用的密码
local current_password="$PASSWORD" local current_password="$PASSWORD"
local pull_success=0
# 首先尝试使用默认密码 pull
echo "尝试使用默认密码执行: git pull $selected_remote $current_branch"
if do_git_pull "$current_password" "$selected_remote" "$current_branch"; then
pull_success=1
echo ""
echo "✅ Pull 成功(使用默认密码)"
else
local pull_result=$?
# 如果是认证失败,提示用户输入密码
if [ $pull_result -eq 1 ]; then
echo ""
echo "⚠️ 默认密码 pull 失败(可能是密码错误),请手动输入密码"
echo ""
read -sp "请输入 Git 密码: " user_password
echo ""
echo ""
echo "使用您输入的密码重新执行: git pull $selected_remote $current_branch"
if do_git_pull "$user_password" "$selected_remote" "$current_branch"; then
pull_success=1
current_password="$user_password"
echo ""
echo "✅ Pull 成功(使用手动输入的密码)"
else
pull_result=$?
if [ $pull_result -eq 2 ]; then
# 合并冲突
echo ""
echo "❌ Pull 失败:存在合并冲突,请手动解决后重试"
return 1
else
echo ""
echo "❌ Pull 失败,请检查密码和网络连接"
return 1
fi
fi
elif [ $pull_result -eq 2 ]; then
# 合并冲突
echo ""
echo "❌ Pull 失败:存在合并冲突,请手动解决后重试"
return 1
else
echo ""
echo "❌ Pull 失败,请检查网络连接"
return 1
fi
fi
# Pull 成功后执行 push # 首先尝试使用默认密码 push
echo "执行: git push $selected_remote $current_branch (使用默认密码)"
if do_git_push "$current_password" "$selected_remote" "$current_branch"; then
echo "" echo ""
echo "==========================================" echo "=========================================="
echo "步骤 2: 执行 git push" echo "执行结果"
echo "==========================================" echo "=========================================="
echo "✅ Push: 成功"
echo "" echo ""
echo "执行: git push $selected_remote $current_branch" echo "✅ 仓库 $repo_path 提交完成!"
echo "=========================================="
local push_success=0
if do_git_push "$current_password" "$selected_remote" "$current_branch"; then
push_success=1
else else
# push 失败,如果之前使用的是默认密码,尝试让用户输入 # 默认密码失败,提示用户输入密码
if [ "$current_password" = "Git@2018" ]; then
echo "" echo ""
echo "⚠️ 默认密码 push 失败,请手动输入密码" echo "⚠️ 默认密码 push 失败,请手动输入密码"
echo "" echo ""
@ -347,33 +222,25 @@ EOF
echo "使用您输入的密码重新执行: git push $selected_remote $current_branch" echo "使用您输入的密码重新执行: git push $selected_remote $current_branch"
if do_git_push "$user_password" "$selected_remote" "$current_branch"; then if do_git_push "$user_password" "$selected_remote" "$current_branch"; then
push_success=1
fi
fi
fi
# 显示最终结果
echo "" echo ""
echo "==========================================" echo "=========================================="
echo "执行结果" echo "执行结果"
echo "==========================================" echo "=========================================="
if [ $pull_success -eq 1 ] && [ $push_success -eq 1 ]; then
echo "✅ Pull: 成功"
echo "✅ Push: 成功" echo "✅ Push: 成功"
echo "" echo ""
echo "✅ 仓库 $repo_path 所有操作完成!" echo "✅ 仓库 $repo_path 提交完成!"
elif [ $pull_success -eq 1 ] && [ $push_success -eq 0 ]; then echo "=========================================="
echo "✅ Pull: 成功"
echo "❌ Push: 失败"
echo ""
echo "⚠️ 仓库 $repo_path Pull 成功,但 Push 失败,请检查密码和网络连接"
else else
echo "❌ Pull: 失败"
echo "❌ Push: 未执行"
echo "" echo ""
echo "❌ 仓库 $repo_path Pull 失败Push 未执行"
fi
echo "==========================================" echo "=========================================="
echo "执行结果"
echo "=========================================="
echo "❌ Push: 失败"
echo ""
echo "❌ 仓库 $repo_path push 失败,请检查密码和网络连接"
echo "=========================================="
fi
fi
echo "" echo ""
} }

Loading…
Cancel
Save