first commit

This commit is contained in:
annnj-company
2026-04-17 18:29:53 +08:00
parent e49fa5a215
commit 130c1026c4
5615 changed files with 1639145 additions and 0 deletions

View File

@@ -0,0 +1,74 @@
<?php
namespace app\admin\service;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
* Description of RestFullService
*
* @author Administrator
*/
use think\facade\Request;
class ApiService {
public static $msg = [
0 => "success",
1 => "数据验证不通过",
2 => "未关注公众号,请先关注!",
100 => "未识别错误!",
101 => '链接微信服务器失败',
102 => '请在微信浏览器打开',
103 => '获取微信数据失败',
1001 => '手机号已注册',
99998 => '对不起,您未取得该业务的操作权限,请联系管理员后再试',
99999 => '请勿异常操作'
];
/**
* 获取错误消息
*/
public static function getMsg($code) {
if (isset(self::$msg[$code]))
return self::$msg[$code];
return self::getMsg(100);
}
/**
* url地址组装
*/
public static function urlParse($url, $array) {
$pre = "?";
strpos($url, '?') !== FALSE && $pre = "&";
foreach ($array as $key => $v) {
$url .= "$pre$key=$v";
}
return $url;
}
public static function is_allow() {
$user_agent = strtolower(Request::server('HTTP_USER_AGENT'));
if (strpos($user_agent, 'windowswechat') !== false) {
//判断是否在白名单
$allow_ips = [];
$ip = Request::ip();
if (!in_array($ip, $allow_ips)) {
//apiErrMsg('请在手机端打开Ai临沂-核酸检测小程序', 99998);
}
}
if (strpos($user_agent, 'micromessenger') === false) {
//判断是否在白名单
$allow_ips = [];
$ip = Request::ip();
if (!in_array($ip, $allow_ips)) {
apiErrMsg('请使用微信小程序访问或升级到最新版微信后重试', 99998);
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,969 @@
<?php
namespace app\admin\service;
use app\common\validate\boc\CommonValidate;
use app\lib\BOC\BocCipherUtil;
use app\lib\HexUtil;
use app\lib\MySm4;
use Mdanter\Ecc\Serializer\PublicKey\DerPublicKeySerializer;
use Mdanter\Ecc\Serializer\PublicKey\PemPublicKeySerializer;
use Rtgm\ecc\RtEccFactory;
use Rtgm\sm\RtSm2;
use think\Db;
use think\facade\Log;
use think\facade\Response;
class BocCommonService extends CommonService
{
private $boc_sm2_public_key = ''; //中行公钥
private $gz_sm2_public_key = ''; //国中公钥
private $gz_sm2_private_key = ''; //国中私钥
private $plain_text = ''; //数据明文
private $plain_boc_sm2_public_key = '';
private $plain_sm2_private_key = '';
private $plain_gz_sm2_public_key = '';
// 银行接收预评估结果接口
private $pre_result_uri = '/cgs/pggsApi/estimate/receivePreResult/v3';
// 银行接收正式评估结果接口
private $apply_official_result_uri = '/cgs/pggsApi/estimate/receiveOff/v3';
private $base_url = '';
private $company_code = '';
private $inquiry_info = null;
private $property_cert_info = [];
private $survey_info = null;
private $latest_return_price_info = null;
private $report_info = null;
private $report_detail_list = [];
private $common_main_info = null;
private $preapply_info = null;
private $apply_official_info = null;
private $apply_official_pre_estimate_list = [];
private $sm2 = null;
public function __construct()
{
$this->base_url = env('boc_common.base_url');
$this->company_code = env('boc_common.company_code');
$this->boc_sm2_public_key = env('boc_common.boc_sm2_public_key');
$this->gz_sm2_public_key = env('boc_common.gz_sm2_public_key');
$this->gz_sm2_private_key = env('boc_common.gz_sm2_private_key');
$this->sm2 = new RtSm2();
$adapter = RtEccFactory::getAdapter();
$this->plain_boc_sm2_public_key = $this->getPublicKeyPlainText($adapter, $this->boc_sm2_public_key);
$this->plain_gz_sm2_public_key = $this->getPublicKeyPlainText($adapter, $this->gz_sm2_public_key);
$this->plain_gz_sm2_private_key = $this->getPrivateKeyPlainText($this->gz_sm2_private_key);
}
public function getPrivateKeyPlainText($base64_private_key)
{
$private_key_decoded = base64_decode($base64_private_key);
$private_key_hex = bin2hex($private_key_decoded);
$private_key_start = strpos($private_key_hex, '0420');
if ($private_key_start !== false) {
return substr($private_key_hex, $private_key_start + 4, 64);
}
return '';
}
public function getPublicKeyPlainText($adapter, $base64_public_key)
{
// 为 Base64 密钥添加 PEM 格式头和尾
$public_key_pem = "-----BEGIN PUBLIC KEY-----\n" . chunk_split($base64_public_key, 64, "\n") . "-----END PUBLIC KEY-----\n";
$pemPublicSerializer = new PemPublicKeySerializer(new DerPublicKeySerializer($adapter));
$publicKeyObject = $pemPublicSerializer->parse($public_key_pem);
$pubPoint = $publicKeyObject->getPoint();
$pubX = $this->sm2->decHex($pubPoint->getX());
$pubY = $this->sm2->decHex($pubPoint->getY());
return '04' . $pubX . $pubY;
}
public function verifySign($cipher_key, $cipher_text, $sign)
{
$sm4_key = $this->sm2->doDecrypt($cipher_key, $this->plain_gz_sm2_private_key);
$sm4 = new MySm4($sm4_key);
$plain_text = $sm4->decrypt($cipher_text);
$verify_res = $this->sm2->verifySign($plain_text, $sign, $this->plain_boc_sm2_public_key);
if ($verify_res) {
$this->plain_text = $plain_text;
}
return $verify_res;
}
public function getPlainText()
{
return $this->plain_text;
}
public function encryptData($data)
{
Log::error("----encryptData----");
$data_str = json_encode($data, JSON_UNESCAPED_UNICODE);
Log::error("----data_str----");
Log::error($data_str);
$sign = $this->sm2->doSign($data_str, $this->plain_gz_sm2_private_key);
Log::error("----sign----");
Log::error($sign);
$sm4Key = HexUtil::encodeHexStr(BocCipherUtil::generateKey());
Log::error("----sm4_key----");
Log::error($sm4Key);
$sm4 = new MySm4($sm4Key);
$cipher_text = $sm4->encrypt($data_str);
Log::error("----cipher_text----");
Log::error(strlen($cipher_text));
$cipher_key = '04' . strtoupper($this->sm2->doEncrypt($sm4Key, $this->plain_boc_sm2_public_key));
Log::error("----cipher_key----");
Log::error($cipher_key);
Log::error("----encryptData----");
return [
'cipherkey' => $cipher_key,
'ciphertext' => $cipher_text,
'sign' => $sign,
'plain_text' => $data_str,
];
}
public function decryptData($result_data)
{
Log::error("----decryptData----");
$sm4_key = $this->sm2->doDecrypt($result_data['cipherkey'], $this->plain_gz_sm2_private_key);
Log::error("----sm4_key----");
Log::error($sm4_key);
$sm4 = new MySm4($sm4_key);
$plain_text = $sm4->decrypt($result_data['ciphertext']);
Log::error("----plain_text----");
Log::error($plain_text);
Log::error("----decryptData----");
return json_decode($plain_text, true);
}
/**
* 组装发送给中行的返回数据(用于返回客户端)
* @param $code string 响应码 0=成功
* @param $message string 响应消息
* @parma $other_response_biz_content array 其他业务响应参数
* @param $req_date array 请求参数
* @return \think\response
*/
public function buildResponseData(
string $code,
string $message,
array $req_data
)
{
// 业务响应参数
$response_content = [
'code' => $code,
'message' => $message,
'data' => null,
];
$resp_data = $this->encryptData($response_content);
if (!empty($resp_data) && !empty($req_data)) {
$insert_boc_req_resp = [
'direct' => 2,
'req_cipher_key' => $req_data['cipherkey'] ?? '',
'req_cipher_text' => $req_data['ciphertext'] ?? '',
'req_sign' => $req_data['sign'],
'req_plain_text' => $this->plain_text,
'resp_cipher_key' => $resp_data['cipherkey'],
'resp_cipher_text' => $resp_data['ciphertext'],
'resp_sign' => $resp_data['sign'],
'resp_plain_text' => $resp_data['plain_text'],
'create_time' => date('Y-m-d H:i:s'),
'update_time' => date('Y-m-d H:i:s'),
];
Db::name('boc_req_resp')->insert($insert_boc_req_resp);
}
unset($resp_data['plain_text']);
$resp_data['companyCode'] = $this->company_code;
$headers['content-type'] = 'application/json';
return Response::create(json_encode($resp_data, 256), '', 200, $headers);
}
private function getInquiryInfo($quot_id)
{
$this->inquiry_info = Db::name('inquiry')->where('id', $quot_id)->find();
if (empty($this->inquiry_info)) {
Log::error("询价单不存在");
Log::error("quot_id:{$quot_id}");
return '询价单不存在';
}
return true;
}
private function getPropertyCertInfo($quot_id)
{
$this->property_cert_info = Db::name('property_cert_info')->where('quot_id', $quot_id)->select();
if (empty($this->property_cert_info)) {
Log::error("物业信息不存在");
Log::error("quot_id:{$quot_id}");
return '物业信息不存在';
}
return true;
}
private function getSurveyInfo($property_cert_info_ids)
{
$this->survey_info = Db::name('survey')->where('property_cert_info_id', 'in', $property_cert_info_ids)->select();
return true;
}
private function getReportInfo($quot_id)
{
$this->report_info = Db::name('report')
->where('quot_id', $quot_id)
->find();
if (empty($this->report_info)) {
Log::error("报告单不存在");
return '报告单不存在';
}
$this->report_detail_list = Db::name('report_detail')
->where('report_id', $this->report_info['id'])
->column('*', 'property_cert_info_id');
if (empty($this->report_detail_list)) {
Log::error("报告单详情不存在");
return '报告单详情不存在';
}
return true;
}
private function getCommonMain($quot_id)
{
$this->common_main_info = Db::name('boc_common_main')
->where('quot_id', $quot_id)
->find();
if (empty($this->common_main_info)) {
Log::error("中行发起的记录不存在");
return '中行发起的记录不存在';
}
return true;
}
private function getPreApplyInfo($boc_common_id)
{
$this->preapply_info = Db::name('boc_common_preapply')
->where('boc_common_id', $boc_common_id)
->find();
if (empty($this->preapply_info)) {
Log::error("中行发起的预评估记录不存在");
return '中行发起的预评估记录不存在';
}
return true;
}
private function getApplyOfficialInfo($bank_estimate_no)
{
$this->apply_official_info = Db::name('boc_common_apply_official')
->where('bankEstimateNo', $bank_estimate_no)
->find();
if (empty($this->apply_official_info)) {
Log::error("中行发起的正式评估记录不存在");
return '中行发起的正式评估记录不存在';
}
return true;
}
private function getApplyOfficialPreEstimateList($boc_common_apply_official_id)
{
$list = Db::name('boc_common_apply_official_pre_estimate')
->where('boc_common_apply_official_id', $boc_common_apply_official_id)
->select();
$this->apply_official_pre_estimate_list = Db::name('boc_common_preapply')
->where('bankPreEstimateNo', 'in', array_column($list, 'preEstimateNo'))
->select();
if (empty($this->apply_official_pre_estimate_list)) {
Log::error("中行发起的预评估记录不存在");
return '中行发起的预评估记录不存在';
}
return true;
}
public function savePreApply($data)
{
try {
Db::startTrans();
$boc_common_id = Db::name('boc_common_main')->insertGetId([
'bankPreEstimateNo' => $data['bankPreEstimateNo'],
'create_time' => date('Y-m-d H:i:s'),
'update_time' => date('Y-m-d H:i:s'),
]);
if ($boc_common_id === false) {
Db::rollback();
return '保存预评估数据失败';
}
$boc_common_preapply_id = Db::name('boc_common_preapply')->insertGetId([
'boc_common_id' => $boc_common_id,
'bankPreEstimateNo' => $data['bankPreEstimateNo'],
'bankerName' => $data['bankerName'],
'bankerPhone' => $data['bankerPhone'],
'estimateType' => $data['estimateType'] ?? '',
'propertyName' => $data['propertyName'] ?? '',
'channelCode' => $data['channelCode'],
'timestamp' => $data['timestamp'],
'companyCode' => $data['companyCode'],
'create_time' => date('Y-m-d H:i:s'),
'update_time' => date('Y-m-d H:i:s'),
]);
if ($boc_common_preapply_id === false) {
Db::rollback();
return '保存预评估数据失败';
}
$propertyCard = json_decode($data['propertyCard'], true);
$propertyCardType = json_decode($data['propertyCardType'], true);
if (count($propertyCard) != count($propertyCardType)) {
Db::rollback();
return '产权证数量和产权证文件格式的数量不一致';
}
$boc_common_preapply_property_card_inst_data = [];
$oss_service = new OssService();
$mime_types = [
'jpg' => 'image/jpg',
'jpeg' => 'image/jpeg',
'png' => 'image/png',
'gif' => 'image/gif',
'pdf' => 'application/pdf',
];
foreach ($propertyCard as $k => $v) {
$url = '';
$mime_type = '';
foreach ($mime_types as $ext => $mime_type) {
if ($ext == $propertyCardType[$k]) {
$temp_file = str_replace('\\', '/', tempnam(sys_get_temp_dir(), 'cos_'));
file_put_contents($temp_file, base64_decode($v));
$ossPath = '/uploads' . '/' . date('Ymd') . '/' . $data['bankPreEstimateNo'] . '-' . ($k + 1) . '.' . $ext;
$url = $oss_service->uploadSingleFile($ossPath, $temp_file, $mime_type);
if (file_exists($temp_file)) {
unlink($temp_file);
}
break;
}
}
$boc_common_preapply_property_card_inst_data[] = [
'boc_common_id' => $boc_common_id,
'boc_common_preapply_id' => $boc_common_preapply_id,
'propertyCard' => "data:{$mime_type};base64," . $v,
'propertyCardType' => $propertyCardType[$k],
'propertyCardFileUrl' => str_replace('\\', '/', $url),
'create_time' => date('Y-m-d H:i:s'),
'update_time' => date('Y-m-d H:i:s'),
];
}
if (!empty($boc_common_preapply_property_card_inst_data)) {
$res = Db::name('boc_common_preapply_property_card')->insertAll($boc_common_preapply_property_card_inst_data);
if ($res === false) {
Db::rollback();
return '保存预评估数据失败';
}
}
Db::commit();
} catch (\Exception $e) {
Db::rollback();
Log::error('错误文件:' . $e->getFile());
Log::error('错误行数:' . $e->getLine());
Log::error('错误编码:' . $e->getCode());
Log::error('错误信息:' . $e->getMessage());
return '保存预评估数据失败';
}
return true;
}
public function saveApplyOfficial($data)
{
try {
Db::startTrans();
$boc_common_insert_data = [];
if (strtoupper($data['channelCode']) == 'XJ') {
if (!empty($data['preEstimateNoList']) && count($data['preEstimateNoList']) == 1) {
$boc_common_insert_data['is_related'] = 2; //自动关联上
$inquiry_info = Db::name('inquiry')->where('estimated_no', $data['preEstimateNoList'][0])->order('id desc')->find();
if (!empty($inquiry_info)) {
$boc_common_insert_data['quot_id'] = $inquiry_info['id'];
$boc_common_insert_data['order_no'] = $inquiry_info['order_no'];
}
}
}
$boc_common_insert_data['bankEstimateNo'] = $data['bankEstimateNo'];
$boc_common_id = Db::name('boc_common_main')->insertGetId($boc_common_insert_data);
if ($boc_common_id === false) {
Db::rollback();
return '保存正式评估数据失败';
}
$boc_common_apply_official_id = Db::name('boc_common_apply_official')->insertGetId([
'boc_common_id' => $boc_common_id,
'bankEstimateNo' => $data['bankEstimateNo'],
'preEstimateNoList' => $data['preEstimateNoList'],
'timestamp' => $data['timestamp'],
'reportType' => $data['reportType'],
'companyCode' => $data['companyCode'],
'channelCode' => $data['channelCode'],
'create_time' => date('Y-m-d H:i:s'),
'update_time' => date('Y-m-d H:i:s'),
]);
if ($boc_common_apply_official_id === false) {
Db::rollback();
return '保存正式评估数据失败';
}
$boc_common_apply_official_pre_estimate_data = [];
foreach ($data['preEstimateNoList'] as $k => $v) {
$boc_common_apply_official_pre_estimate_data[] = [
'boc_common_id' => $boc_common_id,
'boc_common_apply_official_id' => $boc_common_apply_official_id,
'bankEstimateNo' => $data['bankEstimateNo'],
'preEstimateNo' => $v,
'create_time' => date('Y-m-d H:i:s'),
'update_time' => date('Y-m-d H:i:s'),
];
}
if (!empty($boc_common_apply_official_pre_estimate_data)) {
$res = Db::name('boc_common_apply_official_pre_estimate')->insertAll($boc_common_apply_official_pre_estimate_data);
if ($res === false) {
Db::rollback();
return '保存正式评估预评估数据失败';
}
}
Db::commit();
} catch (\Exception $e) {
Log::error('错误文件:' . $e->getFile());
Log::error('错误行数:' . $e->getLine());
Log::error('错误编码:' . $e->getCode());
Log::error('错误信息:' . $e->getMessage());
return false;
}
return true;
}
public function sendPreResult($quot_id)
{
// 获取询价单信息
if (($res = $this->getInquiryInfo($quot_id)) !== true) {
return $res;
}
if ($this->inquiry_info['status'] == 1) {
return '询价单未回价';
}
if (empty($this->inquiry_info['business_no'])) {
Log::error("询价单业务编号为空");
Log::error("quot_id:{$quot_id}");
return '询价单业务编号为空';
}
if (empty($this->inquiry_info['estimate_url'])) {
return '预估单未上传';
}
// 获取物业信息
if (($res = $this->getPropertyCertInfo($quot_id)) !== true) {
return $res;
}
// 获取查勘信息
$this->getSurveyInfo(array_column($this->property_cert_info, 'id'));
if (($res = $this->getCommonMain($quot_id)) !== true) {
return $res;
}
// 获取中行发起的预评估记录
if (($res = $this->getPreApplyInfo($this->common_main_info['id'])) !== true) {
return $res;
}
$plain_data = [
'bankPreEstimateNo' => $this->preapply_info['bankPreEstimateNo'],
'preEstimateNo' => $this->inquiry_info['estimated_no'],
'estimateNo' => $this->inquiry_info['estimated_no'],
'roomArea' => $this->property_cert_info[0]['size'],
'unitPrice' => $this->property_cert_info[0]['eva_unit_price'],
'totalPrice' => $this->property_cert_info[0]['eva_total_value'],
'averagePrice' => 0,
'name' => $this->property_cert_info[0]['appraiser_name'],
'tax' => $this->property_cert_info[0]['total_taxes1'],
'finishedDate' => date('Ymd', strtotime($this->property_cert_info[0]['completion_time'])),
'ownerName' => $this->property_cert_info[0]['owner_name'],
'propertyName' => $this->property_cert_info[0]['land_location'] . $this->property_cert_info[0]['property_full_name'],
'cityName' => $this->property_cert_info[0]['city'],
'districtName' => $this->survey_info ? $this->survey_info[0]['area'] : '暂无信息',
'projectName' => $this->property_cert_info[0]['property_full_name'],
'propertyUse' => getDictionaryName('HOUSE_USAGE', $this->property_cert_info[0]['usage']),
'price1' => $this->property_cert_info[0]['eva_net_value'],
'price2' => $this->property_cert_info[0]['eva_net_value2'],
'price' => $this->property_cert_info[0]['eva_net_value2'],
'appraisedNetValue' => $this->property_cert_info[0]['eva_net_value2'] - $this->property_cert_info[0]['statutory_payment'],
'status' => '03',
'fileContent' => '',
'fileName' => basename(parse_url(str_replace('\\', '/', $this->inquiry_info['estimate_url']), PHP_URL_PATH)),
'fileIndex' => base64_encode(file_get_contents($this->inquiry_info['estimate_url'])),
'coveredArea' => 0,
'evalTime' => date('Ymd', $this->property_cert_info[0]['r_create_time']),
'telephoneNumber' => '',
'regPrice' => $this->property_cert_info[0]['reg_price'],
'landNo' => '',
'landLimitDate' => '',
'landBgnDate' => '',
'landEndDate' => '',
'houseProperty' => getDictionaryName('USE_RIGHT_SOURCE', $this->property_cert_info[0]['use_right_source']),
'registDate' => date('Ymd', strtotime($this->property_cert_info[0]['purchase_date'])),
'timestamp' => (int)round(microtime(true) * 1000),
'companyCode' => $this->preapply_info['companyCode'],
'intentReportType' => '01',
'channelCode' => $this->preapply_info['channelCode'],
'referencePrice' => $this->property_cert_info[0]['reference_price'] ?? 0,
'transactionTotalPrice' => $this->property_cert_info[0]['transaction_total_price'] ?? 0,
'transactionGrossArea' => $this->property_cert_info[0]['transaction_gross_area'] ?? 0,
'transactionDate' => $this->property_cert_info[0]['transaction_date'] ? date('Ymd', strtotime($this->property_cert_info[0]['transaction_date'])) : '',
];
$return_price = Db::name('return_price')->where('property_cert_info_id', $this->property_cert_info[0]['id'])->order('id desc')->find();
$tax_detail = [];
if (!empty($return_price)) {
$tax_detail[] = [
'TaxName' => '增值税',
'TaxValue' => $return_price['added_tax'],
];
$tax_detail[] = [
'TaxName' => '城建税',
'TaxValue' => $return_price['urban_construction_tax'],
];
$tax_detail[] = [
'TaxName' => '教育附加费',
'TaxValue' => $return_price['edu_surcharge'],
];
$tax_detail[] = [
'TaxName' => '土地增值税',
'TaxValue' => $return_price['land_value_added_tax'],
];
$tax_detail[] = [
'TaxName' => '印花税',
'TaxValue' => $return_price['stamp_duty'],
];
$tax_detail[] = [
'TaxName' => '个人所得税',
'TaxValue' => $return_price['personal_income_tax'],
];
$tax_detail[] = [
'TaxName' => '契税',
'TaxValue' => $return_price['deed_tax'],
];
$tax_detail[] = [
'TaxName' => '企业所得税',
'TaxValue' => $return_price['corporate_income_tax'],
];
$tax_detail[] = [
'TaxName' => '拍卖费',
'TaxValue' => $return_price['auction_fee'],
];
$tax_detail[] = [
'TaxName' => '交易服务费',
'TaxValue' => $return_price['tran_service_fee'],
];
}
$plain_data['taxDetail'] = json_encode($tax_detail, JSON_UNESCAPED_UNICODE);
$req_data = $this->encryptData($plain_data);
unset($req_data['plain_text']);
$req_data['companyCode'] = $this->company_code;
Log::error('req_data:');
Log::error($req_data);
$curl_result = curlRequest($this->base_url . $this->pre_result_uri, 'POST', $req_data, [
'Content-Type: application/json',
], [], [], 0);
Log::error('url:');
Log::error($this->base_url . $this->pre_result_uri);
Log::error('curl_result:');
Log::error($curl_result);
$result_string = $curl_result['data'];
$result_data = json_decode($result_string, true);
$validate = new CommonValidate();
if (!$validate->check($result_data)) {
Log::error('validate error:');
Log::error($validate->getError());
return $validate->getError();
}
if (!$this->verifySign($result_data['cipherkey'], $result_data['ciphertext'], $result_data['sign'])) {
Log::error('verifySign error:');
Log::error('验签失败');
return '验签失败';
}
$resp_data = $this->decryptData($result_data);
if (isset($resp_data['code']) && $resp_data['code'] == 0) {
return true;
}
return '发送预评估结果失败';
}
public function sendApplyOfficialResult($quot_id)
{
// 获取询价单信息
if (($res = $this->getInquiryInfo($quot_id)) !== true) {
return $res;
}
if ($this->inquiry_info['status'] != 8) {
return '询价单未生成报告';
}
if (($res = $this->getPropertyCertInfo($quot_id)) !== true) {
return $res;
}
if (($res = $this->getReportInfo($this->inquiry_info['id'])) !== true) {
return $res;
}
$preEstimateNo = '';
if (!empty($this->inquiry_info['business_no'])) { //线上
if ($this->inquiry_info['loan_type'] == '二手按揭') { // 消金
$this->apply_official_pre_estimate_list = Db::name('boc_common_preapply')->where('bankPreEstimateNo', $this->inquiry_info['business_no'])->select();
if (empty($this->apply_official_pre_estimate_list)) {
return '预评估记录不存在';
}
$bank_estimate_no = Db::name('boc_common_main')
->where('order_no', $this->inquiry_info['order_no'])
->where('bankEstimateNo IS NOT NULL AND bankEstimateNo != ""')
->value('bankEstimateNo');
$this->apply_official_info = Db::name('boc_common_apply_official')
->where('bankEstimateNo', $bank_estimate_no)
->find();
if (empty($this->apply_official_info)) {
Log::error("中行发起的正式评估记录不存在");
return '中行发起的正式评估记录不存在';
}
$preEstimateNo = json_decode($this->apply_official_info['preEstimateNoList'], true)[0];
} else { // todo 不会走到普惠,目前没有普惠业务,如果有普惠业务,这里需要修改这个 $this->apply_official_pre_estimate_list 2026-02-12
if (($res = $this->getApplyOfficialInfo($this->inquiry_info['business_no'])) !== true) {
return $res;
}
if (($res = $this->getApplyOfficialPreEstimateList($this->apply_official_info['id'])) !== true) {
return $res;
}
}
$report_url = $this->report_info['report_url'];
if (!empty($this->report_info['upload_report_url'])) {
$report_url = $this->report_info['upload_report_url'];
}
$path = parse_url(str_replace('\\', '/', $report_url), PHP_URL_PATH);
$bankerName = implode(',', array_column($this->apply_official_pre_estimate_list, 'bankerName'));
$bankerPhone = implode(',', array_column($this->apply_official_pre_estimate_list, 'bankerPhone'));
$base64 = $this->pdfToBase64($report_url);
$plain_data = [
'bankEstimateNo' => $this->apply_official_info['bankEstimateNo'],
'estimateNo' => $this->report_info['report_no'],
'fileIndex' => $base64,
'fileUrl' => $report_url,
'evalTime' => $this->report_info['appraisal_time'] ? date('Ymd', strtotime($this->report_info['appraisal_time'])) : date('Ymd'),
'name' => $this->report_info['appraiser_name'],
'companyCode' => $this->company_code,
'fileType' => '02',
'fileName' => basename($path),
'channelCode' => $this->apply_official_info['channelCode'],
'bankerName' => $bankerName,
'bankerPhone' => $bankerPhone,
];
foreach ($this->apply_official_pre_estimate_list as $item) {
$preEstimatePropertyCertInfo = Db::name('property_cert_info')->alias('pci')
->field('pci.id, pci.land_location, pci.property_full_name, pci.city, pci.building_name,
pci.usage, pci.cert_usage, pci.size, pci.eva_unit_price, pci.eva_total_value, pci.reg_price, pci.purchase_date, pci.completion_time,
pci.eva_net_value, pci.eva_net_value2, pci.total_taxes1, pci.statutory_payment, pci.reference_price, pci.obligee,
pci.transaction_total_price, pci.transaction_gross_area, pci.transaction_date')
->join('inquiry i', 'i.id = pci.quot_id')
->where('i.business_no', $item['bankPreEstimateNo'])
// ->where("INSTR('{$item['propertyName']}', pci.property_full_name)")
->find();
if (empty($preEstimatePropertyCertInfo)) {
continue;
}
$survey_info = Db::name('survey')->where('property_cert_info_id', $preEstimatePropertyCertInfo['id'])->find();
if (isset($this->report_detail_list[$preEstimatePropertyCertInfo['id']])) {
$propertyStatus = 1; //默认,有效【中行中的枚举值1有效 2抵押 3查封】
if ($this->report_detail_list[$preEstimatePropertyCertInfo['id']]['otherrights_type'] == 1) { //我方:已抵押未注销
$propertyStatus = 2; //抵押
} else if ($this->report_detail_list[$preEstimatePropertyCertInfo['id']]['otherrights_type'] == 2) { //我方:无抵押
$propertyStatus = 1; //有效
} else if ($this->report_detail_list[$preEstimatePropertyCertInfo['id']]['otherrights_type'] == 3) { //我方:查封
$propertyStatus = 3; //查封
}
}
$return_price = Db::name('return_price')->where('property_cert_info_id', $preEstimatePropertyCertInfo['id'])->order('id desc')->find();
$tax_detail = [];
if (!empty($return_price)) {
$tax_detail[] = [
'TaxName' => '增值税',
'TaxValue' => $return_price['added_tax'],
];
$tax_detail[] = [
'TaxName' => '城建税',
'TaxValue' => $return_price['urban_construction_tax'],
];
$tax_detail[] = [
'TaxName' => '教育附加费',
'TaxValue' => $return_price['edu_surcharge'],
];
$tax_detail[] = [
'TaxName' => '土地增值税',
'TaxValue' => $return_price['land_value_added_tax'],
];
$tax_detail[] = [
'TaxName' => '印花税',
'TaxValue' => $return_price['stamp_duty'],
];
$tax_detail[] = [
'TaxName' => '个人所得税',
'TaxValue' => $return_price['personal_income_tax'],
];
$tax_detail[] = [
'TaxName' => '契税',
'TaxValue' => $return_price['deed_tax'],
];
$tax_detail[] = [
'TaxName' => '企业所得税',
'TaxValue' => $return_price['corporate_income_tax'],
];
$tax_detail[] = [
'TaxName' => '拍卖费',
'TaxValue' => $return_price['auction_fee'],
];
$tax_detail[] = [
'TaxName' => '交易服务费',
'TaxValue' => $return_price['tran_service_fee'],
];
}
$tmp = [
'preEstimateNo' => $preEstimateNo, // todo 不会走到普惠,目前没有普惠业务,如果有普惠业务,这里需要修改这个 $this->apply_official_pre_estimate_list 2026-02-12
'propertyName' => $preEstimatePropertyCertInfo['land_location'] . $preEstimatePropertyCertInfo['property_full_name'] . $preEstimatePropertyCertInfo['city'],
'cityName' => $preEstimatePropertyCertInfo['city'],
'districtName' => $survey_info ? $survey_info['area'] : '暂无信息',
'projectName' => $preEstimatePropertyCertInfo['building_name'],
'propertyId' => isset($this->report_detail_list[$preEstimatePropertyCertInfo['id']]) ? $this->report_detail_list[$preEstimatePropertyCertInfo['id']]['property_cert'] : '',
'propertyUse' => getDictionaryName('HOUSE_USAGE', $preEstimatePropertyCertInfo['usage']),
'propertyUseRemark' => $preEstimatePropertyCertInfo['cert_usage'],
'landNo' => isset($this->report_detail_list[$preEstimatePropertyCertInfo['id']]) ? $this->report_detail_list[$preEstimatePropertyCertInfo['id']]['parcel_no'] : '',
'landLimitDate' => isset($this->report_detail_list[$preEstimatePropertyCertInfo['id']]) ? $this->report_detail_list[$preEstimatePropertyCertInfo['id']]['max_land_use_years'] : '',
'landBgnDate' => isset($this->report_detail_list[$preEstimatePropertyCertInfo['id']]) ? date('Ymd', strtotime($this->report_detail_list[$preEstimatePropertyCertInfo['id']]['land_use_start_time'])) : '',
'landEndDate' => isset($this->report_detail_list[$preEstimatePropertyCertInfo['id']]) ? date('Ymd', strtotime($this->report_detail_list[$preEstimatePropertyCertInfo['id']]['land_use_end_time'])) : '',
'finishedDate' => date('Ymd', strtotime($preEstimatePropertyCertInfo['completion_time'])),
'registPrice' => $preEstimatePropertyCertInfo['reg_price'],
'registDate' => date('Ymd', strtotime($preEstimatePropertyCertInfo['purchase_date'])),
'houseFlag' => $preEstimatePropertyCertInfo['usage'] == 1 ? '0' : '1',
'houseArea' => $preEstimatePropertyCertInfo['size'],
'houseCity' => $preEstimatePropertyCertInfo['city'],
'ownerName' => isset($this->report_detail_list[$preEstimatePropertyCertInfo['id']]) ? $this->report_detail_list[$preEstimatePropertyCertInfo['id']]['obligee'] : '',
'ownerCertId' => isset($this->report_detail_list[$preEstimatePropertyCertInfo['id']]) ? str_replace(["", ""], ',', $this->report_detail_list[$preEstimatePropertyCertInfo['id']]['cert_no']) : '',
'ownerPortion' => isset($this->report_detail_list[$preEstimatePropertyCertInfo['id']]) ? (substr_count($this->report_detail_list[$preEstimatePropertyCertInfo['id']]['obligee_percent'], '%') == 1 ? '100%' : '') : '',
'mortName' => '',
'mortDate' => '',
'propertStatus' => $propertyStatus ?? '',
'sealupOrg' => '',
'sealupDate' => '',
'roomArea' => $preEstimatePropertyCertInfo['size'],
'unitPrice' => $preEstimatePropertyCertInfo['eva_unit_price'],
'totalPrice' => $preEstimatePropertyCertInfo['eva_total_value'],
'price1' => $preEstimatePropertyCertInfo['eva_net_value'],
'price2' => $preEstimatePropertyCertInfo['eva_net_value2'],
'price' => $preEstimatePropertyCertInfo['eva_net_value2'],
'appraisedNetValue' => $preEstimatePropertyCertInfo['eva_net_value2'] - $preEstimatePropertyCertInfo['statutory_payment'],
'tax' => $preEstimatePropertyCertInfo['total_taxes1'],
'referencePrice' => $preEstimatePropertyCertInfo['reference_price'] ?? 0,
'transactionTotalPrice' => $preEstimatePropertyCertInfo['transaction_total_price'] ?? 0,
'transactionGrossArea' => $preEstimatePropertyCertInfo['transaction_gross_area'] ?? 0,
'transactionDate' => $preEstimatePropertyCertInfo['transaction_date'] ? date('Ymd', strtotime($preEstimatePropertyCertInfo['transaction_date'])) : '',
];
$tmp['taxDetail'] = json_encode($tax_detail, 256);
$plain_data['acOffHouseEstates'][] = $tmp;
}
} else { //线下
$report_url = $this->report_info['report_url'];
if (!empty($this->report_info['upload_report_url'])) {
$report_url = $this->report_info['upload_report_url'];
}
$path = parse_url(str_replace('\\', '/', $report_url), PHP_URL_PATH);
$base64 = $this->pdfToBase64($report_url);
$plain_data = [
'estimateNo' => $this->report_info['report_no'],
'fileIndex' => $base64,
'fileUrl' => $report_url,
'evalTime' => $this->report_info['appraisal_time'] ? date('Ymd', strtotime($this->report_info['appraisal_time'])) : date('Ymd'),
'name' => $this->report_info['appraiser_name'],
'companyCode' => $this->company_code,
'fileType' => '02',
'fileName' => basename($path),
'channelCode' => 'XJ',
'bankerName' => $this->inquiry_info['bank_customer_mgr_name'],
'bankerPhone' => $this->inquiry_info['bank_customer_mgr_phone'],
];
foreach ($this->property_cert_info as $item) {
$survey_info = Db::name('survey')->where('property_cert_info_id', $item['id'])->find();
if (isset($this->report_detail_list[$item['id']])) {
$propertyStatus = 1; //默认,有效【中行中的枚举值1有效 2抵押 3查封】
if ($this->report_detail_list[$item['id']]['otherrights_type'] == 1) { //我方:已抵押未注销
$propertyStatus = 2; //抵押
} else if ($this->report_detail_list[$item['id']]['otherrights_type'] == 2) { //我方:无抵押
$propertyStatus = 1; //有效
} else if ($this->report_detail_list[$item['id']]['otherrights_type'] == 3) { //我方:查封
$propertyStatus = 3; //查封
}
}
$return_price = Db::name('return_price')->where('property_cert_info_id', $item['id'])->order('id desc')->find();
$tax_detail = [];
if (!empty($return_price)) {
$tax_detail[] = [
'TaxName' => '增值税',
'TaxValue' => $return_price['added_tax'],
];
$tax_detail[] = [
'TaxName' => '城建税',
'TaxValue' => $return_price['urban_construction_tax'],
];
$tax_detail[] = [
'TaxName' => '教育附加费',
'TaxValue' => $return_price['edu_surcharge'],
];
$tax_detail[] = [
'TaxName' => '土地增值税',
'TaxValue' => $return_price['land_value_added_tax'],
];
$tax_detail[] = [
'TaxName' => '印花税',
'TaxValue' => $return_price['stamp_duty'],
];
$tax_detail[] = [
'TaxName' => '个人所得税',
'TaxValue' => $return_price['personal_income_tax'],
];
$tax_detail[] = [
'TaxName' => '契税',
'TaxValue' => $return_price['deed_tax'],
];
$tax_detail[] = [
'TaxName' => '企业所得税',
'TaxValue' => $return_price['corporate_income_tax'],
];
$tax_detail[] = [
'TaxName' => '拍卖费',
'TaxValue' => $return_price['auction_fee'],
];
$tax_detail[] = [
'TaxName' => '交易服务费',
'TaxValue' => $return_price['tran_service_fee'],
];
}
$tmp = [
'propertyName' => $item['land_location'] . $item['property_full_name'] . $item['city'],
'cityName' => $item['city'],
'districtName' => $survey_info ? $survey_info['area'] : '暂无信息',
'projectName' => $item['building_name'],
'propertyId' => isset($this->report_detail_list[$item['id']]) ? $this->report_detail_list[$item['id']]['property_cert'] : '',
'propertyUse' => getDictionaryName('HOUSE_USAGE', $item['usage']),
'propertyUseRemark' => $item['cert_usage'],
'landNo' => isset($this->report_detail_list[$item['id']]) ? $this->report_detail_list[$item['id']]['parcel_no'] : '',
'landLimitDate' => isset($this->report_detail_list[$item['id']]) ? $this->report_detail_list[$item['id']]['max_land_use_years'] : '',
'landBgnDate' => isset($this->report_detail_list[$item['id']]) ? date('Ymd', strtotime($this->report_detail_list[$item['id']]['land_use_start_time'])) : '',
'landEndDate' => isset($this->report_detail_list[$item['id']]) ? date('Ymd', strtotime($this->report_detail_list[$item['id']]['land_use_end_time'])) : '',
'finishedDate' => date('Ymd', strtotime($item['completion_time'])),
'registPrice' => $item['reg_price'],
'registDate' => date('Ymd', strtotime($item['purchase_date'])),
'houseFlag' => $item['usage'] == 1 ? '0' : '1',
'houseArea' => $item['size'],
'houseCity' => $item['city'],
'ownerName' => isset($this->report_detail_list[$item['id']]) ? $this->report_detail_list[$item['id']]['obligee_percent'] : '',
'ownerCertId' => isset($this->report_detail_list[$item['id']]) ? str_replace(["", ""], ',', $this->report_detail_list[$item['id']]['cert_no']) : '',
'ownerPortion' => isset($this->report_detail_list[$item['id']]) ? (substr_count($this->report_detail_list[$item['id']]['obligee_percent'], '%') == 1 ? '100%' : '') : '',
'mortName' => '',
'mortDate' => '',
'propertStatus' => $propertyStatus ?? '',
'sealupOrg' => '',
'sealupDate' => '',
'roomArea' => $item['size'],
'unitPrice' => $item['eva_unit_price'],
'totalPrice' => $item['eva_total_value'],
'price1' => $item['eva_net_value'],
'price2' => $item['eva_net_value2'],
'price' => $item['eva_net_value2'],
'appraisedNetValue' => $item['eva_net_value2'] - $item['statutory_payment'],
'tax' => $item['total_taxes1'],
'referencePrice' => $item['reference_price'] ?? 0,
'transactionTotalPrice' => $item['transaction_total_price'] ?? 0,
'transactionGrossArea' => $item['transaction_gross_area'] ?? 0,
'transactionDate' => $item['transaction_date'] ? date('Ymd', strtotime($item['transaction_date'])) : '',
];
$tmp['taxDetail'] = json_encode($tax_detail, 256);
$plain_data['acOffHouseEstates'][] = $tmp;
}
}
$req_data = $this->encryptData($plain_data);
unset($req_data['plain_text']);
$req_data['companyCode'] = $this->company_code;
$curl_result = curlRequest($this->base_url . $this->apply_official_result_uri, 'POST', $req_data, [
'Content-Type: application/json',
], [], [], 0);
Log::error('curl_result:');
Log::error($curl_result);
$result_string = $curl_result['data'];
$result_data = json_decode($result_string, true);
$validate = new CommonValidate();
if (!$validate->check($result_data)) {
Log::error('validate error:');
Log::error($validate->getError());
return $validate->getError();
}
if (!$this->verifySign($result_data['cipherkey'], $result_data['ciphertext'], $result_data['sign'])) {
Log::error('verifySign error:');
Log::error('验签失败');
return '验签失败';
}
$resp_data = $this->decryptData($result_data);
if (isset($resp_data['code']) && $resp_data['code'] == 0) {
return true;
}
return '发送正式评估结果失败';
}
public function pdfToBase64($url) {
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true, // 设置为true获取完整的响应数据
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_BINARYTRANSFER => true, // 关键二进制传输选项
CURLOPT_SSL_VERIFYPEER => false, // 生产环境需开启证书验证
CURLOPT_TIMEOUT => 60, // 增加超时时间
]);
// 执行curl请求获取完整的PDF数据
$pdfData = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode !== 200 || empty($pdfData)) {
throw new Exception("PDF获取失败HTTP状态码{$httpCode}");
}
// 对完整的PDF数据进行base64编码
// 使用base64_encode函数它会自动处理填充字符确保只在末尾添加
$base64Buffer = base64_encode($pdfData);
return $base64Buffer;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,210 @@
<?php
/**
* 收费管理公用
*/
namespace app\admin\service;
class ChargeService
{
/**
* 列表页面选择搜索查询条件
*/
public function searchCondition() {
$map = [];
// 非简易报告
$map[] = ['is_simple', '=', 0];
// 业务类型搜索条件
$inquiry_type = request()->param('inquiry_type');
if (!empty($inquiry_type)) {
$map[] = ['inquiry_type', '=', $inquiry_type];
}
// 结单状态搜索条件
$charge_status = request()->param('charge_status');
if (!empty($charge_status)) {
$map[] = ['charge_status', '=', $charge_status];
}
// 银行(客户)搜索条件
$bank_customer_mgr_id = request()->param('bank_customer_mgr_id');
if (!empty($bank_customer_mgr_id)) {
// $map[] = ['bank_customer_mgr_id', '=', $bank_customer_mgr_id];
$map[] = ['bank_id', '=', $bank_customer_mgr_id];
}
// 业务员姓名关键字搜索条件
$salesman_name = request()->param('salesman_name');
if (!empty($salesman_name)) {
$map[] = ['salesman_name', 'like', '%'.$salesman_name.'%'];
}
// 结单开始时间搜索条件
$check_time_start = request()->param('check_time_start');
if (!empty($check_time_start)) {
$map[] = ['check_time', '>', $check_time_start];
}
// 结单结束时间搜索条件
$check_time_end = request()->param('check_time_end');
if (!empty($check_time_end)) {
$map[] = ['check_time', '<', $check_time_end];
}
// 城市搜索条件
$city_id = request()->param('city_id');
if (!empty($city_id)) {
$map[] = ['city_id', '=', $city_id];
}
// 地区搜索条件
$region_id = request()->param('region_id');
if (!empty($region_id)) {
$map[] = ['region_id', '=', $region_id];
}
// 物业名称关键字搜索条件
$building_name = request()->param('building_name');
if (!empty($building_name)) {
$map[] = ['building_name', 'like', '%'.$building_name.'%'];
}
// 出报告开始时间搜索条件
$report_time_start = request()->param('report_time_start');
if (!empty($report_time_start)) {
$map[] = ['report_completion_time', '>', $report_time_start];
}
// 出报告结束时间搜索条件
$report_time_end = request()->param('report_time_end');
if (!empty($report_time_end)) {
$map[] = ['report_completion_time', '<', $report_time_end];
}
return $map;
}
/**
* 汇总列表页面选择搜索查询条件(联表)
*/
public function summarySearchCondition() {
$map = [];
// 非简易报告
$map[] = ['a.is_simple', '=', 0];
// 实收状态搜索条件
$is_confirm = request()->param('is_confirm');
if (!empty($is_confirm)) {
$map[] = ['a.is_confirm', '=', $is_confirm];
}
// 收款状态搜索条件
$collection_status = request()->param('collection_status');
if (!empty($collection_status)) {
$map[] = ['a.collection_status', '=', $collection_status];
}
// 结单状态搜索条件
$charge_status = request()->param('charge_status');
if (!empty($charge_status)) {
$map[] = ['a.charge_status', '=', $charge_status];
}
// 业务员姓名关键字搜索条件
$salesman_name = request()->param('salesman_name');
if (!empty($salesman_name)) {
$map[] = ['a.salesman_name', 'like', '%'.$salesman_name.'%'];
}
// 物业名称关键字搜索条件
$building_name = request()->param('building_name');
if (!empty($building_name)) {
$map[] = ['a.building_name', 'like', '%'.$building_name.'%'];
}
// 银行(客户)搜索条件
$bank_customer_mgr_id = request()->param('bank_customer_mgr_id');
if (!empty($bank_customer_mgr_id)) {
// $map[] = ['a.bank_customer_mgr_id', '=', $bank_customer_mgr_id];
$map[] = ['a.bank_id', '=', $bank_customer_mgr_id];
}
// 城市搜索条件
$city_id = request()->param('city_id');
if (!empty($city_id)) {
$map[] = ['a.city_id', '=', $city_id];
}
// 地区搜索条件
$region_id = request()->param('region_id');
if (!empty($region_id)) {
$map[] = ['a.region_id', '=', $region_id];
}
// 出报告开始时间搜索条件
$report_time_start = request()->param('report_time_start');
if (!empty($report_time_start)) {
$map[] = ['a.report_completion_time', '>', $report_time_start];
}
// 出报告结束时间搜索条件
$report_time_end = request()->param('report_time_end');
if (!empty($report_time_end)) {
$map[] = ['a.report_completion_time', '<', $report_time_end];
}
// 结单开始时间搜索条件
$check_time_start = request()->param('check_time_start');
if (!empty($check_time_start)) {
$map[] = ['a.check_time', '>', $check_time_start];
}
// 结单结束时间搜索条件
$check_time_end = request()->param('check_time_end');
if (!empty($check_time_end)) {
$map[] = ['a.check_time', '<', $check_time_end];
}
// 所属部门搜索条件
$department_name = request()->param('department_name');
if (!empty($department_name)) {
$map[] = ['a.department_name', 'like', '%'.$department_name.'%'];
}
// 业务来源搜索条件
$order_src = request()->param('order_src');
if (!empty($order_src)) {
$map[] = ['a.order_src', '=', $order_src];
}
// 是否公积金搜索条件
$is_housing_fund = request()->param('is_housing_fund');
if (!empty($is_housing_fund)) {
$map[] = ['a.is_housing_fund', '=', $is_housing_fund];
}
// 收费方式搜索条件
$pay_type = request()->param('pay_type');
if (!empty($pay_type)) {
$map[] = ['a.pay_type', '=', $pay_type];
}
// 评估目的搜索条件
$assessment_purpose = request()->param('assessment_purpose');
if (!empty($assessment_purpose)) {
$map[] = ['a.assessment_purpose', '=', $assessment_purpose];
}
return $map;
}
/**
* 简易报告列表页面选择搜索查询条件
*/
public function simpleReportListSearchCondition() {
$map = [];
// 简易报告
$map[] = ['is_simple', '=', 1];
// 物业名称关键字搜索条件
$building_name = request()->param('building_name');
if (!empty($building_name)) {
$map[] = ['building_name', 'like', '%'.$building_name.'%'];
}
// 业务员姓名关键字搜索条件
$salesman_name = request()->param('salesman_name');
if (!empty($salesman_name)) {
$map[] = ['salesman_name', 'like', '%'.$salesman_name.'%'];
}
// 收款状态搜索条件
$simple_collection_status = request()->param('simple_collection_status');
if (!empty($simple_collection_status)) {
$map[] = ['simple_collection_status', '=', $simple_collection_status];
}
// 出报告开始时间搜索条件
$report_time_start = request()->param('report_time_start');
if (!empty($report_time_start)) {
$map[] = ['report_completion_time', '>', $report_time_start];
}
// 出报告结束时间搜索条件
$report_time_end = request()->param('report_time_end');
if (!empty($report_time_end)) {
$map[] = ['report_completion_time', '<', $report_time_end];
}
return $map;
}
}

View File

@@ -0,0 +1,333 @@
<?php
namespace app\admin\service;
use think\Db;
use app\model\Property_cert_info as InquiryDetailModel;
use app\model\Survey as SurveyModel;
use app\model\Attachment;
class CommonService
{
/**
* 封装统一验证结果
*
* @param bool $isSuccess
* @param array $errors
* @return array
*/
public function verifyResult($isSuccess = true,$errors = [])
{
return [
'is_success' => $isSuccess,
'errors' => $errors,
];
}
/**
* 基本信息
*
* @param int $id 询价单详情表id
* @return array
*/
public function getBasicDetatil($id)
{
$result = [];
$frist = Db::table('pg_property_cert_info')->alias('a')
->join(['pg_report_detail' => 'b'], 'a.id = b.property_cert_info_id')
->field('b.building_no,b.floor_no,b.building_area,b.house_use,a.reg_price,a.final_price,a.is_tran_tax_free,
b.eva_purpose,a.owner_name,a.property_cert,b.purchase_date,b.completion_date,b.obligee,b.client,
b.parcel_no,b.parcel_area,b.parcel_usage,b.test_method,b.max_land_use_years,b.anticiated_taxes,b.use_right_source,b.property_addr,
b.max_loan_years,b.purchase_price,a.city,a.property_cert,b.is_vacant,b.property_type,b.report_remark,b.risk_remark,
b.house_cert_img_ids,b.company_qualification_img_ids')
->where(['a.id' => $id])
->find();
$result['frist'] = $frist ? $frist : [];
$second = Db::table('pg_return_price')->field('eva_unit_price,eva_total_value,eva_net_value,eva_net_value2,corporate_income_tax,tran_service_fee,edu_surcharge,urban_construction_tax,deed_tax,stamp_duty,added_tax,land_value_added_tax,personal_income_tax,auction_fee,total_tax,loan_ratio,gross_value,eva_net_value,eva_net_value2,internal_remarks,external_remarks,pricing_remarks')
->where(['property_cert_info_id' => $id])->order('id', 'desc')->find();
if (!empty($second)) {
$third = ['internal_remarks' => $second['internal_remarks'], 'external_remarks' => $second['external_remarks'], 'pricing_remarks' => $second['pricing_remarks']];
unset($second['internal_remarks'], $second['external_remarks'], $second['pricing_remarks']);
} else {
$second = $third = [];
}
$result['second'] = $second;
$result['third'] = $third;
//图片:房产证
$result['four'] = [];
if (!empty($frist['house_cert_img_ids'])) {
$picinfo = explode(',', $frist['house_cert_img_ids']);
foreach ($picinfo as $value) {
$result['four']['house_cert_img_ids'][] = (new Attachment())->getUrl($value);
}
}
//图片:公司资历
if (!empty($frist['company_qualification_img_ids'])) {
$picinfo = explode(',', $frist['company_qualification_img_ids']);
foreach ($picinfo as $value) {
$result['four']['company_qualification_img_ids'][] = (new Attachment())->getUrl($value);
}
}
return $result;
}
/**
* 查勘信息
*
* @param int $id 询价单详情表id
* @param int $type 1住宅 2商业
* @return array
*/
public function getSurveyDetail($id, $type = 1)
{
$surveyModel = new SurveyModel();
$result = $surveyModel->getSurveyData($id, $type);
return $result;
}
/**
* 查档历史
*
* @param int $id 询价单详情表id
* @return array
*/
public function getCheckFileLog($id)
{
$result = [];
return $result;
}
/**
* 操作记录
*
* @param int $id 询价单id
* @param int $type 记录类型1、询价2、回价3、调价4、派单5、其它
* @return array
*/
public function getOrderLog($id, $type)
{
$result = Db::table('pg_operation_log')->field('uname,create_time,content')->where(['order_id' => $id, 'type' => $type])->select();
if (!empty($result)) {
foreach ($result as &$value) {
$value['create_time'] = !empty($value['create_time']) ? date('Y-m-d H:i', $value['create_time']) : '';
}
}
return $result;
}
/**
* 获取询价详情
*
*
* 回价日期: pg_return_price 的 creat_time 为回价
*
* @param int $id 询价单id
* @param int $type 记录类型1、询价2、回价3、调价4、派单5、其它
* @return array
*/
public function getDetatil($id, $property_cert_info_id)
{
$subsql = Db::table('pg_return_price')->group('property_cert_info_id')->order('property_cert_info_id', 'desc')->buildSql();
$res = Db::name('inquiry')->alias('x')
->join('property_cert_info y', 'x.id = y.quot_id')
->join([$subsql => 'z'], 'y.id = z.property_cert_info_id', 'left')
->field('y.city,y.building_name,y.building_unit_no,y.building_no,y.unit_no,y.property_cert,y.purchase_date,y.completion_time,y.land_location,y.obligee,y.is_tran_tax_free,
y.size,y.reg_price,y.usage,y.ownership_type,z.eva_unit_price,z.eva_total_value,
z.eva_net_value,z.eva_net_value2,z.added_tax,z.urban_construction_tax,z.edu_surcharge,
z.land_value_added_tax,z.stamp_duty,z.personal_income_tax,z.deed_tax,z.corporate_income_tax,
z.auction_fee,z.tran_service_fee,z.total_taxes1,z.total_taxes2,z.loan_ratio,z.gross_value,
z.eva_net_value,z.eva_net_value2')
->where(['x.id'=>$id,'y.id'=>$property_cert_info_id])
->find();
if($res){
$res['is_over2year_str'] = $res['is_tran_tax_free'] == 1 ? '已满两年' : ($res['is_tran_tax_free'] == 2 ? '未满两年' : '');
$res['usage_str'] = getDictionaryName('HOUSE_USAGE', $res['usage']);
$res['tenure_type_str'] = $res['ownership_type'] ? getDictionaryName('TENURE_TYPE', $res['ownership_type']) : '';
}
return $res;
}
//获取物业详情
public function getInquiryDetail($property_cert_info_id){
$res = Db::name('property_cert_info')
->field('city,building_name,building_unit_no,building_no,unit_no,property_cert,purchase_date,completion_time,land_location,obligee,is_tran_tax_free,
size,reg_price,usage,ownership_type,usage,evaluated_unit_price,adjust_reason')
->where(['id'=>$property_cert_info_id])
->find();
if($res){
// $res['is_over2year_str'] = $res['is_tran_tax_free'] == 1 ? '已满两年' : $res['is_tran_tax_free'] == 2 ? '未满两年' : '';
$res['is_over2year_str'] = $res['is_tran_tax_free'] == 1 ? '已满两年' : '未满两年';
$res['usage_str'] = $res['usage'] ? getDictionaryName('HOUSE_USAGE', $res['usage']) : '';
$res['tenure_type_str'] = ($res['ownership_type']==1) ? "个人" : "企业" ;
}
return $res;
}
//获取报告详情
public function getReport($property_cert_info_id){
$res = Db::name('report_detail')
->field('property_cert,cert_type,cert_no,obligee,client,parcel_no,parcel_area,parcel_usage,use_right_source,completion_date,
purchase_date,max_land_use_years,land_use_start_time,land_use_end_time,test_method,land_location')
->where(['property_cert_info_id'=>$property_cert_info_id])
->find();
if($res) $res['id_type_str'] = getDictionaryName('CERTTYPE', $res['cert_type']);
return $res ? $res : [];
}
//获取回价详情
public function getReturnPrice($property_cert_info_id){
$res = Db::name('return_price')
->where(['property_cert_info_id'=>$property_cert_info_id])
->field('eva_unit_price,eva_total_value,eva_net_value,eva_net_value2,total_taxes1,total_taxes2,loan_ratio,gross_value,eva_net_value,eva_net_value2')
->order('id', 'desc')
->find();
return $res ? $res : [];
}
//报告详情
public function getReportDetatil($reportid, $property_cert_info_id, $inquiry_type)
{
$res =Db::name('report_detail')->field('id,report_id,ownership_type,year,property_cert,cert_no,cert_type,obligee,obligee_percent,client,parcel_no,parcel_area,parcel_usage,use_right_source,completion_date,purchase_date,purchase_date,max_land_use_years,land_use_start_time,land_use_end_time,land_location,test_method,house_cert_img_ids,company_qualification_img_ids,report_summary_img_ids,report_remark,risk_remark,new_online_info,grand_district_id,grand_district_name,small_district_id,small_district_name,adjacent_property,bus_lines,boundaries,pub_serv,property_intro,is_vacant,vacant_months,is_connect_with_other,is_self_built,is_illegal_building,is_arbitration,is_consistent,is_double_unit,is_multi_unit,has_hidden_room,is_renovation,is_impl_subject,announce_link,is_residential,is_inconsit_cond,inconsistent_reason,is_court,deviation_desc,cert_remark,ref_unit_price_building,attachment_ids,house_condition,gen_saleablility_desc,indp_use_desc,seg_transfer_desc,dev_lv_desc,reg_date,summary_desc,otherrights_type')->where(['report_id' => $reportid, 'property_cert_info_id' => $property_cert_info_id])->find();
$info = $inquiry = [];
if ($res) {
$inquiry = Db::name('property_cert_info')->field('id as property_cert_info_id,city,city_id,property_full_name,building_unit_no,purchase_date,completion_time,land_location,obligee,ownership_type,is_tran_tax_free,usage,size,reg_price,property_complex,building_no,unit_no,building_name,year')->where('id', $property_cert_info_id)->find();
$inquiry['tenure_type_str'] = getDictionaryName('TENURE_TYPE', $inquiry['ownership_type']);
$inquiry['is_over2year_str'] = $inquiry['is_tran_tax_free'] == 1 ? '已满两年' : '未满两年';
$inquiry['usage_str'] = getDictionaryName('HOUSE_USAGE', $inquiry['usage']);
$inquiry['ownership_type'] = (string)$inquiry['ownership_type'];
$inquiry['usage'] = (string)$inquiry['usage'];
$res['id_type_str'] = '';
if (!empty($res['cert_type']) && !empty($res['ownership_type'])) {
if ($res['ownership_type'] == 1) {
$res['id_type_str'] = getDictionaryName('CERTTYPE', $res['cert_type']);
} else {
$res['id_type_str'] = getDictionaryName('COMPANY_CERTTYPE', $res['cert_type']);
}
}
$res_step1 = [];
// $inquiry['purchase_date'] = !empty($inquiry['purchase_date']) ? $inquiry['purchase_date'] : $res['purchase_date'];//登记时间
// if ($inquiry_type == 1) {
// $inquiry['purchase_date'] = $res['purchase_date'];
// } else {
// $inquiry['purchase_date'] = !empty($inquiry['purchase_date']) ? $inquiry['purchase_date'] : $res['purchase_date'];//登记时间
// }
$inquiry['purchase_date'] = $res['purchase_date'];
$inquiry['reg_date'] = $res['reg_date'];
$inquiry['year'] = $res['year'];
$res['house_cert_img_ids'] = !empty($res['house_cert_img_ids']) ? explode(',', $res['house_cert_img_ids']) : [];
$res['house_img_info'] = $this->getAttachments($res['house_cert_img_ids']);
$res['company_qualification_img_ids'] = !empty($res['company_qualification_img_ids']) ? explode(',', $res['company_qualification_img_ids']) : [];
$res['company_qualification_img_info'] = $this->getAttachments($res['company_qualification_img_ids']);
$res['report_summary_img_ids'] = !empty($res['report_summary_img_ids']) ? explode(',', $res['report_summary_img_ids']) : [];
$res['report_summary_img_info'] = $this->getAttachments($res['report_summary_img_ids']);
$res['test_method'] = !empty($res['test_method']) ? explode(',', $res['test_method']) : [];
$info = Db::name('return_price')->field('eva_unit_price,eva_total_value,eva_net_value,eva_net_value2,total_taxes1,total_taxes2,loan_ratio,gross_value,eva_net_value,eva_net_value2,guide_price')
->where('property_cert_info_id', $property_cert_info_id)->order('create_time', 'desc')->find();
$res['cert_type'] = (string)$res['cert_type'];
$res['ownership_type'] = !empty($res['ownership_type']) ? (string)$res['ownership_type'] : (string)$inquiry['ownership_type'];
$res['tenure_type_str'] = getDictionaryName('TENURE_TYPE', $inquiry['ownership_type']);
$res['is_vacant'] = empty($res['is_vacant']) ? 2 : $res['is_vacant'];
$res_step1 = $res;//test
//初始化区域情况分析
if (empty($res['adjacent_property']) && empty($res['bus_lines']) && empty($res['boundaries']) && empty($res['pub_serv']) && empty($res['property_intro']) && !empty($res['parcel_no'])) {
$areaInfo = Db::name('zongdi_info')->field('adjacent_property,bus_lines,boundaries,pub_serv,property_intro')->where('parcel_no', $res['parcel_no'])->order('id', 'asc')->find();
if(!empty($areaInfo)) {
$res['adjacent_property'] = $areaInfo['adjacent_property'];//毗邻物业
$res['bus_lines'] = $areaInfo['bus_lines'];//公交线路
$res['boundaries'] = $areaInfo['boundaries'];//四至
$res['pub_serv'] = $areaInfo['pub_serv'];//公共服务设施
$res['property_intro'] = $areaInfo['property_intro'];//楼盘介绍
}
}
$res['attachment_ids'] = !empty($res['attachment_ids']) ? explode(',', $res['attachment_ids']) : [];
$res['attachment_info'] = $this->getAttachments($res['attachment_ids']);
$res['house_condition'] = (string)$res['house_condition'];//房屋现状
$res['house_status_str'] = getDictionaryName('HOUSE_STATUS', $res['house_condition']);
}
return [
'inquiryinfo' => $inquiry ?: (Object)[],
'reportinfo' => $res ?: (Object)[],
'priceinfo' => $info ?: (Object)[],
'test_step1' => $res_step1 ?:(object)[],
'test_step2' => $res ?:(object)[]
];
}
/**
* 更新宗地信息
*
* @param mixed $parcel_no 宗地编号
* @param array[] $output_info 输出参数-注意:保证传入的结构,一定要一下五个字段,一般是 Db::name('report_detail') 一条记录
*
* adjacent_property 毗邻物业
* bus_lines 公交线路
* boundaries 四至
* pub_serv 公共服务设施
* property_intro 楼盘介绍
*
* @return 是否成功 boolean, 查到的宗地的数据 array[]
*/
//public static function UpdateZongDiInfo( $parcel_no, $output_info)
public static function UpdateZongDiInfo( $parcel_no)
{
$areaInfo = Db::name('zongdi_info')->field('adjacent_property,bus_lines,boundaries,pub_serv,property_intro')->where('parcel_no', $parcel_no )->order('id', 'asc')->find();
$output_info['adjacent_property'] = $areaInfo && $areaInfo['adjacent_property']?$areaInfo['adjacent_property']:'';//毗邻物业
$output_info['bus_lines'] = $areaInfo && $areaInfo['bus_lines']?$areaInfo['bus_lines']:'';//公交线路
$output_info['boundaries'] = $areaInfo && $areaInfo['boundaries']?$areaInfo['boundaries']:'';//四至
$output_info['pub_serv'] = $areaInfo && $areaInfo['pub_serv']?$areaInfo['pub_serv']:'';//公共服务设施
$output_info['property_intro'] = $areaInfo && $areaInfo['property_intro']?$areaInfo['property_intro']:'';//楼盘介绍
return $output_info;
}
//获取附件
public function getAttachments($ids) {
if (!is_array($ids)) {
$ids = explode(',', $ids);
}
$attachments = Db::name('attachment')
->field('id,url,name,ext,thum1')
->whereIn('id', $ids)
->select();
foreach ($attachments as &$value) {
// $value['url'] = config('uploadFile.url') . $value['url'];
if (strpos($value['url'], '/Content/') !== false || strpos($value['url'], '/HousingPhotos/') !== false) {
$value['url'] = config('uploadFile.old_cspg_url') . $value['url'];
$value['thum1'] = config('uploadFile.old_cspg_url') . $value['thum1'];
} else {
$value['url'] = config('uploadFile.url') . $value['url'];
$value['thum1'] = config('uploadFile.url') . DS . $value['thum1'];
}
}
return $attachments;
}
//获取权限
public function getStaffAuth($userInfo){
$result = [];
//部门经理能看自己及下属全部
if (in_array('Business_manager', $userInfo['roleCode'])){
$result = $userInfo['user_ids'];
}elseif(in_array('Evaluation_salesman', $userInfo['group']) || in_array('Inquirer_CSPG', $userInfo['group']) || in_array('Senior_Inquiry_CSPG', $userInfo['group']) || in_array('Surveyor', $userInfo['group'])){
//业务员、询价员、高级询价员、查勘专员只能看自己
$result = [$userInfo['user_id']];
}
return $result;
}
}

View File

@@ -0,0 +1,94 @@
<?php
namespace app\admin\service;
class Consultfiles {
/**
* 查档
*/
public function Consultfiles($data) {
$url = config('serviceConfig.API_CONSULT_PRO_URL');
$result = json_decode($this->post($url, json_encode($data), 60, ['Content-type: application/json']), true);
if (!isset($result['code']) || !in_array($result['code'], array(-1, 1, 2)))
return '查询结果返回有误';
$res = array();
if ($result['code'] == -1) {
$res = ['code' => -1, 'msg' => $result['msg'], 'estate_inquiry_text' => $result['msg'], 'result_code' => $result['code'], 'result' => $result];
} else if ($result['code'] == 1) {
$status_txt = array_column( $result['data'], 'status_txt');
$res = ['code' => $result['code'], 'estatestatus' => !empty($status_txt) ? $status_txt[0] : '', 'result_code' => $result['code'], 'result' => $result];
} else if ($result['code'] == 2) {
$printResult = array_column($result['data'], 'printResult');
$res = ['code' => -1, 'msg' => $printResult, 'estate_inquiry_text' => $printResult, 'result_code' => $result['code'], 'result' => $result];
}
return $res;
}
/**
* POST 请求(支持文件上传)
* @param string $url HTTP请求URL地址
* @param array|string $data POST提交的数据
* @param int $second 请求超时时间
* @param array $header 请求Header信息
* @return bool|string
*/
static public function post($url, $data = [], $second = 30, $header = []) {
$curl = curl_init();
self::applyData($data);
self::applyHttp($curl, $url);
curl_setopt($curl, CURLOPT_TIMEOUT, $second);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
if (!empty($header)) {
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
}
list($content, $status) = [curl_exec($curl), curl_getinfo($curl), curl_close($curl)];
return (intval($status["http_code"]) === 200) ? $content : false;
}
/**
* Post 数据过滤处理
* @param array $data
* @param bool $isBuild
* @return string
*/
private static function applyData(&$data, $isBuild = true) {
if (!is_array($data)) {
return null;
}
foreach ($data as &$value) {
is_array($value) && $isBuild = true;
if (!(is_string($value) && strlen($value) > 0 && $value[0] === '@')) {
continue;
}
if (!file_exists(($file = realpath(trim($value, '@'))))) {
continue;
}
list($isBuild, $mime) = [false, FileService::getFileMine(pathinfo($file, 4))];
if (class_exists('CURLFile', false)) {
$value = new CURLFile($file, $mime);
} else {
$value = "{$value};type={$mime}";
}
}
$isBuild && $data = http_build_query($data);
}
/**
* 设置SSL参数
* @param $curl
* @param string $url
*/
private static function applyHttp(&$curl, $url) {
if (stripos($url, "https") === 0) {
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSLVERSION, 1);
}
}
}

View File

@@ -0,0 +1,35 @@
<?php
namespace app\admin\service;
use app\model\Estate;
class EstateService extends CommonService
{
/**
* 归档一套房产的回价信息
*
* @param array $data
* @return bool
*/
public function archiveEstate(array $data)
{
$estate = new Estate();
$estate->building_name = $data['building_name'];
$estate->building_name = $data['building_name'];
$estate->floor_no = $data['floor_no'];
$estate->house_name = $data['house_name'];
$estate->property_full_name = $data['building_name'].$data['building_name'].$data['house_name'];
$estate->city = $data['city'];
$estate->area = $data['area'];
$estate->type = $data['type'];
$estate->size = $data['size'];
$estate->remark = $data['remark'];
$estate->per_price = $data['per_price'];
$estate->eva_total_value = $data['eva_total_value'];
$estate->clear_price = $data['clear_price'];
return $estate->save();
}
}

View File

@@ -0,0 +1,176 @@
<?php
namespace app\admin\service;
use app\model\Attachment;
use think\Exception;
use think\image\Image;
use think\File;
class FileService
{
protected $rootPath = './uploads/'; // 保存根路径
public function upload($file)
{
// $hasFile = $this->hasFile($file);
// if ($hasFile !== false) {
// return $hasFile;
// }
$info = $file->validate(['ext' => config('uploadFile.file_type')])->move($this->rootPath, true, false);
if ($info) {
$filePath = config('uploadFile.img_path') . DS . 'uploads' . DS . $info->getSaveName();
$data = [
'name' => $info->getInfo('name'), //图片原始名称
'savename' => $info->getFilename(), //新的图片名称
'filesize' => $info->getInfo('size'), //文件大小
'ext' => $info->getExtension(), //文件后缀
'md5' => $info->hash('md5'),
'sha1' => $info->hash('sha1'),
'mimetype' => $info->getMime(), //mime类型
'path' => config('uploadFile.img_path'), //路径
'url' => DS . 'uploads' . DS . $info->getSaveName(),
'create_time' => time(),
];
$isImg = in_array(strtolower($info->getExtension()), ['gif', 'jpg', 'jpeg', 'bmp', 'png', 'swf']); // 上传文件是否为图片
if ($isImg) {
// 生成 690 和1020尺寸的缩略图
$image = \think\Image::open($filePath);
$data['imagewidth'] = $image->width();
$data['imageheight'] = $image->height();
$data['imagetype'] = $info->getInFo('type');
$thumPath690 = 'uploads' . DS . 'thumb690' . DS . date('Ymd', time());
$thumPath1024 = 'uploads' . DS . 'thumb1024' . DS . date('Ymd', time());
$thumb1 = $this->saveThumbCOS($filePath, $thumPath690, $data['imagewidth'], $data['imageheight'], $data['savename'], 690);
$thumb2 = $this->saveThumbCOS($filePath, $thumPath1024, $data['imagewidth'], $data['imageheight'], $data['savename'], 1024);
$data['thum1'] = $thumb1 != false ? $thumb1 : 'uploads' . DS . $info->getSaveName();
$data['thum2'] = $thumb2 != false ? $thumb2 : 'uploads' . DS . $info->getSaveName();
}
//将图片转移到阿里云(原图)
$upload = ossUpload(trim(str_replace("\\", "/", $data['url']), '/'),$filePath);
unset($info); //释放变量才能删除图片
unlink($filePath); //把本地图片删除(原图)
if ($upload['code'] == -1){
throw new Exception($upload['msg']);
}
$result = Attachment::create($data);
if ($result) {
return [
'id' => $result->id,
'url' => str_replace('\\', '/', config('uploadFile.url') . $result['url']),
'name' => $result['name'],
'thumb_url' => $isImg ? str_replace('\\', '/', config('uploadFile.url') . '/' . $result['thum1']): '',
'thumb_url2' => $isImg ?str_replace('\\', '/', config('uploadFile.url') . '/' . $result['thum2']): '',
'ext' => $result['ext']
];
} else {
throw new Exception('文件保存失败');
}
} else {
throw new Exception($file->getError());
}
}
/**
* 检查上传文件是否存在,若存在则直接返回文件
* @param $file 上传文件内容
* @return array|bool
* @author: bordon
*/
public function hasFile($file)
{
if ($attach = Attachment::where(['md5' => $file->hash('md5'), 'sha1' => $file->hash('sha1')])->find()) {
return [
'id' => $attach->id,
'url' => config('uploadFile.url') . $attach['url'],
'name' => $attach['name'],
'thumb_url' => config('uploadFile.url') . DS . $attach['thum1'],
'thumb_url2' => config('uploadFile.url') . DS . $attach['thum2'],
'ext' => $attach['ext']
];
} else {
return false;
}
}
/**
* 生成固定尺寸缩略图
* @param $image 图片内容
* @param $path 存储路径
* @param $width 图片宽度
* @param $height 图片高度
* @param savename 保存文件名
* @param $saveWidth 保存文件最大宽度
* @author: bordon
*/
public function saveThumb($filePath, $path, $width, $height, $savename, $saveWidth)
{
if ($width < $saveWidth) {
return false;
}
if (!is_dir($path)) {
mkdir($path, 0755, true);
}
\think\Image::open($filePath)->thumb($saveWidth, $height * ($width / $saveWidth))->save($path . DS . $savename, null, 100);
return $path . DS . $savename;
}
/**
* 生成固定尺寸缩略图存到腾讯云
* @param $image 图片内容
* @param $path 存储路径
* @param $width 图片宽度
* @param $height 图片高度
* @param savename 保存文件名
* @param $saveWidth 保存文件最大宽度
* @param $isWorker 是否定时器使用这方法(定时器保存图片路径要加上public)
* @author: bordon
*/
public function saveThumbCOS($filePath, $path, $width, $height, $savename, $saveWidth, $isWorker = false){
if ($width < $saveWidth) {
return false;
}
if (!is_dir($path)) {
mkdir($path, 0755, true);
}
$pathName = $path . DS . $savename; //入库 url字段
$thumbPath = config('uploadFile.img_path') . $pathName; //图片全路径
try{
//裁剪图片
\think\Image::open($filePath)->thumb($saveWidth, $height * ($width / $saveWidth))->save($pathName, null, 100);
if ($isWorker){
$thumbPath = ROOT_PATH . $pathName; //图片全路径(多了一层public目录)
$pathName = str_replace('public', '', $pathName); //保存图片到腾讯云要过滤public,保存路径为/uploads/../..
}
//将图片转移到阿里云
$upload = ossUpload( trim(str_replace("\\", "/", $pathName), '/') , $thumbPath);
//$upload = ossUpload($pathName, $thumbPath);
unlink($thumbPath); //把本地图片删除(缩略图)
if ($upload['code'] == 1){
return $pathName;
}else{
trace($upload['msg'], 'error');
return false;
}
}catch (\Exception $e){
unlink($thumbPath); //把本地图片删除(原图)
trace($e->getMessage(), 'error');
return false;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,653 @@
<?php
namespace app\admin\service;
use think\Db;
class OcrService extends CommonService
{
public static function getPropertyCert($data)
{
// // 定义要排除的位置描述词列表
// $excludedWords = ['路', '交汇处', '大道', '交界处', '东北侧', '东南侧', '西北侧', '西南侧', '东侧', '西侧', '南侧', '北侧'];
//
//// 构建排除模式(使用单词边界确保完整匹配)
// $excludedPattern = '\b(?:' . implode('|', array_map('preg_quote', $excludedWords)) . ')\b';
//
//// 构建最终正则表达式
// $pattern = '/(?:(?!' . $excludedPattern . ')\S)+/u';
// dump($pattern);
// die;
// 提取房产证号所需信息
$str1 = $str2 = $str3 = $str4 = '';
$property_cert = '';
// dump(preg_match('/([\p{Han}]+市)房地产/u', '深圳市房地产权登记中心(印章)', $match));
// dump($match);
// die;
$property_situation = 1;
foreach ($data as $value) {
if (is_string($value)) {
if ($value == '权利人名称') {
$property_situation = 3;
break;
}
if (preg_match('/(\w+房地字第\d+号)/u', str_replace(' ', '', $value), $match)) {
$property_cert = $match[1];
$property_situation = 2;
break;
}
// 匹配str1: 省份简称及年份格式
if (empty($str1)) {
if (preg_match('/([京津冀晋蒙辽吉黑沪苏浙皖闽赣鲁豫澳台鄂湘粤桂琼渝川贵云藏陕甘青宁新港])([(]\d{4}[)])?/u', $value, $match)) {
$str1 = $match[0];
$property_cert .= $str1;
}
}
// 如果没有年份,查找单独的年份
if (mb_strpos($str1, '(') === false && mb_strpos($str1, '') === false) {
if (preg_match('/([(]\d{4}[)])/u', $value, $yearMatch)) {
$str1 .= $yearMatch[0];
} elseif (preg_match('/^\d{4}$/', $value, $yearMatch)) {
$str1 .= '' . $yearMatch[0] . '';
}
}
// 匹配str2: 城市名
if (empty($str2)) {
if (preg_match('/(?:.*省)?([\p{Han}]+市)/u', $value, $match)) {
$str2 = $match[1];
} elseif (preg_match('/([\p{Han}]+市)(房地产|国土)\.*$/u', $value, $match)) {
$str2 = $match[1];
}
}
// 匹配str3: 证书类型
if (empty($str3) && (mb_strpos($value, '不动产权') !== false || mb_strpos($value, '房权证') !== false)) {
$str3 = mb_strpos($value, '不动产权') !== false ? '不动产权' : '房权证';
}
// 匹配str4: 7位数字
if (empty($str4) && preg_match('/\d{7}/', $value, $match)) {
$str4 = '第' . $match[0] . '号';
}
}
}
foreach ($data as $value) {
if (is_string($value)) {
if (preg_match('/(?:.*省)?([\p{Han}]+市)$/u', $value, $match)) {
$str2 = $match[1];
} elseif (preg_match('/([\p{Han}]+市)(房地产|国土)\.*$/u', $value, $match)) {
$str2 = $match[1];
}
}
}
$city_id = null;
if (!empty($str2)) {
$city_id = Db::name('region')->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,
];
}
}

View File

@@ -0,0 +1,158 @@
<?php
namespace app\admin\service;
use app\admin\exception\LogicException;
use think\facade\Config;
use Qcloud\Cos\Client;
use think\facade\Log;
/**
* 阿里云OSS服务
*
* Class OssService
* @package app\admin\service
*/
class OssService
{
private $client;
/**
* 不可与oss已有的bucket重名这个不区分账号
*
* @var mixed
*/
private $bucket;
public function __construct()
{
$accessKeyId = Config::get('uploadFile.access_key_id');
$accessKeySecret = Config::get('uploadFile.access_key_secret');
$endpoint = Config::get('uploadFile.endpoint');
$bucket = Config::get('uploadFile.bucket');
try {
$cos_client = new Client([
'region' => $endpoint,
'credentials' => [
'secretId' => $accessKeyId,
'secretKey' => $accessKeySecret
]
]);
if (!$cos_client->doesBucketExist($bucket)) {
$cos_client->createBucket($bucket);
}
} catch (\Exception $e) {
throw new LogicException($e->getMessage());
}
$this->bucket = $bucket;
$this->client = $cos_client;
return $this;
}
/**
* 上传单个文件eg$_FILES['img']
*
* @param string $path
* @param string $tmpFilePath
* @param string $mimeType
* @return string
* @throws LogicException
*/
public function uploadSingleFile($path, $tmpFilePath, $mimeType = 'application/octet-stream')
{
try {
$this->client->putObject([
'Bucket' => $this->bucket,
'Key' => $path,
'Body' => fopen($tmpFilePath, 'rb'),
'ContentType' => $mimeType
]);
} catch (\Exception $e) {
throw new LogicException($e->getMessage());
}
return env('uploadFile.url') . $path;
}
/**
* 上传多文件eg$_FILES['imgs']
*
* @param array $paths
* @param array $tmpPaths
* @return array
* @throws LogicException
*/
public function uploadMultiFiles(array $paths, array $tmpPaths)
{
$signedUrls = [];
foreach ($paths as $index => $path) {
$signedUrls[$index] = $this->uploadSingleFile($path, $tmpPaths[$index]);
}
return $signedUrls;
}
/**
* 获取加密的url
*
* @param $path
* @param int $timeout
* @return string
*/
public function getSignedUrl($path, $timeout = 3600)
{
try {
$url = $this->client->signUrl($this->bucket, $path, $timeout);
} catch (\Exception $e) {
return '';
}
return $url;
}
/**
*获取OSS文件
*/
public function getOSSFile($fileUrl, $localPath = '')
{
$fileUrl = str_replace("\\", "/", $fileUrl);
$path = parse_url($fileUrl, PHP_URL_PATH);
$objectKey = substr($path, 1);
try {
$config = ['Bucket' => $this->bucket, 'Key' => $objectKey];
if (!empty($localPath)) {
$config['SaveAs'] = $localPath;
}
$content = $this->client->getObject($config);
} catch (\Exception $e) {
printf(__FUNCTION__ . ": FAILED\n");
printf($e->getMessage() . "\n");
return "";
}
$content = base64_encode($content);
return $content;
}
/**
*删除文件
*
*/
public function deleteOSSFile($fileUrl)
{
$url = substr($fileUrl, strlen("https://pgevasys.oss-cn-shenzhen.aliyuncs.com"));
$url = str_replace("\\", "/", $url);
$objectKey = substr($url, 1);
try {
$this->client->deleteObject($this->bucket, $objectKey);
} catch (\Exception $e) {
printf(__FUNCTION__ . ": FAILED\n");
printf($e->getMessage() . "\n");
return false;
}
return true;
}
}

View File

@@ -0,0 +1,486 @@
<?php
namespace app\admin\service;
use app\admin\exception\LogicException;
use app\model\Inquiry;
use app\model\Property_cert_info;
use app\model\Survey;
use app\model\SurveyDetail;
use think\Db;
class SurveyService extends CommonService
{
/**
* 发起查勘
*
* @param $userId
* @param array $data
* @return mixed
* @throws LogicException
*/
public function askSurvey(array $data)
{
Db::startTrans();
$inquiry = Db::name('inquiry')->field('id,status')->where(['order_no' => $data['order_no']])->find();
if(!($inquiry['status'] >= 2))
return ['code'=>-1, 'msg'=>'订单状态有误,无法发起查勘'];
$start_time = date('Y-m-d H:i:s', strtotime('-6 months'));
$end_time = date('Y-m-d H:i:s');
//生成查勘数据
foreach ($data['detail'] as $res){
$adddata['order_no'] = $data['order_no'];
$adddata['property_cert_info_id'] = $res['property_cert_info_id'];
$adddata['contact_name'] = $res['contact_name'];
$adddata['contact_phone'] = $res['contact_phone'];
$adddata['area'] = $res['area'];
$adddata['area_id'] = $res['area_id'];
$adddata['remark'] = $res['remark'];
// $adddata['user_id'] = $data['user_id'];
// $adddata['user_name'] = $data['user_name'];
$adddata['user_id'] = $res['survey_user_id'];
$adddata['user_name'] = $res['survey_user_name'];
$adddata['assignee_id']= $data['user_id'];
$adddata['assign_time']=date('Y-m-d H:i:s',time());
$adddata['status'] = 2;
$adddata['create_time'] = date("Y-m-d H:i:s" ,time());
$adddata['update_time'] = date("Y-m-d H:i:s" ,time());
// 检查该物业是否在6个月之内出过报告
$property_full_name = Db::name('property_cert_info')
->where('id='.$res['property_cert_info_id'])
->value('property_full_name');
$ck_where = [];
$ck_where[] = ['property_full_name', '=', $property_full_name];
$ck_where[] = ['id', '<>', $res['property_cert_info_id']];
$ck_where[] = ['create_time', 'between time', [$start_time, $end_time]];
$inquiry_ids = Db::name('property_cert_info')
->where($ck_where)
->field('quot_id')
->select();
// foreach ($inquiry_ids as $quot_id) {
// $status = Db::name('inquiry')
// ->where('id='.$quot_id['quot_id'])
// ->value('status');
// if ($status==8) {
// Db::rollback();
// return ['code'=>-1, 'msg'=>'发起查勘失败存在6个月内出过报告的物业需要申请'];
// }
// }
//添加查勘信息
$survey_id = Db::name('survey')->insertGetId($adddata);
if(!$survey_id){
Db::rollback();
return ['code'=>-1, 'msg'=>'查勘单生成失败'];
}
//添加查勘详情
if(!Db::name('survey_detail')->insert(['survey_id'=>$survey_id])){
Db::rollback();
return ['code'=>-1, 'msg'=>'查勘详情初始化失败'];
}
//写入消息
PublicMessage($inquiry['id'],5,6,$res['property_cert_info_id']); // 消息推送
}
//更新订单状态:查勘待派单
if (!Db::name('inquiry')->where(['order_no' => $data['order_no']])->update(['status'=>4, 'update_time' => new \DateTime])) {
Db::rollback();
return ['code'=>-1, 'msg'=>'更新订单状态失败'];
}
Db::commit();
return ['code'=>1, 'msg'=>'操作成功'];
}
//
public function askSurveyUnck(array $data)
{
Db::startTrans();
$inquiry = Db::name('inquiry')->field('id,status')->where(['order_no' => $data['order_no']])->find();
if(!($inquiry['status'] >= 2))
return ['code'=>-1, 'msg'=>'订单状态有误,无法发起查勘'];
//生成查勘数据
foreach ($data['detail'] as $res){
$adddata['order_no'] = $data['order_no'];
$adddata['property_cert_info_id'] = $res['property_cert_info_id'];
$adddata['contact_name'] = $res['contact_name'];
$adddata['contact_phone'] = $res['contact_phone'];
$adddata['area'] = $res['area'];
$adddata['area_id'] = $res['area_id'];
$adddata['remark'] = $res['remark'];
$adddata['user_id'] = $res['survey_user_id'];
$adddata['user_name'] = $res['survey_user_name'];
$adddata['assignee_id']= $data['user_id'];
$adddata['assign_time']=date('Y-m-d H:i:s',time());
$adddata['status'] = 2;
$adddata['create_time'] = date("Y-m-d H:i:s" ,time());
$adddata['update_time'] = date("Y-m-d H:i:s" ,time());
//添加查勘信息
$survey_id = Db::name('survey')->insertGetId($adddata);
if(!$survey_id){
Db::rollback();
return ['code'=>-1, 'msg'=>'查勘单生成失败'];
}
//添加查勘详情
if(!Db::name('survey_detail')->insert(['survey_id'=>$survey_id])){
Db::rollback();
return ['code'=>-1, 'msg'=>'查勘详情初始化失败'];
}
//写入消息
PublicMessage($inquiry['id'],5,6,$res['property_cert_info_id']); // 消息推送
}
//更新订单状态:查勘待派单
if (!Db::name('inquiry')->where(['order_no' => $data['order_no']])->update(['status'=>4, 'update_time' => new \DateTime])) {
Db::rollback();
return ['code'=>-1, 'msg'=>'更新订单状态失败'];
}
Db::commit();
return ['code'=>1, 'msg'=>'操作成功'];
}
/**
* 检查查勘信息
*/
public function checkSurvey(array $details){
$isSuccess = true;
$errors = [];
foreach ($details as $index => $detail){
//todo 城区检查
if(!isset($detail['property_cert_info_id']) || !$detail['property_cert_info_id']){
$isSuccess = false;
$errors[$index]['property_cert_info_id'] = '询价单详情id必填';
}
if(!isset($detail['contact_name']) || !$detail['contact_name']){
$isSuccess = false;
$errors[$index]['contact_name'] = '联系人必填';
}
if(!isset($detail['contact_phone']) || !$detail['contact_phone']){
$isSuccess = false;
$errors[$index]['contact_phone'] = '联系人电话必填';
}
if(!isset($detail['area']) || !$detail['area']){
$isSuccess = false;
$errors[$index]['area'] = '小片区必填';
}
}
return $this->verifyResult($isSuccess,$errors);
}
/**
* 指派
*
* @param $assignerId
* @param array $data
* @return mixed
* @throws LogicException
*/
public function assign($assignerId,array $data)
{
//todo 检查assignerId权限
$verifyResult = $this->checkSurveyIds($data['survey_ids']);
if ($verifyResult['is_success'] !== true)
throw new LogicException('参数验证失败',500,$verifyResult['errors']);
return DB::transaction(function ()use ($assignerId,$data){
//todo 检查查勘员信息
$user = $data['user_id'];
//survey
if (!Survey::where([['id','in',$data['survey_ids']]])->update([
'user_id' => $data['user_id'],
'user_name' => '',
'assignee_id' => $assignerId,
'assign_time' => date('Y-m-d H:i:s'),
'status' => Survey::STATUS_ASSIGNED,
]))
throw new \Exception('指派失败');
//survey_detail todo 这里user_id是否有利用价值待观察
if (!SurveyDetail::where([['survey_id','in',$data['survey_ids']]])->update([
'user_id' => $data['user_id']
]))
throw new \Exception('指派失败.');
return true;
});
}
/**
* 检查所有物业是否都可以指派
*
* @param array $surveyIds
* @return array
*/
public function checkSurveyIds(array $surveyIds)
{
$allExists = true;
$errors = [];
foreach ($surveyIds as $surveyId) {
$survey = new Survey();
$survey = $survey->find($surveyId);
if (!$survey){
$allExists = false;
$errors[$surveyId] = '查勘id:'.$surveyId.'不存在';
}elseif (!in_array($survey->status,[Survey::STATUS_ASKED,Survey::STATUS_RETURNED])){
$allExists = false;
$errors[$surveyId] = '物业:'.$survey->property_cert_info->property_full_name.'的查勘状态为:'.
Survey::STATUS_MAP[$survey->status].',暂无法指派';
}
}
return $this->verifyResult($allExists,$errors);
}
/**
* 退回到待派单状态
*
* @param $userId
* @param array $data
* @return mixed
* @throws LogicException
*/
public function return_survey_to_asked($userId,array $data)
{
//todo 检查userId权限
$survey = new Survey();
$inquiryModel = new Inquiry();
$survey = $survey->find($data['survey_id']);
if (!$survey)
return ['code' => -1 , 'message' => '该查勘信息不存在'];
if ($survey->status != Survey::STATUS_ASSIGNED)
return ['code' => -1 , 'message' => '该查勘目前状态为:'.Survey::STATUS_MAP[$survey->status].',暂无法退回'];
if($userId != $survey['user_id'])
return ['code' => -1 , 'message' => '当前物业已转派查勘员,无法操作'];
$survey->user_id = null;
$survey->user_name = "";
$survey->last_return_user_id = $userId;
$survey->last_return_username = '';
$survey->status = Survey::STATUS_ASKED;
$inquiryModel->where('order_no' , $survey['order_no'])->update(['status' => 3]);
PublicMessage($inquiryModel->where('order_no' , $survey['order_no'])->value('id'),4,8,$survey['property_cert_info_id']); // 消息推送
$survey->save();
return ['code' => 1];
}
/**
* 退回查勘
*
* @param $userId
* @param array $data
* @return mixed
* @throws LogicException
*/
public function return_survey($userId,array $data)
{
//todo 检查userId权限
$survey = new Survey();
$inquiryModel = new Inquiry();
$survey = $survey->find($data['survey_id']);
if (!$survey)
return ['code' => -1 , 'message' => '该查勘信息不存在'];
if ($survey->status != Survey::STATUS_ASSIGNED)
return ['code' => -1 , 'message' => '该查勘目前状态为:'.Survey::STATUS_MAP[$survey->status].',暂无法退回'];
if($userId != $survey['user_id'])
return ['code' => -1 , 'message' => '当前物业已转派查勘员,无法操作'];
$survey->user_id = null;
$survey->user_name = "";
$survey->last_return_user_id = $userId;
$survey->last_return_username = '';
$survey->return_reason = $data['return_reason'];
$survey->status = Survey::STATUS_RETURNED;
$inquiryModel->where('order_no' , $survey['order_no'])->update(['status' => Inquiry::STATUS_CANCELED]);
//PublicMessage($inquiryModel->where('order_no' , $survey['order_no'])->value('id'),4,8,$survey['property_cert_info_id']); // 消息推送
$survey->save();
return ['code' => 1];
}
/**
* 保存查勘内容
*
* @param $userId
* @param array $data
* @param int $type 1查勘时新增 2报告时编辑 3.查勘完成时编辑
* @param string $user_name 查勘员名称(报告时编辑需传参)
* @param date $complete_time 查勘完成时间(报告时编辑需传参)
* @return bool
*/
public function survey_detail($userId,$data, $type = 1, $user_name = '', $complete_time = ''){
$surveyModel = new Survey();
$inquiryModel = new Inquiry();
$detail=new SurveyDetail();
$survey = $surveyModel->where('id',$data['survey_id'])->find();
// $detail = $detail->where('survey_id',$data['survey_id'])->find();
if (!$survey)
return ['code' => -1, 'message' => '该查勘信息不存在'];
if ($survey->status != Survey::STATUS_ASSIGNED && $type == 1)
return ['code' => -1, 'message' => '该查勘目前状态为:'.Survey::STATUS_MAP[$survey->status].',暂无法提交'];
if($userId != $survey['user_id'])
return ['code' => -1 , 'message' => '当前物业已转派查勘员,无法操作'];
$inquiry_status = $inquiryModel->where('order_no',$survey->order_no)->value('status');
if($inquiry_status > 5 && $type == 3)
return ['code' => -1, 'message' => '该订单已申请报告,暂无法编辑'];
$arr = [];
$arr['survey_id']=$data['survey_id'];
$arr['user_id']=$userId;
if ($type == 2) {
$surveyArray['user_id'] = $userId;
$surveyArray['user_name'] = $user_name;
$surveyArray['complete_time']=$complete_time;
$inquiryArray['survey_time']=$complete_time;
}
isset($data['adjacent_property']) && $arr['adjacent_property'] =$data['adjacent_property'];
isset($data['bus_lines']) && $arr['bus_lines'] =$data['bus_lines'];
isset($data['boundaries']) && $arr['boundaries'] =$data['boundaries'];
isset($data['pub_serv']) && $arr['pub_serv'] =$data['pub_serv'];
isset($data['scenery']) && $arr['scenery'] =$data['scenery'];
isset($data['property_intro']) && $arr['property_intro'] =$data['property_intro'];
isset($data['address']) && $arr['address'] =$data['address'];
isset($data['unit_type']) && $arr['unit_type'] =$data['unit_type'];
isset($data['towards']) && $arr['towards'] =$data['towards'];
isset($data['floor_no']) && $arr['floor_no'] =$data['floor_no'];
isset($data['total_floors']) && $arr['total_floors'] =$data['total_floors'];
isset($data['floor_height']) && $arr['floor_height'] =$data['floor_height'];
isset($data['elevator']) && $arr['elevator'] =$data['elevator'];
isset($data['parking_lot']) && $arr['parking_lot'] =$data['parking_lot'];
isset($data['parking_lot_usage']) && $arr['parking_lot_usage'] =$data['parking_lot_usage'];
isset($data['decoration']) && $arr['decoration'] =$data['decoration'];
isset($data['usage']) && $arr['usage'] =$data['usage'];
isset($data['property_mgm']) && $arr['property_mgm'] =$data['property_mgm'];
isset($data['newness_rate']) && $arr['newness_rate'] =$data['newness_rate'];
isset($data['structure']) && $arr['structure'] =$data['structure'];
// !empty($data['layout']) && $arrlayout =$data['layout'];
// !empty($data['greening']) && $arrgreen_environment =$data['greening'];
isset($data['exterior_view']) && $arr['exterior_view'] =$data['exterior_view'];
isset($data['exterior_view_img_ids']) && $arr['exterior_view_img_ids'] =$data['exterior_view_img_ids'];
isset($data['doorplate']) && $arr['doorplate'] =$data['doorplate'];
isset($data['doorplate_img_ids']) && $arr['doorplate_img_ids'] =$data['doorplate_img_ids'];
isset($data['living_room']) && $arr['living_room'] =$data['living_room'];
isset($data['living_room_img_ids']) && $arr['living_room_img_ids'] =$data['living_room_img_ids'];
isset($data['balcony']) && $arr['balcony'] =$data['balcony'];
isset($data['balcony_img_ids']) && $arr['balcony_img_ids'] =$data['balcony_img_ids'];
isset($data['kitchen']) && $arr['kitchen'] =$this->checkData($data['kitchen'],'kitchen');
isset($data['kitchen_img_ids']) && $arr['kitchen_img_ids'] =$data['kitchen_img_ids'];
isset($data['bedroom']) && $arr['bedroom'] =$data['bedroom'];
isset($data['bedroom_img_ids']) && $arr['bedroom_img_ids'] =$data['bedroom_img_ids'];
isset($data['bathroom']) && $arr['bathroom'] =$data['bathroom'];
isset($data['bathroom_img_ids']) && $arr['bathroom_img_ids'] =$data['bathroom_img_ids'];
isset($data['facility']) && $arr['facility'] =$data['facility'];
isset($data['facility_img_ids']) && $arr['facility_img_ids'] =$data['facility_img_ids'];
isset($data['other']) && $arr['other'] =$data['other'];
// !empty($data['others_img_ids']) && $arrother_imgs =$data['others_img_ids'];
isset($data['auto_loc_img_ids']) && $arr['auto_loc_img_ids'] =$data['auto_loc_img_ids'];
isset($data['loc_img_ids']) && $arr['loc_img_ids'] =$data['loc_img_ids'];
isset($data['prosperity_lv']) && $arr['prosperity_lv'] =$data['prosperity_lv'];
isset($data['business_district_lv']) && $arr['business_district_lv'] =$data['business_district_lv'];
isset($data['pub_fac']) && $arr['pub_fac'] =$data['pub_fac'];
isset($data['traffic']) && $arr['traffic'] =$data['traffic'];
isset($data['size']) && $arr['size'] =$data['size'];
isset($data['building_completion_time']) && $arr['building_completion_time'] =$data['building_completion_time'];
isset($data['podium_floor']) && $arr['podium_floor'] =$data['podium_floor'];
isset($data['business_content']) && $arr['business_content'] =$data['business_content'];
isset($data['property_form']) && $arr['property_form'] =$data['property_form'];
isset($data['commercial_positioning']) && $arr['commercial_positioning'] =$data['commercial_positioning'];
isset($data['shop_condition']) && $arr['shop_condition'] =$data['shop_condition'];
isset($data['parking_condition']) && $arr['parking_condition'] =$data['parking_condition'];
isset($data['usage_condition']) && $arr['usage_condition'] =$data['usage_condition'];
isset($data['exterior_wall']) && $arr['exterior_wall'] =$data['exterior_wall'];
isset($data['exterior_wall_img_ids']) && $arr['exterior_wall_img_ids'] =$data['exterior_wall_img_ids'];
isset($data['interior_wall']) && $arr['interior_wall'] =$data['interior_wall'];
isset($data['interior_wall_img_ids']) && $arr['interior_wall_img_ids'] =$data['interior_wall_img_ids'];
isset($data['door_window']) && $arr['door_window'] =$data['door_window'];
isset($data['door_window_img_ids']) && $arr['door_window_img_ids'] =$data['door_window_img_ids'];
isset($data['ground']) && $arr['ground'] =$data['ground'];
isset($data['ground_img_ids']) && $arr['ground_img_ids'] =$data['ground_img_ids'];
isset($data['ceiling']) && $arr['ceiling'] =$data['ceiling'];
isset($data['ceiling_img_ids']) && $arr['ceiling_img_ids'] =$data['ceiling_img_ids'];
isset($data['supplement_img_ids']) && $arr['supplement_img_ids'] =$data['supplement_img_ids'];
isset($data['elevator_apartment_count']) && $arr['elevator_apartment_count'] =$data['elevator_apartment_count'];
isset($data['loc_img_ids']) && $arr['loc_img_ids'] =$data['loc_img_ids'];
isset($data['house_type_img_ids']) && $arr['house_type_img_ids'] =$data['house_type_img_ids'];
isset($data['orientation_img_ids']) && $arr['orientation_img_ids'] =$data['orientation_img_ids'];
// !empty($data['survey_gallery']) && $arrsurvey_gallery =$data['survey_gallery'];
isset($data['street_view_img_ids']) && $arr['street_view_img_ids'] =$data['street_view_img_ids'];
isset($data['appraisal_img_ids']) && $arr['appraisal_img_ids'] =$data['appraisal_img_ids'];
// isset($data['special_remarks']) && $arr['special_remarks'] =$data['special_remarks'];
if (isset($data['special_remarks']) && !empty($data['special_remarks'])) {
$arr['special_remarks'] = $data['special_remarks'];
} else {
$arr['special_remarks'] = '';
}
isset($data['remarks']) && $arr['remarks'] =$data['remarks']; //备注//2020年5月24日14:54:42 cavan
if ($type == 1) {
$arr['submit_time']=date('Y-m-d H:i:s');//查勘完成时间
}
$arr['update_time']=date('Y-m-d H:i:s');
isset($arr['building_completion_time']) && $arr['building_completion_time'] == '' && $arr['building_completion_time'] = NULL;
empty($arr['exterior_view']) && $arr['exterior_view'] = null ;
empty($arr['doorplate']) && $arr['doorplate'] = null ;
$res= $detail->where('survey_id' , $data['survey_id']) ->update($arr);
if($res){
$surveyArray['id'] = $data['survey_id'];
$surveyArray['area'] = $data['area'];
$surveyArray['area_id'] = $data['area_id'];
$surveyArray['status'] = Survey::STATUS_COMPLETED;
if ($type == 1) {
$surveyArray['complete_time']=date('Y-m-d H:i:s');
}
$survey->update($surveyArray);
if(!empty($data['survey_type'])){
$surveyModel->where('id' , $data['survey_id'])->update(['survey_type' => $data['survey_type']]);
}
$inquiryArray['survey_user_id'] = $survey->user_id;
$inquiryArray['survey_user_name'] = $survey->user_name;
if ($type == 1) {
$inquiryArray['survey_time']=date('Y-m-d H:i:s');
}
Db::name('property_cert_info')->where('id',$survey->property_cert_info_id)->update($inquiryArray);
$survey_all = $survey->where('order_no' ,$survey->order_no)->where('status' , 'neq' , Survey::STATUS_COMPLETED)->find();
if(!$survey_all && $type == 1){
$res = $inquiryModel->where('order_no',$survey->order_no)->update(['status' => 5]);
}
if($type ==1){
PublicMessage($inquiryModel->where('order_no' , $survey->order_no)->value('id'),2,7,$survey->property_cert_info_id); // 消息推送
}
if($res!==false){
return ['code' =>1];
}else{
return ['code' =>1, 'message'=> '保存失败'];
}
}else{
return ['code' =>1, 'message'=> '保存失败'];
}
}
public function checkData($data,$key){
foreach ($data as $k => $v) {
if(!strstr($k,$key)){
unset($data[$k]);
}
}
// $data=json_encode($temp);
return $data;
}
}

View File

@@ -0,0 +1,52 @@
<?php
namespace app\admin\service;
use think\facade\Log;
class SyncHttpService {
public static function post($url = "", $params = [], $header = []) {
empty($url) && apiErrMsg('地址不能为空');
$goUrl = strpos($url, 'http') !== false ? $url : config('domain') . "/index.php/" . $url;
Log::debug('SyncHttpService post url:'. $goUrl);
$info = parse_url($goUrl);
$host = $info['host'];
$port = $info['port'] ?? (strpos($goUrl, 'https') !== false ? 443 : 80);
$path = $info['path'];
$query = empty($params) ? '' : http_build_query($params);
$errno = 0;
$errstr = '';
$timeout = 300;
try {
$fp = fsockopen($host, $port, $errno, $errstr, $timeout);
$head = "POST $path HTTP/1.0\r\n";
$head .= "Host: $host\r\n";
$head .= "Content-type: application/x-www-form-urlencoded\r\n";
$head .= "Content-Length: " . strlen($query) . "\r\n";
$head .= "Connection:close\r\n";
if($header) {
foreach($header as $k => $v) {
$head .= "{$k}: {$v}\r\n";
}
}
$head .= "\r\n";
$head .= trim($query);
fwrite($fp, $head);
usleep(20000);
fclose($fp);
} catch (\Exception $exc) {
Log::debug('SyncHttpService error===');
Log::debug(compact('host', 'port', 'errno', 'errstr'));
Log::debug(compact('params', 'query'));
Log::debug('SyncHttpService error===');
writeLog($goUrl, 'SyncHttpServiceError');
writeLog(compact('host', 'port', 'errno', 'errstr'), 'SyncHttpServiceError');
writeLog(compact('params', 'query'), 'SyncHttpServiceError');
writeLog($exc, 'SyncHttpServiceError');
}
}
}