postData = $this->request->post(); return true; } //待制作报告管理列表页面 public function reqProducingReportList(){ $where = $this->listWhere(1); $field = 'r.id as reporid,i.order_no,r.report_no,d.id as property_cert_info_id,d.city,i.type,i.is_multiple,i.bank_sub_name,i.bank_name,r.e_case_code,i.create_time,i.buss_username,r.status,i.id as quot_id,p.eva_unit_price,p.eva_total_value,r.create_time as report_add_time,i.eva_purpose'; $subsql = Db::table('pg_return_price') ->field('property_cert_info_id,create_time,eva_unit_price,eva_unit_price,eva_total_value,eva_net_value') ->group('property_cert_info_id')->order('property_cert_info_id', 'desc')->buildSql(); $list = \Db::name('report') ->alias('r') ->join('inquiry i','r.quot_id=i.id') ->join('property_cert_info d','i.id=d.quot_id') // ->join([$subsql => 'p'], 'd.id = p.property_cert_info_id', 'left') ->join('return_price p', 'd.id = p.property_cert_info_id', 'left') ->where($where) ->field($field) // ->order('r.create_time', 'desc') ->order('r.create_time desc,p.id desc') ->group('d.quot_id') ->paginate($this->getPage()) ->each(function ($item, $key){ $item['type_str'] = getDictionaryName('BUSINESS_TYPE', $item['type']); $item['is_multi_str'] = getDictionaryName('INQUIRY_NUMBER', $item['is_multiple']); $item['bank_name'] = !empty($item['bank_name']) && !empty($item['bank_sub_name']) ? $item['bank_name'] . $item['bank_sub_name'] : $item['bank_name']; $full_estate_name_info = Db::name('property_cert_info') ->where('quot_id', $item['quot_id']) ->field('id,property_full_name,size') ->order('id', 'desc') ->select(); $eva_unit_price = []; $appraiser_name = []; $item['eva_total_value'] = 0; foreach ($full_estate_name_info as $key=>$value) { $return_price_res = Db::name('return_price') ->where('property_cert_info_id='.$value['id']) ->field('eva_unit_price,eva_total_value,eva_net_value,appraiser_name') ->order('create_time', 'desc') ->find(); $eva_unit_price[] = $return_price_res['eva_unit_price']; $item['eva_total_value'] += $return_price_res['eva_total_value']; $appraiser_name[] = $return_price_res['appraiser_name']; } $item['eva_unit_price'] = implode('/', $eva_unit_price); $item['appraiser_name'] = implode('/', $appraiser_name); $item['full_estate_name_info'] = array('show' => !empty($full_estate_name_info) ? $full_estate_name_info[0]['property_full_name'] : '', 'property_full_name' => array_column($full_estate_name_info, 'property_full_name')); $item['size'] = sprintf('%.2f',array_sum(array_column($full_estate_name_info, 'size'))); unset($item['bank_sub_name']); return $item; }) ->toArray(); return $this->buildSuccess(['data' => $list['data'], 'count' => $list['total']]); } private function listWhere($typeList) { $data = $this->postData; $map = []; //todo 加上userId条件 if (isset($data['user_name']) && !empty($data['user_name'])){ $map[] = ['i.buss_username', 'like', '%'.trim($data['user_name']).'%']; } if (isset($data['type']) && !empty($data['type'])){ $map[] = ['i.type', '=', $data['type']]; } if (isset($data['is_multiple']) && ($data['is_multiple'] === '0' || $data['is_multiple'] === '1')){ $map[] = ['i.is_multiple', '=', $data['is_multiple']]; } if (!empty($data['start_time']) || !empty($data['end_time'])){ // $map[] = getQueryDate('i.create_time', $data['start_time'], $data['end_time']); $map[] = getQueryDate('r.create_time', $data['start_time'], $data['end_time']); }else{ $map[] = getQueryDate('r.create_time', '2025-02-01', date('Y-m-d', strtotime('+1 day'))); } if (isset($data['search_text']) && !empty($data['search_text'])){ $map[] = ['d.property_full_name|i.order_no|r.report_no|r.e_case_code', 'like', '%'.trim($data['search_text']).'%']; } if (isset($data['bank_id']) && !empty($data['bank_id'])){ $map[] = ['i.bank_id', '=', $data['bank_id']]; } if (isset($data['bank_branch_id']) && !empty($data['bank_branch_id'])){ $map[] = ['i.bank_branch_id', '=', $data['bank_branch_id']]; } if (isset($data['bank_sub_id']) && !empty($data['bank_sub_id'])){ $map[] = ['i.bank_sub_id', '=', $data['bank_sub_id']]; } if (isset($data['status']) && !empty($data['status'])){ $map[] = ['i.status', '=', $data['status']]; } else { $map[] = ['i.status', 'in', [6,7]]; } if ($typeList != 3) { $map[] = ['r.status', '=', $typeList]; } $map[] = ['r.report_source', '=', 1];//报告来源 1新系统 return $map; } //待审核报告管理列表页面 public function reqReportReviewingList(){ $where = $this->listWhere(2); $field = 'r.id as reporid,i.order_no,r.report_no,d.id as property_cert_info_id,d.city,i.type,i.is_multiple,i.bank_sub_name,i.bank_name,r.e_case_code,r.producer_name,i.create_time,i.buss_username,r.status,i.id as quot_id,p.eva_unit_price,p.eva_total_value,d.size,p.eva_unit_price,r.create_time as report_add_time,i.eva_purpose'; $subsql = Db::table('pg_return_price') ->field('property_cert_info_id,create_time,eva_unit_price,eva_total_value,eva_net_value') ->group('property_cert_info_id')->order('property_cert_info_id', 'desc')->buildSql(); $list = \Db::name('report') ->alias('r') ->join('inquiry i','r.quot_id=i.id') ->join('property_cert_info d','i.id=d.quot_id') // ->join([$subsql => 'p'], 'd.id = p.property_cert_info_id', 'left') ->join('return_price p', 'd.id = p.property_cert_info_id', 'left') ->where($where) ->where('r.review_status=1 and r.review2_status=1') ->field($field) // ->order('r.create_time', 'desc') ->order('r.update_time asc,p.id desc') ->group('d.quot_id') ->paginate($this->getPage()) ->each(function ($item, $key){ $item['type_str'] = getDictionaryName('BUSINESS_TYPE', $item['type']); $item['is_multi_str'] = getDictionaryName('INQUIRY_NUMBER', $item['is_multiple']); $item['bank_name'] = !empty($item['bank_name']) && !empty($item['bank_sub_name']) ? $item['bank_name'] . $item['bank_sub_name'] : $item['bank_name']; $full_estate_name_info = Db::name('property_cert_info') ->where('quot_id', $item['quot_id']) ->field('id,property_full_name,size,building_name,quot_id') ->order('id', 'desc') ->select(); $eva_unit_price = []; $appraiser_name = []; $item['eva_total_value'] = 0; foreach ($full_estate_name_info as $key=>$value) { $return_price_res = Db::name('return_price') ->where('property_cert_info_id='.$value['id']) ->field('eva_unit_price,eva_total_value,eva_net_value,appraiser_name') ->order('create_time', 'desc') ->find(); $eva_unit_price[] = $return_price_res['eva_unit_price']; $item['eva_total_value'] += $return_price_res['eva_total_value']; $appraiser_name[] = $return_price_res['appraiser_name']; } $item['eva_unit_price'] = implode('/', $eva_unit_price); $item['appraiser_name'] = implode('/', $appraiser_name); $item['full_estate_name_info'] = array('show' => !empty($full_estate_name_info) ? $full_estate_name_info[0]['property_full_name'] : '', 'property_full_name' => array_column($full_estate_name_info, 'property_full_name')); $item['size'] = sprintf('%.2f',array_sum(array_column($full_estate_name_info, 'size'))); // $item['venture_lv'] = $this->getVentureLv( $full_estate_name_info );//获取风险等级 // 列表显示时间太长,默认风险等级为0 $item['venture_lv'] = 0; unset($item['bank_sub_name']); return $item; }) ->toArray(); return $this->buildSuccess(['data' => $list['data'], 'count' => $list['total']]); } // 待审核-三审 public function CheckReportListThird(){ $where = $this->listWhere(2); $field = 'r.id as reporid,i.order_no,r.report_no,d.id as property_cert_info_id,d.city,i.type,i.is_multiple,i.bank_sub_name,i.bank_name,r.e_case_code,r.producer_name,i.create_time,i.buss_username,r.status,i.id as quot_id,p.eva_unit_price,p.eva_total_value,d.size,p.eva_unit_price,r.create_time as report_add_time,i.eva_purpose'; $subsql = Db::table('pg_return_price') ->field('property_cert_info_id,create_time,eva_unit_price,eva_total_value,eva_net_value') ->group('property_cert_info_id')->order('property_cert_info_id', 'desc')->buildSql(); $list = \Db::name('report') ->alias('r') ->join('inquiry i','r.quot_id=i.id') ->join('property_cert_info d','i.id=d.quot_id') ->join('return_price p', 'd.id = p.property_cert_info_id', 'left') ->where($where) ->where('r.review_status=2 and r.review2_status=1') ->field($field) ->order('r.update_time asc,p.id desc') ->group('d.quot_id') ->paginate($this->getPage()) ->each(function ($item, $key){ $item['type_str'] = getDictionaryName('BUSINESS_TYPE', $item['type']); $item['is_multi_str'] = getDictionaryName('INQUIRY_NUMBER', $item['is_multiple']); $item['bank_name'] = !empty($item['bank_name']) && !empty($item['bank_sub_name']) ? $item['bank_name'] . $item['bank_sub_name'] : $item['bank_name']; $full_estate_name_info = Db::name('property_cert_info') ->where('quot_id', $item['quot_id']) ->field('id,property_full_name,size,building_name,quot_id') ->order('id', 'desc') ->select(); $eva_unit_price = []; $appraiser_name = []; $item['eva_total_value'] = 0; foreach ($full_estate_name_info as $key=>$value) { $return_price_res = Db::name('return_price') ->where('property_cert_info_id='.$value['id']) ->field('eva_unit_price,eva_total_value,eva_net_value,appraiser_name') ->order('create_time', 'desc') ->find(); $eva_unit_price[] = $return_price_res['eva_unit_price']; $item['eva_total_value'] += $return_price_res['eva_total_value']; $appraiser_name[] = $return_price_res['appraiser_name']; } $item['eva_unit_price'] = implode('/', $eva_unit_price); $item['appraiser_name'] = implode('/', $appraiser_name); $item['full_estate_name_info'] = array('show' => !empty($full_estate_name_info) ? $full_estate_name_info[0]['property_full_name'] : '', 'property_full_name' => array_column($full_estate_name_info, 'property_full_name')); $item['size'] = sprintf('%.2f',array_sum(array_column($full_estate_name_info, 'size'))); // $item['venture_lv'] = $this->getVentureLv( $full_estate_name_info );//获取风险等级 // 列表显示时间太长,默认风险等级为0 $item['venture_lv'] = 0; unset($item['bank_sub_name']); return $item; }) ->toArray(); return $this->buildSuccess(['data' => $list['data'], 'count' => $list['total']]); } /** * 获取风险等级 */ private function getVentureLv ( $detailsList ) { $MDetail = new Property_cert_info(); $MReport = new Report(); $MReturnPrice = new ReturnPrice(); $maxLv = 0; $min_list = []; // 计算三周前的时间戳 $currentTime = time(); $threeWeeksAgo = strtotime('-3 weeks', $currentTime); foreach ($detailsList as $k=>$row ) { // 1、查询estate_name的所有inquiry_detail_list $detail_reported_list = []; $inquiry_details_list = $MDetail->where('building_name', $row['building_name'])->field('id,quot_id') ->select(); $prices_list = $MReturnPrice->getNewInfoByInquiryDetailID( $row['id'] ); $curPrice = $prices_list['eva_unit_price']; foreach( $inquiry_details_list as $i=>$detail_row) { // 1.1 查询inquiry_detail_list的inquiry_id 字段 在报告里的status是否大于等于3(是已完成报告) // 获取当前时间的时间戳 $reports_list = $MReport->where( 'quot_id', $detail_row['quot_id'] ) ->where('completion_time', '>=', $threeWeeksAgo) ->field('status,quot_id')->find(); if( $reports_list['status'] < self::REPORT_STATUS_COMPLETED ) { continue; } // 1.2 如果已完成,放到列表里 $detail_reported_list[] = $detail_row; // var_dump( 'detail_row',$detail_row); } // 如果没有符合条件物业,跳过 if(count($detail_reported_list) == 0 ) { continue; } // var_dump( 'detail_reported_list',$detail_reported_list); // 获取本小区最低价 $min = $this->getMinPrice( $detail_reported_list ); // 计算风险等级 $curLv = $this->calVentureLv( $curPrice , $min); // 如果多套物业,取风险等级最大的值为此询价的风险等级 if($curLv > $maxLv) { $maxLv = $curLv; } } return $maxLv; } /** * 计算风险等级 * @param float $curPrice 当前价 * @param float $min 最小价 * @return int $lv 风险等级 (0 :无风险,1,2,max最大风险) */ private function calVentureLv( $curPrice , $min) { $result = (float)(abs($curPrice - $min)/$curPrice); $curLv = 0; if( $result > 0.03 ) { $curLv = 2; } else if( $result < 0.009 ) { $curLv = 0; } else // 1% - 2.999% 之间风险等级1Lv { $curLv = 1; } return $curLv; } /** * 获取回价表里最小值 * @param array 表 * @return int 最小值 */ private function getMinPrice( $inquiry_detail_id_list ) { $MReturnPrice = new ReturnPrice(); $minPrice = 0; foreach( $inquiry_detail_id_list as $row ) { $price_list = $MReturnPrice->where('property_cert_info_id',$row['id'] )->field('eva_unit_price')->select(); $minPrice = $price_list[0]['eva_unit_price']; foreach ($price_list as $item) { if (isset($item['eva_unit_price'])) { if ($minPrice === null || $item['eva_unit_price'] < $minPrice) { // 找出最小值 $minPrice = $item['eva_unit_price']; } } } } return $minPrice; } //个人制作列表 public function personalReportList($export_flag = false){ if ($export_flag) { $paginate = ['list_rows' => 10000000, 'page' => 1]; } else { $paginate = $this->getPage(); } $where = $this->listWhere(3); $where[] = ['r.maker_id', '=', $this->userInfo['user_id']]; $field = 'r.id as reporid,i.order_no,r.report_no,d.id as property_cert_info_id,d.city,i.type,i.is_multiple,i.bank_sub_name,i.bank_name,r.e_case_code,i.create_time,i.user_name,r.status,i.id as quot_id,p.eva_total_value,d.size,p.eva_unit_price,r.create_time as report_add_time,i.eva_purpose,i.status,r.valuation_time,r.appraisal_time'; $subsql = Db::table('pg_return_price') ->field('property_cert_info_id,create_time,eva_unit_price,eva_total_value,eva_net_value') ->group('property_cert_info_id')->order('property_cert_info_id', 'desc')->buildSql(); $list = \Db::name('report') ->alias('r') ->join('inquiry i','r.quot_id=i.id') ->join('property_cert_info d','i.id=d.quot_id') ->join('return_price p', 'd.id = p.property_cert_info_id', 'left') ->where($where) ->field($field) // ->order('r.create_time', 'desc') ->order('r.create_time desc,p.id desc') ->group('d.quot_id') ->paginate($paginate) ->each(function ($item, $key){ $item['type_str'] = getDictionaryName('BUSINESS_TYPE', $item['type']); $item['is_multi_str'] = getDictionaryName('INQUIRY_NUMBER', $item['is_multiple']); $item['bank_name'] = !empty($item['bank_name']) && !empty($item['bank_sub_name']) ? $item['bank_name'] . $item['bank_sub_name'] : $item['bank_name']; $full_estate_name_info = Db::table('pg_property_cert_info') ->where('quot_id', $item['quot_id']) ->order('id', 'desc') ->column('property_full_name'); $return_price_info = Db::name('return_price') ->where(['property_cert_info_id'=>$item['property_cert_info_id']]) ->field('eva_unit_price,eva_total_value') ->order('id', 'desc') ->find(); $item['eva_unit_price'] = $return_price_info['eva_unit_price']; $item['eva_total_value'] = $return_price_info['eva_total_value']; $item['full_estate_name_info'] = array('show' => !empty($full_estate_name_info) ? $full_estate_name_info[0] : '', 'property_full_name' => $full_estate_name_info); $item['full_estate_names'] = implode(',', $full_estate_name_info); $item['size'] = Db::name('property_cert_info')->where(new Where(['quot_id' => $item['quot_id']]))->sum('size'); $item['status_str'] = getDictionaryName('ORDER_STATUS', $item['status']); unset($item['bank_sub_name']); return $item; }) ->toArray(); if ($export_flag) { return $list['data']; } else { return $this->buildSuccess(['data' => $list['data'], 'count' => $list['total']]); } } // 报告制作--个人制作导出 public function getPersonalReportListExport() { $export_flag = true; $data = $this->personalReportList($export_flag); $indexKey = ['report_no', 'full_estate_names', 'bank_name', 'type_str', 'status_str', 'valuation_time', 'appraisal_time', 'user_name', 'report_add_time']; $indexValue = ['报告编号', '物业名称', '银行', '贷款类型', '订单状态', '估价时点','评估日期', '业务员', '制作日期']; (new ChargeManage())->exportExcel($data, 'personal_report_'.date('Ymd'), $indexKey, $indexValue); } //报告详情页-头部信息 public function topBaseInfo(){ $postData = $this->postData; if(!empty($postData['reportid'])) $reportid = $postData['reportid']; else return $this->buildFailed('请求参数错误'); $result = Db::name('report')->alias('r') ->join('inquiry x', 'x.id=r.quot_id') ->field('r.id,r.otherrights_type,x.order_no,x.bank_name,x.bank_branch_name,x.bank_sub_name,x.bank_customer_mgr_name,x.type,x.buss_username as user_name,x.eva_purpose,r.appraiser_name,r.appraiser2_name,r.appraiser_id,r.appraiser2_id,r.producer_name,r.produce_time,r.reviewer_name,r.review_time,r.reviewer2_name,r.reviewer2_time,r.company,x.id as quot_id,r.valuation_time,r.status,r.eva_total_value,r.report_file_id,r.attachment_ids,r.cur_tmpl_id,r.size,r.appraisal_time,r.validity_time,r.market_background,r.quot_id,r.commission_note,r.ceb_product_type,r.appraisal_result_remark,x.is_multiple,r.update_time,x.product_id,r.qrurl') ->where(['r.id' => $postData['reportid']]) ->find(); $estate_info = Db::name('property_cert_info') ->field('id,property_full_name as building_name,size') ->where(['quot_id' => $result['quot_id']]) ->order('id', 'desc') ->group('id') ->select(); $result['estata_number'] = count($estate_info);//物业数量 $eva_total_value = $taxation_moeny = $loan_money = $size = 0; foreach ($estate_info as $key => $value) { $price = []; $price = Db::name('return_price')->field('eva_total_value,gross_value')->where(['property_cert_info_id' => $value['id']])->order('create_time', 'desc')->find(); $eva_total_value = $eva_total_value + $price['eva_total_value']; $loan_money = $loan_money + $price['gross_value']; $size = $size + $value['size']; } $result['eva_total_value'] = !empty($result['eva_total_value']) && $result['eva_total_value'] != '0.00' ? $result['eva_total_value'] : sprintf("%.2f", $eva_total_value);//评估总值 $result['loan_money'] = $loan_money ? sprintf("%.2f", $loan_money): '';//贷款总值 $result['size'] = !empty($result['size']) && $result['size'] != '0.00' ? $result['size'] : sprintf("%.2f", $size);//建筑面积 $result['estate_info'] = $estate_info; $evaluation_date = !empty($result['appraisal_time']) ? $result['appraisal_time'] : date('Y-m-d', time()); $result['appraisal_time'] = $evaluation_date; $result['validity_time'] = date('Y-m-d', strtotime("$evaluation_date +1 year -1 day")); $result['evaluate_purpose_str'] = Db::name('product')->where('id', $result['product_id'])->value('product_name'); // $result['valuation_time'] = !empty($result['valuation_time']) ? $result['valuation_time'] : $this->getCostDate(date('Ymd', time()));//价值时点 $result['valuation_time'] = !empty($result['valuation_time']) ? $result['valuation_time'] : getCostDate(date('Ymd', time()));//价值时点 $result['company'] = empty($result['company']) ? '深圳市国中资产土地房地产评估有限公司' : $result['company']; //根据报告状态 取当前操作人 if (!empty($result['status']) && $result['status'] == 1) { $result['producer_id'] = $this->userInfo['user_id']; $result['producer_name'] = $this->userInfo['user_name']; $result['produce_time'] = date('Y-m-d', time()); } elseif (!empty($result['status']) && $result['status'] == 2) { if (!empty($postData['ctype']) && $postData['ctype']=='checkone') { $result['reviewer_id'] = $this->userInfo['user_id']; $result['reviewer_name'] = $this->userInfo['user_name']; $result['review_time'] = date('Y-m-d', time()); } else { $result['reviewer2_id'] = $this->userInfo['user_id']; $result['reviewer2_name'] = $this->userInfo['user_name']; $result['reviewer2_time'] = date('Y-m-d', time()); } } else { $result['produce_time'] = !empty($result['produce_time']) ? date('Y-m-d', strtotime($result['produce_time'])) : null; $result['review_time'] = !empty($result['review_time']) ? date('Y-m-d', strtotime($result['review_time'])) : null; } //判断不存在评估师,取默认选中的两个评估师 if (empty($result['appraiser_id']) && empty($result['appraiser_name'])) { $valuerInfo = Db::name('valuer')->field('id,name')->where('default', 1)->limit(2)->select(); foreach ($valuerInfo as $k => $v) { if ($k == 0) {//评估师1 $result['appraiser_id'] = $v['id']; $result['appraiser_name'] = $v['name']; } else {//评估师2 $result['appraiser2_id'] = $v['id']; $result['appraiser2_name'] = $v['name']; } } } $attachmnet = new Attachment(); //报告上传 $result['report_attachment_info'] = []; if (!empty($result['report_file_id'])) { $result['report_attachment_info'] = $attachmnet->getUrls($result['report_file_id']); } //附件 $result['attachment_info'] = []; if (!empty($result['attachment_ids'])) { $result['attachment_ids'] = explode(',', $result['attachment_ids']); $result['attachment_info'] = $attachmnet->getUrls($result['attachment_ids']); } else { $result['attachment_ids'] = []; } //报告模板名称 $template_info = Db::name('inquiry')->alias('i')->join('product p', 'i.product_id=p.id')->where('i.id', $result['quot_id'])->field('report_template,many_report_template')->find(); if ($result['is_multiple'] == 1) { $report_template = $template_info['many_report_template']; } else { $report_template = $template_info['report_template']; } $result['template_name'] = Db::name('report_template')->where('id', $report_template)->value('name'); $cur_tmpl_id = Db::name('report_template')->where(new Where(['trunk_id' => $report_template]))->order('id', 'desc')->value('id'); $result['cur_tmpl_id'] = !empty($result['cur_tmpl_id']) ? $result['cur_tmpl_id'] : $cur_tmpl_id; $result['current_template_name'] = ''; if (!empty($result['cur_tmpl_id'])) { $result['current_template_name'] = Db::name('report_template')->where('id', $result['cur_tmpl_id'])->value('name'); } $result['market_background'] = !empty($result['market_background']) ? explode(',', $result['market_background']) : []; if (empty($result['commission_note']) && $result['bank_name'] == '中国建设银行') { $result['commission_note'] = '估价对象在此价值时点未发现原结构被明显改变,属于精装,有人居住,居住人为租客,租客无法提供租赁合同,根据现场调查咨询,租赁为2年,租期自2018年1月至2019年12月'; } elseif(empty($result['commission_note']) && $result['bank_name'] == '中国光大银行') { $result['commission_note'] = '本次评估暂不计征个人所得税1,176,120元,若计征,税费合计为1,176,120元,抵押净值为4,826,720。'; } if (empty($result['appraisal_result_remark']) && $result['bank_name'] == '中国建设银行') { $result['appraisal_result_remark'] = '估价对象房屋用途为住宅,现状做住宅,带厨房和卫生间,有管道天然气,为住宅房地产,属深圳市内限购限贷范围内房地产。'; } if (empty($result['appraisal_result_remark']) && $result['bank_name'] == '中信银行') { $result['appraisal_result_remark'] = '本次评估物业非双拼、未打通、非顶层复式、非复式、无加建、结构无变动,现为自用。截止于估价日期,该物业暂未列入旧改名单。'; } if ($result['bank_name'] != '中国光大银行') { unset($result['ceb_product_type']); } return $this->buildSuccess($result); } //获取报告模板 public function getReportTemplate() { $reportid = input('reportid'); if (empty($reportid)) return $this->buildFailed('参数不能为空!'); $info = Db::name('report')->where('id', $reportid)->field('quot_id,cur_tmpl_id')->find(); $res = Db::name('inquiry')->alias('i')->join('product p', 'i.product_id=p.id')->field('p.report_template,p.many_report_template,i.is_multiple')->where('i.id', $info['quot_id'])->find(); if (!empty($res)) { if ($res['is_multiple'] == 1) { $report_template = $res['many_report_template']; } else { $report_template = $res['report_template']; } } else { $report_template = $info['cur_tmpl_id']; } if ($report_template) { $templateInfo = Db::name('report_template')->field('id,name')->where(new Where(['trunk_id' => $report_template]))->order('id', 'desc')->select(); } else { $templateInfo = []; } return $this->buildSuccess($templateInfo); } //获取价值时点:当前日期前一天工作日(避开周末) private function getCostDate($date) { $valuation_time = ''; $workday_api = config('serviceConfig.API_WORKDAY_URL'); for ($i = 1; $i <= 30 ; $i++) { $res_date = date('Ymd', strtotime("$date -$i day")); $valuation_time = date('Y-m-d', strtotime("$date -$i day")); // $getData = file_get_contents($workday_api. $res_date); $getData = $this->http_get($workday_api.$res_date); $result = json_decode($getData, true); if (!empty($result['workday']) && $result['workday'] == 1) { break; } } return $valuation_time; } private function http_get($url) { $oCurl = curl_init(); if (stripos($url, "https://") !== FALSE) { curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($oCurl, CURLOPT_SSLVERSION, 1); } curl_setopt($oCurl, CURLOPT_URL, $url); curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1); $sContent = curl_exec($oCurl); $aStatus = curl_getinfo($oCurl); curl_close($oCurl); if (intval($aStatus["http_code"]) == 200) { return $sContent; } else { return false; } } //报告详情页-参考成交价 public function guideInfo(){ $postData = $this->postData; if (!empty($postData['property_cert_info_id'])) { $property_cert_info_id = $postData['property_cert_info_id']; } else { return $this->buildFailed('请求参数错误'); } $result = []; // 先判断该物业的询价是住宅询价还是商业询价 $quot_id = Db::name('property_cert_info') ->where(['id'=>$property_cert_info_id]) ->field('quot_id') ->find(); $inquiry_type = Db::name('inquiry') ->where(['id'=>$quot_id['quot_id']]) ->field('type') ->find(); $result['inquiry_type'] = $inquiry_type['type']; if ($inquiry_type['type']==2) { $result['display_status'] = 2; // display的值为1时,报告详情页面展示参考成交价的子页面,反之,值为2时报告详情页面不用显示参考成交价的子页面 return $this->buildSuccess($result); } // 验证该物业的指导价是否为0 $return_price_data = Db::name('return_price') ->where(['property_cert_info_id'=>$property_cert_info_id]) ->field('guide_price') ->order('id', 'desc') ->find(); if ($return_price_data['guide_price']>0) { // 该物业有指导价 $result['display_status'] = 2; return $this->buildSuccess($result); } else { // 该物业无指导价 $result['display_status'] = 1; $case_guide_data = Db::name('guide_case') ->where(['property_cert_info_id'=>$property_cert_info_id]) ->select(); $result['case_guide_data'] = $case_guide_data; return $this->buildSuccess($result); } } public function guideInfoDel(){ $postData = $this->postData; if (!empty($postData['id'])) { $id = $postData['id']; } else { return $this->buildFailed('请求参数错误'); } $res = Db::name('guide_case')->where(['id'=>$id])->delete(); if ($res) { return $this->buildSuccess(); } else { return $this->buildFailed('删除失败'); } } //报告详情页-基本信息 public function baseInfo(){ $postData = $this->postData; if(!empty($postData['reportid'])) $reportid = $postData['reportid']; else return $this->buildFailed('请求参数错误'); if(!empty($postData['property_cert_info_id'])) $property_cert_info_id = $postData['property_cert_info_id']; $result = Db::name('report')->alias('r') ->join('inquiry x', 'x.id=r.quot_id') ->field('r.id,x.id as quot_id,x.type as inquiry_type') ->where(['r.id' => $postData['reportid']]) ->find(); $estate_info = Db::name('property_cert_info') ->field('id,property_full_name as building_name') ->where(['quot_id' => $result['quot_id']]) // ->order('id', 'desc') ->group('id') ->select(); foreach ($estate_info as $key => $value) { if (empty($property_cert_info_id) && $key == 0) { $property_cert_info_id = $value['id']; } } $common = new CommonService(); $result['basic_info'] = $property_cert_info_id ? $common->getReportDetatil($reportid,$property_cert_info_id,$result['inquiry_type']) : [];//基本信息 $result['survey_type'] = Db::name('survey')->where('property_cert_info_id', $property_cert_info_id)->value('survey_type'); return $this->buildSuccess($result); } //获取区域情况分析 public function getAreaInfo() { $parcel_no = input('parcel_no'); if (empty($parcel_no)) return $this->buildFailed('宗地号不能为空!'); $res = Db::name('zongdi_info')->field('parcel_no,parcel_area,adjacent_property,bus_lines,boundaries,pub_serv,property_intro')->where('parcel_no', $parcel_no)->order('id', 'desc')->find(); if (empty($res)) { $res = array( 'parcel_area' => '', 'adjacent_property' => '', 'bus_lines' => '', 'boundaries' => '', 'pub_serv' => '', 'property_intro' => '' ); } return $this->buildSuccess($res); } //保存区域情况分析 public function conserveArea() { $parcel_no = input('parcel_no'); if (empty($parcel_no)) return $this->buildFailed('宗地号不能为空!'); $data['parcel_area'] = input('parcel_area'); $data['adjacent_property'] = input('adjacent_property'); $data['bus_lines'] = input('bus_lines'); $data['boundaries'] = input('boundaries'); $data['pub_serv'] = input('pub_serv'); $data['property_intro'] = input('property_intro'); $data['addtime'] = date('Y-m-d H:i:s'); $data['updatetime'] = date('Y-m-d H:i:s'); $zdbh_id = Db::name('zongdi_info')->where('parcel_no', $parcel_no)->value('id'); if ($zdbh_id) { if (!Db::name('zongdi_info')->where('parcel_no', $parcel_no)->update($data)) { return $this->buildFailed('保存区域情况分析失败!'); } } else { $data['parcel_no'] = $parcel_no; if (!Db::name('zongdi_info')->insert($data)) { return $this->buildFailed('保存区域情况分析失败!'); } } return $this->buildSuccess(); } //获取评估师 public function getAppraiser() { $res = Db::name('valuer')->field('id,name')->whereIn('status', [1,2])->select(); return $this->buildSuccess($res); } //报告摘要 public function reqReportAbstractInfo(){ $postData = $this->postData; if(!empty($postData['reportid'])) $reportid = $postData['reportid']; else return $this->buildFailed('请求参数错误'); if(!empty($postData['property_cert_info_id'])) $property_cert_info_id = $postData['property_cert_info_id']; $result = Db::name('report')->field('id as reportid,quot_id,report_no,company')->where('id', $postData['reportid'])->find(); $estate_id = Db::name('property_cert_info') ->where(['quot_id' => $result['quot_id']]) ->order('id', 'desc') ->value('id'); $info = Db::name('property_cert_info')->alias('x') ->join('inquiry i', 'x.quot_id=i.id') ->join('report_detail d', 'x.id=d.property_cert_info_id') ->field('x.property_full_name,d.client,d.property_cert,x.size,i.bank_name,x.id,d.land_location,d.year, i.bank_name,i.eva_purpose,x.city,i.is_multiple,x.usage') ->where(['x.quot_id' => $result['quot_id'], 'x.id' => $estate_id]) ->group('x.id') ->find(); $anticiated_taxes = 0; if (!empty($result) && !empty($info)) { $result = array_merge($result, $info); $result['property_cert'] = !empty($result['year']) ? $result['year'] . $result['property_cert'] : $result['property_cert'];//不动产权证拼接 $detailInfo = Db::name('property_cert_info')->where('quot_id', $result['quot_id'])->field('id,property_full_name,size,statutory_payment')->select(); $size = $deed_tax = $gross_value = $total_tax = $statutory_payment = 0; $estate_name_arr = []; foreach ($detailInfo as $key => $value) { $price = Db::name('return_price')->where('property_cert_info_id', $value['id'])->field('eva_total_value,deed_tax,total_taxes1,total_taxes2')->order('id', 'desc')->find(); $land_location = Db::name('report_detail')->where('property_cert_info_id', $value['id'])->value('land_location'); if (($result['bank_name'] == '中国建设银行' && strpos($result['eva_purpose'], '抵押贷款') !== false) || ($result['bank_name'] == '珠海华润银行' && strpos($result['eva_purpose'], '个贷') !== false) || $result['bank_name'] == '徽商银行股份有限公司') { $total_tax = $total_tax + $price['total_taxes2']; } else { $total_tax = $total_tax + $price['total_taxes1']; } $estate_name_arr[] = $land_location . $value['property_full_name']; $size = $size + $value['size']; $deed_tax = $deed_tax + $price['deed_tax']; $gross_value = $gross_value + $price['eva_total_value']; $statutory_payment = $statutory_payment + $value['statutory_payment']; } $result['property_full_name'] = implode('、', $estate_name_arr); $result['size'] = round($size, 2); $result['gross_value'] = !empty($gross_value) ? $gross_value / 10000 : 0; $result['deed_tax'] = !empty($deed_tax) ? $deed_tax / 10000 : 0; // $result['total_taxes2'] = !empty($total_tax) ? $total_tax / 10000 : 0; // 预计税费 $result['total_taxes2'] = !empty($total_tax) ? $total_tax / 10000 : 0; // 抵押净值 $eva_net_value = $result['gross_value'] - $statutory_payment/10000 - $result['total_taxes2']; $result['total_taxes2'] = '预期实现抵押权的费用和税金为人民币' . $result['total_taxes2'] . '万元,抵押净值为人民币' . $eva_net_value . '万元。'; $result['deed_tax'] = '预期实现抵押权的费用和税金为人民币' . $result['deed_tax'] . '万元,抵押净值为人民币' . ($result['gross_value'] - $result['deed_tax']) . '万元。'; if ($info['is_multiple']==0) { $usage_str = getDictionaryName('HOUSE_USAGE', $info['usage']); $result['property_full_name'] = $result['property_full_name'].'一套'.$usage_str.'用途房地产抵押价值评估'; } else { $result['property_full_name'] = $result['property_full_name'].'房地产抵押价值评估'; } } $result['evaluate'] = '深圳市国中资产土地房地产评估有限公司'; // $result['value_definition'] = '本报告中的市场价值为估价对象于价值时点状态、在公开市场价值标准及满足估价的假设和限制、并假定未设立法定优先受偿权利的条件下的市场价值;抵押价值是根据相关规定,在评估总值的基础上扣减估价人员知悉的法定优先受偿款后的余额。'; $result['value_definition'] = '抵押净值,抵押价值减去预期实现抵押权的费用和税金后的价值。抵押价值,估价对象假定未设立法定优先受偿权下的价值减去注册房地产估价师知悉的法定优先受偿款后的价值。'; if (!empty($result['report_no'])) { $year = mb_substr($result['report_no'], 0, 4); $pos_f = mb_strpos($result['report_no'], '-'); $numberings = mb_substr($result['report_no'], 4, $pos_f+4); $suffix = mb_substr($result['report_no'], $pos_f+8); //根据首套物业所在城市,获取报告code $code = ''; if (!empty($result['city'])) { if ($result['city'] == '北京') { $code = 'B'; } elseif ($result['city'] == '武汉') { $code = 'C'; } else { $code = 'A'; } } $result['report_no'] = '深国中评字['.$year.$code.']第'.$numberings.'号'.$suffix; } return $this->buildSuccess($result); } //打印装订列表 public function reqPrintDocList() { $data = $this->postData; $map = []; $map[] = ['i.status', '=', 8];//订单状态 报告已完成 $map[] = ['r.print_cpy_no', '>=', 1];//打印数量 不能等于0 $map[] = ['r.report_source', '=', 1];//报告来源 1新系统 //todo 加上userId条件 if (isset($data['user_name']) && !empty($data['user_name'])){ $map[] = ['i.user_name', 'like', '%'.trim($data['user_name']).'%']; } if (isset($data['offline_report_status']) && !empty($data['offline_report_status'])){ $map[] = ['r.offline_report_status', '=', $data['offline_report_status']]; } if (!empty($data['start_time']) || !empty($data['end_time'])){ $map[] = getQueryDate('i.create_time', $data['start_time'], $data['end_time']); } if (isset($data['search_text']) && !empty($data['search_text'])){ $map[] = ['d.property_full_name', 'like', '%'.trim($data['search_text']).'%']; } $subsql = Db::table('pg_return_price') ->field('property_cert_info_id,create_time,eva_unit_price,eva_total_value,eva_net_value') ->group('property_cert_info_id')->order('property_cert_info_id', 'desc')->buildSql(); $list = Db::name('report') ->alias('r') ->join('inquiry i','r.quot_id=i.id') ->join('property_cert_info d','i.id=d.quot_id') // ->join([$subsql => 'p'], 'd.id = p.property_cert_info_id', 'left') ->join('return_price p', 'd.id = p.property_cert_info_id', 'left') ->join('report_detail rd', 'r.id=rd.report_id and d.id=rd.property_cert_info_id') ->where($map) ->field('r.id,d.quot_id,r.report_no,r.e_case_code,r.offline_report_status,d.id as property_cert_info_id,d.city,i.type,i.is_multiple,d.size,p.eva_unit_price,p.eva_total_value,i.bank_name,i.bank_sub_name,i.create_time,i.user_name,r.recipient_name,r.recipient_time,r.print_cpy_no') // ->order('r.create_time', 'desc') ->order('r.create_time desc,p.id desc') ->group('i.id') ->paginate($this->getPage()) ->each(function ($item, $key){ $item['type_str'] = getDictionaryName('BUSINESS_TYPE', $item['type']); $item['bank_name'] = !empty($item['bank_name']) && !empty($item['bank_sub_name']) ? $item['bank_name'] . $item['bank_sub_name'] : $item['bank_name']; $full_estate_name_info = Db::table('pg_property_cert_info') ->where('quot_id', $item['quot_id']) ->order('id', 'desc') ->column('property_full_name'); $item['full_estate_name_info'] = array('show' => !empty($full_estate_name_info) ? $full_estate_name_info[0] : '', 'property_full_name' => $full_estate_name_info); $return_price_info = Db::name('return_price') ->where(['property_cert_info_id'=>$item['property_cert_info_id']]) ->field('eva_unit_price,eva_total_value') ->order('id', 'desc') ->find(); $item['eva_unit_price'] = $return_price_info['eva_unit_price']; $item['eva_total_value'] = $return_price_info['eva_total_value']; unset($item['bank_sub_name']); $item['is_multi_str'] = getDictionaryName('INQUIRY_NUMBER', $item['is_multiple']); $item['offline_report_status_str'] = getDictionaryName('OFFLINE_REPORT_STATUS', $item['offline_report_status']); $item['recipient_time'] = !empty($item['recipient_time']) ? date('Y-m-d H:i:s', $item['recipient_time']) : ''; return $item; }) ->toArray(); return $this->buildSuccess(['data' => $list['data'], 'count' => $list['total']]); } //完成打印装订 public function reqReportPrintSubmit() { $id = input('id/a'); if (empty($id)) return $this->buildFailed('请勾选列表页数据'); foreach ($id as $key => $value) { $check = Db::name('report')->field('id,report_no,offline_report_status')->where('id', $value)->find(); if (empty($check)) return $this->buildFailed('没有找到报告!'); if ($check['offline_report_status'] != 1) { continue; //如果全选中有完成打印装订的订单,跳过当前单 继续循环 } elseif ($check['offline_report_status'] == 1) { Db::name('report')->where('id', $value)->update(['offline_report_status' => 2, 'update_time' => date('Y-m-d H:i:s', time())]); } } return $this->buildSuccess(); } // 一键删除查勘图片 public function delAllSurveyImgs() { $id = $this->request->post('survey_id', '', 'trim'); $survey_data = Db::name('survey_detail')->where('survey_id='.$id)->find(); if ($survey_data) { $mergedData = []; $update_data = []; foreach ($survey_data as $key=>$value) { if (strpos($key, '_img_ids') !== false) { if (!empty($value)) { if (strpos($value, ',') !== false) { $arr = explode(',', $value); foreach ($arr as $k=>$v) { if (!empty($v)) { $mergedData[] = $v; } } } else { $mergedData[] = $value; } } $update_data[$key] = ''; } } $upd_where = []; $mergedData_unique = array_unique($mergedData); if (count($mergedData_unique)>1) { $mergedData_str = implode(',', $mergedData_unique); $upd_where[] = ['id', 'in', $mergedData_str]; } elseif(count($mergedData_unique)==1) { $upd_where[] = ['id', '=', $mergedData_unique[0]]; } else { return $this->buildFailed('没有找到可以删除的查勘图片数据!'); } // 更新查勘数据 Db::startTrans(); $survey_upd = Db::name('survey_detail')->where('survey_id='.$id)->update($update_data); if ($survey_upd) { // 更新图片附件表字段delete_time的值 $upd_res = Db::name('attachment')->where($upd_where)->update(['delete_time'=>time()]); if ($upd_res) { Db::commit(); return $this->buildSuccess('', '删除成功!'); } else { Db::rollback(); return $this->buildFailed('删除失败!'); } } else { Db::rollback(); return $this->buildFailed('删除失败!'); } } else { return $this->buildFailed('没有找到可以删除的查勘图片数据!'); } } //完成盖章 public function reqReportSealSubmit() { $id = input('id/a'); if (empty($id)) return $this->buildFailed('请勾选列表页数据'); foreach ($id as $key => $value) { $check = Db::name('report')->field('id,report_no,offline_report_status')->where('id', $value)->find(); if (empty($check)) return $this->buildFailed('没有找到报告!'); if ($check['offline_report_status'] != 2) { continue; //如果全选中有完成盖章的订单,跳过当前单 继续循环 } elseif ($check['offline_report_status'] == 2) { Db::name('report')->where('id', $value)->update(['offline_report_status' => 3, 'update_time' => date('Y-m-d H:i:s', time())]); $quot_id = Db::name('report')->where('id', $value)->value('quot_id'); //写入消息 PublicMessage($quot_id,2,14); } } return $this->buildSuccess(); } //领取报告 public function reqPickupReport() { $id = input('id/a'); $name = input('name', '', 'trim'); if (empty($id)) return $this->buildFailed('请勾选列表页数据'); if (empty($name)) return $this->buildFailed('请输入领取人'); foreach ($id as $key => $value) { $check = Db::name('report')->field('id,report_no,offline_report_status')->where('id', $value)->find(); if (empty($check)) return $this->buildFailed('没有找到报告!'); if ($check['offline_report_status'] != 3) { continue; //如果全选中有领取报告的订单,跳过当前单 继续循环 } elseif ($check['offline_report_status'] == 3) { Db::name('report')->where('id', $value)->update(['offline_report_status' => 4, 'recipient_name' => $name, 'recipient_time' => time(), 'update_time' => date('Y-m-d H:i:s', time())]); } } return $this->buildSuccess(); } //报告管理列表 public function reqReportList($export_flag = false){ if ($export_flag) { $paginate = ['list_rows' => 10000000, 'page' => 1]; } else { $paginate = $this->getPage(); } $data = $this->postData; $map = []; //todo 加上userId条件 if (isset($data['user_name']) && !empty($data['user_name'])){ $map[] = ['i.buss_username', 'like', '%'.trim($data['user_name']).'%']; } if (isset($data['producer_name']) && !empty($data['producer_name'])){ $map[] = ['r.producer_name', 'like', '%'.trim($data['producer_name']).'%']; } if (isset($data['is_multiple']) && ($data['is_multiple'] === '0' || $data['is_multiple'] === '1')){ $map[] = ['i.is_multiple', '=', $data['is_multiple']]; } if (isset($data['type']) && !empty($data['type'])){ $map[] = ['i.type', '=',$data['type']]; } if (isset($data['status']) && !empty($data['status'])){ if (in_array($data['status'], [6,7,8,-2])) { $map[] = ['i.status', '=', $data['status']]; } else { $map[] = ['i.status', '=', null]; } } else { $map[] = ['i.status', 'in', [6,7,8,-2]]; } if (isset($data['offline_report_status']) && !empty($data['offline_report_status'])){ $map[] = ['r.offline_report_status', '=', $data['offline_report_status']]; } if (!empty($data['start_time']) || !empty($data['end_time'])){ // $map[] = getQueryDate('r.completion_time', $data['start_time'], $data['end_time']); $unix_start = strtotime($data['start_time']); $unix_end = strtotime($data['end_time']); if ($unix_start < $unix_end) { $map[] = ['r.completion_time', 'between', [$unix_start, $unix_end]]; } else { $map[] = ['r.completion_time', 'between', [$unix_end, $unix_start]]; } } if (!empty($data['create_start_time']) || !empty($data['create_end_time'])){ $unix_create_start = ($data['create_start_time']); $unix_create_end = ($data['create_end_time']); if ($unix_create_start < $unix_create_end) { $map[] = ['r.create_time', 'between', [$unix_create_start, $unix_create_end]]; } else { $map[] = ['r.create_time', 'between', [$unix_create_start, $unix_create_end]]; } } if (isset($data['search_text']) && !empty($data['search_text'])){ $map[] = ['d.property_full_name|r.report_no|r.e_case_code', 'like', '%'.trim($data['search_text']).'%']; } if (isset($data['bank_id']) && !empty($data['bank_id'])){ $map[] = ['i.bank_id', '=', $data['bank_id']]; } if (isset($data['bank_branch_id']) && !empty($data['bank_branch_id'])){ $map[] = ['i.bank_branch_id', '=', $data['bank_branch_id']]; } if (isset($data['bank_sub_id']) && !empty($data['bank_sub_id'])){ $map[] = ['i.bank_sub_id', '=', $data['bank_sub_id']]; } if (isset($data['bank_customer_mgr_name']) && !empty($data['bank_customer_mgr_name'])){ $map[] = ['i.bank_customer_mgr_id', '=', $data['bank_customer_mgr_name']]; } if (isset($data['eva_purpose']) && !empty($data['eva_purpose'])){ $map[] = ['i.product_id', '=', $data['eva_purpose']]; } $map[] = ['i.is_simple', '=', 0]; $map[] = ['r.report_source', '=', 1];//报告来源 1新系统 $field = 'r.id as reporid,i.order_no,i.business_no,r.report_no,d.city,i.status,i.type,i.is_multiple,i.bank_sub_name,i.bank_name,r.e_case_code,i.create_time,i.buss_username,i.id as quot_id,p.eva_total_value,i.eva_purpose,i.loan_type,r.completion_time,r.producer_name,r.offline_report_status,r.valuation_time,i.bank_customer_mgr_name,r.appraiser_name,r.appraiser2_name, i.biz_status, i.bnkno, i.tlrname, i.is_send_report_to_boc'; $subsql = Db::table('pg_return_price') ->field('property_cert_info_id,create_time,eva_unit_price,eva_total_value,eva_net_value') ->group('property_cert_info_id')->order('property_cert_info_id', 'desc')->buildSql(); $list = \Db::name('report') ->alias('r') ->join('inquiry i','r.quot_id=i.id') ->join('property_cert_info d','i.id=d.quot_id') // ->join([$subsql => 'p'], 'd.id = p.property_cert_info_id', 'left') ->join('return_price p', 'd.id = p.property_cert_info_id', 'left') ->where($map) ->field($field) // ->order('r.create_time', 'desc') ->order('r.create_time desc,p.id desc') ->group('d.quot_id') ->paginate($paginate) ->each(function ($item, $key){ $item['type_str'] = getDictionaryName('BUSINESS_TYPE', $item['type']); $item['is_multi_str'] = getDictionaryName('INQUIRY_NUMBER', $item['is_multiple']); // $item['bank_name'] = !empty($item['bank_name']) && !empty($item['bank_sub_name']) ? $item['bank_name'] . $item['bank_sub_name'] : $item['bank_name']; $full_estate_name_info = Db::table('pg_property_cert_info') ->where('quot_id', $item['quot_id']) ->order('id', 'desc') ->column('property_full_name'); $item['full_estate_name_info'] = array('show' => !empty($full_estate_name_info) ? $full_estate_name_info[0] : '', 'property_full_name' => $full_estate_name_info); $item['property_full_name'] = !empty($full_estate_name_info) ? $full_estate_name_info[0] : ''; $item['full_estate_name_str'] = implode(',', $full_estate_name_info); $inquiry_details = Db::name('property_cert_info') ->where('quot_id='.$item['quot_id']) ->field('id,property_full_name,size') ->select(); foreach ($inquiry_details as $id_k=>$id_v) { // 回价信息 $return_detail_data = Db::name('return_price') ->where('property_cert_info_id='.$id_v['id']) ->field('eva_unit_price,eva_total_value') ->order('create_time','desc') ->find(); if ($return_detail_data) { $id_v['eva_unit_price'] = $return_detail_data['eva_unit_price']; $id_v['eva_total_value'] = $return_detail_data['eva_total_value']; } else { $id_v['eva_unit_price'] = 0; $id_v['eva_total_value'] = 0; } // 报告详细信息 $report_detail_data = Db::name('report_detail') ->where('property_cert_info_id='.$id_v['id']) ->field('area,parcel_no,parcel_area,client,land_use_end_time,land_location') ->find(); if($report_detail_data) { $id_v['area'] = $report_detail_data['area']; $id_v['parcel_no'] = $report_detail_data['parcel_no']; $id_v['parcel_area'] = $report_detail_data['parcel_area']; $id_v['client'] = $report_detail_data['client']; $id_v['land_use_end_time'] = round((strtotime($report_detail_data['land_use_end_time'])-strtotime(date('Y-m-d')))/(365*24*3600)); $id_v['land_location'] = $report_detail_data['land_location']; } else { $id_v['area'] = ''; $id_v['parcel_no'] = ''; $id_v['parcel_area'] = ''; $id_v['client'] = ''; $id_v['land_use_end_time'] = ''; $id_v['land_location'] = ''; } $inquiry_details[$id_k] = $id_v; } if (count($inquiry_details)>1) { $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['area'] = implode('/', array_unique(array_column($inquiry_details, 'area'))); $item['parcel_no'] = implode('/', array_unique(array_column($inquiry_details, 'parcel_no'))); $item['parcel_area'] = implode('/', array_unique(array_column($inquiry_details, 'parcel_area'))); $item['client'] = implode('/', array_unique(array_column($inquiry_details, 'client'))); $item['land_use_end_time'] = implode('/', array_unique(array_column($inquiry_details, 'land_use_end_time'))); $item['land_location'] = implode('/', array_unique(array_column($inquiry_details, 'land_location'))); } elseif (count($inquiry_details) == 1) { $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['area'] = $inquiry_details[0]['area']; $item['parcel_no'] = $inquiry_details[0]['parcel_no']; $item['parcel_area'] = $inquiry_details[0]['parcel_area']; $item['client'] = $inquiry_details[0]['client']; $item['land_use_end_time'] = $inquiry_details[0]['land_use_end_time']; $item['land_location'] = $inquiry_details[0]['land_location']; } $item['eva_total_value'] = array_sum(explode('/', $item['eva_total_value'])); $item['appraisers'] = ''; if ($item['appraiser_name'] && $item['appraiser2_name']) { $item['appraisers'] = $item['appraiser_name'].','.$item['appraiser2_name']; } elseif ($item['appraiser_name'] && !$item['appraiser2_name']) { $item['appraisers'] = $item['appraiser_name']; } elseif (!$item['appraiser_name'] && $item['appraiser2_name']) { $item['appraisers'] = $item['appraiser2_name']; } $item['producer_name'] = !empty($item['producer_name']) ? $item['producer_name'] : ''; // unset($item['bank_sub_name']); $item['status_str'] = getDictionaryName('ORDER_STATUS', $item['status']); $item['offline_report_status_str'] = getDictionaryName('OFFLINE_REPORT_STATUS', $item['offline_report_status']); $item['completion_time'] = !empty($item['completion_time']) ? date('Y-m-d H:i:s', $item['completion_time']) : ''; $item['finish_date'] = !empty($item['completion_time']) ? date('Y-m-d', strtotime($item['completion_time'])) : ''; $report_cost = Db::name('charge')->where('report_no', $item['report_no'])->value('receivable'); if ($report_cost) { $item['receivable'] = $report_cost; } else { $item['receivable'] = 0; } return $item; }) ->toArray(); if ($export_flag) { return $list['data']; } else { return $this->buildSuccess(['data' => $list['data'], 'count' => $list['total']]); } } // 报告管理列表导出 public function getReportListExport() { $export_flag = true; $data = $this->reqReportList($export_flag); // $indexKey = ['report_no', 'e_case_code', 'city', 'property_full_name', 'status_str', 'offline_report_status_str', 'type_str', 'is_multi_str', 'eva_total_value', 'bank_name', 'eva_purpose', 'completion_time', 'user_name', 'producer_name']; // $indexValue = ['报告编号', '电子档提取码', '城市', '物业名称', '订单状态', '线下报告状态', '业务类型', '询价套数', '评估总值(元)', '银行', '评估目的', '报告完成时间', '业务员', '报告制作员']; $indexKey = [ 'full_estate_name_str', 'report_no', 'e_case_code', 'city', 'size', 'eva_unit_price', 'eva_total_value', 'valuation_time', 'parcel_no', 'parcel_area', 'land_use_end_time', 'bank_name', 'bank_sub_name', 'bank_customer_mgr_name', 'eva_purpose', 'client', 'appraisers', 'area', 'land_location', 'completion_time', 'finish_date', 'user_name', 'producer_name', 'receivable' ]; $indexValue = [ '估价项目', '估价报告编号', '电子档提取码', '城市', '面积(㎡)', '评估单价(元)', '评估总值(元)', '价值时点', '宗地号', '宗地面积', '剩余年限', '银行', '支行', '客户经理', '评估目的(是否云快贷)', '委托人', '估价师', '所在区域', '估价项目详细地址', '报告完成时间', '报告完成日期(年-月-日)', '业务员', '报告制作员', '报告费' ]; (new ChargeManage())->exportExcel($data, 'report_'.date('Ymd'), $indexKey, $indexValue); } //获取评估目的 public function getEvaluatePurpose() { $bank_id = input('bank_id'); if (empty($bank_id)) return $this->buildSuccess([]); $res = Db::name('product')->field('id,product_name as eva_purpose')->where('bank_id', $bank_id)->select(); return $this->buildSuccess($res); } //保存报告 admin/ReportManage/conserveReport public function conserveReport() { $data = $this->request->post(); if (empty($data['reportid'])) return $this->buildFailed('报告id不能为空!'); if (empty($data['property_cert_info_id'])) return $this->buildFailed('请选择物业!'); if (empty($data['inquiryinfo'])) return $this->buildFailed('基本信息不能为空!'); if (empty($data['reportinfo'])) return $this->buildFailed('报告信息不能为空!'); if (empty($data['surveyinfo'])) return $this->buildFailed('查勘信息不能为空!'); $res = Db::name('report')->field('report_file_id,status')->where('id', $data['reportid'])->find(); Db::startTrans(); try { $reportModel = new ReportDetail(); //基本信息 $inquiry = $data['inquiryinfo']; $building_no = !empty($inquiry['building_no']) ? $inquiry['building_no'] : ''; $unit_no = !empty($inquiry['unit_no']) ? $inquiry['unit_no'] : ''; $inquiry['building_unit_no'] = $building_no . $unit_no;//栋号房号 $data['inquiryinfo']['building_unit_no'] = $building_no . $unit_no;//栋号房号 $inquiry['property_full_name'] = $inquiry['building_name'] . $inquiry['building_unit_no'];//物业全称 $data['inquiryinfo']['property_full_name'] = $inquiry['building_name'] . $inquiry['building_unit_no'];//物业全称 $inquiry['purchase_date'] = $data['inquiryinfo']['purchase_date']; //存在报告上传,不需要判断必填项 (三期) if (empty($res['report_file_id'])) { $inquiryValidate=new inquiryDetailValidate(); if(!$inquiryValidate->scene(inquiryDetailValidate::SCENE_ASK_INQUIRY)->check($data['inquiryinfo'])){ Db::rollback(); return $this->buildFailed($inquiryValidate->getError()); } } // $inquiry = $data['inquiryinfo']; // $building_no = !empty($inquiry['building_no']) ? $inquiry['building_no'] : ''; // $unit_no = !empty($inquiry['unit_no']) ? $inquiry['unit_no'] : ''; // $inquiry['building_unit_no'] = $building_no . $unit_no;//栋号房号 // $inquiry['property_full_name'] = $inquiry['building_name'] . $inquiry['building_unit_no'];//物业全称 $inquiryDetailModel = new Property_cert_info(); $result = $inquiryDetailModel->allowField(true)->save($inquiry, ['id' => $data['property_cert_info_id']]); $ReturnPriceModel = new ReturnPrice(); $return_price_data['property_name'] = $inquiry['property_full_name']; $return_price_data['building_unit_no'] = $inquiry['building_unit_no']; $return_price_data['building_no'] = $building_no; $return_price_data['unit_no'] = $unit_no; $result_r = $ReturnPriceModel->allowField(true)->save($return_price_data, ['property_cert_info_id' => $data['property_cert_info_id']]); if (!$result || !$result_r) { Db::rollback(); return $this->buildFailed('更新数据失败'); } //存在报告上传,不需要判断必填项 (三期) if (empty($res['report_file_id'])) { if(!$inquiryValidate->scene(inquiryDetailValidate::SCENE_ASK_REPORT)->check($data['reportinfo'])){ Db::rollback(); return $this->buildFailed($inquiryValidate->getError()); } } $reportinfo = $data['reportinfo']; $reportinfo['purchase_date'] = $data['inquiryinfo']['purchase_date']; $reportinfo['reg_date'] = $data['inquiryinfo']['reg_date']; $reportinfo['test_method'] = implode(',', $reportinfo['test_method']); if (empty($reportinfo['house_cert_img_ids'])) { Db::rollback(); return $this->buildFailed('请上传房产证'); } $reportinfo['house_cert_img_ids'] = implode(',', $reportinfo['house_cert_img_ids']); $reportinfo['company_qualification_img_ids'] = implode(',', $reportinfo['company_qualification_img_ids']); if (!empty($reportinfo['report_summary_img_ids'])) { $reportinfo['report_summary_img_ids'] = implode(',', $reportinfo['report_summary_img_ids']); } if (!empty($reportinfo['attachment_ids'])) { $reportinfo['attachment_ids'] = implode(',', $reportinfo['attachment_ids']); } if (!empty($reportinfo['grand_district_id'])) { $reportinfo['grand_district_name'] = Db::name('district_info')->where('id', $reportinfo['grand_district_id'])->value('big_district'); } if (!empty($reportinfo['small_district_id'])) { $reportinfo['small_district_name'] = Db::name('district_info')->where('id', $reportinfo['small_district_id'])->value('small_district'); } if (empty($reportinfo['completion_date'])) { $reportinfo['completion_date'] = null; } $result = $reportModel->allowField(true)->save($reportinfo, ['id' => $reportinfo['id']]); if (!$result) { Db::rollback(); return $this->buildFailed('更新数据失败'); } //查勘信息 $validate=new SurveyValidate(); //存在报告上传,不需要判断必填项 (三期) if (empty($res['report_file_id'])) { if (!empty($data['surveyinfo']['survey_type']) && $data['surveyinfo']['survey_type']==1 && (!empty($data['surveyinfo']['unit_type']) && $data['surveyinfo']['unit_type']=='---' || $data['surveyinfo']['unit_type']=='0-0-0-0' || strlen($data['surveyinfo']['unit_type'])<7)) { Db::rollback(); return $this->buildFailed('户型输入有误,请确认重新输入'); } if(!$validate->scene(SurveyValidate::SCENE_SUBMIT)->batch()->check($data['surveyinfo'])){ Db::rollback(); return $this->buildFailed($validate->getError()); } } $surveyService = new SurveyService(); $surveyController = new SurveyController(); $surveyInfo = $data['surveyinfo']; //删除arr不要的数据 foreach ($surveyInfo as $key=>$v){ if(strpos($key,'_arr')){ unset($surveyInfo[$key]); } if ($key == "facility") { unset($surveyInfo['facility']['shop_facilities_elevator_arr']); } if (strpos($key, '_img_ids') && !strpos($key,'_arr')) { if (is_array($v)) { $surveyInfo[$key] = implode(',', $v); } } } if (!is_array($surveyInfo['kitchen'])) {//厨房 $surveyInfo['kitchen'] = json_decode($surveyInfo['kitchen'], true); } $surveydata=$surveyController->changeArrayToString($surveyInfo); $complete_time = !empty($surveyInfo['complete_time']) ? date("Y-m-d H:i:s", strtotime($surveyInfo['complete_time'])) : null;//查勘时间 if (!$surveyService->survey_detail($surveyInfo['user_id'], $surveydata,2,$surveyInfo['user_name'],$complete_time)){ Db::rollback(); return $this->buildFailed('保存报告失败!'); } //测算方法 if (!empty($data['simpleinfo'])) {//比较法-简单 $methodSimple = new MethodSimple(); $simplelist = []; foreach ($data['simpleinfo'] as $key => $value) { $id = ''; $value['property_cert_info_id'] = $data['property_cert_info_id']; $value['update_time'] = time(); if (empty($value['id'])) { $value['trade_date'] = !empty($value['trade_date']) ? $value['trade_date'] : null; $value['create_uid'] = $this->userInfo['user_id']; $value['create_time'] = time(); $simplelist[] = $value; } else { $id = $value['id']; unset($value['id']); if (!$methodSimple->where('id', $id)->update($value)) { Db::rollback(); return $this->buildFailed('更新比较法简易失败!'); } } } if (!empty($simplelist)) { if (!$methodSimple->allowField(true)->saveAll($simplelist)) { Db::rollback(); return $this->buildFailed('保存比较法简易失败!'); } } } $methodFormal = new MethodFormal(); if (!empty($data['formalinfo'])) {//比较法-正式 $formalinfo = $data['formalinfo']; $formalinfo['property_cert_info_id'] = $data['property_cert_info_id']; $formalinfo['update_time'] = time(); if (empty($formalinfo['id'])) { $formalinfo['create_uid'] = $this->userInfo['user_id']; $formalinfo['create_time'] = time(); if (!$methodFormal->allowField(true)->save($formalinfo)) { Db::rollback(); return $this->buildFailed('保存比较法正式失败!'); } } else { $id = $formalinfo['id']; unset($formalinfo['id']); if (!$methodFormal->allowField(true)->save($formalinfo, ['id' => $id])) { Db::rollback(); return $this->buildFailed('更新比较法正式失败!'); } } } $methodProfit = new MethodProfit(); if (!empty($data['profitinfo'])) {//收益法 $profitinfo = $data['profitinfo']; $profitinfo['property_cert_info_id'] = $data['property_cert_info_id']; $profitinfo['update_time'] = time(); if (empty($profitinfo['id'])) { $profitinfo['create_uid'] = $this->userInfo['user_id']; $profitinfo['create_time'] = time(); if (!$methodProfit->allowField(true)->save($profitinfo)) { Db::rollback(); return $this->buildFailed('保存收益法失败!'); } } else { $id = $profitinfo['id']; unset($profitinfo['id']); if (!$methodProfit->allowField(true)->save($profitinfo, ['id' => $id])) { Db::rollback(); return $this->buildFailed('更新收益法失败!'); } } } // $methodGyProfit = new MethodGyProfit(); $curGyPFInfo = Db::name('method_gyprofit')->where('property_cert_info_id', $data['property_cert_info_id'])->find(); if (!empty($data['gyprofitinfo'])) {// GY收益法 if(null != $curGyPFInfo ) $pfgyInfo['id'] = $curGyPFInfo['id'];//如果原来就有对应收益法 $pfgyInfo = $data['gyprofitinfo']; $pfgyInfo['property_cert_info_id'] = $data['property_cert_info_id']; $pfgyInfo['update_time'] = time(); if (empty($pfgyInfo['id'])) { $pfgyInfo['create_uid'] = $this->userInfo['user_id']; $pfgyInfo['create_time'] = time(); if (!Db::name('method_gyprofit')->insert($pfgyInfo)) { Db::rollback(); return $this->buildFailed('保存GY收益法失败!'); } } else { $id = $pfgyInfo['id']; unset($pfgyInfo['id']); if (!Db::name('method_gyprofit')->where(['id' => $id])->update($pfgyInfo)) { Db::rollback(); return $this->buildFailed('更新GY收益法失败!'); } } } $methodFormalGz = new MethodFormalGz(); if (!empty($data['gzformalinfo'])) {//GZ比较法 $gzformalinfo = $data['gzformalinfo']; $gzformalinfo['property_cert_info_id'] = $data['property_cert_info_id']; $gzformalinfo['update_time'] = time(); if (empty($gzformalinfo['id'])) { $gzformalinfo['create_uid'] = $this->userInfo['user_id']; $gzformalinfo['create_time'] = time(); if (!$methodFormalGz->allowField(true)->save($gzformalinfo)) { Db::rollback(); return $this->buildFailed('保存GZ比较法失败!'); } } else { $id = $gzformalinfo['id']; unset($gzformalinfo['id']); if (!$methodFormalGz->allowField(true)->save($gzformalinfo, ['id' => $id])) { Db::rollback(); return $this->buildFailed('更新GZ比较法失败!'); } } } // 房产信息收集 $ret = $this->estateInfoCollect($data); if (!$ret) { Db::rollback(); return $this->buildFailed('房产信息保存或修改失败'); } if (!empty($res) && $res['status'] == 2) {//审核意见 if (empty($data['approvalinfo'])) { Db::rollback(); return $this->buildFailed('审核意见不能为空!'); } $approvalinfo = $data['approvalinfo']; $reportValidate = new ReportValidate(); if(!$reportValidate->scene('addApproval')->check($approvalinfo)){ Db::rollback(); return $this->buildFailed($reportValidate->getError()); } $approvalOpinion = new ApprovalOpinion(); if (empty($approvalinfo['id'])) { $approvalinfo['create_uid'] = $this->userInfo['user_id']; $approvalinfo['create_time'] = time(); if (!$approvalOpinion->allowField(true)->save($approvalinfo)) { Db::rollback(); return $this->buildFailed('保存审核意见失败!'); } } else { $id = $approvalinfo['id']; unset($approvalinfo['create_time']); if (!$approvalOpinion->allowField(true)->save($approvalinfo, ['id' => $id])) { Db::rollback(); return $this->buildFailed('更新审核意见失败!'); } } } if (!empty($data['guideinfo'])) { $guide_list = []; foreach ($data['guideinfo'] as $key => $value) { $id = ''; $value['property_cert_info_id'] = $data['property_cert_info_id']; $value['update_time'] = date('Y-m-d H:i:s'); if (empty($value['id'])) { $value['create_time'] = date('Y-m-d H:i:s'); $guide_list[] = $value; } else { $id = $value['id']; unset($value['id']); $upd_res = Db::name('guide_case')->where('id', $id)->update($value); if (!$upd_res) { Db::rollback(); return $this->buildFailed('更新案例参考成交价失败!'); } } } if (!empty($guide_list)) { $ins_res = Db::name('guide_case')->insertAll($guide_list); if (!$ins_res) { Db::rollback(); return $this->buildFailed('保存案例参考成交价失败!'); } } } Db::commit(); return $this->buildSuccess(); } catch (\Exception $e) { Db::rollback(); return $this->buildFailed('保存报告失败!'.$e->getMessage()); } } //房产信息收集 private function estateInfoCollect($data){ $ins_data = []; $estate_info = $data['reportinfo']['new_online_info']; $ins_data['city'] = $data['inquiryinfo']['city']; $ins_data['property_full_name'] = $data['inquiryinfo']['property_full_name']; $ins_data['building_name'] = $data['inquiryinfo']['building_name']; $ins_data['building_no'] = $data['inquiryinfo']['building_no']; $ins_data['unit_no'] = $data['inquiryinfo']['unit_no']; $ins_data['estate_year'] = $data['reportinfo']['year']; $ins_data['estate_cert_num'] = $data['reportinfo']['property_cert']; $ins_data['new_online_info'] = $estate_info; $ins_data['building_structure'] = $data['surveyinfo']['structure']; $ins_data['house_usage'] = $data['inquiryinfo']['usage']; $ins_data['house_usage_str'] = $data['inquiryinfo']['usage_str']; $ins_data['zdbh'] = $data['reportinfo']['parcel_no']; $ins_data['zd_area'] = $data['reportinfo']['parcel_area']; $ins_data['land_use'] = $data['reportinfo']['parcel_usage']; $ins_data['land_location'] = $data['reportinfo']['land_location']; $ins_data['land_use_year'] = $data['reportinfo']['max_land_use_years']; $ins_data['land_use_begin'] = $data['reportinfo']['land_use_start_time']; $ins_data['land_use_end'] = $data['reportinfo']['land_use_end_time']; $ins_data['completion_date'] = $data['reportinfo']['completion_date']; $ins_data['register_price'] = $data['inquiryinfo']['reg_price']; $ins_data['register_time'] = $data['inquiryinfo']['purchase_date']; $ins_data['buy_date'] = $data['inquiryinfo']['purchase_date']; $ins_data['is_over2year'] = $data['inquiryinfo']['is_tran_tax_free']; $ins_data['house_property'] = $data['reportinfo']['use_right_source']; $ins_data['floor_area'] = $data['inquiryinfo']['size']; $ins_data['tenure_type'] = $data['inquiryinfo']['ownership_type']; $ins_data['obligee'] = $data['reportinfo']['obligee']; $ins_data['id_number'] = $data['reportinfo']['cert_no']; $ins_data['obligee_percent'] = $data['reportinfo']['obligee_percent']; $ins_data['house_img'] = $data['reportinfo']['house_cert_img_ids']; if (!empty($estate_info)) { $estate_info_arr = explode('。', $estate_info); $deed_number_arr = explode(',', $estate_info_arr[0]); $ins_data['deed_number'] = $deed_number_arr[1]; $estate_right_arr = explode(',', $estate_info_arr[1]); $estate_status_arr = explode(':', $estate_right_arr[0]); $ins_data['estate_status'] = $estate_status_arr[1]; $mortgagee_info_arr = array_values(array_filter(explode(' ', $estate_right_arr[1]))); $a = 1; $b = 1; /*for ($i=1; $i8) { break; } }*/ if($ins_data['estate_status']=='有效'){ $ins_data['seal_up_unit'] = NULL; $ins_data['seal_up_date'] = NULL; for ($i=1; $i<10; $i++) { $ins_data['mortgagee' . $i] = NULL; $ins_data['mortgagee_date' . $i] = NULL; } }else{ for ($i=1; $i9) { break; } } } } $map = []; $map[] = ['building_name','=',$ins_data['building_name']]; $map[] = ['building_no','=',$ins_data['building_no']]; $map[] = ['unit_no','=',$ins_data['unit_no']]; $estate_data = Db::name('estate_info')->where($map)->find(); if ($estate_data) { if ( $estate_data['estate_year']==$ins_data['estate_year'] && $estate_data['estate_cert_num']==$ins_data['estate_cert_num'] && $estate_data['new_online_info']==$ins_data['new_online_info'] && isset($insert_data['new_online_info']['estate_status']) && $ins_data['new_online_info']['estate_status'] == $estate_data['estate_status']) { return true; } else { $ins_data['update_time'] = date('Y-m-d H:i:s'); if (!Db::name('estate_info')->where('id='.$estate_data['id'])->update($ins_data)) { return false; } else { $insert_data = $ins_data; $insert_data['e_id'] = $estate_data['id']; $insert_data['operation'] = 2; $insert_data['desc'] = '修改房产信息'; $insert_data['operator'] = $this->userInfo['user_name']; if (Db::name('estate_info_history')->insert($insert_data)) { return true; } else { return false; } } } } else { $ins_data['update_time'] = date('Y-m-d H:i:s'); $insert_data = $ins_data; $ins_data['create_time'] = date('Y-m-d H:i:s'); if (!Db::name('estate_info')->insert($ins_data)) { return false; } else { $e_id = Db::name('estate_info')->getLastInsID(); $insert_data['e_id'] = $e_id; $insert_data['operation'] = 1; $insert_data['desc'] = '新增房产信息'; $insert_data['operator'] = $this->userInfo['user_name']; if (Db::name('estate_info_history')->insert($insert_data)) { return true; } else { return false; } } } } /** * 保存报告基本信息 * * @return void */ public function saveReportBaseInfo() { $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('report_no,e_case_code,status,quot_id,print_cpy_no,business_type')->where('id', $data['reportid'])->find(); if (empty($res)) return $this->buildFailed('找不到报告'); // if ($res['status'] == 2) return $this->buildFailed('该订单报告已提交'); // if ($res['status'] == 3) return $this->buildFailed('该订单报告已完成'); $inquiry_info = Db::name('inquiry')->where('id', $res['quot_id'])->find(); if (empty($inquiry_info)) return $this->buildFailed('找不到询价信息'); $bank_name = $inquiry_info['bank_name']; if( $bank_name == '中国光大银行' && $data['ceb_product_type'] == "null" ) { return $this->buildFailed('请选择贷款品种。'); } $inquiry_update_date = []; $bank_sub_id = 0; if (!empty($data['bank_sub_name'])) { $bank_sub_name_info_id = Db::name('bank')->where(['pid' => $inquiry_info['bank_branch_id'], 'name' => $data['bank_sub_name']])->value('id'); if (empty($bank_sub_name_info_id)) { $bank_sub_id = Db::name('bank')->insertGetId([ 'pid' => $inquiry_info['bank_branch_id'], 'name' => $data['bank_sub_name'], 'create_time' => time(), 'update_time' => time(), 'update_uid' => $this->userInfo['user_id'], 'update_name' => $this->userInfo['user_name'], ]); } else { if ($bank_sub_name_info_id != $inquiry_info['bank_sub_id']) { $bank_sub_id = $bank_sub_name_info_id; } } } if (!empty($bank_sub_id)) { $inquiry_update_date['bank_sub_id'] = $bank_sub_id; $inquiry_update_date['bank_sub_name'] = $data['bank_sub_name']; } $bank_customer_mgr_id = 0; if (!empty($data['bank_customer_mgr_name'])) { if (!empty($bank_sub_id)) { $account_manager_id = Db::name('account_manager')->where([ 'bank_id' => $inquiry_info['bank_id'], 'bank_branch_id' => $inquiry_info['bank_branch_id'], 'bank_sub_id' => $bank_sub_id, 'name' => $data['bank_customer_mgr_name'], ])->value('id'); if (empty($account_manager_id)) { $bank_customer_mgr_id = Db::name('account_manager')->insertGetId([ 'bank_id' => $inquiry_info['bank_id'], 'bank_name' => $bank_name, 'bank_branch_id' => $inquiry_info['bank_branch_id'], 'bank_branch_name' => $inquiry_info['bank_branch_name'], 'bank_sub_id' => $bank_sub_id, 'bank_sub_name' => $data['bank_sub_name'], 'name' => $data['bank_customer_mgr_name'], ]); } else { if ($account_manager_id != $inquiry_info['bank_customer_mgr_id']) { $bank_customer_mgr_id = $account_manager_id; } } } } if (!empty($bank_customer_mgr_id)) { $inquiry_update_date['bank_customer_mgr_id'] = $bank_customer_mgr_id; $inquiry_update_date['bank_customer_mgr_name'] = $data['bank_customer_mgr_name']; } if (!empty($inquiry_update_date)) { $upd_res = Db::name('inquiry')->where('id',$res['quot_id'])->update($inquiry_update_date); if (!$upd_res) { return $this->buildFailed('保存客户经理信息失败'); } } $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']); } $result = $reportModel->allowField(true)->save($data, ['id' => $data['reportid']]); if (!$result) { return $this->buildFailed('保存报告基础信息失败'); } return $this->buildSuccess(); } //提交报告 admin/ReportManage/subReport public function subReport() { $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('report_no,e_case_code,status,quot_id,print_cpy_no,business_type')->where('id', $data['reportid'])->find(); if (empty($res)) return $this->buildFailed('找不到报告'); if ($res['status'] == 2) return $this->buildFailed('该订单报告已提交'); if ($res['status'] == 3) return $this->buildFailed('该订单报告已完成'); $inquiry_info = Db::name('inquiry')->where('id', $res['quot_id'])->find(); if (empty($inquiry_info)) return $this->buildFailed('找不到询价信息'); $bank_name = $inquiry_info['bank_name']; if( $bank_name == '中国光大银行' && $data['ceb_product_type'] == "null" ) { return $this->buildFailed('请选择贷款品种。'); } $inquiry_update_date = []; $bank_sub_id = 0; if (!empty($data['bank_sub_name'])) { $bank_sub_name_info_id = Db::name('bank')->where(['pid' => $inquiry_info['bank_branch_id'], 'name' => $data['bank_sub_name']])->value('id'); if (empty($bank_sub_name_info_id)) { $bank_sub_id = Db::name('bank')->insertGetId([ 'pid' => $inquiry_info['bank_branch_id'], 'name' => $data['bank_sub_name'], 'create_time' => time(), 'update_time' => time(), 'update_uid' => $this->userInfo['user_id'], 'update_name' => $this->userInfo['user_name'], ]); } else { if ($bank_sub_name_info_id != $inquiry_info['bank_sub_id']) { $bank_sub_id = $bank_sub_name_info_id; } } } if (!empty($bank_sub_id)) { $inquiry_update_date['bank_sub_id'] = $bank_sub_id; $inquiry_update_date['bank_sub_name'] = $data['bank_sub_name']; } $bank_customer_mgr_id = 0; if (!empty($data['bank_customer_mgr_name'])) { if (!empty($bank_sub_id)) { $account_manager_id = Db::name('account_manager')->where([ 'bank_id' => $inquiry_info['bank_id'], 'bank_branch_id' => $inquiry_info['bank_branch_id'], 'bank_sub_id' => $bank_sub_id, 'name' => $data['bank_customer_mgr_name'], ])->value('id'); if (empty($account_manager_id)) { $bank_customer_mgr_id = Db::name('account_manager')->insertGetId([ 'bank_id' => $inquiry_info['bank_id'], 'bank_name' => $bank_name, 'bank_branch_id' => $inquiry_info['bank_branch_id'], 'bank_branch_name' => $inquiry_info['bank_branch_name'], 'bank_sub_id' => $bank_sub_id, 'bank_sub_name' => $data['bank_sub_name'], 'name' => $data['bank_customer_mgr_name'], ]); } else { if ($account_manager_id != $inquiry_info['bank_customer_mgr_id']) { $bank_customer_mgr_id = $account_manager_id; } } } } if (!empty($bank_customer_mgr_id)) { $inquiry_update_date['bank_customer_mgr_id'] = $bank_customer_mgr_id; $inquiry_update_date['bank_customer_mgr_name'] = $data['bank_customer_mgr_name']; } if (!empty($inquiry_update_date)) { $upd_res = Db::name('inquiry')->where('id',$res['quot_id'])->update($inquiry_update_date); if (!$upd_res) { return $this->buildFailed('保存客户经理信息失败'); } } Db::startTrans(); try { //更新信息 if ($res['status'] == 1) { //status 1 待制作 // 提交重新校验报告编号和提取码 /*$appraisal_time = date('Ymd', strtotime($data['appraisal_time'])); $no = explode('-', $res['report_no']); $old_assessment_time = substr($no[0] ,0, 4) . substr($no[1] ,0, 4); if ($appraisal_time != $old_assessment_time) { // 如果评估时间变了,报告号和电子提取码也会变 $report_no_new = $reportModel->changeReportNo($res['quot_id'], $res['business_type'], $appraisal_time); $data['report_no'] = $report_no_new['report_no']; $data['e_case_code'] = $reportModel->changeElectronCode($res['quot_id'], $report_no_new['second'], $appraisal_time); $data['report_url'] = NULL; $data['report_qrcode'] = NULL; $data['create_reportNo_time'] = date('Y-m-d H:i:s'); }*/ $data['producer_id'] = $this->userInfo['user_id']; $data['producer_name'] = $this->userInfo['user_name']; $data['produce_time'] = empty($data['produce_time']) ? date('Y-m-d', time()) : $data['produce_time']; $data['status'] = 2;//待审核 //更新询单状态 Db::name('inquiry')->where('id', $res['quot_id'])->update(['status' => 7, 'update_time' => date('Y-m-d H:i:s', time())]); } elseif ($res['status'] == 2) { $data['reviewer_id'] = $this->userInfo['user_id']; $data['reviewer_name'] = $this->userInfo['user_name']; $data['review_time'] = empty($data['review_time']) ? date('Y-m-d', time()) : $data['review_time']; $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::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) { 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']); } $result = $reportModel->allowField(true)->save($data, ['id' => $data['reportid']]); if (!$result) { Db::rollback(); return $this->buildFailed('提交报告数据失败'); } //推送消息 if ($res['status'] == 1) {//待制作 //写入消息 PublicMessage($res['quot_id'],6,10); } elseif ($res['status'] == 2) {//待审核 //写入消息 PublicMessage($res['quot_id'],2,11); } Db::commit(); return $this->buildSuccess(); } catch (\Exception $e) { // 回滚事务 Db::rollback(); return $this->buildFailed('操作失败' . $e->getMessage()); } } //完成报告 /*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')->where('id', $data['reportid'])->find(); if (empty($res)) return $this->buildFailed('找不到报告'); if ($res['status'] == 3) return $this->buildFailed('该订单报告已完成'); $data['completion_time'] = time(); $data['status'] = 3;//完成 //打印数量大于等于1时,线下报告状态为待装订打印 if ($res['print_cpy_no'] >= 1) { $data['offline_report_status'] = 1;//待装订打印 } $bank_name = Db::name('inquiry')->where('id', $res['quot_id'])->value('bank_name'); if ($bank_name == '中国建设银行') { $data['seal_status'] = 1;//盖章状态 1待盖章 } if ($bank_name != '中国光大银行') { unset($data['ceb_product_type']); } 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']); } $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()); } }*/ 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()); } } } /*public function produceReport() { $report_id = $this->request->param('report_id'); $cur_tmpl_id = $this->request->param('cur_tmpl_id'); if (empty($report_id)) return $this->buildFailed('报告id不能为空!'); if (empty($cur_tmpl_id)) return $this->buildFailed('报告模板id不能为空!'); Log::debug('生成报告2'); Log::debug('report_id:' . $report_id); Log::debug('cur_tmpl_id:' . $cur_tmpl_id); $result = $this->makeReportUploadToCos($report_id, $cur_tmpl_id); if($result['code'] == -1) { return $this->buildFailed('报告制作失败:' . $result['msg']); } return $this->buildSuccess([]); }*/ public function produceReport($report_id, $cur_tmpl_id) { // $report_id = $this->request->param('report_id'); // $cur_tmpl_id = $this->request->param('cur_tmpl_id'); // if (empty($report_id)) return $this->buildFailed('报告id不能为空!'); // if (empty($cur_tmpl_id)) return $this->buildFailed('报告模板id不能为空!'); Log::debug('生成报告2'); Log::debug('report_id:' . $report_id); Log::debug('cur_tmpl_id:' . $cur_tmpl_id); $result = $this->makeReportUploadToCos($report_id, $cur_tmpl_id); // 检查返回值类型 if (is_bool($result)) { // 如果返回布尔值,false表示失败 return $result; } elseif (is_array($result) && isset($result['code']) && $result['code'] == -1) { // 如果返回数组且code为-1,表示失败 return false; } elseif (is_object($result) && method_exists($result, 'getData')) { // 如果返回Response对象,检查其数据 $data = $result->getData(); if (isset($data['code']) && $data['code'] == -1) { return false; } } // 其他情况视为成功 return true; } private function makeReportUploadToCos($report_id, $cur_tmpl_id) { Log::debug('生成报告3'); $res = Db::name('report')->field('quot_id,report_tmpl_id,report_no,status,report_url,old_report_url,report_file_id,cur_tmpl_id,report_qrcode,e_case_code,report_source') ->where('id', $report_id)->find(); $inquiry = Db::name('inquiry')->field('id,is_multiple,bank_name,is_simple,order_no_en')->where('id', $res['quot_id'])->find(); //判断简易报告 if ($inquiry['is_simple'] == 1) { $template = Db::name('report_template_detail_simple')->where(new Where(['status' => 1, 'report_tmpl_id' => 99]))->order('sort', 'asc')->select(); if (empty($template)) { Log::error('查不到简易报告模板'); return false; } $value = new SimpleTemplate();//简易报告参数 } else { //报告状态为待制作、待审核 if (!empty($res['report_file_id'])) { Log::error('上传的报告不可预览!'); return false; } if (empty($cur_tmpl_id)) { $cur_tmpl_id = $res['cur_tmpl_id']; if(empty($cur_tmpl_id)) { Log::error('缺少报告模板'); return false; } } $template = Db::name('report_template')->where('id', $cur_tmpl_id)->value('report_info'); if (empty($template)) { Log::error('查不到报告模板'); return false; } $template = json_decode($template, true); //判断订单是否多套 if (!empty($inquiry) && $inquiry['is_multiple'] == 1) { Log::error("多套"); $value = new OffsiteTwoTemplate();//多套报告参数 } else { Log::error("单套"); $value = new OffsiteOneTemplate();//单套报告参数 } } $e_case_code = $res['e_case_code']; set_time_limit(0); ini_set('max_execution_time', 0); // 动态覆盖php.ini $info = $value->getValue($report_id); $config = array( 'mode' => 'zh-cn',//zh-cn中文符号不会出现乱码 'format' => 'A4', 'default_font_size' => 14, ); try { //设置中文字体 $mpdf = new Mpdf($config); // 设置字体目录 $mpdf->SetDisplayMode('fullpage'); $mpdf->autoScriptToLang = true; if ($inquiry['bank_name'] != '中国建设银行' && $inquiry['bank_name'] != '珠海华润银行' && $inquiry['bank_name'] != '中信银行' && $inquiry['bank_name'] != '广发银行' && $inquiry['bank_name'] != '华夏银行' && $inquiry['bank_name'] != '徽商银行股份有限公司' && $inquiry['bank_name'] != '融兴村镇银行' && $inquiry['bank_name'] != '平安银行股份有限公司') { $mpdf->autoLangToFont = true; } ob_end_clean(); //加水印 //$img_water = ROOT_PATH . 'public' . DS . 'static/background.png'; //$mpdf->SetWatermarkImage($img_water, 0.1, 10);//参数一是图片的位置(图片相对目录 为处理脚本的相对目录),参数二是透明度0.1-1 //$mpdf->showWatermarkImage = true; //设置自动分页符 $mpdf->SetAutoPageBreak(TRUE); $start_module = null; // 目录所在模块 index $end_module = null; // 估价对象位置所在模块 index foreach ($template as $k => $v) { // ===================== 先定位:目录 / 估价对象位置 模块 ===================== if (mb_strpos($v['module_name'], '目录') !== false) { $start_module = $k; } if (mb_strpos($v['module_name'], '估价对象位置') !== false) { $end_module = $k; } } foreach ($template as $k => $v) { $this->assign('info', $info); $data = $this->display($v['content'], $info)->getContent(); // 分页 $resetpagenum = ''; if ($k == $start_module + 1) { $resetpagenum = 1; // 目录后一页开始页码从 1 开始 } if (mb_strpos($v['module_name'], '横向') !== false) { $mpdf->AddPage('L', false, $resetpagenum, '', '', '', '', '', 15); } else { $mpdf->AddPage('', false, $resetpagenum, '', '', '', '', '', 15); } // ===================== 核心:是否显示页码 ===================== $show_footer = false; if ($inquiry['is_simple'] != 1) { if ($start_module !== null && $end_module !== null) { if ($k > $start_module && $k < $end_module) { $show_footer = true; } } if ($show_footer) { $footer = '
第 {PAGENO} 页
'; $mpdf->SetHTMLFooter($footer); } else { $mpdf->SetHTMLFooter(''); } } else { $footer = '
第 {PAGENO} 页
'; $mpdf->SetHTMLFooter($footer); } // ===================== 页眉LOGO 不动 ===================== if ($k === 0) { $img_file10 = ROOT_PATH . 'public' . DS . 'static/logo3.jpg'; $mpdf->Image($img_file10, 70, 40, 72.5, 60, '', '', true, true); } else { $img_file10 = ROOT_PATH . 'public' . DS . 'static/header_logo3.png'; $header = ''; $mpdf->SetHTMLHeader($header, '', true); } $mpdf->WriteHTML($data); } Log::debug('生成报告4'); $Path = config('uploadFile.img_path') . DS . 'uploads' . DS . 'pdf' . DS; if (!file_exists($Path)) { //检查是否有该文件夹,如果没有就创建,并给予最高权限 mkdir($Path, 0777, true); } $file_name = md5(uniqid()); $filename = DS . 'uploads' . DS . 'pdf' . DS . $file_name . ".pdf"; $filePath = $Path . DS . "{$file_name}.pdf"; $mpdf->Output($Path.$file_name.'.pdf', "F"); Log::debug('生成报告5'); //上传文件 $upload = ossUpload(trim(str_replace("\\", "/", $filename), '/'), $filePath); @unlink($filePath); //把本地图片删除(原图) //报告PDF地址 $url = config('uploadFile.url') . $filename; //保存报告URL 20-8-5 亮哥要求增加 $reportData = ['report_file_produce_time' => date('Y-m-d H:i:s', time())]; $reportData = ['report_url' => $url]; Log::debug('生成报告6'); //更新报告pdf生成时间 Db::name('report')->where('id', $report_id)->update($reportData); } catch(\Exception $e) { Log::error('错误文件:'.$e->getFile()); Log::error('错误行数:'.$e->getLine()); Log::error('错误编码:'.$e->getCode()); Log::error('错误信息:'.$e->getMessage()); return false; } return true; } //测试方法-比较法简单信息 admin/ReportManage/methodSimpleInfo public function methodSimpleInfo() { $data = $this->request->post(); if (empty($data['reportid'])) return $this->buildFailed('报告id不能为空!'); if (empty($data['property_cert_info_id'])) return $this->buildFailed('请选择物业!'); $res = Db::name('method_simple')->field('id,property_cert_info_id,item,trade_date,building_name,size,floor_number1,unit_type,floor_number2,price,transactions,attachment_id')->where('property_cert_info_id', $data['property_cert_info_id'])->order('id', 'asc')->select(); $building_name = Db::name('property_cert_info')->where('id', $data['property_cert_info_id'])->field('building_name,size')->find(); $surveyInfo = Db::name('survey')->alias('x')->join('survey_detail d', 'x.id=d.survey_id')->where('x.property_cert_info_id', $data['property_cert_info_id'])->field('unit_type,floor_no')->find(); //户型new $priceInfo = Db::name('return_price')->where('property_cert_info_id', $data['property_cert_info_id'])->order('id', 'desc')->field('eva_unit_price')->find(); // if (empty($surveyInfo)) return $this->buildFailed('数据有误,查勘信息不存在!'); if (empty($priceInfo)) return $this->buildFailed('数据有误,调价信息不存在'); if (empty($res)) { // 搜索同一楼盘的历史可比案例 $where = []; $where[] = ['a.building_name', '=', $building_name['building_name']]; $where[] = ['a.property_cert_info_id', '<>', $data['property_cert_info_id']]; // 确定面积搜索范围 $size_end = $building_name['size'] + 50; if ($building_name['size']<50) { $size_start = 0; } else { $size_start = $building_name['size'] - 50; } $where[] = ['a.building_area', '>', $size_start]; $where[] = ['a.building_area', '<', $size_end]; // 搜索报告已完成的历史数据 $where[] = ['b.status', '=', 3]; // 确定搜索的时间范围 $where[] = ['b.report_file_produce_time', '>', '2022-02-15 00:00:00']; $time_unix_start = time() - 180*24*60*60; $where[] = ['b.report_file_produce_time', '>', date('Y-m-d H:i:s', $time_unix_start)]; $quot_id = Db::name('report_detail') ->alias("a") ->join('pg_report b', 'a.report_id=b.id') ->where($where)->order('b.report_file_produce_time', 'desc') ->value('a.property_cert_info_id'); $history_res = Db::name('method_simple') ->field('id,property_cert_info_id,item,trade_date,building_name,size,floor_number1,unit_type,floor_number2,price,transactions') ->where('property_cert_info_id', $quot_id) ->order('id', 'asc') ->select(); if ($quot_id && $history_res) { foreach ($history_res as &$value) { // $value['id'] = ''; unset($value['id']); $value['property_cert_info_id'] = $data['property_cert_info_id']; } $res = $history_res; } else { //1、面积、楼层案例二数值为物业参数,面积楼层可调整,案例一为-2,案例三为+2,如果为负数,取1,这个设置可修改,页面设置多了一个楼层;2、成交日期为报告制作月份的前三个月;3、交易单价,案例二为本物业的单价,案例一为-200,案例二为+200;4、户型为本物业查勘户型,需可修改;5、交易情况,固定填写“正常” for ($i=0; $i < 3; $i++) { $name = '案例一'; // $size = intval((1*$building_name['size']) - 2); $size = $building_name['size']; // $price = intval((1*$priceInfo['eva_unit_price']) - 200); $price_i = intval(0.01*$priceInfo['eva_unit_price']); //可比案例交易单价由固定加减200调整为加减案例二交易单价的1% $price_i = round($price_i/100)*100; $price = intval((1*$priceInfo['eva_unit_price']) - $price_i); $trade_date = date('Y年m月', strtotime(" last day of -4 month", time())); // $trade_date = '2020年12月'; $floor_no = $surveyInfo['floor_no']?? ''; if ($i == 1) { $name = '案例二'; // $size = intval($building_name['size']); $size = $building_name['size']; $price = intval($priceInfo['eva_unit_price']); $trade_date = date('Y年m月', strtotime(" last day of -3 month", time())); // $trade_date = '2021年01月'; $floor_no = $surveyInfo['floor_no']??''; } elseif ($i == 2) { $name = '案例三'; // $size = intval((1*$building_name['size']) + 2); $size = $building_name['size']; // $price = intval((1*$priceInfo['eva_unit_price']) + 200); $price_i = intval(0.01*$priceInfo['eva_unit_price']); $price_i = round($price_i/100)*100; $price = intval((1*$priceInfo['eva_unit_price']) + $price_i); $trade_date = date('Y年m月', strtotime(" last day of -2 month", time())); // $trade_date = '2021年02月'; $floor_no = $surveyInfo['floor_no']??''; } $list = []; $list['property_cert_info_id'] = $data['property_cert_info_id']; $list['item'] = $name; $list['trade_date'] = $trade_date; $list['building_name'] = $building_name['building_name']; $list['size'] = $size < 0 ? 1 : $size; $list['floor_number1'] = $floor_no; $list['property_type'] = isset($surveyInfo['unit_type']) && !empty($surveyInfo['unit_type'])?$this->getHouseStatus($surveyInfo['unit_type']):''; $list['floor_number2'] = ''; $list['price'] = $price; $list['transactions'] = '正常'; $list['attachment_id'] = []; $list['attachments_list'] = []; $res[] = $list; } } } else { foreach ($res as $key => $value) { $value['price'] = intval($value['price']); $value['attachments_list'] = []; //返回附件 $attachmnet = new Attachment(); if (!empty($value['attachment_id']) && !empty(json_decode($value['attachment_id'], true))){ //获取图片信息 $list = $attachmnet->getUrls(json_decode($value['attachment_id'], true)); $value['attachments_list'] = $list; } } } return $this->buildSuccess($res); } //获取户型 public function getHouseStatus($data) { $result = $data; $data = explode('-', $data); if (is_array($data) && count($data) == 4) { $result = $data[0] . "房" . $data[1] . "厅" . $data[2] . "卫" . $data[3] . "阳台"; } return $result; } //测试方法-比较法正式信息 admin/ReportManage/methodFormalInfo public function methodFormalInfo() { $data = $this->request->post(); if (empty($data['reportid'])) return $this->buildFailed('报告id不能为空!'); if (empty($data['property_cert_info_id'])) return $this->buildFailed('请选择物业!'); $methodFormal = new MethodFormal(); $res = $methodFormal->field('id,property_cert_info_id,transaction_instance,transaction_situation,transaction_date,area_situation,equity_situation,matter_situation,total_situation')->where('property_cert_info_id', $data['property_cert_info_id'])->find(); $info = Db::name('report_detail')->field('building_name,land_location,property_cert_info_id')->where(['report_id' => $data['reportid'], 'property_cert_info_id' => $data['property_cert_info_id']])->find(); if (empty($info)) return $this->buildFailed('报告不存在'); if (empty($res)) { $res['property_cert_info_id'] = $data['property_cert_info_id']; $res['transaction_instance'] = $methodFormal->getTransactionInstance(['building_name', 'land_location', 'traffic', 'matching', 'transaction', 'transaction_date', 'floor', 'price', 'remark'], $info); $res['transaction_situation'] = $methodFormal->getTransactionSituation(['analysis', 'evaluate', 'transaction']); $res['transaction_date'] = $methodFormal->getTransactionDate(['date', 'analysis', 'evaluate'], $data['reportid']); $res['area_situation'] = $methodFormal->getAreaSituation(['total', 'centre', 'gather', 'parking', 'scenery', 'service', 'station', 'transit', 'security', 'facilities']); $res['equity_situation'] = $methodFormal->getEquitySituation(['land', 'house', 'total', 'interest']); $res['matter_situation'] = $methodFormal->getMatterSituation(['floor', 'total', 'newness', 'scenery', 'direction', 'equipment', 'property_type', 'renovation', 'exterior_wall']); $res['total_situation'] = $methodFormal->getTotalSituation(['price', 'weight', 'area_situation', 'correct_result', 'analysis_result', 'equity_situation', 'matter_situation', 'transaction_date', 'transaction_situation'], $info); } $res['building_name'] = $info['building_name']; $res['land_location'] = $info['land_location']; return $this->buildSuccess($res); } //测试方法-收益法信息 admin/ReportManage/methodProfitInfo public function methodProfitInfo() { $data = $this->request->post(); if (empty($data['reportid'])) return $this->buildFailed('报告id不能为空!'); if (empty($data['property_cert_info_id'])) return $this->buildFailed('请选择物业!'); $methodProfit = new MethodProfit(); $res = $methodProfit->field('id,market_research,month_profit,vacancy_rate,insurance_premium,maintenance_cost,remuneration_rate,increase_rate,income_period,month_valid_profit,increase_price,total_area,original_price,insurance_formula,maintenance_formula,added_tax,urban_construction_tax,edu_surcharge,deed_tax,stamp_duty,month_net_profit,year_profit,year_net_profit,appraisal_object,vacant_day,vacant_rate,added_tax_formula,urban_construction_tax_formula,education_surcharges_formula')->where('property_cert_info_id', $data['property_cert_info_id'])->find(); if (empty($res)) { $res['id'] = ''; $res['market_research'] = $this->getMarketResearch(); $res['month_profit'] = ''; $res['vacancy_rate'] = ''; $res['insurance_premium'] = ''; $res['maintenance_cost'] = ''; $res['remuneration_rate'] = ''; $res['increase_rate'] = ''; $res['income_period'] = ''; $res['month_valid_profit'] = ''; $res['total_area'] = ''; $res['original_price'] = ''; $res['insurance_formula'] = '0.08'; $res['maintenance_formula'] = '1'; $res['added_tax'] = ''; $res['urban_construction_tax'] = ''; $res['edu_surcharge'] = ''; $res['deed_tax'] = ''; $res['stamp_duty'] = ''; $res['month_net_profit'] = ''; $res['year_profit'] = ''; $res['year_net_profit'] = ''; $res['appraisal_object'] = ''; $res['vacant_day'] = ''; $res['vacant_rate'] = ''; $res['added_tax_formula'] = '(不含税)月租金≤30000元,免征'; $res['urban_construction_tax_formula'] = '(不含税)月租金≤30000元,免征'; $res['education_surcharges_formula'] = '(不含税)月租金≤30000元,免征'; $res['increase_price'] = ''; } else { $attachmnet = new Attachment(); $market_research = $res['market_research']; $list = []; foreach ($market_research as $key => $value) { $list = []; if (!empty($value['house_imgs'])) { //获取图片信息 $list = $attachmnet->getUrls($value['house_imgs']); } $market_research[$key]['house_imgs_arr'] = $list; } $res['market_research'] = $market_research; } $year = date('Y', time()); $res['one_year'] = date('Y年', strtotime("$year -1 year")) . '平均月租金(元/㎡/月)'; $res['two_year'] = date('Y年', strtotime("$year -2 year")) . '平均月租金(元/㎡/月)'; $res['three_year'] = date('Y年', strtotime("$year -3 year")) . '平均月租金(元/㎡/月)'; return $this->buildSuccess($res); } /** * 测试方法-GY收益法信息[客户端请求 ] * * @return void */ public function methodGYProfitInfo() { $data = $this->request->post(); if (empty($data['reportid'])) return $this->buildFailed('报告id不能为空!'); if (empty($data['property_cert_info_id'])) return $this->buildFailed('请选择物业!'); //$methodProfit = new MethodGyProfit(); $res = Db::name('method_gyprofit')->where('property_cert_info_id', $data['property_cert_info_id'])->find(); return $this->buildSuccess($res); } //获取市场调研-初始数据 private function getMarketResearch() { $result = []; for ($i=0; $i < 3; $i++) { $list = []; $list['house_imgs'] = ''; $list['house_name'] = ''; $list['position'] = ''; $list['floor'] = ''; $list['islimit'] = ''; $list['one_rent'] = ''; $list['two_rent'] = ''; $list['three_rent'] = ''; $list['house_imgs_arr'] = []; $result[] = $list; } return $result; } //获取审核意见信息 public function getApprovalInfo() { $reportid = $this->request->post('reportid'); $property_cert_info_id = $this->request->post('property_cert_info_id'); if (empty($reportid)) return $this->buildFailed('报告id不能为空!'); if (empty($property_cert_info_id)) return $this->buildFailed('请选择物业!'); $res = Db::name('approval_opinion')->field('id,property_cert_info_id,producer_name,maker_date,first_instance,first_instance_date,first_instance_opinion,second_instance,second_instance_date,second_instance_opinion')->where(new Where(['property_cert_info_id' => $property_cert_info_id, 'status' => 1]))->find(); $info = Db::name('report')->field('producer_name,produce_time,create_time,quot_id')->where('id', $reportid)->find(); $inquiry = Db::name('inquiry')->field('user_name')->where('id', $info['quot_id'])->find(); if (empty($res)) {//初始化 $res = array( 'id' => '', 'property_cert_info_id' => $property_cert_info_id, 'producer_name' => $info['producer_name'], 'maker_date' => date('Y-m-d', strtotime($info['produce_time'])), 'first_instance' => $this->userInfo['user_name'], 'first_instance_date' => date('Y-m-d', time()), 'first_instance_opinion' => '', 'second_instance' => $this->userInfo['user_name'], 'second_instance_date' => date('Y-m-d', time()), 'second_instance_opinion' => '' ); } $res['create_time'] = !empty($info['create_time']) ? date('Y-m-d', strtotime($info['create_time'])) : ''; $res['user_name'] = $inquiry['user_name']; return $this->buildSuccess($res); } //报告预览 public function reqPreviewReport() { $postData = $this->postData; if(empty($postData['reportid'])) return $this->buildFailed('请求参数错误'); $url = Db::name('report')->where('id', $postData['reportid'])->value('report_url'); return $this->buildSuccess(['url' => $url]); } /** * 扫描验证防伪页 * * @return void */ public function getAnticounterfeitPage() { $quot_id = $this->request->get("quot_id"); $report_qrcode_unique_key = $this->request->get("key"); $display_data = []; $isReal = true;// 是否真实报告 $err = '000';// 错误码 // 判断询价信息是否存在 $inquiry_info = Db::name('inquiry') ->field('order_no,bank_name,bank_sub_name,eva_purpose') ->where('id', $quot_id) ->find(); if( empty($inquiry_info)) { $isReal = false; $err = '001'; } $property_cert_list = Db::name('property_cert_info') ->field('id,property_full_name,size,evaluated_unit_price,usage,eva_unit_price,eva_total_value,total_taxes1,eva_net_value') ->where('quot_id', $quot_id) ->select(); if( empty($property_cert_list) ) { $isReal = false; $err = '002'; } else { $return_price_info = Db::name('return_price') ->field('eva_unit_price,appraiser_name') ->where('property_cert_info_id', $property_cert_list[0]['id']) ->order("create_time desc") ->find(); if( empty($return_price_info) ) { $isReal = false; $err = '003'; } } // 取报告号 $report_info = Db::name('report')->where('quot_id', $quot_id)->find(); if( empty($report_info)) { $isReal = false; $err = '004'; } if (!$report_info['report_qrcode_unique_key'] || $report_info['report_qrcode_unique_key'] != $report_qrcode_unique_key) { $isReal = false; $err = '005'; } // 报告详情中的委托方列表 $report_client = Db::name('report_detail')->where('report_id', $report_info['id'])->column('client'); $display_data['errorcode'] = $err; $display_data['isReal'] = $isReal; $display_data['full_estate_name_str'] = $property_cert_list[0]['property_full_name'] . (count($property_cert_list) > 1 ? '等共' . count($property_cert_list) . '套' : ''); // 项目名称 $display_data['report_no'] = $report_info['report_no']??''; //报告编号 $display_data['entrusting_party'] = !empty($report_client) ? ($report_client[0] . (count($report_client) > 1 ? '等共' . count($report_client) . '个' : '')) : ''; //委托方 $display_data['eva_purpose'] = $inquiry_info['eva_purpose']??''; // 评估目的 $display_data['valuation_time'] = $report_info['valuation_time']??''; // 价值时间 $display_data['size'] = count($property_cert_list) > 1 ? array_sum(array_column($property_cert_list,'size')) : $property_cert_list[0]['size']; // 评估总面积 $eva_total_value = array_sum(array_column($property_cert_list, 'eva_total_value')); // 评估总价值 $display_data['eva_total_value'] = number_format($eva_total_value, 2, '.', ','); // 评估总价值 $display_data['eva_total_value_wan'] = number_format((float)($eva_total_value / 10000), 4, '.', ','); // 评估总价值万元 $display_data['total_taxes1'] = count($property_cert_list) > 1 ? array_sum(array_column($property_cert_list, 'total_taxes1')) : $property_cert_list[0]['total_taxes1']; // 总税费 $eva_net_value = array_sum(array_column($property_cert_list, 'eva_net_value')); $display_data['eva_net_value'] = number_format($eva_net_value, 2, '.', ','); // 总净值 $display_data['eva_net_value_wan'] = number_format((float)($eva_net_value / 10000), 4, '.', ','); // 总净值万元 $display_data['producer_name'] = $report_info['producer_name']??''; // 报告撰写人 $path = "../public/template/anticounterfeit.html"; if( !$isReal ) { $path = "../public/template/verifyfake.html"; } $f = file_get_contents($path); $this->assign('display_data',$display_data); $c = $this->display($f,$display_data ); $content = $c->getContent(); $page = <<request->post("reportid"); if( empty($reportid) ) { return $this->buildFailed('参数错误'); } $report_info = Db::name('report')->where('id', $reportid)->find(); if( empty($report_info) ) { return $this->buildFailed('报告信息有误'); } if (!$report_info['report_qrcode_unique_key']) { return $this->buildFailed('当前报告的防伪码已作废,无法重复作废,请退回编辑后重新生成'); } $res = Db::name('report')->where('id', $reportid)->update(['report_qrcode_unique_key' => NULL, 'qrvalue' => NULL, 'qrurl' => NULL]); if( !$res ) { return $this->buildFailed('作废防伪码失败'); } return $this->buildSuccess(); } //报告管理-查勘信息获取 public function reqReportSurveyDetail(){ $postData = $this->postData; if (empty($postData['property_cert_info_id'])) return $this->buildFailed('参数不能为空'); $property_cert_info_id = $postData['property_cert_info_id']; $surveyInfo = \Db::name('survey')->alias('x')->join('survey_detail d', 'x.id=d.survey_id')->where(['x.property_cert_info_id' => $property_cert_info_id])->find(); if (empty($surveyInfo)) return $this->buildFailed('查询数据有误'); //查勘完成时间 $surveyInfo['complete_time'] = !empty($surveyInfo['complete_time']) ? date('Y-m-d H:i:s', strtotime($surveyInfo['complete_time'])) : null; if($surveyInfo['survey_type'] == 1 ){ //处理外景信息 $surveyInfo = $this->getWaijingInfo2($surveyInfo); $surveyInfo['scenery'] = str_replace('"' , '' ,$surveyInfo['scenery']); //住宅 //处理四至信息和公共服务设施信息 $surveyInfo['boundaries'] = !empty($surveyInfo['boundaries']) ? json_decode($surveyInfo['boundaries'],1) : (object)[]; $surveyInfo['pub_serv'] = !empty($surveyInfo['pub_serv']) ? json_decode($surveyInfo['pub_serv'],1) : (object)[]; $attachmnet = new Attachment(); //获取图片信息 foreach ($surveyInfo as $key=>$v){ if(strpos($key,'_img_ids')){ $imgId = !empty($v) ? explode(',', $v) : []; $picInfo = []; if($v){ foreach ($imgId as $id){ $imgUrl = $attachmnet->getUrl($id); $picInfo[] = $imgUrl; } } $surveyInfo[$key.'_arr'] = $picInfo; $surveyInfo[$key] = $imgId; } } !empty($surveyInfo['parking_lot']) && $surveyInfo['parking_lot'] = explode(',', $surveyInfo['parking_lot']); } else{ //商业 //外景信息 $surveyInfo = $this->getWaijingInfoBussiness2($surveyInfo); //四至 $surveyInfo['boundaries'] = !empty($surveyInfo['boundaries']) ? json_decode($surveyInfo['boundaries'],1) : (object)[]; //公共设施 $surveyInfo['pub_serv'] = !empty($surveyInfo['pub_serv']) ? json_decode($surveyInfo['pub_serv'],1) : (object)[]; //1、商业繁华程度 $surveyInfo['prosperity_lv'] = !empty($surveyInfo['prosperity_lv']) ? json_decode($surveyInfo['prosperity_lv'],1) : (object)[]; //商圈等级 $surveyInfo['business_district_lv'] = !empty($surveyInfo['business_district_lv']) ? json_decode($surveyInfo['business_district_lv'],1) : (object)[]; //交通条件 $surveyInfo['traffic'] = !empty($surveyInfo['traffic']) ? json_decode($surveyInfo['traffic'],1) : (object)[]; //物业形态 $surveyInfo['property_form'] = (string)$surveyInfo['property_form']; //商业定位 $surveyInfo['commercial_positioning'] = (string)$surveyInfo['commercial_positioning']; //商铺状况 $shop_condition = !empty($surveyInfo['shop_condition']) ? json_decode($surveyInfo['shop_condition'],1) : (object)[]; $surveyInfo['shop_condition'] = $shop_condition; // if(!empty($shop_condition['shop_situation'])){ // //返回空的内铺数据 // $shop_inner_shop = ['width'=>'','length'=>'','distance_entrance'=>'','distance_escalator'=>'', // 'shop_situation_wss'=>'','shop_pillar_shelter2'=>'']; // $shop_condition['shop_inner_shop'] = $shop_inner_shop; // $surveyInfo['shop_condition'] = $shop_condition; // }else{ // //返回空的临街数据 // $shop_beside_street = // ['bay'=>'','depth'=>'','height'=>'','street'=>'', // 'shop_basement'=>'','shop_mezzanine'=>'', // 'shop_green_belt'=>'','shop_ground_meter'=>'','shop_situation_ss'=>'', // 'shop_distance_road'=>'','shop_pillar_shelter1'=>'','shop_beside_street_situation'=>'']; // $shop_condition['shop_beside_street'] = $shop_beside_street; // $surveyInfo['shop_condition'] = $shop_condition; // } //停车状况 $surveyInfo['parking_condition'] = json_decode($surveyInfo['parking_condition'],1); //使用状况 $surveyInfo['usage_condition'] = json_decode($surveyInfo['usage_condition'],1); $attachmnet = new Attachment(); //获取图片信息 foreach ($surveyInfo as $key=>$v){ if(strpos($key,'_img_ids')){ $imgId = !empty($v) ? explode(',', $v) : []; $picInfo = []; if($v){ foreach ($imgId as $id){ $picInfo[] = $attachmnet->getUrl($id); } } $surveyInfo[$key.'_arr'] = $picInfo; $surveyInfo[$key] = $imgId; } } } if($surveyInfo) return $this->buildSuccess($surveyInfo); return $this->buildFailed('未获取到数据'); } //获取住宅信息 private function getWaijingInfo2($surveyInfo){ $living_room = json_decode($surveyInfo['living_room'],1); $kitchen = json_decode($surveyInfo['kitchen'],1); $bathroom = json_decode($surveyInfo['bathroom'],1); $facility = json_decode($surveyInfo['facility'],1); $other = json_decode($surveyInfo['other'],1); $bedroom = json_decode($surveyInfo['bedroom'],1); $surveyInfo['exterior_view'] = !empty($surveyInfo['exterior_view']) ? explode(',', $surveyInfo['exterior_view']) :[]; $surveyInfo['doorplate'] = !empty($surveyInfo['doorplate']) ? explode(',', $surveyInfo['doorplate']) : []; $surveyInfo['special_remarks'] = !empty($surveyInfo['special_remarks']) ? explode(',', $surveyInfo['special_remarks']) :[] ; $allLivingRoom = \Db::name('options_automation')->whereIn('pid', [544,552,562])->select(); $surveyInfo['living_room'] = $this->getAllFacility($living_room, $allLivingRoom); $allKitchen = \Db::name('options_automation')->whereIn('pid', [584,590,593,599])->select(); $surveyInfo['kitchen'] = $this->getAllFacility($kitchen, $allKitchen); $allBathroom = \Db::name('options_automation')->whereIn('pid', [603,609,612,616])->select(); $surveyInfo['bathroom'] = $this->getAllFacility($bathroom, $allBathroom); $allFacility = \Db::name('options_automation')->where('pid','in',[620,624])->select(); $surveyInfo['facility'] = $this->getAllFacility($facility, $allFacility); $allOther = \Db::name('options_automation')->where(['pid'=>628])->select(); $surveyInfo['other'] = $this->getAllFacility($other, $allOther); $allBedroom = \Db::name('options_automation')->whereIn('pid', [700,701,702])->select(); $surveyInfo['bedroom'] = $this->getAllFacility($bedroom, $allBedroom); return $surveyInfo; } //强转int型 private function getInt($data) { foreach ($data as &$value) { $value = (int) $value; } return $data; } //获取 private function getAllFacility($data, $all) { $count1 = $data ? count($data) : 0; $count2 = count($all); $result = []; if($count1 < $count2 && $count1>0){ foreach ($all as $key => $value){ if ($value['key'] != 'shop_facilities_elevator') { $result[$value['key']] = !empty($data[$value['key']]) ? explode(',', $data[$value['key']]) : []; } else { $result[$value['key']] = !empty($data[$value['key']]) ? $data[$value['key']] : []; $result[$value['key'] . '_arr'] = []; if (!empty($data[$value['key']])) { $option = $data[$value['key']]; $arr = [ ['code' => 'keti', 'value' => !empty($option['keti'])?$option['keti']:'', 'status' => !empty($option['keti'])?true:false], ['code' => 'futi', 'value' => !empty($option['futi'])?$option['futi']:'', 'status' => !empty($option['futi'])?true:false], ['code' => 'huoti', 'value' => !empty($option['huoti'])?$option['huoti']:'', 'status' => !empty($option['huoti'])?true:false], ['code' => 'xft', 'value' => !empty($option['xft'])?$option['xft']:'', 'status' => !empty($option['xft'])?true:false] ]; $result[$value['key'] . '_arr'] = $arr; } else { $option = $data[$value['key']]; $arr = [ ['code' => 'keti', 'value' => '', 'status' => false], ['code' => 'futi', 'value' => '', 'status' => false], ['code' => 'huoti', 'value' => '', 'status' => false], ['code' => 'xft', 'value' => '', 'status' => false] ]; $result[$value['key'] . '_arr'] = $arr; } } } }else{ if($count1 == 0){ foreach ($all as $key=>$value){ $result[$value['key']] = []; } } else { $result = $data; } } return $result; } //获取商业 private function getWaijingInfoBussiness2($surveyInfo){ //外景信息选择表 45 2 501 294 $surveyInfo['exterior_wall'] = !empty($surveyInfo['exterior_wall']) ? explode(',', $surveyInfo['exterior_wall']) : []; $surveyInfo['interior_wall'] = !empty($surveyInfo['interior_wall']) ? explode(',', $surveyInfo['interior_wall']): []; $surveyInfo['door_window'] = !empty($surveyInfo['door_window']) ? explode(',', $surveyInfo['door_window']): []; $surveyInfo['ground'] = !empty($surveyInfo['ground']) ? explode(',', $surveyInfo['ground']): []; $surveyInfo['ceiling'] = !empty($surveyInfo['ceiling']) ? explode(',', $surveyInfo['ceiling']): []; $bathroom = json_decode($surveyInfo['bathroom'],1); $facility = json_decode($surveyInfo['facility'],1); $kitchen = json_decode($surveyInfo['kitchen'],1); $allBath = \Db::name('options_automation')->whereIn('pid', [634,636,637,638])->select(); $surveyInfo['bathroom'] = $this->getAllFacility($bathroom, $allBath); $allFacility = \Db::name('options_automation')->whereIn('pid', [308,309,310,311,655])->select(); $surveyInfo['facility'] = $this->getAllFacility($facility, $allFacility); $allKitchen = \Db::name('options_automation')->whereIn('pid', [757,758,759,760])->select(); $surveyInfo['kitchen'] = $this->getAllFacility($kitchen, $allKitchen); return $surveyInfo; } //带制作报告提交修改 public function reqSubmitReportModify(){ //获取数据 $postData = $this->postData; //data:{'wuye1':{'','baseinfo':{'xxx':'xxx'},'Survey':{}},} $report_id = $postData['reportid']; $status = $postData['status']; //2当前待制作 制作 到待审核 3当前待审核 审核 到完成 if($report_id <= 0){ return $this->buildFailed('请求参数错误'); } $singleRes = \Db::name('report')->where(['id'=>$report_id])->find(); // print_r($singleRes);die; if(empty($singleRes)) return $this->buildFailed('该报告不存在'); if($singleRes['status'] != 1 && $status == 1) return $this->buildFailed('该报告当前不是待制作状态 不能制作'); if($singleRes['status'] != 2 && $status == 2) return $this->buildFailed('该报告当前不是待审核状态 不能审核'); $data = $postData['data']; //判断是是住宅还是商业 $i_arr = \Db::name('report') ->alias('r') ->join('inquiry i','r.quot_id=i.id') ->where(['r.id'=>$report_id]) ->field('i.*')->find(); $type = $i_arr['type']; // echo $type;die; \Db::startTrans(); foreach ($data as $key=>$item){ $baseinfo = $item['baseinfo']; $surveyinfo = $item['surveyinfo']; //基本信息 房产证照和公司资质照字段处理 if(!empty($baseinfo['house_cert_img_ids']) && is_array($baseinfo['house_cert_img_ids'])){ $baseinfo['house_cert_img_ids'] = join(',',$baseinfo['house_cert_img_ids']); } if(!empty($baseinfo['company_qualification_img_ids']) && is_array($baseinfo['company_qualification_img_ids'])){ $baseinfo['company_qualification_img_ids'] = join(',',$baseinfo['company_qualification_img_ids']); } //单个物业的信息 //先查找 看有没有 $reportDetailInfo = \Db::name('report_detail') ->where(['report_id'=>$report_id,'building_name'=>$baseinfo['building_name']]) ->find($baseinfo); if($reportDetailInfo){ $baseinfo['update_time'] = date("Y-m-d H:i:s"); $res1[] = \Db::name('report_detail') ->where(['report_id'=>$report_id,'building_name'=>$baseinfo['building_name']]) ->update($baseinfo); }else{ $baseinfo['report_id'] = $report_id; $baseinfo['addtime'] = date("Y-m-d H:i:s"); $res1[] = \Db::name('report_detail')->insert($baseinfo); } $report_detail_id = \Db::name('report_detail') ->where(['building_name'=>$baseinfo['building_name'],'report_id'=>$report_id])->field('id')->find(); if($report_detail_id){ $report_detail_id = $report_detail_id['id']; }else{ \Db::rollback(); return $this->buildFailed('服务器出错'); } if($type == 1){ //处理四至信息和公共设施信息 直接前端传json字符串 存表 if($surveyinfo['boundaries']){ $surveyinfo['boundaries'] = json_encode($surveyinfo['boundaries']); } if($surveyinfo['pub_serv']){ $surveyinfo['pub_serv'] = json_encode($surveyinfo['pub_serv']); } //如果是住宅 删掉商业字段 // unset($surveyinfo['prosperity_lv']); // unset($surveyinfo['business_district_lv']); // unset($surveyinfo['pub_fac']); // unset($surveyinfo['traffic']); // unset($surveyinfo['property_form']); // unset($surveyinfo['business_content']); // unset($surveyinfo['shop_condition']); // unset($surveyinfo['parking_condition']); // unset($surveyinfo['usage_condition']); // unset($surveyinfo['commercial_positioning']); //删除外墙信息 // unset($surveyinfo['exterior_wall']); // unset($surveyinfo['interior_wall']); // unset($surveyinfo['door_window']); // unset($surveyinfo['ceiling']); // unset($surveyinfo['ground']); //处理外景 门牌等信息 也可以直接存储 if(!empty($surveyinfo['living_room'])) $surveyinfo['living_room'] = json_encode($surveyinfo['living_room']); if(!empty($surveyinfo['kitchen'])) $surveyinfo['kitchen'] = json_encode($surveyinfo['kitchen']); } else{ //商业 //商业繁华程度 $surveyinfo['prosperity_lv'] = json_encode($surveyinfo['prosperity_lv']); //商圈等级 $surveyinfo['business_district_lv'] = json_encode($surveyinfo['business_district_lv']); //交通条件 $surveyinfo['traffic'] = json_encode($surveyinfo['traffic']); //商铺状况 shop_condition //只取选中的字段 if($surveyinfo['shop_condition']['shop_situation'] ==1){ unset($surveyinfo['shop_condition']['shop_inner_shop']); }else{ unset($surveyinfo['shop_condition']['shop_beside_street']); } $surveyinfo['shop_condition'] = json_encode($surveyinfo['shop_condition']); //停车状况 $surveyinfo['parking_condition'] = json_encode($surveyinfo['parking_condition']); //使用状况 $surveyinfo['usage_condition'] = json_encode($surveyinfo['usage_condition']); //{"shop_situation": "2", "shop_inner_shop": {"width": "1", "length": "1", "distance_entrance": "1", "distance_escalator": "1", "shop_situation_wss": "1", "shop_pillar_shelter2": "1"}} //如果是商业 删除住宅信息 // unset($surveyinfo['bus_lines']); // unset($surveyinfo['boundaries']); // unset($surveyinfo['pub_serv']); // unset($surveyinfo['scenery']); // unset($surveyinfo['property_intro']); //删除外景信息 // unset($surveyinfo['exterior_view']); // unset($surveyinfo['doorplate']); // unset($surveyinfo['living_room']); // unset($surveyinfo['balcony']); // unset($surveyinfo['kitchen']); // unset($surveyinfo['other']); $surveyinfo['exterior_wall'] = join(',',$surveyinfo['exterior_wall']); $surveyinfo['door_window'] = join(',',$surveyinfo['door_window']); $surveyinfo['interior_wall'] = join(',',$surveyinfo['interior_wall']); $surveyinfo['ceiling'] = join(',',$surveyinfo['ceiling']); $surveyinfo['ground'] = join(',',$surveyinfo['ground']); } if(!empty($surveyinfo['bathroom'])) $surveyinfo['bathroom'] = json_encode($surveyinfo['bathroom']); if(isset($surveyinfo['building_area'])){ $surveyinfo['size'] = $surveyinfo['building_area']; unset($surveyinfo['building_area']); unset($surveyinfo['completion_date']); } if($type == 1){ //住宅 $surveyinfo['facility'] = json_encode($surveyinfo['facility2']); unset($surveyinfo['facility2']); }else{ unset($surveyinfo['facility2']); } $reportSurveyDetail = \Db::name('report_survey_detail') ->where(['report_detail_id'=>$report_detail_id]) ->find(); // print_r($surveyinfo);die; foreach ($surveyinfo as $key=>$value){ if(strpos($key,'_img_ids')){ $imgs = ''; if($value){ $imgs = join(',',$value); $surveyinfo[$key] = $imgs; } } } if($reportSurveyDetail){ $surveyinfo['update_time'] = date('Y-m-d H:i:s'); $res2[] = \Db::name('report_survey_detail') ->where(['report_detail_id'=>$report_detail_id]) ->update($surveyinfo); }else{ $surveyinfo['report_id'] = $report_id; $surveyinfo['report_detail_id'] = $report_detail_id; $res2[] = \Db::name('report_survey_detail') ->insert($surveyinfo); } } //主表状态修改 $updateData['producer_name'] = 1;//先写死 $updateData['produce_time'] = date('Y-m-d H:i:s'); // $updateData['status'] = $status+1; $updateData['update_time'] = date('Y-m-d H:i:s'); $res = \Db::name('report')->where(['id'=>$report_id])->update($updateData); if((in_array(1,$res1) || in_array(1,$res2) ) && $res){ \Db::commit(); $result = [ 'code' => 1, 'msg' => '修改成功', ]; $response = \Response::create($result, 'json'); return $response; } \Db::rollback(); return $this->buildFailed('修改失败'); } //获取报告大区 public function getBigArea() { $res = Db::name('district_info')->field('id,big_district as name')->where('pid', 0)->select(); return $this->buildSuccess($res); } //获取报告小片区 public function getSmallArea() { $pid = input('pid'); if (empty($pid)) return $this->buildFailed('参数不能为空!'); $res = Db::name('district_info')->field('id,small_district as name')->where('pid', $pid)->select(); return $this->buildSuccess($res); } //报告待审核-退回 public function subApprovalReturn() { $reportid = input('reportid'); if (empty($reportid)) return $this->buildFailed('参数不能为空!'); $status = Db::name('report')->where('id', $reportid)->value('status'); if (empty($status)) return $this->buildFailed('查询不到该报告!'); if ($status != 2) { return $this->buildFailed('该报告当前不是待审核状态'); } $quot_id = Db::name('report')->where('id', $reportid)->value('quot_id'); //写入消息 PublicMessage($quot_id,6,12); $data['producer_id'] = null; $data['producer_name'] = null; $data['produce_time'] = null; $data['reviewer_id'] = null; $data['reviewer_name'] = null; $data['review_time'] = null; $data['review_status'] = 1; $data['reviewer2_id'] = null; $data['reviewer2_name'] = null; $data['reviewer2_time'] = null; $data['review2_status'] = 1; $data['status'] = 1;//待审核 $data['update_time'] = date('Y-m-d H:i:s', time()); if (!Db::name('report')->where('id', $reportid)->update($data)) { return $this->buildFailed('操作失败!'); } //更新询单状态 Db::name('inquiry')->where('id', $quot_id)->update(['status' => 6, 'update_time' => date('Y-m-d H:i:s', time())]); return $this->buildSuccess(); } //报告管理-退回 public function subFinishReturn() { $reportid = input('reportid'); if (empty($reportid)) return $this->buildFailed('参数不能为空!'); $status = Db::name('report')->where('id', $reportid)->value('status'); if (empty($status)) return $this->buildFailed('查询不到该报告!'); if ($status != 3) { return $this->buildFailed('该报告当前不是已完成状态'); } // $quot_id = Db::name('report')->where('id', $reportid)->value('quot_id'); $inquiry_data = Db::name('report')->where('id', $reportid)->field('quot_id,report_no')->find(); //写入消息 // PublicMessage($quot_id,7,13); PublicMessage($inquiry_data['quot_id'],7,13); $data['completion_time'] = null; $data['status'] = 2;//待审核 $data['update_time'] = date('Y-m-d H:i:s', time()); $data['reviewer_id'] = null; $data['reviewer_name'] = null; $data['review_time'] = null; $data['review_status'] = 1; $data['reviewer2_id'] = null; $data['reviewer2_name'] = null; $data['reviewer2_time'] = null; $data['report_url'] = null; $data['qrvalue'] = null; $data['qrurl'] = null; $data['report_qrcode'] = null; $data['report_qrcode_unique_key'] = null; $data['review2_status'] = 1; if (!Db::name('report')->where('id', $reportid)->update($data)) { return $this->buildFailed('操作失败!'); } //更新询单状态 // Db::name('inquiry')->where('id', $quot_id)->update(['status' => 7, 'update_time' => date('Y-m-d H:i:s', time())]); Db::name('inquiry')->where('id', $inquiry_data['quot_id'])->update(['status' => 7, 'update_time' => date('Y-m-d H:i:s', time())]); // 删除费用管理表相关记录 Db::name('charge')->where(['report_no'=>$inquiry_data['report_no']])->delete(); return $this->buildSuccess(); } //报告管理-建行报告盖章列表 public function reportSealList() { $data = $this->postData; $map = []; $map[] = ['i.status', '=', 8];//订单状态 报告已完成 $map[] = ['i.bank_name', '=', '中国建设银行'];//数据源 均来自于订单状态=报告已完成的数据 且银行=中国建设银行 $map[] = ['r.report_source', '=', 1];//报告来源 1新系统 //todo 加上userId条件 if (isset($data['user_name']) && !empty($data['user_name'])){ $map[] = ['i.buss_username', 'like', '%'.trim($data['user_name']).'%']; } if (isset($data['seal_status']) && !empty($data['seal_status'])){ $map[] = ['r.seal_status', '=', $data['seal_status']]; } else { $map[] = ['r.seal_status', 'in', [1,2]]; } if (!empty($data['start_time']) || !empty($data['end_time'])){ // $map[] = getQueryDate('i.create_time', $data['start_time'], $data['end_time']); $map[] = getQueryDate('r.report_file_produce_time', $data['start_time'], $data['end_time']); } if (isset($data['search_text']) && !empty($data['search_text'])){ $map[] = ['d.property_full_name', 'like', '%'.trim($data['search_text']).'%']; } $subsql = Db::table('pg_return_price') ->field('property_cert_info_id,create_time,eva_unit_price,eva_total_value,eva_net_value') ->group('property_cert_info_id')->order('property_cert_info_id', 'desc')->buildSql(); $list = Db::name('report') ->alias('r') ->join('inquiry i','r.quot_id=i.id') ->join('property_cert_info d','i.id=d.quot_id') // ->join([$subsql => 'p'], 'd.id = p.property_cert_info_id', 'left') ->join('return_price p', 'd.id = p.property_cert_info_id', 'left') ->join('report_detail rd', 'r.id=rd.report_id and d.id=rd.property_cert_info_id') ->where($map) ->field('r.id,d.quot_id,r.report_no,r.e_case_code,d.id as property_cert_info_id,d.city,i.type,i.is_multiple,d.size,p.eva_unit_price,p.eva_total_value,i.bank_name,i.bank_sub_name,r.create_time,i.buss_username as user_name,r.producer_name,r.reviewer_name,r.recipient_name,r.recipient_time,r.seal_status') // ->order('r.create_time', 'desc') ->order('r.report_file_produce_time desc,p.id desc') ->group('i.id') ->paginate($this->getPage()) ->each(function ($item, $key){ $item['type_str'] = getDictionaryName('BUSINESS_TYPE', $item['type']); $item['bank_name'] = !empty($item['bank_name']) && !empty($item['bank_sub_name']) ? $item['bank_name'] . $item['bank_sub_name'] : $item['bank_name']; $full_estate_name_info = Db::table('pg_property_cert_info') ->where('quot_id', $item['quot_id']) ->order('id', 'desc') ->column('property_full_name'); $item['full_estate_name_info'] = array('show' => !empty($full_estate_name_info) ? $full_estate_name_info[0] : '', 'property_full_name' => $full_estate_name_info); $return_price_info = Db::name('return_price') ->where(['property_cert_info_id'=>$item['property_cert_info_id']]) ->field('eva_unit_price,eva_total_value') ->order('id', 'desc') ->find(); $item['eva_unit_price'] = $return_price_info['eva_unit_price']; $item['eva_total_value'] = $return_price_info['eva_total_value']; unset($item['bank_sub_name']); $item['is_multi_str'] = getDictionaryName('INQUIRY_NUMBER', $item['is_multiple']); $item['seal_status_str'] = getDictionaryName('SEAL_STATUS', $item['seal_status']); $item['recipient_time'] = !empty($item['recipient_time']) ? date('Y-m-d H:i:s', $item['recipient_time']) : ''; return $item; }) ->toArray(); return $this->buildSuccess(['data' => $list['data'], 'count' => $list['total']]); } //建行报告盖章-完成盖章 public function subReportSeal() { $id = input('id/a'); if (empty($id)) return $this->buildFailed('请选择报告!'); foreach ($id as $key => $value) { $check = Db::name('report')->field('id,report_no,seal_status')->where('id', $value)->find(); if (empty($check)) return $this->buildFailed('没有找到报告!'); if ($check['seal_status'] != 1) { continue; //如果全选中有完成打印装订的订单,跳过当前单 继续循环 } elseif ($check['seal_status'] == 1) { Db::name('report')->where('id', $value)->update(['seal_status' => 2, 'update_time' => date('Y-m-d H:i:s', time())]); $quot_id = Db::name('report')->where('id', $value)->value('quot_id'); //写入消息 PublicMessage($quot_id,2,14); } } return $this->buildSuccess(); } //迁移报告列表 public function moveReportList() { $data = $this->postData; $map = []; $map[] = ['r.report_source', '=', 2];//报告来源 2老系统 if (isset($data['search_text']) && !empty($data['search_text'])){ $map[] = ['d.property_full_name', 'like', '%'.trim($data['search_text']).'%']; } $subsql = Db::table('pg_return_price') ->field('property_cert_info_id,create_time,eva_unit_price,eva_total_value,eva_net_value') ->group('property_cert_info_id')->order('property_cert_info_id', 'desc')->buildSql(); $res = Db::name('report')->alias('r') ->join('inquiry i', 'r.quot_id=i.id') ->join('property_cert_info d', 'i.id=d.quot_id') // ->join([$subsql => 'p'], 'd.id = p.property_cert_info_id', 'left') ->join('return_price p', 'd.id = p.property_cert_info_id', 'left') ->where($map) ->field('r.id,d.quot_id,r.report_no,r.e_case_code,p.eva_unit_price,p.eva_total_value,i.bank_name,i.bank_sub_name,i.eva_purpose,r.completion_time') // ->order('r.create_time', 'desc') ->order('r.create_time desc,p.id desc') ->group('i.id') ->paginate($this->getPage()) ->each(function ($item, $key){ $item['bank_name'] = !empty($item['bank_name']) && !empty($item['bank_sub_name']) ? $item['bank_name'] . $item['bank_sub_name'] : $item['bank_name']; $full_estate_name_info = Db::table('pg_property_cert_info') ->where('quot_id', $item['quot_id']) ->order('id', 'desc') ->column('property_full_name'); $item['full_estate_name_info'] = array('show' => !empty($full_estate_name_info) ? $full_estate_name_info[0] : '', 'property_full_name' => $full_estate_name_info); unset($item['bank_sub_name']); $item['completion_time'] = !empty($item['completion_time']) ? date('Y-m-d H:i:s', $item['completion_time']) : ''; $item['size'] = Db::name('property_cert_info')->where(new Where(['quot_id' => $item['quot_id']]))->sum('size'); return $item; }) ->toArray(); return $this->buildSuccess(['count' => $res['total'], 'data' => $res['data']]); } //简易打印装订列表 public function easyPrintList() { $data = $this->postData; $map = []; $map[] = ['i.status', '=', 8];//订单状态 报告已完成 $map[] = ['i.is_simple', '=', 1]; //todo 加上userId条件 if (isset($data['user_name']) && !empty($data['user_name'])){ $map[] = ['i.user_name', 'like', '%'.trim($data['user_name']).'%']; } if (isset($data['offline_report_status']) && !empty($data['offline_report_status'])){ $map[] = ['r.offline_report_status', '=', $data['offline_report_status']]; } if (!empty($data['start_time']) || !empty($data['end_time'])){ $map[] = getQueryDate('i.create_time', $data['start_time'], $data['end_time']); } if (isset($data['search_text']) && !empty($data['search_text'])){ $map[] = ['d.property_full_name', 'like', '%'.trim($data['search_text']).'%']; } $subsql = Db::table('pg_return_price') ->field('property_cert_info_id,create_time,eva_unit_price,eva_total_value,eva_net_value') ->group('property_cert_info_id')->order('property_cert_info_id', 'desc')->buildSql(); $list = Db::name('report') ->alias('r') ->join('inquiry i','r.quot_id=i.id') ->join('property_cert_info d','i.id=d.quot_id') // ->join([$subsql => 'p'], 'd.id = p.property_cert_info_id', 'left') ->join('return_price p', 'd.id = p.property_cert_info_id', 'left') ->join('report_detail rd', 'r.id=rd.report_id and d.id=rd.property_cert_info_id') ->where($map) ->field('r.id,d.quot_id,r.report_no,r.offline_report_status,i.type,d.id as property_cert_info_id,d.size,p.eva_unit_price,p.eva_total_value,i.create_time,i.user_name,r.recipient_name,r.recipient_time,i.bank_name,i.bank_sub_name') // ->order('i.create_time', 'desc') ->order('r.create_time desc,p.id desc') ->group('i.id') ->paginate($this->getPage()) ->each(function ($item, $key){ $item['type_str'] = getDictionaryName('BUSINESS_TYPE', $item['type']); $full_estate_name_info = Db::table('pg_property_cert_info') ->where('quot_id', $item['quot_id']) ->order('id', 'desc') ->column('property_full_name'); $item['full_estate_name_info'] = array('show' => !empty($full_estate_name_info) ? $full_estate_name_info[0] : '', 'property_full_name' => $full_estate_name_info); $return_price_info = Db::name('return_price') ->where(['property_cert_info_id'=>$item['property_cert_info_id']]) ->field('eva_unit_price,eva_total_value') ->order('id', 'desc') ->find(); $item['eva_unit_price'] = $return_price_info['eva_unit_price']; $item['eva_total_value'] = $return_price_info['eva_total_value']; $item['offline_report_status_str'] = getDictionaryName('OFFLINE_REPORT_STATUS', $item['offline_report_status']); $item['recipient_time'] = !empty($item['recipient_time']) ? date('Y-m-d H:i:s', $item['recipient_time']) : ''; $item['bank_name'] = !empty($item['bank_name']) && !empty($item['bank_sub_name']) ? $item['bank_name'] . $item['bank_sub_name'] : $item['bank_name']; unset($item['bank_sub_name']); return $item; }) ->toArray(); return $this->buildSuccess(['data' => $list['data'], 'count' => $list['total']]); } //提交简易报告操作 public function subEasyPrint() { $id = input('id/a'); $type = input('type'); $name = input('name'); if (empty($type)) return $this->buildFailed('参数有误!'); if (empty($id)) return $this->buildFailed('请勾选列表页数据'); if ($type == 3 && empty($name)) return $this->buildFailed('领取人不能为空!'); foreach ($id as $key => $value) { $check = Db::name('report')->field('id,report_no,offline_report_status')->where('id', $value)->find(); if (empty($check)) return $this->buildFailed('没有找到报告!'); if ($type == 1) {//完成打印装订 if ($check['offline_report_status'] != 1) { return $this->buildFailed('当前线下报告状态不可执行此操作!'); } elseif ($check['offline_report_status'] == 1) { Db::name('report')->where('id', $value)->update(['offline_report_status' => 2, 'update_time' => date('Y-m-d H:i:s', time())]); } } elseif ($type == 2) {//完成盖章 if ($check['offline_report_status'] != 2) { return $this->buildFailed('当前线下报告状态不可执行此操作!'); } elseif ($check['offline_report_status'] == 2) { Db::name('report')->where('id', $value)->update(['offline_report_status' => 3, 'update_time' => date('Y-m-d H:i:s', time())]); } } else {//领取报告 if ($check['offline_report_status'] != 3) { return $this->buildFailed('当前线下报告状态不可执行此操作!'); } elseif ($check['offline_report_status'] == 3) { Db::name('report')->where('id', $value)->update(['offline_report_status' => 4, 'recipient_name' => $name, 'recipient_time' => time(), 'update_time' => date('Y-m-d H:i:s', time())]); } } } return $this->buildSuccess(); } /** * 报告复制 */ public function reportCopy() { $report_no = $this->request->param('report_no'); // 必选项 $remark = $this->request->param('remark'); // 必选项 if (empty($report_no)) { return $this->buildFailed('报告编号不能为空'); } if (empty($remark)) { return $this->buildFailed('备注不能为空'); } // 报告主表数据 $report_data = Db::name('report')->where(['report_no'=>$report_no,'status'=>3])->find(); if (!$report_data) { return $this->buildFailed('无法复制不存在或未完成的报告'); } Db::startTrans(); $inquiry = new Inquiry(); $report = new Report(); // 更新费用表备注 $upd_charge = Db::name('charge')->where(['report_no'=>$report_no])->update(['remark'=>$remark]); if (!$upd_charge) { Db::rollback(); return $this->buildFailed('更新备注失败!'); } // 询价主表数据 $inquiry_data = Db::name('inquiry')->where(['id'=>$report_data['quot_id']])->find(); // 询价主表数据复制 $inquiry_data_copy = $inquiry_data; $inquiry_data_copy['id'] = ''; $inquiry_data_copy['order_no'] = $inquiry->generateInquiryNo($inquiry_data['branchCom_id']); $inquiry_data_copy['status'] = 6; $inquiry_data_copy['seal_status'] = 1; $inquiry_data_copy['estimated_no'] = ''; $inquiry_data_copy['create_time'] = date('Y-m-d H:i:s'); $inquiry_data_copy['update_time'] = date('Y-m-d H:i:s'); $inquiry_data_copy['seal_time'] = NULL; $ins_inquiry = Db::name('inquiry')->insert($inquiry_data_copy); if (!$ins_inquiry) { Db::rollback(); return $this->buildFailed('复制报告失败!'); } $quot_id = Db::name('inquiry')->getLastInsID(); // 报告主表数据复制 $report_data_copy = $report_data; $report_data_copy['id'] = ''; $report_data_copy['quot_id'] = $quot_id; $report_no_new = $report->generateReportNo($report_data['quot_id'], $report_data['business_type']); $report_data_copy['report_no'] = $report_no_new['report_no']; $report_data_copy['e_case_code'] = $report->generateElectronCode($report_data['quot_id'], $report_no_new['second']); $report_data_copy['status'] = 1; $report_data_copy['producer_id'] = NULL; $report_data_copy['producer_name'] = NULL; $report_data_copy['produce_time'] = NULL; $report_data_copy['reviewer_id'] = NULL; $report_data_copy['reviewer_name'] = NULL; $report_data_copy['review_time'] = NULL; $report_data_copy['review_status'] = 1; $report_data_copy['reviewer2_id'] = NULL; $report_data_copy['reviewer2_name'] = NULL; $report_data_copy['reviewer2_time'] = NULL; $report_data_copy['review2_status'] = 1; $report_data_copy['completion_time'] = NULL; $report_data_copy['report_url'] = NULL; $report_data_copy['report_qrcode'] = NULL; $report_data_copy['create_time'] = date('Y-m-d H:i:s'); $report_data_copy['update_time'] = NULL; $report_data_copy['create_reportNo_time'] = date('Y-m-d H:i:s'); $report_data_copy['report_file_produce_time'] = date('Y-m-d H:i:s'); $report_data_copy['report_remark_copy'] = $remark; $ins_report = Db::name('report')->insert($report_data_copy); if (!$ins_report) { Db::rollback(); return $this->buildFailed('复制报告失败!'); } $report_id = Db::name('report')->getLastInsID(); // 询价详细表数据 $inquiry_detail_data = Db::name('property_cert_info')->where(['quot_id'=>$inquiry_data['id']])->select(); foreach ($inquiry_detail_data as $key=>$val) { // 回价数据 $return_data = Db::name('return_price')->where(['property_cert_info_id'=>$val['id']])->order('create_time desc')->find(); // 查勘主表数据 $survey_data = Db::name('survey')->where(['order_no'=>$inquiry_data, 'property_cert_info_id'=>$val['id']])->find(); // 查勘详细表数据 $survey_detail_data = Db::name('survey_detail')->where(['survey_id'=>$survey_data['id']])->find(); // 报告详细表数据 $report_detail_data = Db::name('report_detail')->where(['property_cert_info_id'=>$val['id']])->find(); // 测算方法-比较法正式 $method_formal_data = Db::name('method_formal')->where(['property_cert_info_id'=>$val['id']])->find(); // 测算方法-收益法 $method_profit_data = Db::name('method_profit')->where(['property_cert_info_id'=>$val['id']])->find(); // 测算方法-GY收益法 $method_gyprofit_data = Db::name('method_gyprofit')->where(['property_cert_info_id'=>$val['id']])->find(); // 测算方法-比较法简易 $method_simple_data = Db::name('method_simple')->where(['property_cert_info_id'=>$val['id']])->select(); // 询价详细数据复制 $val['id'] = ''; $val['quot_id'] = $quot_id; $ins_inquiry_detail = Db::name('property_cert_info')->insert($val); $property_cert_info_id = Db::name('property_cert_info')->getLastInsID(); // 回价数据复制 $return_data['id'] = ''; $return_data['property_cert_info_id'] = $property_cert_info_id; $ins_return_price = Db::name('return_price')->insert($return_data); // 查勘数据复制 $survey_data_copy = $survey_data; $survey_data_copy['id'] = ''; $survey_data_copy['order_no'] = $inquiry_data_copy['order_no']; $survey_data_copy['property_cert_info_id'] = $property_cert_info_id; $ins_survey = Db::name('survey')->insert($survey_data_copy); $survey_id = Db::name('survey')->getLastInsID(); // 查勘详细表数据复制 $survey_detail_data_copy = $survey_detail_data; $survey_detail_data_copy['id'] = ''; $survey_detail_data_copy['survey_id'] = $survey_id; $survey_detail_data_copy['living_room'] = !empty($survey_detail_data_copy['living_room']) ? $survey_detail_data_copy['living_room'] : NULL; $survey_detail_data_copy['bedroom'] = !empty($survey_detail_data_copy['bedroom']) ? $survey_detail_data_copy['bedroom'] : NULL; $survey_detail_data_copy['other'] = !empty($survey_detail_data_copy['other']) ? $survey_detail_data_copy['other'] : NULL; $ins_survey_detail = Db::name('survey_detail')->insert($survey_detail_data_copy); // 报告详细表数据复制 $report_detail_data_copy = $report_detail_data; $report_detail_data_copy['id'] = ''; $report_detail_data_copy['report_id'] = $report_id; $report_detail_data_copy['property_cert_info_id'] = $property_cert_info_id; $ins_report_detail = Db::name('report_detail')->insert($report_detail_data_copy); // 案例数据复制(比较法正式) $method_formal_data['id'] = ''; $method_formal_data['property_cert_info_id'] = $property_cert_info_id; $ins_method_formal = Db::name('method_formal')->insert($method_formal_data); // 案例数据复制(收益法) $method_profit_data['id'] = ''; $method_profit_data['property_cert_info_id'] = $property_cert_info_id; $ins_method_profit = Db::name('method_profit')->insert($method_profit_data); // 案例数据复制(GY收益法) $method_gyprofit_data['id'] = ''; $method_gyprofit_data['property_cert_info_id'] = $property_cert_info_id; $ins_method_gyprofit = Db::name('method_gyprofit')->insert($method_gyprofit_data); // 案例数据复制(比较法简易) foreach ($method_simple_data as $k=>$v) { $v['id'] = ''; $v['property_cert_info_id'] = $property_cert_info_id; $ins_method_simple = Db::name('method_simple')->insert($v); if (!$ins_method_simple) { break; } } if ($inquiry_data['type']==2) { $ins_method_simple = 1; } if (!$ins_inquiry_detail || !$ins_return_price || !$ins_survey || !$ins_survey_detail || !$ins_report_detail || !$ins_method_formal || !$ins_method_profit || !$ins_method_gyprofit || !$ins_method_simple) { Db::rollback(); return $this->buildFailed('复制报告失败!'); } } Db::commit(); return $this->buildSuccess('', '复制报告成功!'); } /** * 修改报告编号 */ public function changeReportNo() { $report_no = $this->request->param('report_no'); // 必选项 if (empty($report_no)) { return $this->buildFailed('报告编号不能为空'); } // 报告主表数据 $report_data = Db::name('report')->where(['report_no'=>$report_no,'status'=>1])->find(); if (!$report_data) { return $this->buildFailed('无法修改不存在或报告状态不是待制作的报告'); } $report = new Report(); $appraisal_time = date('Ymd', strtotime($report_data['appraisal_time'])); if ($appraisal_time == date('Ymd')) { $report_no_new = $report->generateReportNo($report_data['quot_id'], $report_data['business_type']); $upd_data['report_no'] = $report_no_new['report_no']; $upd_data['e_case_code'] = $report->generateElectronCode($report_data['quot_id'], $report_no_new['second']); } else { $report_no_new = $report->changeReportNo($report_data['quot_id'], $report_data['business_type'], $appraisal_time); $upd_data['report_no'] = $report_no_new['report_no']; $upd_data['e_case_code'] = $report->changeElectronCode($report_data['quot_id'], $report_no_new['second'], $appraisal_time); } $upd_data['report_url'] = NULL; $upd_data['report_qrcode'] = NULL; $upd_data['create_reportNo_time'] = date('Y-m-d H:i:s'); // 更新 $upd_result = Db::name('report')->where(['id'=>$report_data['id']])->update($upd_data); if ($upd_result) { return $this->buildSuccess('', '修改报告编号成功!'); } else { return $this->buildFailed('修改报告编号失败!'); } } /** * 添加备注 */ public function addRemark() { $flag = true; $report_no = $this->request->param('report_no'); // 必选项 $remark = $this->request->param('remark'); // 必选项 if (empty($report_no)) { return $this->buildFailed('报告编号不能为空'); } if (empty($remark)) { return $this->buildFailed('备注不能为空'); } // 报告主表数据 $report_data = Db::name('report')->where(['report_no' => $report_no])->find(); if (!$report_data) { return $this->buildFailed('无法修改不存在的报告'); } // 更新 $report_upd_result = Db::name('report')->where(['id' => $report_data['id']])->update(['report_remark_copy' => $remark]); if (!$report_upd_result) { $flag = false; } // 验证报告是否已完成 $charge_data = Db::name('charge')->where(['report_no' => $report_no])->find(); if ($charge_data) { $charge_upd_result = Db::name('charge')->where(['report_no' => $report_no])->update(['remark' => $remark]); if (!$charge_upd_result) { $flag = false; } } if ($flag) { return $this->buildSuccess('', '添加备注成功!'); } else { return $this->buildFailed('添加备注失败!'); } } //获取GZ比较法 public function methodGzFormalInfo() { $data = $this->request->post(); if (empty($data['reportid'])) return $this->buildFailed('报告id不能为空!'); if (empty($data['property_cert_info_id'])) return $this->buildFailed('请选择物业!'); $methodFormalGz = new MethodFormalGz(); $res = $methodFormalGz->field('id,property_cert_info_id,building_name,comparative_factor_conditions,location_factors,equity_situation_factors,physical_condition_factors,comparative_price_calculation')->where('property_cert_info_id', $data['property_cert_info_id'])->find(); if (empty($res)) { $info = Db::name('report_detail')->field('building_name,property_cert_info_id')->where(['report_id' => $data['reportid'], 'property_cert_info_id' => $data['property_cert_info_id']])->find(); if (empty($info)) return $this->buildFailed('报告不存在'); $res['property_cert_info_id'] = $data['property_cert_info_id']; $res['comparative_factor_conditions'] = $methodFormalGz->getComparativeFactorConditions(['transaction_situation', 'market_conditions', 'position', 'traffic', 'external_support', 'residential_atmosphere', 'environment', 'rights', 'surplus_service_life', 'other_rights', 'usage_status', 'scale', 'floor', 'floor_height', 'landscape', 'decoration', 'face', 'facilities', 'damage', 'property']); $res['location_factors'] = $methodFormalGz->getLocationFactors(['position', 'traffic', 'external_support', 'residential_atmosphere', 'environment', 'count']); $res['equity_situation_factors'] = $methodFormalGz->getEquitySituationFactors(['rights', 'surplus_service_life', 'other_rights', 'count']); $res['physical_condition_factors'] = $methodFormalGz->getPhysicalConditionFactors(['usage_status', 'scale', 'floor', 'floor_height', 'landscape', 'decoration', 'face', 'facilities', 'damage', 'property', 'count']); $res['comparative_price_calculation'] = $methodFormalGz->getComparativePriceCalculation(['building_name','price','transaction_situation','market_conditions','regional_factors','rights_condition','physical_condition','price_revision','comparing_prices','valuation_calculation'], $info['building_name']); $res['building_name'] = $info['building_name']; } //对价格进行修正 $priceInfo = Db::name('return_price')->where('property_cert_info_id', $data['property_cert_info_id']) ->order('id', 'desc')->field('eva_unit_price')->find(); // 先将comparative_price_calculation转换为数组 $comparativePriceCalc = is_object($res['comparative_price_calculation']) ? json_decode(json_encode($res['comparative_price_calculation']), true) : $res['comparative_price_calculation']; // 修改数组中的值 $comparativePriceCalc['price']['one'] = intval($priceInfo['eva_unit_price']); // 将修改后的数组重新赋值 $res['comparative_price_calculation'] = $comparativePriceCalc; return $this->buildSuccess($res); } public function updateInquiryReportUrl() { $upload_file = $this->request->post('upload_file', '', 'trim'); $quot_id = $this->request->post('quot_id', '', 'trim'); try { $report_info = Db::name('report')->where(['quot_id' => $quot_id])->find(); if (empty($report_info)) { return $this->buildFailed("报告信息不存在"); } if (isset($upload_file['url']) && !empty($upload_file['url'])) { $res = Db::name('report')->where(['quot_id' => $quot_id])->update(['upload_report_url' => $upload_file['url']]); if (!$res) { return $this->buildFailed("更新报告地址失败"); } } return $this->buildSuccess(); } catch (\Exception $e) { Log::error('错误文件:' . $e->getFile()); Log::error('错误行数:' . $e->getLine()); Log::error('错误编码:' . $e->getCode()); Log::error('错误信息:' . $e->getMessage()); return $this->buildFailed("更新报告地址失败"); } } }