|
|
|
@ -318,16 +318,23 @@ class UpdateUserFromCourseSign extends Command
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 获取该课程的表单字段配置
|
|
|
|
// 获取该课程的表单字段配置,建立 field -> belong_user_table 的映射关系
|
|
|
|
$courseForms = CourseForm::where('course_id', $courseSign->course_id)
|
|
|
|
$courseForms = CourseForm::where('course_id', $courseSign->course_id)
|
|
|
|
->where('belong_user', 1) // 只获取属于用户信息的字段
|
|
|
|
->where('belong_user', 1) // 只获取属于用户信息的字段
|
|
|
|
->pluck('field')
|
|
|
|
->whereNotNull('belong_user_table') // 必须有对应的用户表字段
|
|
|
|
->toArray();
|
|
|
|
->where('belong_user_table', '!=', '') // 用户表字段不能为空
|
|
|
|
|
|
|
|
->get(['field', 'belong_user_table']);
|
|
|
|
|
|
|
|
|
|
|
|
if (empty($courseForms)) {
|
|
|
|
if ($courseForms->isEmpty()) {
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 建立 field -> belong_user_table 的映射关系
|
|
|
|
|
|
|
|
$fieldMapping = [];
|
|
|
|
|
|
|
|
foreach ($courseForms as $form) {
|
|
|
|
|
|
|
|
$fieldMapping[$form->field] = $form->belong_user_table;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 将 data 数组转换为以 field 为 key 的关联数组
|
|
|
|
// 将 data 数组转换为以 field 为 key 的关联数组
|
|
|
|
$dataArray = [];
|
|
|
|
$dataArray = [];
|
|
|
|
foreach ($courseSign->data as $item) {
|
|
|
|
foreach ($courseSign->data as $item) {
|
|
|
|
@ -336,16 +343,16 @@ class UpdateUserFromCourseSign extends Command
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 提取属于用户信息的字段
|
|
|
|
// 提取属于用户信息的字段,使用 belong_user_table 作为用户表的字段名
|
|
|
|
foreach ($courseForms as $field) {
|
|
|
|
foreach ($fieldMapping as $field => $userTableField) {
|
|
|
|
if (isset($dataArray[$field]) && $dataArray[$field] !== null && $dataArray[$field] !== '') {
|
|
|
|
if (isset($dataArray[$field]) && $dataArray[$field] !== null && $dataArray[$field] !== '') {
|
|
|
|
// 如果字段已经在 $userData 中,且新值不为空,则更新(优先使用非空值)
|
|
|
|
// 如果字段已经在 $userData 中,且新值不为空,则更新(优先使用非空值)
|
|
|
|
if (!isset($userData[$field]) || empty($userData[$field])) {
|
|
|
|
if (!isset($userData[$userTableField]) || empty($userData[$userTableField])) {
|
|
|
|
$userData[$field] = $dataArray[$field];
|
|
|
|
$userData[$userTableField] = $dataArray[$field];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 检查是否是公司名字
|
|
|
|
// 检查是否是公司名字
|
|
|
|
if ($field === 'company_name') {
|
|
|
|
if ($userTableField === 'company_name') {
|
|
|
|
$hasCompanyName = true;
|
|
|
|
$hasCompanyName = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|