1011 lines
48 KiB
PHP
1011 lines
48 KiB
PHP
<?php
|
||
|
||
|
||
namespace app\model;
|
||
|
||
|
||
use think\Db;
|
||
use app\model\ReportDetail;
|
||
use app\admin\service\CommonService;
|
||
use app\admin\controller\Charge as ChargeController;
|
||
use app\common\config\EnumCfg;
|
||
use app\util\Tools;
|
||
|
||
class Report extends Base
|
||
{
|
||
public $autoWriteTimestamp = 'datetime';
|
||
|
||
/**
|
||
* 报告编号修改-精确到年月日
|
||
* @param $quot_id
|
||
* @param string $business_type
|
||
* @return array
|
||
*/
|
||
public function generateReportNo($quot_id, $business_type = '')
|
||
{
|
||
$report_no_array = ['report_no' => "", 'second' => "",'code'=>'0','msg'=>'success!'];
|
||
$resInfo = Tools::generateNo($quot_id,Tools::GENERATE_TYPE_REPORT,$business_type);
|
||
|
||
if($resInfo['code'] != 0)
|
||
{
|
||
$report_no_array['code']=-1;
|
||
$report_no_array['msg']=$resInfo['msg'];
|
||
return $report_no_array;
|
||
}
|
||
|
||
$report_no_array['report_no'] = $resInfo['data'];
|
||
$second = 0; // 去掉建行电子提取码的算法
|
||
$report_no_array['msg'] = '生成成功!';
|
||
return $report_no_array;
|
||
|
||
|
||
// 国中规则:区域inquiry.brankCom_id + 报告方向report.report_dir + 年份 +
|
||
// 报告(对象)类型report.report_obj_type + 客户类型bank.custom_type +
|
||
// 类型report.report_class + 月份 + 流水号 + 机构简称 bank.short_name
|
||
// 区域
|
||
/* $inquiry = Db::name('inquiry')->field('type,bank_id,eva_purpose,is_simple,branchCom_id,report_class,report_dir,report_obj_type')->where('id', $quot_id)->find();
|
||
//检查inquiry表数据是否存在
|
||
if(!$inquiry){
|
||
$report_no_array['code'] = -1;
|
||
$report_no_array['msg'] = '询价ID:['.$quot_id.']的询价表数据不存在';
|
||
return $report_no_array;
|
||
}
|
||
// 报告方向 鉴证类:(评)字、预估类:(预)字、咨询类:(咨)字、复核类:(核)字
|
||
$reportDirItem = Enumcfg::findById(Enumcfg::reportDir, $inquiry['report_dir']);
|
||
if(null == $reportDirItem){
|
||
$report_no_array['code'] = -5;
|
||
$report_no_array['msg'] = '报告方向:['.$inquiry['report_dir'].']的枚举表数据不存在';
|
||
return $report_no_array;
|
||
}
|
||
$reportDir = $reportDirItem['shortName'];
|
||
|
||
// 报告对象类型 F:房产 T:土地 Z:资产
|
||
$reportObjTypeItem = Enumcfg::findById( Enumcfg::reportObjType, $inquiry['report_obj_type']);
|
||
if(null == $reportObjTypeItem){
|
||
$report_no_array['code'] = -6;
|
||
$report_no_array['msg'] = '报告对象类型:['.$inquiry['report_obj_type'].']的枚举表数据不存在';
|
||
return $report_no_array;
|
||
}
|
||
$reportObjType = $reportObjTypeItem['shortName'];
|
||
|
||
// 报告类型:
|
||
$reportClassItem = Enumcfg::findById( Enumcfg::reportClass, $inquiry['report_class']);
|
||
if(null == $reportClassItem){
|
||
$report_no_array['code'] = -7;
|
||
$report_no_array['msg'] = '报告类型:['.$inquiry['report_class'].']的枚举表数据不存在';
|
||
return $report_no_array;
|
||
}
|
||
$reportClass = $reportClassItem ['shortName'];
|
||
|
||
// 机构简称
|
||
$branchComConfig = Db::name('branchcom_config')->where('id', $inquiry['branchCom_id']) // 或者根据实际关联字段调整查询条件
|
||
->field('short_name')
|
||
->find();
|
||
|
||
if(!$branchComConfig){
|
||
$report_no_array['code'] = -2;
|
||
$report_no_array['msg'] = '机构代码:['.$inquiry['branchCom_id'].']的机构表数据不存在';
|
||
return $report_no_array;
|
||
}
|
||
$short_name = $branchComConfig['short_name'];
|
||
|
||
// 机构简称 暂时用银行简称代替,后续需要改成机构简称
|
||
$bankInfo = Db::name('bank')->field('bank_abbreviation')->where('id', $inquiry['bank_id'])->find();
|
||
if(!$bankInfo){
|
||
$report_no_array['code'] = -3;
|
||
$report_no_array['msg'] = '询价ID:['.$quot_id.']的机构表数据不存在';
|
||
return $report_no_array;
|
||
}
|
||
|
||
$first = '';
|
||
if(!$business_type || $business_type == 1){
|
||
$first = 'G';
|
||
}elseif($business_type == 2){
|
||
$first = 'C';
|
||
}
|
||
|
||
//判断物业用途有没有商务公寓(住宅)
|
||
$res = Db::name('property_cert_info')->where(['quot_id'=>$quot_id,'usage'=>18])->find();
|
||
if($inquiry['type'] == 1 && !$res){
|
||
$first .= 'A';
|
||
}elseif($inquiry['type'] == 1 && $res){
|
||
$first .= 'B';
|
||
} else{
|
||
$first .= 'C';
|
||
}
|
||
$first = date('Y') . $first;
|
||
|
||
$where[] = ['r.report_source', '=', 1];
|
||
$where[] = ['i.is_simple', '=', $inquiry['is_simple']];
|
||
$where[] = ['r.report_no', 'neq', ''];
|
||
$where[] = ['r.e_case_code', 'like', '%'.date('Ymd').'%'];
|
||
$max = $this->lock(true)->alias('r')
|
||
->field('r.id,r.report_no')
|
||
->join('inquiry i', 'i.id = r.quot_id')
|
||
->where($where)
|
||
->order('r.create_reportNo_time desc,r.id desc')
|
||
->find();
|
||
|
||
// 中国建设银行合同周期内同一抵押物历史评估次数统计(合同服务开始时间2023年7月13日)
|
||
// 抵押贷款(云)
|
||
$frequency = 0;
|
||
if ($inquiry['bank_id']==777 && $inquiry['eva_purpose']=='抵押贷款(云)') {
|
||
$estate_data = Db::name('property_cert_info')->where(['quot_id'=>$quot_id])->field('property_full_name')->select();
|
||
if ($estate_data) {
|
||
$map[] = ['a.assessment_purpose', '=', '抵押贷款(云)'];
|
||
$map[] = ['a.bank_id', '=', 777];
|
||
$map[] = ['a.create_time', 'gt', '2023-07-20 00:00:00'];
|
||
$map[] = ['b.seal_status', '=', 2];
|
||
foreach ($estate_data as $key=>$value) {
|
||
$freq_count = Db::name('charge')
|
||
->alias('a')
|
||
->join('report b', 'a.report_no=b.report_no')
|
||
->where($map)
|
||
->where("a.building_name like '%" . $value['property_full_name'] . "%'")
|
||
->count();
|
||
if ($freq_count>$frequency){
|
||
$frequency = $freq_count;
|
||
}
|
||
}
|
||
$frequency = $frequency + 1;
|
||
}
|
||
}
|
||
|
||
if (!$max) {
|
||
// $second = "001";
|
||
$serial_number = "001";
|
||
} else {
|
||
$no = explode('-', $max->report_no);
|
||
$month = substr($no[1] ,0, 4);
|
||
$month_now = date('md');
|
||
if ($month==$month_now) {
|
||
$number = (int)substr($no[1] ,4, 3);
|
||
$number += 1;
|
||
// $second = str_pad($number, 3, 0, STR_PAD_LEFT);
|
||
$serial_number = str_pad($number, 3, 0, STR_PAD_LEFT);
|
||
} else {
|
||
// $second = "001";
|
||
$serial_number = "001";
|
||
}
|
||
}
|
||
// $second = date('md').$second;
|
||
$second = date('md') . $serial_number;
|
||
$third = Db::name('bank')->where('id', $inquiry['bank_id'])->value('bank_code');
|
||
$report_no = $first . '-'. $second;
|
||
if($third) $report_no = $first . '-'. $second . '-' . $third;
|
||
|
||
if ($inquiry['bank_id']==777 && $inquiry['eva_purpose']=='抵押贷款(云)') {
|
||
$second = date('md') . $frequency . $serial_number;
|
||
}
|
||
|
||
return ['report_no' => $report_no, 'second' => $second];*/
|
||
}
|
||
|
||
/**
|
||
* (旧版)生成报告编号
|
||
* @param $quot_id
|
||
* @param string $business_type
|
||
* @return array
|
||
*/
|
||
public function generateReportNo_gy($quot_id, $business_type = '')
|
||
{
|
||
$inquiry = Db::name('inquiry')->field('type,bank_id,eva_purpose,is_simple')->where('id', $quot_id)->find();
|
||
$first = '';
|
||
if(!$business_type || $business_type == 1){
|
||
$first = 'G';
|
||
}elseif($business_type == 2){
|
||
$first = 'C';
|
||
}
|
||
|
||
//判断物业用途有没有商务公寓(住宅)
|
||
$res = Db::name('property_cert_info')->where(['quot_id'=>$quot_id,'usage'=>18])->find();
|
||
if($inquiry['type'] == 1 && !$res){
|
||
$first .= 'A';
|
||
}elseif($inquiry['type'] == 1 && $res){
|
||
$first .= 'B';
|
||
} else{
|
||
$first .= 'C';
|
||
}
|
||
$first = date('Y') . $first;
|
||
|
||
$where[] = ['r.report_source', '=', 1];
|
||
$where[] = ['i.is_simple', '=', $inquiry['is_simple']];
|
||
$where[] = ['r.report_no', 'neq', ''];
|
||
$where[] = ['r.e_case_code', 'like', '%'.date('Ymd').'%'];
|
||
$max = $this->lock(true)->alias('r')
|
||
->field('r.id,r.report_no')
|
||
->join('inquiry i', 'i.id = r.quot_id')
|
||
->where($where)
|
||
->order('r.create_reportNo_time desc,r.id desc')
|
||
->find();
|
||
|
||
// 中国建设银行合同周期内同一抵押物历史评估次数统计(合同服务开始时间2023年7月13日)
|
||
// 抵押贷款(云)
|
||
$frequency = 0;
|
||
if ($inquiry['bank_id']==777 && $inquiry['eva_purpose']=='抵押贷款(云)') {
|
||
$estate_data = Db::name('property_cert_info')->where(['quot_id'=>$quot_id])->field('property_full_name')->select();
|
||
if ($estate_data) {
|
||
$map[] = ['a.assessment_purpose', '=', '抵押贷款(云)'];
|
||
$map[] = ['a.bank_id', '=', 777];
|
||
$map[] = ['a.create_time', 'gt', '2023-07-20 00:00:00'];
|
||
$map[] = ['b.seal_status', '=', 2];
|
||
foreach ($estate_data as $key=>$value) {
|
||
$freq_count = Db::name('charge')
|
||
->alias('a')
|
||
->join('report b', 'a.report_no=b.report_no')
|
||
->where($map)
|
||
->where("a.building_name like '%" . $value['property_full_name'] . "%'")
|
||
->count();
|
||
if ($freq_count>$frequency){
|
||
$frequency = $freq_count;
|
||
}
|
||
}
|
||
$frequency = $frequency + 1;
|
||
}
|
||
}
|
||
|
||
if (!$max) {
|
||
// $second = "001";
|
||
$serial_number = "001";
|
||
} else {
|
||
$no = explode('-', $max->report_no);
|
||
$month = substr($no[1] ,0, 4);
|
||
$month_now = date('md');
|
||
if ($month==$month_now) {
|
||
$number = (int)substr($no[1] ,4, 3);
|
||
$number += 1;
|
||
// $second = str_pad($number, 3, 0, STR_PAD_LEFT);
|
||
$serial_number = str_pad($number, 3, 0, STR_PAD_LEFT);
|
||
} else {
|
||
// $second = "001";
|
||
$serial_number = "001";
|
||
}
|
||
}
|
||
// $second = date('md').$second;
|
||
$second = date('md') . $serial_number;
|
||
$third = Db::name('bank')->where('id', $inquiry['bank_id'])->value('bank_code');
|
||
$report_no = $first . '-'. $second;
|
||
if($third) $report_no = $first . '-'. $second . '-' . $third;
|
||
|
||
if ($inquiry['bank_id']==777 && $inquiry['eva_purpose']=='抵押贷款(云)') {
|
||
$second = date('md') . $frequency . $serial_number;
|
||
}
|
||
|
||
return ['report_no' => $report_no, 'second' => $second];
|
||
}
|
||
|
||
public function changeReportNo($quot_id, $business_type, $appraisal_time)
|
||
{
|
||
$inquiry = Db::name('inquiry')
|
||
->field('type,bank_id,eva_purpose,is_simple')
|
||
->where('id', $quot_id)
|
||
->find();
|
||
$first = '';
|
||
if (!$business_type || $business_type == 1) {
|
||
$first = 'G';
|
||
} elseif($business_type == 2) {
|
||
$first = 'C';
|
||
}
|
||
|
||
//判断物业用途有没有商务公寓(住宅)
|
||
$res = Db::name('property_cert_info')
|
||
->where(['quot_id'=>$quot_id,'usage'=>18])
|
||
->find();
|
||
if ($inquiry['type'] == 1 && !$res) {
|
||
$first .= 'A';
|
||
} elseif($inquiry['type'] == 1 && $res) {
|
||
$first .= 'B';
|
||
} else {
|
||
$first .= 'C';
|
||
}
|
||
$year = substr($appraisal_time ,0, 4);
|
||
$first = $year . $first;
|
||
|
||
$where[] = ['r.report_source', '=', 1];
|
||
$where[] = ['i.is_simple', '=', $inquiry['is_simple']];
|
||
$where[] = ['r.report_no', 'neq', ''];
|
||
$where[] = ['r.e_case_code', 'like', '%'.$appraisal_time.'%'];
|
||
$max = $this->lock(true)->alias('r')
|
||
->field('r.id,r.report_no')
|
||
->join('inquiry i', 'i.id = r.quot_id')
|
||
->where($where)
|
||
->order('r.create_reportNo_time desc,r.id desc')
|
||
->find();
|
||
|
||
// 中国建设银行合同周期内同一抵押物历史评估次数统计(合同服务开始时间2023年7月13日)
|
||
// 抵押贷款(云)
|
||
$frequency = 0;
|
||
if ($inquiry['bank_id']==777 && $inquiry['eva_purpose']=='抵押贷款(云)') {
|
||
$estate_data = Db::name('property_cert_info')->where(['quot_id'=>$quot_id])->field('property_full_name')->select();
|
||
if ($estate_data) {
|
||
$map[] = ['a.assessment_purpose', '=', '抵押贷款(云)'];
|
||
$map[] = ['a.bank_id', '=', 777];
|
||
$map[] = ['a.create_time', 'gt', '2023-07-20 00:00:00'];
|
||
$map[] = ['b.seal_status', '=', 2];
|
||
foreach ($estate_data as $key=>$value) {
|
||
$freq_count = Db::name('charge')
|
||
->alias('a')
|
||
->join('report b', 'a.report_no=b.report_no')
|
||
->where($map)
|
||
->where("a.building_name like '%" . $value['property_full_name'] . "%'")
|
||
->count();
|
||
if ($freq_count>$frequency){
|
||
$frequency = $freq_count;
|
||
}
|
||
}
|
||
$frequency = $frequency + 1;
|
||
}
|
||
}
|
||
|
||
if (!$max) {
|
||
// $second = "001";
|
||
$serial_number = "001";
|
||
} else {
|
||
$no = explode('-', $max->report_no);
|
||
$monthday = substr($no[1] ,0, 4);
|
||
$monthday_assessment = substr($appraisal_time ,4, 4);
|
||
if ($monthday==$monthday_assessment) {
|
||
$number = (int)substr($no[1] ,4, 3);
|
||
$number += 1;
|
||
// $second = str_pad($number, 3, 0, STR_PAD_LEFT);
|
||
$serial_number = str_pad($number, 3, 0, STR_PAD_LEFT);
|
||
} else {
|
||
// $second = "001";
|
||
$serial_number = "001";
|
||
}
|
||
}
|
||
// $second = substr($appraisal_time ,4, 4) . $second;
|
||
$second = substr($appraisal_time, 4, 4) . $serial_number;
|
||
$third = Db::name('bank')->where('id', $inquiry['bank_id'])->value('bank_code');
|
||
$report_no = $first . '-'. $second;
|
||
if($third) $report_no = $first . '-'. $second . '-' . $third;
|
||
|
||
if ($inquiry['bank_id']==777 && $inquiry['eva_purpose']=='抵押贷款(云)') {
|
||
// $second = date('md') . $frequency . $serial_number;
|
||
$second = substr($appraisal_time, 4, 4) . $frequency . $serial_number;
|
||
}
|
||
|
||
return ['report_no' => $report_no, 'second' => $second];
|
||
}
|
||
|
||
/**
|
||
* 通过询价ID获取报告制作时间
|
||
*
|
||
* @param [type] $quot_id
|
||
* @return void
|
||
*/
|
||
public function getReportMakeTimeByInquiryDetailID( $quot_id )
|
||
{
|
||
$arr = $this->where(['quot_id' => $quot_id ])->field('produce_time')->select();
|
||
if( count($arr) == 0 )
|
||
{
|
||
return 0;
|
||
}
|
||
else
|
||
{
|
||
return $arr[0];
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 通过Inquiryid查询报告记录
|
||
*
|
||
* @return reports[] //返回报告记录
|
||
*/
|
||
public function getReportByInquiryID( $inquiryID)
|
||
{
|
||
return Db::name('report')->where(['quot_id'=> $inquiryID])->select();
|
||
}
|
||
|
||
/**
|
||
* 获取离线报告号
|
||
* @param int $quot_id
|
||
* @param int $business_type
|
||
* @return [‘report_no’=>xxxx, 'second'=>xxxx ]
|
||
*/
|
||
private function getOffLineReportNo( $quot_id, $business_type )
|
||
{
|
||
$rp_no = $this->generateReportNo( $quot_id, $business_type );
|
||
$res = ['report_no' => 'F'.$rp_no['report_no'], 'second' => $rp_no['second'] ];
|
||
return $res;
|
||
}
|
||
|
||
/**
|
||
* 创建线下报告(用于取报告码用)
|
||
*
|
||
* @param [type] $data
|
||
* @return $res [
|
||
* 'result' boolean // 事务回调函数执行结果
|
||
* 'report_no' string // 报告号
|
||
* 'e_case_code' string // 电子档提取码
|
||
* ]
|
||
* @throws \think\db\exception\DataNotFoundException
|
||
* @throws \think\db\exception\ModelNotFoundException
|
||
* @throws \think\exception\DbException
|
||
*/
|
||
public function createOffLineReport( $data )
|
||
{
|
||
// 返回结果的定义
|
||
$res=[];
|
||
|
||
$res['isSucess'] = false;
|
||
$res['report_no'] ='';
|
||
$res['reason'] ='';
|
||
|
||
$resTran = Db::transaction( function ()use ($data){
|
||
// 1、需要InquiryId
|
||
$this->quot_id = $data['quot_id'];
|
||
$inquiryInfo = Db::name('inquiry')->field("id,report_dir,report_obj_type,report_class,branchCom_id,seal_time")
|
||
->where(['id'=> $data['quot_id']])->find();
|
||
|
||
// 2、报告表里是否存在此InquiryId
|
||
$reportId = Db::name('report')->where(['quot_id'=> $data['quot_id']])->value('id');
|
||
|
||
// 如果存在,直接返回报告ID
|
||
if($reportId)
|
||
{
|
||
$res['isSucess'] = true;
|
||
$report_no = Db::name('report')->where(['id'=>$reportId])->value('report_no');
|
||
$res['report_no'] = $report_no;
|
||
|
||
return $res;
|
||
}
|
||
else // 如果不存在,生成一条空报告
|
||
{
|
||
|
||
$detail_list = Db::table('pg_property_cert_info')->where(['quot_id' => $this->quot_id ])->select();
|
||
if( count($detail_list) <= 0 )
|
||
throw new \Exception('pg_inquiry_detail表找不到inquiry_id为'.$this->quot_id.'的记录。');
|
||
|
||
$CHECKING = 2; // 待审核
|
||
$this->status = $CHECKING; // status: 1待制作 2待审核 3完成 4草稿
|
||
$this->create_time = date('Y-m-d H:i:s', time());
|
||
$this->business_type = 3;//业务类型 1个贷 2对公 3 其他
|
||
$reportNOInfo = $this->generateReportNo( $this->quot_id, $this->business_type );
|
||
if($reportNOInfo['code'] != 0)
|
||
{
|
||
$res['isSucess'] = false;
|
||
$res['report_no'] ='';
|
||
$res['reason'] =$reportNOInfo['msg'];
|
||
return $res;
|
||
}
|
||
$this->report_no = $reportNOInfo['report_no']; //报告编号
|
||
$this->create_reportNo_time = date('Y-m-d H:i:s');
|
||
$this->print_cpy_no =1;
|
||
$this->pay_type = 0; // 收费方式 1月结 2个人
|
||
$this->is_housing_fund = -1 ;//是否用公积金:-1未知 1是 0否
|
||
$this->borrower_name = "";
|
||
$this->e_case_code = $this->generateElectronCode( $this->quot_id, $reportNOInfo['second'] );
|
||
$this->borrower_idcard = 0;
|
||
$this->completion_time = time();
|
||
$this->order_src = 4;//业务来源,1:银行,2:中介,3:中诚致信,4:其他,5:中介(Q房东部),6:中介(Q房西部),7:中介(中原),8:中介(贝壳)9:中介(乐有家)
|
||
$this->offline_report_status = 3; //线下报告状态 0无 1待装订打印 2待盖章 3待取报告 4已取报告
|
||
$this->qrvalue = $data['qrvalue'];//保存二维码值
|
||
$this->qrurl = $data['qrurl'];//保存二维码地址
|
||
$this->producer_name = $data['user_name'];
|
||
$this->maker_id = $data['user_id'];
|
||
$this->valuation_time = $data['valuation_time']?? ($inquiryInfo['seal_time']?? date('Y-m-d'));
|
||
$this->maker_id = $data['user_id'];
|
||
$this->makertime = date('Y-m-d', time());
|
||
$this->report_dir = $inquiryInfo['report_dir'];//报告目录
|
||
$this->report_obj_type = $inquiryInfo['report_obj_type'];
|
||
$this->report_class = $inquiryInfo['report_class'];
|
||
$this->branchCom_id = $inquiryInfo['branchCom_id'];
|
||
$this->report_qrcode_unique_key = $data['report_qrcode_unique_key'];
|
||
|
||
|
||
$returnPriceModel = new ReturnPrice();
|
||
|
||
// 写入一条线下报告,并产生出 report id
|
||
if (!$this->isUpdate(false)->save())
|
||
throw new \Exception('report表插入异常');
|
||
|
||
// 创建一个reportDetail
|
||
foreach ($detail_list as $detail)
|
||
{
|
||
$reportDetail = new ReportDetail();
|
||
// $reportDetail->id = $detail['id'];
|
||
$reportDetail->report_id = $this->id;
|
||
$reportDetail->property_cert_info_id = $detail['id'];
|
||
$building_name = Db::table('pg_property_cert_info')->where(['id' => $detail['id']])->value('building_name');
|
||
$reportDetail->building_name = $building_name;
|
||
$reportDetail->property_cert = $detail['property_cert'];
|
||
$reportDetail->obligee = $detail['obligee'];
|
||
$reportDetail->cert_no = $detail['cert_no'];
|
||
$reportDetail->cert_type = $detail['cert_type'];
|
||
$reportDetail->land_location = $detail['land_location'];
|
||
$reportDetail->client = $data['client']??'';
|
||
|
||
if (!$reportDetail->isUpdate(false)->save())
|
||
throw new \Exception('report_detail表插入异常');
|
||
|
||
//更新询价详情表的年份
|
||
if(Db::name('property_cert_info')->where(['id'=>$detail['id']])->update(['year' => $detail['year'], 'update_time'=>date('Y-m-d H:i:s')])===false)
|
||
throw new \Exception('inquiry_detail表更新失败');
|
||
}
|
||
|
||
// 报告更新为已完成。 询价单状态,1:待回价,2:待业务确认,3:查勘待派单,4:查勘待完成,5:待生成报告,6:报告制作中,7:报告待审核,8:报告已完成,-1:已撤单(申请出报告前的撤单),-2:已撤单(申请出报告后的撤单)
|
||
if (Db::table('pg_inquiry')->where(['id' => $data['quot_id']])->update(['status' => 8, 'update_time'=>date('Y-m-d H:i:s')])===false)
|
||
throw new \Exception('inquiry表更新异常');
|
||
|
||
//写入消息
|
||
PublicMessage($data['quot_id'],6,9);
|
||
|
||
// 返回结果
|
||
$res['isSucess'] = true;
|
||
$res['report_no'] = $reportNOInfo['report_no'];
|
||
|
||
return $res;
|
||
}
|
||
});
|
||
|
||
return $resTran;
|
||
}
|
||
|
||
/**
|
||
* 生成电子提取码
|
||
* @param $quot_id 询价id
|
||
* @param $second 报告编号流水号
|
||
*/
|
||
public function generateElectronCode($quot_id, $second){
|
||
$inquiry = Db::name('inquiry')->field('type,bank_id,bank_name,eva_purpose,is_simple')->where('id', $quot_id)->find();
|
||
if($inquiry['is_simple'] == 1){ //简易
|
||
$e_case_code = '160101'.date('Y').$second.'1';
|
||
}
|
||
elseif($inquiry['bank_name'] == '中国建设银行' && $inquiry['type'] == 1 && ($inquiry['eva_purpose'] == '抵押贷款(云)' || $inquiry['eva_purpose'] == '抵押贷款(云)(续贷)' || $inquiry['eva_purpose'] == '抵押云贷(商务公寓)' || $inquiry['eva_purpose'] == '异地云贷(北京)')){
|
||
// $e_case_code = '160103'.date('Y').$second.'2';
|
||
$e_case_code = '160103' . date('Y') . $second;
|
||
}
|
||
elseif($inquiry['bank_name'] == '中国建设银行' && $inquiry['type'] == 1 && ($inquiry['eva_purpose'] == '二手房按揭贷款' || $inquiry['eva_purpose'] == '二手房按揭贷款(旧政策)'))
|
||
{
|
||
$e_case_code = '160101'.date('Y').$second.'2';
|
||
}
|
||
elseif ($inquiry['bank_name'] == '中国建设银行' && $inquiry['type'] == 2 && ($inquiry['eva_purpose'] == '抵押贷款(云)' || $inquiry['eva_purpose'] == '抵押贷款(云)(续贷)' || $inquiry['eva_purpose'] == '抵押云贷(商务公寓)' || $inquiry['eva_purpose'] == '异地云贷(北京)'))
|
||
{
|
||
// $e_case_code = '160103'.date('Y').$second.'3';
|
||
$e_case_code = '160103' . date('Y') . $second;
|
||
}
|
||
elseif ($inquiry['bank_name'] == '中国建设银行' && $inquiry['type'] == 2 && ($inquiry['eva_purpose'] == '二手房按揭贷款' || $inquiry['eva_purpose'] == '二手房按揭贷款(旧政策)'))
|
||
{
|
||
$e_case_code = '160101'.date('Y').$second.'3';
|
||
}
|
||
else{
|
||
$e_case_code = '16'.date('Y').$second;
|
||
}
|
||
|
||
return $e_case_code;
|
||
}
|
||
|
||
public function changeElectronCode($quot_id, $second, $appraisal_time){
|
||
$year = substr($appraisal_time ,0, 4);
|
||
$inquiry = Db::name('inquiry')->field('type,bank_id,bank_name,eva_purpose,is_simple')->where('id', $quot_id)->find();
|
||
if($inquiry['is_simple'] == 1){ //简易
|
||
$e_case_code = '160101' . $year . $second . '1';
|
||
}
|
||
elseif($inquiry['bank_name'] == '中国建设银行' && $inquiry['type'] == 1 && ($inquiry['eva_purpose'] == '抵押贷款(云)' || $inquiry['eva_purpose'] == '抵押贷款(云)(续贷)' || $inquiry['eva_purpose'] == '抵押云贷(商务公寓)' || $inquiry['eva_purpose'] == '异地云贷(北京)')){
|
||
// $e_case_code = '160103' . $year . $second . '2';
|
||
$e_case_code = '160103' . $year . $second;
|
||
}
|
||
elseif($inquiry['bank_name'] == '中国建设银行' && $inquiry['type'] == 1 && ($inquiry['eva_purpose'] == '二手房按揭贷款' || $inquiry['eva_purpose'] == '二手房按揭贷款(旧政策)'))
|
||
{
|
||
$e_case_code = '160101' . $year . $second . '2';
|
||
}
|
||
elseif ($inquiry['bank_name'] == '中国建设银行' && $inquiry['type'] == 2 && ($inquiry['eva_purpose'] == '抵押贷款(云)' || $inquiry['eva_purpose'] == '抵押贷款(云)(续贷)' || $inquiry['eva_purpose'] == '抵押云贷(商务公寓)' || $inquiry['eva_purpose'] == '异地云贷(北京)'))
|
||
{
|
||
// $e_case_code = '160103' . $year . $second . '3';
|
||
$e_case_code = '160103' . $year . $second;
|
||
}
|
||
elseif ($inquiry['bank_name'] == '中国建设银行' && $inquiry['type'] == 2 && ($inquiry['eva_purpose'] == '二手房按揭贷款' || $inquiry['eva_purpose'] == '二手房按揭贷款(旧政策)'))
|
||
{
|
||
$e_case_code = '160101' . $year . $second . '3';
|
||
}
|
||
else{
|
||
$e_case_code = '16' . $year . $second;
|
||
}
|
||
|
||
return $e_case_code;
|
||
}
|
||
|
||
/**
|
||
* 生成报告
|
||
*
|
||
* @return string
|
||
* @throws \think\db\exception\DataNotFoundException
|
||
* @throws \think\db\exception\ModelNotFoundException
|
||
* @throws \think\exception\DbException
|
||
*/
|
||
public function createReport($data)
|
||
{
|
||
return Db::transaction( function ()use ($data){
|
||
$this->quot_id = $data['quot_id'];
|
||
|
||
$inquiryInfo = Db::name('inquiry')->field("id,report_dir,report_obj_type,report_class,branchCom_id")
|
||
->where(['id'=> $data['quot_id']])->find();
|
||
|
||
$reportId = Db::name('report')->where(['quot_id'=> $data['quot_id']])->value('id');
|
||
if($reportId) $this->id = $reportId;
|
||
// $data['type] 1保存 2提交
|
||
$this->status = ($data['type'] == 1) ? 4 : 1; // $this->status状态 1待制作 2待审核 3完成 4草稿
|
||
$this->create_time = date('Y-m-d H:i:s', time());
|
||
if($data['type'] == 2){ //如果是提交
|
||
$report = $this->generateReportNo($data['quot_id'], $data['business_type']);
|
||
$this->report_no = $report['report_no']; //报告编号
|
||
$this->e_case_code = $this->generateElectronCode($data['quot_id'], $report['second']); //电子档提取码
|
||
$this->create_reportNo_time = date('Y-m-d H:i:s');
|
||
}
|
||
if (isset($data['print_cpy_no']) && strlen($data['print_cpy_no']))
|
||
$this->print_cpy_no = $data['print_cpy_no'];
|
||
if (isset($data['pay_type']) && strlen($data['pay_type']))
|
||
$this->pay_type = $data['pay_type'];
|
||
if (isset($data['is_housing_fund']) && strlen($data['is_housing_fund']))
|
||
$this->is_housing_fund = $data['is_housing_fund'];
|
||
if (isset($data['borrower_name']))
|
||
$this->borrower_name = $data['borrower_name'];
|
||
if (isset($data['borrower_idcard']))
|
||
$this->borrower_idcard = $data['borrower_idcard'];
|
||
$this->report_tmpl_id = Db::name('inquiry')->alias('i')->join('product p', 'i.product_id = p.id')->where(['i.id'=>$data['quot_id']])->value('report_template'); //模板id
|
||
if (isset($data['order_src']) && $data['order_src'] != null)
|
||
$this->order_src = $data['order_src'];
|
||
if (isset($data['business_type']) && $data['business_type'] != null)
|
||
$this->business_type = $data['business_type'];
|
||
if (isset($data['qrvalue']) && $data['qrvalue'] != null)
|
||
$this->qrvalue = $data['qrvalue'];
|
||
if (isset($data['qrurl']) && $data['qrurl'] != null)
|
||
$this->qrurl = $data['qrurl'];
|
||
if (isset($data['report_obj_type']) && $inquiryInfo['report_obj_type'] != null)
|
||
$this->report_obj_type = $inquiryInfo['report_obj_type'];
|
||
// if (isset($data['reportClass']) && $inquiryInfo['reportClass'] != null)
|
||
// $this->reportClass = $dinquiryInfoata['reportClass'];
|
||
if (isset($data['report_dir']) && $inquiryInfo['report_dir'] != null)
|
||
$this->report_dir = $inquiryInfo['report_dir'];
|
||
if (isset($data['branchCom_id']) && $inquiryInfo['branchCom_id'] != null)
|
||
$this->report_dir = $inquiryInfo['branchCom_id'];
|
||
|
||
if($reportId){ //更新操作
|
||
if (!$this->isUpdate(true)->save())
|
||
throw new \Exception('report表插入异常');
|
||
}else{ //添加操作
|
||
if (!$this->isUpdate(false)->save())
|
||
throw new \Exception('report表插入异常');
|
||
}
|
||
|
||
|
||
//report_detail
|
||
foreach ($data['details'] as $detail) {
|
||
$reportDetail = new ReportDetail();
|
||
$reportDetail->id = $detail['id'];
|
||
$reportDetail->report_id = $this->id;
|
||
$reportDetail->property_cert_info_id = $detail['property_cert_info_id'];
|
||
$building_name = Db::table('pg_property_cert_info')->where(['id' => $detail['property_cert_info_id']])->value('building_name');
|
||
$reportDetail->building_name = $building_name;
|
||
$reportDetail->year = $detail['year'];
|
||
$reportDetail->property_cert = $detail['property_cert'];
|
||
$reportDetail->obligee = $detail['obligee'];
|
||
$reportDetail->cert_no = $detail['cert_no'];
|
||
$reportDetail->cert_type = $detail['cert_type'];
|
||
$reportDetail->client = $detail['client'];
|
||
$reportDetail->parcel_no = $detail['parcel_no'];
|
||
$reportDetail->parcel_area = $detail['parcel_area'];
|
||
$reportDetail->parcel_usage = $detail['parcel_usage'];
|
||
$reportDetail->use_right_source = $detail['use_right_source'];
|
||
$reportDetail->completion_date = $detail['completion_date'];
|
||
$reportDetail->purchase_date = $detail['purchase_date'];
|
||
$reportDetail->reg_date = $detail['reg_date'];
|
||
$reportDetail->max_land_use_years = $detail['max_land_use_years'];
|
||
$reportDetail->land_use_start_time = $detail['land_use_start_time'];
|
||
$reportDetail->land_use_end_time = $detail['land_use_end_time'];
|
||
$reportDetail->area = $detail['area'];
|
||
$reportDetail->area_id = $detail['area_id'];
|
||
$reportDetail->land_location = $detail['land_location'];
|
||
$reportDetail->building_area = $detail['building_area'];
|
||
if (isset($detail['house_cert_img_ids']))
|
||
$reportDetail->house_cert_img_ids = implode(',', $detail['house_cert_img_ids']);
|
||
|
||
if($detail['id']){ //更新操作
|
||
if (!$reportDetail->isUpdate(true)->save())
|
||
throw new \Exception('report_detail表插入异常');
|
||
}else{ //添加操作
|
||
if (!$reportDetail->isUpdate(false)->save())
|
||
throw new \Exception('report_detail表插入异常');
|
||
}
|
||
|
||
//更新询价详情表的年份
|
||
// if(!Db::name('property_cert_info')->where(['id'=>$detail['property_cert_info_id']])->update(['year' => $detail['year'], 'update_time'=>date('Y-m-d H:i:s')]))
|
||
if(Db::name('property_cert_info')->where(['id'=>$detail['property_cert_info_id']])->update(['year' => $detail['year'], 'update_time'=>date('Y-m-d H:i:s')])===false)
|
||
throw new \Exception('inquiry_detail表更新失败');
|
||
}
|
||
if($data['type'] == 2){ //提交操作
|
||
//inquiry
|
||
// if (!Db::table('pg_inquiry')->where(['id' => $data['quot_id']])->update(['status' => 6, 'update_time'=>date('Y-m-d H:i:s')]))
|
||
if (Db::table('pg_inquiry')->where(['id' => $data['quot_id']])->update(['status' => 6, 'update_time'=>date('Y-m-d H:i:s')])===false)
|
||
throw new \Exception('inquiry表更新异常');
|
||
|
||
//写入消息
|
||
PublicMessage($data['quot_id'],6,9);
|
||
}
|
||
return true;
|
||
});
|
||
}
|
||
|
||
/**
|
||
* 创建空报告(用于取报告码用)
|
||
*
|
||
* @param [type] $data
|
||
* @return $res [
|
||
*
|
||
* 'result' boolean // 事务回调函数执行结果
|
||
* 'report_no' string // 报告号
|
||
* 'e_case_code' string // 电子档提取码
|
||
* ]
|
||
* @throws \think\db\exception\DataNotFoundException
|
||
* @throws \think\db\exception\ModelNotFoundException
|
||
* @throws \think\exception\DbException
|
||
*/
|
||
public function createNullReport( $data )
|
||
{
|
||
// 返回结果的定义
|
||
$res=[];
|
||
|
||
$res['isSucess'] = false;
|
||
$res['report_no'] ='';
|
||
|
||
$resTran = Db::transaction( function ()use ($data){
|
||
// 1、需要InquiryId
|
||
$this->quot_id = $data['quot_id'];
|
||
// 2、报告表里是否存在此InquiryId
|
||
$reportId = Db::name('report')->where(['quot_id'=> $data['quot_id']])->value('id');
|
||
// 如果存在,直接返回报告ID
|
||
if($reportId)
|
||
{
|
||
$res['isSucess'] = true;
|
||
$report_no = Db::name('report')->where(['id'=>$reportId])->value('report_no');
|
||
$res['report_no'] = $report_no;
|
||
|
||
return $res;
|
||
}
|
||
else // 如果不存在,生成一条空报告
|
||
{
|
||
|
||
$detail_list = Db::table('pg_property_cert_info')->where(['quot_id' => $this->quot_id ]);
|
||
if( count($detail_list) <= 0 )
|
||
throw new \Exception('pg_inquiry_detail表找不到inquiry_id为'.$this->quot_id.'的记录。');
|
||
|
||
$FINISH = 3;
|
||
$this->status = $FINISH; // status: 1待制作 2待审核 3完成 4草稿
|
||
$this->create_time = date('Y-m-d H:i:s', time());
|
||
$this->create_time = date('Y-m-d H:i:s', time());
|
||
$this->business_type = 3;//业务类型 1个贷 2对公 3 其他
|
||
$report = $this->generateReportNo($data['quot_id'], $this->business_type );
|
||
$this->report_no = $report['report_no']; //报告编号
|
||
$this->create_reportNo_time = date('Y-m-d H:i:s');
|
||
$this->print_cpy_no =1;
|
||
$this->pay_type = 0; // 收费方式 1月结 2个人
|
||
$this->is_housing_fund = -1 ;//是否用公积金:-1未知 1是 0否
|
||
$this->borrower_name = "";
|
||
$this->borrower_idcard = 0;
|
||
$this->order_src = 4;//业务来源,1:银行,2:中介,3:中诚致信,4:其他,5:中介(Q房东部),6:中介(Q房西部),7:中介(中原),8:中介(贝壳)9:中介(乐有家)
|
||
|
||
// 写入一条线下报告,并产生出 report id
|
||
if (!$this->isUpdate(false)->save())
|
||
throw new \Exception('report表插入异常');
|
||
|
||
// 创建一个reportDetail
|
||
foreach ($detail_list as $detail)
|
||
{
|
||
$reportDetail = new ReportDetail();
|
||
$reportDetail->id = $detail['id'];
|
||
$reportDetail->report_id = $this->id;
|
||
$reportDetail->property_cert_info_id = $detail['property_cert_info_id'];
|
||
$building_name = Db::table('pg_property_cert_info')->where(['id' => $detail['property_cert_info_id']])->value('building_name');
|
||
$reportDetail->building_name = $building_name;
|
||
$reportDetail->property_cert = $detail['property_cert'];
|
||
$reportDetail->obligee = $detail['obligee'];
|
||
$reportDetail->cert_no = $detail['cert_no'];
|
||
$reportDetail->cert_type = $detail['cert_type'];
|
||
$reportDetail->client = $detail['client'];
|
||
$reportDetail->parcel_no = $detail['parcel_no'];
|
||
$reportDetail->parcel_area = $detail['parcel_area'];
|
||
$reportDetail->parcel_usage = $detail['parcel_usage'];
|
||
$reportDetail->use_right_source = $detail['use_right_source'];
|
||
$reportDetail->completion_date = $detail['completion_date'];
|
||
$reportDetail->purchase_date = $detail['purchase_date'];
|
||
$reportDetail->reg_date = $detail['reg_date'];
|
||
$reportDetail->max_land_use_years = $detail['max_land_use_years'];
|
||
$reportDetail->land_use_start_time = $detail['land_use_start_time'];
|
||
$reportDetail->land_use_end_time = $detail['land_use_end_time'];
|
||
$reportDetail->area = $detail['area'];
|
||
$reportDetail->area_id = $detail['area_id'];
|
||
$reportDetail->land_location = $detail['land_location'];
|
||
$reportDetail->building_area = $detail['building_area'];
|
||
if (isset($detail['house_cert_img_ids']))
|
||
$reportDetail->house_cert_img_ids = implode(',', $detail['house_cert_img_ids']);
|
||
|
||
if($detail['id']){ //更新操作
|
||
if (!$reportDetail->isUpdate(true)->save())
|
||
throw new \Exception('report_detail表插入异常');
|
||
}else{ //添加操作
|
||
if (!$reportDetail->isUpdate(false)->save())
|
||
throw new \Exception('report_detail表插入异常');
|
||
}
|
||
|
||
//更新询价详情表的年份
|
||
if(Db::name('property_cert_info')->where(['id'=>$detail['property_cert_info_id']])->update(['year' => $detail['year'], 'update_time'=>date('Y-m-d H:i:s')])===false)
|
||
throw new \Exception('inquiry_detail表更新失败');
|
||
}
|
||
|
||
if (Db::table('pg_inquiry')->where(['id' => $data['quot_id']])->update(['status' => 6, 'update_time'=>date('Y-m-d H:i:s')])===false)
|
||
throw new \Exception('inquiry表更新异常');
|
||
|
||
//写入消息
|
||
PublicMessage($data['quot_id'],6,9);
|
||
|
||
// 返回结果
|
||
$res['isSucess'] = true;
|
||
$res['report_no'] = $this->report_no;
|
||
return $res;
|
||
}
|
||
});
|
||
|
||
$res['isSucess'] = $resTran;
|
||
return $res;
|
||
}
|
||
|
||
|
||
/**
|
||
* 我的报告
|
||
*
|
||
* @return array
|
||
* @throws \think\db\exception\DataNotFoundException
|
||
* @throws \think\db\exception\ModelNotFoundException
|
||
* @throws \think\exception\DbException
|
||
*/
|
||
public function getReportList($paginate, $data)
|
||
{
|
||
|
||
$map = $this->buildMapFromArray($data);
|
||
$res = Db::table('pg_inquiry')
|
||
->alias('a')
|
||
->join(['pg_property_cert_info' => 'b'], 'b.quot_id = a.id')
|
||
->join(['pg_report' => 'c'], 'a.id = c.quot_id')
|
||
->join(['pg_report_detail' => 'd'], 'c.id = d.report_id')
|
||
->join(['pg_refund' => 'f'], 'c.report_no = f.report_no', 'left')
|
||
|
||
->where($map)
|
||
->order('c.create_time', 'desc')
|
||
->group('a.order_no')
|
||
->field('a.id,a.order_no,c.id as reportid,c.report_no,c.e_case_code,a.type,b.city,b.city,b.property_full_name,a.is_multiple,a.status,b.size,a.bank_name,a.bank_sub_name,a.create_time,a.user_name,c.create_time as report_completion_time,c.print_cpy_no,f.refund_status,c.print_cpy_no,c.offline_report_status,c.producer_name,d.area,d.area_id')
|
||
->order('a.create_time', 'desc')
|
||
->paginate($paginate)->each(function ($item,$key){
|
||
//todo 加入回价信息
|
||
$item['full_estate_name_info'] = Db::name('property_cert_info')
|
||
->where('quot_id', $item['id'])
|
||
->field('id,property_full_name')
|
||
->select();
|
||
$item['eva_unit_price'] = 0;
|
||
$item['eva_total_value'] = 0;
|
||
$item['eva_net_value'] = 0;
|
||
foreach ($item['full_estate_name_info'] as $key=>$value) {
|
||
$return_price_res = Db::name('return_price')
|
||
->where('property_cert_info_id='.$value['id'])
|
||
->field('eva_unit_price,eva_total_value,eva_net_value')
|
||
->order('create_time', 'desc')
|
||
->find();
|
||
$item['eva_unit_price'] = $return_price_res['eva_unit_price'];
|
||
$item['eva_total_value'] += $return_price_res['eva_total_value'];
|
||
$item['eva_net_value'] += $return_price_res['eva_net_value'];
|
||
}
|
||
$item['area'] = Db::name('report_detail')->where('report_id', $item['reportid'])->field('area_id,area')->select();
|
||
// $full_estate_name_info = Db::table('pg_property_cert_info')
|
||
// ->where('quot_id', $item['id'])
|
||
// ->column('property_full_name');
|
||
// $item['full_estate_name_info'] = array('show' => !empty($full_estate_name_info) ? $full_estate_name_info[0] : '', 'property_full_name' => $full_estate_name_info);
|
||
|
||
$item['status_str'] = getDictionaryName('ORDER_STATUS', $item['status']);
|
||
$item['is_multi_str'] = getDictionaryName('INQUIRY_NUMBER', $item['is_multiple']);
|
||
$item['type_str'] = getDictionaryName('BUSINESS_TYPE', $item['type']);
|
||
$item['offline_report_status_str'] = getDictionaryName('OFFLINE_REPORT_STATUS', $item['offline_report_status']);
|
||
|
||
$item['bank_name'] = $item['bank_name'] . $item['bank_sub_name'];
|
||
unset($item['bank_sub_name']);
|
||
return $item;
|
||
})->toArray();
|
||
return $res;
|
||
}
|
||
|
||
/**
|
||
* 从数组构造查询条件
|
||
*
|
||
* @param array $data
|
||
* @return array
|
||
*/
|
||
public function buildMapFromArray($data = [])
|
||
{
|
||
//显示报告制作中/报告待审核/报告已完成
|
||
$map[] = ['a.status', 'in', '6,7,8'];
|
||
//todo 加上userId条件
|
||
if (isset($data['user_name']) && !empty($data['user_name'])){
|
||
$map[] = ['a.user_name','like','%'.trim($data['user_name']).'%'];
|
||
}
|
||
if (isset($data['type']) && !empty($data['type'])){
|
||
$map[] = ['a.type', '=',$data['type']];
|
||
}
|
||
if (isset($data['status']) && !empty($data['status'])){
|
||
$map[] = ['a.status', '=',$data['status']];
|
||
}
|
||
if (isset($data['is_multiple']) && ($data['is_multiple'] === 0 || $data['is_multiple'] === 1)){
|
||
$map[] = ['a.is_multiple', '=', $data['is_multiple']];
|
||
}
|
||
if (!empty($data['start_time']) || !empty($data['end_time'])) {
|
||
$map[] = getQueryDate('c.create_time', $data['start_time'], $data['end_time']);
|
||
}
|
||
if (isset($data['search_text']) && !empty($data['search_text'])){
|
||
$map[] = ['b.property_full_name|a.order_no','like', '%'.trim($data['search_text']).'%'];
|
||
}
|
||
|
||
if (isset($data['refund_status']) && !empty($data['refund_status'])){
|
||
$map[] = ['f.refund_status', '=', $data['refund_status']];
|
||
}
|
||
|
||
if (isset($data['user_id']) && !empty($data['user_id'])){ //权限
|
||
$map[] = ['a.user_id','in',$data['user_id']];
|
||
}
|
||
if (isset($data['city_id']) && !empty($data['city_id'])){ //城市
|
||
$map[] = ['b.city_id','=',$data['city_id']];
|
||
}
|
||
if (isset($data['area_id']) && !empty($data['area_id'])){ //小片区
|
||
$map[] = ['d.area_id','in',$data['area_id']];
|
||
}
|
||
|
||
return $map;
|
||
}
|
||
|
||
/**
|
||
* 报告详情
|
||
*
|
||
* @return array
|
||
* @throws \think\db\exception\DataNotFoundException
|
||
* @throws \think\db\exception\ModelNotFoundException
|
||
* @throws \think\exception\DbException
|
||
*/
|
||
public function getReportDetail($data)
|
||
{
|
||
|
||
$subsql = Db::table('pg_return_price')
|
||
->field('appraiser_name,property_cert_info_id')->group('property_cert_info_id')->order('property_cert_info_id', 'desc')->buildSql();
|
||
$result = Db::name('inquiry')->alias('a')
|
||
->join(['pg_property_cert_info' => 'b'], 'b.quot_id = a.id')
|
||
->join([$subsql => 'd'], 'b.id = d.property_cert_info_id', 'left')
|
||
->field('a.id,a.order_no,a.bank_name,a.bank_branch_name,a.bank_sub_name,a.bank_customer_mgr_name,a.type,a.user_name,a.eva_purpose,d.appraiser_name')
|
||
->where(['a.id' => $data['id']])
|
||
->find();
|
||
|
||
$estate_info = Db::table('pg_property_cert_info')
|
||
->field('id,property_full_name as building_name')
|
||
->where(['quot_id' => $data['id']])
|
||
->order('id', 'desc')
|
||
->group('id')
|
||
->select();
|
||
$result['estata_number'] = count($estate_info);//物业数量
|
||
|
||
if($estate_info) $property_cert_info_id = $estate_info[0]['id'];
|
||
$result['estate_info'] = $estate_info;
|
||
|
||
|
||
$common = new CommonService();
|
||
|
||
$property_cert_info_id = '';
|
||
if (!empty($data['property_cert_info_id'])) {
|
||
$property_cert_info_id = $data['property_cert_info_id'];
|
||
} else {
|
||
$property_cert_info_id = $estate_info ? $estate_info[0]['id'] : '';
|
||
}
|
||
|
||
//基本信息
|
||
$result['basic_info']['frist'] = $common->getInquiryDetail($property_cert_info_id);
|
||
$result['basic_info']['second'] = $common->getReport($property_cert_info_id);
|
||
$result['basic_info']['third'] = $common->getReturnPrice($property_cert_info_id);
|
||
$result['survey_info'] = $common->getSurveyDetail($property_cert_info_id,$result['type']);//查勘信息
|
||
|
||
return $result;
|
||
}
|
||
} |