384 lines
17 KiB
PHP
384 lines
17 KiB
PHP
<?php
|
||
|
||
|
||
namespace app\api\controller;
|
||
|
||
use app\admin\service\SurveyService;
|
||
use app\admin\service\InquiryService;
|
||
use app\common\validate\InquiryDetailValidate;
|
||
use app\common\validate\InquiryValidate;
|
||
use app\common\validate\SurveyValidate;
|
||
use app\admin\service\Zcdc;
|
||
use app\model\Inquiry as InquiryModel;
|
||
use app\util\ReturnCode;
|
||
use app\model\Report;
|
||
use think\Db;
|
||
|
||
class AppInquiry extends Base
|
||
{
|
||
|
||
/**
|
||
* @api {post} api/AppInquiry/save 提交询价
|
||
*/
|
||
public function save()
|
||
{
|
||
$data = $this->request->post();
|
||
|
||
$validate = new InquiryValidate();
|
||
if (!$validate->scene(InquiryValidate::APP_SCENE_CREATE)->batch()->check($data)) {
|
||
return $this->buildFailed('提交信息有误', $validate->getError());
|
||
}
|
||
$inquiryService = new InquiryService();
|
||
$verifyResult = $inquiryService->checkInquiryDetails($data['type'], $data['details']);
|
||
if ($verifyResult['is_success'] !== true) {
|
||
return $this->buildFailed('提交信息有误', $verifyResult['errors'], -2);
|
||
}
|
||
$inquiryService->createInquiry($data);
|
||
return $this->buildSuccess('询价成功');
|
||
}
|
||
|
||
/**
|
||
* @api {post} api/AppInquiry/simpleSave 提交简易询价
|
||
*/
|
||
public function simpleSave()
|
||
{
|
||
$data = $this->request->post();
|
||
|
||
if(!isset($data['user_id']) || !$data['user_id'] || !isset($data['user_name']) || !$data['user_name'] || !isset($data['user_phone']) || !isset($data['department_id']) || !isset($data['department_name'])){
|
||
return $this->buildFailed('参数有误', ReturnCode::EMPTY_PARAMS);
|
||
}
|
||
|
||
//验证
|
||
$inquiryService = new InquiryService();
|
||
$verifyResult = $inquiryService->checkSimpleInquiry($data);
|
||
if ($verifyResult['is_success'] !== true) {
|
||
return $this->buildFailed('提交信息有误', $verifyResult['errors'], -2);
|
||
}
|
||
|
||
$res = $inquiryService->createSimpleInquiry($data);
|
||
if($res['code'] == 1) return $this->buildSuccess();
|
||
return $this->buildFailed($res['code'], $res['msg']);
|
||
|
||
}
|
||
|
||
|
||
/**
|
||
* @api {post} api/AppInquiry/reqApplySurvey 发起查勘
|
||
*/
|
||
public function reqApplySurvey()
|
||
{
|
||
$order_no = $this->request->post('order_no');
|
||
$user_id = $this->request->post('user_id');
|
||
$user_name = $this->request->post('user_name');
|
||
$data = $this->request->post('details/a');
|
||
|
||
if (!$order_no || !$user_id || !$user_name || !$data)
|
||
return $this->buildFailed('参数错误');
|
||
//验证
|
||
$surveyService = new SurveyService();
|
||
$verifyResult = $surveyService->checkSurvey($data);
|
||
if ($verifyResult['is_success'] !== true) {
|
||
return $this->buildFailed($verifyResult['errors']);
|
||
}
|
||
|
||
$result = $surveyService->askSurvey(['order_no'=>$order_no, 'user_id'=>$user_id, 'user_name'=>$user_name, 'detail'=>$data]);
|
||
if ($result['code'] == -1) {
|
||
return $this->buildFailed($result['msg']);
|
||
}
|
||
return $this->buildSuccess('发起查勘成功');
|
||
}
|
||
|
||
|
||
/**
|
||
* @api {post} api/AppInquiry/reqPropertCertInfo 上传房产信息
|
||
*/
|
||
public function reqPropertCertInfo()
|
||
{
|
||
$data = $this->request->post();
|
||
$validate = new InquiryValidate();
|
||
if (!$validate->scene(InquiryValidate::SCENE_UPLOADATTACHMENTS)->batch()->check($data)) {
|
||
return $this->buildFailed($validate->getError());
|
||
}
|
||
|
||
$inquiryService = new InquiryService();
|
||
$isSuccess = $inquiryService->reqPropertCertInfo($data);
|
||
if (!$isSuccess) {
|
||
return $this->buildFailed('上传产证信息失败');
|
||
}
|
||
return $this->buildSuccess('上传产证信息成功');
|
||
}
|
||
|
||
/**
|
||
* @api {post} api/AppInquiry/reqNormalAdjustApprisePrice 正常调价
|
||
*/
|
||
public function reqNormalAdjustApprisePrice()
|
||
{
|
||
$data = $this->request->post();
|
||
$validate = new InquiryValidate();
|
||
if (!$validate->scene(InquiryValidate::SCENE_MODIFYPRICE)->batch()->check($data)) {
|
||
return $this->buildFailed('提交信息有误', $validate->getError());
|
||
}
|
||
$inquiryService = new InquiryService();
|
||
$result = $inquiryService->reqNormalAdjustApprisePrice($data);
|
||
if ($result['code'] == -1) {
|
||
return $this->buildFailed($result['msg']);
|
||
}
|
||
return $this->buildSuccess('正常调价成功');
|
||
}
|
||
|
||
/**
|
||
* 撤单
|
||
*/
|
||
public function cancel()
|
||
{
|
||
$data = $this->request->post();
|
||
$validate = new InquiryValidate();
|
||
if (!$validate->scene(InquiryValidate::SCENE_CANCEL)->batch()->check($data)) {
|
||
return $this->buildFailed('提交信息有误', $validate->getError());
|
||
}
|
||
$inquiryService = new InquiryService();
|
||
$isSuccess = $inquiryService->cancelInquiry($data['quot_id']);
|
||
if (!$isSuccess) {
|
||
return $this->buildFailed('撤单失败');
|
||
}
|
||
return $this->buildSuccess('成功');
|
||
}
|
||
|
||
/**
|
||
*提交查勘
|
||
* JA
|
||
*/
|
||
public function reqSubmitSurvey()
|
||
{
|
||
$data = $this->request->post();
|
||
$validate = new SurveyValidate();
|
||
if (!$validate->scene(SurveyValidate::SCENE_SUBMIT)->batch()->check($data)) {
|
||
return $this->buildFailed('数据验证失败', $validate->getError());
|
||
}
|
||
try {
|
||
$surveyService = new SurveyService();
|
||
if (!$surveyService->survey_detail($data['user_id'], $data, $data['action'])) {
|
||
return $this->buildFailed('保存失败');
|
||
}
|
||
return $this->buildSuccess();
|
||
} catch (\Exception $e) {
|
||
// \think\Log::error('错误文件:' . $e->getFile());
|
||
// \think\Log::error('错误行数:' . $e->getLine());
|
||
// \think\Log::error('错误代码:' . $e->getCode());
|
||
// \think\Log::error('错误信息:' . $e->getMessage());
|
||
return $this->output(-1, $e->getMessage());
|
||
}
|
||
|
||
}
|
||
|
||
/**
|
||
* 退回
|
||
* JA
|
||
*/
|
||
public function reqSubmitSurveyReturn()
|
||
{
|
||
$data = $this->request->post();
|
||
$validate = new SurveyValidate();
|
||
if (!$validate->scene(SurveyValidate::SCENE_RETURN)->batch()->check($data)) {
|
||
return $this->buildFailed('数据验证失败', $validate->getError());
|
||
}
|
||
try {
|
||
$surveyService = new SurveyService();
|
||
if (!$surveyService->return_survey($data['user_id'], $data)) {
|
||
return $this->buildFailed('退回失败');
|
||
}
|
||
return $this->buildSuccess();
|
||
|
||
} catch (\Exception $e) {
|
||
return $this->output(-1, $e->getMessage());
|
||
}
|
||
|
||
}
|
||
|
||
|
||
/**
|
||
* @api {post} api/AppInquiry/createReport 申请生成报告
|
||
*/
|
||
public function createReport()
|
||
{
|
||
// $user_id = $this->request->post('user_id');
|
||
// $user_name = $this->request->post('user_name');
|
||
|
||
// $quot_id = $this->request->post('quot_id');
|
||
// $print_cpy_no = $this->request->post('print_cpy_no');
|
||
// $details = $this->request->post('details/a');
|
||
// if (!$quot_id || !$details || !$print_cpy_no || !$user_id || !$user_name) return $this->buildFailed('参数错误');
|
||
|
||
// //验证
|
||
// $inquiryService = new InquiryService();
|
||
// $verifyResult = $inquiryService->checkcreateReport($details);
|
||
// if ($verifyResult['is_success'] !== true) {
|
||
// return $this->buildFailed('提交信息有误',$verifyResult['errors']);
|
||
// }
|
||
|
||
// $data['user_id'] = $user_id;
|
||
// $data['user_name'] = $user_name;
|
||
// $data['quot_id'] = $quot_id;
|
||
// $data['print_cpy_no'] = $print_cpy_no;
|
||
// $data['details'] = $details;
|
||
$data = $this->request->post();
|
||
//验证
|
||
$inquiryService = new InquiryService();
|
||
if($data['type'] == 1){ //保存操作 - 验证物业信息合法
|
||
$verifyResult = $inquiryService->checkcreateReportDraft($data);
|
||
}elseif($data['type'] == 2){ //提交操作 - 验证数据是否合法
|
||
$verifyResult = $inquiryService->checkcreateReport($data);
|
||
}
|
||
if ($verifyResult['is_success'] !== true) {
|
||
return $this->buildFailed('提交信息有误',$verifyResult['errors']);
|
||
}
|
||
|
||
|
||
|
||
$isSuccess = (new Report())->createReport($data);
|
||
if (!$isSuccess) {
|
||
return $this->buildFailed('申请生成报告失败');
|
||
}
|
||
return $this->buildSuccess();
|
||
}
|
||
|
||
// 重复询价的保存
|
||
public function reqQuotSubmitAgain(){
|
||
$flag = true;
|
||
$request_data = $this->request->post();
|
||
$validate = new InquiryValidate();
|
||
if (!$validate->scene(InquiryValidate::SCENE_CREATE)->batch()->check($request_data)) {
|
||
return $this->buildFailed('提交信息有误', $validate->getError());
|
||
}
|
||
$inquiryService = new InquiryService();
|
||
$verifyResult = $inquiryService->checkInquiryDetails($request_data['type'], $request_data['details']);
|
||
if ($verifyResult['is_success'] !== true) {
|
||
return $this->buildFailed('提交信息有误', $verifyResult['errors'], -2);
|
||
}
|
||
|
||
$period = getSystemConfig('INQUIRY_PERIOD'); // 询价时间范围
|
||
// $start_time_unix = time() - $period * 30 * 24 * 3600;
|
||
$start_time_unix = time() - $period * 24 * 3600; // 单位由月修改为天
|
||
|
||
$bank_id = $request_data['bank_id']; // 银行
|
||
$product_id = $request_data['product_id']; // 评估目的
|
||
$building_name = $request_data['details'][0]['building_name']; // 楼盘名称
|
||
$building_no = $request_data['details'][0]['building_no']; // 栋号
|
||
$unit_no = $request_data['details'][0]['unit_no']; // 房号
|
||
$is_tran_tax_free = $request_data['details'][0]['is_tran_tax_free']; // 是否满两年,1:是,2:否
|
||
$size = $request_data['details'][0]['size']; // 建筑面积
|
||
$reg_price = $request_data['details'][0]['reg_price']; // 登记价
|
||
$start_time = date('Y-m-d H:i:s', $start_time_unix);
|
||
$end_time = date('Y-m-d H:i:s');
|
||
|
||
$building_no = $building_no!='0'?$building_no:'';
|
||
$unit_no = $unit_no!='0'?$unit_no:'';
|
||
|
||
if (strpos($reg_price, ".")===false) {
|
||
$reg_price = sprintf("%.2f", $reg_price);
|
||
}
|
||
|
||
$where[] = ['i.status', '>', 1];
|
||
$where[] = ['i.create_time', 'between time', [$start_time, $end_time]];
|
||
$where[] = ['i.bank_id', '=', $bank_id];
|
||
$where[] = ['i.product_id', '=', $product_id];
|
||
$where[] = ['id.property_full_name', '=', trim($building_name).trim($building_no).trim($unit_no)];
|
||
$where[] = ['id.is_tran_tax_free', '=', $is_tran_tax_free];
|
||
$where[] = ['id.size', '=', $size];
|
||
$where[] = ['id.reg_price', '=', $reg_price];
|
||
|
||
Db::startTrans();
|
||
$result = Db::name('inquiry')
|
||
->alias('i')
|
||
->Join('property_cert_info id', 'i.id=id.quot_id')
|
||
->field('id.*')
|
||
->where($where)
|
||
->order('i.create_time desc')
|
||
->find();
|
||
|
||
$return_price_data = Db::name('return_price')
|
||
->where(['property_cert_info_id'=>$result['id']])
|
||
->order('id desc')
|
||
->find();
|
||
if ($result && $return_price_data) {
|
||
$inquiry = new InquiryModel();
|
||
$ins_inquiry_data = [];
|
||
$ins_inquiry_data['order_no'] = $inquiry->generateInquiryNo($request_data['branchCom_id']);
|
||
$ins_inquiry_data['user_id'] = $request_data['user_id'];
|
||
$ins_inquiry_data['user_name'] = $request_data['user_name'];
|
||
$ins_inquiry_data['user_phone'] = $request_data['user_phone'];
|
||
$ins_inquiry_data['bank_id'] = $request_data['bank_id'];
|
||
$ins_inquiry_data['bank_name'] = $request_data['bank_name'];
|
||
$ins_inquiry_data['bank_branch_id'] = $request_data['bank_branch_id'];
|
||
$ins_inquiry_data['bank_branch_name'] = $request_data['bank_branch_name'];
|
||
$ins_inquiry_data['bank_sub_id'] = $request_data['bank_sub_id'];
|
||
$ins_inquiry_data['bank_sub_name'] = $request_data['bank_sub_name'];
|
||
$ins_inquiry_data['bank_customer_mgr_id'] = $request_data['bank_customer_mgr_id'];
|
||
$ins_inquiry_data['bank_customer_mgr_name'] = $request_data['bank_customer_mgr_name'];
|
||
$ins_inquiry_data['bank_customer_mgr_phone'] = $request_data['bank_customer_mgr_phone'];
|
||
$ins_inquiry_data['eva_purpose'] = $request_data['eva_purpose'];
|
||
$ins_inquiry_data['product_id'] = $request_data['product_id'];
|
||
$ins_inquiry_data['type'] = $request_data['type'];
|
||
$ins_inquiry_data['status'] = 2;
|
||
$ins_inquiry_data['department_id'] = $request_data['department_id'];
|
||
$ins_inquiry_data['department_name'] = $request_data['department_name'];
|
||
$ins_inquiry_data['eva_detail_time_long'] = 0;
|
||
$ins_inquiry_data['create_time'] = date('Y-m-d H:i:s');
|
||
$ins_inquiry_data['update_time'] = date('Y-m-d H:i:s');
|
||
$ins_inquiry_result = Db::name('inquiry')->insert($ins_inquiry_data);
|
||
$quot_id = Db::name('inquiry')->getLastInsID();
|
||
|
||
$ins_inquiry_detail_data = [];
|
||
$ins_inquiry_detail_data['quot_id'] = $quot_id;
|
||
$ins_inquiry_detail_data['city'] = $result['city'];
|
||
$ins_inquiry_detail_data['city_id'] = $result['city_id'];
|
||
$ins_inquiry_detail_data['property_full_name'] = $result['property_full_name'];
|
||
$ins_inquiry_detail_data['building_name'] = $result['building_name'];
|
||
$ins_inquiry_detail_data['building_unit_no'] = $result['building_unit_no'];
|
||
$ins_inquiry_detail_data['building_no'] = $result['building_no'];
|
||
$ins_inquiry_detail_data['unit_no'] = $result['unit_no'];
|
||
$ins_inquiry_detail_data['size'] = $result['size'];
|
||
$ins_inquiry_detail_data['reg_price'] = $result['reg_price'];
|
||
$ins_inquiry_detail_data['is_tran_tax_free'] = $result['is_tran_tax_free'];
|
||
$ins_inquiry_detail_data['ownership_type'] = $request_data['details'][0]['ownership_type'];
|
||
$ins_inquiry_detail_data['usage'] = $request_data['details'][0]['usage'];
|
||
$ins_inquiry_detail_data['property_cert'] = $request_data['details'][0]['property_cert']?$request_data['details'][0]['property_cert']:NULL;
|
||
$ins_inquiry_detail_data['purchase_date'] = $request_data['details'][0]['purchase_date']?$request_data['details'][0]['purchase_date']:NULL;
|
||
$ins_inquiry_detail_data['completion_time'] = $request_data['details'][0]['completion_time']?$request_data['details'][0]['completion_time']:NULL;
|
||
$ins_inquiry_detail_data['land_location'] = $request_data['details'][0]['land_location']?$request_data['details'][0]['land_location']:'';
|
||
$ins_inquiry_detail_data['obligee'] = $request_data['details'][0]['obligee']?$request_data['details'][0]['obligee']:'';
|
||
$ins_inquiry_detail_data['remark'] = $request_data['details'][0]['remark']?$request_data['details'][0]['remark']:NULL;
|
||
$ins_inquiry_detail_data['attachments'] = $request_data['details'][0]['attachments']?$request_data['details'][0]['attachments']:NULL;
|
||
$ins_inquiry_detail_data['create_time'] = date('Y-m-d H:i:s');
|
||
$ins_inquiry_detail_data['update_time'] = date('Y-m-d H:i:s');
|
||
$ins_inquiry_detail_result = Db::name('property_cert_info')->insert($ins_inquiry_detail_data);
|
||
$property_cert_info = Db::name('property_cert_info')->getLastInsID();
|
||
|
||
$ins_return_price_data = $return_price_data;
|
||
$ins_return_price_data['id'] = '';
|
||
$ins_return_price_data['property_cert_info_id'] = $property_cert_info;
|
||
$ins_return_price_data['create_time'] = time();
|
||
$ins_return_price_result = Db::name('return_price')->insert($ins_return_price_data);
|
||
|
||
if ($ins_inquiry_result && $ins_inquiry_detail_result && $ins_return_price_result) {
|
||
Db::commit();
|
||
PublicMessage($quot_id,2,2);
|
||
} else {
|
||
$flag = false;
|
||
Db::rollback();
|
||
}
|
||
} else {
|
||
$flag = false;
|
||
Db::rollback();
|
||
}
|
||
|
||
if ($flag) {
|
||
return $this->buildSuccess('', '提交询价成功!');
|
||
} else {
|
||
return $this->buildFailed('提交询价失败!');
|
||
}
|
||
}
|
||
|
||
|
||
}
|