632 lines
29 KiB
PHP
632 lines
29 KiB
PHP
<?php
|
|
|
|
|
|
namespace app\model;
|
|
|
|
|
|
use app\admin\service\CommonService;
|
|
use app\migrate\controller\Migrates;
|
|
use think\Db;
|
|
use think\db\Where;
|
|
|
|
class Inquiry extends Base
|
|
{
|
|
|
|
const STATUS_MAP = [
|
|
self::STATUS_CANCELED => '已撤单',
|
|
self::STATUS_CREATED => '待回价',
|
|
self::STATUS_PRICE_GIVEN => '已回价',
|
|
self::STATUS_ASK_SURVEY => '待派单',
|
|
self::STATUS_SURVEY_RETURNED => '查勘退回',
|
|
self::STATUS_SURVEY_ASSIGNED => '已派单',
|
|
self::STATUS_SURVEY_COMPLETED => '查勘完成',
|
|
self::STATUS_ASK_REPORT => '待制作',
|
|
self::STATUS_REPORT_SUBMITTED => '待审核',
|
|
self::STATUS_REPORT_CHECKED => '审核通过',
|
|
self::STATUS_MONEY_CHECKED => '已确认',
|
|
self::STATUS_MONEY_RECEIVED => '已收费',
|
|
];
|
|
|
|
const INQUERY_NUMBER_RESIDENCE_PREFIX = "GZ01";// 询价编号前缀-住宅
|
|
const INQUERY_NUMBER_BUSINESS_PREFIX = "GZ02";// 询价编号前缀-商业
|
|
|
|
const STATUS_CREATED = 1;
|
|
const STATUS_PRICE_GIVEN = 2;
|
|
|
|
const STATUS_ASK_SURVEY = 3;
|
|
const STATUS_SURVEY_RETURNED = 4;
|
|
const STATUS_SURVEY_ASSIGNED = 5;
|
|
const STATUS_SURVEY_COMPLETED = 6;
|
|
const STATUS_ASK_REPORT = 7;
|
|
const STATUS_REPORT_SUBMITTED = 8;
|
|
const STATUS_REPORT_CHECKED = 9;
|
|
const STATUS_MONEY_CHECKED = 10;
|
|
const STATUS_MONEY_RECEIVED = 11;
|
|
const STATUS_CANCELED = -1;
|
|
|
|
const STATUS_MODIFY_PRICE_MAP = [
|
|
self::STATUS_NO_MODIFY => '无需调价',
|
|
self::STATUS_ASK_MODIFY => '待调价',
|
|
self::STATUS_MODIFY_COMPLETED => '已调价',
|
|
];
|
|
const STATUS_NO_MODIFY = 0;
|
|
const STATUS_ASK_MODIFY = 1;
|
|
const STATUS_MODIFY_COMPLETED = 2;
|
|
|
|
const TYPE_MAP = [
|
|
self::TYPE_RESIDENTIAL => '住宅询价',
|
|
self::TYPE_BUSINESS => '商业询价',
|
|
];
|
|
const TYPE_RESIDENTIAL = 1;
|
|
const TYPE_BUSINESS = 2;
|
|
|
|
public function inquiryDetails()
|
|
{
|
|
return $this->hasMany(Property_cert_info::class);
|
|
}
|
|
|
|
/**
|
|
* 产生唯一订单号
|
|
*
|
|
* @param $type
|
|
* @return string
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
* @throws \think\exception\DbException
|
|
*/
|
|
public function generateInquiryNo_old($type)
|
|
{
|
|
if ($type == self::TYPE_RESIDENTIAL){
|
|
$inquiryNo = self::INQUERY_NUMBER_RESIDENCE_PREFIX.date('Ymd');
|
|
}else{
|
|
$inquiryNo = self::INQUERY_NUMBER_BUSINESS_PREFIX.date('Ymd');
|
|
}
|
|
$map[] = ['order_no', 'like', $inquiryNo."%"];
|
|
$max = $this->where($map)->order('id','desc')->find();
|
|
if (!$max){
|
|
$inquiryNo .= '00001';
|
|
}else{
|
|
$number = substr($max['order_no'],strlen($max['order_no'])-5, 5);
|
|
$number += 1;
|
|
$inquiryNo .= sprintf('%05d',$number);
|
|
}
|
|
return $inquiryNo;
|
|
}
|
|
|
|
|
|
/**
|
|
* 生成询价单号
|
|
* @author cavan
|
|
* @param $branchComID
|
|
* @return mixed
|
|
*/
|
|
public function generateInquiryNo( $branchComID ):string{
|
|
// var_dump('branchComID:',$branchComID);
|
|
$inquiryModel = new Inquiry();
|
|
/* $res = $inquiryModel->alias('i')
|
|
->where('i.id',$inquiryId)
|
|
->leftJoin('branchcom_config b','i.branchCom_id = b.id')
|
|
->find();*/
|
|
$G_COMPANY_SN = env('service.estimate_short_name'); // 公司简称
|
|
$res = Db::name('branchcom_config')->where('id',$branchComID)->find();
|
|
if(empty($res)){
|
|
return "";
|
|
}
|
|
|
|
$shortName = $res['short_name'];
|
|
// $year = date("Y",time());
|
|
// $m = date("m",time());
|
|
|
|
// $inquiry_last_order_no = Db::name('inquiry')->where('order_no', 'like', $G_COMPANY_SN.$shortName.$year.$m."%")->order('order_no desc')->value('order_no');
|
|
// $last_number_str = mb_substr($inquiry_last_order_no, -5);
|
|
// $now_number = intval($last_number_str) + 1;
|
|
// $estimateNumber = str_pad($now_number, 5, '0', STR_PAD_LEFT);
|
|
// return( $G_COMPANY_SN.$shortName.$year.$m.$estimateNumber);
|
|
|
|
$date = date("Ymd",time());
|
|
$inquiry_last_order_no = Db::name('inquiry')->where('order_no', 'like', $G_COMPANY_SN.$shortName.$date."%")->order('order_no desc')->value('order_no');
|
|
$last_number_str = mb_substr($inquiry_last_order_no, -5);
|
|
$now_number = intval($last_number_str) + 1;
|
|
$estimateNumber = str_pad($now_number, 5, '0', STR_PAD_LEFT);
|
|
return( $G_COMPANY_SN.$shortName.$date.$estimateNumber);
|
|
}
|
|
|
|
/**
|
|
* 从数组构造查询条件
|
|
* 用于询价列表api
|
|
*
|
|
* @param array $data
|
|
* @return array
|
|
*/
|
|
public function buildMapFromArray($data = [])
|
|
{
|
|
$map = [];
|
|
// if (isset($data['type']) && !empty($data['type'])) { //业务类型
|
|
// $map[] = ['a.type', '=', $data['type']];
|
|
// } else {
|
|
// $map[] = ['a.type', 'in', '1,2'];
|
|
// }
|
|
|
|
if (isset($data['status']) && !empty($data['status'])) { //订单状态
|
|
$map[] = ['a.status', '=', $data['status']];
|
|
} else {
|
|
$map[] = ['a.status', 'in', [-3,-2,-1,1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], '_logic' => 'or'];
|
|
}
|
|
|
|
$map[] = ['a.is_simple', '=', 0];
|
|
|
|
if (isset($data['start_time']) && isset($data['end_time']) && ($data['start_time'] || $data['end_time'])){
|
|
// $map[] = getQueryDate('a.create_time', $data['start_time'], $data['end_time']);
|
|
$map[] = ['a.create_time', '>=', $data['start_time']." 00:00:00"];
|
|
$map[] = ['a.create_time', '<=', $data['end_time']." 23:59:59"];
|
|
} elseif(empty($data['start_time']) &&
|
|
empty($data['end_time']) &&
|
|
empty($data['bank_id']) &&
|
|
empty($data['status']) &&
|
|
empty($data['type']) &&
|
|
empty($data['is_multiple']) &&
|
|
empty($data['eva_purpose']) &&
|
|
empty($data['search_text']) &&
|
|
empty($data['user_name']) &&
|
|
empty($data['response_username']) &&
|
|
empty($data['user_id']) &&
|
|
empty($data['start_time_length']) &&
|
|
empty($data['end_time_length'])) {
|
|
$map[] = ['a.create_time', '>=', date('Y-m-d',strtotime("-90 day"))." 00:00:00"];
|
|
$map[] = ['a.create_time', '<=', date('Y-m-d')." 23:59:59"];
|
|
}
|
|
|
|
if (isset($data['bank_id']) && !empty($data['bank_id'])) { //银行
|
|
$map[] = ['a.bank_id','=',$data['bank_id']];
|
|
}
|
|
|
|
if (isset($data['is_multiple']) && ($data['is_multiple'] === 0 || $data['is_multiple'] === 1)){ //询价套数
|
|
$map[] = ['a.is_multiple', '=', $data['is_multiple']];
|
|
}
|
|
|
|
if (isset($data['eva_purpose']) && !empty($data['eva_purpose'])){ //询价目的
|
|
$map[] = ['a.eva_purpose','like','%'.trim($data['eva_purpose']).'%'];
|
|
}
|
|
|
|
if (isset($data['search_text']) && !empty($data['search_text'])){ //物业名称
|
|
$map[] = ['b.property_full_name|a.order_no|a.bank_name|a.estimated_no','like','%'.trim($data['search_text']).'%'];
|
|
}
|
|
|
|
if (isset($data['user_name']) && !empty($data['user_name'])){ //业务员
|
|
$map[] = ['a.buss_username','like','%'.trim($data['user_name']).'%'];
|
|
}
|
|
|
|
if (isset($data['response_username']) && !empty($data['response_username'])){ //回价员
|
|
$map[] = ['b.appraiser_name','like','%'.trim($data['response_username']).'%'];
|
|
}
|
|
|
|
//时间长度
|
|
if (isset($data['start_time_length']) && isset($data['end_time_length']) && ($data['start_time_length'] || $data['end_time_length'])){
|
|
$map[] = getQuery('a.eva_detail_time_long', $data['start_time_length'], $data['end_time_length']);
|
|
}
|
|
|
|
$map[] = ['a.is_auto', '=', 0];
|
|
|
|
if (isset($data['user_id']) && !empty($data['user_id'])) { //权限
|
|
$map[] = ['a.user_id|a.buss_user_id', 'in', $data['user_id']];
|
|
}
|
|
|
|
if (!empty($data['usage'])) {
|
|
$map[] = ['b.usage', '=', $data['usage']];
|
|
}
|
|
|
|
return $map;
|
|
}
|
|
|
|
public function getInquiryPaginate($paginate,$data = [])
|
|
{
|
|
$map = $this->buildMapFromArray($data);
|
|
$attachmentModel = new Attachment();
|
|
$biz_status_text = ['10' => '待回价', '20' => '已回价', '30' => '已发送预估单', '40' => '申请出具报告', '50' => '已发送报告'];
|
|
$resultData = Db::name('inquiry')->alias("a")
|
|
->leftJoin('pg_property_cert_info b','b.quot_id=a.id')
|
|
->field('
|
|
a.id,
|
|
a.order_no,
|
|
a.type,
|
|
a.is_multiple,
|
|
a.status,
|
|
a.bank_name,
|
|
a.bank_branch_name,
|
|
a.bank_sub_name,
|
|
a.bank_customer_mgr_name,
|
|
a.create_time,
|
|
a.report_class as reportClass,
|
|
a.report_obj_type as reportObjType,
|
|
a.report_dir ,
|
|
a.branchCom_id ,
|
|
a.buss_username,
|
|
a.estimated_no,
|
|
a.eva_purpose,
|
|
a.eva_detail_time_long,
|
|
a.business_no,
|
|
a.contract_no,
|
|
a.loan_type,
|
|
a.return_price_attachments,
|
|
b.id as did,
|
|
b.quot_id,
|
|
b.city,
|
|
b.city_id,
|
|
b.property_full_name,
|
|
b.size,
|
|
b.reg_price,
|
|
b.year,
|
|
b.appraiser_name AS response_username,
|
|
b.appraiser_id,
|
|
b.risk_grade,
|
|
b.r_create_time AS response_time,
|
|
b.eva_unit_price,
|
|
b.eva_total_value,
|
|
b.eva_net_value,
|
|
b.eva_net_value2,
|
|
b.total_taxes1,
|
|
b.total_taxes2,
|
|
b.internal_remarks,
|
|
b.rid,
|
|
a.biz_status,
|
|
a.return_price_status
|
|
')
|
|
->where($map)
|
|
->group('a.id')
|
|
->order('a.id','desc')
|
|
->paginate($paginate)
|
|
->each(function ($item,$key) use ($attachmentModel, $biz_status_text){
|
|
$item['return_price_attachments_list'] = !empty($item['return_price_attachments']) ? $attachmentModel->getUrls($item['return_price_attachments']) : [];
|
|
$item['type_str'] = getDictionaryName('BUSINESS_TYPE', $item['type']);
|
|
$item['is_multi_str'] = getDictionaryName('INQUIRY_NUMBER', $item['is_multiple']);
|
|
$item['status_str'] = getDictionaryName('ORDER_STATUS', $item['status']);
|
|
$item['business_no'] = $item['business_no'];
|
|
//回价时间
|
|
$item['response_time'] = $item['response_time'] ? date('m-d H:i', $item['response_time']) : '';
|
|
//询价时间
|
|
$item['create_time'] = date( 'm-d H:i',strtotime($item['create_time']));
|
|
$item['estimated_no'] = $item['estimated_no'];
|
|
$item['inquiry_details'] = Db::name('property_cert_info')
|
|
->where('quot_id='.$item['id'])
|
|
->field('id,city,property_full_name,size,ownership_type,usage,eva_unit_price,eva_total_value,eva_net_value,eva_net_value2,total_taxes1,
|
|
total_taxes2,cert_usage,attachments')
|
|
->select();
|
|
if (count($item['inquiry_details'])>0) {
|
|
foreach ($item['inquiry_details'] as $key => $value) {
|
|
$external_remarks = '';
|
|
$return_price_info = Db::name('return_price')->where("property_cert_info_id", $value['id'])
|
|
->field('*')
|
|
->order('create_time desc')
|
|
->find();
|
|
if (!empty($return_price_info)) {
|
|
$external_remarks = $return_price_info['external_remarks'];
|
|
}
|
|
$item['inquiry_details'][$key]['external_remarks'] = $external_remarks;
|
|
$item['inquiry_details'][$key]['usage'] = getDictionaryName('HOUSE_USAGE', $value['usage']);
|
|
$item['inquiry_details'][$key]['attachments_list'] = !empty($value['attachments']) ? $attachmentModel->getUrls($value['attachments']) : [];
|
|
}
|
|
}
|
|
|
|
if (count($item['inquiry_details'])>1) {
|
|
$item['property_full_name'] = implode(',', array_column($item['inquiry_details'], 'property_full_name'));
|
|
$item['size'] = implode('/', array_column($item['inquiry_details'], 'size'));
|
|
$item['eva_unit_price'] = implode('/', array_column($item['inquiry_details'], 'eva_unit_price'));
|
|
$item['eva_total_value'] = implode('/', array_column($item['inquiry_details'], 'eva_total_value'));
|
|
$item['eva_net_value'] = implode('/', array_column($item['inquiry_details'], 'eva_net_value'));
|
|
$item['eva_net_value2'] = implode('/', array_column($item['inquiry_details'], 'eva_net_value2'));
|
|
$item['total_taxes1'] = implode('/', array_column($item['inquiry_details'], 'total_taxes1'));
|
|
$item['total_taxes2'] = implode('/', array_column($item['inquiry_details'], 'total_taxes2'));
|
|
$item['usage'] = implode('/', array_column($item['inquiry_details'], 'usage'));
|
|
} elseif(count($item['inquiry_details']) == 1) {
|
|
$item['property_full_name'] = $item['inquiry_details'][0]['property_full_name'];
|
|
$item['size'] = $item['inquiry_details'][0]['size'];
|
|
$item['eva_unit_price'] = $item['inquiry_details'][0]['eva_unit_price'];
|
|
$item['eva_total_value'] = $item['inquiry_details'][0]['eva_total_value'];
|
|
$item['eva_net_value'] = $item['inquiry_details'][0]['eva_net_value'];
|
|
$item['eva_net_value2'] = $item['inquiry_details'][0]['eva_net_value2'];
|
|
$item['total_taxes1'] = $item['inquiry_details'][0]['total_taxes1'];
|
|
$item['total_taxes2'] = $item['inquiry_details'][0]['total_taxes2'];
|
|
$item['usage'] = $item['inquiry_details'][0]['usage'];
|
|
}
|
|
// 报告已完成的报告制作人
|
|
$producer_name = Db::name('report')->where('quot_id='.$item['id'])->where('status=3')->value('producer_name');
|
|
$item['producer_name'] = !empty($producer_name) ? $producer_name : NULL;
|
|
|
|
if ($item['bank_name'] == '中国银行' && $item['loan_type'] == '二手按揭' && !empty($item['business_no'])) {
|
|
$item['biz_status_text'] = $biz_status_text[$item['biz_status']] ?? '';
|
|
}
|
|
|
|
return $item;
|
|
})
|
|
->toArray();
|
|
return $resultData;
|
|
}
|
|
|
|
|
|
//简易报告列表
|
|
public function simpleInquiryList($paginate, $map)
|
|
{
|
|
$subsql = Db::table('pg_return_price')->field('property_cert_info_id,create_time,eva_unit_price,eva_total_value,eva_net_value,eva_net_value2,appraiser_name,create_time,total_taxes1,total_taxes2')
|
|
->group('property_cert_info_id')->order('property_cert_info_id', 'desc')->buildSql();
|
|
$inquiries = Db::name('inquiry')->alias('i')
|
|
->join(['pg_property_cert_info' => 'd'], 'd.quot_id = i.id')
|
|
->join([$subsql => 'p'], 'd.id = p.property_cert_info_id', 'left')
|
|
->join('pg_report r', 'i.id = r.quot_id', 'left')
|
|
->where($map)
|
|
->group('i.order_no')
|
|
->field('i.id,i.order_no,i.type,i.status,i.client_name,i.create_time,i.user_name,p.eva_unit_price,p.eva_total_value,p.create_time as response_time, p.appraiser_name as response_username,r.producer_name')
|
|
->order('i.create_time', 'desc')
|
|
->paginate($paginate)
|
|
->each(function ($item){
|
|
|
|
$item['type_str'] = getDictionaryName('BUSINESS_TYPE', $item['type']);
|
|
$item['status_str'] = getDictionaryName('ORDER_STATUS', $item['status']);
|
|
|
|
$item['inquiry_details'] = Db::name('property_cert_info')
|
|
->alias('a')
|
|
->join(['pg_return_price' => 'b'], 'b.property_cert_info_id = a.id','left')
|
|
->whereIn('a.quot_id', $item['id'])
|
|
->field(['a.id','a.property_full_name','a.size','a.remark'])
|
|
->group('a.id')
|
|
->order('b.create_time', 'desc')
|
|
->select();
|
|
$item['size'] = implode('/', array_column($item['inquiry_details'], 'size'));
|
|
|
|
$item['response_time'] = $item['response_time'] ? date('Y-m-d H:i:s', $item['response_time']) : '';
|
|
|
|
return $item;
|
|
|
|
})->toArray();
|
|
return $inquiries;
|
|
}
|
|
|
|
/**
|
|
* 正常调价列表
|
|
*
|
|
* @param $userId
|
|
* @param array $data
|
|
* @return \think\Paginator
|
|
* @throws \think\exception\DbException
|
|
*/
|
|
public function getNormalModifyList($userId,$paginate,$data = [])
|
|
{
|
|
$map = $this->normalModifyWhere($userId, $data);
|
|
$inquiries = Db::table('pg_inquiry')->alias('a')
|
|
->join(['pg_property_cert_info' => 'b'], 'b.quot_id = a.id')
|
|
->where($map)
|
|
->group('b.id')
|
|
->field('a.id,a.order_no,a.status,b.city,a.type,a.is_multiple,a.eva_purpose,b.adjust_status,size,a.bank_name,a.bank_sub_name,a.create_time,a.user_name,b.evaluated_unit_price,b.price_adjust_time,b.adjust_reason,b.reg_price,b.property_full_name,b.id as property_cert_info_id')
|
|
->order('a.create_time', 'asc')
|
|
->paginate($paginate)->each(function ($item, $key){
|
|
//todo 加入回价信息
|
|
$return_price_data = Db::name('return_price')
|
|
->where(['property_cert_info_id' => $item['property_cert_info_id']])
|
|
->field('eva_unit_price,eva_total_value,appraiser_name as response_username,create_time as response_time,eva_net_value,eva_net_value2')
|
|
->order('id', 'desc')
|
|
->find();
|
|
$item['eva_unit_price'] = $return_price_data['eva_unit_price'];
|
|
$item['eva_total_value'] = $return_price_data['eva_total_value'];
|
|
$item['eva_net_value'] = $return_price_data['eva_net_value'];
|
|
$item['eva_net_value2'] = $return_price_data['eva_net_value2'];
|
|
$item['response_username'] = $return_price_data['response_username'];
|
|
$item['modify_status_str'] = getDictionaryName('MODIFY_STATUS', $item['adjust_status']);
|
|
$item['is_multi_str'] = getDictionaryName('INQUIRY_NUMBER', $item['is_multiple']);
|
|
$item['type_str'] = getDictionaryName('BUSINESS_TYPE', $item['type']);
|
|
$item['status_name'] = ($item['status'] == 1)?"未回价":"已回价";
|
|
$item['response_time'] = !empty($return_price_data['response_time']) ? date('Y-m-d H:i:s', $return_price_data['response_time']) : '';
|
|
$item['bank_name'] = $item['bank_name'] . $item['bank_sub_name'];
|
|
$item['create_time'] = date('m-d H:i', strtotime($item['create_time']));
|
|
unset($item['bank_sub_name']);
|
|
return $item;
|
|
})->toArray();
|
|
return $inquiries;
|
|
}
|
|
|
|
/**
|
|
* 写入合同号
|
|
*
|
|
* @param [type] $inquiry_id
|
|
* @return void
|
|
*/
|
|
public function updateContractNo( $inquiry_id, $contract_no )
|
|
{
|
|
// 定义要更新的数据
|
|
$data = [
|
|
'contract_no' => $contract_no, // 将这里的字符串替换为实际的合同号
|
|
];
|
|
|
|
// 执行更新操作
|
|
$result = Db::name('Inquiry')->where('id', $inquiry_id )->update($data); // 假设你要更新id为1的记录
|
|
}
|
|
|
|
/**
|
|
* 正常调价列表查询条件
|
|
*
|
|
* @param array $data
|
|
* @return array
|
|
*/
|
|
public function normalModifyWhere($userId, $data = [])
|
|
{
|
|
$map = [];
|
|
//todo 加上userId条件
|
|
if (isset($data['user_name']) && !empty($data['user_name'])){ //业务员
|
|
$map[] = ['a.user_name','like','%'.trim($data['user_name']).'%'];
|
|
}
|
|
if (isset($data['adjust_status']) && !empty($data['adjust_status'])){ //调价状态
|
|
$map[] = ['b.adjust_status','=',trim($data['adjust_status'])];
|
|
}else{
|
|
$map[] = ['b.adjust_status', 'in', [1,2]];
|
|
}
|
|
|
|
if (isset($data['type']) && !empty($data['type'])){ //业务类型
|
|
$map[] = ['a.type', '=',$data['type']];
|
|
}
|
|
if (isset($data['is_multiple']) && strlen($data['is_multiple'])){
|
|
$map[] = ['a.is_multiple', '=',$data['is_multiple']];
|
|
}
|
|
if (!empty($data['start_time']) || !empty($data['end_time'])) {
|
|
$map[] = getQueryDate('b.price_adjust_time', $data['start_time'], $data['end_time']);
|
|
}
|
|
if (isset($data['search_text']) && !empty($data['search_text'])){
|
|
$map[] = ['b.property_full_name|a.order_no|a.bank_name|a.estimated_no', 'like', '%'.trim($data['search_text']).'%'];
|
|
}
|
|
|
|
if (isset($data['user_id']) && !empty($data['user_id'])){
|
|
$map[] = ['a.user_id','in',$data['user_id']];
|
|
}
|
|
|
|
if (isset($data['variance_ratio']) && !empty($data['variance_ratio'])){
|
|
if(isset($data['diff_flag']) && $data['diff_flag'] == 1){
|
|
$map[] = ['b.variance_ratio','<=',$data['variance_ratio']];
|
|
}else{
|
|
$map[] = ['b.variance_ratio','>',$data['variance_ratio']];
|
|
}
|
|
}
|
|
|
|
//银行名称
|
|
if (isset($data['bank_id']) && !empty($data['bank_id'])){
|
|
$map[] = ['a.bank_id','=',$data['bank_id']];
|
|
}
|
|
//评估目的
|
|
if (isset($data['product_id']) && !empty($data['product_id'])){
|
|
$map[] = ['a.product_id','=',$data['product_id']];
|
|
}
|
|
|
|
// 自动估价
|
|
if (isset($data['is_auto']) && !empty($data['is_auto'])){
|
|
$map[] = ['a.is_auto','=',$data['is_auto']];
|
|
}
|
|
|
|
//end
|
|
return $map;
|
|
}
|
|
|
|
/**
|
|
* 正常调价详情
|
|
*
|
|
* @return array
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
* @throws \think\exception\DbException
|
|
*/
|
|
public function getNormalModifyDetail($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,b.adjust_status,b.property_full_name')
|
|
->where(['a.id' => $data['id'], 'b.id'=> $data['property_cert_info_id']])
|
|
->find();
|
|
|
|
$estate_info = Db::table('pg_property_cert_info')
|
|
->field('id as property_cert_info_id,building_name')
|
|
->where(['quot_id' => $data['id']])
|
|
->order('id', 'desc')
|
|
->select();
|
|
$result['estata_number'] = count($estate_info);//物业数量
|
|
|
|
$property_cert_info_id = $data['property_cert_info_id'];
|
|
|
|
$common = new CommonService();
|
|
$result['basic_info'] = $property_cert_info_id ? $common->getInquiryDetail($property_cert_info_id) : [];//基本信息
|
|
|
|
$modify_front = $modify_after = [];
|
|
//分为调价前和调价后,若评估未调价,不显示调价后数据,若评估已调价,显示调价后的数据。
|
|
if ($result['adjust_status'] == 1) {
|
|
$res = 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,loan_ratio,gross_value,eva_net_value,eva_net_value2')
|
|
->where(['property_cert_info_id' => $property_cert_info_id])->order('create_time', 'desc')->limit(2)->select();
|
|
if (count($res) > 1) {
|
|
$res[0]['is_isset'] = $res[1]['is_isset'] = 1;
|
|
$modify_front = $res[1];
|
|
$modify_after = $res[0];
|
|
} else {
|
|
$res[1]['is_isset'] = 1;
|
|
$modify_front = $res[1];
|
|
$res[0]['is_isset'] = 2;
|
|
$modify_after = $res[0];
|
|
}
|
|
} else {
|
|
$res = Db::table('pg_return_price')
|
|
->field('eva_unit_price, eva_total_value, eva_net_value, eva_net_value2, added_tax, urban_construction_tax, edu_surcharge,
|
|
land_value_added_tax, stamp_duty, personal_income_tax, deed_tax, corporate_income_tax, auction_fee, tran_service_fee, total_taxes1, total_taxes2, loan_ratio,
|
|
gross_value, eva_net_value, eva_net_value2')
|
|
->where(['property_cert_info_id' => $property_cert_info_id])
|
|
->order('create_time', 'desc')
|
|
->limit(2)
|
|
->select();
|
|
$res[0]['is_isset'] = $res[1]['is_isset'] = 1;
|
|
$modify_front = $res[1];
|
|
$modify_after = $res[0];
|
|
}
|
|
$result['modify_front'] = $modify_front;//调价前
|
|
$result['modify_after'] = $modify_after;//调价后
|
|
|
|
return $result;
|
|
}
|
|
|
|
public static function getInquiryReportList($where,$field,$paginate,$order=''){
|
|
$res=self::alias('i')
|
|
->join(['pg_property_cert_info'=>'id'],'i.id=id.quot_id','LEFT')
|
|
->join(['pg_report'=>'r'],'i.id=r.quot_id','LEFT')
|
|
->join(['pg_report_detail'=>'rd'],'r.id=rd.report_id','LEFT')
|
|
->join(['pg_charge'=>'c'],'i.order_no=c.order_no','LEFT')
|
|
->field($field)
|
|
->where(new Where($where))
|
|
->order($order)
|
|
->group('i.id')
|
|
->paginate($paginate)
|
|
->toArray();
|
|
|
|
if(!empty($res)){
|
|
$v['property_full_name']=[];
|
|
foreach ($res['data'] as $k => &$v) {
|
|
$idarr=Db::name('property_cert_info')->where('quot_id',$v['iid'])->select();
|
|
$rdarr=Db::name('report_detail')->where('report_id',$v['rid'])->select();
|
|
$v['bank_name']=$v['bank_name'].'-'.$v['bank_branch_name'].'-'.$v['bank_sub_name'];
|
|
if(!empty($idarr)){
|
|
$v['property_full_name']['show']=$idarr[0]['property_full_name'];
|
|
$v['full_estate_name_str']='';
|
|
foreach ($idarr as $key => $value) {
|
|
$v['property_full_name']['list'][]=$value['property_full_name'];
|
|
$v['full_estate_name_str'].=$value['property_full_name'].',';
|
|
}
|
|
$v['full_estate_name_str']=trim($v['full_estate_name_str'],',');
|
|
}
|
|
$v['type_str']=$v['type']==1?'住宅':'商业';
|
|
$v['building_area']=$v['eva_total_value']=$v['eva_net_value']=$v['eva_net_value2']=$v['obligee']=$v['cert_no']=$v['property_cert']=$v['purchase_date']='';
|
|
if(!empty($rdarr)){
|
|
foreach ($rdarr as $key => $value) {
|
|
// $v['building_area'].=$value['building_area'].'/';
|
|
// $v['eva_total_value'].=$value['eva_total_value'].'/';
|
|
// $v['eva_net_value'].=$value['eva_net_value'].'/';
|
|
// $v['eva_net_value2'].=$value['eva_net_value2'].'/';
|
|
$return_price=Db::name('return_price')->where('property_cert_info_id',$value['id'])->find();
|
|
$v['building_area'].=$return_price['area'].'/';
|
|
$v['eva_total_value'].=$return_price['eva_total_value'].'/';
|
|
$v['eva_net_value'].=$return_price['eva_net_value'].'/';
|
|
$v['eva_net_value2'].=$return_price['eva_net_value2'].'/';
|
|
|
|
$v['obligee'].=$value['obligee'].'/';
|
|
$v['cert_no'].=$value['cert_no'].'/';
|
|
$v['property_cert'].=$value['property_cert'].'/';
|
|
$v['purchase_date'].=$value['purchase_date'].'/';
|
|
}
|
|
$v['building_area']=trim($v['building_area'],'/');
|
|
$v['eva_total_value']=trim($v['eva_total_value'],'/');
|
|
$v['eva_net_value']=trim($v['eva_net_value'],'/');
|
|
$v['eva_net_value2']=trim($v['eva_net_value2'],'/');
|
|
$v['obligee']=trim($v['obligee'],'/');
|
|
$v['cert_no']=(string)trim($v['cert_no'],'/');
|
|
$v['property_cert']=trim($v['property_cert'],'/');
|
|
$v['purchase_date']=trim($v['purchase_date'],'/');
|
|
}
|
|
}
|
|
}
|
|
return $res;
|
|
}
|
|
|
|
|
|
|
|
} |