1309 lines
60 KiB
PHP
1309 lines
60 KiB
PHP
<?php
|
||
|
||
|
||
namespace app\admin\service;
|
||
|
||
|
||
use app\admin\controller\Customer;
|
||
use app\admin\controller\CheckFile;
|
||
use app\admin\exception\LogicException;
|
||
use app\common\config\EnumCfg;
|
||
use app\model\Dictionary;
|
||
use app\model\Inquiry;
|
||
use app\model\Property_cert_info;
|
||
|
||
use app\model\ReportDetail;
|
||
use Overtrue\Pinyin\Pinyin;
|
||
use think\Db;
|
||
|
||
use app\model\ReturnPrice;
|
||
use app\model\ZongdiInfo;
|
||
use PDOException;
|
||
use think\facade\Log;
|
||
|
||
class InquiryService extends CommonService
|
||
{
|
||
/**
|
||
* 批量创建
|
||
*/
|
||
const IS_BATCH_TAG = 1;
|
||
|
||
/**
|
||
* 非批量创建
|
||
*/
|
||
const IS_NOT_BATCH_TAG = 0;
|
||
|
||
/**
|
||
* 创建询价单
|
||
*
|
||
* @param $userId
|
||
* @param array $data
|
||
* @return mixed
|
||
*/
|
||
public function createInquiry(array $data)
|
||
{
|
||
try {
|
||
Db::startTrans();
|
||
// 查看客户经理是否存在
|
||
if (!empty($data['bank_customer_mgr_name'])) {
|
||
$isManagerExist = Db::name('account_manager')
|
||
->where('name', $data['bank_customer_mgr_name'])
|
||
->where('bank_id', $data['bank_id'])
|
||
->find();
|
||
if (!$isManagerExist) {
|
||
$data['bank_customer_mgr_id'] = Db::name('account_manager')->insertGetId([
|
||
'bank_id' => $data['bank_id'],
|
||
'bank_name' => $data['bank_name'],
|
||
'bank_branch_id' => $data['bank_branch_id'],
|
||
'bank_branch_name' => $data['bank_branch_name'],
|
||
'bank_sub_id' => $data['bank_sub_id'],
|
||
'bank_sub_name' => $data['bank_sub_name'],
|
||
'name' => removeEmoji($data['bank_customer_mgr_name']),
|
||
'mobile' => removeEmoji($data['bank_customer_mgr_phone']),
|
||
'addtime' => date('Y-m-d H:i:s'),
|
||
]);
|
||
}
|
||
}
|
||
|
||
$inquiry = new Inquiry();
|
||
$order_no = $inquiry->generateInquiryNo($data['branchCom_id']);
|
||
if (empty($order_no)) {
|
||
Db::rollback();
|
||
return ['code' => -1, 'msg' => '生成询价单号失败'];
|
||
}
|
||
$inquiry->order_no = $order_no;
|
||
$inquiry->order_no_en = $this->enOrderNo($inquiry->order_no);
|
||
$inquiry->user_id = $data['user_id'];
|
||
$inquiry->user_name = $data['user_name'];
|
||
$inquiry->buss_user_id = $data['buss_user_id'];
|
||
$inquiry->buss_username = $data['buss_username'];
|
||
$inquiry->buss_userphone = $data['buss_userphone'];
|
||
$inquiry->department_id = $data['department_id'];
|
||
$inquiry->department_name = $data['department_name'];
|
||
$inquiry->user_phone = $data['user_phone'];
|
||
$inquiry->bank_name = $data['bank_name'];
|
||
$inquiry->bank_id = $data['bank_id'];
|
||
$inquiry->bank_branch_name = $data['bank_branch_name'];
|
||
$inquiry->bank_branch_id = $data['bank_branch_id'];
|
||
$inquiry->bank_sub_name = $data['bank_sub_name'];
|
||
$inquiry->bank_sub_id = $data['bank_sub_id'];
|
||
$inquiry->bank_customer_mgr_id = $data['bank_customer_mgr_id'];
|
||
$inquiry->bank_customer_mgr_name = $data['bank_customer_mgr_name'];
|
||
$inquiry->bank_customer_mgr_phone = removeEmoji($data['bank_customer_mgr_phone']);
|
||
$inquiry->branchCom_id = $data['branchCom_id'];
|
||
//$inquiry->customType_id = $data['customType_id'];
|
||
$inquiry->eva_purpose = $data['eva_purpose'];
|
||
|
||
$boc_common_main_id = 0;
|
||
if (isset($data['business_no']) && !empty($data['business_no'])) {
|
||
$inquiry->business_no = $data['business_no'];
|
||
// todo 中行消金
|
||
/*if ($data['bank_name'] == '中国银行' && $data['loan_type'] == '二手按揭') {
|
||
$boc_cf_inquiry_apply = Db::name('boc_cf_inquiry_apply')->where('dealNo', $data['business_no'])->find();
|
||
if (empty($boc_cf_inquiry_apply)) {
|
||
Db::rollback();
|
||
return ['code' => -1, 'msg' => '中行业务编号不存在'];
|
||
}
|
||
if ($boc_cf_inquiry_apply['is_related'] == 2) {
|
||
Db::rollback();
|
||
return ['code' => -1, 'msg' => '中行业务编号已被关联,请勿重复关联'];
|
||
}
|
||
$res = Db::name('boc_cf_inquiry_apply')->where('dealNo', $data['business_no'])->update([
|
||
'related_order_no' => $inquiry->order_no,
|
||
'is_related' => 2,
|
||
]);
|
||
if (!$res) {
|
||
Db::rollback();
|
||
return ['code' => -1, 'msg' => '更新中行业务编号状态失败'];
|
||
}
|
||
$inquiry->bnkno = $boc_cf_inquiry_apply['bnkno'];
|
||
$inquiry->tlrname = $boc_cf_inquiry_apply['tlrname'];
|
||
$inquiry->biz_status = 10;
|
||
}*/
|
||
// 中行消金和普惠
|
||
if ($data['bank_name'] == '中国银行' && in_array($data['loan_type'], ['二手按揭', '普惠'])) {
|
||
$boc_common_main = Db::name('boc_common_main')
|
||
->where('bankPreEstimateNo', $data['business_no'])
|
||
->whereOr('bankEstimateNo', $data['business_no'])
|
||
->find();
|
||
if (empty($boc_common_main)) {
|
||
Db::rollback();
|
||
return ['code' => -1, 'msg' => '中行业务编号不存在'];
|
||
}
|
||
if ($boc_common_main['is_related'] == 2) {
|
||
Db::rollback();
|
||
return ['code' => -1, 'msg' => '中行业务编号已被关联,请勿重复关联'];
|
||
}
|
||
$boc_common_main_id = $boc_common_main['id'];
|
||
if(!empty($boc_common_main['bankPreEstimateNo'])) {
|
||
$boc_where['bankPreEstimateNo'] = $data['business_no'];
|
||
$inquiry->boc_biz_status = 10;
|
||
} else {
|
||
$boc_where['bankEstimateNo'] = $data['business_no'];
|
||
$inquiry->boc_biz_status = 30;
|
||
}
|
||
$res = Db::name('boc_common_main')->where($boc_where)->update([
|
||
'order_no' => $order_no,
|
||
'is_related' => 2,
|
||
]);
|
||
if (!$res) {
|
||
Db::rollback();
|
||
return ['code' => -1, 'msg' => '更新中行业务编号状态失败'];
|
||
}
|
||
}
|
||
}
|
||
|
||
$inquiry->product_id = $data['product_id'];
|
||
// $inquiry->type = $data['type']; // 2025-12-15 annnj 注释掉type字段
|
||
$inquiry->is_multiple = count($data['details']) > 1;
|
||
$inquiry->status = Inquiry::STATUS_CREATED;
|
||
$inquiry->return_price_status = 2;
|
||
$inquiry->create_time = date('Y-m-d H:i:s');
|
||
$inquiry->update_time = date('Y-m-d H:i:s');
|
||
$inquiry->sort = getSort($data['buss_user_id']);
|
||
$inquiry->create_time_unix = time();
|
||
$inquiry->loan_type = $data['loan_type'];
|
||
$inquiry->report_obj_type = $data['report_obj_type'];
|
||
$reportClassRes = EnumCfg::findByFullName(EnumCfg::reportClass, $data['loan_type']);
|
||
if (!empty($reportClassRes)) {
|
||
$inquiry->report_class = $reportClassRes['id'];
|
||
}
|
||
|
||
//2025-12-15 annnj 存在一个物业是非住宅的,整个单就是非住宅的单
|
||
$usage_arr = array_column($data['details'], 'usage');
|
||
$inquiry_type = 1; //默认住宅,1=住宅 2=非住宅
|
||
foreach ($usage_arr as $u) {
|
||
if ($u != 1) {
|
||
$inquiry_type = 2;
|
||
break;
|
||
}
|
||
}
|
||
$inquiry->type = $inquiry_type;
|
||
|
||
|
||
if (!$inquiry->save()) {
|
||
Db::rollback();
|
||
return ['code' => -1, 'msg' => 'inquiry表插入异常'];
|
||
}
|
||
$id = $inquiry->getLastInsID();
|
||
if (!empty($boc_common_main_id)) {
|
||
$res = Db::name('boc_common_main')->where('id', $boc_common_main_id)->update(['quot_id' => $id]);
|
||
if ($res === false) {
|
||
Db::rollback();
|
||
return ['code' => -1, 'msg' => '更新中行业务编号状态失败'];
|
||
}
|
||
}
|
||
|
||
foreach ($data['details'] as $detail) {
|
||
$property_cert_info = new Property_cert_info();
|
||
$property_cert_info->quot_id = $inquiry->id;
|
||
$property_cert_info->city = $detail['city'];
|
||
$property_cert_info->city_id = $detail['city_id'];
|
||
$property_cert_info->building_name = removeEmoji(trim($detail['building_name']));;
|
||
$property_cert_info->building_no = removeEmoji(trim($detail['building_no']));
|
||
$property_cert_info->unit_no = removeEmoji(trim($detail['unit_no']));
|
||
$property_cert_info->building_unit_no = (empty($detail['building_no']) || trim($detail['building_no']) == '0') ? $detail['unit_no'] : $detail['building_no'] . $detail['unit_no'];
|
||
$property_cert_info->property_full_name = $property_cert_info->building_name . $property_cert_info->building_unit_no;
|
||
$property_cert_info->size = removeEmoji($detail['size']);
|
||
$property_cert_info->reg_price = removeEmoji($detail['reg_price']);
|
||
$property_cert_info->usage = $detail['usage'];
|
||
$property_cert_info->cert_usage = removeEmoji($detail['cert_usage']);
|
||
$property_cert_info->use_right_source = $detail['use_right_source'];
|
||
$property_cert_info->tax_type = $detail['tax_type'] ?? null;
|
||
$property_cert_info->is_tran_tax_free = $detail['is_tran_tax_free'];
|
||
if (isset($detail['purchase_date']) && !empty($detail['purchase_date']))
|
||
$property_cert_info->purchase_date = $detail['purchase_date'];
|
||
if (isset($detail['completion_time']) && !empty($detail['completion_time']))
|
||
$property_cert_info->completion_time = $detail['completion_time'];
|
||
if (isset($detail['land_location']) && $detail['land_location'])
|
||
$property_cert_info->land_location = removeEmoji($detail['land_location']);
|
||
if (isset($detail['obligee']) && $detail['obligee'])
|
||
$property_cert_info->obligee = removeEmoji($detail['obligee']);
|
||
if (isset($detail['year']) && $detail['year'])
|
||
$property_cert_info->year = $detail['year'];
|
||
if (isset($detail['property_cert']))
|
||
$property_cert_info->property_cert = removeEmoji($detail['property_cert']);
|
||
if (isset($detail['ownership_type']))
|
||
$property_cert_info->ownership_type = $detail['ownership_type'];
|
||
if (isset($detail['attachments']) && !empty($detail['attachments'])) {
|
||
$property_cert_info->attachments = is_array($detail['attachments']) ? implode(",", $detail['attachments']) : $detail['attachments'];
|
||
}
|
||
if (isset($detail['remark']))
|
||
$property_cert_info->remark = removeEmoji($detail['remark']);
|
||
//todo 附件的处理
|
||
if (!$property_cert_info->save()) {
|
||
Db::rollback();
|
||
return ['code' => -1, 'msg' => 'property_cert_info表插入异常'];
|
||
}
|
||
|
||
//查档处理:询价添加成功添加对应的查档
|
||
if (isset($detail['consult_id']) && $detail['consult_id']) {
|
||
(new CheckFile())->addConsult(['consult_id' => $detail['consult_id'], 'order_no' => $inquiry->order_no, 'property_cert_info_id' => $property_cert_info->id, 'user_id' => $data['user_id']]);
|
||
}
|
||
}
|
||
Db::commit();
|
||
//写入消息
|
||
PublicMessage($inquiry->id, 1, 1);
|
||
} catch (\Exception $e) {
|
||
Db::rollback();
|
||
Log::error('错误文件:' . $e->getFile());
|
||
Log::error('错误行数:' . $e->getLine());
|
||
Log::error('错误编码:' . $e->getCode());
|
||
Log::error('错误信息:' . $e->getMessage());
|
||
return false;
|
||
}
|
||
|
||
|
||
return ['code' => 1, "inquiryId" => $inquiry->id];
|
||
}
|
||
|
||
/**
|
||
* 批量创建询价单
|
||
*
|
||
* @param $userId
|
||
* @param array $data
|
||
* @return mixed
|
||
*/
|
||
public function createInquirybyBatch(array $data, $file, $user_id, $user_name)
|
||
{
|
||
try {
|
||
Db::startTrans();
|
||
$inquiry = new Inquiry();
|
||
if (!empty($data['bank_customer_mgr_name'])) {
|
||
$isManagerExist = Db::name('account_manager')
|
||
->where('name', $data['bank_customer_mgr_name'])
|
||
->where('bank_id', $data['bank_id'])
|
||
->find();
|
||
if (!$isManagerExist) {
|
||
$data['bank_customer_mgr_id'] = Db::name('account_manager')->insertGetId([
|
||
'bank_id' => $data['bank_id'],
|
||
'bank_name' => $data['bank_name'],
|
||
'bank_branch_id' => $data['bank_branch_id'],
|
||
'bank_branch_name' => $data['bank_branch_name'],
|
||
'bank_sub_id' => $data['bank_sub_id'],
|
||
'bank_sub_name' => $data['bank_sub_name'],
|
||
'name' => removeEmoji($data['bank_customer_mgr_name']),
|
||
'mobile' => removeEmoji($data['bank_customer_mgr_phone']),
|
||
'addtime' => date('Y-m-d H:i:s'),
|
||
]);
|
||
}
|
||
}
|
||
|
||
|
||
$order_no = $inquiry->generateInquiryNo($data['branchCom_id']);
|
||
if (empty($order_no)) {
|
||
Db::rollback();
|
||
return ['code' => -1, 'msg' => '生成询价单号失败'];
|
||
}
|
||
$inquiry->order_no = $order_no;
|
||
$inquiry->order_no_en = $this->enOrderNo($inquiry->order_no);
|
||
$inquiry->user_id = $user_id;
|
||
$inquiry->is_batch = InquiryService::IS_BATCH_TAG; // 批量创建标志
|
||
$inquiry->user_name = $user_name;
|
||
$inquiry->department_id = $data['department_id'];
|
||
$inquiry->department_name = $data['department_name'];
|
||
$inquiry->user_phone = $data['user_phone'];
|
||
$inquiry->bank_name = $data['bank_name'];
|
||
$inquiry->bank_id = $data['bank_id'];
|
||
$inquiry->buss_user_id = $data['buss_user_id'];
|
||
$inquiry->buss_username = $data['buss_username'];
|
||
$inquiry->buss_userphone = $data['buss_userphone'];
|
||
$inquiry->bank_branch_name = $data['bank_branch_name'];
|
||
$inquiry->bank_branch_id = $data['bank_branch_id'];
|
||
$inquiry->bank_sub_name = $data['bank_sub_name'];
|
||
$inquiry->bank_sub_id = $data['bank_sub_id'];
|
||
$inquiry->bank_customer_mgr_id = $data['bank_customer_mgr_id'];
|
||
$inquiry->bank_customer_mgr_name = $data['bank_customer_mgr_name'];
|
||
$inquiry->bank_customer_mgr_phone = $data['bank_customer_mgr_phone'];
|
||
$inquiry->branchCom_id = $data['branchCom_id'];
|
||
$inquiry->eva_purpose = $data['eva_purpose'];
|
||
if (isset($data['business_no']) && !empty($data['business_no'])) {
|
||
$inquiry->business_no = $data['business_no'];
|
||
// todo 中行消金
|
||
/*if ($data['bank_name'] == '中国银行' && $data['loan_type'] == '二手按揭') {
|
||
$boc_cf_inquiry_apply = Db::name('boc_cf_inquiry_apply')->where('dealNo', $data['business_no'])->find();
|
||
if (empty($boc_cf_inquiry_apply)) {
|
||
Db::rollback();
|
||
return ['code' => -1, 'msg' => '中行业务编号不存在'];
|
||
}
|
||
if ($boc_cf_inquiry_apply['is_related'] == 2) {
|
||
Db::rollback();
|
||
return ['code' => -1, 'msg' => '中行业务编号已被关联,请勿重复关联'];
|
||
}
|
||
$res = Db::name('boc_cf_inquiry_apply')->where('dealNo', $data['business_no'])->update([
|
||
'related_order_no' => $inquiry->order_no,
|
||
'is_related' => 2,
|
||
]);
|
||
if (!$res) {
|
||
Db::rollback();
|
||
return ['code' => -1, 'msg' => '更新中行业务编号状态失败'];
|
||
}
|
||
$inquiry->bnkno = $boc_cf_inquiry_apply['bnkno'];
|
||
$inquiry->tlrname = $boc_cf_inquiry_apply['tlrname'];
|
||
$inquiry->biz_status = 10;
|
||
}*/
|
||
// 中行消金和普惠
|
||
if ($data['bank_name'] == '中国银行' && in_array($data['loan_type'], ['二手按揭', '普惠'])) {
|
||
$boc_common_main = Db::name('boc_common_main')
|
||
->where('bankPreEstimateNo', $data['business_no'])
|
||
->whereOr('bankEstimateNo', $data['business_no'])
|
||
->find();
|
||
if (empty($boc_common_main)) {
|
||
Db::rollback();
|
||
return ['code' => -1, 'msg' => '中行业务编号不存在'];
|
||
}
|
||
if ($boc_common_main['is_related'] == 2) {
|
||
Db::rollback();
|
||
return ['code' => -1, 'msg' => '中行业务编号已被关联,请勿重复关联'];
|
||
}
|
||
$boc_common_main_id = $boc_common_main['id'];
|
||
if(!empty($boc_common_main['bankPreEstimateNo'])) {
|
||
$boc_where['bankPreEstimateNo'] = $data['business_no'];
|
||
$inquiry->boc_biz_status = 10;
|
||
} else {
|
||
$boc_where['bankEstimateNo'] = $data['business_no'];
|
||
$inquiry->boc_biz_status = 30;
|
||
}
|
||
$res = Db::name('boc_common_main')->where($boc_where)->update([
|
||
'order_no' => $order_no,
|
||
'is_related' => 2,
|
||
]);
|
||
if (!$res) {
|
||
Db::rollback();
|
||
return ['code' => -1, 'msg' => '更新中行业务编号状态失败'];
|
||
}
|
||
}
|
||
}
|
||
|
||
$inquiry->product_id = $data['product_id'];
|
||
// $inquiry->type = $data['type']; //2025-12-15 annnj 注释掉type字段
|
||
|
||
$inquiry->status = Inquiry::STATUS_CREATED; // 业务待确认
|
||
$inquiry->create_time = date('Y-m-d H:i:s');
|
||
$inquiry->update_time = date('Y-m-d H:i:s');
|
||
$inquiry->create_time_unix = time();
|
||
$inquiry->loan_type = $data['loan_type'];
|
||
$inquiry->report_obj_type = $data['report_obj_type'];
|
||
$reportClassRes = EnumCfg::findByFullName(EnumCfg::reportClass, $data['loan_type']);
|
||
if (!empty($reportClassRes)) {
|
||
$inquiry->report_class = $reportClassRes['id'];
|
||
}
|
||
|
||
$res = getArrayByExcel($file, 2);
|
||
if ($res['code'] == -1) {
|
||
return ['code' => $res['code'], 'msg' => $res['msg']];
|
||
}
|
||
|
||
$arrExcel = $res['data'];
|
||
|
||
//2025-12-15 annnj 存在一个物业是非住宅的,整个单就是非住宅的单
|
||
$usage_arr = array_column($arrExcel, 'usage');
|
||
$inquiry_type = 1; //默认住宅,1=住宅 2=非住宅
|
||
foreach ($usage_arr as $u) {
|
||
if ($u != 1) {
|
||
$inquiry_type = 2;
|
||
break;
|
||
}
|
||
}
|
||
$inquiry->type = $inquiry_type;
|
||
|
||
|
||
//var_dump($arrExcel);
|
||
$isMulti = false;
|
||
$update_counter = 0;
|
||
|
||
if (is_countable($arrExcel))
|
||
$isMulti = count($arrExcel) > 1;
|
||
|
||
$inquiry->is_multiple = $isMulti;//是否多套物业
|
||
if (!$inquiry->save()) {
|
||
Db::rollback();
|
||
return ['code' => -1, 'msg' => '询价表插入异常'];
|
||
}
|
||
$id = $inquiry->getLastInsID();
|
||
if (!empty($boc_common_main_id)) {
|
||
$res = Db::name('boc_common_main')->where('id', $boc_common_main_id)->update(['quot_id' => $id]);
|
||
if ($res === false) {
|
||
Db::rollback();
|
||
return ['code' => -1, 'msg' => '更新中行业务编号状态失败'];
|
||
}
|
||
}
|
||
//var_dump($arrExcel);
|
||
|
||
$quot_id = $inquiry->id;
|
||
$usage_arr = Db::name('dictionary')->where('type', 'HOUSE_USAGE')->column('code', 'valname');
|
||
$ownership_type_arr = ['个人' => 1, '公司' => 2];
|
||
|
||
|
||
foreach ($arrExcel as $detail) {
|
||
if ('0' == trim($detail['building_name'])) {
|
||
continue;
|
||
}
|
||
|
||
$mInquiryDetail = new Property_cert_info();
|
||
$property_cert_info = array();
|
||
$property_cert_info['quot_id'] = $quot_id;
|
||
$property_cert_info['reg_price'] = (float)trim(str_replace([',',','], '',$detail['reg_price']));
|
||
$property_cert_info['purchase_date'] = $detail['purchase_date'];
|
||
$property_cert_info['city'] = trim($detail['city']);
|
||
$property_cert_info['city_id'] = Db::name("region")->where("name", trim($detail['city']))->value("id");
|
||
$property_full_name = trim($detail['building_name'] . $detail['building_no'] . $detail['unit_no']);
|
||
$property_cert_info['property_full_name'] = $property_full_name;
|
||
$property_cert_info['building_name'] = trim($detail['building_name']);
|
||
$property_cert_info['building_no'] = trim($detail['building_no']);
|
||
$property_cert_info['unit_no'] = trim($detail['unit_no']);
|
||
$property_cert_info['size'] = (float)trim(str_replace([',',','], '',$detail['size']));
|
||
$property_cert_info['usage'] = $usage_arr[$detail['usage']] ?? 1;
|
||
$property_cert_info['cert_usage'] = $detail['cert_usage'] ?? null;
|
||
$property_cert_info['completion_time'] = $detail['completion_time'] ?? null;
|
||
$property_cert_info['ownership_type'] = $ownership_type_arr[$detail['ownership_type']] ?? 1;
|
||
$property_cert_info['use_right_source'] = 1;
|
||
$property_cert_info['parcel_no'] = $detail['parcel_no'];
|
||
$property_cert_info['parcel_area'] = $detail['parcel_area'];
|
||
$property_cert_info['land_unit_price'] = (float)trim(str_replace([',',','], '',$detail['land_unit_price']));
|
||
$property_cert_info['floor_unit_price'] = (float)trim(str_replace([',',','], '',$detail['floor_unit_price']));
|
||
|
||
//if (isset($arrExcel['remark']))
|
||
// $property_cert_info['remark'] = $arrExcel['remark'];
|
||
|
||
if (!$mInquiryDetail->save($property_cert_info)) {
|
||
Db::rollback();
|
||
return ['code' => -1, 'msg' => '房产表插入异常'];
|
||
}
|
||
|
||
$ReturnPrice = new ReturnPrice();
|
||
$insert_date = array();
|
||
$insert_date['property_cert_info_id'] = $mInquiryDetail->id;
|
||
$insert_date['building_unit_no'] = $property_full_name;
|
||
$insert_date['property_name'] = trim($detail['building_name']);
|
||
$insert_date['building_no'] = trim($detail['building_no']);
|
||
$insert_date['unit_no'] = trim($detail['unit_no']);
|
||
$insert_date['area'] = $detail['size'];
|
||
$insert_date['eva_unit_price'] = $detail['assessment_price'];
|
||
$insert_date['eva_total_value'] = $detail['assessment_all_value'];
|
||
$insert_date['internal_remarks'] = $detail['remark'];
|
||
$insert_date['net_value'] = $detail['net_worth']; //净值
|
||
$insert_date['eva_total_value'] = $detail['net_worth']; // 评估净值
|
||
// $insert_date['external_remarks'] = $detail['remark'];
|
||
$insert_date['appraiser_id'] = $user_id; //执行人id
|
||
$insert_date['appraiser_name'] = $user_name; //执行人名称
|
||
$insert_date['create_time'] = time();
|
||
if (!$ReturnPrice->save($insert_date)) //插入回价表
|
||
{
|
||
Db::rollback();
|
||
return ['code' => -1, 'msg' => '回价表插入异常'];
|
||
} else {
|
||
$ind_upd_data['rid'] = $ReturnPrice->id;
|
||
$ind_upd_data['appraiser_id'] = $user_id;
|
||
$ind_upd_data['appraiser_name'] = $user_name;
|
||
$ind_upd_data['risk_grade'] = 1;
|
||
$ind_upd_data['r_create_time'] = $insert_date['create_time'];
|
||
$ind_upd_data['eva_unit_price'] = $detail['assessment_price'];
|
||
$ind_upd_data['eva_total_value'] = $detail['assessment_all_value'];
|
||
$ind_upd_data['eva_net_value'] = $detail['net_worth'];
|
||
$ind_upd_data['internal_remarks'] = $detail['remark'];
|
||
$ind_upd_res = Db::name('property_cert_info')->where('id', $mInquiryDetail->id)->update($ind_upd_data);
|
||
if (!$ind_upd_res) {
|
||
Db::rollback();
|
||
return ['code' => -1, 'msg' => '询价详情表更新异常'];
|
||
}
|
||
}
|
||
}
|
||
Db::commit();
|
||
} catch (PDOException $e) {
|
||
Db::rollback();
|
||
return ['code' => -2, 'msg' => $e->getMessage()];
|
||
}
|
||
|
||
return ['code' => 1, "inquiryId" => $inquiry->id];
|
||
}
|
||
|
||
/**
|
||
* 批量更新询价单
|
||
*
|
||
* @param $quot_id 询价id
|
||
* @param array $data
|
||
* @param file
|
||
* @param user_id
|
||
* @param user_name
|
||
* @return mixed
|
||
*/
|
||
public function updateInquirybyBatch($quot_id, $file, $data, $user_id, $user_name)
|
||
{
|
||
Db::startTrans();
|
||
|
||
$inquiry = new Inquiry();
|
||
$inquiry_data = $inquiry->where('id', $quot_id)->find();
|
||
|
||
$res = getArrayByExcel($file, 0);// 2代表 读取excel中sheet[2]的表数据
|
||
if ($res['code'] == -1) {
|
||
return ['code' => $res['code'], 'msg' => $res['msg']];
|
||
}
|
||
|
||
$arrExcel = $res['data'];
|
||
$update_counter = 0;
|
||
|
||
foreach ($arrExcel as $detail) {
|
||
if ('0' == trim($detail['property_full_name'])) {
|
||
continue;
|
||
}
|
||
|
||
// ---- 物业信息表 --------------------------
|
||
$mInquiryDetail = new Property_cert_info();
|
||
$property_cert_info = array();
|
||
$property_cert_info['quot_id'] = $quot_id;
|
||
$property_cert_info['reg_price'] = trim($detail['register_price']);
|
||
$property_cert_info['property_full_name'] = trim($detail['full_estate_name']);
|
||
$property_cert_info['building_name'] = trim($detail['full_estate_name']);
|
||
$property_cert_info['size'] = $detail['size'];
|
||
$property_cert_info['usage'] = $detail['usage'];
|
||
$property_cert_info['parcel_no'] = $detail['zd_bh'];
|
||
$property_cert_info['parcel_area'] = $detail['zd_area'];
|
||
$property_cert_info['land_unit_price'] = $detail['zd_price'];
|
||
$property_cert_info['floor_unit_price'] = $detail['zd_building_price'];
|
||
|
||
if (isset($arrExcel['remark']))
|
||
$property_cert_info['remark'] = $arrExcel['remark'];
|
||
|
||
//todo 附件的处理
|
||
$map = [
|
||
'quot_id' => $quot_id,
|
||
'property_full_name' => trim($detail['full_estate_name'])
|
||
];
|
||
|
||
$res = $mInquiryDetail->where($map)->update($property_cert_info);//var_dump($map);
|
||
if (0 == $res) //如果更新数量为0
|
||
{
|
||
++$update_counter;
|
||
}
|
||
|
||
// 合规检查
|
||
if ($detail['property_full_name'] == 0
|
||
|| $detail['property_full_name'] == ''
|
||
|| $detail['size'] == 0
|
||
|| $detail['eva_unit_price'] == 0) {
|
||
continue;
|
||
}
|
||
|
||
$ReturnPrice = new ReturnPrice();
|
||
$insert_date = array();
|
||
$insert_date['property_cert_info_id'] = $mInquiryDetail->id;
|
||
$insert_date['building_unit_no'] = trim($detail['full_estate_name']);
|
||
$insert_date['property_name'] = trim($detail['full_estate_name']);
|
||
$insert_date['area'] = $detail['size'];
|
||
$insert_date['eva_unit_price'] = $detail['assessment_price'];
|
||
$insert_date['eva_total_value'] = $detail['assessment_all_value'];
|
||
$insert_date['internal_remarks'] = $detail['remark'];
|
||
$insert_date['eva_net_value'] = $detail['net_worth'];
|
||
$insert_date['net_value'] = $detail['net_worth'];
|
||
// $insert_date['external_remarks'] = $detail['remark']; //只显示外部批注
|
||
$insert_date['appraiser_id'] = $user_id; //执行人id
|
||
$insert_date['appraiser_name'] = $user_name; //执行人名称
|
||
$insert_date['create_time'] = time();
|
||
|
||
if (!$ReturnPrice->insert($insert_date)) //插入回价表
|
||
{
|
||
Db::rollback();
|
||
return ['code' => -1, 'msg' => '回价表插入异常'];
|
||
}
|
||
}
|
||
|
||
Db::commit();
|
||
|
||
return ['code' => 1, "inquiryId" => $quot_id];
|
||
}
|
||
|
||
/**
|
||
* Generates a unique inquiry order number
|
||
*
|
||
* @return string The generated inquiry order number
|
||
*/
|
||
public function generateInquiryNo()
|
||
{
|
||
$inquiry = new Inquiry();
|
||
$inquiry->order_no = $inquiry->generateInquiryNo();
|
||
return $inquiry->order_no;
|
||
}
|
||
|
||
/**
|
||
* 创建简易询价
|
||
*
|
||
* @param $userId
|
||
* @param array $data
|
||
* @return mixed
|
||
*/
|
||
public function createSimpleInquiry(array $data)
|
||
{
|
||
$inquiry = new Inquiry();
|
||
$inquiry->order_no = $inquiry->generateInquiryNo($data['branchCom_id']);
|
||
$inquiry->user_id = $data['user_id'];
|
||
$inquiry->user_name = $data['user_name'];
|
||
$inquiry->department_id = $data['department_id'];
|
||
$inquiry->department_name = $data['department_name'];
|
||
$inquiry->user_phone = $data['user_phone'];
|
||
$inquiry->type = $data['type'];
|
||
$inquiry->status = 1;
|
||
$inquiry->is_simple = 1;
|
||
$inquiry->client_name = $data['client_name'];
|
||
$inquiry->create_time = date('Y-m-d H:i:s');
|
||
$inquiry->update_time = date('Y-m-d H:i:s');
|
||
if (!$inquiry->save()) {
|
||
return ['code' => -1, 'msg' => 'inquiry表插入异常'];
|
||
}
|
||
|
||
foreach ($data['details'] as $detail) {
|
||
$property_cert_info = new Property_cert_info();
|
||
$property_cert_info->quot_id = $inquiry->id;
|
||
$property_cert_info->building_name = $detail['building_name'];
|
||
$property_cert_info->building_no = $detail['building_no'];
|
||
$property_cert_info->unit_no = $detail['unit_no'];
|
||
$property_cert_info->building_unit_no = (empty($detail['building_no']) || $detail['building_no'] == '0') ? $detail['unit_no'] : $detail['building_no'] . $detail['unit_no'];
|
||
$property_cert_info->property_full_name = $property_cert_info->building_name . $property_cert_info->building_unit_no;
|
||
$property_cert_info->size = $detail['size'];
|
||
if (isset($detail['remark']) && !empty($detail['remark'])) {
|
||
$property_cert_info->remark = $detail['remark'];
|
||
}
|
||
if (!$property_cert_info->save()) {
|
||
return ['code' => -1, 'msg' => 'inquiryDetail表插入异常'];
|
||
}
|
||
}
|
||
|
||
//写入消息
|
||
PublicMessage($inquiry->id, 1, 29);
|
||
|
||
return ['code' => 1];
|
||
|
||
}
|
||
|
||
|
||
/**
|
||
* 获取询价单详情
|
||
*
|
||
* @param $id
|
||
* @return array
|
||
*/
|
||
public function getInquiryDetail($id)
|
||
{
|
||
//todo 定制返回参数
|
||
$inquiryModel = new Inquiry();
|
||
$inquiry = $inquiryModel->find($id);
|
||
return $inquiry;
|
||
}
|
||
|
||
/**
|
||
* 撤单
|
||
*
|
||
* @param $userId
|
||
* @param $inquiryId
|
||
* @return mixed
|
||
* @throws \Exception
|
||
*/
|
||
public function cancelInquiry($inquiryId)
|
||
{
|
||
$inquiry = new Inquiry();
|
||
$inquiry = $inquiry->find($inquiryId);
|
||
if (!$inquiry)
|
||
throw new LogicException('该询价单不存在');
|
||
if ($inquiry->status == 8)
|
||
throw new LogicException('报告已完成,无法撤单,若需退报告,请走退报告流程');
|
||
if ($inquiry->status == -1 || $inquiry->status == -2)
|
||
throw new LogicException('该询价单已撤单');
|
||
if ($inquiry->status == 6 || $inquiry->status == 7) {
|
||
// 申请出报告后的撤单
|
||
$inquiry->status = -2;
|
||
} elseif ($inquiry->status == 5) {
|
||
// 查勘已完成未申请出报告的撤单
|
||
$inquiry->status = -3;
|
||
} else {
|
||
// 申请出报告前的撤单
|
||
if ($inquiry->status <= 4) {
|
||
$survey_data = Db::name('survey')
|
||
->where("order_no='" . $inquiry->order_no . "'")
|
||
->where('status<>3 and status<>4')
|
||
->select();
|
||
if ($survey_data) {
|
||
foreach ($survey_data as $key => $value) {
|
||
$upd_survey = Db::name('survey')
|
||
->where('id=' . $value['id'])
|
||
->update([
|
||
'status' => 4,
|
||
'return_reason' => '业务员已撤单,系统退回',
|
||
'delete_time' => date('Y-m-d H:i:s')
|
||
]);
|
||
if (!$upd_survey) {
|
||
throw new LogicException('撤单失败,请稍后再撤单!');
|
||
}
|
||
}
|
||
}
|
||
}
|
||
$inquiry->status = -1;
|
||
}
|
||
return $inquiry->save();
|
||
}
|
||
|
||
/**
|
||
* 上传产证信息
|
||
*
|
||
* @param $userId
|
||
* @param array $data
|
||
* @return mixed
|
||
* @throws \Exceptione
|
||
*/
|
||
public function reqPropertCertInfo(array $data)
|
||
{
|
||
//判断订单状态 != 订单状态!=报告制作中/报告待审核/报告已完成
|
||
$status = Db::name('inquiry')->alias('a')
|
||
->join('__INQUIRY_DETAIL__ b', 'a.id=b.quot_id')
|
||
->where(['b.id' => $data['order_no']])
|
||
->value('status');
|
||
if ($status == 6 || $status == 7 || $status == 8) //订单状!= 报告制作中/报告待审核/报告已完成
|
||
return false;
|
||
|
||
$property_cert_info = new Property_cert_info();
|
||
$property_cert_info = $property_cert_info->find($data['property_cert_info_id']);
|
||
if ($property_cert_info) {
|
||
$property_cert_info->id = $data['property_cert_info_id'];
|
||
$property_cert_info->owner_name = $data['owner_name'];
|
||
$property_cert_info->property_cert = $data['property_cert'];
|
||
$property_cert_info->attachments = $data['attachments'] ? implode(',', $data['attachments']) : '';
|
||
$property_cert_info->save();
|
||
}
|
||
return true;
|
||
}
|
||
|
||
/**
|
||
* 正常调价
|
||
*
|
||
* @param $userId
|
||
* @param array $data
|
||
* @return mixed
|
||
* @throws \Exception
|
||
*/
|
||
public function reqNormalAdjustApprisePrice(array $data)
|
||
{
|
||
|
||
Db::startTrans();
|
||
|
||
$status = Db::name('inquiry')->where(['order_no' => $data['order_no']])->value('status');
|
||
if (!($status == 2 || $status == 3 || $status == 4 || $status == 5))
|
||
return ['code' => -1, 'msg' => '订单状态有误,无法正常调价'];
|
||
|
||
if (Db::name('property_cert_info')->where(['id' => $data['property_cert_info_id'], 'adjust_status' => 1])->find())
|
||
return ['code' => -1, 'msg' => '此物业您已提交正常调价,待评估回复'];
|
||
|
||
$update['adjust_status'] = 1;
|
||
$update['evaluated_unit_price'] = $data['evaluated_unit_price'];
|
||
$update['variance_ratio'] = sprintf('%.2f', (float)$data['variance_ratio'] / 100);
|
||
$update['adjust_reason'] = $data['adjust_reason'];
|
||
$update['update_time'] = date('Y-m-d H:i:s');
|
||
$update['price_adjust_time'] = date('Y-m-d H:i:s');
|
||
|
||
//更新正常调价
|
||
if (!Db::name('property_cert_info')->where(['id' => $data['property_cert_info_id']])->update($update)) {
|
||
Db::rollback();
|
||
return ['code' => -1, 'msg' => '正常调价失败'];
|
||
}
|
||
//写入消息
|
||
$inquiry = Db::name('inquiry')->where(['order_no' => $data['order_no']])->field('id')->find();
|
||
PublicMessage($inquiry['id'], 3, 3, $data['property_cert_info_id']);
|
||
Db::commit();
|
||
return ['code' => 1, 'msg' => '更新成功'];
|
||
}
|
||
|
||
|
||
//检测调价属性是否正确
|
||
public function checkmodifyPrice(array $details)
|
||
{
|
||
$isSuccess = true;
|
||
$errors = [];
|
||
foreach ($details as $index => $detail) {
|
||
//todo 城区检查
|
||
if (!isset($detail['property_cert_info_id']) || !$detail['property_cert_info_id']) {
|
||
$isSuccess = false;
|
||
$errors[$index]['property_cert_info_id'] = '询价单详情id必填';
|
||
}
|
||
if (!isset($detail['evaluated_unit_price']) || !$detail['evaluated_unit_price']) {
|
||
$isSuccess = false;
|
||
$errors[$index]['evaluated_unit_price'] = '期望评估单价必填';
|
||
}
|
||
if (!isset($detail['variance_ratio']) || !$detail['variance_ratio']) {
|
||
$isSuccess = false;
|
||
$errors[$index]['variance_ratio'] = '差异比例必填';
|
||
}
|
||
if (!isset($detail['adjust_reason']) || !$detail['adjust_reason']) {
|
||
$isSuccess = false;
|
||
$errors[$index]['area'] = '调价原因必填';
|
||
}
|
||
}
|
||
return $this->verifyResult($isSuccess, $errors);
|
||
}
|
||
|
||
//检测生成报告数据 - 提交
|
||
public function checkcreateReport(array $data)
|
||
{
|
||
$isSuccess = true;
|
||
$errors = [];
|
||
|
||
if (!isset($data['quot_id']) || !$data['quot_id']) {
|
||
$isSuccess = false;
|
||
$errors[] = '询价单id必填';
|
||
}
|
||
// if(!isset($data['print_cpy_no']) || !$data['print_cpy_no']){
|
||
// $isSuccess = false;
|
||
// $errors[] = '打印份数必填';
|
||
// }
|
||
if (!isset($data['pay_type']) || !$data['pay_type']) {
|
||
$isSuccess = false;
|
||
$errors[] = '收费方式必填';
|
||
}
|
||
if (!isset($data['is_housing_fund']) || $data['is_housing_fund'] === false) {
|
||
$isSuccess = false;
|
||
$errors[] = '公积金必填';
|
||
}
|
||
if (!isset($data['order_src']) || !$data['order_src']) {
|
||
$isSuccess = false;
|
||
$errors['order_src'] = '业务来源必填';
|
||
}
|
||
if (!isset($data['business_type']) || !$data['business_type']) {
|
||
$isSuccess = false;
|
||
$errors['business_type'] = '业务类型必填';
|
||
}
|
||
if (!isset($data['details']) || !$data['details']) {
|
||
$isSuccess = false;
|
||
$errors[] = '报告详情必填';
|
||
}
|
||
|
||
$details = $data['details'];
|
||
if ($isSuccess) {
|
||
foreach ($details as $index => $detail) {
|
||
//todo 城区检查
|
||
if (!isset($detail['property_cert_info_id']) || !$detail['property_cert_info_id']) {
|
||
$isSuccess = false;
|
||
$errors[$index]['property_cert_info_id'] = '询价单详情id必填';
|
||
}
|
||
if (!isset($detail['property_cert']) || !$detail['property_cert']) {
|
||
$isSuccess = false;
|
||
$errors[$index]['property_cert'] = '房产证号必填';
|
||
}
|
||
if (!isset($detail['cert_type']) || !$detail['cert_type']) {
|
||
$isSuccess = false;
|
||
$errors[$index]['cert_type'] = '证件类型必填';
|
||
}
|
||
if (!isset($detail['obligee']) || !$detail['obligee']) {
|
||
$isSuccess = false;
|
||
$errors[$index]['obligee'] = '权利人必填';
|
||
}
|
||
if (!isset($detail['cert_no']) || !$detail['cert_no']) {
|
||
$isSuccess = false;
|
||
$errors[$index]['cert_no'] = '证件号必填';
|
||
}
|
||
if (!isset($detail['client']) || !$detail['client']) {
|
||
$isSuccess = false;
|
||
$errors[$index]['client'] = '委托方必填';
|
||
}
|
||
if (!isset($detail['parcel_no']) || !$detail['parcel_no']) {
|
||
$isSuccess = false;
|
||
$errors[$index]['parcel_no'] = '宗地号必填';
|
||
}
|
||
if (!isset($detail['parcel_area']) || !$detail['parcel_area']) {
|
||
$isSuccess = false;
|
||
$errors[$index]['parcel_area'] = '宗地面积必填';
|
||
}
|
||
if (!isset($detail['parcel_usage']) || !$detail['parcel_usage']) {
|
||
$isSuccess = false;
|
||
$errors[$index]['parcel_usage'] = '土地用途必填';
|
||
}
|
||
if (!isset($detail['use_right_source']) || !$detail['use_right_source']) {
|
||
$isSuccess = false;
|
||
$errors[$index]['use_right_source'] = '使用权来源必填';
|
||
}
|
||
if (!isset($detail['purchase_date']) || !$detail['purchase_date']) {
|
||
$isSuccess = false;
|
||
$errors[$index]['purchase_date'] = '登记/购买日期必填';
|
||
}
|
||
if (!isset($detail['reg_date']) || !$detail['reg_date']) {
|
||
$isSuccess = false;
|
||
$errors[$index]['reg_date'] = '评估日期必填';
|
||
}
|
||
if (!isset($detail['max_land_use_years']) || !$detail['max_land_use_years']) {
|
||
$isSuccess = false;
|
||
$errors[$index]['area'] = '土地使用年限必填';
|
||
}
|
||
if (!isset($detail['land_use_start_time']) || !$detail['land_use_start_time']) {
|
||
$isSuccess = false;
|
||
$errors[$index]['land_use_start_time'] = '土地使用开始时间必填';
|
||
}
|
||
if (!isset($detail['land_use_end_time']) || !$detail['land_use_end_time']) {
|
||
$isSuccess = false;
|
||
$errors[$index]['land_use_end_time'] = '土地使用结束时间必填';
|
||
}
|
||
if (!isset($detail['area']) || !$detail['area']) {
|
||
$isSuccess = false;
|
||
$errors[$index]['area'] = '所在城区必填';
|
||
}
|
||
if (!isset($detail['land_location']) || !$detail['land_location']) {
|
||
$isSuccess = false;
|
||
$errors[$index]['land_location'] = '土地位置';
|
||
}
|
||
if (!isset($detail['building_area']) || !$detail['building_area']) {
|
||
$isSuccess = false;
|
||
$errors[$index]['building_area'] = '建筑面积';
|
||
}
|
||
|
||
if (!isset($detail['house_cert_img_ids']) || !$detail['house_cert_img_ids']) {
|
||
$isSuccess = false;
|
||
$errors[$index]['land_location'] = '房产证照片';
|
||
}
|
||
|
||
}
|
||
}
|
||
return $this->verifyResult($isSuccess, $errors);
|
||
}
|
||
|
||
//检测生成报告数据 - 保存
|
||
public function checkcreateReportDraft(array $data)
|
||
{
|
||
$isSuccess = true;
|
||
$errors = [];
|
||
|
||
if (!isset($data['quot_id']) || !$data['quot_id']) {
|
||
$isSuccess = false;
|
||
$errors[] = '询价单id必填';
|
||
}
|
||
// if(!isset($data['print_cpy_no']) || !$data['print_cpy_no']){
|
||
// $isSuccess = false;
|
||
// $errors[] = '打印份数必填';
|
||
// }
|
||
|
||
$details = $data['details'];
|
||
if ($isSuccess) {
|
||
foreach ($details as $index => $detail) {
|
||
//todo 城区检查
|
||
if (!isset($detail['property_cert_info_id']) || !$detail['property_cert_info_id']) {
|
||
$isSuccess = false;
|
||
$errors[$index]['property_cert_info_id'] = '询价单详情id必填';
|
||
}
|
||
if (!isset($detail['property_cert']) || !$detail['property_cert']) {
|
||
$isSuccess = false;
|
||
$errors[$index]['property_cert'] = '房产证号必填';
|
||
}
|
||
if (!isset($detail['year']) && !$detail['year'] && $detail['year'] >= 9999) {
|
||
$isSuccess = false;
|
||
$errors[$index]['year'] = '请填写4位数年份,没有请留空';
|
||
}
|
||
if (!isset($detail['cert_type']) || !$detail['cert_type']) {
|
||
$isSuccess = false;
|
||
$errors[$index]['cert_type'] = '证件类型必填';
|
||
}
|
||
if (!isset($detail['obligee']) || !$detail['obligee']) {
|
||
$isSuccess = false;
|
||
$errors[$index]['obligee'] = '权利人必填';
|
||
}
|
||
if (!isset($detail['cert_no']) || !$detail['cert_no']) {
|
||
$isSuccess = false;
|
||
$errors[$index]['cert_no'] = '证件号必填';
|
||
}
|
||
if (!isset($detail['client']) || !$detail['client']) {
|
||
$isSuccess = false;
|
||
$errors[$index]['client'] = '委托方必填';
|
||
}
|
||
if (!isset($detail['parcel_no']) || !$detail['parcel_no']) {
|
||
$isSuccess = false;
|
||
$errors[$index]['parcel_no'] = '宗地号必填';
|
||
}
|
||
if (!isset($detail['parcel_area']) || !$detail['parcel_area']) {
|
||
$isSuccess = false;
|
||
$errors[$index]['parcel_area'] = '宗地面积必填';
|
||
}
|
||
if (!isset($detail['parcel_usage']) || !$detail['parcel_usage']) {
|
||
$isSuccess = false;
|
||
$errors[$index]['parcel_usage'] = '土地用途必填';
|
||
}
|
||
if (!isset($detail['use_right_source']) || !$detail['use_right_source']) {
|
||
$isSuccess = false;
|
||
$errors[$index]['use_right_source'] = '使用权来源必填';
|
||
}
|
||
if (!isset($detail['purchase_date']) || !$detail['purchase_date']) {
|
||
$isSuccess = false;
|
||
$errors[$index]['purchase_date'] = '登记/购买日期必填';
|
||
}
|
||
if (!isset($detail['reg_date']) || !$detail['reg_date']) {
|
||
$isSuccess = false;
|
||
$errors[$index]['reg_date'] = '评估日期必填';
|
||
}
|
||
if (!isset($detail['max_land_use_years']) || !$detail['max_land_use_years']) {
|
||
$isSuccess = false;
|
||
$errors[$index]['area'] = '土地使用年限必填';
|
||
}
|
||
if (!isset($detail['land_use_start_time']) || !$detail['land_use_start_time']) {
|
||
$isSuccess = false;
|
||
$errors[$index]['land_use_start_time'] = '土地使用开始时间必填';
|
||
}
|
||
if (!isset($detail['land_use_end_time']) || !$detail['land_use_end_time']) {
|
||
$isSuccess = false;
|
||
$errors[$index]['land_use_end_time'] = '土地使用结束时间必填';
|
||
}
|
||
if (!isset($detail['area']) || !$detail['area']) {
|
||
$isSuccess = false;
|
||
$errors[$index]['area'] = '所在城区必填';
|
||
}
|
||
if (!isset($detail['land_location']) || !$detail['land_location']) {
|
||
$isSuccess = false;
|
||
$errors[$index]['land_location'] = '土地位置';
|
||
}
|
||
if (!isset($detail['building_area']) || !$detail['building_area']) {
|
||
$isSuccess = false;
|
||
$errors[$index]['building_area'] = '建筑面积';
|
||
}
|
||
|
||
if (!isset($detail['house_cert_img_ids']) || !$detail['house_cert_img_ids']) {
|
||
$isSuccess = false;
|
||
$errors[$index]['land_location'] = '房产证照片';
|
||
}
|
||
|
||
}
|
||
}
|
||
return $this->verifyResult($isSuccess, $errors);
|
||
}
|
||
|
||
/**
|
||
* 检查询价物业信息正确性
|
||
*
|
||
* @param $type
|
||
* @param array $details
|
||
* @return array
|
||
*/
|
||
public function checkInquiryDetails($type, array $details)
|
||
{
|
||
switch ($type) {
|
||
case Inquiry::TYPE_RESIDENTIAL:
|
||
return $this->checkResidentialDetails($details);
|
||
break;
|
||
case Inquiry::TYPE_BUSINESS:
|
||
return $this->checkBusinessDetails($details);
|
||
break;
|
||
default:
|
||
return $this->verifyResult(false, ['type' => '询价类型不存在']);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 以批量上传的标准检查Inquiry
|
||
*
|
||
* @param [type] $type
|
||
* @param array $details
|
||
* @return void
|
||
*/
|
||
public function checkInquiryDetailByBatch($type, array $details)
|
||
{
|
||
$isSuccess = true;
|
||
$errors = [];
|
||
return $this->verifyResult($isSuccess, $errors);
|
||
}
|
||
|
||
public function checkResidentialDetails(array $details)
|
||
{
|
||
$isSuccess = true;
|
||
$errors = [];
|
||
foreach ($details as $index => $detail) {
|
||
//todo 城区检查
|
||
if (!isset($detail['city_id'])) {
|
||
$isSuccess = false;
|
||
$errors[$index]['city_id'] = '所在城市id未填';
|
||
}
|
||
if (!isset($detail['building_name'])) {
|
||
$isSuccess = false;
|
||
$errors[$index]['building_name'] = '物业名称未填';
|
||
}
|
||
if (!isset($detail['building_no'])) {
|
||
$isSuccess = false;
|
||
$errors[$index]['building_no'] = '栋号未填';
|
||
}
|
||
if (!isset($detail['unit_no'])) {
|
||
$isSuccess = false;
|
||
$errors[$index]['unit_no'] = '房号未填';
|
||
}
|
||
if (!isset($detail['is_tran_tax_free'])) {
|
||
$isSuccess = false;
|
||
$errors[$index]['is_tran_tax_free'] = '购买年限未填';
|
||
}
|
||
if (!isset($detail['size'])) {
|
||
$isSuccess = false;
|
||
$errors[$index]['size'] = '面积未填';
|
||
} elseif (!is_numeric(removeEmoji($detail['size']))) {
|
||
$isSuccess = false;
|
||
$errors[$index]['size'] = '面积必须是数字类型';
|
||
}
|
||
/* if (!isset($detail['reg_price'])){
|
||
$isSuccess = false;
|
||
$errors[$index]['reg_price'] = '登记价未填';
|
||
}
|
||
elseif (!is_numeric($detail['reg_price'])){
|
||
$isSuccess = false;
|
||
$errors[$index]['reg_price'] = '登记价不能为空且必须是数字类型';
|
||
}*/
|
||
if (!isset($detail['usage'])) {
|
||
$isSuccess = false;
|
||
$errors[$index]['usage'] = '物业用途未填';
|
||
}
|
||
if (!isset($detail['ownership_type'])) {
|
||
$errors[$index]['ownership_type'] = '产权人类型未填';
|
||
}
|
||
|
||
}
|
||
return $this->verifyResult($isSuccess, $errors);
|
||
}
|
||
|
||
/**
|
||
* 检查上传房产信息
|
||
*/
|
||
public function checkHouseProperty(array $details)
|
||
{
|
||
$isSuccess = true;
|
||
$errors = [];
|
||
foreach ($details as $index => $detail) {
|
||
//todo 城区检查
|
||
if (!isset($detail['id'])) {
|
||
$isSuccess = false;
|
||
$errors[$index]['id'] = '询价单详情id必填';
|
||
}
|
||
// if(!isset($detail['owner_name'])){
|
||
// $isSuccess = false;
|
||
// $errors[$index]['owner_name'] = '权利人必填';
|
||
// }
|
||
// if(!isset($detail['property_cert'])){
|
||
// $isSuccess = false;
|
||
// $errors[$index]['property_cert'] = '房产证号必填';
|
||
// }
|
||
// if(!isset($detail['attachments'])){
|
||
// $isSuccess = false;
|
||
// $errors[$index]['attachments'] = '附件必填';
|
||
// }
|
||
}
|
||
return $this->verifyResult($isSuccess, $errors);
|
||
}
|
||
|
||
public function checkBusinessDetails(array $details)
|
||
{
|
||
$isSuccess = true;
|
||
$errors = [];
|
||
foreach ($details as $index => $detail) {
|
||
//todo 城区检查
|
||
if (!isset($detail['city_id'])) {
|
||
$isSuccess = false;
|
||
$errors[$index]['city_id'] = '所在城市id未填';
|
||
}
|
||
if (!isset($detail['building_name'])) {
|
||
$isSuccess = false;
|
||
$errors[$index]['building_name'] = '物业名称未填';
|
||
}
|
||
if (!isset($detail['purchase_date'])) {
|
||
$isSuccess = false;
|
||
$errors[$index]['purchase_date'] = '登记日期未填';
|
||
} elseif (strtotime(date('Y-m-d', strtotime($detail['purchase_date']))) !== strtotime($detail['purchase_date'])) {
|
||
$isSuccess = false;
|
||
$errors[$index]['purchase_date'] = '登记日期格式有误';
|
||
}
|
||
if (!isset($detail['is_tran_tax_free'])) {
|
||
$isSuccess = false;
|
||
$errors[$index]['is_tran_tax_free'] = '购买年限未填';
|
||
}
|
||
if (!isset($detail['size'])) {
|
||
$isSuccess = false;
|
||
$errors[$index]['size'] = '面积未填';
|
||
} elseif (!is_numeric(removeEmoji($detail['size']))) {
|
||
$isSuccess = false;
|
||
$errors[$index]['size'] = '面积必须是数字类型';
|
||
}
|
||
if (!isset($detail['reg_price'])) {
|
||
$isSuccess = false;
|
||
$errors[$index]['reg_price'] = '登记价未填';
|
||
} elseif (!is_numeric(removeEmoji($detail['reg_price']))) {
|
||
$isSuccess = false;
|
||
$errors[$index]['reg_price'] = '登记价必须是数字类型';
|
||
}
|
||
if (!isset($detail['usage'])) {
|
||
$isSuccess = false;
|
||
$errors[$index]['usage'] = '物业用途未填';
|
||
}
|
||
if (!isset($detail['ownership_type'])) {
|
||
$errors[$index]['ownership_type'] = '产权人类型未填';
|
||
}
|
||
}
|
||
return $this->verifyResult($isSuccess, $errors);
|
||
}
|
||
|
||
|
||
/**
|
||
* 检查简易询价数据
|
||
*
|
||
* @param $type
|
||
* @param array $details
|
||
* @return array
|
||
*/
|
||
public function checkSimpleInquiry(array $data)
|
||
{
|
||
$isSuccess = true;
|
||
$errors = [];
|
||
|
||
if (!isset($data['type']) || !$data['type']) {
|
||
$isSuccess = false;
|
||
$errors[] = '业务类型必填';
|
||
}
|
||
|
||
if (!isset($data['client_name']) || !$data['client_name']) {
|
||
$isSuccess = false;
|
||
$errors[] = '委托人必填';
|
||
}
|
||
|
||
if (!isset($data['details']) || !$data['details']) {
|
||
$isSuccess = false;
|
||
$errors[] = '物业信息必填';
|
||
return $this->verifyResult($isSuccess, $errors);
|
||
}
|
||
|
||
$details = $data['details'];
|
||
foreach ($details as $index => $detail) {
|
||
//todo 城区检查
|
||
if (!isset($detail['building_name']) || !$detail['building_name']) {
|
||
$isSuccess = false;
|
||
$errors[$index]['building_name'] = '物业名称必填';
|
||
}
|
||
if (!isset($detail['building_no']) || $detail['building_no'] === false) {
|
||
$isSuccess = false;
|
||
$errors[$index]['building_no'] = '栋号必填';
|
||
}
|
||
if (!isset($detail['unit_no']) || !$detail['unit_no']) {
|
||
$isSuccess = false;
|
||
$errors[$index]['unit_no'] = '房号必填';
|
||
}
|
||
if (!isset($detail['size']) || !$detail['size']) {
|
||
$isSuccess = false;
|
||
$errors[$index]['size'] = '建筑面积必填';
|
||
}
|
||
}
|
||
return $this->verifyResult($isSuccess, $errors);
|
||
}
|
||
|
||
public function enOrderNo($order_no)
|
||
{
|
||
$pinyin = new Pinyin();
|
||
|
||
// 步骤1:分离中文字符与非中文字符
|
||
preg_match_all('/[\x{4e00}-\x{9fa5}]+|\d+/u', $order_no, $matches);
|
||
$parts = $matches[0];
|
||
|
||
// 步骤2:逐段处理
|
||
$result = '';
|
||
foreach ($parts as $part) {
|
||
if (preg_match('/^[\x{4e00}-\x{9fa5}]+$/u', $part)) {
|
||
// 中文部分 → 转大写首字母
|
||
$result .= strtoupper($pinyin->abbr($part, ''));
|
||
} else {
|
||
// 数字/英文部分 → 直接保留
|
||
$result .= $part;
|
||
}
|
||
}
|
||
return $result;
|
||
}
|
||
} |