Files
annnj-company 130c1026c4 first commit
2026-04-17 18:29:53 +08:00

415 lines
18 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace app\admin\controller;
use think\Db;
use app\model\Dictionary;
use app\admin\service\Consultfiles;
use think\Log;
class CheckFile extends Base {
/**
* @api {get} admin/CheckFile/consultFiles 查档
*
* @param $year 年份
* @param $property_cert 房产证号
*/
/*
public function consultFiles() {
$year = $this->request->post('year'); //年份
$property_cert = $this->request->post('property_cert'); //房产证号
$client = $this->request->post('client'); //权利人
if(!$property_cert) return $this->buildFailed('请输入房产证号');
if($year){
$param = ['proveCode1'=>$year, 'proveCode2'=>$property_cert];
}else{
$param = ['proveCode'=>$property_cert];
}
$client && $param['orgName'] = $client;
$consultfile = new Consultfiles;
$res = $consultfile->Consultfiles($param);
Db::startTrans();
try{
if($res['code'] != 1 || (isset($res['estatestatus']) && $res['estatestatus'] == '没有房产')) return $this->buildFailed('没有房产');
//新增查档记录详情
$adddatadet = [
'estatestatus' => $res['estatestatus'],
'code' => $res['result']['code'],
'msg' => $res['result']['msg'],
'data_printResult' => implode(',', array_column($res['result']['data'], 'printResult')),
'data_status_txt' => implode(',', array_column($res['result']['data'], 'status_txt')),
'data_list' => json_encode(array_column($res['result']['data'], 'list')),
'create_time' => date('Y-m-d H:i:s')
];
//新增查档记录详情
$consult_id = Db::name('consult_record_det')->insertGetId($adddatadet);
if(!$consult_id){
Db::rollback();
return $this->buildFailed('查档记录详情新增失败');
}
//组装数据
$printResult = implode(',', array_column($res['result']['data'], 'printResult'));
// $data = (explode('【产权信息】',$printResult));
// $data = (explode('',$data[0]));
$data = $res['result']['data'][0]['list'];
$fill = [];
$fill['year'] = $year;
$fill['property_cert'] = $property_cert;
if($data){
foreach ($data as $v){
if($v['key'] == '房屋地址'){
$fill['building_name'] = $v['value']; //物业名称
}elseif($v['key'] == '登记价'){
$fill['reg_price'] = mb_substr($v['value'], 3); //登记价
}elseif($v['key'] == '登记日期'){
$fill['purchase_date'] = preg_replace(['/年|月/','/日/'],['-',''],$v['value']);
}elseif($v['key'] == '建筑面积'){
$fill['size'] = $v['value'];
}elseif($v['key'] == '土地使用年限'){
$fill['max_land_use_years'] = mb_substr($v['value'],0,-27); //土地使用年限
$fill['land_use_start_time'] = preg_replace(['/年|月/','/日/'],['-',''],mb_substr($v['value'],-24,-13)); //土地使用开始时间
$fill['land_use_end_time'] = preg_replace(['/年|月/','/日/'],['-',''],mb_substr($v['value'],-12,-1)); //土地使用结束时间
}elseif ($v['key'] == '宗地号'){
$fill['parcel_no'] = $v['value'];
}elseif($v['key'] == '房屋性质'){
$fill['use_right_source'] = $v['value'];
}elseif($v['key'] == '竣工时间'){
$fill['completion_date'] = preg_replace(['/年|月/','/日/'],['-',''],$v['value']); //竣工日期
}
}
$fill['consult_id'] = $consult_id;
$fill['estatestatus'] = $res['estatestatus'];
if((time() - strtotime($fill['purchase_date'])) > 365*2*24*3600){
$fill['is_tran_tax_free'] = 1; //满两年
}else{
$fill['is_tran_tax_free'] = 2; //没有满两年
}
}
Db::commit();
return $this->buildSuccess(['show'=>implode('', array_column($res['result']['data'], 'printResult')) , 'fill'=>$fill]);
}catch (\Exception $e){
Db::rollback();
return $this->buildFailed('该房产信息不存在'. $e->getMessage());
}
}
*/
// 询价录单(申请下单出报告)自动填充房产信息相关字段的值
public function consultFiles() {
$year = $this->request->post('year'); //年份
$property_cert = $this->request->post('property_cert'); //房产证号
if(!$property_cert) return $this->buildFailed('请输入房产证号');
$where = [];
$where[] = ['estate_year', '=', $year];
$where[] = ['estate_cert_num', '=', $property_cert];
$estate_info_res = Db::name('estate_info')->where($where)->find();
if ($estate_info_res) {
$fill = [];
$fill['year'] = $year;
$fill['property_cert'] = $property_cert;
$fill['building_name'] = $estate_info_res['building_name']; //楼盘名称
$fill['building_no'] = $estate_info_res['building_no']; //栋号
$fill['unit_no'] = $estate_info_res['unit_no']; //房号
$fill['reg_price'] = $estate_info_res['register_price']; //登记价
$fill['purchase_date'] = $estate_info_res['buy_date'];
$fill['size'] = $estate_info_res['floor_area'];
$fill['usage'] = $estate_info_res['house_usage']; //房屋用途
$fill['parcel_usage'] = $estate_info_res['land_use']; //土地用途
$fill['max_land_use_years'] = $estate_info_res['land_use_year']; //土地使用年限
$fill['land_use_start_time'] = $estate_info_res['land_use_begin']; //土地使用开始时间
$fill['land_use_end_time'] = $estate_info_res['land_use_end']; //土地使用结束时间
$fill['parcel_no'] = $estate_info_res['zdbh'];
$fill['parcel_area'] = $estate_info_res['zd_area'];
$fill['obligee'] = $estate_info_res['obligee'];
$fill['cert_no'] = $estate_info_res['id_number'];
$fill['land_location'] = $estate_info_res['land_location'];
$fill['use_right_source'] = $estate_info_res['house_property'];
$fill['completion_date'] = $estate_info_res['completion_date']; //竣工日期
if ((time()-strtotime($fill['purchase_date']))>365*2*24*3600) {
$fill['is_tran_tax_free'] = 1; //满两年
} else {
$fill['is_tran_tax_free'] = 2; //没有满两年
}
return $this->buildSuccess(['show'=>$estate_info_res['new_online_info'], 'fill'=>$fill]);
} else {
return $this->buildFailed('房产信息库还没有录入该房产信息');
}
}
// 楼盘名称模糊匹配搜索
public function getEstate() {
$building_name = $this->request->post('building_name'); //楼盘名称关键字
$map = [];
$map[] = ['building_name', 'like', '%'.$building_name.'%'];
$estate_name_data = Db::name('estate_info')
->distinct(true)
->field('building_name')
->where($map)
->order('building_name', 'asc')
->select();
if ($estate_name_data) {
return $this->buildSuccess($estate_name_data);
} else {
return $this->buildFailed('无数据');
}
}
// 楼栋号模糊匹配搜索
public function getBuildingNumber() {
$building_name = $this->request->post('building_name'); //楼盘名称
$building_no = $this->request->post('building_no'); //楼栋号关键字
$map = [];
$map[] = ['building_name', '=', $building_name];
$map[] = ['building_no', 'like', '%'.$building_no.'%'];
$building_number_data = Db::name('estate_info')
->distinct(true)
->field('building_no')
->where($map)
->order('building_no', 'asc')
->select();
if ($building_number_data) {
return $this->buildSuccess($building_number_data);
} else {
return $this->buildFailed('无数据');
}
}
// 房号模糊匹配搜索
public function getHouseNumber() {
$building_name = $this->request->post('building_name'); //楼盘名称
$building_no = $this->request->post('building_no'); //楼栋号
$unit_no = $this->request->post('unit_no'); //房号关键字
$map = [];
$map[] = ['building_name', '=', $building_name];
$map[] = ['building_no', '=', $building_no];
$map[] = ['unit_no', 'like', '%'.$unit_no.'%'];
$house_number_data = Db::name('estate_info')
->where($map)
->order('unit_no', 'asc')
->select();
if ($house_number_data) {
$return_data = [];
foreach ($house_number_data as $key=>$value) {
$value['year'] = $value['estate_year'];
$value['property_cert'] = $value['estate_cert_num'];
$value['purchase_date'] = $value['purchase_date'];
$value['size'] = $value['floor_area'];
$value['usage'] = $value['house_usage'];
$value['use_right_source'] = $value['house_property'];
$return_data[] = $value;
}
return $this->buildSuccess($return_data);
} else {
return $this->buildFailed('无数据');
}
}
/**
* @api {get} admin/CheckFile/addConsult 添加查档
*
*/
public function addConsult($data){
$res = Db::name('consult_record_det')->where(['id'=>$data['consult_id']])->find();
$adddata['order_no'] = $data['order_no'];
$adddata['property_cert_info_id'] = $data['property_cert_info_id'];
$adddata['new_online_info'] = isset($res['estatestatus']) && !empty($res['estatestatus']) ? (new Dictionary())->getcodeByvalname('PROPERTY_STATUS', $res['estatestatus']) : ''; //根据返回的查询结果获得房产状态
$adddata['estate_inquiry_text'] = $res['estatestatus']?? '';
$list = isset($res['data_list']) && !empty($res['data_list']) ? json_decode($res['data_list'], true) : '';
$adddata['mortgage_text'] = $this->getMortgageText($list[0]) ?: NULL; //抵押信息(抵押权人、抵押时间
$adddata['result_code'] = 1;
$adddata['user_id'] = $data['user_id'];
$adddata['create_time'] = $res['create_time']??date('Y-m-d H:i:s');
$adddata['consult_record_det_id'] = $data['consult_id'];
$consult_record_id = Db::name('consult_record')->insertGetId($adddata);
if(!$consult_record_id){
return false;
}
return true;
}
/**
* 保存base64图片
* @param $content 图片内容
* @param $path 保存路径
* @return null|string
*/
public function base64ToImage($content, $directory = 'checkfile') {
if (!$content) {
return false;
}
//判断是否有逗号 如果有就截取后半部分
if (strstr($content, ",")) {
$content = explode(',', $content);
$content = $content[1];
}
//图片上传路径
$file_path = DS . 'uploads' . DS . $directory . DS . date('Ymd') . DS;
//图片名称
$image_path = md5(time() . mt_rand(1000, 9999)) . '.png';
//全路径
$path = ROOT_PATH . 'public' . $file_path;
//判断目录是否存在 不存在就创建
!is_dir($path) && mkdir($path, 0755, true);
try {
if (file_put_contents($path . $image_path, base64_decode($content))) {
$upload = ossUpload($file_path.$image_path, $path.$image_path);
unlink($path.$image_path); //把本地图片删除
if ($upload['code'] == 1){
//返回图片路径
return $file_path . $image_path;
}else{
Log::record($upload['msg'], 'error');
return false;
}
} else {
return false;
}
} catch (\Exception $e) {
Log::record($e->getMessage(), 'error');
return false;
}
}
/**
* 处理抵押信息(抵押权人、抵押时间)'
*/
public function getMortgageText($list) {
$mortgage_text = '';
if (!empty($list)) {
foreach ($list as $key => $v) {
if ($v['key'] == '抵押权人') {
$mortgage_text .= $v['value'];
}
if ($v['key'] == '抵押日期') {
$mortgage_text .= '(' . $v['value'] . ');';
}
}
//删除最后一个字符(;)
if (!empty($mortgage_text)) {
$mortgage_text = substr($mortgage_text, 0, -1);
}
}
return $mortgage_text;
}
/**
* @api {get} admin/CheckFile/checkRecord 查档历史
*
*/
public function checkRecord() {
$property_cert_info_id = $this->request->post('property_cert_info_id');
$res = Db::name('consult_record')->alias('r')
->join('property_cert_info d', 'r.property_cert_info_id = d.id')
->field('d.owner_name,d.building_name,d.property_cert,r.mortgage_text,estate_inquiry_text,r.create_time,r.result_code,d.year')
->where(['r.property_cert_info_id'=>$property_cert_info_id])
->order('r.create_time desc')
->limit(10)
->select();
foreach ($res as &$val){
$val['result_code_str'] = ($val['result_code'] == 1) ? '成功' : (($val['result_code'] == 2) ? '查询失败': '网络问题');
}
return $this->buildSuccess($res);
}
/**
* @api {get} admin/CheckFile/checkAgain 再次查档
*
*/
public function checkAgain(){
$order_no = $this->request->post('order_no');
$property_cert_info_id = $this->request->post('property_cert_info_id');
$year = $this->request->post('year'); //年份
$property_cert = $this->request->post('property_cert'); //房产证号
if(!$order_no || !$property_cert_info_id || !$property_cert) return $this->buildFailed('参数错误');
if($year){
$param = ['proveCode1'=>$year, 'proveCode2'=>$property_cert];
}else{
$param = ['proveCode'=>$property_cert];
}
$consultfile = new Consultfiles;
$res = $consultfile->Consultfiles($param);
Db::startTrans();
try{
if($res['code'] != 1 || (isset($res['msg']) && $res['msg'] == '没有房产')) return $this->buildFailed('没有房产');
$adddata['order_no'] = $order_no;
$adddata['property_cert_info_id'] = $property_cert_info_id;
$adddata['new_online_info'] = (new Dictionary())->getcodeByvalname('PROPERTY_STATUS', $res['estatestatus']); //根据返回的查询结果获得房产状态
$adddata['estate_inquiry_text'] = $res['estatestatus'];
$list = !empty($res['result']['data'][0]['list']) ? $res['result']['data'][0]['list'] : '';
$adddata['mortgage_text'] = $this->getMortgageText($list) ?: NULL; //抵押信息(抵押权人、抵押时间
$adddata['result_code'] = 1;
$adddata['user_id'] = $this->userInfo['user_id'];
$adddatadet = [
'code' => $res['result']['code'],
'msg' => $res['result']['msg'],
'data_printResult' => implode(',', array_column($res['result']['data'], 'printResult')),//$result['data']['printResult'],
'data_status_txt' => implode(',', array_column($res['result']['data'], 'status_txt')),//$result['data']['status_txt'],
'data_list' => json_encode(array_column($res['result']['data'], 'list'))//json_encode($result['data']['list'])
];
// if (isset($res['result']['img_base64']) && !empty($res['result']['img_base64'])) {
// $adddata['img_url'] = $this->base64ToImage($res['result']['img_base64']);
// if (!$adddata['img_url']) {
// Db::rollback();
// return $this->buildFailed(ReturnCode::ADD_FAILED, '上传图片失败!');
// }
//}
//新增查档记录
$adddata['create_time'] = date('Y-m-d H:i:s');
$consult_record_id = Db::name('consult_record')->insertGetId($adddata);
if(!$consult_record_id){
Db::rollback();
return $this->buildFailed('查档记录新增失败');
}
//新增查档记录详情
$adddatadet['create_time'] = $adddatadet['update_time'] = date('Y-m-d H:i:s');
if(!Db::name('consult_record_det')->insert($adddatadet)){
Db::rollback();
return $this->buildFailed('查档记录详情新增失败');
}
Db::commit();
return $this->buildSuccess();
}catch (\Exception $e){
Db::rollback();
return $this->buildFailed('该房产信息不存在'. $e->getMessage());
}
}
}