getCalcTaxServer()->test(); } // 获取算数服务的实例 private function getCalcTaxServer() { if ($this->_calcTaxServer == null) { $this->_calcTaxServer = new CalcTaxService; } return $this->_calcTaxServer; } /** * 是否是某个角色 $this->userInfo['roleCode'] */ public function isRole($roleCode) { return in_array($roleCode, $this->userInfo['roleCode']); } /** * 获取住宅项目组列表 * @author zcx */ public function reqAppraisingPriceList() { $user_name = $this->request->post('user_name', '', 'trim'); //业务人员名称 $start_time = $this->request->post('start_time', '', 'trim'); //开始时间 $end_time = $this->request->post('end_time', '', 'trim'); //结束时间 $keyword = $this->request->post('keyword', '', 'trim'); //物业名称搜索 $usage = $this->request->post('usage', '', 'trim'); //房屋用途 $team_type = $this->request->post('team_type', '', 'trim'); //住宅项目类型 1、加急,2、拓展,3、特殊,4、工行,5、其它 $bank_id = $this->request->post('bank_id', '', 'trim'); //银行 $product_id = $this->request->post('product_id', '', 'trim'); //评估目的 //if (!$type) return $this->buildFailed("查询类型不能为空"); //糅合一起,注释掉 $where = []; $user_name && $where[] = ['i.user_name', 'like', "%" . $user_name . "%"]; $keyword && $where[] = ['ii.property_full_name', 'like', "%" . $keyword . "%"]; $start_time && $where[] = ['i.create_time', ">=", $start_time . " 00:00:00"]; $end_time && $where[] = ['i.create_time', "<=", $end_time . " 23:59:59"]; $usage && $where[] = ['ii.usage', '=', $usage]; if ($bank_id) { $where[] = ['i.bank_id', '=', $bank_id]; if ($bank_id == 777) { $order = 'i.sort desc,i.create_time asc'; } else { $order = 'i.create_time asc'; } } else { $where[] = ['i.bank_id', '<>', 777]; $order = 'i.create_time asc'; } static $CITIC_BANK_ID = 1129;// 中信银行 测试服930,正式服 1129 $roleCode = $this->userInfo['roleCode']; // 没有授权中信银行的,不显示 if (!in_array('citic_buniness', $roleCode)) { $where[] = ['i.bank_id', '<>', $CITIC_BANK_ID]; } $product_id && $where[] = ['i.product_id', '=', $product_id]; $where[] = ['i.is_simple', '=', 0]; $Inquiry = new Inquiry(); $Property_cert_info = new Property_cert_info(); $resultData = $Inquiry->alias("i") ->join('pg_property_cert_info ii', 'ii.quot_id=i.id') ->field('i.id,i.order_no,i.type,i.is_multiple,i.bank_name,i.status,i.bank_branch_name,i.bank_sub_name,i.create_time,i.user_name,i.buss_username,i.eva_purpose,ii.city,ii.property_full_name,ii.size,ii.reg_price,i.business_no,i.loan_type') ->where($where) ->where("status", 1) ->order($order) ->group('ii.quot_id') ->paginate($this->getPage()); if ($resultData) { foreach ($resultData as $k => &$v) { $detail = $Property_cert_info->where("quot_id", $v['id'])->field("id,property_full_name,size,reg_price")->select()->toArray(); $v['size'] = implode('/', array_column($detail, 'size')); $v['reg_price'] = implode('/', array_column($detail, 'reg_price')); $v['status_name'] = ($v['status'] == 1) ? "待回价" : "已回价"; $v['propertyDetails'] = $detail; $v['create_time'] = date('m-d H:i', strtotime($v['create_time'])); } } return $this->buildSuccess($resultData); } /** * 获取自动估价项目 */ public function AutomaticList() { $user_name = $this->request->post('user_name', '', 'trim'); //业务人员名称 $start_time = $this->request->post('start_time', '', 'trim'); //开始时间 $end_time = $this->request->post('end_time', '', 'trim'); //结束时间 $bank_id = $this->request->post('bank_id', '', 'trim'); //银行 $product_id = $this->request->post('product_id', '', 'trim'); //评估目的 $keyword = $this->request->post('keyword', '', 'trim'); //物业名称搜索 $where = []; $user_name && $where[] = ['i.user_name', 'like', "%" . $user_name . "%"]; $start_time && $where[] = ['i.create_time', ">=", $start_time . " 00:00:00"]; $end_time && $where[] = ['i.create_time', "<=", $end_time . " 23:59:59"]; $bank_id && $where[] = ['i.bank_id', '=', $bank_id]; $product_id && $where[] = ['i.product_id', '=', $product_id]; $keyword && $where[] = ['ii.property_full_name', 'like', "%" . $keyword . "%"]; $where[] = ['i.is_auto', '=', 1]; $Inquiry = new Inquiry(); $Property_cert_info = new Property_cert_info(); $resultData = $Inquiry->alias("i") ->join('pg_property_cert_info ii', 'ii.quot_id=i.id') ->field('i.id,i.order_no,ii.city,i.bank_name, i.bank_sub_name,i.eva_purpose,i.create_time,i.user_name, GROUP_CONCAT(ii.property_full_name) as property_full_name, GROUP_CONCAT(ii.size SEPARATOR "/") as size') ->where($where) ->where("status", 1) ->order('i.create_time asc') ->group('ii.quot_id') ->paginate($this->getPage()); if ($resultData) { foreach ($resultData as $k => &$v) { $v['bank_name'] = $v['bank_sub_name'] ? $v['bank_name'] . $v['bank_sub_name'] : $v['bank_name']; $detail = explode(',', $v['property_full_name']); $v['property_full_name'] = $detail[0]; $v['propertyDetails'] = $detail; $v['create_time'] = date('m-d H:i', strtotime($v['create_time'])); } } return $this->buildSuccess($resultData); } // 回价打开最大时长 public const OPEN_DETAIL_LIMIT_TIME_LONG = 600; //回价详情是否允许查看 public function isAllowOpen() { // return $this->buildSuccess(); $id = $this->request->post('id'); $type = $this->request->post('type'); if (!$id || !$type) return $this->buildFailed("缺少参数"); if ($type == 1) { //以订单为单位 $Inquiry = new Inquiry(); //600秒计时 $res = $Inquiry->field('eva_detail_start_time,eva_detail_user_id')->where('id', $id)->find(); if (!$res) { return $this->buildFailed('该数据不存在!'); } $eva_detail_start_time = $res['eva_detail_start_time']; if (time() - $eva_detail_start_time >= Pending::OPEN_DETAIL_LIMIT_TIME_LONG) { $eva_detail_start_time = time(); $Inquiry->where('id', $id)->update(['eva_detail_start_time' => $eva_detail_start_time, 'eva_detail_user_id' => $this->userInfo['user_id']]); } else { if ($res['eva_detail_user_id'] != $this->userInfo['user_id']) { return $this->buildFailed('该数据被打开中!'); } } /*if ($res['eva_detail_user_id'] != $this->userInfo['user_id'] && $res['eva_detail_start_time'] && (time() - $eva_detail_start_time) < Pending::OPEN_DETAIL_LIMIT_TIME_LONG) { return $this->buildFailed('该数据被打开中!'); } elseif ((time() - $eva_detail_start_time) > Pending::OPEN_DETAIL_LIMIT_TIME_LONG) { $eva_detail_start_time = time(); $Inquiry->where('id', $id)->update(['eva_detail_start_time' => $eva_detail_start_time, 'eva_detail_user_id' => $this->userInfo['user_id']]); }*/ } elseif ($type == 2) { //以物业为单位 $Property_cert_info = new Property_cert_info(); //600秒计时 $res = $Property_cert_info->field('eva_detail_start_time,eva_detail_user_id')->where('id', $id)->find(); if (!$res) { return $this->buildFailed('该数据不存在!'); } $eva_detail_start_time = $res['eva_detail_start_time']; if (time() - $eva_detail_start_time >= Pending::OPEN_DETAIL_LIMIT_TIME_LONG) { $eva_detail_start_time = time(); $Property_cert_info->where('id', $id)->update(['eva_detail_start_time' => $eva_detail_start_time, 'eva_detail_user_id' => $this->userInfo['user_id']]); } else { if ($res['eva_detail_user_id'] != $this->userInfo['user_id']) { return $this->buildFailed('该数据被打开中!'); } } /*if ($res['eva_detail_user_id'] != $this->userInfo['user_id'] && $res['eva_detail_start_time'] && (time() - $eva_detail_start_time) < Pending::OPEN_DETAIL_LIMIT_TIME_LONG) { return $this->buildFailed('该数据被打开中!'); } elseif ((time() - $eva_detail_start_time) > Pending::OPEN_DETAIL_LIMIT_TIME_LONG) { $eva_detail_start_time = time(); $Property_cert_info->where('id', $id)->update(['eva_detail_start_time' => $eva_detail_start_time, 'eva_detail_user_id' => $this->userInfo['user_id']]); }*/ } return $this->buildSuccess(['open_time' => $eva_detail_start_time]); } public function testeno() { $id = $this->request->post('id'); $id = 183911; return $this->buildSuccess([$this->GenerateEstimateNo($id)]); } /** * 生成预估号 * @param $inquiryId * @return mixed * @author cavan */ public function GenerateEstimateNo($inquiryId): string { $inquiryModel = new Inquiry(); $res = $inquiryModel->alias('i') ->where('i.id', $inquiryId) ->leftJoin('branchcom_config b', 'i.branchCom_id = b.id') ->find(); $shortName = $res['short_name']; $year = date("Y", time()); $m = date("m", time()); $count = $inquiryModel->whereTime('create_time', 'month') ->where(function ($query) { $query->whereNotNull('estimated_no') ->where('estimated_no', '<>', ''); }) ->count(); $estimateNumber = str_pad($count + 1, 5, '0', STR_PAD_LEFT); $G_COMPANY_SN = env('service.estimate_short_name'); // 公司简称 //var_dump('estimateNumber',$estimateNumber); return ($G_COMPANY_SN . $shortName . $year . $m . $estimateNumber); } // 延迟打开回价详情数据的时间 (重新再倒计时600秒) public function delayOpenDetail() { $id = $this->request->post('id'); $type = $this->request->post('type'); if (!$id || !$type) return $this->buildFailed("缺少参数"); if ($type == 1) { //以订单为单位 $Inquiry = new Inquiry(); $eva_detail_start_time = time(); $Inquiry->where('id', $id)->update(['eva_detail_start_time' => $eva_detail_start_time, 'eva_detail_user_id' => $this->userInfo['user_id']]); } elseif ($type == 2) { //以物业为单位 $Property_cert_info = new Property_cert_info(); $eva_detail_start_time = time(); $Property_cert_info->where('id', $id)->update(['eva_detail_start_time' => $eva_detail_start_time, 'eva_detail_user_id' => $this->userInfo['user_id']]); } return $this->buildSuccess(['open_time' => $eva_detail_start_time]); } //回价详情关闭 public function close() { $id = $this->request->post('id'); $type = $this->request->post('type'); if (!$id || !$type) return $this->buildFailed("缺少参数"); if ($type == 1) { $info = Db::name('inquiry')->where('id', $id)->whereNotNull("eva_detail_user_id")->whereNotNull("eva_detail_start_time")->find(); if ($info) { if (!Db::name('inquiry')->where('id', $id)->update(['eva_detail_user_id' => NULL, 'eva_detail_start_time' => NULL])) { return $this->buildFailed('更新计时时间失败'); } } } elseif ($type == 2) { $info = Db::name('property_cert_info')->where('id', $id)->whereNotNull("eva_detail_user_id")->whereNotNull("eva_detail_start_time")->find(); if ($info) { if (!Db::name('property_cert_info')->where('id', $id)->update(['eva_detail_user_id' => NULL, 'eva_detail_start_time' => NULL])) { return $this->buildFailed('更新计时时间失败'); } } } return $this->buildSuccess(); } /** * 待回价详情 * @author zcx * */ public function reqAppraisingInfo() { $id = $this->request->post('id', '', 'trim'); if (!$id) return $this->buildFailed("缺少参数id"); $Inquiry = new Inquiry(); $Property_cert_info = new Property_cert_info(); $ReturnPrice = new ReturnPrice(); //回价表 $Attachment = new Attachment(); //获取图片信息 $Taxation = new Taxation(); $property_full_name = ""; //第一个物业名称 $property_cert_info_id = ""; //第一个物业对应表id //主表信息 $list = $Inquiry->where("id", $id) ->field("id,user_name,buss_username,buss_user_id,bank_name,bank_id,bank_branch_name,bank_branch_id,bank_sub_name,bank_sub_id,bank_customer_mgr_id,bank_customer_mgr_name,eva_purpose,product_id,loan_type,status,type,business_no,estimated_qrcode_url,estimate_audit_status") ->find(); //物业信息 if (!$list) return $this->buildFailed("未查的数据"); $e2 = controller('TaxationSetUp'); $taxDetailInfo = $e2->taxDetailInfo(2); //税费项目 $Taxation_onr = $Taxation->where(["bank_id" => $list['bank_id'], "product_name" => $list['loan_type'], "type" => $list['type'], "state" => 1])->field("id,loan_percentage,tax_items")->find(); $propertyDetails = $Property_cert_info->where('quot_id', $id)->field("id,city,city_id,property_full_name,building_name,building_unit_no,building_no,unit_no,property_cert,purchase_date,completion_time,land_location,obligee,is_tran_tax_free,size,reg_price,usage,cert_usage,use_right_source,ownership_type,remark,attachments,tax_type,appraiser_id")->select(); if ($propertyDetails) { foreach ($propertyDetails as $k => $v) { $loan_percentage = ""; if ($k == 0) { $property_full_name = $v['property_full_name']; $property_cert_info_id = $v['id']; } $propertyDetails[$k]['usage_name'] = getDictionaryName('HOUSE_USAGE', $v['usage']); $propertyDetails[$k]['is_over2year_name'] = ($v['is_tran_tax_free'] == 1) ? "已满两年" : "未满两年"; $propertyDetails[$k]['ownership_type'] = intval($v['ownership_type']); $propertyDetails[$k]['tenure_type_name'] = ($v['ownership_type'] == 1) ? "个人" : (($v['ownership_type'] == 2) ? "企业" : ""); //图片列表 $propertyDetails[$k]['attachmentslist'] = $v['attachments'] ? $Attachment->getUrls($v['attachments']) : []; $propertyDetails[$k]['attachments'] = $v['attachments'] ? explode(",", $v['attachments']) : []; //税费项目列表 if ($taxDetailInfo) { $loan_percentage = ""; $tax_items = []; if ($Taxation_onr) { $loan_percentage = $Taxation_onr['loan_percentage']; $tax_items = explode(",", $Taxation_onr['tax_items']); } foreach ($taxDetailInfo as $ka => $va) { if (in_array($va['id'], $tax_items)) { $taxDetailInfo[$ka]['is_state'] = true; } else { $taxDetailInfo[$ka]['is_state'] = false; } } } $propertyDetails[$k]['taxDetailInfo'] = $taxDetailInfo; //税费项目 //固定信息 后期修改 $propertyDetails[$k]['eva_total_value'] = ""; //评估总值 $propertyDetails[$k]['eva_net_value'] = ""; //评估净值 $propertyDetails[$k]['eva_net_value2'] = ""; //评估净值2 $propertyDetails[$k]['gross_value'] = ""; //总值 $propertyDetails[$k]['eva_net_value'] = ""; //净值 $propertyDetails[$k]['eva_net_value2'] = ""; //净值2 // $propertyDetails[$k]['obligee'] = ""; //权利人 // $propertyDetails[$k]['land_location'] = ""; //土地位置 $propertyDetails[$k]['added_tax'] = ""; //增值税 $propertyDetails[$k]['urban_construction_tax'] = ""; //城建税 $propertyDetails[$k]['edu_surcharge'] = ""; //教育附加费 $propertyDetails[$k]['land_value_added_tax'] = ""; //土地增值税 $propertyDetails[$k]['stamp_duty'] = ""; //印花税 $propertyDetails[$k]['personal_income_tax'] = ""; //个人所得税 $propertyDetails[$k]['deed_tax'] = ""; //契税 $propertyDetails[$k]['corporate_income_tax'] = ""; //企业所得税 $propertyDetails[$k]['auction_fee'] = ""; //拍卖费 $propertyDetails[$k]['tran_service_fee'] = ""; //交易服务费 $propertyDetails[$k]['total_taxes1'] = ""; //税费1合计 $propertyDetails[$k]['total_taxes2'] = ""; //税费2合计 $propertyDetails[$k]['loan_ratio'] = $loan_percentage; //贷款成数 $propertyDetails[$k]['tips'] = "按七成算"; //成数显示 // 获取指导价 $g_where['loupan_name'] = $v['building_name']; $guide_price_data = DB::name('guide_price')->where($g_where)->field('guide_price')->find(); if ($guide_price_data) { $propertyDetails[$k]['guide_price'] = $guide_price_data['guide_price']; } else { $propertyDetails[$k]['guide_price'] = 0; } } $list['propertyDetails'] = $propertyDetails; } $list['appraiser_id'] = $list['propertyDetails'][0]['appraiser_id']; //回价历史 $ReturnPricelist = $ReturnPrice->where('property_name', $property_full_name)->where('property_cert_info_id', $property_cert_info_id) ->field('property_name,area,eva_unit_price,total_taxes1,gross_value,appraiser_id,appraiser_name,create_time') ->paginate(10, false, ["list_rows" => 10, "page" => 1]); if (!empty($ReturnPricelist)) { foreach ($ReturnPricelist as $k => $v) { $ReturnPricelist[$k]['create_time'] = date("Y-m-d H:i:s", $v['create_time']); } } $date['list'] = $list; $date['ReturnPricelist'] = $ReturnPricelist; //回价历史 return $this->buildSuccess($date); } public function reqQuotHistoryList() { $start_time = $this->request->post('start_time', '', 'trim'); //开始时间 $end_time = $this->request->post('end_time', '', 'trim'); //结束时间 $property_full_name = $this->request->post('keyword', '', 'trim'); //物业名称搜索 $paginate = $this->getPage(); $inquiry = new Inquiry(); $where = []; $property_full_name && $where[] = ['r.property_name', 'like', "%" . $property_full_name . "%"]; if ($start_time) { $where[] = ['i.create_time', ">=", $start_time]; } if ($end_time) { $where[] = ['i.create_time', "<=", $end_time]; } $where[] = ['i.status', ">", 0]; $order = json_encode(array('i.create_time' => 'desc', 'r.create_time' => 'desc')); $subsql = $inquiry->alias("i") ->leftJoin('pg_property_cert_info ii', 'ii.quot_id=i.id') ->leftJoin('pg_return_price r', 'ii.id=r.property_cert_info_id') ->where($where) ->field('i.id,i.bank_name,i.eva_purpose,i.is_auto,i.is_auto_eva,i.create_time,r.create_time as appraise_time') ->order(json_decode($order, true)) ->buildSql(); $resultData_count = Db::query('SELECT a.id FROM ' . $subsql . ' AS a GROUP BY a.id ORDER BY a.id DESC'); $resultData = Db::query('SELECT id,bank_name,eva_purpose,is_auto,is_auto_eva,create_time,appraise_time FROM ' . $subsql . ' AS a GROUP BY a.create_time ORDER BY a.create_time DESC LIMIT ' . ($paginate['page'] - 1) * $paginate['list_rows'] . ', ' . $paginate['list_rows']); if (!empty($resultData)) { foreach ($resultData as $k => $v) { $inquiry_details = Db::name('property_cert_info') ->where('quot_id=' . $v['id']) ->field('id,property_full_name,size as area,cert_usage') ->select(); foreach ($inquiry_details as $id_k => $id_v) { $id_v['eva_unit_price'] = 0; $id_v['eva_total_value'] = 0; $id_v['internal_remarks'] = ''; $id_v['external_remarks'] = ''; $id_v['appraiser_name'] = ''; $id_v['appraise_time'] = ''; $return_detail_data = Db::name('return_price') ->where('property_cert_info_id=' . $id_v['id']) ->field('eva_unit_price,eva_total_value,internal_remarks,external_remarks,appraiser_name,create_time as appraise_time') ->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']; $id_v['internal_remarks'] = $return_detail_data['internal_remarks']; $id_v['external_remarks'] = $return_detail_data['external_remarks']; $id_v['appraiser_name'] = $return_detail_data['appraiser_name']; $id_v['appraise_time'] = $return_detail_data['appraise_time']; } $inquiry_details[$id_k] = $id_v; } if (count($inquiry_details) > 1) { $resultData[$k]['property_name'] = implode(',', array_column($inquiry_details, 'property_full_name')); $resultData[$k]['area'] = implode('/', array_column($inquiry_details, 'area')); $resultData[$k]['eva_unit_price'] = implode('/', array_column($inquiry_details, 'eva_unit_price')); $resultData[$k]['eva_total_value'] = implode('/', array_column($inquiry_details, 'eva_total_value')); $resultData[$k]['internal_remarks'] = implode('/', array_column($inquiry_details, 'internal_remarks')); $resultData[$k]['external_remarks'] = implode('/', array_column($inquiry_details, 'external_remarks')); $resultData[$k]['appraiser_name'] = implode('/', array_column($inquiry_details, 'appraiser_name')); $resultData[$k]['appraise_time'] = implode('/', array_column($inquiry_details, 'appraise_time')); $resultData[$k]['cert_usage'] = implode('/', array_column($inquiry_details, 'cert_usage')); } elseif (count($inquiry_details) == 1) { $resultData[$k]['property_name'] = $inquiry_details[0]['property_full_name']; $resultData[$k]['area'] = $inquiry_details[0]['area']; $resultData[$k]['eva_unit_price'] = $inquiry_details[0]['eva_unit_price']; $resultData[$k]['eva_total_value'] = $inquiry_details[0]['eva_total_value']; $resultData[$k]['internal_remarks'] = $inquiry_details[0]['internal_remarks']; $resultData[$k]['external_remarks'] = $inquiry_details[0]['external_remarks']; $resultData[$k]['appraiser_name'] = $inquiry_details[0]['appraiser_name']; $resultData[$k]['appraise_time'] = $inquiry_details[0]['appraise_time']; $resultData[$k]['cert_usage'] = $inquiry_details[0]['cert_usage']; } // $resultData[$k]['appraise_time'] = $v['appraise_time'] ? date("Y-m-d H:i:s", $v['appraise_time']) : ''; $detail_appraiser_name = explode('/', $resultData[$k]['appraiser_name']); $resultData[$k]['appraiser_name'] = $detail_appraiser_name[0]; $detail_appraiser_time = explode('/', $resultData[$k]['appraise_time']); $resultData[$k]['appraise_time'] = $detail_appraiser_time[0] ? date("Y-m-d H:i:s", $detail_appraiser_time[0]) : ''; //自动估价,默认值 if ($v['is_auto'] == 1 && $v['is_auto_eva'] == 1) { $resultData[$k]['appraiser_name'] = '自动估价'; $resultData[$k]['appraise_time'] = $v['create_time']; } } } return $this->buildSuccess(['data' => $resultData, 'current_page' => $paginate['page'], 'last_page' => ceil(count($resultData_count) / $paginate['list_rows']), 'per_page' => $paginate['list_rows'], 'total' => count($resultData_count)]); } public function save() { $id = $this->request->post('id', '', 'trim'); $estimated_desc = $this->request->post('estimated_desc', '', 'trim'); $appraiser_id = $this->request->post('appraiser_id', '', 'trim'); $business_no = $this->request->post('business_no', '', 'trim'); $appraiser_name = $this->request->post('appraiser_name', '', 'trim'); $json_data = $this->request->post('json_data', '', 'trim'); $submit_bank_id = $this->request->post('bank_id', '', 'trim'); $submit_bank_name = $this->request->post('bank_name', '', 'trim'); $submit_bank_branch_id = $this->request->post('bank_branch_id', '', 'trim'); $submit_bank_branch_name = $this->request->post('bank_branch_name', '', 'trim'); $submit_bank_sub_id = $this->request->post('bank_sub_id', '', 'trim'); $submit_bank_sub_name = $this->request->post('bank_sub_name', '', 'trim'); $submit_bank_customer_mgr_id = $this->request->post('bank_customer_mgr_id', '', 'trim'); $submit_bank_customer_mgr_name = $this->request->post('bank_customer_mgr_name', '', 'trim'); $submit_bank_customer_mgr_phone = $this->request->post('bank_customer_mgr_phone', '', 'trim'); $submit_eva_purpose = $this->request->post('eva_purpose', '', 'trim'); $submit_product_id = $this->request->post('product_id', '', 'trim'); $submit_load_type = $this->request->post('loan_type', '', 'trim'); $return_price_attachments = $this->request->post('return_price_attachments', '', 'trim'); if (!$id) { return $this->buildFailed("缺少参数询价单主表id"); } if (!$json_data) { return $this->buildFailed("缺少参数回价详情信息"); } //判断json数据字段不能为空 $relust = $this->Verification($json_data, $id); if ($relust !== true) { Log::error("json数据有误:" . $relust); return $this->buildFailed($relust); } $Inquiry = new Inquiry(); $Property_cert_info = new Property_cert_info(); $ReturnPrice = new ReturnPrice(); // 回价表 $message_flag = 0; // 发送消息 1:回价发送消息 2:调价发送消息 Db::startTrans(); $inquiryInfo = $Inquiry->where("id", $id) ->field(' order_no, status, create_time, seal_status, eva_detail_time_long, is_auto, bank_id, bank_name, bank_branch_id, bank_branch_name, bank_sub_id, bank_sub_name, type, estimated_no, business_no, bank_customer_mgr_id, branchCom_id, eva_purpose, product_id, loan_type, estimate_qrcode_unique_key ') ->find(); if (empty($inquiryInfo)) return $this->buildFailed("询价单不存在"); if (!empty($inquiryInfo['estimate_qrcode_unique_key'])) return $this->buildFailed("该询价单已生成预估编号,无法进行回价操作"); $inquiry_data = []; foreach ($json_data as $k => $v) { $tax_items = implode(",", $v['tax_items']); // 选择税费项目 $insert_date = array(); $insert_date['property_cert_info_id'] = $v['id']; $insert_date['building_no'] = trim($v['building_no']); $insert_date['unit_no'] = trim($v['unit_no']); $insert_date['building_unit_no'] = (empty($v['building_no']) || trim($v['building_no']) == '0') ? $v['unit_no'] : $v['building_no'] . $v['unit_no']; $insert_date['property_name'] = trim($v['building_name']) . $insert_date['building_unit_no']; $insert_date['area'] = $v['size']; $insert_date['eva_unit_price'] = $v['eva_unit_price']; $insert_date['market_price'] = $v['market_price']; $insert_date['guide_price'] = $v['guide_price']; $insert_date['eva_total_value'] = $v['eva_total_value']; $insert_date['eva_net_value'] = $v['eva_net_value']; $insert_date['eva_net_value2'] = $v['eva_net_value2']; $insert_date['risk_grade'] = $v['risk_grade']; $insert_date['corporate_income_tax'] = $v['corporate_income_tax']; $insert_date['tran_service_fee'] = $v['tran_service_fee']; $insert_date['edu_surcharge'] = $v['edu_surcharge']; $insert_date['urban_construction_tax'] = $v['urban_construction_tax']; $insert_date['deed_tax'] = $v['deed_tax']; $insert_date['stamp_duty'] = $v['stamp_duty']; $insert_date['added_tax'] = $v['added_tax']; $insert_date['land_value_added_tax'] = $v['land_value_added_tax']; $insert_date['land_value_added_tax_copy'] = (array_key_exists("land_value_added_tax_copy", $v)) ? $v['land_value_added_tax_copy'] : 0; $insert_date['personal_income_tax'] = $v['personal_income_tax']; $insert_date['personal_income_tax_copy'] = $v['personal_income_tax_copy']; $insert_date['auction_fee'] = $v['auction_fee']; $insert_date['total_taxes1'] = $v['total_taxes1']; $insert_date['total_taxes2'] = $v['total_taxes2']; $insert_date['loan_ratio'] = $v['loan_ratio']; $insert_date['gross_value'] = $v['gross_value']; $insert_date['eva_net_value'] = $v['eva_net_value']; $insert_date['eva_net_value2'] = $v['eva_net_value2']; $insert_date['internal_remarks'] = $v['internal_remarks']; $insert_date['external_remarks'] = $v['external_remarks']; $insert_date['pricing_remarks'] = $v['pricing_remarks']; $insert_date['tax_items'] = $tax_items; $insert_date['tips'] = $v['tips']; $insert_date['appraiser_id'] = $appraiser_id; // 评估师id $insert_date['appraiser_name'] = $appraiser_name; // 评估师名称 $insert_date['create_time'] = time(); $insert_date['total_guide_tax'] = $v['guide_total_value'] ?? 0; // 参考总值(参考单价*面积) - 参考净值 = 参考税费 $rp_ins = $ReturnPrice->insert($insert_date); // 插入回价表 if (!$rp_ins) { Db::rollback(); return $this->buildFailed('回价信息保存失败!'); } $rid = $ReturnPrice->getLastInsID(); $p_date['city'] = $v['city']; $p_date['city_id'] = $v['city_id']; $p_date['building_no'] = $insert_date['building_no']; $p_date['unit_no'] = $insert_date['unit_no']; $p_date['building_unit_no'] = $insert_date['building_unit_no']; $p_date['building_name'] = trim($v['building_name']); $p_date['property_full_name'] = $p_date['building_name'] . $p_date['building_unit_no']; $p_date['property_cert'] = $v['property_cert']; $p_date['purchase_date'] = !empty($v['purchase_date']) ? $v['purchase_date'] : null; $p_date['completion_time'] = !empty($v['completion_time']) ? $v['completion_time'] : null; $p_date['land_location'] = !empty($v['land_location']) ? $v['land_location'] : ''; $p_date['obligee'] = !empty($v['obligee']) ? $v['obligee'] : ''; $p_date['is_tran_tax_free'] = $v['is_tran_tax_free']; $p_date['ownership_type'] = $v['ownership_type']; $p_date['usage'] = $v['usage'] ?? null; $p_date['cert_usage'] = $v['cert_usage'] ?? null; $p_date['use_right_source'] = $v['use_right_source'] ?? null; $p_date['size'] = $v['size']; $p_date['reg_price'] = $v['reg_price']; $p_date['remark'] = $v['remark']; $p_date['attachments'] = !empty($v['attachments']) ? implode(",", $v['attachments']) : ""; $p_date['update_time'] = date("Y-m-d H:i:s", time()); $p_date['tax_type'] = $v['tax_type'] ?? null; $p_date['statutory_payment'] = $v['statutory_payment']; $p_date['rid'] = $rid; // $p_date['appraiser_id'] = $appraiser_id; // $p_date['appraiser_name'] = $appraiser_name; $p_date['risk_grade'] = $v['risk_grade']; $p_date['r_create_time'] = $insert_date['create_time']; $p_date['eva_unit_price'] = $v['eva_unit_price']; $p_date['eva_total_value'] = $v['eva_total_value']; $p_date['eva_net_value'] = $v['eva_net_value']; $p_date['eva_net_value2'] = $v['eva_net_value2']; $p_date['total_taxes1'] = $v['total_taxes1']; $p_date['total_taxes2'] = $v['total_taxes2']; $p_date['internal_remarks'] = $v['internal_remarks']; $p_date['reference_price'] = $v['reference_price'] ?? 0; $p_date['transaction_total_price'] = $v['transaction_total_price'] ?? 0; $p_date['transaction_gross_area'] = $v['transaction_gross_area'] ?? 0; $p_date['transaction_date'] = !empty($v['transaction_date']) ? $v['transaction_date'] : NULL; // $adjust_status = $Property_cert_info->where("id", $v['id'])->value("adjust_status"); // 判断是否是调价数据 $p_info = $Property_cert_info->where("id", $v['id'])->find(); if (empty($p_info)) { Db::rollback(); return $this->buildFailed('物业信息不存在!'); } if ($p_info['adjust_status'] == 1) { $p_date['adjust_status'] = 2; // 修改调价状态 $message_flag = 2; } if (empty($p_info['appraiser_id']) && empty($p_info['appraiser_name'])) { $p_date['appraiser_id'] = $appraiser_id; $p_date['appraiser_name'] = $appraiser_name; } $ind_upd = $Property_cert_info->where("id", $v['id'])->update($p_date); // 修改物业表 if (!$ind_upd) { Db::rollback(); return $this->buildFailed('询价详情信息更新失败!'); } // 2021年6月自动估价系统重新开发重写 if ($inquiryInfo['is_auto'] == 1) { $inquiry_data['is_auto_eva'] = 0; $data = [ 'order_no' => $inquiryInfo['order_no'], 'user_name' => $p_info['appraiser_name'], 'price' => round($insert_date['eva_unit_price'] / 10) * 10, 'eva_total_value' => round(round($insert_date['eva_unit_price'] / 10) * 10 * $v['size']), 'net_one' => $insert_date['eva_net_value'], 'net_two' => $insert_date['eva_net_value2'], 'tax_one' => $insert_date['total_taxes1'], 'tax_two' => $insert_date['total_taxes2'], 'guide_price' => round($insert_date['guide_price'] / 10) * 10, 'external_remarks' => $insert_date['external_remarks'], 'gross_value' => $insert_date['gross_value'], 'estimates_url' => !empty($inquiryInfo['estimated_no']) ? env('uploadFile.evaluate_host_url') . '/admin/Pending/EstimateSheetTemplate?estimated_no=' . $inquiryInfo['estimated_no'] . '&branchCom_id=' . $inquiryInfo['branchCom_id'] : '', 'estimates_no' => !empty($inquiryInfo['estimated_no']) ? $inquiryInfo['estimated_no'] : '', ]; $this->updEvaluateInquiry($data); } } $status = $inquiryInfo['status']; if ($status == 1) { $inquiry_data['status'] = 2; $message_flag = 1; } // 更新业务编号 if (!empty($business_no) && empty($inquiryInfo['business_no'])) { $inquiry_data['business_no'] = $business_no; /*if ($inquiryInfo['bank_name'] == '中国银行' && $inquiryInfo['loan_type'] == '二手按揭') { $boc_cf_inquiry_apply = Db::name('boc_cf_inquiry_apply')->where('dealNo', $business_no)->find(); if (!empty($boc_cf_inquiry_apply)) { if ($boc_cf_inquiry_apply['is_related'] == 2) { if ($boc_cf_inquiry_apply['related_order_no'] != $inquiryInfo['order_no']) { Db::rollback(); return $this->buildFailed('中行业务编号已被关联,请勿重复关联'); } } else { if ($boc_cf_inquiry_apply['related_order_no'] == $inquiryInfo['order_no']) { $inquiry_data['bnkno'] = $boc_cf_inquiry_apply['bnkno']; $inquiry_data['tlrname'] = $boc_cf_inquiry_apply['tlrname']; $res = Db::name('boc_cf_inquiry_apply')->where('dealNo', $business_no)->update([ 'related_order_no' => $inquiryInfo['order_no'], 'is_related' => 2, ]); if (!$res) { Db::rollback(); return $this->buildFailed('中行业务编号关联失败复关联'); } } } } }*/ // 中行消金和普惠 if ($inquiryInfo['bank_name'] == '中国银行' && in_array($inquiryInfo['loan_type'], ['二手按揭', '普惠'])) { $boc_common_main = Db::name('boc_common_main') ->where('bankPreEstimateNo', $business_no) ->whereOr('bankEstimateNo', $business_no) ->find(); if (empty($boc_common_main)) { Db::rollback(); return $this->buildFailed('中行业务编号不存在'); } if ($boc_common_main['is_related'] == 2) { Db::rollback(); return $this->buildFailed('中行业务编号已被关联,请勿重复关联'); } if (!empty($boc_common_main['bankPreEstimateNo'])) { $boc_where['bankPreEstimateNo'] = $business_no; } else { $boc_where['bankEstimateNo'] = $business_no; } $res = Db::name('boc_common_main')->where($boc_where)->update([ 'quot_id' => $id, 'order_no' => $inquiryInfo['order_no'], 'is_related' => 2, ]); if (!$res) { Db::rollback(); return $this->buildFailed('更新中行业务编号状态失败!'); } } } $seal_status = $inquiryInfo['seal_status']; if ($seal_status == 1 || ($seal_status == 2 && $inquiryInfo['is_auto'] == 1)) { $inquiry_data['estimated_desc'] = $estimated_desc; } // 第一次回价才更新 : 时间长度(分钟数) = 回价时间 - 询价时间 if (!$inquiryInfo['eva_detail_time_long']) { $js_response_time = strtotime(date('Y-m-d H:i', time()) . ":00"); $js_create_time = strtotime(date('Y-m-d H:i', strtotime($inquiryInfo['create_time'])) . ":00"); $inquiry_data['eva_detail_time_long'] = ($js_response_time - $js_create_time) / 60; if ($inquiry_data['eva_detail_time_long'] > 9999999) $inquiry_data['eva_detail_time_long'] = 9999999; } // 更新询价信息 $inquiry_data['update_time'] = date('Y-m-d H:i:s'); $inquiry_data['return_price_attachments'] = !empty($return_price_attachments) ? implode(",", $return_price_attachments) : null; /*if (empty($inquiryInfo['estimated_no'])) { $estimated_no = ''; $generate_estimated_info = Tools::generateNo($id, Tools::GENERATE_TYPE_ESTIMATE); if ($generate_estimated_info['code'] == 0) { $estimated_no = $generate_estimated_info['data']; } $inquiry_data['estimated_no'] = $estimated_no; // 生成预估号 $estimated_qrcode_content = env("uploadFile.qrcode_url") . "/index.php/admin/Pending/getAnticounterfeitPage?quot_id=" . $id; $qrcode_oss_url = Tools::createQRCode($estimated_qrcode_content); if (!empty($qrcode_oss_url)) { $inquiry_data['estimated_qrcode_url'] = $qrcode_oss_url; } $inquiry_data['seal_status'] = 2; $inquiry_data['seal_time'] = date('Y-m-d H:i:s'); }*/ // 银行信息 if (!empty($submit_bank_id) && $inquiryInfo['bank_id'] != $submit_bank_id) { $inquiry_data['bank_id'] = $submit_bank_id; $inquiry_data['bank_name'] = $submit_bank_name; } // 分行信息 if (!empty($submit_bank_branch_id) && $inquiryInfo['bank_branch_id'] != $submit_bank_branch_id) { $inquiry_data['bank_branch_id'] = $submit_bank_branch_id; $inquiry_data['bank_branch_name'] = $submit_bank_branch_name; } // 支行信息 if (!empty($submit_bank_sub_id) && $inquiryInfo['bank_sub_id'] != $submit_bank_sub_id) { $inquiry_data['bank_sub_id'] = $submit_bank_sub_id; $inquiry_data['bank_sub_name'] = $submit_bank_sub_name; } // 客户经理信息 if (!empty($submit_bank_customer_mgr_id) && $inquiryInfo['bank_customer_mgr_id'] != $submit_bank_customer_mgr_id) { $inquiry_data['bank_customer_mgr_id'] = $submit_bank_customer_mgr_id; $inquiry_data['bank_customer_mgr_name'] = $submit_bank_customer_mgr_name; $inquiry_data['bank_customer_mgr_phone'] = $submit_bank_customer_mgr_phone; } // 评估目的 if (!empty($submit_eva_purpose) && $inquiryInfo['eva_purpose'] != $submit_eva_purpose) { $inquiry_data['eva_purpose'] = $submit_eva_purpose; } // 贷款品种ID if (!empty($submit_product_id) && $inquiryInfo['product_id'] != $submit_product_id) { $inquiry_data['product_id'] = $submit_product_id; } // 贷款品种 if (!empty($submit_load_type) && $inquiryInfo['loan_type'] != $submit_load_type) { $inquiry_data['loan_type'] = $submit_load_type; } $inquiry_data['return_price_status'] = 1; $in_upd = $Inquiry->where("id", $id)->update($inquiry_data); if (!$in_upd) { Db::rollback(); return $this->buildFailed('询价信息更新失败!'); } // if ($inquiryInfo['bank_name'] == '中国银行' && in_array($inquiryInfo['loan_type'], ['按揭', '普惠', '消费'])) { // $boc_cf_service = new BocCfService(); // $boc_cf_service->inquiryResultFeedback($inquiryInfo['business_no']); // } // 写入消息 if ($message_flag == 1) { // 回价提交发现消息 PublicMessage($id, 2, 2); } else { // 调价提交发送消息 PublicMessage($id, 2, 4); } Db::commit(); return $this->buildSuccess(); } // 更新询价详情表新增字段的值 2024-03-19 16:33:30 public function setFieldValue() { $start_time = $this->request->get('start_t', '', 'trim'); $end_time = $this->request->get('end_t', '', 'trim'); if (empty($start_time) || empty($end_time)) { return $this->buildFailed('参数错误,请传入时间范围!'); } $ind_data = Db::name('property_cert_info') ->field('id') ->where('create_time', 'between', [$start_time, $end_time]) ->select(); if (count($ind_data) > 1) { foreach ($ind_data as $key => $value) { $rp_data = Db::name('return_price') ->field(' id, appraiser_id, appraiser_name, risk_grade, create_time, eva_unit_price, eva_total_value, eva_net_value, eva_net_value2, total_taxes1, total_taxes2, internal_remarks ') ->where('property_cert_info_id=' . $value['id']) ->order('id', 'desc') ->find(); if ($rp_data) { $ind_upd_data['rid'] = $rp_data['id']; $ind_upd_data['appraiser_id'] = $rp_data['appraiser_id']; $ind_upd_data['appraiser_name'] = $rp_data['appraiser_name']; $ind_upd_data['risk_grade'] = $rp_data['risk_grade']; $ind_upd_data['r_create_time'] = $rp_data['create_time']; $ind_upd_data['eva_unit_price'] = $rp_data['eva_unit_price']; $ind_upd_data['eva_total_value'] = $rp_data['eva_total_value']; $ind_upd_data['eva_net_value'] = $rp_data['eva_net_value']; $ind_upd_data['eva_net_value2'] = $rp_data['eva_net_value2']; $ind_upd_data['total_taxes1'] = $rp_data['total_taxes1']; $ind_upd_data['total_taxes2'] = $rp_data['total_taxes2']; $ind_upd_data['internal_remarks'] = $rp_data['internal_remarks']; Db::name('property_cert_info')->where('id', $value['id'])->update($ind_upd_data); } } return $this->buildSuccess(); } else { return $this->buildFailed('没有需要更新的记录!'); } } /** * 验证回价信息不要字段不能为空 * @author zcx * * @parameter $json 回价数组信息 * */ public function Verification($json = array(), $id = "") { if (empty($json)) { return $this->buildFailed("缺少回价信息"); } $Inquiry = new Inquiry(); $Taxation = new Taxation(); $TaxationAuxiliary = new TaxationAuxiliary(); foreach ($json as $k => $v) { if (!array_key_exists("tax_items", $v)) { return "请选择需要计算的税费"; } $tax_items_arr = $v['tax_items']; if (!array_key_exists("id", $v)) { return "缺少询价单详情表id"; } else if (!array_key_exists("building_name", $v)) { return "缺少物业名称"; } else if ($v['reg_price'] < 0) { return "登记价不能小于0"; } else if (!array_key_exists("size", $v)) { return "缺少建筑面积"; } else if (!array_key_exists("building_no", $v)) { return "缺少栋号"; } else if (!array_key_exists("unit_no", $v)) { return "缺少房号"; } else if (!array_key_exists("eva_unit_price", $v)) { return "缺少评估单价"; } else if (!array_key_exists("eva_total_value", $v)) { return "缺少评估总值"; } else if (!array_key_exists("eva_net_value", $v)) { return "缺少评估净值"; } else if (!array_key_exists("eva_net_value2", $v)) { return "缺少评估净值2"; } else if (!array_key_exists("total_taxes1", $v)) { return "缺少税费合计1"; } else if (!array_key_exists("total_taxes2", $v)) { return "缺少税费合计2"; } else if (!array_key_exists("gross_value", $v)) { return "缺少总值"; } else if (!array_key_exists("eva_net_value", $v)) { return "缺少净值"; } else if (!array_key_exists("eva_net_value2", $v)) { return "缺少净值2"; } else if (!array_key_exists("tax_items", $v)) { return "缺少选中税费项目"; } if (!empty($v['tax_items'])) { foreach ($v['tax_items'] as $kt => $vt) { $t_key = $TaxationAuxiliary->where("id", $vt)->field("name,key")->find(); if (!empty($t_key)) { if (!array_key_exists($t_key["key"], $v)) { return "缺少" . $t_key['name'] . "值"; } } } } } return true; } public function reqAppraisedCompletedPriceList($export_flag = false) { if ($export_flag) { $paginate = ['list_rows' => 10000000, 'page' => 1]; } else { $paginate = $this->getPage(); } $apply_estimate_make_status = $this->request->post('apply_estimate_make_status', '', 'trim'); $usage = $this->request->post('usage', '', 'trim'); $user_name = $this->request->post('user_name', '', 'trim'); $response_username = $this->request->post('response_username', '', 'trim'); $is_multiple = $this->request->post('is_multiple', '', 'trim'); $start_time = $this->request->post('start_time', '', 'trim'); $end_time = $this->request->post('end_time', '', 'trim'); $keyword = $this->request->post('keyword', '', 'trim'); $city_id = $this->request->post('city_id', '', 'trim'); //城市 $bank_id = $this->request->post('bank_id', '', 'trim'); //银行id $product_id = $this->request->post('product_id', '', 'trim'); //评估目的id $internal_remarks = $this->request->post('internal_remarks', '', 'trim'); //内部备注 $start_size = $this->request->post('start_size', '', 'trim'); //面积起 $end_size = $this->request->post('end_size', '', 'trim'); //面积止 $issue_report = $this->request->post('issue_report', '', 'trim'); //是否出具报告 $is_signature = $this->request->post('is_signature', '', 'trim'); //是否已签章 $start_time_length = $this->request->post('start_time_length', '', 'trim'); //时间长度起 $end_time_length = $this->request->post('end_time_length', '', 'trim'); //时间长度止 // if (!$type) { // return $this->buildFailed("查询类型不能为空"); // } $where = array(); $usage && $where[] = ['ii.usage', '=', intval($usage)]; if ($issue_report == 1) { //是否出具报告 $where[] = ['i.status', '=', 8]; } elseif ($issue_report === 0) { // $where[] = ['i.status', 'gt', 1]; // $where[] = ['i.status', 'lt', 8]; $where[] = ['i.status', 'in', [2, 3, 4, 5, 6, 7], '_logic' => 'or']; } else { // $where[] = ['i.status', 'gt', 1]; $where[] = ['i.status', 'in', [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], '_logic' => 'or']; } $where[] = ['i.is_simple', '=', 0]; $start_time && $where[] = ['i.create_time', '>=', $start_time . " 00:00:00"]; $end_time && $where[] = ['i.create_time', '<=', $end_time . " 23:59:59"]; $is_multiple && $where[] = ['i.is_multiple', '=', $is_multiple]; $user_name && $where[] = ['i.buss_username', 'like', "%" . $user_name . "%"]; $keyword && $where[] = ['ii.property_full_name|i.estimated_no|i.business_no|i.order_no', 'like', "%" . $keyword . "%"]; $city_id && $where[] = ['ii.city_id', '=', $city_id]; //城市 $bank_id && $where[] = ['i.bank_id', '=', $bank_id]; //银行 $apply_estimate_make_status && $where[] = ['i.apply_estimate_make_status', '=', $apply_estimate_make_status]; //是否已经申请预估制作 $product_id && $where[] = ['i.product_id', '=', $product_id]; //评估目的 $start_size && $end_size && $where[] = getQuery('ii.size', $start_size, $end_size); //面积开始 $start_time_length && $end_time_length && $where[] = getQuery('i.eva_detail_time_long', $start_time_length, $end_time_length); $is_signature && $where[] = ['i.seal_status', '=', $is_signature]; $response_username && $where[] = ['ii.appraiser_name', 'like', "%" . $response_username . "%"]; $internal_remarks && $where[] = ['ii.internal_remarks', 'like', "%{$internal_remarks}%"]; //内部备注 $Inquiry = new Inquiry(); $resultData = $Inquiry->alias("i") ->leftJoin('pg_property_cert_info ii', 'ii.quot_id=i.id') ->leftJoin('pg_boc_cf_inquiry_apply iii', 'iii.dealNo = i.business_no') ->field('i.id, i.order_no, i.business_no, i.type, i.is_multiple, i.bank_name, i.bank_branch_name, i.bank_sub_name, i.bank_customer_mgr_name, i.estimated_no, i.create_time, i.buss_username, i.user_name, i.seal_status, i.adjust_reason, i.status, i.eva_purpose, i.loan_type, i.eva_detail_time_long, i.is_auto, i.is_auto_eva, i.estimate_audit_status, i.estimate_audit1_date, i.branchCom_id, ii.id as did, ii.quot_id, ii.city, ii.parcel_no, ii.parcel_area, ii.land_unit_price, ii.floor_unit_price, ii.reg_price, ii.rid, i.biz_status, i.is_send_estimate_to_boc, i.apply_estimate_make_status') ->where($where) ->group('i.id') ->order('i.id', 'desc') ->paginate($paginate) ->each(function ($item, $key) { $inquiry_details = Db::name('property_cert_info') ->where('quot_id=' . $item['id']) ->field(' id, property_full_name, size, parcel_no, land_unit_price, parcel_area, floor_unit_price, eva_unit_price, eva_total_value, internal_remarks, risk_grade, appraiser_name, r_create_time AS appraiser_time ') ->select(); // dump($inquiry_details); // die; // $inquiry_details = $inquiry_details->toArray(); foreach ($inquiry_details as $key => $value) { $return_price_count = Db::name('return_price')->where('property_cert_info_id=' . $inquiry_details[$key]['id'])->field('id')->count(); // $return_price_count = count($return_price_info); // 是否有调价 $item['is_adjusted_price'] = $return_price_count > 2 ? true : false; } if (count($inquiry_details) > 1) { $item['property_full_name'] = implode(',', array_column($inquiry_details, 'property_full_name')); $item['size'] = implode('/', array_column($inquiry_details, 'size')); $item['eva_unit_price'] = implode('/', array_column($inquiry_details, 'eva_unit_price')); $item['eva_total_value'] = implode('/', array_column($inquiry_details, 'eva_total_value')); $item['internal_remarks'] = implode('/', array_column($inquiry_details, 'internal_remarks')); $item['appraiser_name'] = implode('/', array_column($inquiry_details, 'appraiser_name')); $item['risk_grade'] = implode('/', array_column($inquiry_details, 'risk_grade')); $item['appraiser_time'] = implode('/', array_column($inquiry_details, 'appraiser_time')); } elseif (count($inquiry_details) == 1) { $item['property_full_name'] = $inquiry_details[0]['property_full_name']; $item['size'] = $inquiry_details[0]['size']; $item['eva_unit_price'] = $inquiry_details[0]['eva_unit_price']; $item['eva_total_value'] = $inquiry_details[0]['eva_total_value']; $item['internal_remarks'] = $inquiry_details[0]['internal_remarks']; $item['appraiser_name'] = $inquiry_details[0]['appraiser_name']; $item['risk_grade'] = $inquiry_details[0]['risk_grade']; $item['appraiser_time'] = $inquiry_details[0]['appraiser_time']; } $detail_estate_name = explode(',', $item['property_full_name']); $detail_appraiser_name = explode('/', $item['appraiser_name']); $detail_appraise_level = explode('/', $item['risk_grade']); $detail_appraiser_time = explode('/', $item['appraiser_time']); $item['property_full_name'] = $detail_estate_name[0]; $item['appraiser_name'] = $detail_appraiser_name[0]; $item['risk_grade'] = (int)max($detail_appraise_level); $item['appraiser_time'] = $detail_appraiser_time[0] ? date("Y-m-d H:i:s", $detail_appraiser_time[0]) : ''; $propertyDetails = []; foreach ($inquiry_details as $key => $value) { $propertyDetails[$key]['property_full_name'] = $value['property_full_name']; $propertyDetails[$key]['internal_remarks'] = $value['internal_remarks']; } $item['propertyDetails'] = $propertyDetails; // 是否出具报告 $item['issue_report'] = $item['status'] == 8 ? '已出具报告' : '否'; // 订单状态文字描述 $item['status_str'] = getDictionaryName('ORDER_STATUS', $item['status']); // 自动估价,默认值 if ($item['is_auto'] == 1 && $item['is_auto_eva'] == 1) { $item['appraiser_name'] = '自动估价'; $item['appraiser_time'] = $item['create_time']; } // 预估已审核 // 如果预估未审核,则不显示预估单号 // $item['estimated_no'] = ($item['estimate_audit_status'] == self::ALREADY_ESTIMATE_AUDIT) ? $item['estimated_no'] : ""; $item['bank'] = $item['bank_name']; $item['bank_name'] = $item['bank_sub_name'] ? $item['bank_name'] . $item['bank_sub_name'] : $item['bank_name']; $item['export_create_time'] = date('Y-m-d', strtotime($item['create_time'])); return $item; }) ->toArray(); if ($export_flag) { return ['data' => $resultData['data'], 'type' => $type]; } else { return $this->buildSuccess($resultData); } } // 回价管理-项目汇总-导出 public function reqAppraisedCompletedPriceListExport() { $export_flag = true; $data = $this->reqAppraisedCompletedPriceList($export_flag); if ($data['type'] == 1) { $file_name = self::INQUERY_NUMBER_RESIDENCE_PREFIX . '_' . date('Ymd'); } elseif ($data['type'] == 2) { $file_name = self::INQUERY_NUMBER_BUSINIESS_PREFIX . '_' . date('Ymd'); } else { $file_name = date('Ymd'); } $indexKey = ['order_no', 'estimated_no', 'city', 'property_full_name', 'internal_remarks', 'size', 'eva_unit_price', 'eva_total_value', 'bank', 'bank_sub_name', 'bank_customer_mgr_name', 'eva_purpose', 'user_name', 'appraiser_name', 'export_create_time', 'appraiser_time', 'eva_detail_time_long', 'issue_report']; $indexValue = ['询价单号', '预估单号', '城市', '物业名称', '内部备注', '面积(m²)', '评估单价', '评估总价', '银行', '支行', '客户经理', '评估目的', '业务员', '询价员', '询价时间', '回价时间', '时间长度(分钟)', '是否出具报告']; (new ChargeManage())->exportExcel($data['data'], $file_name, $indexKey, $indexValue); } /** * 已回价详情 * @author pser * */ public function reqAppraisedPriceInfo() { $id = $this->request->post('id', '', 'trim'); if (!$id) { return $this->buildFailed("缺少参数id"); } $Inquiry = new Inquiry(); $Property_cert_info = new Property_cert_info(); $ReturnPrice = new ReturnPrice(); //回价表 $Attachment = new Attachment(); //获取图片信息 $Taxation = new Taxation(); $property_full_name = ""; //第一个物业名称 $property_cert_info_id = ""; //第一个物业对应表id //主表信息 $list = $Inquiry->where("id", $id) ->field("id,user_name,buss_username,bank_name,bank_id,bank_branch_name,bank_branch_id,bank_sub_name,bank_customer_mgr_id,bank_customer_mgr_name, eva_purpose,product_id,loan_type,estimated_desc,status,type,adjust_status,seal_status,business_no,estimated_qrcode_url,estimate_audit_status, return_price_attachments") ->find(); //物业信息 if (!empty($list)) { //回价附件 $list['return_price_attachments_list'] = !empty($list['return_price_attachments']) ? $Attachment->getUrls($list['return_price_attachments']) : array(); $list['return_price_attachments'] = !empty($list['return_price_attachments']) ? explode(",", $list['return_price_attachments']) : array(); $list['status_name'] = $list['status'] > 1 ? "已回价" : "待回价"; $list['modify_status_name'] = $list['adjust_status'] == 0 ? "无需回价" : ($list['adjust_status'] == 1 ? "待评估回复" : "已结束"); //获取预估说明 if (empty($list['estimated_desc'])) { $list['estimated_desc'] = Db::name("estimate")->where(["bank_id" => $list["bank_id"], "product_id" => $list["product_id"], "type" => $list["type"]])->value("estimated_desc"); } $propertyDetails = $Property_cert_info->where("quot_id", $id) ->field("id,city,city_id,property_full_name,building_name,building_unit_no,building_no,unit_no,property_cert,purchase_date, completion_time,land_location,obligee,is_tran_tax_free,size,reg_price,usage,cert_usage,use_right_source,ownership_type,remark, attachments,adjust_reason,evaluated_unit_price,parcel_no,parcel_area,land_unit_price,floor_unit_price,tax_type,statutory_payment, appraiser_id,land_value_added_tax_rate,personal_income_tax_rate,reference_price,transaction_total_price,transaction_gross_area, transaction_date") ->select(); if (!empty($propertyDetails)) { foreach ($propertyDetails as $k => $v) { if ($k == 0) { $property_full_name = $v['property_full_name']; $property_cert_info_id = $v['id']; } $propertyDetails[$k]['usage_name'] = Db::name("dictionary")->where(["type" => "HOUSE_USAGE", "code" => $v['usage']])->value("valname"); $propertyDetails[$k]['use_right_source_name'] = Db::name("dictionary")->where(["type" => "USE_RIGHT_SOURCE", "code" => $v['use_right_source']])->value("valname"); $propertyDetails[$k]['is_over2year_name'] = ($v['is_tran_tax_free'] == 1) ? "已满两年" : "未满两年"; $propertyDetails[$k]['ownership_type'] = intval($v['ownership_type']); $propertyDetails[$k]['tenure_type_name'] = ($v['ownership_type'] == 1) ? "个人" : (($v['ownership_type'] == 2) ? "企业" : ""); $propertyDetails[$k]['parcel_no'] = $v['parcel_no']; $propertyDetails[$k]['parcel_area'] = $v['parcel_area']; $propertyDetails[$k]['land_unit_price'] = $v['land_unit_price']; $propertyDetails[$k]['floor_unit_price'] = $v['floor_unit_price']; $propertyDetails[$k]['tax_type'] = $v['tax_type'] == NULL ? $list['type'] : $v['tax_type'];//物业算税类型为空的处理 $propertyDetails[$k]['statutory_payment'] = $v['statutory_payment']; $propertyDetails[$k]['reference_price'] = $v['reference_price']; $propertyDetails[$k]['transaction_total_price'] = $v['transaction_total_price']; $propertyDetails[$k]['transaction_gross_area'] = $v['transaction_gross_area']; $propertyDetails[$k]['transaction_date'] = $v['transaction_date']; //图片列表 $propertyDetails[$k]['attachmentslist'] = !empty($v['attachments']) ? $Attachment->getUrls($v['attachments']) : array(); $propertyDetails[$k]['attachments'] = !empty($v['attachments']) ? explode(",", $v['attachments']) : array(); //评估价及税费等 $price = $ReturnPrice->where("property_cert_info_id", $v['id']) ->field('*') ->order('create_time desc') ->find(); $e2 = controller('TaxationSetUp'); $taxDetailInfo = $e2->taxDetailInfo(2); //税费项目 if (!empty($taxDetailInfo)) { if (!empty($price['tax_items'])) { $tax_items = explode(",", $price['tax_items']); } else { $tax_items = array(); } foreach ($taxDetailInfo as $ka => $va) { if (in_array($va['id'], $tax_items)) { $taxDetailInfo[$ka]['is_state'] = true; } else { $taxDetailInfo[$ka]['is_state'] = false; } } } $propertyDetails[$k]['taxDetailInfo'] = $taxDetailInfo; //税费项目 $propertyDetails[$k]['eva_unit_price'] = $price['eva_unit_price'] ? $price['eva_unit_price'] : 0; //评估单价 $propertyDetails[$k]['market_price'] = $price['market_price'] ? $price['market_price'] : 0; //市场参考单价 $guide_price = $price['guide_price'] ? $price['guide_price'] : 0; //二手房成交参考单价(2021年2月8日政府公布指导价) $propertyDetails[$k]['guide_price'] = $guide_price; $propertyDetails[$k]['loan_ratio'] = $price['loan_ratio']; //贷款成数 $propertyDetails[$k]['eva_total_value'] = $price['eva_total_value'] ? $price['eva_total_value'] : 0; //评估总值 $propertyDetails[$k]['eva_net_value'] = $price['eva_net_value'] ? $price['eva_net_value'] : 0; //评估净值 $propertyDetails[$k]['eva_net_value2'] = $price['eva_net_value2'] ? $price['eva_net_value2'] : 0; //评估净值2 $propertyDetails[$k]['risk_grade'] = $price['risk_grade']; //定价弧度 $propertyDetails[$k]['appraise_level_str'] = getDictionaryName('APPRAISE_LEVEL', $price['risk_grade']); //定价弧度文本 $propertyDetails[$k]['gross_value'] = $price['gross_value'] ? $price['gross_value'] : 0; //总值 $propertyDetails[$k]['eva_net_value'] = $price['eva_net_value'] ? $price['eva_net_value'] : 0; //净值 $propertyDetails[$k]['eva_net_value2'] = $price['eva_net_value2'] ? $price['eva_net_value2'] : 0; //净值2 $propertyDetails[$k]['added_tax'] = $price['added_tax']; //增值税 $propertyDetails[$k]['urban_construction_tax'] = $price['urban_construction_tax']; //城建税 $propertyDetails[$k]['edu_surcharge'] = $price['edu_surcharge']; //教育附加费 $propertyDetails[$k]['land_value_added_tax'] = $price['land_value_added_tax']; //土地增值税 $propertyDetails[$k]['land_value_added_tax_copy'] = $price['land_value_added_tax_copy']; //土地增值税-商业 光大银行实际值 $propertyDetails[$k]['stamp_duty'] = $price['stamp_duty']; //印花税 $propertyDetails[$k]['personal_income_tax'] = $price['personal_income_tax']; //个人所得税 $propertyDetails[$k]['personal_income_tax_copy'] = $price['personal_income_tax_copy']; //个人所得税-住宅民生和光大银行真实税值,商业光大 $propertyDetails[$k]['deed_tax'] = $price['deed_tax']; //契税 $propertyDetails[$k]['corporate_income_tax'] = $price['corporate_income_tax']; //企业所得税 $propertyDetails[$k]['auction_fee'] = $price['auction_fee']; //拍卖费 $propertyDetails[$k]['tran_service_fee'] = $price['tran_service_fee']; //交易服务费 $propertyDetails[$k]['total_taxes1'] = $price['total_taxes1']; //税费1合计 $propertyDetails[$k]['total_taxes2'] = $price['total_taxes2']; //税费2合计 $propertyDetails[$k]['ref_net_worth'] = $guide_price * $propertyDetails[$k]['size'] - $price['total_guide_tax'];//参考净值=参考单价*面积 - 参考税费合计 $propertyDetails[$k]['tips'] = $price['tips']; //成数显示 $propertyDetails[$k]['internal_remarks'] = $price['internal_remarks']; //内部备注 $propertyDetails[$k]['external_remarks'] = $price['external_remarks']; //外部备注 $propertyDetails[$k]['pricing_remarks'] = $price['pricing_remarks']; //核价情况 $propertyDetails[$k]['land_value_added_tax_rate'] = $v['land_value_added_tax_rate']; //核价情况 $propertyDetails[$k]['personal_income_tax_rate'] = $v['personal_income_tax_rate']; //核价情况 // $propertyDetails[$k]['price']=$price; } $list['propertyDetails'] = $propertyDetails; } } else { return $this->buildFailed("未查的数据"); } $list['appraiser_id'] = $list['propertyDetails'][0]['appraiser_id']; //回价记录 $ReturnPricelist = $ReturnPrice->where('property_name', $property_full_name) ->where('property_cert_info_id', $property_cert_info_id) ->field('property_name,area,eva_unit_price,total_taxes1,gross_value,appraiser_id,appraiser_name,FROM_UNIXTIME(create_time) as create_time') ->paginate(10, false, ["list_rows" => 10, "page" => 1]); /*if($ReturnPricelist){ foreach ($ReturnPricelist as $k => &$v){ $v['create_time'] = date("Y-m-d H:i:s",$v['create_time']); } }*/ $date['list'] = $list; $date['ReturnPricelist'] = $ReturnPricelist; //回价记录 return $this->buildSuccess($date); } // 获取回价记录 public function getReturnPriceRecord() { $id = $this->request->post('id', '', 'trim'); $ReturnPricelist = DB::name('return_price')->where('property_cert_info_id', $id) ->field('property_name,area,eva_unit_price,total_taxes1,gross_value,appraiser_id,appraiser_name,FROM_UNIXTIME(create_time) as create_time,eva_net_value,eva_net_value2') ->paginate(10, false, ["list_rows" => 10, "page" => 1]); /*if($ReturnPricelist){ foreach ($ReturnPricelist as $k => &$v){ $v['create_time'] = date("Y-m-d H:i:s",$v['create_time']); } }*/ $date['ReturnPricelist'] = $ReturnPricelist; //回价记录 return $this->buildSuccess($date); } /** * 待调价-回价详情 * @author zcx * */ public function ModifyPriceDetails() { $id = $this->request->post('id', '', 'trim'); if (!$id) { return $this->buildFailed("缺少参数id"); } $Inquiry = new Inquiry(); $Property_cert_info = new Property_cert_info(); $ReturnPrice = new ReturnPrice(); //回价表 $Attachment = new Attachment(); //获取图片信息 $Taxation = new Taxation(); $property_full_name = ""; //第一个物业名称 $property_cert_info_id = ""; //第一个物业对应表id $pid = $Property_cert_info->where("id", $id)->value("quot_id"); //主表信息 $list = $Inquiry->where("id", $pid) ->field("id,user_name,bank_name,bank_id,bank_branch_id,bank_branch_name,bank_sub_name,bank_sub_id,bank_customer_mgr_id,bank_customer_mgr_name,eva_purpose,estimated_desc,product_id,status,type,estimate_audit_status") ->find(); //物业信息 if (!empty($list)) { if (empty($list['estimated_desc'])) { $list['estimated_desc'] = Db::name("estimate")->where(["bank_id" => $list["bank_id"], "product_id" => $list["product_id"], "type" => $list["type"]])->value("estimated_desc"); } $e2 = controller('TaxationSetUp'); $taxDetailInfo = $e2->taxDetailInfo(2); //税费项目 $Taxation_onr = $Taxation->where(["bank_id" => $list['bank_id'], "product_name" => $list['eva_purpose'], "type" => $list['type'], "state" => 1])->field("loan_percentage,tax_items")->find(); $propertyDetails = $Property_cert_info->where("id", $id) ->field("id,city,city_id,property_full_name,building_name,building_unit_no,building_no,unit_no,property_cert,purchase_date,completion_time,land_location,obligee,is_tran_tax_free,size,reg_price,usage,ownership_type,remark,attachments,adjust_reason,evaluated_unit_price") ->select(); if (!empty($propertyDetails)) { foreach ($propertyDetails as $k => $v) { if ($k == 0) { $property_full_name = $v['property_full_name']; $property_cert_info_id = $v['id']; } $propertyDetails[$k]['usage_name'] = Db::name("dictionary")->where(["type" => "HOUSE_USAGE", "code" => $v['usage']])->value("valname"); $propertyDetails[$k]['is_over2year_name'] = ($v['is_tran_tax_free'] == 1) ? "已满两年" : "未满两年"; $propertyDetails[$k]['ownership_type'] = intval($v['ownership_type']); $propertyDetails[$k]['tenure_type_name'] = ($v['ownership_type'] == 1) ? "个人" : (($v['ownership_type'] == 2) ? "企业" : ""); //图片列表 $propertyDetails[$k]['attachmentslist'] = !empty($v['attachments']) ? $Attachment->getUrls($v['attachments']) : array(); $propertyDetails[$k]['attachments'] = !empty($v['attachments']) ? explode(",", $v['attachments']) : array(); //税费项目列表 if (!empty($taxDetailInfo)) { if (!empty($Taxation_onr)) { $tax_items = explode(",", $Taxation_onr['tax_items']); } else { $tax_items = array(); } foreach ($taxDetailInfo as $ka => $va) { if (in_array($va['id'], $tax_items)) { $taxDetailInfo[$ka]['is_state'] = true; } else { $taxDetailInfo[$ka]['is_state'] = false; } } } $propertyDetails[$k]['taxDetailInfo'] = $taxDetailInfo; //税费项目 //评估价及税费等 $price = $ReturnPrice->where("property_cert_info_id", $id) ->field('*') ->order('create_time desc') ->find(); $propertyDetails[$k]['eva_unit_price'] = $price['eva_unit_price'] ? $price['eva_unit_price'] : 0; //评估单价 $propertyDetails[$k]['loan_ratio'] = $price['loan_ratio']; //贷款成数 $propertyDetails[$k]['eva_total_value'] = $price['eva_total_value'] ? $price['eva_total_value'] : 0; //评估总值 $propertyDetails[$k]['eva_net_value'] = $price['eva_net_value'] ? $price['eva_net_value'] : 0; //评估净值 $propertyDetails[$k]['eva_net_value2'] = $price['eva_net_value2'] ? $price['eva_net_value2'] : 0; //评估净值2 $propertyDetails[$k]['gross_value'] = $price['gross_value'] ? $price['gross_value'] : 0; //总值 $propertyDetails[$k]['eva_net_value'] = $price['eva_net_value'] ? $price['eva_net_value'] : 0; //净值 $propertyDetails[$k]['eva_net_value2'] = $price['eva_net_value2'] ? $price['eva_net_value2'] : 0; //净值2 $propertyDetails[$k]['added_tax'] = $price['added_tax']; //增值税 $propertyDetails[$k]['urban_construction_tax'] = $price['urban_construction_tax']; //城建税 $propertyDetails[$k]['edu_surcharge'] = $price['edu_surcharge']; //教育附加费 $propertyDetails[$k]['land_value_added_tax'] = $price['land_value_added_tax']; //土地增值税 $propertyDetails[$k]['land_value_added_tax_copy'] = $price['land_value_added_tax_copy']; //土地增值税 商业光大银行实际值 $propertyDetails[$k]['stamp_duty'] = $price['stamp_duty']; //印花税 $propertyDetails[$k]['personal_income_tax'] = $price['personal_income_tax']; //个人所得税 $propertyDetails[$k]['personal_income_tax_copy'] = $price['personal_income_tax_copy']; //个人所得税-住宅民生和光大银行真实税值 商业光大 $propertyDetails[$k]['deed_tax'] = $price['deed_tax']; //契税 $propertyDetails[$k]['corporate_income_tax'] = $price['corporate_income_tax']; //企业所得税 $propertyDetails[$k]['auction_fee'] = $price['auction_fee']; //拍卖费 $propertyDetails[$k]['tran_service_fee'] = $price['tran_service_fee']; //交易服务费 $propertyDetails[$k]['total_taxes1'] = $price['total_taxes1']; //税费1合计 $propertyDetails[$k]['total_taxes2'] = $price['total_taxes2']; //税费2合计 $propertyDetails[$k]['loan_ratio'] = $price['loan_ratio']; //贷款成数 $propertyDetails[$k]['tips'] = $price['tips']; //成数显示 $propertyDetails[$k]['internal_remarks'] = $price['internal_remarks']; //内部备注 $propertyDetails[$k]['external_remarks'] = $price['external_remarks']; //外部备注 $propertyDetails[$k]['pricing_remarks'] = $price['pricing_remarks']; //核价情况 } } $list['propertyDetails'] = $propertyDetails; } else { return $this->buildFailed("未查的数据"); } //回价历史 $ReturnPricelist = $ReturnPrice->where('property_name', $property_full_name)->where('property_cert_info_id', $property_cert_info_id) ->field('property_name,area,eva_unit_price,total_taxes1,gross_value,appraiser_id,appraiser_name,create_time') ->paginate(10, false, ["list_rows" => 10, "page" => 1]); if (!empty($ReturnPricelist)) { foreach ($ReturnPricelist as $k => $v) { $ReturnPricelist [$k]['create_time'] = date("Y-m-d H:i:s", $v['create_time']); } } //询价历史 $InquiryHistory = $ReturnPrice->where("property_name", "like", "%" . $property_full_name . "%") ->field('property_cert_info_id,property_name,area,building_unit_no,eva_unit_price,appraiser_id,appraiser_name,internal_remarks,create_time') ->group("property_cert_info_id") ->paginate(10, false, ["list_rows" => 10, "page" => 1]); if (!empty($InquiryHistory)) { foreach ($InquiryHistory as $kr => $vr) { $InquiryHistory[$kr]['create_time'] = $Property_cert_info->where("id", $vr['property_cert_info_id'])->value("create_time"); } } $date['list'] = $list; $date['ReturnPricelist'] = $ReturnPricelist; //回价历史 $date['InquiryHistory'] = $InquiryHistory; //询价历史 return $this->buildSuccess($date); } /** * 税费计算 * @param mixed _InquiryList 询价列表, 算税金额,xxx * @return $isOK(Boolean),tax1 */ protected function calTax($_InquiryList, $price, $tax_items, $gfa, $ResidentialType, $ManuTotalamo, $OriginalAmount, $buyYears, $purpose, $tenureType, $data_purchase_date, $bankName, $houseUsage) { //评估总值=建筑面积*评估单价 $ManuTotalamo = $gfa * $price; $list = $_InquiryList; $debugStr = ""; //所选银行 $banksubTax = $list['bank_name']; $Taxation = new Taxation(); $tlist = $Taxation->where(["bank_id" => $list['bank_id'], "branch_id" => $list['bank_branch_id'], "product_name" => $list['eva_purpose'], "type" => $list['type'], "state" => 1])->field("id,eva_net_value,eva_net_value2,loan_percentage,net_worth_one_percentage,net_worth_tow_percentage")->find(); //[X]增值税 [N]城建税 [L]教育附加费 [Q]土地增值税 [P]印花税 [R]个人所得税 [V]契税 [Z]企业所得税 [T]拍卖费 [O]交易服务费 $TaxationItem = new TaxationItem(); $bin = $TaxationItem->where("taxation_id", $tlist['id'])->field("*")->select(); $X = $N = $L = $Q = $P = $R = $V = $Z = $T = $O = $S = $U = $R_COPY = $Q_COPY = 0; //住宅光大和民生银行个人所得税显示为0 商业个人所得税和土地增值税显示为0 $tt = array(); $you = array(); $TaxationAuxiliary = new TaxationAuxiliary(); foreach ($bin as $key => $va) { $vid = $TaxationAuxiliary->where("number", $va['code_name'])->value("id"); if (!in_array($vid, $tt)) { $tt[] = $vid; } if (!in_array($vid, $tax_items)) { continue; } $va['condition'] = !empty($va['condition']) ? str_replace(['and', 'or', '(', ')'], ['&&', '||', '(', ')'], $va['condition']) : ""; $va['formula'] = !empty($va['formula']) ? str_replace(['(', ')'], ['(', ')'], $va['formula']) : ""; if ($va['code_name'] == 'X') { $resAT = []; $resAT = Pending::calculate_valueAddtion_tax( $tenureType, $list['type'], $data_purchase_date, $ManuTotalamo, $OriginalAmount, "caltax", ); $X = $resAT['res']; $debugStr = $debugStr . '增值税:' . $X; $X = ($X > 0) ? $X : 0; /* if (empty($va['condition'])) { $str = $this->pipei($va['formula'], $ResidentialType, $gfa, $price, $ManuTotalamo, $OriginalAmount, $buyYears, $purpose,$tenureType, $X, $N, $L, $Q, $P, $R, $V, $Z, $T, $O,$S,$U); $X = round(eval("return {$str};")); $X = ($X > 0)?$X:0; if (!in_array($vid, $you)) { $you[] = $vid; } else { continue; } } else { $str = $this->pipei($va['condition'], $ResidentialType, $gfa, $price, $ManuTotalamo, $OriginalAmount, $buyYears, $purpose,$tenureType, $X, $N, $L, $Q, $P, $R, $V, $Z, $T, $O,$S,$U); if (eval("return {$str};")) { if (!in_array($vid, $you)) { $you[] = $vid; } else { continue; } $str = $this->pipei($va['formula'], $ResidentialType, $gfa, $price, $ManuTotalamo, $OriginalAmount, $buyYears, $purpose,$tenureType, $X, $N, $L, $Q, $P, $R, $V, $Z, $T, $O,$S,$U); $X = round(eval("return {$str};")); $X = ($X > 0)?$X:0; } else { continue; } }*/ } if ($va['code_name'] == 'N') { if (empty($va['condition'])) { $str = $this->pipei($va['formula'], $ResidentialType, $gfa, $price, $ManuTotalamo, $OriginalAmount, $buyYears, $purpose, $tenureType, $X, $N, $L, $Q, $P, $R, $V, $Z, $T, $O, $S, $U); $N = round(eval("return {$str};")); $N = ($N > 0) ? $N : 0; if (!in_array($vid, $you)) { $you[] = $vid; } else { continue; } } else { $str = $this->pipei($va['condition'], $ResidentialType, $gfa, $price, $ManuTotalamo, $OriginalAmount, $buyYears, $purpose, $tenureType, $X, $N, $L, $Q, $P, $R, $V, $Z, $T, $O, $S, $U); if (eval("return {$str};")) { if (!in_array($vid, $you)) { $you[] = $vid; } else { continue; } $str = $this->pipei($va['formula'], $ResidentialType, $gfa, $price, $ManuTotalamo, $OriginalAmount, $buyYears, $purpose, $tenureType, $X, $N, $L, $Q, $P, $R, $V, $Z, $T, $O, $S, $U); $N = round(eval("return {$str};")); $N = ($N > 0) ? $N : 0; } else { continue; } } } if ($va['code_name'] == 'L') { if (empty($va['condition'])) { $str = $this->pipei($va['formula'], $ResidentialType, $gfa, $price, $ManuTotalamo, $OriginalAmount, $buyYears, $purpose, $tenureType, $X, $N, $L, $Q, $P, $R, $V, $Z, $T, $O, $S, $U); $L = round(eval("return {$str};")); $L = ($L > 0) ? $L : 0; if (!in_array($vid, $you)) { $you[] = $vid; } else { continue; } } else { $str = $this->pipei($va['condition'], $ResidentialType, $gfa, $price, $ManuTotalamo, $OriginalAmount, $buyYears, $purpose, $tenureType, $X, $N, $L, $Q, $P, $R, $V, $Z, $T, $O, $S, $U); if (eval("return {$str};")) { if (!in_array($vid, $you)) { $you[] = $vid; } else { continue; } $str = $this->pipei($va['formula'], $ResidentialType, $gfa, $price, $ManuTotalamo, $OriginalAmount, $buyYears, $purpose, $tenureType, $X, $N, $L, $Q, $P, $R, $V, $Z, $T, $O, $S, $U); $L = round(eval("return {$str};")); $L = ($L > 0) ? $L : 0; } else { continue; } } } if ($va['code_name'] == 'S') { if (empty($va['condition'])) { $str = $this->pipei($va['formula'], $ResidentialType, $gfa, $price, $ManuTotalamo, $OriginalAmount, $buyYears, $purpose, $tenureType, $X, $N, $L, $Q, $P, $R, $V, $Z, $T, $O, $S, $U); $S = round(eval("return {$str};")); $S = ($S > 0) ? $S : 0; $debugStr = $debugStr . "扣除项目金额:" . $S; if (!in_array($vid, $you)) { $you[] = $vid; } else { continue; } } else { $str = $this->pipei($va['condition'], $ResidentialType, $gfa, $price, $ManuTotalamo, $OriginalAmount, $buyYears, $purpose, $tenureType, $X, $N, $L, $Q, $P, $R, $V, $Z, $T, $O, $S, $U); if (eval("return {$str};")) { if (!in_array($vid, $you)) { $you[] = $vid; } else { continue; } $str = $this->pipei($va['formula'], $ResidentialType, $gfa, $price, $ManuTotalamo, $OriginalAmount, $buyYears, $purpose, $tenureType, $X, $N, $L, $Q, $P, $R, $V, $Z, $T, $O, $S, $U); $S = round(eval("return {$str};")); $S = ($S > 0) ? $S : 0; $debugStr = $debugStr . "扣除项目金额[c]:" . $S; } else { continue; } } } if ($va['code_name'] == 'Q') { // 过于复杂,不能配置实现 $Q = $this->getCalcTaxServer()->calcLandVat( 0, // 重置成本 $OriginalAmount,//原建购价 0,//应补地价 0,//改良投资 $N,//城建税 $L,//教育费附加 $P,//印花税 $buyYears,//购买年限(年) $bankName,//银行名称 $houseUsage,//房屋用途 0, //交易服务费 $ManuTotalamo, $ResidentialType, false,//增值税是否免征 $tenureType, $data_purchase_date )['res']; $Q = ($Q > 0) ? $Q : 0; /* $resAT = $resBT = []; $resAT = Pending::calculateLandValueAddedTax($ManuTotalamo,$S);//核实 $resBT = Pending::calculateAssessedLandValueAddedTax($ManuTotalamo, $ResidentialType );//核定 $Q = min( $resAT['res'],$resBT['res']); //$debugStr = $debugStr.'核定土增:'.$resBT['res'].'核实土增:'.$resAT['res']; $Q = ($Q > 0)?$Q:0; if (empty($va['condition'])) { $str = $this->pipei($va['formula'], $ResidentialType, $gfa, $price, $ManuTotalamo, $OriginalAmount, $buyYears, $purpose,$tenureType, $X, $N, $L, $Q, $P, $R, $V, $Z, $T, $O,$S,$U); $Q = round(eval("return {$str};")); $Q = ($Q > 0)?$Q:0; if (!in_array($vid, $you)) { $you[] = $vid; } else { continue; } } else { $str = $this->pipei($va['condition'], $ResidentialType, $gfa, $price, $ManuTotalamo, $OriginalAmount, $buyYears, $purpose,$tenureType, $X, $N, $L, $Q, $P, $R, $V, $Z, $T, $O,$S,$U); if (eval("return {$str};")) { if (!in_array($vid, $you)) { $you[] = $vid; } else { continue; } $str = $this->pipei($va['formula'], $ResidentialType, $gfa, $price, $ManuTotalamo, $OriginalAmount, $buyYears, $purpose,$tenureType, $X, $N, $L, $Q, $P, $R, $V, $Z, $T, $O,$S,$U); $Q = round(eval("return {$str};")); $Q = ($Q > 0)?$Q:0; } else { continue; } }*/ } if ($va['code_name'] == 'P') { $resAT = $this->getCalcTaxServer()->calc_stamp_tax( $ManuTotalamo,//评估总值 $tenureType,//权利人 $ResidentialType, //服务类型 $data_purchase_date // 购买日期 ); $P = $resAT['res']; $debugStr = $debugStr . $resAT['debug']; $P = ($P > 0) ? $P : 0; /* if (empty($va['condition'])) { if (!in_array($vid, $you)) { $you[] = $vid; } else { continue; } $str = $this->pipei($va['formula'], $ResidentialType, $gfa, $price, $ManuTotalamo, $OriginalAmount, $buyYears, $purpose,$tenureType, $X, $N, $L, $Q, $P, $R, $V, $Z, $T, $O,$S,$U); $P = round(eval("return {$str};")); $P = ($P > 0)?$P:0; } else { $str = $this->pipei($va['condition'], $ResidentialType, $gfa, $price, $ManuTotalamo, $OriginalAmount, $buyYears, $purpose,$tenureType, $X, $N, $L, $Q, $P, $R, $V, $Z, $T, $O,$S,$U); if (in_array($vid, $you)) { continue; }else{} if (eval("return {$str};")) { $you[] = $vid; $str = $this->pipei($va['formula'], $ResidentialType, $gfa, $price, $ManuTotalamo, $OriginalAmount, $buyYears, $purpose,$tenureType, $X, $N, $L, $Q, $P, $R, $V, $Z, $T, $O,$S,$U); $P = round(eval("return {$str};")); $P = ($P > 0)?$P:0; } else { continue; } }*/ } if ($va['code_name'] == 'R') { if (empty($va['condition'])) { $str = $this->pipei($va['formula'], $ResidentialType, $gfa, $price, $ManuTotalamo, $OriginalAmount, $buyYears, $purpose, $tenureType, $X, $N, $L, $Q, $P, $R, $V, $Z, $T, $O, $S, $U); $R = round(eval("return {$str};")); $R = ($R > 0) ? $R : 0; if (!in_array($vid, $you)) { $you[] = $vid; } else { continue; } } else { $str = $this->pipei($va['condition'], $ResidentialType, $gfa, $price, $ManuTotalamo, $OriginalAmount, $buyYears, $purpose, $tenureType, $X, $N, $L, $Q, $P, $R, $V, $Z, $T, $O, $S, $U); if (eval("return {$str};")) { if (!in_array($vid, $you)) { $you[] = $vid; } else { continue; } $str = $this->pipei($va['formula'], $ResidentialType, $gfa, $price, $ManuTotalamo, $OriginalAmount, $buyYears, $purpose, $tenureType, $X, $N, $L, $Q, $P, $R, $V, $Z, $T, $O, $S, $U); $R = round(eval("return {$str};")); $R = ($R > 0) ? $R : 0; } else { continue; } } } if ($va['code_name'] == 'U') { if (empty($va['condition'])) { $str = $this->pipei($va['formula'], $UesidentialType, $gfa, $price, $ManuTotalamo, $OriginalAmount, $buyYears, $purpose, $tenureType, $X, $N, $L, $Q, $P, $R, $V, $Z, $T, $O, $S, $U); $U = round(eval("return {$str};")); $U = ($U > 0) ? $U : 0; $debugStr = $debugStr . "规定税率:" . $U; if (!in_array($vid, $you)) { $you[] = $vid; } else { continue; } } else { $str = $this->pipei($va['condition'], $ResidentialType, $gfa, $price, $ManuTotalamo, $OriginalAmount, $buyYears, $purpose, $tenureType, $X, $N, $L, $Q, $P, $R, $V, $Z, $T, $O, $S, $U); if (eval("return {$str};")) { if (!in_array($vid, $you)) { $you[] = $vid; } else { continue; } $str = $this->pipei($va['formula'], $ResidentialType, $gfa, $price, $ManuTotalamo, $OriginalAmount, $buyYears, $purpose, $tenureType, $X, $N, $L, $Q, $P, $R, $V, $Z, $T, $O, $S, $U); $U = round(eval("return {$str};")); $U = ($U > 0) ? $U : 0; $debugStr = $debugStr . "规定税率[c]:" . $U; } else { continue; } } } if ($va['code_name'] == 'V') { $resAT = []; $is_mornthan2Years = ($buyYears >= 2); $resAT = Pending::calculate_deed_tax($tenureType, $ResidentialType, $is_mornthan2Years, $gfa, $ManuTotalamo, $OriginalAmount, $data_purchase_date, $X, "calctax"); //var_dump('buyyears:',$buyYears); $V = $resAT['res']; $debugStr = $debugStr . '契税:' . $V . ' 税率:' . $resAT['taxrate']; $V = ($V > 0) ? $V : 0; /* if (empty($va['condition'])) { $str = $this->pipei($va['formula'], $ResidentialType, $gfa, $price, $ManuTotalamo, $OriginalAmount, $buyYears, $purpose,$tenureType, $X, $N, $L, $Q, $P, $R, $V, $Z, $T, $O,$S,$U); $V = round(eval("return {$str};")); $V = ($V > 0)?$V:0; if (!in_array($vid, $you)) { $you[] = $vid; } else { continue; } } else { $str = $this->pipei($va['condition'], $ResidentialType, $gfa, $price, $ManuTotalamo, $OriginalAmount, $buyYears, $purpose,$tenureType, $X, $N, $L, $Q, $P, $R, $V, $Z, $T, $O,$S,$U); if (eval("return {$str};")) { if (!in_array($vid, $you)) { $you[] = $vid; } else { continue; } $str = $this->pipei($va['formula'], $ResidentialType, $gfa, $price, $ManuTotalamo, $OriginalAmount, $buyYears, $purpose,$tenureType, $X, $N, $L, $Q, $P, $R, $V, $Z, $T, $O,$S,$U); $V = round(eval("return {$str};")); $V = ($V > 0)?$V:0; } else { continue; } }*/ } if ($va['code_name'] == 'Z') { if (empty($va['condition'])) { $str = $this->pipei($va['formula'], $ResidentialType, $gfa, $price, $ManuTotalamo, $OriginalAmount, $buyYears, $purpose, $tenureType, $X, $N, $L, $Q, $P, $R, $V, $Z, $T, $O, $S, $U); $Z = round(eval("return {$str};")); $Z = ($Z > 0) ? $Z : 0; if (!in_array($vid, $you)) { $you[] = $vid; } else { continue; } } else { $str = $this->pipei($va['condition'], $ResidentialType, $gfa, $price, $ManuTotalamo, $OriginalAmount, $buyYears, $purpose, $tenureType, $X, $N, $L, $Q, $P, $R, $V, $Z, $T, $O, $S, $U); if (eval("return {$str};")) { if (!in_array($vid, $you)) { $you[] = $vid; } else { continue; } $str = $this->pipei($va['formula'], $ResidentialType, $gfa, $price, $ManuTotalamo, $OriginalAmount, $buyYears, $purpose, $tenureType, $X, $N, $L, $Q, $P, $R, $V, $Z, $T, $O, $S, $U); $Z = round(eval("return {$str};")); $Z = ($Z > 0) ? $Z : 0; } else { continue; } } } if ($va['code_name'] == 'T') { if (empty($va['condition'])) { $str = $this->pipei($va['formula'], $ResidentialType, $gfa, $price, $ManuTotalamo, $OriginalAmount, $buyYears, $purpose, $tenureType, $X, $N, $L, $Q, $P, $R, $V, $Z, $T, $O, $S, $U); $T = round(eval("return {$str};")); $T = ($T > 0) ? $T : 0; if (!in_array($vid, $you)) { $you[] = $vid; } else { continue; } } else { $str = $this->pipei($va['condition'], $ResidentialType, $gfa, $price, $ManuTotalamo, $OriginalAmount, $buyYears, $purpose, $tenureType, $X, $N, $L, $Q, $P, $R, $V, $Z, $T, $O, $S, $U); if (eval("return {$str};")) { if (!in_array($vid, $you)) { $you[] = $vid; } else { continue; } $str = $this->pipei($va['formula'], $ResidentialType, $gfa, $price, $ManuTotalamo, $OriginalAmount, $buyYears, $purpose, $tenureType, $X, $N, $L, $Q, $P, $R, $V, $Z, $T, $O, $S, $U); $T = round(eval("return {$str};")); $T = ($T > 0) ? $T : 0; } else { continue; } } } if ($va['code_name'] == 'O') { if (empty($va['condition'])) { $str = $this->pipei($va['formula'], $ResidentialType, $gfa, $price, $ManuTotalamo, $OriginalAmount, $buyYears, $purpose, $tenureType, $X, $N, $L, $Q, $P, $R, $V, $Z, $T, $O, $S, $U); $O = round(eval("return {$str};")); $O = ($O > 0) ? $O : 0; if (!in_array($vid, $you)) { $you[] = $vid; } else { continue; } } else { $str = $this->pipei($va['condition'], $ResidentialType, $gfa, $price, $ManuTotalamo, $OriginalAmount, $buyYears, $purpose, $tenureType, $X, $N, $L, $Q, $P, $R, $V, $Z, $T, $O, $S, $U); if (eval("return {$str};")) { if (!in_array($vid, $you)) { $you[] = $vid; } else { continue; } $str = $this->pipei($va['formula'], $ResidentialType, $gfa, $price, $ManuTotalamo, $OriginalAmount, $buyYears, $purpose, $tenureType, $X, $N, $L, $Q, $P, $R, $V, $Z, $T, $O, $S, $U); $O = round(eval("return {$str};")); $O = ($O > 0) ? $O : 0; } else { continue; } } } } $TaxType = $list['type']; if ($TaxType == 1 && ((strpos($banksubTax, '中信') !== false && $list['eva_purpose'] != "了解市场价值") || (strpos($banksubTax, '民生') !== false && $list['eva_purpose'] != "了解市场价值") || (strpos($banksubTax, '光大') !== false) && $list['eva_purpose'] != "了解市场价值")) { //业务类型:住宅,民生和光大(除了评估目的为了解市场价值之外)个人所得税显示为0 $R_COPY = $R; $R = 0; } else if ($TaxType == 2 && (strpos($banksubTax, '光大') !== false || strpos($banksubTax, '中信') !== false) && $list['eva_purpose'] != "了解市场价值") { $R_COPY = $R; $Q_COPY = $Q; $R = 0; $Q = 0; } // 各种税费 $data['added_tax'] = round($X); $data['urban_construction_tax'] = round($N); $data['edu_surcharge'] = round($L); $data['land_value_added_tax'] = round($Q); $data['land_value_added_tax_copy'] = round($Q_COPY); $data['stamp_duty'] = round($P); $data['personal_income_tax'] = round($R); $data['personal_income_tax_copy'] = round($R_COPY); $data['deed_tax'] = round($V); $data['corporate_income_tax'] = round($Z); $data['auction_fee'] = round($T); $data['tran_service_fee'] = round($O); //统计(税费计算公式) $net_worth_one_arr = !empty($tlist['eva_net_value']) ? explode(",", $tlist['eva_net_value']) : ""; $eva_net_value = $eva_net_value2 = 0; // 参考净值的计算 $ref_net_worth = 0; if ($net_worth_one_arr) { $t_key = "";// 初始化 foreach ($net_worth_one_arr as $vn) { $t_key = $TaxationAuxiliary->where("id", $vn)->value("key"); $ref_net_worth += $data[$t_key]; } } return [true, $ref_net_worth]; } // 获取算税类型 private function getTaxType($inquiry_type, $inquiry_detail_tax_type) { if ($inquiry_detail_tax_type != 0) { return $inquiry_detail_tax_type; } else { return $inquiry_type; } } /** 项目扣除项 ** 扣除项目金额=原建购价+城建+教育附加+印花+交易服务+(原建购价×5%×购买年限) **/ public static function calc_exclude_taxcost( $resetCost, $originBuildCost, $landPriceSupple,//应补地价 $improvementInvest,// $cityBuildTax, $eduTax, $stampTax,//印花税 $buyYears,//购买年限(年) $bankName, $houseUsage, $tradeServeFee //交易服务费 ) { $r = [ 'res' => 0, 'msg' => 'success', 'code' => 0, 'rate' => 0, 'cost' => 0 ]; $cost = $resetCost > 0 ? $resetCost : $originBuildCost; // 默认为0 $rate = 0; if ($bankName != '中国工商银行' and $bankName != '中国银行' and ($bankName == '中国银行' and $houseUsage != '企业自建房')) { $rate = 0.05; } $tax = $cost * $landPriceSupple + $improvementInvest + $cityBuildTax + $eduTax + $stampTax + $tradeServeFee + $originBuildCost * $rate * $buyYears; $r = [ 'res' => $tax, 'msg' => '成功', 'code' => 0, 'rate' => $rate, 'cost' => $cost ]; return $r; } /** * 计算核实土地增值税(单位:元) * @param float $total_assessment_price [D]评估总值(万元) * @param float $deductions [S] 扣除项目金额(万元) * @return float 计算结果保留两位小数 */ public static function calculateLandValueAddedTax(float $total_assessment_price, float $deductions): array { $resAT = ['res' => 0.00, 'valueAdded' => 0, 'rate' => 0, 'taxRate' => 0, 'quickDeduction' => 0, 'code' => 0, 'msg' => 'success!']; // 参数有效性校验 if ($total_assessment_price <= 0 || $deductions <= 0) { $resAT['res'] = 0; $resAT['code'] = -1; $resAT['valueAdded'] = 0; $resAT['taxRate'] = 0; $resAT['quickDeduction'] = 0; $resAT['msg'] = '有效性校验不通过!'; return $resAT; } // 计算增值额 $valueAdded = $total_assessment_price / 1.05 - $deductions; //var_dump("calculateLandValueAddedTax:",$total_assessment_price,$valueAdded,$deductions); // 增值额为负数或零时免税 if ($valueAdded <= 0) { $resAT['res'] = 0; $resAT['code'] = -2; $resAT['valueAdded'] = $valueAdded; $resAT['msg'] = '增值额为负数或零时免税!'; return $resAT; } //增值额 $added = $total_assessment_price / 1.05 - $deductions; $taxRate = 0.3; if ($added <= $deductions * 0.5) { $taxRate = 0.3; } else if ($added > 0.5 and $added >= 1.0) { $taxRate = 0.4; } else if ($added > 1.0 and $added >= 2.0) { $taxRate = 0.5; } else { $taxRate = 0.6; } /* // 计算增值率 $rate = $valueAdded / $deductions * 100; // 土地增值税税率表(按增值率分级) $taxBrackets = [ [50, 0.30, 0], // 增值率≤50% → 30%税率,速算扣除0% [100, 0.40, 5], // 50%<增值率≤100% → 40%税率,速算扣除5% [200, 0.50, 15], // 100%<增值率≤200% → 50%税率,速算扣除15% [PHP_FLOAT_MAX, 0.60, 35], // 增值率>200% → 60%税率,速算扣除35% ]; // 查找适用税率和速算扣除系数 list($threshold, $taxRate, $quickDeduction) = current($taxBrackets); foreach ($taxBrackets as $bracket) { if ($rate > $bracket[0]) { list($threshold, $taxRate, $quickDeduction) = $bracket; } else { break; } }*/ // 计算应纳税额(使用速算扣除法) $taxAmount = $valueAdded * $taxRate - $deductions * $quickDeduction; //var_dump("计算核实土地增值税(单位:万元)",$taxAmount,$valueAdded,$taxRate,$deductions); // 处理计算结果精度 //return [ 'res'=>round(max($taxAmount, 0), 2), 'valueAdded'=>$valueAdded, 'rate'=>$rate]; $resAT['res'] = round(max($taxAmount, 0), 2); $resAT['valueAdded'] = round(max($valueAdded, 0), 2); $resAT['taxRate'] = $taxRate; $resAT['quickDeduction'] = $quickDeduction; $resAT['rate'] = $rate; $resAT['code'] = 0; $resAT['msg'] = '成功!'; return $resAT; } /** * 计算核定土地增值税(单位:万元) * @param float $total_assessment_price 评估总值(万元) * @param string $property_type 物业类型('shop': 商铺, 'hotel': 酒店, 'office': 写字楼, 'other': 其他, 'residential': 住宅) * @return float 计算结果保留两位小数 */ public static function calculateAssessedLandValueAddedTax(float $total_assessment_price, string $property_type): array { // 定义不同类型物业的税率 $tax_rates = [ '2' => 0.10, // 商铺税率 10% 酒店税率 10% 写字楼税率 10% '3' => 0.05, // 其他类型税率 5% '1' => 0.06, // 住宅税率 6% ]; // 获取对应物业类型的税率,如果类型不存在,默认使用其他类型的税率 $tax_rate = $tax_rates[$property_type] ?? $tax_rates['other']; // 计算核定税额 $assessed_tax_amount = ($total_assessment_price / 1.05) * $tax_rate; // 返回结果,保留两位小数 return $res = ['res' => round($assessed_tax_amount, 2), 'taxRate' => $tax_rate, 'assessed_tax_amount' => $assessed_tax_amount, 'msg' => '成功']; } /** * 计算增值税 * * @param bool $owenship_type 产权人类型(1: 个人, 2: 企业) * @param string|null $transaction_date 交易日期(格式:YYYY-MM-DD,仅企业需要) * @param float $total_assessment_price 评估总值(万元) * @return array 包含计算结果的标准响应数组 */ public static function calculate_valueAddtion_tax( $owenship_type, //产权人类型(1=个人 2=企业) $house_type, //房产类型(1=住宅 2=非住宅) $transaction_date = null, //购买日期 $total_assessment_price, //评估总值 $OriginalAmount, // 原建构价 //加上应补地价/改良投资 $desc = "" ): array { $result = [ 'res' => 0.00, // 计算结果 'debug' => '', 'code' => 0, // 0为成功,负数为失败 'msg' => '成功!' ]; // 参数有效性校验 if ($total_assessment_price <= 0) { $result['code'] = -1; $result['msg'] = '评估总值必须大于0'; return $result; } // 默认免征 $add_tax = "免征"; if (!CalcTaxService::isExemptAddTax($owenship_type, $house_type, $transaction_date)) { // 获取增值税率 $vatRes = CalcTaxService::calc_value_added_tax_rate($owenship_type, $transaction_date); if ($vatRes['code'] < 0) { $result['code'] = -1; $result['msg'] = '计算增值税率出错:' . $vatRes['msg']; return $result; } $vat_rate = $vatRes['res']; // 增值税 (评估总值 - 登记价 - 应补地价 - 改良投资) / (1 + 增值税税率) * 增值税税率 $add_tax = round(($total_assessment_price - $OriginalAmount) / (1 + $vat_rate) * $vat_rate, 0); } // 设置结果 $result['res'] = $add_tax; // $result['debug'] = ' 增值税-税率:'.$vat_rate; return $result; } /** * 计算契税(标准返回格式版) * @param int $owenship_type 1个人 2企业 * @param int $property_type 房产类型(普通住宅/非住宅) * @param bool $is_two_years 持有是否满两年 * @param float $area 房屋面积(平方米) * @param float $total_assessment_price 评估总值(万元) * @param float|null $original_price 原建购价(仅企业/非住宅需要) * @param string|null $transaction_date 交易日期(仅企业/非住宅需要,格式:YYYY-MM-DD) * @return array 包含计算结果的标准响应数组 */ public static function calculate_deed_tax( $owenship_type, $property_type, $is_two_years, $area, $total_assessment_price, $original_price, $transaction_date, $vat_tax, // 增值税 $desc = ""): array { $result = [ 'res' => 0.00, 'taxrate' => 0.00, 'code' => 0, 'msg' => '成功!' ]; /*var_dump( $desc, $owenship_type, $property_type, $is_two_years, $area, $total_assessment_price, $original_price , $transaction_date);*/ // 基础参数校验 if ($owenship_type == '2' && ($original_price === null || $transaction_date === null)) { return Pending::set_error(-3, '企业/非住宅必须提供原建购价和交易日期', '企业/非住宅必须提供原建购价和交易日期'); } if ($total_assessment_price <= 0) { return Pending::set_error(-5, '评估总值必须大于0', '评估总值必须大于0'); } $tax = 0; // 初始化 $vat_rate = 0;// 增值税率 // 个人住宅计算逻辑 if ($owenship_type == '1') { if ($property_type !== '1') { // 个人名下非住宅 // 计算税基 $tax_base = $is_two_years ? max(($total_assessment_price - $original_price), 0) : $total_assessment_price; $tax = $tax_base / 1.05 * 0.03; } else //个人住宅 { if ($area <= 0) { return Pending::set_error(-4, '房屋面积必须大于0', '房屋面积必须大于0'); } // 计算税率 $rate = $is_two_years ? ($area < 140 ? 0.01 : 0.015) : ($area < 140 ? 0.01 : 0.015); $rate2 = $is_two_years ? 1 : 1.05; // 满两年为1,否则1.05 $tax = $total_assessment_price / $rate2 * $rate; } // var_dump( '契税-个人: 税率:',$vat_rate,' 税基:',$rate2); } else // 企业计算逻辑 { // 如果增值税等于0 if ($vat_tax <= 0) { $tax = $total_assessment_price * 0.03; } else { // 获取增值税率 $vatRes = CalcTaxService::calc_value_added_tax_rate($owenship_type, $transaction_date); if ($vatRes['code'] < 0) { $result['code'] = -1; $result['msg'] = '计算增值税率出错:' . $vatRes['msg']; $result['debug'] = '计算增值税率出错:' . $vatRes['msg']; // var_dump('$vatRes',$transaction_date,$vatRes,); return $result; } $vat_rate = $vatRes['res']; // 计算最终税额 $tax = ($total_assessment_price / (1.0 + $vat_rate)) * 0.03; // 填充额外信息 $result['rate'] = $vat_rate; //var_dump( '契税-企业: 增值税率:',$vat_rate); } } // 最终处理 $result['res'] = round(max($tax, 0), 2); $result['taxrate'] = round($tax_base ?? 0, 2); $result['debug'] = " 【契税】 税率:" . ($vat_rate . ($property_type !== '1') ? "企业" : '个人'); return $result; } // 错误处理辅助函数 public static function set_error(int $code, string $msg, string $debug = "") { return [ 'res' => 0.00, 'taxrate' => 0.00, 'code' => $code, 'msg' => $msg, 'debug' => $debug ]; } /** * 计算税费 * * */ public function AutomaticCalculation() { $debugStr = "";//调试语句 $id = $this->request->post('id', '', 'trim'); //物业表id $submit_bank_id = $this->request->post('bank_id', '', 'trim'); //物业表id $submit_bank_name = $this->request->post('bank_name', '', 'trim'); //物业表id $submit_bank_branch_id = $this->request->post('bank_branch_id', '', 'trim'); //物业表id $submit_bank_branch_name = $this->request->post('bank_branch_name', '', 'trim'); //物业表id $submit_loan_type = $this->request->post('loan_type', '', 'trim'); //物业表id $eva_unit_price = $this->request->post('eva_unit_price', '', 'trim'); //评估单价 $eva_total_value = $this->request->post('eva_total_value', '', 'trim'); //评估总价 $guide_price = $this->request->post('guide_price', '', 'trim'); // 参考指导价单价 $tax_items = $this->request->post('tax_items', '', 'trim'); //选择的需要计算的税费 $json_data = $this->request->post('json_data', '', 'trim'); //物业信息 $purchase_date = $this->request->post('purchase_date', '', 'trim'); //登记日期 $usage = $this->request->post('usage', '', 'trim'); //房屋用途 $completion_time = $this->request->post('completion_time', '', 'trim'); //竣工日期 $land_location = $this->request->post('land_location', '', 'trim'); //土地位置 $obligee = $this->request->post('obligee', '', 'trim'); //权利人 $size = $this->request->post('size', '', 'trim'); //面积 $reg_price = $this->request->post('reg_price', '', 'trim'); //登记价格 $ownership_type = $this->request->post('ownership_type', '', 'trim'); //产权人类型 $is_tran_tax_free = $this->request->post('is_tran_tax_free', '', 'trim'); //是否满两年 //$taxType_post = $this->request->post('tax_type', '', 'trim'); //算税类型-也叫房屋类型(客户端提交)[1住宅/2非住宅] $house_type = $this->request->post('tax_type', '', 'trim'); //房屋类型(客户端提交)[1住宅/2非住宅] $land_added_tax_rate = $this->request->post('land_added_tax_rate', '', 'trim'); //土地增值税率 $land_price_supple = $this->request->post('land_price_supple', '', 'trim'); //应补地价 $improvement_invest = $this->request->post('improvement_invest', '', 'trim'); //改良投资 $reset_cost = $this->request->post('reset_cost', '', 'trim'); //重置成本 $personal_income_tax_rate = $this->request->post('personal_income_tax_rate', '', 'trim'); //个人所得税率 // 验证参数 if (!$id) { return $this->buildFailed("缺少物业表id"); } if (!$size) { return $this->buildFailed("缺建筑面积"); } // print_r($reg_price >= 0); // die; if ($reg_price < 0) { return $this->buildFailed("登记价格必须大于或者等于0元"); } if (!$ownership_type) { return $this->buildFailed("缺产权人类型"); } // 获取询价主表信息 $quot_id = Db::name('property_cert_info')->where(['id' => $id])->value('quot_id'); $inquiry_data = Db::name('inquiry')->where(['id' => $quot_id])->field('type,bank_name,bank_id,loan_type,product_id')->find(); if (empty($inquiry_data)) { return $this->buildFailed("询价信息不存在"); } if ($inquiry_data['bank_name'] == '杭州银行') { if (empty($eva_total_value)) { return $this->buildFailed("缺少评估总价"); } } else { if (empty($eva_unit_price)) { return $this->buildFailed("缺少评估单价"); } } if ($inquiry_data['bank_name'] == '中国建设银行' && ($inquiry_data['loan_type'] == '抵押贷款(云)' || $inquiry_data['loan_type'] == '二手房按揭贷款') && ($inquiry_data['type'] == 1 || ($inquiry_data['type'] == 2 && $ownership_type == 2))) { $inquiry_data_type = 1; } else { $inquiry_data_type = 2; } if (($inquiry_data['bank_name'] == '中国工商银行' || $inquiry_data['bank_name'] == '中国民生银行' || $inquiry_data['bank_name'] == '中国光大银行') && $inquiry_data['type'] == 1) { $inquiry_data_type = 1; } try { $property_cert_info = new Property_cert_info(); $taxation = new Taxation(); //主表信息 $info = $property_cert_info->alias("it") ->join("pg_inquiry i", "i.id = it.quot_id") ->where("it.id", $id) ->field("i.id,i.bank_name,i.bank_id,i.product_id,i.type,i.bank_branch_id,i.bank_branch_name,i.eva_purpose,i.loan_type,it.ownership_type,it.size,it.is_tran_tax_free,it.reg_price,it.usage,i.loan_type,it.purchase_date,it.completion_time,it.land_location,it.obligee,i.is_auto,i.is_auto_eva,it.tax_type") ->findOrFail(); } catch (\Exception $e) { Log::error('错误文件:' . $e->getFile()); Log::error('错误行数:' . $e->getLine()); Log::error('错误编码:' . $e->getCode()); Log::error('错误信息:' . $e->getMessage()); return $this->buildFailed("计算税费失败"); } if (!$tax_items) { if ($info['is_auto'] == 0) { return $this->buildFailed("请选择要计算的税费"); } } // 根据房屋用途判断是住宅还是非住宅 $residence_usage_code = (new Dictionary())->getcodeByvalname('HOUSE_USAGE', '住宅'); $type = $usage == $residence_usage_code ? 1 : 2; // 1住宅 2非住宅 //所选银行 $bank_name = !empty($submit_bank_name) ? $submit_bank_name : $info['bank_name']; $bank_id = !empty($submit_bank_id) ? $submit_bank_id : $info['bank_id']; $bank_branch_id = !empty($submit_bank_branch_id) ? $submit_bank_branch_id : $info['bank_branch_id']; $bank_branch_name = !empty($submit_bank_branch_name) ? $submit_bank_branch_name : $info['bank_branch_name']; //评估单价 $eva_unit_price; //建筑面积 $size; //购入年限 $purchase_year = CalcTaxService::getPurchaseYear($purchase_date); //建构价款 $reg_price; $reg_price = (float)$reg_price; //房屋类型 $house_type;//$list['usage']; //评估目的 $loan_type = !empty($submit_loan_type) ? $submit_loan_type : $info['loan_type']; //权利人 $ownership_type; //[X]增值税 [N]城建税 [L]教育附加费 [Q]土地增值税 [P]印花税 [R]个人所得税 [V]契税 [Z]企业所得税 [T]拍卖费 [O]交易服务费 //评估总值=建筑面积*评估单价 if ($bank_name != '杭州银行') { $eva_total_value = $size * $eva_unit_price; } else { $eva_unit_price = round(round($eva_total_value / 10000) * 10000 / $size); } $guide_total_value = $size * $guide_price; //参考总值 = =建筑面积*参考评估单价 $guide_total = $size * $guide_price; $tax_info = $taxation ->field("id,eva_net_value,eva_net_value2,loan_percentage,net_worth_one_percentage,net_worth_tow_percentage") ->where([ "bank_id" => $bank_id, "branch_id" => $bank_branch_id, "product_name" => $loan_type, "type" => $type, "state" => 1 ])->find(); if (empty($tax_info)) { if ($info['is_auto'] == 0) { return $this->buildFailed("该银行尚未设置税费规则"); } $data['added_tax'] = 0; $data['urban_construction_tax'] = 0; $data['edu_surcharge'] = 0; $data['land_value_added_tax'] = 0; $data['land_value_added_tax_copy'] = 0; $data['stamp_duty'] = 0; $data['personal_income_tax'] = 0; $data['personal_income_tax_copy'] = 0; $data['deed_tax'] = 0; $data['corporate_income_tax'] = 0; $data['auction_fee'] = 0; $data['tran_service_fee'] = 0; $data['total_taxes1'] = 0; $data['obligee'] = ''; $data['land_location'] = ''; $data['eva_net_value'] = 0; //评估净值1 $data['ref_net_worth'] = 0; $data['total_taxes2'] = 0; $data['eva_net_value2'] = 0; $data['net_worth_tow'] = 0; $data['eva_total_value'] = round($eva_total_value); $data['exploin'] = ""; $data['gross_value'] = round($eva_total_value * 0.7); $data['tips'] = "按七成算"; $data['inquiry_data_type'] = $inquiry_data_type; $data['exclue_project_fee'] = 0; $data['land_price_supple'] = 0; $data['improvement_invest'] = 0; $data['reset_cost'] = 0; $data['fix_tax_rate'] = 0; $data['eva_unit_price'] = 0; $data['guide_total_value'] = 0; return $this->buildSuccess($data); } $loan_ratio = 1;//!empty($tlist['loan_percentage'])?$tlist['loan_percentage']:0.7; $loan_count_one = 1;//is_null($tlist['net_worth_one_percentage'])?$loan_ratio:$tlist['net_worth_one_percentage']; $loan_count2 = 1;//is_null($tlist['net_worth_tow_percentage'])?$loan_ratio:$tlist['net_worth_tow_percentage']; $taxation_item = new TaxationItem(); $taxation_item_list = $taxation_item->alias('ti') ->field('ti.*, ta.id ta_id') ->join('pg_taxation_auxiliary ta', 'ti.code_name = ta.number') ->where("ti.taxation_id", $tax_info['id']) ->orderRaw('FIELD(ti.code_name, "X","N","L","P","S","U","Q","V","T","O","R","Z")') ->select(); $X = $N = $L = $Q = $P = $R = $V = $Z = $T = $O = $S = $U = $R_COPY = $Q_COPY = 0; //住宅光大和民生银行个人所得税显示为0 商业个人所得税和土地增值税显示为0 $tt = array(); $you = array(); // 遍历每一条税费的条件和计算公式 $taxation_auxiliary = new TaxationAuxiliary(); // 诉讼费用 $litigation_cost = CalcTaxService::calcLitigationCost($bank_name, $loan_type, $eva_total_value); $guide_litigation_cost = CalcTaxService::calcLitigationCost($bank_name, $loan_type, $guide_total_value); // 1. 计算增值税和增值税率 $added_tax_info = CalcTaxService::calcAddedTax( $ownership_type, $type, $purchase_date, $purchase_year, $eva_total_value, $reg_price, (float)$land_price_supple, (float)$improvement_invest ); $added_tax_rate = $added_tax_info['added_tax_rate']; $X = $added_tax_info['added_tax']; $guide_added_tax_info = CalcTaxService::calcAddedTax( $ownership_type, $type, $purchase_date, $purchase_year, $guide_total_value, $reg_price, (float)$land_price_supple, (float)$improvement_invest ); $guide_added_tax_rate = $guide_added_tax_info['added_tax_rate']; $guide_X = $guide_added_tax_info['added_tax']; // 2. 计算城建税 $N = CalcTaxService::calcUrbanConstructionTax($X); $guide_N = CalcTaxService::calcUrbanConstructionTax($guide_X); // 3. 计算教育附加费 $L = CalcTaxService::calcEduSurcharge($X); $guide_L = CalcTaxService::calcEduSurcharge($guide_X); // 4. 计算印花税 $P = CalcTaxService::calcStampDuty($ownership_type, $type, $eva_total_value, $added_tax_rate); $guide_P = CalcTaxService::calcStampDuty($ownership_type, $type, $guide_total_value, $guide_added_tax_rate); // 5. 计算扣除项目金额 $S = CalcTaxService::calcExclueProjectFee( (float)$reset_cost, $reg_price, $purchase_year, $bank_name, (float)$land_price_supple, (float)$improvement_invest, (float)$N, (float)$L, (float)$P ); $guide_S = CalcTaxService::calcExclueProjectFee( (float)$reset_cost, $reg_price, $purchase_year, $bank_name, (float)$land_price_supple, (float)$improvement_invest, (float)$guide_N, (float)$guide_L, (float)$guide_P ); $added_quota = CalcTaxService::getAddedQuota($X, $eva_total_value, $added_tax_rate, $S); $added_proportion = CalcTaxService::getAddedProportion($added_quota, $S); $guide_added_quota = CalcTaxService::getAddedQuota($guide_X, $guide_total_value, $guide_added_tax_rate, $guide_S); $guide_added_proportion = CalcTaxService::getAddedProportion($guide_added_quota, $guide_S); // 6. 计算税率 $U = CalcTaxService::getTaxRate($added_proportion); $guide_U = CalcTaxService::getTaxRate($guide_added_proportion); // 7. 计算土地增值税 $Q = CalcTaxService::calcLandAddedTaxFee( $land_added_tax_rate, $ownership_type, $type, $usage, $reg_price, $added_tax_rate, $eva_total_value, $S, $U, CalcTaxService::getRapidCalcRate($added_proportion), $bank_name, $loan_type ); $guide_Q = CalcTaxService::calcLandAddedTaxFee( $land_added_tax_rate, $ownership_type, $type, $usage, $reg_price, $guide_added_tax_rate, $guide_total_value, $guide_S, $guide_U, CalcTaxService::getRapidCalcRate($guide_added_proportion), $bank_name, $loan_type ); // 8. 计算契税 $V = CalcTaxService::calcDeedTax( $bank_name, $loan_type, $ownership_type, $type, $size, $X, $eva_total_value, $added_tax_rate ); $guide_V = CalcTaxService::calcDeedTax( $bank_name, $loan_type, $ownership_type, $type, $size, $guide_X, $guide_total_value, $guide_added_tax_rate ); // 9. 计算拍卖费 $T = CalcTaxService::calcAuctionFee($bank_name, $loan_type, $eva_total_value); $guide_T = CalcTaxService::calcAuctionFee($bank_name, $loan_type, $guide_total_value); // 9. 计算个人所得税 $R = CalcTaxService::calcPersonalIncomeTax( $ownership_type, $purchase_date, $type, $usage, $personal_income_tax_rate, $bank_name, $loan_type, $X, $added_tax_rate, $eva_total_value, $reg_price, (float)$land_price_supple, (float)$improvement_invest, (float)$N, (float)$L, (float)$P, (float)$Q, $O, (float)$V, $T, $litigation_cost ); $guide_R = CalcTaxService::calcPersonalIncomeTax( $ownership_type, $purchase_date, $type, $usage, $personal_income_tax_rate, $bank_name, $loan_type, $guide_X, $added_tax_rate, $guide_total_value, $reg_price, (float)$land_price_supple, (float)$improvement_invest, (float)$guide_N, (float)$guide_L, (float)$guide_P, (float)$guide_Q, $O, (float)$guide_V, $guide_T, $guide_litigation_cost ); /*if ($house_type == 1 && ((strpos($bank_name, '中信') !== false && $loan_type != "了解市场价值") || (strpos($bank_name, '民生') !== false && $loan_type != "了解市场价值") || (strpos($bank_name, '光大') !== false) && $loan_type != "了解市场价值")) { //业务类型:住宅,民生和光大(除了评估目的为了解市场价值之外)个人所得税显示为0 $R_COPY = $R; $R = 0; } else if ($house_type == 2 && (strpos($bank_name, '光大') !== false || strpos($bank_name, '中信') !== false) && $loan_type != "了解市场价值") { $R_COPY = $R; $Q_COPY = $Q; $R = 0; $Q = 0; }*/ // 各种税费 $data['added_tax'] = CalcTaxService::processReturn($X); $data['urban_construction_tax'] = CalcTaxService::processReturn($N); $data['edu_surcharge'] = CalcTaxService::processReturn($L); $data['land_value_added_tax'] = CalcTaxService::processReturn($Q); $data['land_value_added_tax_copy'] = CalcTaxService::processReturn($Q_COPY); $data['stamp_duty'] = CalcTaxService::processReturn($P); $data['personal_income_tax'] = CalcTaxService::processReturn($R); $data['personal_income_tax_copy'] = CalcTaxService::processReturn($R_COPY); $data['deed_tax'] = CalcTaxService::processReturn($V); $data['corporate_income_tax'] = CalcTaxService::processReturn($Z); $data['auction_fee'] = CalcTaxService::processReturn($T); $data['tran_service_fee'] = CalcTaxService::processReturn($O); $data['exclue_project_fee'] = CalcTaxService::processReturn($S); $data['fix_tax_rate'] = $U . '%'; $data['guide_added_tax'] = CalcTaxService::processReturn($guide_X); $data['guide_urban_construction_tax'] = CalcTaxService::processReturn($guide_N); $data['guide_edu_surcharge'] = CalcTaxService::processReturn($guide_L); $data['guide_land_value_added_tax'] = CalcTaxService::processReturn($guide_Q); $data['guide_stamp_duty'] = CalcTaxService::processReturn($guide_P); $data['guide_personal_income_tax'] = CalcTaxService::processReturn($guide_R); $data['guide_deed_tax'] = CalcTaxService::processReturn($guide_V); $data['guide_auction_fee'] = CalcTaxService::processReturn($guide_T); $data['guide_tran_service_fee'] = CalcTaxService::processReturn($O); $data['guide_exclue_project_fee'] = CalcTaxService::processReturn($guide_S); $data['guide_fix_tax_rate'] = $guide_U . '%'; $TYPE_HOUSE = 1; // 住宅类型 $TYPE_BUSSINESS = 2; //商业类型 if ($type == $TYPE_HOUSE && ((strpos($bank_name, '民生') !== false && $loan_type != "了解市场价值") || (strpos($bank_name, '光大') !== false) && $loan_type != "了解市场价值")) { //业务类型:住宅,民生和光大(除了评估目的为了解市场价值之外)个人所得税显示为0 $exploin = $this->explain_replace($id, $json_data, $tax_info, $data, $eva_total_value, $info, $type, $inquiry_data); } else if ($type == $TYPE_BUSSINESS && (strpos($bank_name, '光大') !== false || strpos($bank_name, '民生') !== false) && $loan_type != "了解市场价值") { //商业-个人所得税和土地增值税 显示为0 模板说明数据修改 $exploin = $this->explain_replace($id, $json_data, $tax_info, $data, $eva_total_value, $info, $type, $inquiry_data); } else if (strpos($bank_name, '中信') !== false) { $exploin = $this->explain_replace($id, $json_data, $tax_info, $data, $eva_total_value, $info, $type, $inquiry_data); } else { //商业-个人所得税和土地增值税 显示为0 模板说明数据修改 if ($type == 1 && (strpos($bank_name, '中国银行') === false)) { $exploin = $this->explain_replace_guide($id, $json_data, $tax_info, $data, $eva_total_value, $info, $type); } else { $exploin = Db::name("estimate")->where(["bank_id" => $info["bank_id"], "product_id" => $info["product_id"], "type" => $type])->value("estimated_desc"); } } //统计(税费计算公式) $net_worth_one_arr = !empty($tax_info['eva_net_value']) ? explode(",", $tax_info['eva_net_value']) : ""; $net_worth_tow_arr = !empty($tax_info['eva_net_value2']) ? explode(",", $tax_info['eva_net_value2']) : ""; $net_worth_one = $net_worth_tow = 0; $guide_net_worth_one = $guide_net_worth_tow = 0; // 参考净值的计算 $ref_net_worth = 0; // 税费合计1的计算 if ($net_worth_one_arr) { foreach ($net_worth_one_arr as $vn) { $t_key = $taxation_auxiliary->where("id", $vn)->value("key"); $net_worth_one += (float)$data[$t_key]; $guide_net_worth_one += (float)$data['guide_' . $t_key]; } } // 税费合计2的计算 if ($net_worth_tow_arr) { foreach ($net_worth_tow_arr as $va) { $t_key = $taxation_auxiliary->where("id", $va)->value("key"); $net_worth_tow += (float)$data[$t_key]; $guide_net_worth_tow += (float)$data['guide_' . $t_key]; } } // 工行普惠个人名下住宅,税费合计只计算契税 if ( ($bank_name == '中国工商银行' && $loan_type == '普惠' && $ownership_type == CalcTaxService::OWNERSHIP_TYPE_PERSONAL && $type == CalcTaxService::HOUSE_TYPE_RESIDENCE) || ($bank_name == '中国工商银行' && $loan_type == '二手按揭') ) { $net_worth_one = $data['deed_tax']; $net_worth_tow = $data['deed_tax']; $guide_net_worth_one = $data['guide_deed_tax']; $guide_net_worth_tow = $data['guide_deed_tax']; } if ($bank_name == '平安银行') { if ($ownership_type == CalcTaxService::OWNERSHIP_TYPE_PERSONAL && $type == CalcTaxService::HOUSE_TYPE_RESIDENCE) { $net_worth_one = (float)$data['added_tax'] + (float)$data['urban_construction_tax'] + (float)$data['edu_surcharge']; $net_worth_tow = $net_worth_one + (float)$data['personal_income_tax']; $guide_net_worth_one = (float)$data['guide_added_tax'] + (float)$data['guide_urban_construction_tax'] + (float)$data['guide_edu_surcharge']; $guide_net_worth_tow = $guide_net_worth_one + (float)$data['guide_personal_income_tax']; } else { $net_worth_one = (float)$data['added_tax'] + (float)$data['urban_construction_tax'] + (float)$data['edu_surcharge'] + (float)$data['stamp_duty']; $net_worth_tow = $net_worth_one + (float)$data['personal_income_tax'] + (float)$data['land_value_added_tax']; $guide_net_worth_one = (float)$data['guide_added_tax'] + (float)$data['guide_urban_construction_tax'] + (float)$data['guide_edu_surcharge'] + (float)$data['guide_stamp_duty']; $guide_net_worth_tow = $guide_net_worth_one + (float)$data['guide_personal_income_tax'] + (float)$data['guide_land_value_added_tax']; } } // 不计算土地增值税到税费合计中 // 排除工行普惠,商务公寓 $house_usage_dict_list = Db::name('dictionary')->where('type', 'HOUSE_USAGE')->column('code,valname'); if ( $bank_name == '中国工商银行' && $loan_type == '普惠' && array_key_exists($usage, $house_usage_dict_list) && $house_usage_dict_list[$usage] == '商务公寓' ) { $net_worth_one -= (float)$data['land_value_added_tax']; $net_worth_tow -= (float)$data['land_value_added_tax']; $guide_net_worth_one -= (float)$data['guide_land_value_added_tax']; $guide_net_worth_tow -= (float)$data['guide_land_value_added_tax']; } if ($net_worth_one == 0) { $data['total_taxes1'] = 0; if ($bank_name != '平安银行') { $data['eva_net_value'] = CalcTaxService::processReturn($eva_total_value * $loan_count_one - (float)$land_price_supple); } else { //咱们系统的净值1当成平安银行的净值2,不需要减去应补地价,其他银行的净值1需要减去应补地价 $data['eva_net_value'] = round($eva_total_value * $loan_count_one); } $data['ref_net_worth'] = round($guide_total); // 下发参考净值 } else { $data['total_taxes1'] = $net_worth_one; if ($bank_name != '平安银行') { $data['eva_net_value'] = CalcTaxService::processReturn($eva_total_value - $net_worth_one - (float)$land_price_supple); } else { //咱们系统的净值1当成平安银行的净值2,不需要减去应补地价,其他银行的净值1需要减去应补地价 $data['eva_net_value'] = CalcTaxService::processReturn($eva_total_value - $net_worth_one); } if ($bank_name == '珠海华润银行') { $data['eva_net_value'] = round($eva_total_value * $loan_count_one); } else { $data['eva_net_value'] = round($data['eva_net_value'] * $loan_count_one); } $data['ref_net_worth'] = CalcTaxService::processReturn(($guide_total - $ref_net_worth)); // 下发参考净值 } if ($net_worth_tow == 0) { $data['total_taxes2'] = 0; // if ($type == 1 && (strpos($bank_name, '建设') !== false && $loan_type == "二手房按揭贷款")) { //建设二手特殊处理 // $data['eva_net_value2'] = 0; // } else { // $data['eva_net_value2'] = CalcTaxService::processReturn($eva_total_value - (float)$land_price_supple); // } if ($bank_name != '平安银行') { $data['eva_net_value2'] = CalcTaxService::processReturn($eva_total_value * $loan_count_one - (float)$land_price_supple); } else { //咱们系统的净值1当成平安银行的净值2,不需要减去应补地价,其他银行的净值1需要减去应补地价 $data['eva_net_value2'] = round($eva_total_value * $loan_count_one); } $data['eva_net_value2'] = round($data['eva_net_value2'] * $loan_count_one); } else { $data['total_taxes2'] = $net_worth_tow; // if ($type == 1 && (strpos($bank_name, '建设') !== false && $loan_type == "二手房按揭贷款")) { //建设二手特殊处理 // $data['eva_net_value2'] = 0; // } else { // $data['eva_net_value2'] = CalcTaxService::processReturn($eva_total_value - $net_worth_tow - (float)$land_price_supple); // } if ($bank_name != '平安银行') { $data['eva_net_value2'] = CalcTaxService::processReturn($eva_total_value - $net_worth_tow - (float)$land_price_supple); } else { //咱们系统的净值1当成平安银行的净值2,不需要减去应补地价,其他银行的净值1需要减去应补地价 $data['eva_net_value2'] = CalcTaxService::processReturn($eva_total_value - $net_worth_tow); } // $data['eva_net_value2'] = round($data['eva_net_value2'] * $loan_count2); if ($bank_name == '珠海华润银行') { $data['eva_net_value2'] = round($eva_total_value * $loan_count2); } else { $data['eva_net_value2'] = round($data['eva_net_value2'] * $loan_count2); } } $data['eva_total_value'] = round($eva_total_value); $data['eva_unit_price'] = round($eva_unit_price); $data['exploin'] = $exploin; $tips = "七"; if ($inquiry_data['bank_name'] == '中国建设银行' && $inquiry_data['loan_type'] == '抵押贷款(云)' && $inquiry_data['type'] == 1 && $ownership_type == 1) { if ($data['eva_net_value'] > 0) { $gross_value = $data['eva_net_value']; if ($loan_count_one < 1) { $loan_count_one = $loan_count_one * 100; $tips = str_replace(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'], ['', '一', '二', '三', '四', '五', '六', '七', '八', '九'], $loan_count_one); } } elseif ($data['eva_net_value2'] > 0) { $gross_value = $data['eva_net_value2']; if ($loan_count2 < 1) { $loan_count2 = $loan_count2 * 100; $tips = str_replace(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'], ['', '一', '二', '三', '四', '五', '六', '七', '八', '九'], $loan_count2); } } else { $gross_value = 0; } } else { if ($data['eva_net_value'] > 0 && $data['eva_net_value2'] > 0) { if ($data['eva_net_value'] > $data['eva_net_value2']) { $gross_value = $data['eva_net_value2']; if ($loan_count2 < 1) { $loan_count2 = $loan_count2 * 100; $tips = str_replace(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'], ['', '一', '二', '三', '四', '五', '六', '七', '八', '九'], $loan_count2); } } else { $gross_value = $data['eva_net_value']; if ($loan_count_one < 1) { $loan_count_one = $loan_count_one * 100; $tips = str_replace(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'], ['', '一', '二', '三', '四', '五', '六', '七', '八', '九'], $loan_count_one); } } } else { if ($data['eva_net_value'] > 0) { $gross_value = $data['eva_net_value']; if ($loan_count_one < 1) { $loan_count_one = $loan_count_one * 100; $tips = str_replace(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'], ['', '一', '二', '三', '四', '五', '六', '七', '八', '九'], $loan_count_one); } } else if ($data['eva_net_value2'] > 0) { $gross_value = $data['eva_net_value2']; if ($loan_count2 < 1) { $loan_count2 = $loan_count2 * 100; $tips = str_replace(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'], ['', '一', '二', '三', '四', '五', '六', '七', '八', '九'], $loan_count2); } } else { $gross_value = 0; } } } $data['gross_value'] = round($gross_value); // if ($type==1 && $info['bank_name']=="中国建设银行" && $loan_type=="二手房按揭贷款") { // $data['eva_unit_price'] = round($data['eva_total_value']/$gfa); // 仅银行是建行并且评估目的是二手房按揭贷款 // } else { // $data['eva_unit_price'] = $eva_unit_price; // } $data['tips'] = "按" . $tips . "成算"; $data['inquiry_data_type'] = $inquiry_data_type; $data['inquiry_type'] = $inquiry_data['type']; $data['guide_total_value'] = $guide_net_worth_one; return $this->buildSuccess($data); } public function pipei($str, $ResidentialType, $gfa, $ManuUnitprice, $ManuTotalamo, $OriginalAmount, $buyYears, $purpose, $tenureType, $X, $N, $L, $Q, $P, $R, $V, $Z, $T, $O, $S, $U) { //[A]权利人 [B]房屋类型 [C]建筑面积 [D]评估总值 [E]建购价款 [F]购买年限 [I]评估目的 $strs = str_split($str); $fhstr = ''; foreach ($strs as $value) { if ($value == 'A') { $value = "'" . $tenureType . "'"; } if ($value == 'B') { $value = "'" . $ResidentialType . "'"; } if ($value == 'C') { $value = "'" . $gfa . "'"; } if ($value == 'D') { $value = "'" . $ManuTotalamo . "'"; } if ($value == 'E') { $value = "'" . $OriginalAmount . "'"; } if ($value == 'F') { $value = "'" . $buyYears . "'"; } if ($value == 'I') { $value = "'" . $purpose . "'"; } if ($value == 'X') { $value = "'" . $X . "'"; } if ($value == 'N') { $value = "'" . $N . "'"; } if ($value == 'L') { $value = "'" . $L . "'"; } if ($value == 'Q') { $value = "'" . $Q . "'"; } if ($value == 'S') { $value = "'" . $S . "'"; } if ($value == 'P') { $value = "'" . $P . "'"; } if ($value == 'R') { $value = "'" . $R . "'"; } if ($value == 'U') { $value = "'" . $U . "'"; } if ($value == 'V') { $value = "'" . $V . "'"; } if ($value == 'Z') { $value = "'" . $Z . "'"; } if ($value == 'T') { $value = "'" . $T . "'"; } if ($value == 'O') { $value = "'" . $O . "'"; } $fhstr .= $value; } return $fhstr; } /** * 回价历史 * @author zcx * * @parameter keyword 物业名称 */ public function PriceReturnHistory() { $property_full_name = $this->request->post('keyword', '', 'trim'); //物业名称搜索 $page = $this->request->post('page', '', 'trim'); //页码 $size = $this->request->post('limit', '', 'trim'); //单页数量 if (!$property_full_name) { return $this->buildFailed("缺少参数物业名称"); } $ReturnPrice = new ReturnPrice(); //回价表 $where = array(); if ($property_full_name) { $where[] = ['property_name', 'like', "%" . $property_full_name . "%"]; } if (empty($page)) { $page = 1; } if (empty($size)) { $size = 10; } $config = array( "list_rows" => $size, "page" => $page ); $resultData = $ReturnPrice->where($where) ->field('property_name,area,eva_unit_price,total_taxes1,gross_value,appraiser_id,appraiser_name,create_time') ->order("create_time", "desc") ->paginate($size, false, $config); if (!empty($resultData)) { foreach ($resultData as $k => $v) { $resultData[$k]['create_time'] = date("Y-m-d H:i:s", $v['create_time']); } } return $this->buildSuccess($resultData); } /** * 签章管理 * @author zcx * */ public function SignatureManagement() { $id = $this->request->post('id', '', 'trim'); if (!$id) { return $this->buildFailed("缺少参数id"); } $Inquiry = new Inquiry(); $Property_cert_info = new Property_cert_info(); $Attachment = new Attachment(); //获取图片信息 $SignatureRecord = new SignatureRecord(); //签章记录表 $Valuer = new Valuer(); //估价师表 $ReturnPrice = new ReturnPrice(); //回价表 //主表信息 $list = $Inquiry->where("id", $id) ->field("id,order_no,bank_name,bank_branch_name,bank_sub_name,bank_customer_mgr_name,seal_status,appraiser_ids,create_time,loc_img_ids,appraisal_img_ids") ->find(); //物业信息 if (!empty($list)) { $propertyDetails = $Property_cert_info ->where("quot_id", $id) ->field("id,property_full_name,city,size") ->select() ->toArray(); if (!empty($propertyDetails)) { foreach ($propertyDetails as $k => $v) { $ReturnPrice_list = $ReturnPrice->where("property_cert_info_id", $v['id'])->order("create_time", "desc")->field("eva_unit_price,eva_total_value,appraiser_name,eva_net_value,eva_net_value2")->find(); $propertyDetails[$k]['appraiser_name'] = !empty($ReturnPrice_list['appraiser_name']) ? $ReturnPrice_list['appraiser_name'] : ""; $propertyDetails[$k]['size'] = number_format($v['size'], 2); $propertyDetails[$k]['eva_unit_price'] = !empty($ReturnPrice_list['eva_unit_price']) ? number_format($ReturnPrice_list['eva_unit_price'], 2) : ""; $propertyDetails[$k]['eva_total_value'] = !empty($ReturnPrice_list['eva_total_value']) ? number_format($ReturnPrice_list['eva_total_value'], 2) : ""; $propertyDetails[$k]['eva_net_value'] = !empty($ReturnPrice_list['eva_net_value']) ? number_format($ReturnPrice_list['eva_net_value'], 2) : ""; $propertyDetails[$k]['eva_net_value2'] = !empty($ReturnPrice_list['eva_net_value2']) ? number_format($ReturnPrice_list['eva_net_value2'], 2) : ""; } } $list['signature_status_name'] = ($list['seal_status'] == 1) ? "未签章" : "已签章"; $list['full_estate_name_str'] = implode("/", array_column($propertyDetails, 'property_full_name')); $list['city_str'] = implode("/", array_unique(array_column($propertyDetails, 'city'))); $list['size_str'] = implode("/", array_column($propertyDetails, 'size')); $list['assessment_price_str'] = implode("/", array_column($propertyDetails, 'eva_unit_price')); $list['assessment_all_value_str'] = implode("/", array_column($propertyDetails, 'eva_total_value')); $list['appraiser_name_str'] = implode("/", array_unique(array_column($propertyDetails, 'appraiser_name'))); $list['full_estate_name_arr'] = array_column($propertyDetails, 'property_full_name'); $list['appraiser_ids'] = intval($list['appraiser_ids']); //物业位置图 $list['location_imgs_detail'] = ($list['loc_img_ids']) ? (new Attachment())->getUrls(explode(',', $list['loc_img_ids'])) : []; //估价对象照片 $list['survey_gallery_detail'] = ($list['appraisal_img_ids']) ? (new Attachment())->getUrls(explode(',', $list['appraisal_img_ids'])) : []; $list['assessment_eva_net_value_str'] = implode("/", array_column($propertyDetails, 'eva_net_value'));//评估净值 $list['assessment_eva_net_value2_str'] = implode("/", array_column($propertyDetails, 'eva_net_value2'));//评估净值2 } else { return $this->buildFailed("未查的数据"); } //估价师列表 $Valuerlist = $Valuer->field('name,autograph,id,visible')->where('status', 1)->select(); if (!empty($Valuerlist)) { foreach ($Valuerlist as $kr => $vr) { $flag = $this->isSignAppraiser();//$this->isVisible($vr['visible']); if (!$flag) { unset($Valuerlist[$kr]); } else { $files = $Attachment->getUrl($vr['autograph']); $Valuerlist[$kr]['url'] = $files['url']; if ($vr['id'] == $list['appraiser_ids']) { $Valuerlist[$kr]['is_status'] = true; } else { $Valuerlist[$kr]['is_status'] = false; } } } } //签章历史 $SignatureRecordlist = $SignatureRecord->where("quot_id", $id) ->field("name,create_time,type,user_name") ->select(); if (!empty($SignatureRecordlist)) { foreach ($SignatureRecordlist as $kt => $vt) { $SignatureRecordlist[$kt]['create_time'] = date("Y-m-d H:i:s", $vt['create_time']); } } $date['list'] = $list; $date['Valuerlist'] = $Valuerlist; //估价师列表 $date['SignatureRecordlist'] = $SignatureRecordlist; //签章历史 return $this->buildSuccess($date); } private function isVisible($visible) { $flag = false; $visible_arr = explode(',', $visible); foreach ($visible_arr as $key => $value) { if ($value == $this->userInfo['user_id']) { $flag = true; break; } } return $flag; } /** * 签章管理 提交 * @author cavan * */ public function SignatureSave() { $id = $this->request->post('id', '', 'trim'); $valuer_id = $this->request->post('appraiser_ids', '', 'trim'); $loc_img_ids = $this->request->post('loc_img_ids', '', 'trim'); //物业位置图 $appraisal_img_ids = $this->request->post('appraisal_img_ids', '', 'trim'); //估价对象照片 if (!$id) { return $this->buildFailed("缺少参数id"); } if (!$valuer_id) { return $this->buildFailed("缺少估价师信息"); } $Inquiry = new Inquiry(); $inquiryInfo = $Inquiry->where("id", $id)->field("id,bank_id,is_auto,estimate_status,branchCom_id")->find(); if (empty($inquiryInfo)) { return $this->buildFailed("未查到询价id:" . $id . "的数据"); } // 回价是否经过审核 if ($inquiryInfo['estimate_status'] != 4) { return $this->buildFailed("请审核预估后再签章!"); } $SignatureRecord = new SignatureRecord(); //签章记录表 // 产生预估号 // $estimated_no = $this->GenerateEstimateNo($id); //$inquiryInfo = $Inquiry->where("id",$id)->find(); $estimated_bank_no = ''; // 建设银行的特殊处理 // if ($inquiryInfo['bank_id'] == 777) { //// if($inquiryInfo['type']==1){ //// $estimated_bank_no = '002'.$year.$str.'1'; //// }elseif($inquiryInfo['type']==2){ //// $estimated_bank_no = '002'.$year.$str.'2'; //// } // if ($inquiryInfo['eva_purpose'] == '抵押贷款(云)') { // $year = date("Y", time()); // // $keyword_code = '160103' . date('Ymd'); // $code = $Inquiry->where("estimated_bank_no", "like", "%{$keyword_code}%")->order("estimated_bank_no", "desc")->value("estimated_bank_no"); // if ($code) { // $str = substr($code, 6); // $str += 1; // $estimated_bank_no = '160103' . $str; // } else { // $estimated_bank_no = '160103' . date('Ymd') . '0001'; // } // } elseif ($inquiryInfo['eva_purpose'] == '二手房按揭贷款') { // $str = substr_replace($str, '', 4, 2); // $estimated_bank_no = '160101' . $year . $str . '1'; // } // } // $update_data['estimated_no'] = $estimated_no; // $update_data['estimated_bank_no'] = $estimated_bank_no; $update_data['status'] = 12; $update_data['estimate_status'] = 5; $update_data['seal_status'] = 2; $update_data['appraiser_ids'] = $valuer_id; $update_data['update_time'] = date("Y-m-d H:i:s", time()); $update_data['seal_time'] = date("Y-m-d H:i:s", time()); $update_data['loc_img_ids'] = $loc_img_ids ? implode(',', $loc_img_ids) : ''; $update_data['appraisal_img_ids'] = $appraisal_img_ids ? implode(',', $appraisal_img_ids) : ''; $Valuer = new Valuer(); $re = $Inquiry->where("id", $id)->update($update_data); if ($re) { if (!empty($valuer_id)) { $insert_data = array(); $insert_data['quot_id'] = $id; $insert_data['name'] = $Valuer->where("id", $valuer_id)->value("name"); $insert_data['type'] = 1; $insert_data['user_id'] = $this->userInfo['user_id']; $insert_data['user_name'] = $this->userInfo['user_name']; $insert_data['create_time'] = time(); $SignatureRecord->insertGetId($insert_data); } } else { return $this->buildFailed("提交失败"); } // $inquiryInfo = $Inquiry->where("id",$id)->find(); // 2021年6月自动估价系统重新开发重写 // if ($inquiryInfo['is_auto'] == 1) { // $data = [ // 'order_no' => $inquiryInfo['order_no'], // 'estimates_url' => !empty($inquiryInfo['estimated_no']) ? env('uploadFile.evaluate_host_url') . '/admin/Pending/EstimateSheetTemplate?estimated_no=' . $estimated_no . '&branchCom_id=' . $inquiryInfo['branchCom_id'] : '', // 'estimates_no' => !empty($inquiryInfo['estimated_no']) ? $estimated_no : '', // ]; // $this->updEvaluateSignature($data); // } // return $this->buildSuccess($estimated_no); return $this->buildSuccess(); } /** * 取消签章 提交 * @author cavan * */ public function CancelSignature() { $id = $this->request->post('id', '', 'trim'); if (!$id) { return $this->buildFailed("缺少参数id"); } $Inquiry = new Inquiry(); $inquiryInfo = $Inquiry->where("id", $id)->find(); if (empty($inquiryInfo)) { return $this->buildFailed("未查到询价id:" . $id . "的数据"); } // 回价是否经过审核 if ($inquiryInfo['estimate_status'] != 5 && $inquiryInfo['seal_status'] != 2) { return $this->buildFailed("当前询价单未签章,无法取消签章!"); } $update_data['status'] = 11; $update_data['estimate_status'] = 4; $update_data['seal_status'] = 1; $update_data['appraiser_ids'] = NULL; $update_data['update_time'] = date("Y-m-d H:i:s", time()); $update_data['seal_time'] = NULL; $update_data['loc_img_ids'] = NULL; $update_data['appraisal_img_ids'] = NULL; $re = $Inquiry->where("id", $id)->update($update_data); if (!$re) { return $this->buildFailed("提交失败"); } return $this->buildSuccess(); } /** * 签章管理 提交 * @author cavan * */ public function SignatureSave_old() { $id = $this->request->post('id', '', 'trim'); $valuer_id = $this->request->post('appraiser_ids', '', 'trim'); $loc_img_ids = $this->request->post('loc_img_ids', '', 'trim'); //物业位置图 $appraisal_img_ids = $this->request->post('appraisal_img_ids', '', 'trim'); //估价对象照片 if (!$id) { return $this->buildFailed("缺少参数id"); } if (!$valuer_id) { return $this->buildFailed("缺少估价师信息"); } $Inquiry = new Inquiry(); $SignatureRecord = new SignatureRecord(); //签章记录表 $Valuer = new Valuer(); //估价师表 $G_COMPANY_SN = "GZ"; // 公司简称 $year = date("Y", time()); $md = date("md", time()); $m = date("m", time()); $keyword = $year . "-" . $G_COMPANY_SN . $md; $estimated_no = $this->GenerateEstimateNo($id); $inquiryInfo = $Inquiry->where("id", $id)->find(); $estimated_bank_no = ''; /* $estimated_no = $Inquiry->where("estimated_no","like","%{$keyword}%")->order("estimated_no","desc")->value("estimated_no"); if($estimated_no){ if($m > 9){ $str = substr($estimated_no,7); $str += 1; $estimated_no = $year."-".$G_COMPANY_SN.$str; }else{ $str = substr($estimated_no,8); $str += 1; $estimated_no = $year."-".$G_COMPANY_SN."0".$str; $str = '0'.$str; } }else{ $estimated_no = $keyword."00001"; $str = $md."00001"; } */ if ($inquiryInfo['bank_id'] == 777) { // if($inquiryInfo['type']==1){ // $estimated_bank_no = '002'.$year.$str.'1'; // }elseif($inquiryInfo['type']==2){ // $estimated_bank_no = '002'.$year.$str.'2'; // } if ($inquiryInfo['eva_purpose'] == '抵押贷款(云)') { $keyword_code = '160103' . date('Ymd'); $code = $Inquiry->where("estimated_bank_no", "like", "%{$keyword_code}%")->order("estimated_bank_no", "desc")->value("estimated_bank_no"); if ($code) { $str = substr($code, 6); $str += 1; $estimated_bank_no = '160103' . $str; } else { $estimated_bank_no = '160103' . date('Ymd') . '0001'; } } elseif ($inquiryInfo['eva_purpose'] == '二手房按揭贷款') { $str = substr_replace($str, '', 4, 2); $estimated_bank_no = '160101' . $year . $str . '1'; } } $update_data['estimated_no'] = $estimated_no; $update_data['estimated_bank_no'] = $estimated_bank_no; $update_data['seal_status'] = 2; $update_data['appraiser_ids'] = $valuer_id; $update_data['update_time'] = date("Y-m-d H:i:s", time()); $update_data['seal_time'] = date("Y-m-d H:i:s", time()); $update_data['loc_img_ids'] = $loc_img_ids ? implode(',', $loc_img_ids) : ''; $update_data['appraisal_img_ids'] = $appraisal_img_ids ? implode(',', $appraisal_img_ids) : ''; $re = $Inquiry->where("id", $id)->update($update_data); if ($re) { if (!empty($valuer_id)) { $insert_data = array(); $insert_data['quot_id'] = $id; $insert_data['name'] = $Valuer->where("id", $valuer_id)->value("name"); $insert_data['type'] = 1; $insert_data['user_id'] = $this->userInfo['user_id']; $insert_data['user_name'] = $this->userInfo['user_name']; $insert_data['create_time'] = time(); $SignatureRecord->insertGetId($insert_data); } } else { return $this->buildFailed("提交失败"); } // $inquiryInfo = $Inquiry->where("id",$id)->find(); // 2021年6月自动估价系统重新开发重写 if ($inquiryInfo['is_auto'] == 1) { $data = [ 'order_no' => $inquiryInfo['order_no'], 'estimates_url' => !empty($inquiryInfo['estimated_no']) ? env('uploadFile.evaluate_host_url') . '/admin/Pending/EstimateSheetTemplate?estimated_no=' . $estimated_no : '', 'estimates_no' => !empty($inquiryInfo['estimated_no']) ? $estimated_no : '', ]; $this->updEvaluateSignature($data); } return $this->buildSuccess($estimated_no); } /** * 签章管理 取消签章 * @author zcx * */ /*public function CancelSignature() { $id = $this->request->post('id', '', 'trim'); if (!$id) { return $this->buildFailed("缺少参数id"); } $Inquiry = new Inquiry(); $SignatureRecord = new SignatureRecord(); //签章记录表 $update_data['estimated_no'] = ""; $update_data['seal_status'] = 1; $update_data['appraiser_ids'] = ""; $update_data['update_time'] = date("Y-m-d H:i:s", time()); $update_data['seal_time'] = null; $re = $Inquiry->where("id", $id)->update($update_data); if ($re) { $valuer_name = $SignatureRecord->where("quot_id", $id)->order('id', 'desc')->field('name')->find(); $insert_data = array(); $insert_data['quot_id'] = $id; $insert_data['name'] = $valuer_name['name']; $insert_data['type'] = 2; $insert_data['user_id'] = $this->userInfo['user_id']; $insert_data['user_name'] = $this->userInfo['user_name']; $insert_data['create_time'] = time(); $SignatureRecord->insertGetId($insert_data); } else { return $this->buildFailed("取消签章失败"); } return $this->buildSuccess(); }*/ /** * 请求审核预估单 */ // public function RequestEstimateAudit() // { // $id = $this->request->post('id', '', 'trim'); // if (!$id) { // return $this->buildFailed("缺少参数询价id"); // } // // // 如果角色不是预估审核员,则不能审核 //// if (!$this->isRole(self::RoleCode_ESTIMATE_APPROVAL)) { //// return $this->buildFailed("您不是预估审核员,不能进行审核"); //// } // // /* // 已改为先审核再签章,所以注释掉 // //检查Inquiry表的Seal_status字段是否0,如果为0,则提示“请先完成签章操作" // $Inquiry = new Inquiry(); // $inquiryInfo = $Inquiry->where("id",$id)->find(); // if($inquiryInfo['seal_status'] != 2){ // return $this->buildFailed("请先完成签章操作"); // }*/ // // // 更新签章状态为1 // $Inquiry = new Inquiry(); // // $inquiryInfo = $Inquiry->where("id", $id)->find(); // if (empty($inquiryInfo)) { // return $this->buildFailed("询价记录不存在"); // } // // // 更新预估状态: 0-未审核,预估 1-已审核预估 [v2.0] // $update_data['estimate_audit_status'] = 1; // // // 更新预估审核日期[v2.0] // $update_data['estimate_audit1_date'] = date("Y-m-d H:i:s", time()); // $update_data['estimate_audit_user_id'] = $this->userInfo['user_id']; // $update_data['estimate_audit_user_name'] = $this->userInfo['user_name']; // // if (empty($inquiryInfo['estimated_no'])) { // $estimated_no = ''; // $generate_estimated_info = Tools::generateNo($id, Tools::GENERATE_TYPE_ESTIMATE); // if ($generate_estimated_info['code'] == 0) { // $estimated_no = $generate_estimated_info['data']; // } // $update_data['estimated_no'] = $estimated_no; // 生成预估号 // /*$estimate_qrcode_unique_key = md5(uniqid(md5(microtime(true)), true)); // $estimated_qrcode_content = env("uploadFile.qrcode_url") . "/index.php/admin/Pending/getAnticounterfeitPage?quot_id=" . // $id . '&key=' . $estimate_qrcode_unique_key; // $qrcode_oss_url = Tools::createQRCode($estimated_qrcode_content); // if (!empty($qrcode_oss_url)) { // $update_data['estimated_qrcode_url'] = $qrcode_oss_url; // } // $update_data['estimate_qrcode_unique_key'] = $estimate_qrcode_unique_key; // $update_data['seal_status'] = 2; // $update_data['seal_time'] = date('Y-m-d H:i:s');*/ // } // $estimate_qrcode_unique_key = md5(uniqid()); // $estimated_qrcode_content = env("uploadFile.qrcode_url") . "/index.php/admin/Pending/getAnticounterfeitPage?quot_id=" . // $id . '&key=' . $estimate_qrcode_unique_key; // \think\facade\Log::error('estimated_qrcode_content:'. $estimated_qrcode_content); // $qrcode_oss_url = Tools::createQRCode($estimated_qrcode_content); // if (!empty($qrcode_oss_url)) { // $update_data['estimated_qrcode_url'] = $qrcode_oss_url; // } // $update_data['estimate_qrcode_unique_key'] = $estimate_qrcode_unique_key; // $update_data['seal_status'] = 2; // $update_data['seal_time'] = date('Y-m-d H:i:s'); // // $re = $Inquiry->where("id", $id)->update($update_data); // // if (!$re) { // return $this->buildFailed("签章失败"); // } // // return $this->buildSuccess(); // } /** * 申请预估制作 */ public function applyEstimateMake() { $id = $this->request->post('id', '', 'trim'); if (!$id) { return $this->buildFailed("缺少参数询价id"); } // 更新签章状态为1 $Inquiry = new Inquiry(); $inquiryInfo = $Inquiry->where("id", $id)->find(); if (empty($inquiryInfo)) { return $this->buildFailed("询价记录不存在"); } $update_data['status'] = 9; $update_data['apply_estimate_make_status'] = 1; $update_data['apply_estimate_make_datetime'] = date("Y-m-d H:i:s", time()); $update_data['apply_estimate_make_user_id'] = $this->userInfo['user_id']; $update_data['apply_estimate_make_user_name'] = $this->userInfo['user_name']; $update_data['estimate_status'] = 1; // if (empty($inquiryInfo['estimated_no'])) { // $estimated_no = ''; // $generate_estimated_info = Tools::generateNo($id, Tools::GENERATE_TYPE_ESTIMATE); // if ($generate_estimated_info['code'] == 0) { // $estimated_no = $generate_estimated_info['data']; // } // $update_data['estimated_no'] = $estimated_no; // 生成预估号 // /*$estimate_qrcode_unique_key = md5(uniqid(md5(microtime(true)), true)); // $estimated_qrcode_content = env("uploadFile.qrcode_url") . "/index.php/admin/Pending/getAnticounterfeitPage?quot_id=" . // $id . '&key=' . $estimate_qrcode_unique_key; // $qrcode_oss_url = Tools::createQRCode($estimated_qrcode_content); // if (!empty($qrcode_oss_url)) { // $update_data['estimated_qrcode_url'] = $qrcode_oss_url; // } // $update_data['estimate_qrcode_unique_key'] = $estimate_qrcode_unique_key; // $update_data['seal_status'] = 2; // $update_data['seal_time'] = date('Y-m-d H:i:s');*/ // } // $estimate_qrcode_unique_key = md5(uniqid()); // $estimated_qrcode_content = env("uploadFile.qrcode_url") . "/index.php/admin/Pending/getAnticounterfeitPage?quot_id=" . // $id . '&key=' . $estimate_qrcode_unique_key; // $qrcode_oss_url = Tools::createQRCode($estimated_qrcode_content); // if (!empty($qrcode_oss_url)) { // $update_data['estimated_qrcode_url'] = $qrcode_oss_url; // } // $update_data['estimate_qrcode_unique_key'] = $estimate_qrcode_unique_key; // $update_data['seal_status'] = 2; // $update_data['seal_time'] = date('Y-m-d H:i:s'); $re = $Inquiry->where("id", $id)->update($update_data); if (!$re) { return $this->buildFailed("确认回价失败"); } return $this->buildSuccess(); } /** * 请求取消审核预估单 */ // public function CancelEstimateAudit() // { // $id = $this->request->post('id', '', 'trim'); // if (!$id) { // return $this->buildFailed("缺少参数询价id"); // } // // // 如果角色不是预估审核员,则不能审核 //// if (!$this->isRole(self::RoleCode_ESTIMATE_APPROVAL)) { //// return $this->buildFailed("您不是预估审核员,不能进行审核"); //// } // // // 检查Inquiry表的estimate_audit_status字段是否0,如果为0,则提示“您暂时还没有审核,无法取消审核" // $Inquiry = new Inquiry(); // $inquiryInfo = $Inquiry->where("id", $id)->find(); // if ($inquiryInfo['estimate_audit_status'] != 1) { // return $this->buildFailed("您暂时还没有审核,无法取消审核"); // } // // // 更新签章状态为1 // $Inquiry = new Inquiry(); // // // 更新预估状态: 0-未审核,预估 1-已审核预估 [v2.0] //// $update_data['estimate_audit_status'] = 0; // $update_data['estimate_audit_status'] = NULL; // // // 更新预估审核日期[v2.0] // $update_data['estimate_audit1_date'] = NULL; // $update_data['estimate_audit_user_id'] = NULL; // $update_data['estimate_audit_user_name'] = NULL; // $update_data['estimate_qrcode_unique_key'] = NULL; // $update_data['seal_status'] = 1; // $update_data['seal_time'] = NULL; // $update_data['estimated_no'] = NULL; // 2025-05-23 annnj 修改 // // // $re = $Inquiry->where("id", $id)->update($update_data); // // if (!$re) { // return $this->buildFailed("取消签章失败"); // } // // return $this->buildSuccess(); // } // 作废防伪码 public function cancelAntiCounterfeitingCode() { $id = $this->request->post('id', '', 'trim'); if (!$id) { return $this->buildFailed("缺少参数询价id"); } $Inquiry = new Inquiry(); $inquiryInfo = $Inquiry->where("id", $id)->find(); if ($inquiryInfo['estimate_audit_status'] != 1) { return $this->buildFailed("防伪码未生成,无法作废"); } // 更新签章状态为1 $Inquiry = new Inquiry(); // 更新预估状态: 0-未审核,预估 1-已审核预估 [v2.0] $update_data['estimate_audit_status'] = NULL; // 更新预估审核日期[v2.0] $update_data['estimate_audit1_date'] = NULL; $update_data['estimate_audit_user_id'] = NULL; $update_data['estimate_audit_user_name'] = NULL; $update_data['estimate_qrcode_unique_key'] = NULL; $update_data['seal_status'] = 1; $update_data['seal_time'] = NULL; // $update_data['estimated_no'] = NULL; // 2025-05-23 annnj 修改 $re = $Inquiry->where("id", $id)->update($update_data); if (!$re) { return $this->buildFailed("取消签章失败"); } return $this->buildSuccess(); } /** * 预估单 * @author zcx * */ public function EstimateSheet() { $id = $this->request->post('id', '', 'trim'); $bank = $this->request->post('bank', '', 'trim'); if (!$id) { return $this->buildFailed("缺少询价表id"); } if (!$bank) { return $this->buildFailed("缺少银行名称"); } $Inquiry = new Inquiry(); $Bank = new Bank(); $Attachment = new Attachment(); //获取图片信息 $type = $Inquiry->where("id", $id)->value("type"); if ($type == 1) { $file_id = $Bank->where("type", 1)->where("name", $bank)->where("template_status", 1)->where("status", 1)->value("house_attachment_id"); } else { $file_id = $Bank->where("type", 1)->where("name", $bank)->where("template_status", 1)->where("status", 1)->value("business_attachment_id"); } if ($file_id) { $list = $Attachment->getUrl($file_id); } else { $list = array(); } return $this->buildSuccess($list); } /** * @api 调价列表 * * @author zcx */ public function ModifyPriceList() { $type = $this->request->post('type', '', 'trim'); //查询类型 1、住宅,2、商业 $team_type = $this->request->post('team_type', '', 'trim'); //住宅项目类型 1、加急,2、拓展,3、特殊,4、工行,5、其它,6、自动估价 if ($type && $type == 1 && !$team_type) { return $this->buildFailed("缺少参数住宅项目类型team_type"); } $userId = $this->userInfo['user_id']; $data = $this->request->post(); if ($team_type == 1) { $role = 'Urgent_project_CSPG'; } else if ($team_type == 2) { $role = 'Development_project_CSPG'; } else if ($team_type == 3) { $role = 'Special_project_CSPG'; } else if ($team_type == 5) { $role = 'Other_project_CSPG'; } if ($team_type && $team_type != 4 && $team_type != 6) { $e2 = controller('User'); $uid_arr = $e2->getRole_copy($role); //税费项目 if (!empty($uid_arr)) { $uids = implode(",", array_column($uid_arr, 'oid')); } else { $uids = ""; } } if ($type == 1 && $team_type == 4) { $data['bank_id'] = 1; } if ($type == 1 && $team_type == 6) { $data['is_auto'] = 1; } if ($type) { $data['diff_flag'] = 1; //差异在0.1以下包含0.1 } else { $data['diff_flag'] = 2; //差异在0.1以上 } $data['variance_ratio'] = "0.1"; //差异 if ($team_type && $team_type != 4 && $team_type != 6) { $data['user_id'] = $uids; } $data['adjust_status'] = 1; $inquiry = new Inquiry(); $res = $inquiry->getNormalModifyList($userId, $this->getPage(), $data); return $this->buildSuccess($res); } /** * 计算贷款 * */ public function CalculateLoan() { $id = $this->request->post('id', '', 'trim'); //物业表id $eva_total_value = $this->request->post('eva_total_value', '', 'trim'); //评估总价 $eva_net_value = $this->request->post('eva_net_value', '', 'trim'); //评估净值 $eva_net_value2 = $this->request->post('eva_net_value2', '', 'trim'); //评估净值2 $loan_ratio = $this->request->post('loan_ratio', '', 'trim'); //贷款成数 if (!$eva_total_value) { return $this->buildFailed("缺少评估总价"); } if (!$eva_net_value && $eva_net_value === "") { return $this->buildFailed("缺少评估净值"); } if ($eva_net_value2 && $eva_net_value2 === "") { return $this->buildFailed("缺少评估净值2"); } $Property_cert_info = new Property_cert_info(); $Taxation = new Taxation(); if (!$loan_ratio) { $loan_ratio = 0.7; } //主表信息 $list = $Property_cert_info->alias("it") ->join("pg_inquiry i", "i.id = it.quot_id") ->where("it.id", $id) ->field("i.bank_name,i.bank_id,i.product_id,i.type,i.bank_branch_name,i.bank_branch_id,i.eva_purpose,it.ownership_type,it.size,it.is_tran_tax_free,it.reg_price,it.usage,i.eva_purpose") ->find(); $tlist = $Taxation->where(["bank_id" => $list['bank_id'], "branch_id" => $list['bank_branch_id'], "product_name" => $list['eva_purpose'], "type" => $list['type'], "state" => 1])->field("id,eva_net_value,eva_net_value2,loan_percentage,net_worth_one_percentage,net_worth_tow_percentage")->find(); if (empty($tlist)) { return $this->buildFailed("该银行尚未设置税费规则"); } // $loan_count_one = (!empty($tlist['net_worth_one_percentage']) && $tlist['net_worth_one_percentage'] > 0)?$tlist['net_worth_one_percentage']:$loan_ratio; // $loan_count2 = (!empty($tlist['net_worth_tow_percentage']) && $tlist['net_worth_tow_percentage'] > 0)?$tlist['net_worth_tow_percentage']:$loan_ratio; $loan_count_one = $loan_ratio; $loan_count2 = $loan_ratio; $eva_total_value = floatval($eva_total_value); $loan_count_one = floatval($loan_count_one); $loan_count2 = floatval($loan_count2); $info = array(); $info['gross_value_temporary'] = round($eva_total_value * $loan_ratio); $info['net_worth_temporary'] = round($eva_net_value * $loan_count_one); $info['net_worth_tow_temporary'] = round($eva_net_value2 * $loan_count2); $info['ref_net_worth_temporary'] = round($eva_net_value2 * $loan_count2);// 参考净值 return $this->buildSuccess($info); } /** * 替换说明内容 * * data 税费数组 * $inquiry_data 该询价InquiryDetail对应的询价表的数据 */ public function explain_replace($id, $json_data, $tlist, $data, $ManuTotalamo, $list, $type, $inquiry_data) { // 物业信息及最新回价信息 if (empty($json_data)) { $json_data = Db::name('property_cert_info') ->where('quot_id=' . $list['id']) ->select(); foreach ($json_data as $jd_k => $jd_v) { $return_price_data = Db::name('return_price') ->where('property_cert_info_id=' . $jd_v['id']) ->order('create_time', 'desc') ->find(); if ($return_price_data) { foreach ($return_price_data as $r_k => $r_v) { if ($r_k == 'id') { $jd_v['rid'] = $r_v; } else { $jd_v[$r_k] = $r_v; } } $json_data[$jd_k] = $jd_v; } else { $json_data = []; break; } } } $TaxationAuxiliary = new TaxationAuxiliary(); //统计 $net_worth_one_arr = !empty($tlist['eva_net_value']) ? explode(",", $tlist['eva_net_value']) : ""; $net_worth_tow_arr = !empty($tlist['eva_net_value2']) ? explode(",", $tlist['eva_net_value2']) : ""; $eva_net_value = $eva_net_value2 = 0; //if($type == 1) { if ($net_worth_one_arr) { foreach ($net_worth_one_arr as $vn) { $t_key = $TaxationAuxiliary->where("id", $vn)->value("key"); if ($t_key == 'personal_income_tax') { $t_key = 'personal_income_tax_copy'; } $eva_net_value += (float)$data[$t_key]; } } if ($net_worth_tow_arr) { foreach ($net_worth_tow_arr as $va) { $t_key = $TaxationAuxiliary->where("id", $va)->value("key"); if ($t_key == 'personal_income_tax') { $t_key = 'personal_income_tax_copy'; } $eva_net_value2 += (float)$data[$t_key]; } } $added_tax = $edu_surcharge = $urban_construction_tax = $net_worth_one_all = $net_worth_tow_all = $individual_income_tax_all = 0; if (!empty($json_data)) { foreach ($json_data as $k => $v) { if ($v['id'] != $id) { $added_tax += (float)$v['added_tax']; $edu_surcharge += (float)$v['edu_surcharge']; $urban_construction_tax += (float)$v['urban_construction_tax']; $net_worth_one_all += (float)$v['total_taxes1']; $net_worth_tow_all += (float)$v['total_taxes2']; $individual_income_tax_all += (float)$v['personal_income_tax_copy']; $ManuTotalamo += (float)$v['eva_total_value']; } else { $added_tax += (float)$data['added_tax']; $edu_surcharge += (float)$data['edu_surcharge']; $urban_construction_tax += (float)$data['urban_construction_tax']; $net_worth_one_all += $eva_net_value; $net_worth_tow_all += $eva_net_value2; $individual_income_tax_all += (float)$data['personal_income_tax_copy']; } } } $personal_income_tax = $individual_income_tax_all; $estimated_tax = $net_worth_one_all + $net_worth_tow_all + $individual_income_tax_all; $estimated_tax_ceb = $net_worth_one_all + $net_worth_tow_all + $individual_income_tax_all + $added_tax; // 光大抵押贷款预估模板修改,2022-04-24 $ms_estimated_tax = $net_worth_one_all + $net_worth_tow_all + $individual_income_tax_all + $added_tax + $edu_surcharge + $urban_construction_tax; $net_mortgage_value = $ManuTotalamo - $estimated_tax; $net_mortgage_value_ceb = $ManuTotalamo - $estimated_tax_ceb; // 光大抵押贷款预估模板修改,2022-04-24 $ms_net_mortgage_value = $ManuTotalamo - $ms_estimated_tax; //}else if($type == 2){ $personal_income_tax_copy = $data['personal_income_tax_copy']; $land_value_added_tax_copy = $data['land_value_added_tax_copy']; //} $exploin = Db::name("estimate")->where(["bank_id" => $list["bank_id"], "product_name" => $list["eva_purpose"], "type" => $list["type"]])->value("estimated_desc"); if ($exploin) { if ($type == 1) { if (strpos($exploin, '深建房产[2021]2号') !== false) { $string_arr = explode("。", $exploin); if (!empty($string_arr)) { $array = explode("(深建房产[2021]2号)", $string_arr[0]); if (count($json_data) > 1) { $exploin_s = "(深建房产[2021]2号)的"; foreach ($json_data as $k_s => $v_s) { $exploin_s .= "估价对象" . $v_s['property_name'] . "的二手住房成交参考单价为:" . round($v_s['guide_price']) . "元/平方米,参考总值" . round($v_s['guide_price'] * $v_s['area']) . "元,"; } $exploin_s .= "提请评估报告使用方注意遵守相关政策,正确使用本评估报告。"; } elseif (count($json_data) == 1) { $exploin_s = "(深建房产[2021]2号)的估价对象" . $json_data[0]['property_name'] . "的二手住房成交参考单价为:" . round($json_data[0]['guide_price']) . "元/平方米,参考总值" . round($json_data[0]['guide_price'] * $json_data[0]['area']) . "元,提请评估报告使用方注意遵守相关政策,正确使用本评估报告。"; } else { $exploin_s = "(深建房产[2021]2号)的估价对象二手住房成交参考单价为:****元/平方米,参考总值****元,提请评估报告使用方注意遵守相关政策,正确使用本评估报告。"; } unset($string_arr[0]); $array_s = implode("。", $string_arr); $exploin = $array[0] . $exploin_s . $array_s; } } if ($list["bank_id"] == 16 && $list["eva_purpose"] == '二手房按揭贷款') { $str = explode("增值税", $exploin); if (!empty($str)) { $str_arr = explode("。", $str[1]); unset($str_arr[0]); $str_s = implode("。", $str_arr); $exploin = $str[0] . "增值税" . $added_tax . "元,教育费附加税" . $edu_surcharge . "元,城市建设维护税" . $urban_construction_tax . "元,个人所得税" . $personal_income_tax . "元,若正常计征,则预计税费为" . $ms_estimated_tax . "元,抵押净值为" . round($ms_net_mortgage_value) . "元。" . $str_s; } } elseif ($list["bank_id"] == 15 && $list["eva_purpose"] == '抵押贷款') { $str = explode("个人所得税", $exploin); if (!empty($str)) { $str_arr = explode("。", $str[1]); unset($str_arr[0]); $str_s = implode("。", $str_arr); $exploin = $str[0] . "增值税" . $added_tax . "元,个人所得税" . $personal_income_tax . "元,若正常计征,则预计税费为" . $estimated_tax_ceb . "元,抵押净值为" . round($net_mortgage_value_ceb) . "元。" . $str_s; } } elseif ($inquiry_data["product_id"] == 110) { // 针对 光大银行-住宅-抵押贷款 这个产品 ID=110 的输出 $str = explode("个人所得税", $exploin); if (!empty($str)) { $str_arr = explode("。", $str[1]); unset($str_arr[0]); $str_s = implode("。", $str_arr); $exploin = $str[0] . "增值税" . $added_tax . "元,个人所得税" . $personal_income_tax . "元,若正常计征,则预计税费为" . ($added_tax + $personal_income_tax + $net_worth_one_all) . "元,抵押净值为" . round($ManuTotalamo - $personal_income_tax - $added_tax - $net_worth_one_all) . "元。" . $str_s; } //} elseif($list["bank_id"] == 1129 && $list["eva_purpose"]=='抵押贷款(普惠)') { // 针对 中信银行-住宅-抵押贷款(个贷) } elseif ($list["bank_id"] == 1129) { // 针对 中信银行 $str = explode("其中所得税为", $exploin); if (!empty($str)) { $str_arr = explode("。", $str[1]); unset($str_arr[0]); $str_s = implode("。", $str_arr); $exploin = $str[0] . "其中所得税为" . $personal_income_tax . "元,土地增值税为0元。" . $str_s; } } elseif ($list["bank_id"] != 1129) { $str = explode("个人所得税", $exploin); if (!empty($str)) { $str_arr = explode("。", $str[1]); unset($str_arr[0]); $str_s = implode("。", $str_arr); $exploin = $str[0] . "个人所得税" . $personal_income_tax . "元,若正常计征,则预计税费为" . $estimated_tax . "元,抵押净值为" . round($net_mortgage_value) . "元。" . $str_s; } } } else if ($type == 2) { //if($list["bank_id"] == 1129 && $list["eva_purpose"]=='抵押贷款(普惠)') { // 针对 中信银行-商业-抵押贷款(个贷) if ($list["bank_id"] == 1129) { // 针对中信银行 $str = explode("其中所得税为", $exploin); if (!empty($str)) { $str_arr = explode("。", $str[1]); unset($str_arr[0]); $str_s = implode("。", $str_arr); $exploin = $str[0] . "其中所得税为" . $personal_income_tax_copy . "元,土地增值税为" . $land_value_added_tax_copy . "元。" . $str_s; } } elseif ($list["bank_id"] == 780) { $str = explode("所得税", $exploin); if (!empty($str)) { $str_arr = explode("。", $str[1]); unset($str_arr[0]); $str_s = implode("。", $str_arr); $exploin = $str[0] . "所得税" . $personal_income_tax_copy . "元,若正常计征,则预计税费为" . $ms_estimated_tax . "元,抵押净值为" . round($ms_net_mortgage_value) . "元。" . $str_s; } } elseif ($list["bank_id"] != 1129) { $str = explode("个人所得税", $exploin); if (!empty($str)) { $str_arr = explode("。", $str[1]); unset($str_arr[0]); $str_s = implode("。", $str_arr); $exploin = $str[0] . "个人所得税" . $personal_income_tax_copy . "元、土地增值税" . $land_value_added_tax_copy . "元。" . $str_s; } } } } else { $exploin = ""; } return $exploin; } public function explain_replace_guide($id, $json_data, $tlist, $data, $ManuTotalamo, $list, $type) { // 物业信息及最新回价信息 if (empty($json_data)) { $json_data = Db::name('property_cert_info') ->where('quot_id=' . $list['id']) ->select(); foreach ($json_data as $jd_k => $jd_v) { $return_price_data = Db::name('return_price') ->where('property_cert_info_id=' . $jd_v['id']) ->order('create_time', 'desc') ->find(); if ($return_price_data) { foreach ($return_price_data as $r_k => $r_v) { if ($r_k == 'id') { $jd_v['rid'] = $r_v; } else { $jd_v[$r_k] = $r_v; } } $json_data[$jd_k] = $jd_v; } else { $json_data = []; break; } } } $exploin = Db::name("estimate")->where(["bank_id" => $list["bank_id"], "product_name" => $list["eva_purpose"], "type" => $list["type"]])->value("estimated_desc"); if ($exploin) { if (strpos($exploin, '深建房产[2021]2号') !== false) { $string_arr = explode("。", $exploin); if (!empty($string_arr)) { $array = explode("(深建房产[2021]2号)", $string_arr[0]); if ($list["bank_id"] == 800 && $list["eva_purpose"] == '抵押贷款(普惠)') { if (count($json_data) > 1) { $exploin_s = "(深建房产[2021]2号)的"; foreach ($json_data as $k_s => $v_s) { $exploin_s .= "估价对象" . $v_s['property_name'] . "的二手住房成交参考单价为:" . round($v_s['guide_price']) . "元/平方米,参考总值" . round($v_s['guide_price'] * $v_s['area']) . "元,参考净值" . (round($v_s['guide_price'] * $v_s['area']) - round($v_s['total_guide_tax'])) . "元,"; } $exploin_s .= "提请评估报告使用方注意遵守相关政策,正确使用本评估报告。"; } elseif (count($json_data) == 1) { $exploin_s = "(深建房产[2021]2号)的估价对象" . $json_data[0]['property_name'] . "的二手住房成交参考单价为:" . round($json_data[0]['guide_price']) . "元/平方米,参考总值" . round($json_data[0]['guide_price'] * $json_data[0]['area']) . "元,参考净值" . (round($json_data[0]['guide_price'] * $json_data[0]['area']) - round($json_data[0]['total_guide_tax'])) . "元,提请评估报告使用方注意遵守相关政策,正确使用本评估报告。"; } else { $exploin_s = "(深建房产[2021]2号)的估价对象二手住房成交参考单价为:****元/平方米,参考总值****元,参考净值****元,提请评估报告使用方注意遵守相关政策,正确使用本评估报告。"; } } else { if (count($json_data) > 1) { $exploin_s = "(深建房产[2021]2号)的"; foreach ($json_data as $k_s => $v_s) { $exploin_s .= "估价对象" . $v_s['property_name'] . "的二手住房成交参考单价为:" . round($v_s['guide_price']) . "元/平方米,参考总值" . round($v_s['guide_price'] * $v_s['area']) . "元,"; } $exploin_s .= "提请评估报告使用方注意遵守相关政策,正确使用本评估报告。"; } elseif (count($json_data) == 1) { $exploin_s = "(深建房产[2021]2号)的估价对象" . $json_data[0]['property_name'] . "的二手住房成交参考单价为:" . round($json_data[0]['guide_price']) . "元/平方米,参考总值" . round($json_data[0]['guide_price'] * $json_data[0]['area']) . "元,提请评估报告使用方注意遵守相关政策,正确使用本评估报告。"; } else { $exploin_s = "(深建房产[2021]2号)的估价对象二手住房成交参考单价为:****元/平方米,参考总值****元,提请评估报告使用方注意遵守相关政策,正确使用本评估报告。"; } } unset($string_arr[0]); $array_s = implode("。", $string_arr); $exploin = $array[0] . $exploin_s . $array_s; } } } else { $exploin = ""; } return $exploin; } /*************************************************************预估单*******************************************************/ /** * 预估单模板 */ public function EstimateSheetTemplate() { $estimated_no = $this->request->get('estimated_no', '', 'trim'); $branchCom_id = $this->request->get('branchCom_id', '', 'trim'); if (empty($estimated_no)) { return $this->buildFailed("预估单号不能为空"); } if (empty($branchCom_id)) { return $this->buildFailed("业务归属不能为空"); } $Estimate = new Estimate(); $Inquiry = new Inquiry(); $Property_cert_info = new Property_cert_info(); $Attachment = new Attachment(); $basic = $Inquiry->where("estimated_no", $estimated_no) ->where('branchCom_id', $branchCom_id) ->field("id,user_name,buss_username,bank_id,bank_name,bank_branch_id,bank_branch_name,bank_sub_id,bank_sub_name,eva_purpose,product_id,loan_type,type,estimated_bank_no,estimated_no,seal_status,seal_time,appraiser_ids,estimated_desc,loc_img_ids,appraisal_img_ids,estimated_qrcode_url,estimate_audit_user_name") ->find(); if (empty($basic)) { return $this->buildFailed("未查得数据,请刷新后重试!"); } $full_name = Db::name('bank')->where('id', $basic['bank_id'])->value('full_name'); $basic['bank_name'] = $full_name; // 为了匹配原来的字段名 $basic['estimate_no'] = $basic['estimated_no']; $basic['estimate_code'] = $basic['estimated_bank_no']; $basic['evaluate_purpose'] = $basic['eva_purpose']; // $basic['signature_time'] = $basic['seal_time']; $basic['signature_time'] = !empty($basic['seal_time']) ? date("Y年m月d日", strtotime($basic['seal_time'])) : date('Y年m月d日'); // $info = $Property_cert_info->alias("a") // ->join("pg_return_price r","r.property_cert_info_id = a.id","left") // ->where("a.quot_id",$basic['id']) // ->order("r.create_time","desc") // ->field("a.*,r.eva_unit_price,r.eva_total_value,r.eva_total_value,r.eva_net_value2,r.corporate_income_tax,r.tran_service_fee,r.edu_surcharge,r.urban_construction_tax,r.deed_tax,r.stamp_duty,r.added_tax,r.land_value_added_tax,r.personal_income_tax,r.personal_income_tax_copy,r.auction_fee,r.total_taxes1,r.total_taxes2,r.loan_ratio,r.gross_value,r.eva_net_value,r.eva_net_value2,r.internal_remarks,r.external_remarks,r.pricing_remarks,r.appraiser_name") // ->group("r.property_cert_info_id") // ->select() // ->toArray(); // print_r($Property_cert_info->getLastSql());exit(); $info = $Property_cert_info->where('quot_id', $basic['id'])->select()->toArray(); $basic_signatrue_time = 0; if (!empty($info)) { foreach ($info as $r_key => $r_value) { $return_price_date = Db::name('return_price')->where('property_cert_info_id', $r_value['id'])->order('id', 'desc')->find(); if ($return_price_date) { // 选出最近一条询价回价记录的时间 if ($basic_signatrue_time < $return_price_date['create_time']) { $basic_signatrue_time = $return_price_date['create_time']; } $r_value['register_price'] = $r_value['reg_price'] != 1 ? $r_value['reg_price'] : 0; $r_value['market_price'] = $return_price_date['market_price']; $r_value['guide_price'] = $return_price_date['guide_price']; $r_value['assessment_price'] = $return_price_date['eva_unit_price']; $r_value['assessment_all_value'] = $return_price_date['eva_total_value']; $r_value['assessment_net_worth'] = $return_price_date['eva_net_value']; $r_value['assessment_net_worth_tow'] = $return_price_date['eva_net_value2']; $r_value['sales_tax'] = $return_price_date['corporate_income_tax']; $r_value['service_charge'] = $return_price_date['tran_service_fee']; $r_value['education_surcharges'] = $return_price_date['edu_surcharge']; $r_value['urban_construction_tax'] = $return_price_date['urban_construction_tax']; $r_value['deed_tax'] = $return_price_date['deed_tax']; $r_value['stamp_duty'] = $return_price_date['stamp_duty']; $r_value['added_tax'] = $return_price_date['added_tax']; $r_value['land_value_added_tax'] = $return_price_date['land_value_added_tax']; $r_value['individual_income_tax'] = $return_price_date['personal_income_tax']; $r_value['individual_income_tax_copy'] = $return_price_date['personal_income_tax_copy']; $r_value['auction_fee'] = $return_price_date['auction_fee']; $r_value['total_tax1'] = $return_price_date['total_taxes1']; $r_value['total_tax2'] = $return_price_date['total_taxes2']; $r_value['loan_count'] = $return_price_date['loan_ratio']; $r_value['gross_value'] = $return_price_date['gross_value']; $r_value['net_worth'] = $return_price_date['eva_net_value']; $r_value['net_worth_tow'] = $return_price_date['eva_net_value2']; $r_value['internal_remarks'] = $return_price_date['internal_remarks']; $r_value['external_remarks'] = $return_price_date['external_remarks']; $r_value['nuclear_price_situation'] = $return_price_date['pricing_remarks']; // $r_value['appraiser_name'] = $return_price_date['appraiser_name']; // $r_value['appraiser_name'] = $r_value['appraiser_name']; $r_value['total_guide_tax'] = $return_price_date['total_guide_tax'] > 0 ? $return_price_date['total_guide_tax'] : 0; $r_value['total_tax_ceb'] = $r_value['total_taxes1']; //光大-住宅-第一贷款不算增值税 if ($basic['type'] == 1) { $r_value['rapid_roi_citic'] = $return_price_date['eva_total_value'] * 0.7;//中信银行住宅快速变现价值 } else { $r_value['rapid_roi_citic'] = $return_price_date['eva_total_value'] * 0.5;//中信银行商业快速变现价值 } $info[$r_key] = $r_value; } } } $total_size = 0; //面积总和 $total_assessment_price = 0; //评估单价和 $total_assessment_all_value = 0; //评估总值总和 $total_total_tax = 0; //预计税费总和 $total_total_tax1 = 0; //税费1总和 $total_total_tax2 = 0; $total_eva_net_value = 0; //评估净值1总和 $total_eva_net_value2 = 0; //评估净值2总和 $total_guide_assessment_price = 0; // 参考单价总和 $total_guide_assessment_net_worth = 0;//参考净值总和 $total_guide_tax = 0; $total_value_add_tax = 0; // 增值税总和 $total_value_education_surcharges = 0; // 教育费附加税总和 $total_value_urban_construction_tax = 0; // 城市建设维护税总和 $total_value_deed_tax = 0; // 契税总和 $total_value_individual_income_tax = 0; // 个人所得税总和 $total_value_individual_income_tax_copy = 0; // 个人所得税总和 $total_value_service_charge = 0; // 交易服务费总和 $total_value_stamp_duty = 0; // 印花税总和 $total_value_land_value_added_tax = 0; // 土地增值税总和 $total_auction_fee = 0; // 拍卖费总和 $t_total_tax_ceb = 0; $total_value_register_price = 0; $total_value_rapid_roi_citic = 0;//中信银行快速变现总值 $total_statutory_payment = 0;//中行法定优先受偿款 $total_boc_net = 0; if (!empty($info)) { foreach ($info as $k => $v) { $info[$k]['full_estate_name'] = $v['property_full_name']; //权利人 $info[$k]['obligee'] = $v['obligee']; //权利人 $info[$k]['evaluate_purpose'] = $basic['eva_purpose']; //估价目的 $info[$k]['is_over2year_name'] = ($v['is_tran_tax_free'] == 1) ? "是" : "否"; //是否满2年,1.是 2.否 $info[$k]['tenure_type_name'] = ($v['ownership_type'] == 1) ? "个人" : (($v['ownership_type'] == 2) ? "企业" : ""); //权属类型,1.个人 2.公司 $info[$k]['usage_name'] = Db::name("dictionary")->where(["type" => "HOUSE_USAGE", "code" => $v['usage']])->value("valname"); $info[$k]['urban_construction_education'] = $v['education_surcharges'] + $v['urban_construction_tax']; //城建和教育附加费 $info[$k]['total_tax'] = $v['sales_tax'] + $v['service_charge'] + $v['education_surcharges'] + $v['urban_construction_tax'] + $v['deed_tax'] + $v['stamp_duty'] + $v['added_tax'] + $v['land_value_added_tax'] + $v['individual_income_tax'] + $v['auction_fee']; //税费合计 $total_value_add_tax += $v['added_tax'];//计算增值税总和 $total_value_education_surcharges += $v['education_surcharges']; $total_value_urban_construction_tax += $v['urban_construction_tax']; $total_value_deed_tax += $v['deed_tax']; $total_value_individual_income_tax += $v['individual_income_tax']; $total_value_service_charge += $v['service_charge']; $total_value_stamp_duty += $v['stamp_duty']; $total_value_land_value_added_tax += $v['land_value_added_tax']; $total_size += $v['size']; $total_assessment_price += $v['eva_unit_price']; $total_assessment_all_value += $v['eva_total_value']; $total_total_tax += $info[$k]['total_tax']; $total_total_tax1 += $info[$k]['total_taxes1']; $total_total_tax2 += $info[$k]['total_taxes2']; $total_eva_net_value += $v['eva_net_value']; $total_eva_net_value2 += $v['eva_net_value2']; $total_guide_assessment_price += $total_size * $v['guide_price']; // 指导总价 $tax = $info[$k]['total_guide_tax']; $tax = $tax > 0 ? $tax : 0; $total_guide_tax += $tax; //指导税费合计 $total_guide_assessment_net_worth += ($total_guide_assessment_price - $total_guide_tax);//指导净值 $t_total_tax_ceb += $v['total_tax_ceb']; $total_value_individual_income_tax_copy += $v['individual_income_tax_copy']; $total_value_register_price += $v['reg_price']; $total_value_rapid_roi_citic += $v['rapid_roi_citic']; $total_statutory_payment += $v['statutory_payment']; $total_auction_fee += $v['auction_fee']; //处理数据成千分位显示 $info[$k]['market_price'] = ($info[$k]['market_price'] > 0) ? number_format($info[$k]['market_price'], 0) : 0; $info[$k]['guide_price'] = ($info[$k]['guide_price'] > 0) ? number_format($info[$k]['guide_price'], 0) : 0; $info[$k]['assessment_price'] = ($info[$k]['assessment_price'] > 0) ? number_format($info[$k]['assessment_price'], 0) : 0; // $info[$k]['total_guide_assessment_price'] = $total_guide_assessment_price?number_format($total_guide_assessment_price):0;// 参考总价价 $info[$k]['total_guide_assessment_price'] = $v['guide_price'] ? number_format($v['guide_price'] * $v['size']) : 0; // $info[$k]['total_guide_assessment_net_worth'] = $total_guide_assessment_net_worth?number_format($total_guide_assessment_net_worth):0;//// 参考净值 $info[$k]['total_guide_assessment_net_worth'] = number_format($v['guide_price'] * $v['size'] - $info[$k]['total_guide_tax']); $info[$k]['assessment_all_value'] = ($info[$k]['assessment_all_value'] > 0) ? number_format($info[$k]['assessment_all_value'], 0) : 0; $info[$k]['assessment_net_worth'] = ($info[$k]['assessment_net_worth'] > 0) ? number_format($info[$k]['assessment_net_worth'], 0) : 0; $info[$k]['assessment_net_worth_tow'] = ($info[$k]['assessment_net_worth_tow'] > 0) ? number_format($info[$k]['assessment_net_worth_tow'], 0) : 0; $info[$k]['sales_tax'] = ($info[$k]['sales_tax'] > 0) ? number_format($info[$k]['sales_tax'], 0) : 0; $info[$k]['service_charge'] = ($info[$k]['service_charge'] > 0) ? number_format($info[$k]['service_charge'], 0) : 0; $info[$k]['education_surcharges'] = ($info[$k]['education_surcharges'] > 0) ? number_format($info[$k]['education_surcharges'], 0) : 0; $info[$k]['urban_construction_tax'] = ($info[$k]['urban_construction_tax'] > 0) ? number_format($info[$k]['urban_construction_tax'], 0) : 0; $info[$k]['deed_tax'] = ($info[$k]['deed_tax'] > 0) ? number_format($info[$k]['deed_tax'], 0) : 0; $info[$k]['stamp_duty'] = ($info[$k]['stamp_duty'] > 0) ? number_format($info[$k]['stamp_duty'], 0) : 0; $info[$k]['added_tax'] = ($info[$k]['added_tax'] > 0) ? number_format($info[$k]['added_tax'], 0) : 0; $info[$k]['land_value_added_tax'] = ($info[$k]['land_value_added_tax'] > 0) ? number_format($info[$k]['land_value_added_tax'], 0) : 0; $info[$k]['individual_income_tax'] = ($info[$k]['individual_income_tax'] > 0) ? number_format($info[$k]['individual_income_tax'], 0) : 0; $info[$k]['individual_income_tax_copy'] = ($info[$k]['individual_income_tax_copy'] > 0) ? number_format($info[$k]['individual_income_tax_copy'], 0) : 0; $info[$k]['auction_fee'] = ($info[$k]['auction_fee'] > 0) ? number_format($info[$k]['auction_fee'], 0) : 0; $info[$k]['total_tax1'] = ($info[$k]['total_tax1'] > 0) ? number_format($info[$k]['total_tax1'], 0) : 0; $info[$k]['total_tax2'] = ($info[$k]['total_tax2'] > 0) ? number_format($info[$k]['total_tax2'], 0) : 0; $info[$k]['urban_construction_education'] = ($info[$k]['urban_construction_education'] > 0) ? number_format($info[$k]['urban_construction_education'], 0) : 0; $info[$k]['total_tax'] = ($info[$k]['total_tax'] > 0) ? number_format($info[$k]['total_tax'], 0) : 0; $info[$k]['total_guide_tax'] = ($info[$k]['total_guide_tax'] > 0) ? number_format($info[$k]['total_guide_tax'], 0) : 0; $info[$k]['total_tax_ceb'] = ($info[$k]['total_tax_ceb'] > 0) ? number_format($info[$k]['total_tax_ceb'], 0) : 0; $info[$k]['register_price'] = ($info[$k]['register_price'] > 0) ? number_format($info[$k]['register_price'], 2) : 0; $info[$k]['rapid_roi_citic'] = ($info[$k]['rapid_roi_citic'] > 0) ? number_format($info[$k]['rapid_roi_citic'], 0) : 0; //中行净值扣除法定优先受偿款 $info[$k]['boc_net'] = $v['eva_total_value'] - $v['statutory_payment']; $total_boc_net += $info[$k]['boc_net']; $info[$k]['boc_net'] = ($info[$k]['boc_net'] > 0) ? number_format($info[$k]['boc_net'], 0) : 0; } } //处理合计 $all = array(); $all['added_tax'] = number_format($total_value_add_tax, 0); $all['education_surcharges'] = number_format($total_value_education_surcharges, 0); $all['urban_construction_tax'] = number_format($total_value_urban_construction_tax, 0); $all['deed_tax'] = number_format($total_value_deed_tax, 0); $all['individual_income_tax'] = number_format($total_value_individual_income_tax, 0); $all['individual_income_tax_copy'] = number_format($total_value_individual_income_tax_copy, 0); $all['service_charge'] = number_format($total_value_service_charge, 0); $all['stamp_duty'] = number_format($total_value_stamp_duty, 0); $all['land_value_added_tax'] = number_format($total_value_land_value_added_tax, 0); $all['auction_fee'] = number_format($total_auction_fee, 0); $all['size'] = number_format($total_size, 2); $all['assessment_price'] = number_format($total_assessment_price, 0); $all['assessment_all_value'] = number_format($total_assessment_all_value, 0); $all['total_tax'] = number_format($total_total_tax, 0); $all['total_tax1'] = number_format($total_total_tax1, 0); $all['total_tax2'] = number_format($total_total_tax2, 0); $all['assessment_net_worth'] = number_format($total_eva_net_value, 0); $all['assessment_net_worth_tow'] = number_format($total_eva_net_value2, 0); $all['total_guide_assessment_price'] = number_format($total_guide_assessment_price); // 参考单价 $all['total_guide_tax'] = number_format($total_guide_tax > 0 ? $total_guide_tax : 0);//指导税费合计 $all['total_guide_assessment_net_worth'] = number_format($total_guide_assessment_price - $total_guide_tax);//参考净值 $all['t_total_tax_ceb'] = number_format($t_total_tax_ceb, 0); $all['t_register_price'] = number_format($total_value_register_price, 2); $all['t_rapid_roi_citic'] = number_format($total_value_rapid_roi_citic, 0); $all['t_statutory_payment'] = number_format($total_statutory_payment, 0); $all['t_boc_net'] = number_format($total_boc_net, 0); // //银行名称处理 /*if($basic['bank_id']==783){ $basic['bank'] = implode("",array_unique(array($basic['bank_name'],$basic['bank_branch_name']))); }else{ $basic['bank'] = implode("",array_unique(array($basic['bank_name'],$basic['bank_branch_name'],$basic['bank_sub_name']))); }*/ $basic['bank'] = implode("", array_unique(array($basic['bank_name'], $basic['bank_branch_name']))); $basic['seal_time'] = date("Y年m月d日", $basic_signatrue_time);//date("Y年m月d日",strtotime($basic['seal_time'])); $basic['full_estate_name'] = implode("、", array_unique(array_column($info, 'full_estate_name'))); $basic['appraiser_name'] = implode(" ", array_unique(array_column($info, 'appraiser_name'))); if (count($info) > 1) { $basic['full_estate_name_index'] = $info[0]['land_location'] . $info[0]['full_estate_name'] . "等" . count($info) . "套"; } else { $basic['full_estate_name_index'] = $info[0]['land_location'] . $info[0]['full_estate_name']; } if (!empty($basic['appraiser_ids'])) { $autograph = Db::name('valuer')->where(['id' => $basic['appraiser_ids']])->value('autograph'); $basic['valuer_list'] = $Attachment->getUrl($autograph); } else { $basic['valuer_list'] = ['id' => '', 'url' => '']; } // $basic['qrcode'] = $this->index("http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); $basic['qrcode'] = $basic['estimated_qrcode_url']; //物业位置图 $loc_img_ids = []; if ($basic['loc_img_ids']) { $locationIds = explode(',', $basic['loc_img_ids']); $loc_img_ids = $Attachment->getUrls($locationIds); } $basic['location_imgs'] = $loc_img_ids; //估价对象照片 $appraisal_img_ids = []; if ($basic['appraisal_img_ids']) { $allIds = explode(',', $basic['appraisal_img_ids']); $appraisal_img_ids = $Attachment->getUrls(array_filter($allIds)); } $basic['survey_gallery_imgs'] = $appraisal_img_ids; $datas['basic'] = json_decode($basic, true); $datas['info'] = $info; $datas['all'] = $all; //合计 $datas['total']['size'] = $total_size; //建筑面积总和 $datas['total']['assessment_all_value'] = ($total_assessment_all_value > 0) ? number_format($total_assessment_all_value, 0) : 0; //评估总值总和 $datas['total']['total_tax'] = ($total_total_tax > 0) ? number_format($total_total_tax, 0) : 0; //预计税费总和 $datas['total']['total_tax1'] = ($total_total_tax1 > 0) ? number_format($total_total_tax1, 0) : 0; //税费1总和 $datas['total']['assessment_net_worth'] = ($total_eva_net_value > 0) ? number_format($total_eva_net_value, 0) : 0; //评估净值总和 //文件信息 $datas['file_folder'] = Env::get('service.project_folder'); $content = $Estimate->where(["bank_id" => $basic['bank_id'], "product_name" => $basic['loan_type'], "type" => $basic['type']])->value('estimate_sheet'); if (!$content) { return "该银行对应的业务类型的评估目的未设置预估单模板"; } if (empty($datas['basic']['estimated_desc'])) { $datas['basic']['estimated_desc'] = $Estimate->where(["bank_id" => $basic['bank_id'], "product_id" => $basic['product_id'], "type" => $basic['type']])->value("estimated_desc"); } $content = str_replace("说明显示位置", $datas['basic']['estimated_desc'], $content); $this->assign('datas', $datas); $data = $this->display($content, $datas); $data = $data->getContent(); $firstpageone = <<request->get("quot_id"); $estimate_qrcode_unique_key = $this->request->get("key"); $display_data = []; $isReal = true;// 是否真实报告 // 判断询价信息是否存在 $inquiry_info = Db::name('inquiry') ->field('order_no,bank_name,bank_branch_name,bank_sub_name,eva_purpose,seal_time,estimated_no,estimate_qrcode_unique_key') ->where('id', $quot_id) ->find(); if (empty($inquiry_info) || !$inquiry_info['estimate_qrcode_unique_key'] || $inquiry_info['estimate_qrcode_unique_key'] != $estimate_qrcode_unique_key) { $isReal = false; return $this->displayAnticounterfeit($isReal, $display_data); } $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,appraiser_name') ->where('quot_id', $quot_id) ->select(); if (empty($property_cert_list)) { $isReal = false; return $this->displayAnticounterfeit($isReal, $display_data); } $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; return $this->displayAnticounterfeit($isReal, $display_data); } $display_data['full_estate_name_str'] = $property_cert_list[0]['property_full_name'] . (count($property_cert_list) > 1 ? '等共' . count($property_cert_list) . '套' : ''); // 项目名称 $display_data['estimated_no'] = $inquiry_info['estimated_no'] ?? ''; //预估编号 $display_data['customer_full_name'] = $inquiry_info['bank_name'] . $inquiry_info['bank_branch_name']; //客户全称 $display_data['eva_purpose'] = $inquiry_info['eva_purpose'] ?? ''; // 评估目的 $display_data['seal_time'] = isset($inquiry_info['seal_time']) && !empty($inquiry_info['seal_time']) ? date('Y-m-d', strtotime($inquiry_info['seal_time'])) : ''; // yuping时间 $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['appraiser_name'] = $property_cert_list[0]['appraiser_name'] ?? ''; // 预评撰写人 return $this->displayAnticounterfeit($isReal, $display_data); } public function displayAnticounterfeit($isReal, $display_data) { $path = "../public/template/estimate_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 = <<http_post($url, $data); } // 2021年6月自动估价系统重新开发重写 public function updEvaluateInquiry($data) { $url = env('evaluate.el_api') . '/api/Inquiry/personReviewNotification'; $time = time(); $header = [ 'appkey:' . env('evaluate.appkey'), 'timestamp:' . $time, 'sign:' . md5(env('evaluate.appkey') . env('evaluate.appsecret') . $time), ]; trace('header:'); trace($header); trace('url:'); trace($url); trace('data:'); trace($data); $res = $this->http_post($url, $data, 30, $header); trace('res:'); trace($res); } // 重新签章更新自动估价系统 public function updEvaluateSignature($data) { $url = env('evaluate.el_api') . '/api/Inquiry/updEvaluateSignature'; $time = time(); $header = [ 'appkey:' . env('evaluate.appkey'), 'timestamp:' . $time, 'sign:' . md5(env('evaluate.appkey') . env('evaluate.appsecret') . $time), ]; trace('header:'); trace($header); trace('url:'); trace($url); trace('data:'); trace($data); $res = $this->http_post($url, $data, 30, $header); trace('res:'); trace($res); } public static function http_post($url, $data = [], $second = 30, $header = []) { $curl = curl_init(); curl_setopt($curl, CURLOPT_TIMEOUT, $second); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); if (!empty($header)) { curl_setopt($curl, CURLOPT_HTTPHEADER, $header); } list($content, $status) = [curl_exec($curl), curl_getinfo($curl), curl_close($curl)]; return (intval($status["http_code"]) === 200) ? $content : false; } /** * 预估单列表 */ public function estimateList() { $paginate = $this->getPage(); $estimate_status = $this->request->post('estimate_status', '', 'trim'); $type = $this->request->post('type', '', 'trim'); $user_name = $this->request->post('user_name', '', 'trim'); $response_username = $this->request->post('response_username', '', 'trim'); $is_multiple = $this->request->post('is_multiple', '', 'trim'); $start_time = $this->request->post('start_time', '', 'trim'); $end_time = $this->request->post('end_time', '', 'trim'); $keyword = $this->request->post('keyword', '', 'trim'); $city_id = $this->request->post('city_id', '', 'trim'); //城市 $bank_id = $this->request->post('bank_id', '', 'trim'); //银行id $product_id = $this->request->post('product_id', '', 'trim'); //评估目的id $internal_remarks = $this->request->post('internal_remarks', '', 'trim'); //内部备注 $start_size = $this->request->post('start_size', '', 'trim'); //面积起 $end_size = $this->request->post('end_size', '', 'trim'); //面积止 $issue_report = $this->request->post('issue_report', '', 'trim'); //是否出具报告 $is_signature = $this->request->post('is_signature', '', 'trim'); //是否已签章 $start_time_length = $this->request->post('start_time_length', '', 'trim'); //时间长度起 $end_time_length = $this->request->post('end_time_length', '', 'trim'); //时间长度止 // if (!$type) { // return $this->buildFailed("查询类型不能为空"); // } $where = array(); $type && $where[] = ['i.type', '=', intval($type)]; // if ($issue_report == 1) { //是否出具报告 // $where[] = ['i.status', '=', 8]; // } elseif ($issue_report === 0) { // $where[] = ['i.status', 'in', [2, 3, 4, 5, 6, 7], '_logic' => 'or']; // } else { // $where[] = ['i.status', 'in', [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], '_logic' => 'or']; // } $where[] = ['i.is_simple', '=', 0]; $where[] = ['i.apply_estimate_make_status', '=', 1]; if (!empty($estimate_status)) { $where[] = ['i.estimate_status', '=', $estimate_status]; } else { $where[] = ['i.estimate_status', 'not null', '']; } $start_time && $where[] = ['i.create_time', '>=', $start_time . " 00:00:00"]; $end_time && $where[] = ['i.create_time', '<=', $end_time . " 23:59:59"]; $is_multiple && $where[] = ['i.is_multiple', '=', $is_multiple]; $user_name && $where[] = ['i.buss_username', 'like', "%" . $user_name . "%"]; $keyword && $where[] = ['ii.property_full_name|i.estimated_no|i.business_no|i.order_no', 'like', "%" . $keyword . "%"]; $city_id && $where[] = ['ii.city_id', '=', $city_id]; //城市 $bank_id && $where[] = ['i.bank_id', '=', $bank_id]; //银行 $product_id && $where[] = ['i.product_id', '=', $product_id]; //评估目的 $start_size && $end_size && $where[] = getQuery('ii.size', $start_size, $end_size); //面积开始 $start_time_length && $end_time_length && $where[] = getQuery('i.eva_detail_time_long', $start_time_length, $end_time_length); $is_signature && $where[] = ['i.seal_status', '=', $is_signature]; $response_username && $where[] = ['ii.appraiser_name', 'like', "%" . $response_username . "%"]; $internal_remarks && $where[] = ['ii.internal_remarks', 'like', "%{$internal_remarks}%"]; //内部备注 $Inquiry = new Inquiry(); $resultData = $Inquiry->alias("i") ->leftJoin('pg_property_cert_info ii', 'ii.quot_id=i.id') ->leftJoin('pg_boc_cf_inquiry_apply iii', 'iii.dealNo = i.business_no') ->field('i.id, i.order_no, i.business_no, i.type, i.is_multiple, i.bank_name, i.bank_branch_name, i.bank_sub_name, i.bank_customer_mgr_name, i.estimated_no, i.create_time, i.buss_username, i.user_name, i.seal_status, i.adjust_reason, i.status, i.eva_purpose, i.loan_type, i.eva_detail_time_long, i.is_auto, i.is_auto_eva, i.estimate_audit_status, i.estimate_audit1_date, i.estimate_audit_user_name, i.branchCom_id, ii.id as did, ii.quot_id, ii.city, ii.parcel_no, ii.parcel_area, ii.land_unit_price, ii.floor_unit_price, ii.reg_price, ii.rid, i.biz_status, i.estimate_url, i.bnkno, i.tlrname, i.is_send_estimate_to_boc, i.estimate_status') ->where($where) // ->whereNotNull('i.estimate_status') // ->whereNotNull('i.estimate_audit1_date') ->group('i.id') ->order('i.id', 'desc') ->paginate($paginate) ->each(function ($item, $key) { $inquiry_details = Db::name('property_cert_info') ->where('quot_id=' . $item['id']) ->field(' id, property_full_name, size, parcel_no, land_unit_price, parcel_area, floor_unit_price, eva_unit_price, eva_total_value, internal_remarks, risk_grade, appraiser_name, r_create_time AS appraiser_time ') ->select(); foreach ($inquiry_details as $key => $value) { $return_price_count = Db::name('return_price')->where('property_cert_info_id=' . $inquiry_details[$key]['id'])->field('id')->count(); // 是否有调价 $item['is_adjusted_price'] = $return_price_count > 2 ? true : false; } if (count($inquiry_details) > 1) { $item['property_full_name'] = implode(',', array_column($inquiry_details, 'property_full_name')); $item['size'] = implode('/', array_column($inquiry_details, 'size')); $item['eva_unit_price'] = implode('/', array_column($inquiry_details, 'eva_unit_price')); $item['eva_total_value'] = implode('/', array_column($inquiry_details, 'eva_total_value')); $item['internal_remarks'] = implode('/', array_column($inquiry_details, 'internal_remarks')); $item['appraiser_name'] = implode('/', array_column($inquiry_details, 'appraiser_name')); $item['risk_grade'] = implode('/', array_column($inquiry_details, 'risk_grade')); $item['appraiser_time'] = implode('/', array_column($inquiry_details, 'appraiser_time')); } elseif (count($inquiry_details) == 1) { $item['property_full_name'] = $inquiry_details[0]['property_full_name']; $item['size'] = $inquiry_details[0]['size']; $item['eva_unit_price'] = $inquiry_details[0]['eva_unit_price']; $item['eva_total_value'] = $inquiry_details[0]['eva_total_value']; $item['internal_remarks'] = $inquiry_details[0]['internal_remarks']; $item['appraiser_name'] = $inquiry_details[0]['appraiser_name']; $item['risk_grade'] = $inquiry_details[0]['risk_grade']; $item['appraiser_time'] = $inquiry_details[0]['appraiser_time']; } $detail_estate_name = explode(',', $item['property_full_name']); $detail_appraiser_name = explode('/', $item['appraiser_name']); $detail_appraise_level = explode('/', $item['risk_grade']); $detail_appraiser_time = explode('/', $item['appraiser_time']); $item['property_full_name'] = $detail_estate_name[0]; $item['appraiser_name'] = $detail_appraiser_name[0]; $item['risk_grade'] = (int)max($detail_appraise_level); $item['appraiser_time'] = $detail_appraiser_time[0] ? date("Y-m-d H:i:s", $detail_appraiser_time[0]) : ''; $propertyDetails = []; foreach ($inquiry_details as $key => $value) { $propertyDetails[$key]['property_full_name'] = $value['property_full_name']; $propertyDetails[$key]['internal_remarks'] = $value['internal_remarks']; } $item['propertyDetails'] = $propertyDetails; // 是否出具报告 $item['issue_report'] = $item['status'] == 8 ? '已出具报告' : '否'; // 订单状态文字描述 $item['status_str'] = getDictionaryName('ORDER_STATUS', $item['status']); // 自动估价,默认值 if ($item['is_auto'] == 1 && $item['is_auto_eva'] == 1) { $item['appraiser_name'] = '自动估价'; $item['appraiser_time'] = $item['create_time']; } // 如果预估未审核,则不显示预估单号 // $item['estimated_no'] = ($item['estimate_audit_status'] == self::ALREADY_ESTIMATE_AUDIT) ? $item['estimated_no'] : ""; $item['bank'] = $item['bank_name']; $item['bank_name'] = $item['bank_sub_name'] ? $item['bank_name'] . $item['bank_sub_name'] : $item['bank_name']; $item['export_create_time'] = date('Y-m-d', strtotime($item['create_time'])); return $item; }) ->toArray(); return $this->buildSuccess($resultData); } public function GetOnlineReport() { $quot_id = $this->request->post('quot_id', '', 'trim'); if (empty($quot_id)) { return $this->buildFailed("参数错误"); } Db::startTrans(); $res = Db::name('inquiry')->where(['id' => $quot_id])->update(['status' => 6, 'update_time' => date('Y-m-d H:i:s')]); if (!$res) { Db::rollback(); return $this->buildFailed("线上报告制作取号失败"); } $report_info = Db::name('report')->where(['quot_id' => $quot_id])->find(); if (!empty($report_info)) { Db::commit(); return $this->buildSuccess(['report_no' => $report_info['report_no']]); } $inquiry_info = Db::name('inquiry')->field("id,report_dir,report_obj_type,report_class,branchCom_id,product_id,bank_name,loan_type,business_no") ->where(['id' => $quot_id])->find(); if (empty($inquiry_info)) { Db::rollback(); return $this->buildFailed("询价信息不存在"); } $report_no_info = (new ReportModel())->generateReportNo($quot_id); $report_id = Db::name('report')->insertGetId([ 'quot_id' => $quot_id, 'report_no' => $report_no_info['report_no'], 'create_time' => date('Y-m-d H:i:s', time()), 'create_reportNo_time' => date('Y-m-d H:i:s'), 'report_tmpl_id' => Db::name('product')->where(['id' => $inquiry_info['product_id']])->value('report_template'), 'report_obj_type' => $inquiry_info['report_obj_type'], 'report_class' => $inquiry_info['report_class'], 'report_dir' => $inquiry_info['report_dir'], 'branchCom_id' => $inquiry_info['branchCom_id'], ]); if (!$report_id) { Db::rollback(); return $this->buildFailed("线上报告制作取号失败"); } $property_cert_info_list = Db::name('property_cert_info')->where(['quot_id' => $quot_id])->select(); $insert_detail_data = []; foreach ($property_cert_info_list as $key => $value) { $insert_detail_data[] = [ 'report_id' => $report_id, 'property_cert_info_id' => $value['id'], 'building_name' => $value['building_name'], 'year' => $value['year'], 'property_cert' => $value['property_cert'], 'obligee' => $value['obligee'], 'cert_no' => $value['cert_no'], 'cert_type' => $value['cert_type'], // 'client' => $value['client'], 'parcel_no' => $value['parcel_no'], 'parcel_area' => $value['parcel_area'], // 'parcel_usage' => $value['parcel_usage'], 'use_right_source' => $value['use_right_source'], 'completion_date' => $value['completion_time'], 'purchase_date' => $value['purchase_date'], // 'reg_date' => $value['reg_date'], // 'max_land_use_years' => $value['max_land_use_years'], // 'land_use_start_time' => $value['land_use_start_time'], // 'land_use_end_time' => $value['land_use_end_time'], // 'area' => $value['area'], // 'area_id' => $value['area_id'], 'land_location' => $value['land_location'], 'building_area' => $value['size'], ]; } $res = Db::name('report_detail')->insertAll($insert_detail_data); if (!$res) { Db::rollback(); return $this->buildFailed("线上报告制作取号失败"); } Db::commit(); if ($inquiry_info['bank_name'] == '中国银行' && in_array($inquiry_info['loan_type'], ['按揭', '普惠', '消费'])) { $boc_cf_service = new BocCfService(); } return $this->buildSuccess(['report_no' => $report_no_info['report_no']]); } public function updateInquiryEstimateUrl() { $upload_file = $this->request->post('upload_file', '', 'trim'); $quot_id = $this->request->post('quot_id', '', 'trim'); try { $inquiry_info = Db::name('inquiry')->where(['id' => $quot_id])->find(); if (empty($inquiry_info)) { return $this->buildFailed("询价信息不存在"); } if (isset($upload_file['url']) && !empty($upload_file['url'])) { $res = Db::name('inquiry')->where(['id' => $quot_id])->update(['estimate_url' => $upload_file['url'], 'is_send_estimate_to_boc' => 2]); 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 false; } } public function exportInquiryExcel() { $start_date = input('start_date'); $end_date = input('end_date'); $dateInterval = date_diff(date_create($end_date), date_create($start_date)); $diff_month = $dateInterval->m; $diff_day = $dateInterval->d; if ($diff_month > 6 || ($diff_month == 6 && $diff_day > 0)) { return $this->buildFailed('日期范围不能超过6个月'); } Db::execute("SET @row_num = 0"); $list = Db::name('property_cert_info')->alias('pci') ->field("CAST(@row_num := @row_num + 1 AS CHAR) AS row_num, pci.property_full_name, i.bank_name, i.buss_username, pci.appraiser_name, FROM_UNIXTIME(pci.r_create_time, '%Y-%m-%d %H:%i:%s') r_create_time") ->leftJoin("pg_inquiry i", "i.id = pci.quot_id") ->where("pci.r_create_time >= UNIX_TIMESTAMP('{$start_date} 00:00:00') and pci.r_create_time <= UNIX_TIMESTAMP('{$end_date} 23:59:59')") ->order("pci.r_create_time asc") // ->limit(1) ->select(); if (empty($list)) { return $this->buildFailed('没有数据可以导出'); } $indexKey = [ 'row_num', 'property_full_name', 'bank_name', 'buss_username', 'appraiser_name', 'r_create_time', ]; $indexValue = [ '序号', '物业名称', '银行', '业务员', '询价员', '时间', ]; return $this->buildSuccess([ 'url' => exportExcel($list, 'inquiry_' . date('YmdHis'), $indexKey, $indexValue), ]); } public function getThreeMonthSameEstateInquiryRecord() { $building_name = input('building_name'); $building_no = input('building_no'); $unit_no = input('unit_no'); if (empty($building_name)) return $this->buildFailed('物业名称不能为空'); if (empty($building_no)) return $this->buildFailed('栋号不能为空'); if (empty($unit_no)) return $this->buildFailed('房号不能为空'); $field = [ 'i.id', 'i.order_no', 'i.create_time', 'i.eva_purpose', 'pci.eva_unit_price', 'pci.eva_total_value', 'i.bank_name', 'i.bank_branch_name', 'i.bank_sub_name', 'i.type', 'i.is_multiple', 'i.status', 'i.bank_customer_mgr_name', 'i.report_class as reportClass', 'i.report_obj_type as reportObjType', 'i.report_dir ', 'i.branchCom_id ', 'i.buss_username', 'i.estimated_no', 'i.eva_detail_time_long', 'i.business_no', 'i.contract_no', 'i.loan_type', 'i.return_price_attachments', 'pci.id as did', 'pci.quot_id', 'pci.city', 'pci.city_id', 'pci.property_full_name', 'pci.size', 'pci.reg_price', 'pci.year', 'pci.appraiser_name AS response_username', 'pci.appraiser_id', 'pci.risk_grade', 'pci.r_create_time AS response_time', 'pci.eva_net_value', 'pci.eva_net_value2', 'pci.total_taxes1', 'pci.total_taxes2', 'pci.internal_remarks', 'pci.rid', ]; $attachmentModel = new Attachment(); $list = Db::name('property_cert_info')->alias('pci') ->field($field) ->join('pg_inquiry i', 'i.id = pci.quot_id') ->where('pci.building_name', $building_name) ->where('pci.building_no', $building_no) ->where('pci.unit_no', $unit_no) ->where('pci.unit_no', $unit_no) // ->where('pci.r_create_time >= UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 3 MONTH))') ->where('pci.r_create_time >= UNIX_TIMESTAMP(DATE_SUB(FROM_UNIXTIME(UNIX_TIMESTAMP(NOW()), "%Y-%m-%d 00:00:00"), INTERVAL 3 MONTH))') ->paginate($this->getPage()) ->each(function ($item) use ($attachmentModel) { $item['return_price_attachments_list'] = !empty($item['return_price_attachments']) ? $attachmentModel->getUrls($item['return_price_attachments']) : []; $item['type_str'] = getDictionaryName('BUSINESS_TYPE', $item['type']); $item['is_multi_str'] = getDictionaryName('INQUIRY_NUMBER', $item['is_multiple']); $item['status_str'] = getDictionaryName('ORDER_STATUS', $item['status']); $item['response_time'] = $item['response_time'] ? date('m-d H:i', $item['response_time']) : ''; $item['create_time'] = date('m-d H:i', strtotime($item['create_time'])); $item['inquiry_details'] = Db::name('property_cert_info') ->where('quot_id=' . $item['id']) ->field('id,city,property_full_name,size,ownership_type,usage,eva_unit_price,eva_total_value,eva_net_value,eva_net_value2,total_taxes1, total_taxes2,cert_usage,attachments') ->select(); if (count($item['inquiry_details']) > 0) { foreach ($item['inquiry_details'] as $key => $value) { $external_remarks = ''; $return_price_info = Db::name('return_price')->where("property_cert_info_id", $value['id']) ->field('*') ->order('create_time desc') ->find(); if (!empty($return_price_info)) { $external_remarks = $return_price_info['external_remarks']; } $item['inquiry_details'][$key]['external_remarks'] = $external_remarks; $item['inquiry_details'][$key]['usage'] = getDictionaryName('HOUSE_USAGE', $value['usage']); $item['inquiry_details'][$key]['attachments_list'] = !empty($value['attachments']) ? $attachmentModel->getUrls($value['attachments']) : []; } } if (count($item['inquiry_details']) > 1) { $item['property_full_name'] = implode(',', array_column($item['inquiry_details'], 'property_full_name')); $item['size'] = implode('/', array_column($item['inquiry_details'], 'size')); $item['eva_unit_price'] = implode('/', array_column($item['inquiry_details'], 'eva_unit_price')); $item['eva_total_value'] = implode('/', array_column($item['inquiry_details'], 'eva_total_value')); $item['eva_net_value'] = implode('/', array_column($item['inquiry_details'], 'eva_net_value')); $item['eva_net_value2'] = implode('/', array_column($item['inquiry_details'], 'eva_net_value2')); $item['total_taxes1'] = implode('/', array_column($item['inquiry_details'], 'total_taxes1')); $item['total_taxes2'] = implode('/', array_column($item['inquiry_details'], 'total_taxes2')); $item['usage'] = implode('/', array_column($item['inquiry_details'], 'usage')); } elseif (count($item['inquiry_details']) == 1) { $item['property_full_name'] = $item['inquiry_details'][0]['property_full_name']; $item['size'] = $item['inquiry_details'][0]['size']; $item['eva_unit_price'] = $item['inquiry_details'][0]['eva_unit_price']; $item['eva_total_value'] = $item['inquiry_details'][0]['eva_total_value']; $item['eva_net_value'] = $item['inquiry_details'][0]['eva_net_value']; $item['eva_net_value2'] = $item['inquiry_details'][0]['eva_net_value2']; $item['total_taxes1'] = $item['inquiry_details'][0]['total_taxes1']; $item['total_taxes2'] = $item['inquiry_details'][0]['total_taxes2']; $item['usage'] = $item['inquiry_details'][0]['usage']; } $producer_name = Db::name('report')->where('quot_id=' . $item['id'])->where('status=3')->value('producer_name'); $item['producer_name'] = !empty($producer_name) ? $producer_name : NULL; return $item; }) ->toArray(); return $this->buildSuccess($list); } }