813 lines
39 KiB
PHP
813 lines
39 KiB
PHP
<?php
|
||
|
||
namespace app\admin\controller;
|
||
|
||
use app\model\Estimate as EstimateModel;
|
||
use app\model\Inquiry;
|
||
use app\model\Property_cert_info;
|
||
use app\model\ReturnPrice;
|
||
use app\model\Taxation;
|
||
use app\model\TaxationAuxiliary;
|
||
use app\util\Tools;
|
||
use think\Db;
|
||
use think\facade\Log;
|
||
|
||
class Estimate extends Base
|
||
{
|
||
public function exportEstimateExcel()
|
||
{
|
||
$start_date = input('start_date');
|
||
$end_date = input('end_date');
|
||
|
||
$dateInterval = date_diff(date_create($end_date), date_create($start_date));
|
||
$diff_month = $dateInterval->m;
|
||
$diff_day = $dateInterval->d;
|
||
|
||
if ($diff_month > 6 || ($diff_month == 6 && $diff_day > 0)) {
|
||
return $this->buildFailed('日期范围不能超过6个月');
|
||
}
|
||
|
||
Db::execute("SET @row_num = 0");
|
||
$list = Db::name('property_cert_info')->alias('pci')
|
||
->field("CAST(@row_num := @row_num + 1 AS CHAR) AS row_num, i.bank_name, i.buss_username, pci.property_full_name, ifnull(i.estimate_audit1_date, '') as estimate_audit1_date,
|
||
ifnull(i.estimate_audit_user_name, '') as estimate_audit_user_name")
|
||
->leftJoin("pg_inquiry i", "i.id = pci.quot_id")
|
||
->where("i.estimate_audit1_date >= '{$start_date} 00:00:00' and i.estimate_audit1_date <= '{$end_date} 23:59:59'")
|
||
->order("i.estimate_audit1_date asc")
|
||
// ->limit(1)
|
||
->select();
|
||
if (empty($list)) {
|
||
return $this->buildFailed('没有数据可以导出');
|
||
}
|
||
$indexKey = [
|
||
'row_num',
|
||
'bank_name',
|
||
'buss_username',
|
||
'property_full_name',
|
||
'estimate_audit1_date',
|
||
'estimate_audit_user_name'
|
||
];
|
||
$indexValue = [
|
||
'序号',
|
||
'银行',
|
||
'业务员',
|
||
'物业名称',
|
||
'确认日期',
|
||
'提交人'
|
||
];
|
||
|
||
return $this->buildSuccess([
|
||
'url' => exportExcel($list, 'estimate_' . date('YmdHis'), $indexKey, $indexValue),
|
||
]);
|
||
}
|
||
|
||
// 待制作
|
||
public function estimateList()
|
||
{
|
||
$paginate = $this->getPage();
|
||
$estimate_status = $this->request->post('estimate_status', '', 'trim'); //预估状态,1=待制作 2=二审待制作 3=三审待制作 4=待签章
|
||
$type = $this->request->post('type', '', 'trim'); //业务类型
|
||
$user_name = $this->request->post('user_name', '', 'trim'); //业务员
|
||
$response_username = $this->request->post('response_username', '', 'trim'); //回价员
|
||
$is_multiple = $this->request->post('is_multiple', '', 'trim'); //是否多套
|
||
$start_time = $this->request->post('start_time', '', 'trim'); //开始时间
|
||
$end_time = $this->request->post('end_time', '', 'trim'); //结束时间
|
||
$keyword = $this->request->post('keyword', '', 'trim'); //关键字,物业名称/预估单号
|
||
$city_id = $this->request->post('city_id', '', 'trim'); //城市
|
||
$bank_id = $this->request->post('bank_id', '', 'trim'); //银行id
|
||
$product_id = $this->request->post('product_id', '', 'trim'); //评估目的id
|
||
$internal_remarks = $this->request->post('internal_remarks', '', 'trim'); //内部备注
|
||
$start_size = $this->request->post('start_size', '', 'trim'); //面积起
|
||
$end_size = $this->request->post('end_size', '', 'trim'); //面积止
|
||
$issue_report = $this->request->post('issue_report', '', 'trim'); //是否出具报告
|
||
$is_signature = $this->request->post('is_signature', '', 'trim'); //是否已签章
|
||
$start_time_length = $this->request->post('start_time_length', '', 'trim'); //时间长度起
|
||
$end_time_length = $this->request->post('end_time_length', '', 'trim'); //时间长度止
|
||
|
||
$where = array();
|
||
$type && $where[] = ['i.type', '=', intval($type)];
|
||
// if ($issue_report == 1) { //是否出具报告
|
||
// $where[] = ['i.status', '=', 8];
|
||
// } elseif ($issue_report === 0) {
|
||
// $where[] = ['i.status', 'in', [2, 3, 4, 5, 6, 7], '_logic' => 'or'];
|
||
// } else {
|
||
// $where[] = ['i.status', 'in', [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], '_logic' => 'or'];
|
||
// }
|
||
$where[] = ['i.is_simple', '=', 0];
|
||
$where[] = ['i.estimate_status', '=', $estimate_status];
|
||
$start_time && $where[] = ['i.create_time', '>=', $start_time . " 00:00:00"];
|
||
$end_time && $where[] = ['i.create_time', '<=', $end_time . " 23:59:59"];
|
||
$is_multiple && $where[] = ['i.is_multiple', '=', $is_multiple];
|
||
$user_name && $where[] = ['i.buss_username', 'like', "%" . $user_name . "%"];
|
||
$keyword && $where[] = ['ii.property_full_name|i.estimated_no|i.business_no', 'like', "%" . $keyword . "%"];
|
||
$city_id && $where[] = ['ii.city_id', '=', $city_id]; //城市
|
||
$bank_id && $where[] = ['i.bank_id', '=', $bank_id]; //银行
|
||
$product_id && $where[] = ['i.product_id', '=', $product_id]; //评估目的
|
||
$start_size && $end_size && $where[] = getQuery('ii.size', $start_size, $end_size); //面积开始
|
||
$start_time_length && $end_time_length && $where[] = getQuery('i.eva_detail_time_long', $start_time_length, $end_time_length);
|
||
$is_signature && $where[] = ['i.seal_status', '=', $is_signature];
|
||
$response_username && $where[] = ['ii.appraiser_name', 'like', "%" . $response_username . "%"];
|
||
$internal_remarks && $where[] = ['ii.internal_remarks', 'like', "%{$internal_remarks}%"]; //内部备注
|
||
|
||
$Inquiry = new Inquiry();
|
||
$resultData = $Inquiry->alias("i")
|
||
->leftJoin('pg_property_cert_info ii', 'ii.quot_id=i.id')
|
||
->leftJoin('pg_boc_cf_inquiry_apply iii', 'iii.dealNo = i.business_no')
|
||
->field('i.id,
|
||
i.order_no,
|
||
i.business_no,
|
||
i.type,
|
||
i.is_multiple,
|
||
i.bank_name,
|
||
i.bank_branch_name,
|
||
i.bank_sub_name,
|
||
i.bank_customer_mgr_name,
|
||
i.estimated_no,
|
||
i.create_time,
|
||
i.buss_username,
|
||
i.user_name,
|
||
i.seal_status,
|
||
i.adjust_reason,
|
||
i.status,
|
||
i.eva_purpose,
|
||
i.loan_type,
|
||
i.eva_detail_time_long,
|
||
i.is_auto,
|
||
i.is_auto_eva,
|
||
i.estimate_audit_status,
|
||
i.estimate_audit1_date,
|
||
i.estimate_audit_user_name,
|
||
i.branchCom_id,
|
||
ii.id as did,
|
||
ii.quot_id,
|
||
ii.city,
|
||
ii.parcel_no,
|
||
ii.parcel_area,
|
||
ii.land_unit_price,
|
||
ii.floor_unit_price,
|
||
ii.reg_price,
|
||
ii.rid,
|
||
i.biz_status,
|
||
i.estimate_url,
|
||
i.bnkno,
|
||
i.tlrname,
|
||
i.is_send_estimate_to_boc,
|
||
i.estimate_status')
|
||
->where($where)
|
||
->group('i.id')
|
||
->order('i.id', 'desc')
|
||
->paginate($paginate)
|
||
->each(function ($item, $key) {
|
||
$inquiry_details = Db::name('property_cert_info')
|
||
->where('quot_id=' . $item['id'])
|
||
->field('
|
||
id,
|
||
property_full_name,
|
||
size,
|
||
parcel_no,
|
||
land_unit_price,
|
||
parcel_area,
|
||
floor_unit_price,
|
||
eva_unit_price,
|
||
eva_total_value,
|
||
internal_remarks,
|
||
risk_grade,
|
||
appraiser_name,
|
||
r_create_time AS appraiser_time
|
||
')
|
||
->select();
|
||
foreach ($inquiry_details as $key => $value) {
|
||
$return_price_count = Db::name('return_price')->where('property_cert_info_id=' . $inquiry_details[$key]['id'])->field('id')->count();
|
||
// 是否有调价
|
||
$item['is_adjusted_price'] = $return_price_count > 2 ? true : false;
|
||
}
|
||
|
||
if (count($inquiry_details) > 1) {
|
||
$item['property_full_name'] = implode(',', array_column($inquiry_details, 'property_full_name'));
|
||
$item['size'] = implode('/', array_column($inquiry_details, 'size'));
|
||
$item['eva_unit_price'] = implode('/', array_column($inquiry_details, 'eva_unit_price'));
|
||
$item['eva_total_value'] = implode('/', array_column($inquiry_details, 'eva_total_value'));
|
||
$item['internal_remarks'] = implode('/', array_column($inquiry_details, 'internal_remarks'));
|
||
$item['appraiser_name'] = implode('/', array_column($inquiry_details, 'appraiser_name'));
|
||
$item['risk_grade'] = implode('/', array_column($inquiry_details, 'risk_grade'));
|
||
$item['appraiser_time'] = implode('/', array_column($inquiry_details, 'appraiser_time'));
|
||
} elseif (count($inquiry_details) == 1) {
|
||
$item['property_full_name'] = $inquiry_details[0]['property_full_name'];
|
||
$item['size'] = $inquiry_details[0]['size'];
|
||
$item['eva_unit_price'] = $inquiry_details[0]['eva_unit_price'];
|
||
$item['eva_total_value'] = $inquiry_details[0]['eva_total_value'];
|
||
$item['internal_remarks'] = $inquiry_details[0]['internal_remarks'];
|
||
$item['appraiser_name'] = $inquiry_details[0]['appraiser_name'];
|
||
$item['risk_grade'] = $inquiry_details[0]['risk_grade'];
|
||
$item['appraiser_time'] = $inquiry_details[0]['appraiser_time'];
|
||
|
||
}
|
||
$detail_estate_name = explode(',', $item['property_full_name']);
|
||
$detail_appraiser_name = explode('/', $item['appraiser_name']);
|
||
$detail_appraise_level = explode('/', $item['risk_grade']);
|
||
$detail_appraiser_time = explode('/', $item['appraiser_time']);
|
||
$item['property_full_name'] = $detail_estate_name[0];
|
||
$item['appraiser_name'] = $detail_appraiser_name[0];
|
||
$item['risk_grade'] = (int)max($detail_appraise_level);
|
||
$item['appraiser_time'] = $detail_appraiser_time[0] ? date("Y-m-d H:i:s", $detail_appraiser_time[0]) : '';
|
||
$propertyDetails = [];
|
||
foreach ($inquiry_details as $key => $value) {
|
||
$propertyDetails[$key]['property_full_name'] = $value['property_full_name'];
|
||
$propertyDetails[$key]['internal_remarks'] = $value['internal_remarks'];
|
||
}
|
||
$item['propertyDetails'] = $propertyDetails;
|
||
// 是否出具报告
|
||
$item['issue_report'] = $item['status'] == 8 ? '已出具报告' : '否';
|
||
// 订单状态文字描述
|
||
$item['status_str'] = getDictionaryName('ORDER_STATUS', $item['status']);
|
||
|
||
// 自动估价,默认值
|
||
if ($item['is_auto'] == 1 && $item['is_auto_eva'] == 1) {
|
||
$item['appraiser_name'] = '自动估价';
|
||
$item['appraiser_time'] = $item['create_time'];
|
||
}
|
||
|
||
// 如果预估未审核,则不显示预估单号
|
||
// $item['estimated_no'] = ($item['estimate_audit_status'] == self::ALREADY_ESTIMATE_AUDIT) ? $item['estimated_no'] : "";
|
||
$item['bank'] = $item['bank_name'];
|
||
$item['bank_name'] = $item['bank_sub_name'] ? $item['bank_name'] . $item['bank_sub_name'] : $item['bank_name'];
|
||
$item['export_create_time'] = date('Y-m-d', strtotime($item['create_time']));
|
||
return $item;
|
||
})
|
||
->toArray();
|
||
|
||
return $this->buildSuccess($resultData);
|
||
}
|
||
|
||
// 预估取号
|
||
public function getEstimateNo()
|
||
{
|
||
$id = $this->request->post('id', '', 'trim');
|
||
if (empty($id)) {
|
||
return $this->buildFailed('缺少询价ID');
|
||
}
|
||
|
||
$inquiryInfo = Db::name('inquiry')->where('id', $id)->find();
|
||
if (empty($inquiryInfo)) {
|
||
return $this->buildFailed("询价单不存在");
|
||
}
|
||
|
||
if (empty($inquiryInfo['estimated_no'])) {
|
||
$estimated_no = '';
|
||
$generate_estimated_info = Tools::generateNo($id, Tools::GENERATE_TYPE_ESTIMATE);
|
||
if ($generate_estimated_info['code'] == 0) {
|
||
$estimated_no = $generate_estimated_info['data'];
|
||
}
|
||
$update_data['estimated_no'] = $estimated_no; // 生成预估号
|
||
}
|
||
$estimate_qrcode_unique_key = md5(uniqid());
|
||
$estimated_qrcode_content = env("uploadFile.qrcode_url") . "/index.php/admin/Pending/getAnticounterfeitPage?quot_id=" .
|
||
$id . '&key=' . $estimate_qrcode_unique_key;
|
||
Log::error('estimated_qrcode_content:' . $estimated_qrcode_content);
|
||
$qrcode_oss_url = Tools::createQRCode($estimated_qrcode_content);
|
||
if (!empty($qrcode_oss_url)) {
|
||
$update_data['estimated_qrcode_url'] = $qrcode_oss_url;
|
||
}
|
||
$update_data['estimate_qrcode_unique_key'] = $estimate_qrcode_unique_key;
|
||
|
||
$re = Db::name('inquiry')->where("id", $id)->update($update_data);
|
||
|
||
if (!$re) {
|
||
return $this->buildFailed("预估取号失败");
|
||
}
|
||
|
||
return $this->buildSuccess();
|
||
}
|
||
|
||
public function submit()
|
||
{
|
||
$id = $this->request->post('id', '', 'trim');
|
||
$estimated_desc = $this->request->post('estimated_desc', '', 'trim');
|
||
$appraiser_id = $this->request->post('appraiser_id', '', 'trim');
|
||
$appraiser_name = $this->request->post('appraiser_name', '', 'trim');
|
||
$json_data = $this->request->post('json_data', '', 'trim');
|
||
$return_price_attachments = $this->request->post('return_price_attachments', '', 'trim');
|
||
|
||
if (!$id) {
|
||
return $this->buildFailed("缺少参数询价单主表id");
|
||
}
|
||
if (!$json_data) {
|
||
return $this->buildFailed("缺少参数回价详情信息");
|
||
}
|
||
|
||
//判断json数据字段不能为空
|
||
$result = $this->Verification($json_data, $id);
|
||
if ($result !== true) {
|
||
Log::error("json数据有误:" . $result);
|
||
return $this->buildFailed($result);
|
||
}
|
||
|
||
$Inquiry = new Inquiry();
|
||
$Property_cert_info = new Property_cert_info();
|
||
$ReturnPrice = new ReturnPrice(); // 回价表
|
||
|
||
Db::startTrans();
|
||
|
||
$inquiryInfo = $Inquiry->where("id", $id)
|
||
->field('
|
||
order_no,
|
||
status,
|
||
create_time,
|
||
seal_status,
|
||
eva_detail_time_long,
|
||
is_auto,
|
||
bank_id,
|
||
bank_name,
|
||
bank_branch_id,
|
||
bank_branch_name,
|
||
bank_sub_id,
|
||
bank_sub_name,
|
||
type,
|
||
estimated_no,
|
||
business_no,
|
||
bank_customer_mgr_id,
|
||
branchCom_id,
|
||
eva_purpose,
|
||
product_id,
|
||
loan_type,
|
||
estimate_qrcode_unique_key
|
||
')
|
||
->find();
|
||
if (empty($inquiryInfo)) return $this->buildFailed("询价单不存在");
|
||
|
||
$inquiry_data = [];
|
||
foreach ($json_data as $k => $v) {
|
||
$tax_items = implode(",", $v['tax_items']); // 选择税费项目
|
||
$insert_date = array();
|
||
$insert_date['property_cert_info_id'] = $v['id'];
|
||
$insert_date['building_no'] = trim($v['building_no']);
|
||
$insert_date['unit_no'] = trim($v['unit_no']);
|
||
$insert_date['building_unit_no'] = (empty($v['building_no']) || trim($v['building_no']) == '0') ? $v['unit_no'] : $v['building_no'] . $v['unit_no'];
|
||
$insert_date['property_name'] = trim($v['building_name']) . $insert_date['building_unit_no'];
|
||
$insert_date['area'] = $v['size'];
|
||
$insert_date['eva_unit_price'] = $v['eva_unit_price'];
|
||
$insert_date['market_price'] = $v['market_price'];
|
||
$insert_date['guide_price'] = $v['guide_price'];
|
||
$insert_date['eva_total_value'] = $v['eva_total_value'];
|
||
$insert_date['risk_grade'] = $v['risk_grade'];
|
||
$insert_date['corporate_income_tax'] = $v['corporate_income_tax'];
|
||
$insert_date['tran_service_fee'] = $v['tran_service_fee'];
|
||
$insert_date['edu_surcharge'] = $v['edu_surcharge'];
|
||
$insert_date['urban_construction_tax'] = $v['urban_construction_tax'];
|
||
$insert_date['deed_tax'] = $v['deed_tax'];
|
||
$insert_date['stamp_duty'] = $v['stamp_duty'];
|
||
$insert_date['added_tax'] = $v['added_tax'];
|
||
$insert_date['land_value_added_tax'] = $v['land_value_added_tax'];
|
||
$insert_date['land_value_added_tax_copy'] = (array_key_exists("land_value_added_tax_copy", $v)) ? $v['land_value_added_tax_copy'] : 0;
|
||
$insert_date['personal_income_tax'] = $v['personal_income_tax'];
|
||
$insert_date['personal_income_tax_copy'] = $v['personal_income_tax_copy'];
|
||
$insert_date['auction_fee'] = $v['auction_fee'];
|
||
$insert_date['total_taxes1'] = $v['total_taxes1'];
|
||
$insert_date['total_taxes2'] = $v['total_taxes2'];
|
||
$insert_date['loan_ratio'] = $v['loan_ratio'];
|
||
$insert_date['gross_value'] = $v['gross_value'];
|
||
$insert_date['eva_net_value'] = $v['eva_net_value'];
|
||
$insert_date['eva_net_value2'] = $v['eva_net_value2'];
|
||
$insert_date['internal_remarks'] = $v['internal_remarks'];
|
||
$insert_date['external_remarks'] = $v['external_remarks'];
|
||
$insert_date['pricing_remarks'] = $v['pricing_remarks'];
|
||
$insert_date['tax_items'] = $tax_items;
|
||
$insert_date['tips'] = $v['tips'];
|
||
$insert_date['appraiser_id'] = $appraiser_id; // 评估师id
|
||
$insert_date['appraiser_name'] = $appraiser_name; // 评估师名称
|
||
$insert_date['create_time'] = time();
|
||
$insert_date['total_guide_tax'] = $v['guide_total_value'] ?? 0; // 参考总值(参考单价*面积) - 参考净值 = 参考税费
|
||
$rp_ins = $ReturnPrice->insert($insert_date); // 插入回价表
|
||
if (!$rp_ins) {
|
||
Db::rollback();
|
||
return $this->buildFailed('回价信息保存失败!');
|
||
}
|
||
$rid = $ReturnPrice->getLastInsID();
|
||
|
||
$p_date['city'] = $v['city'];
|
||
$p_date['city_id'] = $v['city_id'];
|
||
$p_date['building_no'] = $insert_date['building_no'];
|
||
$p_date['unit_no'] = $insert_date['unit_no'];
|
||
$p_date['building_unit_no'] = $insert_date['building_unit_no'];
|
||
$p_date['building_name'] = trim($v['building_name']);
|
||
$p_date['property_full_name'] = $p_date['building_name'] . $p_date['building_unit_no'];
|
||
$p_date['property_cert'] = $v['property_cert'];
|
||
$p_date['purchase_date'] = !empty($v['purchase_date']) ? $v['purchase_date'] : null;
|
||
$p_date['completion_time'] = !empty($v['completion_time']) ? $v['completion_time'] : null;
|
||
$p_date['land_location'] = !empty($v['land_location']) ? $v['land_location'] : '';
|
||
$p_date['obligee'] = !empty($v['obligee']) ? $v['obligee'] : '';
|
||
$p_date['is_tran_tax_free'] = $v['is_tran_tax_free'];
|
||
$p_date['ownership_type'] = $v['ownership_type'];
|
||
$p_date['usage'] = $v['usage'] ?? null;
|
||
$p_date['cert_usage'] = $v['cert_usage'] ?? null;
|
||
$p_date['use_right_source'] = $v['use_right_source'] ?? null;
|
||
$p_date['size'] = $v['size'];
|
||
$p_date['reg_price'] = $v['reg_price'];
|
||
$p_date['remark'] = $v['remark'];
|
||
$p_date['attachments'] = !empty($v['attachments']) ? implode(",", $v['attachments']) : "";
|
||
$p_date['update_time'] = date("Y-m-d H:i:s", time());
|
||
$p_date['tax_type'] = $v['tax_type'] ?? null;
|
||
$p_date['statutory_payment'] = $v['statutory_payment'];
|
||
$p_date['rid'] = $rid;
|
||
$p_date['risk_grade'] = $v['risk_grade'];
|
||
$p_date['r_create_time'] = $insert_date['create_time'];
|
||
$p_date['eva_unit_price'] = $v['eva_unit_price'];
|
||
$p_date['eva_total_value'] = $v['eva_total_value'];
|
||
$p_date['eva_net_value'] = $v['eva_net_value'];
|
||
$p_date['eva_net_value2'] = $v['eva_net_value2'];
|
||
$p_date['total_taxes1'] = $v['total_taxes1'];
|
||
$p_date['total_taxes2'] = $v['total_taxes2'];
|
||
$p_date['internal_remarks'] = $v['internal_remarks'];
|
||
$p_date['reference_price'] = $v['reference_price'] ?? 0;
|
||
$p_date['transaction_total_price'] = $v['transaction_total_price'] ?? 0;
|
||
$p_date['transaction_gross_area'] = $v['transaction_gross_area'] ?? 0;
|
||
$p_date['transaction_date'] = !empty($v['transaction_date']) ? $v['transaction_date'] : NULL;
|
||
|
||
$p_info = $Property_cert_info->where("id", $v['id'])->find();
|
||
if (empty($p_info)) {
|
||
Db::rollback();
|
||
return $this->buildFailed('物业信息不存在!');
|
||
}
|
||
if ($p_info['adjust_status'] == 1) {
|
||
$p_date['adjust_status'] = 2; // 修改调价状态
|
||
}
|
||
if (empty($p_info['appraiser_id']) && empty($p_info['appraiser_name'])) {
|
||
$p_date['appraiser_id'] = $appraiser_id;
|
||
$p_date['appraiser_name'] = $appraiser_name;
|
||
}
|
||
|
||
$ind_upd = $Property_cert_info->where("id", $v['id'])->update($p_date); // 修改物业表
|
||
if (!$ind_upd) {
|
||
Db::rollback();
|
||
return $this->buildFailed('询价详情信息更新失败!');
|
||
}
|
||
|
||
// 2021年6月自动估价系统重新开发重写
|
||
if ($inquiryInfo['is_auto'] == 1) {
|
||
$inquiry_data['is_auto_eva'] = 0;
|
||
$data = [
|
||
'order_no' => $inquiryInfo['order_no'],
|
||
'user_name' => $p_info['appraiser_name'],
|
||
'price' => round($insert_date['eva_unit_price'] / 10) * 10,
|
||
'eva_total_value' => round(round($insert_date['eva_unit_price'] / 10) * 10 * $v['size']),
|
||
'net_one' => $insert_date['eva_net_value'],
|
||
'net_two' => $insert_date['eva_net_value2'],
|
||
'tax_one' => $insert_date['total_taxes1'],
|
||
'tax_two' => $insert_date['total_taxes2'],
|
||
'guide_price' => round($insert_date['guide_price'] / 10) * 10,
|
||
'external_remarks' => $insert_date['external_remarks'],
|
||
'gross_value' => $insert_date['gross_value'],
|
||
'estimates_url' => !empty($inquiryInfo['estimated_no']) ? env('uploadFile.evaluate_host_url') . '/admin/Pending/EstimateSheetTemplate?estimated_no=' . $inquiryInfo['estimated_no'] . '&branchCom_id=' . $inquiryInfo['branchCom_id'] : '',
|
||
'estimates_no' => !empty($inquiryInfo['estimated_no']) ? $inquiryInfo['estimated_no'] : '',
|
||
];
|
||
$this->updEvaluateInquiry($data);
|
||
}
|
||
}
|
||
$status = $inquiryInfo['status'];
|
||
if ($status == 1) {
|
||
$inquiry_data['status'] = 2;
|
||
}
|
||
|
||
$seal_status = $inquiryInfo['seal_status'];
|
||
if ($seal_status == 1 || ($seal_status == 2 && $inquiryInfo['is_auto'] == 1)) {
|
||
$inquiry_data['estimated_desc'] = $estimated_desc;
|
||
}
|
||
|
||
// 更新询价信息
|
||
$inquiry_data['update_time'] = date('Y-m-d H:i:s');
|
||
$inquiry_data['return_price_attachments'] = !empty($return_price_attachments) ? implode(",", $return_price_attachments) : null;
|
||
|
||
$in_upd = $Inquiry->where("id", $id)->update($inquiry_data);
|
||
if (!$in_upd) {
|
||
Db::rollback();
|
||
return $this->buildFailed('询价信息更新失败!');
|
||
}
|
||
|
||
Db::commit();
|
||
return $this->buildSuccess();
|
||
}
|
||
|
||
// 提交审核
|
||
public function submitVerify()
|
||
{
|
||
$opt_type = $this->request->post('opt_type', '', 'trim'); //审核操作类型,1=待制作提交到二审 2=二审提交到三审 3=三审提交到待签章
|
||
$id = $this->request->post('id', '', 'trim');
|
||
|
||
if (!$id) {
|
||
return $this->buildFailed("缺少参数询价单主表id");
|
||
}
|
||
|
||
if (!in_array($opt_type, [1, 2, 3])) {
|
||
return $this->buildFailed("操作有误");
|
||
}
|
||
|
||
$Inquiry = new Inquiry();
|
||
|
||
$inquiryInfo = $Inquiry->where("id", $id)
|
||
->field('estimated_no')
|
||
->find();
|
||
if (empty($inquiryInfo)) return $this->buildFailed("询价单不存在");
|
||
|
||
$inquiry_data = [];
|
||
|
||
// 更新询价信息
|
||
$inquiry_data['update_time'] = date('Y-m-d H:i:s');
|
||
|
||
if ($opt_type == 1) { //待制作提交到二审
|
||
if (!$inquiryInfo['estimated_no']) {
|
||
return $this->buildFailed("请先进行预估取号操作");
|
||
}
|
||
$inquiry_data['status'] = 10;
|
||
$inquiry_data['estimate_status'] = 2;
|
||
$inquiry_data['estimate_make_user_id'] = $this->userInfo['user_id'];
|
||
$inquiry_data['estimate_make_user_name'] = $this->userInfo['user_name'];
|
||
$inquiry_data['estimate_make_datetime'] = date('Y-m-d H:i:s');
|
||
} else if ($opt_type == 2) { //二审提交到三审
|
||
$inquiry_data['estimate_status'] = 3;
|
||
$inquiry_data['estimate_second_verify_user_id'] = $this->userInfo['user_id'];
|
||
$inquiry_data['estimate_second_verify_user_name'] = $this->userInfo['user_name'];
|
||
$inquiry_data['estimate_second_verify_datetime'] = date('Y-m-d H:i:s');
|
||
} else { //三审提交到待签章
|
||
$inquiry_data['status'] = 11;
|
||
$inquiry_data['estimate_status'] = 4;
|
||
$inquiry_data['estimate_third_verify_user_id'] = $this->userInfo['user_id'];
|
||
$inquiry_data['estimate_third_verify_user_name'] = $this->userInfo['user_name'];
|
||
$inquiry_data['estimate_third_verify_datetime'] = date('Y-m-d H:i:s');
|
||
$inquiry_data['seal_status'] = 1;
|
||
}
|
||
|
||
$in_upd = $Inquiry->where("id", $id)->update($inquiry_data);
|
||
if (!$in_upd) {
|
||
return $this->buildFailed('操作失败!');
|
||
}
|
||
return $this->buildSuccess();
|
||
}
|
||
|
||
public function returnEstimate()
|
||
{
|
||
$quot_id = $this->request->post('quot_id', '', 'trim');
|
||
if (empty($quot_id)) return $this->buildFailed('缺少询价id');
|
||
|
||
$inquiry_info = Db::name('inquiry')->where('id', $quot_id)->find();
|
||
if (empty($inquiry_info)) return $this->buildFailed('询价信息不存在');
|
||
|
||
//退回统一退回到待制作,签了章的也得去掉
|
||
$update_data['status'] = 9;
|
||
$update_data['estimate_status'] = 1;
|
||
$update_data['seal_status'] = 1;
|
||
$update_data['seal_time'] = NULL;
|
||
$update_data['appraiser_ids'] = NULL;
|
||
$update_data['estimate_make_user_id'] = NULL;
|
||
$update_data['estimate_make_user_name'] = NULL;
|
||
$update_data['estimate_make_datetime'] = NULL;
|
||
$update_data['estimate_second_verify_user_id'] = NULL;
|
||
$update_data['estimate_second_verify_user_name'] = NULL;
|
||
$update_data['estimate_second_verify_datetime'] = NULL;
|
||
$update_data['estimate_third_verify_user_id'] = NULL;
|
||
$update_data['estimate_third_verify_user_name'] = NULL;
|
||
$update_data['estimate_third_verify_datetime'] = NULL;
|
||
$res = Db::name('inquiry')->where('id', $quot_id)->update($update_data);
|
||
if ($res === false) {
|
||
return $this->buildFailed('退回失败');
|
||
}
|
||
return $this->buildSuccess();
|
||
}
|
||
|
||
/**
|
||
* 验证回价信息不要字段不能为空
|
||
* @author zcx
|
||
*
|
||
* @parameter $json 回价数组信息
|
||
*
|
||
*/
|
||
public function Verification($json = array(), $id = "")
|
||
{
|
||
if (empty($json)) {
|
||
return $this->buildFailed("缺少回价信息");
|
||
}
|
||
$Inquiry = new Inquiry();
|
||
$Taxation = new Taxation();
|
||
$TaxationAuxiliary = new TaxationAuxiliary();
|
||
|
||
foreach ($json as $k => $v) {
|
||
if (!array_key_exists("tax_items", $v)) {
|
||
return "请选择需要计算的税费";
|
||
}
|
||
$tax_items_arr = $v['tax_items'];
|
||
if (!array_key_exists("id", $v)) {
|
||
return "缺少询价单详情表id";
|
||
} else if (!array_key_exists("building_name", $v)) {
|
||
return "缺少物业名称";
|
||
} else if ($v['reg_price'] < 0) {
|
||
return "登记价不能小于0";
|
||
} else if (!array_key_exists("size", $v)) {
|
||
return "缺少建筑面积";
|
||
} else if (!array_key_exists("building_no", $v)) {
|
||
return "缺少栋号";
|
||
} else if (!array_key_exists("unit_no", $v)) {
|
||
return "缺少房号";
|
||
} else if (!array_key_exists("eva_unit_price", $v)) {
|
||
return "缺少评估单价";
|
||
} else if (!array_key_exists("eva_total_value", $v)) {
|
||
return "缺少评估总值";
|
||
} else if (!array_key_exists("eva_net_value", $v)) {
|
||
return "缺少评估净值";
|
||
} else if (!array_key_exists("eva_net_value2", $v)) {
|
||
return "缺少评估净值2";
|
||
} else if (!array_key_exists("total_taxes1", $v)) {
|
||
return "缺少税费合计1";
|
||
} else if (!array_key_exists("total_taxes2", $v)) {
|
||
return "缺少税费合计2";
|
||
} else if (!array_key_exists("gross_value", $v)) {
|
||
return "缺少总值";
|
||
} else if (!array_key_exists("eva_net_value", $v)) {
|
||
return "缺少净值";
|
||
} else if (!array_key_exists("eva_net_value2", $v)) {
|
||
return "缺少净值2";
|
||
} else if (!array_key_exists("tax_items", $v)) {
|
||
return "缺少选中税费项目";
|
||
}
|
||
if (!empty($v['tax_items'])) {
|
||
foreach ($v['tax_items'] as $kt => $vt) {
|
||
$t_key = $TaxationAuxiliary->where("id", $vt)->field("name,key")->find();
|
||
if (!empty($t_key)) {
|
||
if (!array_key_exists($t_key["key"], $v)) {
|
||
return "缺少" . $t_key['name'] . "值";
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
// 2021年6月自动估价系统重新开发重写
|
||
public function updEvaluateInquiry($data)
|
||
{
|
||
$url = env('evaluate.el_api') . '/api/Inquiry/personReviewNotification';
|
||
$time = time();
|
||
$header = [
|
||
'appkey:' . env('evaluate.appkey'),
|
||
'timestamp:' . $time,
|
||
'sign:' . md5(env('evaluate.appkey') . env('evaluate.appsecret') . $time),
|
||
];
|
||
trace('header:');
|
||
trace($header);
|
||
trace('url:');
|
||
trace($url);
|
||
trace('data:');
|
||
trace($data);
|
||
$res = $this->http_post($url, $data, 30, $header);
|
||
trace('res:');
|
||
trace($res);
|
||
}
|
||
|
||
public function subFinish()
|
||
{
|
||
$data = $this->request->post();
|
||
if (empty($data['reportid'])) return $this->buildFailed('报告id不能为空!');
|
||
|
||
//验证信息
|
||
$reportValidate = new ReportValidate();
|
||
if (!$reportValidate->scene('addReport')->check($data)) {
|
||
return $this->buildFailed($reportValidate->getError());
|
||
}
|
||
|
||
$reportModel = new Report();
|
||
$res = $reportModel->field('status,quot_id,print_cpy_no,review_status,review2_status,update_time')->where('id', $data['reportid'])->find();
|
||
if (empty($res)) return $this->buildFailed('找不到报告');
|
||
if ($res['update_time'] !== $data['update_time']) return $this->buildFailed('该订单报告已被修改,请重新审核');
|
||
if ($res['status'] != 2) return $this->buildFailed('请确认该订单报告的状态,目前非待审核状态');
|
||
if ($res['status'] == 3) return $this->buildFailed('该订单报告已完成');
|
||
|
||
$flag = false;
|
||
// if ($res['review_status']==2 || $res['review2_status']==2) {
|
||
// $flag = true;
|
||
// }
|
||
|
||
if ($data['ctype'] == 2) {
|
||
$data['review_status'] = 2;
|
||
} elseif ($data['ctype'] == 3) {
|
||
$flag = true;
|
||
$data['review2_status'] = 2;
|
||
$serverIP = env("uploadFile.qrcode_url");
|
||
|
||
// 生成二维码值(腾讯云登记域名)
|
||
$report_qrcode_unique_key = md5(uniqid());
|
||
$qrvalue = $serverIP . "/index.php/admin/ReportManage/getAnticounterfeitPage?quot_id=" . $data['quot_id'] . '&key=' . $report_qrcode_unique_key;
|
||
$data['report_qrcode_unique_key'] = $report_qrcode_unique_key;
|
||
|
||
// 创建二维码
|
||
$url = Tools::createQRCode($qrvalue);
|
||
if (!empty($url)) {
|
||
$data['report_qrcode'] = $url; //报告防伪码
|
||
$data['qrvalue'] = $qrvalue;
|
||
$data['qrurl'] = $url;
|
||
}
|
||
|
||
// 生成pdf报告并上传到cos
|
||
}
|
||
|
||
$bank_name = Db::name('inquiry')->where('id', $res['quot_id'])->value('bank_name');
|
||
if ($bank_name != '中国光大银行') {
|
||
unset($data['ceb_product_type']);
|
||
}
|
||
|
||
if ($flag) {
|
||
$data['completion_time'] = time();
|
||
$data['status'] = 3;//完成
|
||
//打印数量大于等于1时,线下报告状态为待装订打印
|
||
if ($res['print_cpy_no'] >= 1) {
|
||
$data['offline_report_status'] = 1;//待装订打印
|
||
}
|
||
|
||
if ($bank_name == '中国建设银行') {
|
||
$data['seal_status'] = 1;//盖章状态 1待盖章
|
||
}
|
||
|
||
Db::startTrans();
|
||
try {
|
||
//更新询单状态
|
||
Db::name('inquiry')->where('id', $res['quot_id'])->update(['status' => 8, 'update_time' => date('Y-m-d H:i:s', time())]);
|
||
|
||
//生成费用
|
||
$ChargeController = new ChargeController();
|
||
$resultCharge = $ChargeController->insReportData($data['reportid']);
|
||
if (!empty($resultCharge) && $resultCharge['result'] != true) {
|
||
// 回滚事务
|
||
Db::rollback();
|
||
return $this->buildFailed($resultCharge['msg']);
|
||
}
|
||
$data['appraiser_name'] = Db::name('valuer')->where('id', $data['appraiser_id'])->value('name');
|
||
$data['appraiser2_name'] = Db::name('valuer')->where('id', $data['appraiser2_id'])->value('name');
|
||
if (!empty($data['attachment_ids'])) {
|
||
$data['attachment_ids'] = implode(',', $data['attachment_ids']);
|
||
}
|
||
if (!empty($data['market_background'])) {
|
||
$data['market_background'] = implode(',', $data['market_background']);
|
||
}
|
||
$data['update_time'] = date('Y-m-d H:i:s');
|
||
$result = $reportModel->allowField(true)->save($data, ['id' => $data['reportid']]);
|
||
if (!$result) {
|
||
// 回滚事务
|
||
Db::rollback();
|
||
return $this->buildFailed('提交报告数据失败');
|
||
}
|
||
|
||
if ($data['ctype'] == 3) {
|
||
Log::debug('生成报告1');
|
||
/*SyncHttpService::post('admin/ReportManage/produceReport', [
|
||
'report_id' => $data['reportid'],
|
||
'cur_tmpl_id' => $data['cur_tmpl_id'],
|
||
]);*/
|
||
if (!$this->produceReport($data['reportid'], $data['cur_tmpl_id'])) {
|
||
return $this->buildFailed('报告制作失败');
|
||
}
|
||
}
|
||
|
||
//写入消息
|
||
PublicMessage($res['quot_id'], 2, 11);
|
||
|
||
Db::commit();
|
||
|
||
|
||
return $this->buildSuccess();
|
||
} catch (\Exception $e) {
|
||
// 回滚事务
|
||
Db::rollback();
|
||
return $this->buildFailed('提交报告数据失败' . $e->getMessage(), '文件:' . $e->getFile() . ' 行数:' . $e->getLine());
|
||
}
|
||
} else {
|
||
Db::startTrans();
|
||
try {
|
||
$data['appraiser_name'] = Db::name('valuer')->where('id', $data['appraiser_id'])->value('name');
|
||
$data['appraiser2_name'] = Db::name('valuer')->where('id', $data['appraiser2_id'])->value('name');
|
||
if (!empty($data['attachment_ids'])) {
|
||
$data['attachment_ids'] = implode(',', $data['attachment_ids']);
|
||
}
|
||
if (!empty($data['market_background'])) {
|
||
$data['market_background'] = implode(',', $data['market_background']);
|
||
}
|
||
$data['update_time'] = date('Y-m-d H:i:s');
|
||
$result = $reportModel->allowField(true)->save($data, ['id' => $data['reportid']]);
|
||
if (!$result) {
|
||
// 回滚事务
|
||
Db::rollback();
|
||
return $this->buildFailed('提交报告数据失败');
|
||
}
|
||
|
||
//写入消息
|
||
PublicMessage($res['quot_id'], 2, 11);
|
||
|
||
Db::commit();
|
||
return $this->buildSuccess();
|
||
} catch (\Exception $e) {
|
||
// 回滚事务
|
||
Db::rollback();
|
||
return $this->buildFailed('提交报告数据失败' . $e->getMessage());
|
||
}
|
||
}
|
||
}
|
||
|
||
} |