674 lines
35 KiB
PHP
674 lines
35 KiB
PHP
<?php
|
||
|
||
namespace app\api\controller;
|
||
|
||
use app\api\validate\EvaluateInquiryValidate;
|
||
use app\model\Inquiry as InquiryModel;
|
||
use app\model\Taxation;
|
||
use think\Db;
|
||
use think\facade\Env;
|
||
|
||
class EvaluateInquiry extends Base
|
||
{
|
||
const CHECK_LOUPAN_URL = 'api/EvaluateInquiry/checkEstate';
|
||
protected $data;
|
||
|
||
/**
|
||
* @return mixed
|
||
*/
|
||
public function getData()
|
||
{
|
||
return $this->data;
|
||
}
|
||
|
||
/**
|
||
* 获取银行
|
||
*/
|
||
public function reqBankList()
|
||
{
|
||
$bank_data = Db::name('bank')
|
||
->where(['type' => 1, 'status' => 1])
|
||
->field('id,name,bank_code')
|
||
->select();
|
||
if ($bank_data) {
|
||
return $this->buildSuccess($bank_data);
|
||
} else {
|
||
return $this->buildFailed('暂无银行数据!');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取分行
|
||
*/
|
||
public function getSubBank()
|
||
{
|
||
$bank_id = request()->param('bank_id');
|
||
if (empty($bank_id)) {
|
||
return $this->buildFailed('银行id不能为空');
|
||
}
|
||
$sub_bank_data = Db::name('bank')
|
||
->where(['pid' => $bank_id, 'type' => 2, 'status' => 1])
|
||
->field('id,name')
|
||
->select();
|
||
if ($sub_bank_data) {
|
||
return $this->buildSuccess($sub_bank_data);
|
||
} else {
|
||
return $this->buildFailed('暂无分行数据!');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取支行
|
||
*/
|
||
public function getBranchBank()
|
||
{
|
||
$bank_branch_id = request()->param('bank_branch_id');
|
||
if (empty($bank_branch_id)) {
|
||
return $this->buildFailed('分行id不能为空');
|
||
}
|
||
$branch_bank_data = Db::name('bank')
|
||
->where(['pid' => $bank_branch_id, 'type' => 3, 'status' => 1])
|
||
->field('id,name')
|
||
->select();
|
||
if ($branch_bank_data) {
|
||
return $this->buildSuccess($branch_bank_data);
|
||
} else {
|
||
return $this->buildFailed('暂无支行数据!');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取银行贷款类型(评估目的)
|
||
*/
|
||
public function getEvaluatePurpose()
|
||
{
|
||
$bank_id = request()->param('bank_id');
|
||
if (empty($bank_id)) {
|
||
return $this->buildFailed('银行id不能为空');
|
||
}
|
||
$purpose_data = Db::name('product')
|
||
->where(['bank_id' => $bank_id, 'type' => 1, 'state' => 1])
|
||
->field('id,product_name')
|
||
->select();
|
||
if ($purpose_data) {
|
||
return $this->buildSuccess($purpose_data);
|
||
} else {
|
||
return $this->buildFailed('暂无该银行的贷款类型!');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 报告防伪查询
|
||
*/
|
||
public function reportCheck()
|
||
{
|
||
$report_no = request()->param('report_no', '', 'trim'); // 报告编号
|
||
if (empty($report_no)) {
|
||
return $this->buildFailed('报告编号不能为空');
|
||
}
|
||
$report_data = Db::name('report')
|
||
->where(['report_no' => $report_no])
|
||
->where(['status' => 3])
|
||
->field('id,quot_id,appraisal_time')
|
||
->find();
|
||
if ($report_data) {
|
||
// 询价详情数据
|
||
$inq_detail_data = Db::name('property_cert_info')
|
||
->where(['quot_id' => $report_data['quot_id']])
|
||
->field('id,property_full_name')
|
||
->select();
|
||
$result_data = [];
|
||
foreach ($inq_detail_data as $key => $value) {
|
||
// 获取回价信息
|
||
$return_data = Db::name('return_price')
|
||
->where(['property_cert_info_id' => $value['id']])
|
||
->field('property_name,area,eva_unit_price,eva_total_value,eva_net_value,eva_net_value2,total_taxes1,total_taxes2')
|
||
->order('id', 'desc')
|
||
->find();
|
||
$result_data[] = $return_data;
|
||
}
|
||
$resultData['property_full_name'] = implode(',', array_column($result_data, 'property_name'));
|
||
$resultData['size'] = implode('/', array_column($result_data, 'area'));
|
||
$resultData['eva_unit_price'] = implode('/', array_column($result_data, 'eva_unit_price'));
|
||
$resultData['eva_total_value'] = array_sum(array_column($result_data, 'eva_total_value'));
|
||
$resultData['eva_net_value'] = array_sum(array_column($result_data, 'eva_net_value'));
|
||
$resultData['eva_net_value2'] = array_sum(array_column($result_data, 'eva_net_value2'));
|
||
$resultData['total_taxes1'] = array_sum(array_column($result_data, 'total_taxes1'));
|
||
$resultData['total_taxes2'] = array_sum(array_column($result_data, 'total_taxes2'));
|
||
$resultData['appraisal_time'] = $report_data['appraisal_time'];
|
||
return $this->buildSuccess($resultData);
|
||
} else {
|
||
return $this->buildFailed('抱歉,您查询的报告不存在!');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 询价匹配查询
|
||
*/
|
||
public function inquiryMatch()
|
||
{
|
||
$request_data = $this->request->post();
|
||
|
||
$loupan_name = $request_data['loupan_name']; // 楼盘名称
|
||
$building_name = $request_data['building_name']; // 栋号
|
||
$unit_no = $request_data['unit_no']; // 房号
|
||
$province_id = $request_data['province_id']; // 省份ID
|
||
$city_id = $request_data['city_id']; // 城市ID
|
||
$size = $request_data['size']; // 建筑面积
|
||
|
||
/**
|
||
* 1.先去OA匹配
|
||
*/
|
||
|
||
|
||
$oa_res = $this->checkFromOa($loupan_name, $building_name, $unit_no);
|
||
|
||
if ($oa_res === true) { //OA匹配上了
|
||
|
||
if ($request_data['customer_type'] == 1) { //游客,直接返回评估单价、评估总值、二手房参考价
|
||
$return = [
|
||
'redirect' => 1, //1.跳转到询价信息详情页 2.游客弹起提示 3.VIP跳转到资料补充页
|
||
'inquiry_type' => 1, //1.OA匹配的自动询价 2.楼盘字典匹配的自动询价 3.人工询价
|
||
'eva_unit_price' => round($this->data['eva_unit_price'] / 10) * 10,
|
||
// 'guide_price' => $request_data['guide_price']!=0 ? $request_data['guide_price'] : $this->data['guide_price'],
|
||
'guide_price' => $this->data['guide_price'],
|
||
];
|
||
} else {
|
||
$return = [];
|
||
// VIP,需要在OA插入一条询价记录
|
||
$request_data['guide_price'] = $request_data['guide_price']!=0 ? $request_data['guide_price'] : $this->data['guide_price'];
|
||
if ($this->addInquiryRecord($request_data, $this->data['eva_unit_price']) === true) {
|
||
$return = [
|
||
'redirect' => 1,
|
||
'inquiry_type' => 1, //1.OA匹配的自动询价 2.楼盘字典匹配的自动询价 3.人工询价
|
||
'order_no' => $this->data['order_no'],
|
||
'eva_unit_price' => $this->data['eva_unit_price'],
|
||
'eva_net_value' => $this->data['eva_net_value'],
|
||
'eva_net_value2' => $this->data['eva_net_value2'],
|
||
'total_taxes1' => $this->data['total_taxes1'],
|
||
'total_taxes2' => $this->data['total_taxes2'],
|
||
'gross_value' => $this->data['gross_value'],
|
||
'guide_price' => $this->data['guide_price'],
|
||
'estimates_no' => $this->data['estimates_no'],
|
||
'estimates_url' => $this->data['estimates_url'],
|
||
];
|
||
}
|
||
}
|
||
return $this->buildSuccess($return);
|
||
}
|
||
|
||
/**
|
||
* 2.楼盘字典匹配
|
||
*/
|
||
$url = config('serviceConfig.EVALUATE_DICT_API_URL') . self::CHECK_LOUPAN_URL;
|
||
$param = [
|
||
'loupan_name' => $loupan_name,
|
||
'building_name' => $building_name,
|
||
'unit_no' => $unit_no,
|
||
'province_id' => $province_id,
|
||
'city_id' => $city_id,
|
||
'size' => $size,
|
||
];
|
||
trace($url);
|
||
$loupan_response_data = json_decode($this->sendPost($url, json_encode($param), 30, ['Content-type: application/json']), 1);
|
||
trace('loupan_response_data');
|
||
trace($loupan_response_data);
|
||
|
||
if ($loupan_response_data['code'] == 1) {
|
||
if ($request_data['customer_type'] == 1) { //游客
|
||
$return = [
|
||
'redirect' => 1,
|
||
'inquiry_type' => 2,
|
||
'eva_unit_price' => round($loupan_response_data['data']['price'] / 10) * 10,
|
||
'guide_price' => $loupan_response_data['data']['guide_price'],
|
||
];
|
||
} else {
|
||
$return = [];
|
||
// VIP,需要在OA插入一条询价记录
|
||
$request_data['guide_price'] = $loupan_response_data['data']['guide_price'];
|
||
if ($this->addInquiryRecord($request_data, $loupan_response_data['data']['price']) === true) {
|
||
$return = [
|
||
'redirect' => 1,
|
||
'inquiry_type' => 2, //1.OA匹配的自动询价 2.楼盘字典匹配的自动询价 3.人工询价
|
||
'order_no' => $this->data['order_no'],
|
||
'eva_unit_price' => $this->data['eva_unit_price'],
|
||
'eva_net_value' => $this->data['eva_net_value'],
|
||
'eva_net_value2' => $this->data['eva_net_value2'],
|
||
'total_taxes1' => $this->data['total_taxes1'],
|
||
'total_taxes2' => $this->data['total_taxes2'],
|
||
'gross_value' => $this->data['gross_value'],
|
||
'guide_price' => $this->data['guide_price'],
|
||
];
|
||
}
|
||
}
|
||
return $this->buildSuccess($return);
|
||
}
|
||
trace('OA and Loupan both not match');
|
||
/**
|
||
* 3.OA和楼盘都没匹配到
|
||
*/
|
||
$return = $request_data['customer_type'] == 1 ? ['redirect' => 2] : ['redirect' => 3];
|
||
return $this->buildSuccess($return);
|
||
}
|
||
|
||
// 匹配OA
|
||
private function checkFromOa($loupan_name, $building_name, $unit_no)
|
||
{
|
||
$period = getSystemConfig('EVALUATE_INQUIRY_PERIOD'); // 询价时间范围
|
||
$start_unix_time = time() - $period * 30 * 24 * 3600;
|
||
|
||
$start = date('Y-m-d H:i:s', $start_unix_time);
|
||
$end = date('Y-m-d H:i:s');
|
||
|
||
$building_name = ($building_name != '0' && $building_name != '--') ? $building_name : '';
|
||
$unit_no = ($unit_no != '0' && $unit_no != '--') ? $unit_no : '';
|
||
|
||
$where[] = ['i.status', '>', 1];
|
||
$where[] = ['i.create_time', 'between time', [$start, $end]];
|
||
$where[] = ['id.property_full_name', '=', trim($loupan_name) . trim($building_name) . trim($unit_no)];
|
||
$where[] = ['i.is_auto_eva', '=', 0];
|
||
|
||
$result = Db::name('inquiry')
|
||
->alias('i')
|
||
->Join('property_cert_info id', 'i.id=id.quot_id')
|
||
->field('id.*')
|
||
->where($where)
|
||
->order('i.create_time desc')
|
||
->find();
|
||
|
||
$return_price_data = Db::name('return_price')
|
||
->where(['property_cert_info_id' => $result['id']])
|
||
->order('id desc')
|
||
->find();
|
||
|
||
if ($result && $return_price_data) {
|
||
$this->data = $return_price_data;
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
// OA添加一条询价记录
|
||
private function addInquiryRecord($request_data, $eva_unit_price)
|
||
{
|
||
try {
|
||
// 评估单价个位四舍五入
|
||
$eva_unit_price = round($eva_unit_price/10) * 10;
|
||
Db::startTrans();
|
||
// 1.inquiry表
|
||
$inquiry = new InquiryModel();
|
||
$ins_inquiry_data = [];
|
||
$ins_inquiry_data['order_no'] = $inquiry->generateInquiryNo($request_data['branchCom_id']);
|
||
$ins_inquiry_data['user_id'] = $request_data['user_id'];
|
||
$ins_inquiry_data['user_name'] = $request_data['user_name'];
|
||
$ins_inquiry_data['user_phone'] = $request_data['user_phone'];
|
||
$ins_inquiry_data['bank_id'] = $request_data['bank_id'];
|
||
$ins_inquiry_data['bank_name'] = $request_data['bank_name'];
|
||
$ins_inquiry_data['bank_branch_id'] = $request_data['bank_branch_id'];
|
||
$ins_inquiry_data['bank_branch_name'] = $request_data['bank_branch_name'];
|
||
$ins_inquiry_data['bank_sub_id'] = $request_data['bank_sub_id'];
|
||
$ins_inquiry_data['bank_sub_name'] = $request_data['bank_sub_name'];
|
||
$ins_inquiry_data['eva_purpose'] = $request_data['loan_type'];
|
||
$ins_inquiry_data['product_id'] = $request_data['loan_type_id'];
|
||
$ins_inquiry_data['type'] = 1;
|
||
$ins_inquiry_data['status'] = 2;
|
||
$ins_inquiry_data['eva_detail_time_long'] = 0;
|
||
$ins_inquiry_data['is_auto'] = 1;
|
||
$ins_inquiry_data['is_auto_eva'] = 1;
|
||
$ins_inquiry_data['source'] = 2;
|
||
$ins_inquiry_data['create_time'] = date('Y-m-d H:i:s');
|
||
$ins_inquiry_data['update_time'] = date('Y-m-d H:i:s');
|
||
$quot_id = Db::name('inquiry')->insertGetId($ins_inquiry_data);
|
||
// 2.inquiry_detail表
|
||
$ins_inquiry_detail_data = [];
|
||
$ins_inquiry_detail_data['quot_id'] = $quot_id;
|
||
$ins_inquiry_detail_data['city'] = getCity($request_data['city'])['shortname'];
|
||
$ins_inquiry_detail_data['city_id'] = getCity($request_data['city'])['id'];
|
||
$ins_inquiry_detail_data['property_full_name'] = trim($request_data['loupan_name']) . trim($request_data['building_name']) . trim($request_data['unit_no']);
|
||
$ins_inquiry_detail_data['building_name'] = trim($request_data['loupan_name']);
|
||
$ins_inquiry_detail_data['building_unit_no'] = trim($request_data['building_name']) . trim($request_data['unit_no']);
|
||
$ins_inquiry_detail_data['building_no'] = trim($request_data['building_name']);
|
||
$ins_inquiry_detail_data['unit_no'] = trim($request_data['unit_no']);
|
||
$ins_inquiry_detail_data['size'] = $request_data['size'];
|
||
$ins_inquiry_detail_data['reg_price'] = $request_data['reg_price'];
|
||
$ins_inquiry_detail_data['is_tran_tax_free'] = $request_data['is_over5year'];
|
||
$ins_inquiry_detail_data['ownership_type'] = $request_data['ownership_type'];
|
||
$ins_inquiry_detail_data['usage'] = getDictionaryCode('HOUSE_USAGE', '住宅')['code'];
|
||
$ins_inquiry_detail_data['create_time'] = date('Y-m-d H:i:s');
|
||
$ins_inquiry_detail_data['update_time'] = date('Y-m-d H:i:s');
|
||
$property_cert_info = Db::name('property_cert_info')->insertGetId($ins_inquiry_detail_data);
|
||
// 判断结果
|
||
if (!$quot_id || !$property_cert_info) {
|
||
Db::rollback();
|
||
return false;
|
||
}
|
||
Db::commit();
|
||
|
||
// 3.查询税费计算
|
||
$Taxation = new Taxation();
|
||
$map['bank_id'] = $request_data['bank_id'];
|
||
$map['product_name'] = $request_data['loan_type'];
|
||
$map['type'] = 1;
|
||
$map['state'] = 1;
|
||
if (isset($request_data['bank_branch_id']) && !empty($request_data['bank_branch_id'])) {
|
||
$map['branch_id'] = $request_data['bank_branch_id'];
|
||
}
|
||
$tax_items = $Taxation->where($map)->value("tax_items");
|
||
$post_data = [
|
||
'eva_unit_price' => $eva_unit_price,
|
||
'id' => $property_cert_info,
|
||
'is_tran_tax_free' => $request_data['is_over5year'],
|
||
'loan_ratio' => "0.70",
|
||
'reg_price' => $request_data['reg_price'],
|
||
'size' => $request_data['size'],
|
||
'tax_items' => explode(',', $tax_items),
|
||
'ownership_type' => $request_data['ownership_type']
|
||
];
|
||
$url = env('uploadFile.host_url') . '/admin/Pending/AutomaticCalculation';
|
||
$return_price_data = json_decode($this->sendPost($url, json_encode($post_data), 30, ['Content-type: application/json']), true);
|
||
if ($return_price_data['code'] != 1) {
|
||
trace('税费计算出错:');
|
||
trace($return_price_data);
|
||
return false;
|
||
}
|
||
|
||
$ins_return_price_data = [
|
||
'property_cert_info_id' => $property_cert_info,
|
||
'property_name' => trim($request_data['loupan_name']) . trim($request_data['building_name']) . trim($request_data['unit_no']),
|
||
'area' => $request_data['size'],
|
||
// 'floor' => $request_data['floor'],
|
||
'building_unit_no' => trim($request_data['building_name']) . trim($request_data['unit_no']),
|
||
'building_no' => trim($request_data['building_name']),
|
||
'unit_no' => trim($request_data['unit_no']),
|
||
'eva_unit_price' => $eva_unit_price,
|
||
'guide_price' => $request_data['guide_price'] ?? 0,
|
||
'eva_total_value' => $return_price_data['data']['eva_total_value'],
|
||
'eva_net_value' => $return_price_data['data']['eva_net_value'],
|
||
'eva_net_value2' => $return_price_data['data']['eva_net_value2'],
|
||
'corporate_income_tax' => $return_price_data['data']['corporate_income_tax'],
|
||
'tran_service_fee' => $return_price_data['data']['tran_service_fee'],
|
||
'edu_surcharge' => $return_price_data['data']['edu_surcharge'],
|
||
'urban_construction_tax' => $return_price_data['data']['urban_construction_tax'],
|
||
'deed_tax' => $return_price_data['data']['deed_tax'],
|
||
'stamp_duty' => $return_price_data['data']['stamp_duty'],
|
||
'added_tax' => $return_price_data['data']['added_tax'],
|
||
'land_value_added_tax' => $return_price_data['data']['land_value_added_tax'],
|
||
'land_value_added_tax_copy' => $return_price_data['data']['land_value_added_tax_copy'],
|
||
'personal_income_tax' => $return_price_data['data']['personal_income_tax'],
|
||
'personal_income_tax_copy' => $return_price_data['data']['personal_income_tax_copy'],
|
||
'auction_fee' => $return_price_data['data']['auction_fee'],
|
||
'total_taxes1' => $return_price_data['data']['total_taxes1'],
|
||
'total_taxes2' => $return_price_data['data']['total_taxes2'],
|
||
'loan_ratio' => 0.70,
|
||
'gross_value' => $return_price_data['data']['gross_value'],
|
||
'eva_net_value' => $return_price_data['data']['eva_net_value'],
|
||
'eva_net_value2' => $return_price_data['data']['eva_net_value2'],
|
||
'tax_items' => $tax_items,
|
||
'tips' => $return_price_data['data']['tips'],
|
||
'appraiser_id' => 0,
|
||
'appraiser_name' => '自动估价',
|
||
'create_time' => time()
|
||
];
|
||
|
||
Db::name('return_price')->insert($ins_return_price_data);
|
||
|
||
// 匹配OA生成盖章的预估单(取消自动签章2021-06-30)
|
||
// $post_estimate_data = [
|
||
// 'id' => $quot_id,
|
||
// 'appraiser_ids' => env('evaluate.valuer_id')
|
||
// ];
|
||
// $estimate_url = env('uploadFile.host_url') . '/admin/Pending/SignatureSave';
|
||
// $estimate = json_decode($this->sendPost($estimate_url, json_encode($post_estimate_data), 30, ['Content-type: application/json']), true);
|
||
|
||
// PublicMessage($quot_id, 2, 2);
|
||
$this->data = [
|
||
'order_no' => $ins_inquiry_data['order_no'],
|
||
'eva_unit_price' => $eva_unit_price,
|
||
'eva_total_value' => $return_price_data['data']['eva_total_value'],
|
||
'eva_net_value' => $return_price_data['data']['eva_net_value'],
|
||
'eva_net_value2' => $return_price_data['data']['eva_net_value2'],
|
||
'total_taxes1' => $return_price_data['data']['total_taxes1'],
|
||
'total_taxes2' => $return_price_data['data']['total_taxes2'],
|
||
'gross_value' => $return_price_data['data']['gross_value'],
|
||
'guide_price' => $request_data['guide_price'],
|
||
// 'estimates_no' => !empty($estimate['data']) ? $estimate['data'] : '',
|
||
// 'estimates_url' => !empty($estimate['data']) ? env('uploadFile.host_url') . '/admin/Pending/EstimateSheetTemplate?estimated_no=' . $estimate['data'] : '',
|
||
'estimates_no' => '',
|
||
'estimates_url' => '',
|
||
];
|
||
return true;
|
||
} catch (\Exception $e) {
|
||
Db::rollback();
|
||
trace('错误接口:' . request()->path());
|
||
trace('操作参数:' . json_encode(input(), 256));
|
||
trace('错误文件:' . $e->getFile());
|
||
trace('错误行数:' . $e->getLine());
|
||
trace('错误代码:' . $e->getCode());
|
||
trace('错误信息:' . $e->getMessage());
|
||
return '系统开小差,请稍后重试!';
|
||
}
|
||
|
||
|
||
}
|
||
|
||
/**
|
||
* POST 请求(支持文件上传)
|
||
* @param string $url HTTP请求URL地址
|
||
* @param array|string $data POST提交的数据
|
||
* @param int $second 请求超时时间
|
||
* @param array $header 请求Header信息
|
||
* @return bool|string
|
||
*/
|
||
static public function sendPost($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);
|
||
}
|
||
}
|
||
|
||
// 估价系统补充资料时,询价记录需要改状态到待回价
|
||
public function modifyInquiryStatus()
|
||
{
|
||
// $order_no = input('order_no');
|
||
$input = input('');
|
||
if (!$input['order_no']) return $this->buildFailed('询价单号不能为空');
|
||
$attachments = '';
|
||
if (!empty($input['property_pic_info'])) {
|
||
$input['property_pic_info']['url'] = $input['oss_base_url'] . $input['property_pic_info']['url'];
|
||
$input['property_pic_info']['thum1'] = $input['property_pic_info']['url'];
|
||
unset($input['property_pic_info']['id']);
|
||
unset($input['property_pic_info']['fs_attachment_id']);
|
||
unset($input['property_pic_info']['thum2']);
|
||
unset($input['property_pic_info']['thum3']);
|
||
unset($input['property_pic_info']['category']);
|
||
$attachments = Db::name('attachment')->insertGetId($input['property_pic_info']);
|
||
}
|
||
|
||
$remark = '';
|
||
if (!empty($input['house_structure'])) $remark .= '户型结构:' . $input['house_structure'] . '|';
|
||
if (!empty($input['is_double_str'])) $remark .= '是否双拼:' . $input['is_double_str'] . '|';
|
||
if (!empty($input['is_double_plus_str'])) $remark .= '是否多拼:' . $input['is_double_plus_str'] . '|';
|
||
if (!empty($input['unit_type'])) $remark .= '户型:' . $input['unit_type'] . '|';
|
||
if (!empty($input['house_toward'])) $remark .= '朝向:' . $input['house_toward'] . '|';
|
||
if (!empty($input['landspace'])) $remark .= '景观:' . $input['landspace'] . '|';
|
||
if (!empty($input['decoration'])) $remark .= '装修情况:' . $input['decoration'] . '|';
|
||
if (!empty($input['remark'])) $remark .= '其他说明:' . $input['remark'];
|
||
|
||
try {
|
||
$inquiry_info = Db::name('inquiry')->where(['order_no' => $input['order_no']])->find();
|
||
if (!$inquiry_info) return $this->buildFailed('询价记录不存在');
|
||
if (!in_array($inquiry_info['status'], [1, 2])) return $this->buildFailed('估计师正在加急处理此询价,请勿重复操作');
|
||
// 补充资料更新到询价详情表
|
||
$property_cert_info['attachments'] = $attachments;
|
||
$property_cert_info['remark'] = trim($remark, '|');
|
||
if ($inquiry_info['status'] == 2) {
|
||
$property_cert_info['adjust_status'] = 1;
|
||
$property_cert_info['adjust_reason'] = '城市云估价格复核';
|
||
$property_cert_info['variance_ratio'] = 0.05;
|
||
}
|
||
Db::name('property_cert_info')->where(['quot_id' => $inquiry_info['id']])->update($property_cert_info);
|
||
// 已回价的估价系统询价,价格复核不用修改status为1,流转到自动估价调价项目2021-07-02
|
||
// Db::name('inquiry')->where(['id' => $inquiry_info['id']])->update(['status' => 1, 'update_time' => date('Y-m-d H:i:s')]); // 2021-07-02 注释
|
||
return $this->buildSuccess();
|
||
} catch (\Exception $e) {
|
||
trace('错误接口:' . request()->path());
|
||
trace('操作参数:' . json_encode(input(), 256));
|
||
trace('错误文件:' . $e->getFile());
|
||
trace('错误行数:' . $e->getLine());
|
||
trace('错误代码:' . $e->getCode());
|
||
trace('错误信息:' . $e->getMessage());
|
||
return $this->buildFailed('系统开小差,请稍后重试!');
|
||
}
|
||
}
|
||
|
||
// 估价系统补充资料时,如果之前没匹配OA或者后台的,需在OA系统新增一条询价记录
|
||
public function addInquiry()
|
||
{
|
||
$request_data = input('');
|
||
|
||
$validate = new EvaluateInquiryValidate();
|
||
if (!$validate->check($request_data)) return $this->buildFailed($validate->getError());
|
||
|
||
$attachments = '';
|
||
if (!empty($request_data['property_pic_info'])) {
|
||
$request_data['property_pic_info']['url'] = $request_data['oss_base_url'] . $request_data['property_pic_info']['url'];
|
||
$request_data['property_pic_info']['thum1'] = $request_data['property_pic_info']['url'];
|
||
unset($request_data['property_pic_info']['id']);
|
||
unset($request_data['property_pic_info']['fs_attachment_id']);
|
||
unset($request_data['property_pic_info']['thum2']);
|
||
unset($request_data['property_pic_info']['thum3']);
|
||
unset($request_data['property_pic_info']['category']);
|
||
$attachments = Db::name('attachment')->insertGetId($request_data['property_pic_info']);
|
||
}
|
||
|
||
$remark = '';
|
||
if (!empty($request_data['house_structure'])) $remark .= '户型结构:' . $request_data['house_structure'] . '|';
|
||
if (!empty($request_data['is_double_str'])) $remark .= '是否双拼:' . $request_data['is_double_str'] . '|';
|
||
if (!empty($request_data['is_double_plus_str'])) $remark .= '是否多拼:' . $request_data['is_double_plus_str'] . '|';
|
||
if (!empty($request_data['unit_type'])) $remark .= '户型:' . $request_data['unit_type'] . '|';
|
||
if (!empty($request_data['house_toward'])) $remark .= '朝向:' . $request_data['house_toward'] . '|';
|
||
if (!empty($request_data['landspace'])) $remark .= '景观:' . $request_data['landspace'] . '|';
|
||
if (!empty($request_data['decoration'])) $remark .= '装修情况:' . $request_data['decoration'] . '|';
|
||
if (!empty($request_data['remark'])) $remark .= '其他说明:' . $request_data['remark'];
|
||
|
||
try {
|
||
Db::startTrans();
|
||
// 1.inquiry表
|
||
$inquiry = new InquiryModel();
|
||
$order_no = $inquiry->generateInquiryNo($request_data['type']);
|
||
$ins_inquiry_data = [];
|
||
$ins_inquiry_data['order_no'] = $order_no;
|
||
$ins_inquiry_data['user_id'] = $request_data['user_id'];
|
||
$ins_inquiry_data['user_name'] = $request_data['user_name'];
|
||
$ins_inquiry_data['user_phone'] = $request_data['user_phone'];
|
||
$ins_inquiry_data['bank_id'] = $request_data['bank_id'];
|
||
$ins_inquiry_data['bank_name'] = $request_data['bank_name'];
|
||
$ins_inquiry_data['bank_branch_id'] = $request_data['bank_branch_id'];
|
||
$ins_inquiry_data['bank_branch_name'] = $request_data['bank_branch_name'];
|
||
$ins_inquiry_data['bank_sub_id'] = $request_data['bank_sub_id'];
|
||
$ins_inquiry_data['bank_sub_name'] = $request_data['bank_sub_name'];
|
||
$ins_inquiry_data['eva_purpose'] = $request_data['loan_type'];
|
||
$ins_inquiry_data['product_id'] = $request_data['loan_type_id'];
|
||
$ins_inquiry_data['type'] = 1;
|
||
$ins_inquiry_data['status'] = 1;
|
||
$ins_inquiry_data['eva_detail_time_long'] = 0;
|
||
$ins_inquiry_data['is_auto'] = 1;
|
||
$ins_inquiry_data['is_auto_eva'] = 0;
|
||
$ins_inquiry_data['source'] = 2;
|
||
$ins_inquiry_data['create_time'] = date('Y-m-d H:i:s');
|
||
$ins_inquiry_data['update_time'] = date('Y-m-d H:i:s');
|
||
$quot_id = Db::name('inquiry')->insertGetId($ins_inquiry_data);
|
||
// 2.inquiry_detail表
|
||
$ins_inquiry_detail_data = [];
|
||
$ins_inquiry_detail_data['quot_id'] = $quot_id;
|
||
$ins_inquiry_detail_data['city'] = getCity($request_data['city'])['shortname'];
|
||
$ins_inquiry_detail_data['city_id'] = getCity($request_data['city'])['id'];
|
||
$ins_inquiry_detail_data['property_full_name'] = trim($request_data['loupan_name']) . trim($request_data['building_name']) . trim($request_data['unit_no']);
|
||
$ins_inquiry_detail_data['building_name'] = trim($request_data['loupan_name']);
|
||
$ins_inquiry_detail_data['building_unit_no'] = trim($request_data['building_name']) . trim($request_data['unit_no']);
|
||
$ins_inquiry_detail_data['building_no'] = trim($request_data['building_name']);
|
||
$ins_inquiry_detail_data['unit_no'] = trim($request_data['unit_no']);
|
||
$ins_inquiry_detail_data['size'] = $request_data['size'];
|
||
$ins_inquiry_detail_data['reg_price'] = $request_data['reg_price'];
|
||
$ins_inquiry_detail_data['is_tran_tax_free'] = $request_data['is_over5year'];
|
||
$ins_inquiry_detail_data['ownership_type'] = $request_data['ownership_type'];
|
||
$ins_inquiry_detail_data['usage'] = getDictionaryCode('HOUSE_USAGE', '住宅')['code'];
|
||
$ins_inquiry_detail_data['attachments'] = $attachments;
|
||
$ins_inquiry_detail_data['remark'] = trim($remark, '|');
|
||
$ins_inquiry_detail_data['create_time'] = date('Y-m-d H:i:s');
|
||
$ins_inquiry_detail_data['update_time'] = date('Y-m-d H:i:s');
|
||
$property_cert_info = Db::name('property_cert_info')->insertGetId($ins_inquiry_detail_data);
|
||
// 判断结果
|
||
if (!$quot_id || !$property_cert_info) {
|
||
Db::rollback();
|
||
return false;
|
||
}
|
||
Db::commit();
|
||
return $this->buildSuccess(['order_no' => $order_no]);
|
||
} catch (\Exception $e) {
|
||
trace('错误接口:' . request()->path());
|
||
trace('操作参数:' . json_encode(input(), 256));
|
||
trace('错误文件:' . $e->getFile());
|
||
trace('错误行数:' . $e->getLine());
|
||
trace('错误代码:' . $e->getCode());
|
||
trace('错误信息:' . $e->getMessage());
|
||
return $this->buildFailed('系统开小差,请稍后重试!');
|
||
}
|
||
}
|
||
|
||
|
||
} |