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