master
cody 3 months ago
parent 3fafb5885a
commit 08fe80fa41

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

@ -122,80 +122,6 @@ execute_git_operations() {
done
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 的函数
do_git_push() {
local password="$1"
@ -264,117 +190,58 @@ EOF
return 0
}
# 先执行 pull执行 push
# 执行 push
echo ""
echo "=========================================="
echo "步骤 1: 执行 git pull"
echo "执行 git push"
echo "=========================================="
echo ""
# 使用局部变量保存当前使用的密码
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
# 首先尝试使用默认密码 push
echo "执行: git push $selected_remote $current_branch (使用默认密码)"
if do_git_push "$current_password" "$selected_remote" "$current_branch"; then
echo ""
echo "✅ Pull 成功(使用默认密码)"
echo "=========================================="
echo "执行结果"
echo "=========================================="
echo "✅ Push: 成功"
echo ""
echo "✅ 仓库 $repo_path 提交完成!"
echo "=========================================="
else
local pull_result=$?
# 默认密码失败,提示用户输入密码
echo ""
echo "⚠️ 默认密码 push 失败,请手动输入密码"
echo ""
read -sp "请输入 Git 密码: " user_password
echo ""
echo ""
echo "使用您输入的密码重新执行: git push $selected_remote $current_branch"
# 如果是认证失败,提示用户输入密码
if [ $pull_result -eq 1 ]; then
echo ""
echo "⚠️ 默认密码 pull 失败(可能是密码错误),请手动输入密码"
echo ""
read -sp "请输入 Git 密码: " user_password
if do_git_push "$user_password" "$selected_remote" "$current_branch"; then
echo ""
echo "=========================================="
echo "执行结果"
echo "=========================================="
echo "✅ Push: 成功"
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
echo "✅ 仓库 $repo_path 提交完成!"
echo "=========================================="
else
echo ""
echo "❌ Pull 失败,请检查网络连接"
return 1
fi
fi
# Pull 成功后执行 push
echo ""
echo "=========================================="
echo "步骤 2: 执行 git push"
echo "=========================================="
echo ""
echo "执行: git push $selected_remote $current_branch"
local push_success=0
if do_git_push "$current_password" "$selected_remote" "$current_branch"; then
push_success=1
else
# push 失败,如果之前使用的是默认密码,尝试让用户输入
if [ "$current_password" = "Git@2018" ]; then
echo ""
echo "⚠️ 默认密码 push 失败,请手动输入密码"
echo ""
read -sp "请输入 Git 密码: " user_password
echo ""
echo "=========================================="
echo "执行结果"
echo "=========================================="
echo "❌ Push: 失败"
echo ""
echo "使用您输入的密码重新执行: git push $selected_remote $current_branch"
if do_git_push "$user_password" "$selected_remote" "$current_branch"; then
push_success=1
fi
echo "❌ 仓库 $repo_path push 失败,请检查密码和网络连接"
echo "=========================================="
fi
fi
# 显示最终结果
echo ""
echo "=========================================="
echo "执行结果"
echo "=========================================="
if [ $pull_success -eq 1 ] && [ $push_success -eq 1 ]; then
echo "✅ Pull: 成功"
echo "✅ Push: 成功"
echo ""
echo "✅ 仓库 $repo_path 所有操作完成!"
elif [ $pull_success -eq 1 ] && [ $push_success -eq 0 ]; then
echo "✅ Pull: 成功"
echo "❌ Push: 失败"
echo ""
echo "⚠️ 仓库 $repo_path Pull 成功,但 Push 失败,请检查密码和网络连接"
else
echo "❌ Pull: 失败"
echo "❌ Push: 未执行"
echo ""
echo "❌ 仓库 $repo_path Pull 失败Push 未执行"
fi
echo "=========================================="
echo ""
}

Loading…
Cancel
Save