where('name', '=', $str2)->value('id'); if (empty($city_id)) { $str2 = ''; } } if ($property_situation == 1) { $property_cert = $str1 . $str2 . $str3 . $str4; } // 组合结果 return [ 'property_cert' => $property_cert, 'city' => !empty($str2) ? mb_substr($str2, 0, mb_strrpos($str2, '市')) : null, 'city_id' => $city_id ]; } public static function getObligeeAndCertNo($data) { // 提取权利人和身份证信息 $obligee = $cert_no = ''; foreach ($data as $key => $value) { if (is_string($value)) { if (mb_strpos($value, '[100%]') !== false) { if (preg_match('/^(?:([\x{4e00}-\x{9fa5}]+))[((]([^))\n]+)[))]|([\x{4e00}-\x{9fa5}]{5,})$/u', mb_substr($value, 0, mb_strpos($value, '[100%]')), $match)) { $obligee = empty($match[1]) ? ($match[3]??'') : $match[1]; $cert_no = $match[2]??''; break; } } else { if (preg_match('/^([\x{4e00}-\x{9fa5}]+)[((]([a-zA-Z0-9]+)[))]/u', $value, $match)) { $obligee = $match[1]; $cert_no = $match[2]; break; } else { if (!empty($obligee)) { break; } if(mb_strpos($value, '民币') !== false) { continue; } if (in_array($value, ['权利人名称'])) { for ($i = 1; ; $i++) { $nextKey = $key + $i; if(!isset($data[$nextKey]) || !empty($obligee)) { break; } $nextValue = $data[$nextKey]; if(empty($nextValue) || mb_strlen($nextValue) < 2) { continue; } if (mb_strpos($nextValue, '附着物') === false) { if (mb_strpos($nextValue, '(') !== false || mb_strpos($nextValue, '(') !== false) { // 处理格式: 郭佩萍(440514199805131840) preg_match('/^([\x{4e00}-\x{9fa5}]+)[((]([a-zA-Z0-9]+)[))]/u', $nextValue, $match); $obligee = trim($match[1] ?? ''); $cert_no = $match[2] ?? ''; } else { $obligee = $nextValue; } } } } elseif (in_array($value, ['权利人', '利人', '人'])) { for ($i = 1; ; $i++) { $nextKey = $key + $i; if(!isset($data[$nextKey]) || !empty($obligee)) { break; } $nextValue = $data[$nextKey]; if(empty($nextValue) || mb_strlen($nextValue) < 2) { continue; } if (mb_strpos($nextValue, '附着物') === false) { if (mb_strpos($nextValue, '(') !== false || mb_strpos($nextValue, '(') !== false) { // 处理格式: 郭佩萍(440514199805131840) preg_match('/^([\x{4e00}-\x{9fa5}]+)[((]([a-zA-Z0-9]+)[))]/u', $nextValue, $match); $obligee = trim($match[1] ?? ''); $cert_no = $match[2] ?? ''; } } } } // 情况2: 前缀匹配关键词 elseif (preg_match('/^(权利人名称|权利人|利人|人)[::]?([^(性质|类型)].+)/u', $value, $match)) { $content = $match[2]; if (strpos($content, '(') !== false || strpos($content, '(') !== false) { preg_match('/^([\x{4e00}-\x{9fa5}]+)[((]([a-zA-Z0-9]+)[))]$/u', $content, $match); $obligee = trim($match[1] ?? ''); $cert_no = $match[2] ?? ''; } else { $obligee = $content; } } } } } } // 情况3: 如果已找到权利人但未找到身份证号,全局搜索 if (!empty($obligee) && empty($cert_no)) { foreach ($data as $key => $item) { if (is_string($item)) { if ( strpos($item, $obligee) !== false && preg_match('/' . preg_quote($obligee, '/') . '\s*[((](\w+)[))]/u', $item, $matches)) { $cert_no = $matches[1]; break; } elseif (preg_match('/^身份证号码[::]?\s*$/u', $item)) { $nextKey = $key + 1; $nextValue = $data[$nextKey] ?? ''; if (preg_match('/^\d{18}$/u', $nextValue)) { $cert_no = $nextValue; } } } } } return [ 'obligee' => $obligee, 'cert_no' => $cert_no, ]; } public static function getSizeAndRegPriceAndCompletionTime($data) { // 提取面积、登记价和竣工日期 $size = null; $reg_price = null; $completion_time = null; foreach ($data as $key => $value) { // size 规则 // 提取面积(size) - 规则1 if (preg_match('/^建筑面积[::]?(\d+\.?\d*)(平方米|m²|m)$/u', $value, $sizeMatches)) { $size = $sizeMatches[1]; } // 提取面积(size) - 规则2 elseif (trim($value) === '建筑面积' && isset($data[$key + 1]) && preg_match('/^\d+\.?\d*$/u', $data[$key + 1])) { $size = $data[$key + 1]; } // 提取面积(size) - 规则3 elseif (trim($value) === '建筑面积' && isset($data[$key + 1]) && preg_match('/^(\d+\.?\d*)(平方米|m²|m)$/u', $data[$key + 1], $nextSizeMatches)) { $size = $nextSizeMatches[1]; } elseif (mb_strpos($value, '建筑面积') !== false) { for($i = 1; ; $i++) { $nextKey = $key + $i; if(!isset($data[$nextKey]) || !empty($size)) { break; } $nextValue = $data[$nextKey]; if(empty($nextValue)) continue; if (preg_match('/^(\d+\.?\d*)(平方米|m²|m)?$/u', $nextValue, $nextSizeMatches)) { $size = $nextSizeMatches[1]; break; } } for($i = 1; ; $i++) { $prevKey = $key - $i; if(!isset($data[$prevKey]) || !empty($size)) { break; } $prevValue = $data[$prevKey]; if(empty($prevValue)) continue; if (preg_match('/^(\d+\.?\d*)(平方米|m²|m)?$/u', $prevValue, $prevSizeMatches)) { $size = $prevSizeMatches[1]; break; } } } // reg_price 规则 // 提取登记价(reg_price) - 规则1 if (preg_match('/登记价[::]?.*人民币(\d+\.?\d*)元$/u', $value, $priceMatches)) { $reg_price = $priceMatches[1]; } // 提取登记价(reg_price) - 规则2 elseif (trim($value) === '登记价' && isset($data[$key + 1]) && preg_match('/^\d+\.?\d*$/u', $data[$key + 1])) { $reg_price = $data[$key + 1]; } // 提取登记价(reg_price) - 规则3 elseif (trim($value) === '登记价' && isset($data[$key + 1]) && preg_match('/^人民币(\d+\.?\d*)元$/u', $data[$key + 1], $nextPriceMatches)) { $reg_price = $nextPriceMatches[1]; } // 提取登记价(reg_price) - 规则4 elseif (preg_match('/人民币(\d+\.?\d*)元$/u', $value, $priceMatches)) { $reg_price = $priceMatches[1]; } // 提取登记价(reg_price) - 规则5 elseif (preg_match('/[¥$](\d+\.?\d*)元?$/u', $value, $priceMatches)) { $reg_price = $priceMatches[1]; } // completion_time 规则 // 提取竣工日期(completion_time) - 规则1 if (preg_match('/竣工日期[::](\d+)年(\d+)月(\d+)日$/u', $value, $dateMatches)) { $completion_time = $dateMatches[1] . '-' . str_pad($dateMatches[2], 2, '0', STR_PAD_LEFT) . '-' . str_pad($dateMatches[3], 2, '0', STR_PAD_LEFT); } // 提取竣工日期(completion_time) - 规则2 elseif (trim($value) === '竣工日期' && isset($data[$key + 1]) && preg_match('/^(\d+)年(\d+)月(\d+)日$/u', $data[$key + 1], $nextDateMatches)) { $completion_time = $nextDateMatches[1] . '-' . str_pad($nextDateMatches[2], 2, '0', STR_PAD_LEFT) . '-' . str_pad($nextDateMatches[3], 2, '0', STR_PAD_LEFT); } // 提取竣工日期(completion_time) - 规则3 elseif (trim($value) === '竣工日期' && isset($data[$key + 1]) && preg_match('/^(\d+)-(\d+)-(\d+)$/u', $data[$key + 1], $nextDateMatches)) { $completion_time = $nextDateMatches[1] . '-' . str_pad($nextDateMatches[2], 2, '0', STR_PAD_LEFT) . '-' . str_pad($nextDateMatches[3], 2, '0', STR_PAD_LEFT); } // 提取竣工日期(completion_time) - 规则4 elseif(mb_strpos($value, '竣工日期') !== false) { for($i = 1; ; $i++) { $nextKey = $key + $i; $nextValue = $data[$nextKey] ?? ''; if (empty($nextValue) || !empty($completion_time)) { break; } if (preg_match('/^(\d+)年(\d+)月(\d+)日$/u', $nextValue, $nextDateMatches)) { $completion_time = $nextDateMatches[1] . '-' . str_pad($nextDateMatches[2], 2, '0', STR_PAD_LEFT) . '-' . str_pad($nextDateMatches[3], 2, '0', STR_PAD_LEFT); break; } elseif (preg_match('/^(\d+)-(\d+)-(\d+)$/u', $nextValue, $nextDateMatches)) { $completion_time = $nextDateMatches[1] . '-' . str_pad($nextDateMatches[2], 2, '0', STR_PAD_LEFT) . '-' . str_pad($nextDateMatches[3], 2, '0', STR_PAD_LEFT); break; } } for ($i = 1; ; $i++) { $prevKey = $key - $i; if (!isset($data[$prevKey]) || !empty($completion_time)) { break; } $prevValue = $data[$prevKey]; if (empty($prevValue)) continue; if (preg_match('/^(\d+)年(\d+)月(\d+)日$/u', $prevValue, $prevDateMatches)) { $completion_time = $prevDateMatches[1] . '-' . str_pad($prevDateMatches[2], 2, '0', STR_PAD_LEFT) . '-' . str_pad($prevDateMatches[3], 2, '0', STR_PAD_LEFT); break; } elseif (preg_match('/^(\d+)-(\d+)-(\d+)$/u', $prevValue, $prevDateMatches)) { $completion_time = $prevDateMatches[1] . '-' . str_pad($prevDateMatches[2], 2, '0', STR_PAD_LEFT) . '-' . str_pad($prevDateMatches[3], 2, '0', STR_PAD_LEFT); break; } } } } return [ 'size' => $size, 'reg_price' => $reg_price, 'completion_time' => $completion_time, ]; } public static function getPurchaseDateAndUseRightSource($data) { // 提取购买日期 $purchase_date = ''; $datePatterns = [ // 情况1: 关键词+日期格式 '/(购买日期|购房日期|登记日期|购买时间|购房时间|登记时间|裁定日期|裁定时间|买卖合同签订日期|合同签订日期)[::]?\s*(\d{4}年\d{1,2}月\d{1,2}日|\d{4}-\d{1,2}-\d{1,2})/u' => 2, // 情况2: 于xxxx年xx月xx日购买 或 xxxx年xx月xx日购买 '/(于)?(\d{4}年\d{1,2}月\d{1,2}日|\d{4}-\d{1,2}-\d{1,2})(购买|签订)/u' => 2 ]; // 定义使用权来源映射关系 $use_right_source_arr = ['市场商品房' => '1', '商品房' => '2', '非市场商品房' => '3', '非商品房' => '3']; $use_right_source = '1'; // 默认值为市场商品房 // dump(preg_match('/(购买日期|购房日期|登记日期|购买时间|购房时间|登记时间|裁定日期|裁定时间|买卖合同签订日期)[::]?\s*(\d{4}年\d{1,2}月\d{1,2}日|\d{4}-\d{1,2}-\d{1,2})/u', '', $matches)); // die; // 遍历数组查找日期 for ($i = 0; $i < count($data); $i++) { $item = $data[$i]; foreach ($datePatterns as $pattern => $group) { // dump($item); // dump(preg_match($pattern, $item, $matches)); if (preg_match($pattern, $item, $matches)) { $dateStr = $matches[$group]; // 转换日期格式 if (strpos($dateStr, '年') !== false) { list($year, $month, $day) = preg_split('/年|月|日/u', $dateStr, 4, PREG_SPLIT_NO_EMPTY); $purchase_date = sprintf('%04d-%02d-%02d', $year, $month, $day); } else { $purchase_date = date('Y-m-d', strtotime($dateStr)); } break 2; } } // 检查下一个和下两个元素是否包含日期 if (preg_match('/(购买日期|购房日期|登记日期|购买时间|购房时间|登记时间|裁定日期|裁定时间|买卖合同签订日期|合同签订日期)[::]?\s*$/u', $item)) { for ($j = $i + 1; $j <= $i + 2 && $j < count($data); $j++) { if (preg_match('/(\d{4}年\d{1,2}月\d{1,2}日|\d{4}-\d{1,2}-\d{1,2})/u', $data[$j], $matches)) { $dateStr = $matches[1]; if (strpos($dateStr, '年') !== false) { list($year, $month, $day) = preg_split('/[年月日]/u', $dateStr, 4, PREG_SPLIT_NO_EMPTY); $purchase_date = sprintf('%04d-%02d-%02d', $year, $month, $day); } else { $purchase_date = date('Y-m-d', strtotime($dateStr)); } break 2; } } } } // die; // 遍历数组查找权利来源 foreach ($data as $item) { foreach ($use_right_source_arr as $keyword => $value) { if (strpos($item, $keyword) !== false) { $use_right_source = $value; break 2; // 找到匹配项后退出双层循环 } } } return [ 'purchase_date' => $purchase_date, 'use_right_source' => $use_right_source, ]; } public static function getPropertyFullName($data) { // 提取物业名称 $property_full_name = ''; $has_attachment = false; // 检查是否存在"附着物"字眼 foreach ($data as $item) { if (mb_strpos($item, '及其它附着物') !== false) { $has_attachment = true; break; } } foreach ($data as $key => $item) { if (!empty($property_full_name)) break; // 条件4: 存在"附着物"时查找特定格式内容 if ($has_attachment) { if (preg_match('/([^\s]+(座|栋|单元|号楼|号房|复式|阁|幢|办公楼|地下层|厦|山庄)\w*)$/u', $item, $matches)) { $property_full_name = trim($matches[1]); break; } } else { // 条件1: 查找"房地产名称"及后续内容 if (preg_match('/房地产名称[::]?\s*(.*)/u', $item, $matches)) { if (!empty($matches[1])) { $property_full_name = trim($matches[1]); } else { for($i = 1; ; $i++) { $prevKey = $key - $i; if(!isset($data[$prevKey])) { break; } $prevValue = $data[$prevKey]; if(empty($prevValue)) continue; if (preg_match('/([^\s]+(座|栋|单元|号楼|号房|复式|阁|幢|办公楼|地下层|厦|山庄)\w*)$/u', $prevValue, $matches)) { $property_full_name = trim($matches[1]); break; } } for($i = 1; ; $i++) { $nextKey = $key + $i; if(!isset($data[$nextKey]) || !empty($property_full_name)) { break; } $nextValue = $data[$nextKey]; if(empty($nextValue)) continue; if (preg_match('/([^\s]+(座|栋|单元|号楼|号房|复式|阁|幢|办公楼|地下层|厦|山庄)\w*)$/u', $nextValue, $matches)) { $property_full_name = trim($matches[1]); break; } } } } else { for($i = 1; ; $i++) { $prevKey = $key - $i; if(!isset($data[$prevKey])) { break; } $prevValue = $data[$prevKey]; if(empty($prevValue)) continue; if (preg_match('/([^\s]+(座|栋|单元|号楼|号房|复式|阁|幢|办公楼|地下层|厦|山庄)\w*)$/u', $prevValue, $matches)) { $property_full_name = trim($matches[1]); break; } } for($i = 1; ; $i++) { $nextKey = $key + $i; if(!isset($data[$nextKey]) || !empty($property_full_name)) { break; } $nextValue = $data[$nextKey]; if(empty($nextValue)) continue; if (preg_match('/([^\s]+(座|栋|单元|号楼|号房|复式|阁|幢|办公楼|地下层|厦|山庄)\w*)$/u', $nextValue, $matches)) { $property_full_name = trim($matches[1]); break; } } if (!empty($property_full_name)) { // 条件2: 查找"交界处"及后续内容 if (preg_match('/(交界处|东北侧|东南侧|西北侧|西南侧|东侧|西侧|南侧|北侧)\s*(.*)/u', $property_full_name, $matches)) { $property_full_name = trim($matches[2]); break; } // 条件3: 查找包含"路"字的内容 if (preg_match('/([^\s]*路[^\s]*)/u', $property_full_name, $matches)) { $road_part = $matches[1]; $road_pos = mb_strpos($road_part, '路'); if ($road_pos !== false) { $property_full_name = trim(mb_substr($road_part, $road_pos + 1)); break; } } // 条件4: 查找包含"道"字的内容 if (preg_match('/([^\s]*大道[^\s]*)/u', $property_full_name, $matches)) { $road_part = $matches[1]; $road_pos = mb_strpos($road_part, '道'); if ($road_pos !== false) { $property_full_name = trim(mb_substr($road_part, $road_pos + 1)); break; } } } } // 条件2: 查找"交界处"及后续内容 if (preg_match('/(交界处|东北侧|东南侧|西北侧|西南侧|东侧|西侧|南侧|北侧)\s*(.*)/u', $item, $matches)) { $property_full_name = trim($matches[2]); break; } // 条件3: 查找包含"路"字的内容 if (preg_match('/([^\s]*路[^\s]*)/u', $item, $matches)) { $road_part = $matches[1]; $road_pos = mb_strpos($road_part, '路'); if ($road_pos !== false) { $property_full_name = trim(mb_substr($road_part, $road_pos + 1)); break; } } // 条件4: 查找包含"道"字的内容 if (preg_match('/([^\s]*大道[^\s]*)/u', $item, $matches)) { $road_part = $matches[1]; $road_pos = mb_strpos($road_part, '道'); if ($road_pos !== false) { $property_full_name = trim(mb_substr($road_part, $road_pos + 1)); break; } } } } return [ 'property_full_name' => $property_full_name, ]; } public static function getOwnershipTypeAndUsage($data) { // 提取权利人性质类型 $ownership_type = ''; // 默认值:空 $ownership_types = ['个人' => '1', '其他' => '2']; // 提取用途信息 $usage = '7'; // 默认值 foreach ($data as $key => $value) { if (is_string($value) && strpos($value, '权利人性质') !== false) { // 规则1:匹配"权利人性质"后跟文字 if (preg_match('/权利人性质[::]?\s*(.*)/u', $value, $match)) { $content = trim($match[1]); if (!empty($content)) { $ownership_type = $ownership_types[$content] ?? '2'; break; } } // 规则2:匹配"权利人性质"后无文字,检查下一个元素 for ($i = 1; $i < count($data) - $key; $i++) { $next_key = $key + $i; $next_value = $data[$next_key] ?? ''; if ($next_value == '个人') { $ownership_type = '1'; break; } } } // 情况1:匹配以"用途"开头的元素 if (preg_match('/^用途[::]?\s*(.*)$/u', $value, $matches)) { $content = trim($matches[1]); if (!empty($content)) { // 处理情况1.1到1.7 if (mb_strpos($content, '住宅') !== false) { $usage = '1'; } elseif (mb_strpos($content, '商业') !== false && mb_strpos($content, '住宅') === false) { $usage = '2'; } elseif (mb_strpos($content, '办公') !== false && mb_strpos($content, '住宅') === false) { $usage = '3'; } elseif (mb_strpos($content, '厂房') !== false && mb_strpos($content, '住宅') === false) { $usage = '4'; } elseif (mb_strpos($content, '土地') !== false && mb_strpos($content, '住宅') === false) { $usage = '5'; } elseif ((mb_strpos($content, '商务公寓') !== false || mb_strpos($content, '公寓') !== false) && mb_strpos($content, '住宅') === false) { $usage = '6'; } else { $usage = '7'; } break; } else { // 情况2:后面没有文字,检查下一个元素 if (isset($data[$key + 1])) { $nextContent = $data[$key + 1]; if (mb_strpos($nextContent, '住宅') !== false) { $usage = '1'; } elseif (mb_strpos($nextContent, '商业') !== false && mb_strpos($nextContent, '住宅') === false) { $usage = '2'; } elseif (mb_strpos($nextContent, '办公') !== false && mb_strpos($nextContent, '住宅') === false) { $usage = '3'; } elseif (mb_strpos($nextContent, '厂房') !== false && mb_strpos($nextContent, '住宅') === false) { $usage = '4'; } elseif (mb_strpos($nextContent, '土地') !== false && mb_strpos($nextContent, '住宅') === false) { $usage = '5'; } elseif ((mb_strpos($nextContent, '商务公寓') !== false || mb_strpos($nextContent, '公寓') !== false) && mb_strpos($nextContent, '住宅') === false) { $usage = '6'; } else { $usage = '7'; } break; } } } // 情况3:单独的"用"和"途" elseif ($value === '用' && isset($data[$key + 1]) && $data[$key + 1] === '途') { if (isset($data[$key + 2])) { $nextContent = $data[$key + 2]; if (mb_strpos($nextContent, '住宅') !== false) { $usage = '1'; } elseif (mb_strpos($nextContent, '商业') !== false && mb_strpos($nextContent, '住宅') === false) { $usage = '2'; } elseif (mb_strpos($nextContent, '办公') !== false && mb_strpos($nextContent, '住宅') === false) { $usage = '3'; } elseif (mb_strpos($nextContent, '厂房') !== false && mb_strpos($nextContent, '住宅') === false) { $usage = '4'; } elseif (mb_strpos($nextContent, '土地') !== false && mb_strpos($nextContent, '住宅') === false) { $usage = '5'; } elseif ((mb_strpos($nextContent, '商务公寓') !== false || mb_strpos($nextContent, '公寓') !== false) && mb_strpos($nextContent, '住宅') === false) { $usage = '6'; } else { $usage = '7'; } break; } } } // foreach ($data as $value) { // if ((mb_strpos($value, '住宅') !== false || mb_strpos($value, '往宅') !== false) && $usage != 1) { // $usage = '1'; // break; // } // if (mb_strpos($value, '商业') !== false && $usage != 2) { // $usage = '2'; // break; // } // } return [ 'ownership_type' => $ownership_type, 'usage' => $usage, ]; } }