enableQueryLog(); // 开启QueryLog $deep3_area_list = $model_area->getAreaList($condition); // \App\User::find(1); // return DB::getQueryLog(); // 三级地址的匹配出现多个结果 依靠二级地址缩小范围 if ($deep3_area_list && count($deep3_area_list) > 1) { if ($deep2_area_name) { $area_info_2 = $model_area->getAreaInfo(['area_name','like', '%' . $deep2_area_name . '%']); //2级地址匹配成功 再次缩小三级地址 然后确定一级地址 if ($area_info_2) { $area_info_3 = $model_area->getAreaInfo(['area_parent_id' => $area_info_2['area_id'], array('area_name','like', '%' . $deep3_area_name . '%')]); } $area_info_1 = $model_area->getAreaInfo(['area_id' => $area_info_2['area_parent_id'], 'area_deep' => 1]); //获得结果 $result[1]['area_id'] = $area_info_2['area_parent_id']; $result[1]['area_name'] = $area_info_1['area_name']; $result[2]['area_id'] = $area_info_2['area_id']; $result[2]['area_name'] = $area_info_2['area_name']; $result[3]['area_id'] = $area_info_3['area_id']; $result[3]['area_name'] = $area_info_3['area_name']; } } else { if ($deep3_area_list && count($deep3_area_list) == 1) { $area_info_2 = $model_area->getAreaInfo(['area_id' => $deep3_area_list[0]['area_parent_id'], 'area_deep' => 2]); if ($area_info_2) { $area_info_1 = $model_area->getAreaInfo(['area_id' => $area_info_2['area_parent_id'], 'area_deep' => 1]); //获得结果 $result[1]['area_id'] = $area_info_2['area_parent_id']; $result[1]['area_name'] = $area_info_1['area_name']; $result[2]['area_id'] = $area_info_2['area_id']; $result[2]['area_name'] = $area_info_2['area_name']; $result[3]['area_id'] = $deep3_area_list[0]['area_id']; $result[3]['area_name'] = $deep3_area_list[0]['area_name']; } }elseif($deep2_area_name == $deep3_area_name){ //如出现内蒙古自治区乌兰察布市公安局交警支队车管所这种只有省市,没有区的情况 $area_info_2 = $model_area->getAreaInfo(['area_deep'=>2, ['area_name','like', '%' . $deep2_area_name . '%']]); if ($area_info_2) { $area_info_1 = $model_area->getAreaInfo(['area_id' => $area_info_2['area_parent_id'], 'area_deep' => 1]); //获得结果 if($area_info_1){ $result[1]['area_id'] = $area_info_2['area_parent_id']; $result[1]['area_name'] = $area_info_1['area_name']; $result[2]['area_id'] = $area_info_2['area_id']; $result[2]['area_name'] = $area_info_2['area_name']; $result[3]['area_id'] = ''; $result[3]['area_name'] = ''; } } } } } //最终结果 return $result; } } //$obj = AddressDetail::detail_parse('成都市高新区天府软件园B区科技大楼'); //$obj2 = AddressDetail::detail_parse('朝阳区宵云路36号国航大厦一层');