|
|
@ -457,19 +457,47 @@ class OrderTableService extends BaseApiService |
|
|
$insert_data = []; |
|
|
$insert_data = []; |
|
|
$now = date('Y-m-d H:i:s'); |
|
|
$now = date('Y-m-d H:i:s'); |
|
|
|
|
|
|
|
|
// 为每个占位符配置创建数据源记录,关联到具体的签署记录 |
|
|
// 获取学员信息,用于数据库字段值处理 |
|
|
foreach ($placeholder_config as $config) { |
|
|
$student_info = $this->getStudentInfoForContract($orderData['student_id']); |
|
|
|
|
|
if (!$student_info) { |
|
|
|
|
|
\think\facade\Log::warning('获取学员信息失败', ['student_id' => $orderData['student_id']]); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
\think\facade\Log::info('开始处理占位符配置', [ |
|
|
|
|
|
'contract_id' => $contract_id, |
|
|
|
|
|
'config_structure' => array_keys($placeholder_config), |
|
|
|
|
|
'config_count' => count($placeholder_config) |
|
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
|
|
// 处理JSON对象格式的占位符配置:{"占位符名": {配置}} |
|
|
|
|
|
foreach ($placeholder_config as $placeholder_name => $config) { |
|
|
|
|
|
// 确保$config是数组 |
|
|
|
|
|
if (!is_array($config)) { |
|
|
|
|
|
\think\facade\Log::warning('跳过无效配置项', [ |
|
|
|
|
|
'placeholder' => $placeholder_name, |
|
|
|
|
|
'config' => $config |
|
|
|
|
|
]); |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 处理实际值:根据数据类型获取对应的值 |
|
|
|
|
|
$processed_value = $this->getProcessedFieldValue($config, $student_info, $orderData); |
|
|
|
|
|
|
|
|
|
|
|
// 获取占位符的显示名称,如果配置中有label则使用label,否则使用键名 |
|
|
|
|
|
$placeholder_display_name = $config['label'] ?? $config['placeholder'] ?? $placeholder_name; |
|
|
|
|
|
|
|
|
$data_source_record = [ |
|
|
$data_source_record = [ |
|
|
'contract_id' => $contract_id, |
|
|
'contract_id' => $contract_id, |
|
|
'contract_sign_id' => $contract_sign_id, // 新增:关联到具体的签署记录 |
|
|
'contract_sign_id' => $contract_sign_id, // 关联到具体的签署记录 |
|
|
'placeholder' => $config['placeholder'] ?? '', |
|
|
'placeholder' => $placeholder_display_name, // 使用配置的显示名称或键名 |
|
|
'data_type' => $config['data_type'] ?? 'user_input', |
|
|
'data_type' => $config['data_type'] ?? 'user_input', |
|
|
'system_function' => $config['system_function'] ?? '', |
|
|
'system_function' => $config['system_function'] ?? '', |
|
|
'table_name' => $config['table_name'] ?? '', |
|
|
'table_name' => $config['table_name'] ?? '', |
|
|
'field_name' => $config['field_name'] ?? '', |
|
|
'field_name' => $config['field_name'] ?? '', |
|
|
'field_type' => $config['field_type'] ?? 'text', |
|
|
'field_type' => $config['field_type'] ?? 'text', |
|
|
'is_required' => $config['is_required'] ?? 0, |
|
|
'is_required' => $config['is_required'] ?? 0, |
|
|
'default_value' => $config['default_value'] ?? '', |
|
|
'default_value' => $processed_value, // 使用处理过的实际值 |
|
|
'sign_party' => $config['sign_party'] ?? '', |
|
|
'sign_party' => $config['sign_party'] ?? '', |
|
|
'validation_rule' => $config['validation_rule'] ?? '', |
|
|
'validation_rule' => $config['validation_rule'] ?? '', |
|
|
'created_at' => $now, |
|
|
'created_at' => $now, |
|
|
@ -477,6 +505,13 @@ class OrderTableService extends BaseApiService |
|
|
]; |
|
|
]; |
|
|
|
|
|
|
|
|
$insert_data[] = $data_source_record; |
|
|
$insert_data[] = $data_source_record; |
|
|
|
|
|
|
|
|
|
|
|
\think\facade\Log::info('处理占位符字段', [ |
|
|
|
|
|
'placeholder_key' => $placeholder_name, |
|
|
|
|
|
'placeholder_display' => $placeholder_display_name, |
|
|
|
|
|
'data_type' => $config['data_type'] ?? 'user_input', |
|
|
|
|
|
'processed_value' => $processed_value |
|
|
|
|
|
]); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (!empty($insert_data)) { |
|
|
if (!empty($insert_data)) { |
|
|
@ -507,6 +542,223 @@ class OrderTableService extends BaseApiService |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 获取学员信息用于合同处理 |
|
|
|
|
|
* @param int $student_id 学员ID |
|
|
|
|
|
* @return array|null |
|
|
|
|
|
*/ |
|
|
|
|
|
private function getStudentInfoForContract($student_id) |
|
|
|
|
|
{ |
|
|
|
|
|
try { |
|
|
|
|
|
$student = Db::table('school_student') |
|
|
|
|
|
->where('id', $student_id) |
|
|
|
|
|
->where('status', 1) |
|
|
|
|
|
->field([ |
|
|
|
|
|
'id', 'name', 'gender', 'age', 'birthday', |
|
|
|
|
|
'emergency_contact', 'contact_phone', 'member_label', |
|
|
|
|
|
'user_id', 'campus_id', 'created_at' |
|
|
|
|
|
]) |
|
|
|
|
|
->find(); |
|
|
|
|
|
|
|
|
|
|
|
return $student ? $student : null; |
|
|
|
|
|
|
|
|
|
|
|
} catch (\Exception $e) { |
|
|
|
|
|
\think\facade\Log::error('获取学员信息失败', [ |
|
|
|
|
|
'student_id' => $student_id, |
|
|
|
|
|
'error' => $e->getMessage() |
|
|
|
|
|
]); |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 获取处理过的字段值 |
|
|
|
|
|
* 根据字段的数据类型获取相应的值 |
|
|
|
|
|
* @param array $config 字段配置 |
|
|
|
|
|
* @param array $student_info 学员信息 |
|
|
|
|
|
* @param array $order_data 订单数据 |
|
|
|
|
|
* @return string |
|
|
|
|
|
*/ |
|
|
|
|
|
private function getProcessedFieldValue($config, $student_info, $order_data) |
|
|
|
|
|
{ |
|
|
|
|
|
try { |
|
|
|
|
|
$data_type = $config['data_type'] ?? 'user_input'; |
|
|
|
|
|
|
|
|
|
|
|
switch ($data_type) { |
|
|
|
|
|
case 'database': |
|
|
|
|
|
// 数据库类型:从相关表获取数据 |
|
|
|
|
|
return $this->getDatabaseFieldValueForConfig($config, $student_info, $order_data); |
|
|
|
|
|
|
|
|
|
|
|
case 'system': |
|
|
|
|
|
// 系统函数类型:调用系统函数获取值 |
|
|
|
|
|
return $this->getSystemFunctionValueForConfig($config); |
|
|
|
|
|
|
|
|
|
|
|
case 'user_input': |
|
|
|
|
|
// 用户输入类型:使用配置的默认值 |
|
|
|
|
|
return $config['default_value'] ?? ''; |
|
|
|
|
|
|
|
|
|
|
|
case 'signature': |
|
|
|
|
|
case 'sign_img': |
|
|
|
|
|
// 签名类型:无默认值,需要用户操作 |
|
|
|
|
|
return ''; |
|
|
|
|
|
|
|
|
|
|
|
default: |
|
|
|
|
|
return $config['default_value'] ?? ''; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} catch (\Exception $e) { |
|
|
|
|
|
\think\facade\Log::error('获取处理字段值失败', [ |
|
|
|
|
|
'config' => $config, |
|
|
|
|
|
'error' => $e->getMessage() |
|
|
|
|
|
]); |
|
|
|
|
|
return ''; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 从数据库获取字段值 |
|
|
|
|
|
* @param array $config 字段配置 |
|
|
|
|
|
* @param array $student_info 学员信息 |
|
|
|
|
|
* @param array $order_data 订单数据 |
|
|
|
|
|
* @return string |
|
|
|
|
|
*/ |
|
|
|
|
|
private function getDatabaseFieldValueForConfig($config, $student_info, $order_data) |
|
|
|
|
|
{ |
|
|
|
|
|
try { |
|
|
|
|
|
$table_name = $config['table_name'] ?? ''; |
|
|
|
|
|
$field_name = $config['field_name'] ?? ''; |
|
|
|
|
|
|
|
|
|
|
|
if (empty($table_name) || empty($field_name)) { |
|
|
|
|
|
return ''; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$value = ''; |
|
|
|
|
|
|
|
|
|
|
|
switch ($table_name) { |
|
|
|
|
|
case 'school_student': |
|
|
|
|
|
// 学员表:直接从学员信息获取 |
|
|
|
|
|
$value = $student_info[$field_name] ?? ''; |
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case 'school_customer_resources': |
|
|
|
|
|
// 用户表:通过学员的user_id关联查询 |
|
|
|
|
|
if (!empty($student_info['user_id'])) { |
|
|
|
|
|
$value = Db::table('school_customer_resources') |
|
|
|
|
|
->where('id', $student_info['user_id']) |
|
|
|
|
|
->value($field_name) ?? ''; |
|
|
|
|
|
} |
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case 'school_order_table': |
|
|
|
|
|
// 订单表:使用当前订单数据 |
|
|
|
|
|
$value = $order_data[$field_name] ?? ''; |
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
default: |
|
|
|
|
|
\think\facade\Log::warning('不支持的数据库表', [ |
|
|
|
|
|
'table_name' => $table_name, |
|
|
|
|
|
'field_name' => $field_name |
|
|
|
|
|
]); |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 对特殊字段进行格式化处理 |
|
|
|
|
|
$value = $this->formatFieldValueForContract($field_name, $value); |
|
|
|
|
|
|
|
|
|
|
|
return (string)$value; |
|
|
|
|
|
|
|
|
|
|
|
} catch (\Exception $e) { |
|
|
|
|
|
\think\facade\Log::error('获取数据库字段值失败', [ |
|
|
|
|
|
'config' => $config, |
|
|
|
|
|
'error' => $e->getMessage() |
|
|
|
|
|
]); |
|
|
|
|
|
return ''; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 获取系统函数值 |
|
|
|
|
|
* @param array $config 字段配置 |
|
|
|
|
|
* @return string |
|
|
|
|
|
*/ |
|
|
|
|
|
private function getSystemFunctionValueForConfig($config) |
|
|
|
|
|
{ |
|
|
|
|
|
try { |
|
|
|
|
|
$system_function = $config['system_function'] ?? ''; |
|
|
|
|
|
|
|
|
|
|
|
if (empty($system_function)) { |
|
|
|
|
|
return ''; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 预定义的系统函数 |
|
|
|
|
|
switch ($system_function) { |
|
|
|
|
|
case 'current_date': |
|
|
|
|
|
return date('Y-m-d'); |
|
|
|
|
|
case 'current_time': |
|
|
|
|
|
return date('H:i:s'); |
|
|
|
|
|
case 'current_datetime': |
|
|
|
|
|
return date('Y-m-d H:i:s'); |
|
|
|
|
|
case 'current_year': |
|
|
|
|
|
return date('Y'); |
|
|
|
|
|
case 'current_month': |
|
|
|
|
|
return date('m'); |
|
|
|
|
|
case 'current_day': |
|
|
|
|
|
return date('d'); |
|
|
|
|
|
default: |
|
|
|
|
|
\think\facade\Log::warning('未知的系统函数', [ |
|
|
|
|
|
'function_name' => $system_function |
|
|
|
|
|
]); |
|
|
|
|
|
return ''; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} catch (\Exception $e) { |
|
|
|
|
|
\think\facade\Log::error('获取系统函数值失败', [ |
|
|
|
|
|
'config' => $config, |
|
|
|
|
|
'error' => $e->getMessage() |
|
|
|
|
|
]); |
|
|
|
|
|
return ''; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 格式化字段值 |
|
|
|
|
|
* @param string $field_name 字段名 |
|
|
|
|
|
* @param mixed $value 原始值 |
|
|
|
|
|
* @return string |
|
|
|
|
|
*/ |
|
|
|
|
|
private function formatFieldValueForContract($field_name, $value) |
|
|
|
|
|
{ |
|
|
|
|
|
if (empty($value)) { |
|
|
|
|
|
return ''; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 根据字段名进行特殊处理 |
|
|
|
|
|
switch (true) { |
|
|
|
|
|
case str_contains($field_name, 'date') || str_contains($field_name, 'time'): |
|
|
|
|
|
// 日期时间字段格式化 |
|
|
|
|
|
if (is_numeric($value)) { |
|
|
|
|
|
return date('Y-m-d', $value); |
|
|
|
|
|
} elseif (strtotime($value)) { |
|
|
|
|
|
return date('Y-m-d', strtotime($value)); |
|
|
|
|
|
} |
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case str_contains($field_name, 'amount') || str_contains($field_name, 'price'): |
|
|
|
|
|
// 金额字段格式化 |
|
|
|
|
|
return number_format((float)$value, 2); |
|
|
|
|
|
|
|
|
|
|
|
case str_contains($field_name, 'phone'): |
|
|
|
|
|
// 手机号格式化 |
|
|
|
|
|
return (string)$value; |
|
|
|
|
|
|
|
|
|
|
|
default: |
|
|
|
|
|
// 默认返回字符串 |
|
|
|
|
|
return (string)$value; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return (string)$value; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 支付成功后创建支付记录 |
|
|
* 支付成功后创建支付记录 |
|
|
* @param array $orderData 订单数据 |
|
|
* @param array $orderData 订单数据 |
|
|
|