Files
pgserver3.0/pgserver/application/admin/service/CalcTaxService.php
annnj-company 130c1026c4 first commit
2026-04-17 18:29:53 +08:00

1391 lines
51 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* 收费管理公用
*/
namespace app\admin\service;
use think\Db;
class CalcTaxService
{
const OWNERSHIP_TYPE_PERSONAL = 1; // 个人
const OWNERSHIP_TYPE_ENTERPRISE = 2; // 企业
const HOUSE_TYPE_RESIDENCE = 1; // 住宅
const HOUSE_TYPE_NOT_RESIDENCE = 2; // 非住宅
public function __construct()
{
}
//测试数据
public function test()
{
// 88.57m² 88000元/m²
$rVAt = $this->calcLandVat(
0,//重置成本
6220810,// 原建购价
0,// 应补地价
0,//改良投资
5244,// 城建税
3746,// 教育费附加
3712,//印花税
2,// 购买年限
'中国工商银行',
'企业自建房',//房屋用途
0,
7794160,
false,
'1');
var_dump($rVAt);
}
function valueAddedRatio(
$totalAssessValue, // U6: 评估总值(元)
$valueAddedTax, // AA6: 增值税(元)
$vatRate, // E6: 增值税(税率)
$resetCost, // Z6: 重置成本(元)
$originalCost, // S6: 原建购价(元)
$landPremium, // X6: 应补地价(元)
$improvementInvestment, // Y6: 改良投资(元)
$urbanConstructionTax, // AB6: 城建税(元)
$educationSurcharge, // AC6: 教育费附加(元)
$localEducationSurcharge, // AD6: 地方教育附加费(元)
$stampDuty, // AE6: 印花税(元)
$purchaseYears, // D6: 购买年限
$bankType, // B6: 银行
$isFivePercentPolicy // J3单元格是否为"是5%"
)
{
// 计算增值税处理后的分母
$denominator = ($valueAddedTax === '免征')
? 1
: (1 + $vatRate);
// 计算分子基础值(评估总值/增值税处理)
$numeratorBase = $totalAssessValue / $denominator;
// 计算SUM参数集合
$sumParams = [
($resetCost > 0) ? $resetCost : $originalCost, // 重置成本或原建购价
$landPremium, // 应补地价
$improvementInvestment,// 改良投资
$urbanConstructionTax, // 城建税
$educationSurcharge, // 教育费附加
$localEducationSurcharge, // 地方教育附加费
$stampDuty // 印花税
];
// 计算特殊条件参数AND嵌套逻辑
$specialParam = 0;
if ($purchaseYears >= 1
&& $isFivePercentPolicy === '是5%'
&& $resetCost === '') {
// 银行类型税率判断
$taxRate = in_array($bankType, [
'工行',
'中行',
'中行(企业自建房)'
]) ? 0 : 0.05; // 5%转为小数
$specialParam = $originalCost * $taxRate * $purchaseYears;
}
// 总和计算分子分母的SUM部分
$totalSum = array_sum(array_merge($sumParams, [$specialParam]));
// 最终增值比例计算保留4位小数
return round(
(($numeratorBase - $totalSum) / $totalSum) * 100,
4
);
}
/** 项目扣除项
** 扣除项目金额=原建购价+城建+教育附加+印花+交易服务+原建购价×5%×购买年限)
**/
public static function calc_exclude_taxcost(
$resetCost, // 重置成本 原Z6
$originBuildCost,//原建购价
$landPriceSupple,//应补地价
$improvementInvest,//改良投资原Y6
$cityBuildTax,//城建税原AB6
$eduTax,// 教育费附加原AC6
$stampTax,//印花税
$buyYears,//购买年限(年)
$bankName,//银行名称 原B6
$houseUsage,//房屋用途 原J3_house_usage
$tradeServeFee //交易服务费
)
{
$r = [
'res' => 0,
'msg' => 'success',
'code' => 0,
'debug' => '',
'rate' => 0,
'cost' => 0
];
// 重置成本优先,若无重置成本则使用原建购价
$cost = $resetCost > 0 ? $resetCost : $originBuildCost;
// 默认为0
$rate = 0;
// 银行为中国工商银行或中国银行且非企业自建房则税率5%
if ($bankName === '中国工商银行'
or $bankName === '中国银行'
or ($bankName === '中国银行' and $houseUsage === '企业自建房')) { // 银行为中国工商银行或中国银行且非企业自建房则税率5%
$rate = 0.00;
} else { // 其他情况税率为0.05
$rate = 0.05;
}
// 计算扣除项目金额
$tax = round((float)$cost + (float)$improvementInvest + (float)$cityBuildTax + (float)$eduTax + (float)$stampTax + (float)$tradeServeFee + ((float)$originBuildCost * (float)$rate * (float)$buyYears));
$r = [
'res' => (float)$tax,
'msg' => '成功',
'code' => 0,
'debug' => ' 银行:' . $bankName . ' 扣除-银行影响的税率:' . $rate . ' 重置成本:' . $resetCost . ' 原建构成本:' . $originBuildCost . ' cost:' . $cost . ' improvementInvest' . $improvementInvest . ' cityBuildTax:' . $cityBuildTax . ' eduTax:' . $eduTax . ' stampTax:' . $stampTax . ' tradeServeFee:' . $tradeServeFee,
'rate' => (float)$rate,
'cost' => (float)$cost
];
return $r;
}
/**
* 计算增值价格
* @param $totalAssessValue 评估总值 原U6
* @param $valueAddedTax 增值税原AA6
* @param $vatRate 增值税税率原E6
* @param $resetCost 重置成本 原Z6
* @param $originalCost 原建购价 原S6
* @param $landPremium 应补地价 原X6
* @param $improvementInvestment 改良投资 原Y6
* @param $urbanConstructionTax 城建税 原AB6
* @param $educationSurcharge 教育费附加 原AC6
* @param $localEducationSurcharge 地方教育附加费 原AD6
* @param $stampDuty 印花税 原AE6
* @param $purchaseYears 购买年限 原D6
* @param $bankType 银行 原B6
* @param $isFivePercentPolicy J3单元格是否为"是5%" 原J3_is_5_percent
* @return float
*/
private function valueAddedPrice(
$totalAssessValue, // 评估总值 原U6
$valueAddedTax, // 增值税原AA6
$vatRate, // 增值税税率原E6
$resetCost, // 重置成本 原Z6
$originalCost, // 原建购价 原S6
$landPremium, // 应补地价 原X6
$improvementInvestment, // 改良投资 原Y6
$urbanConstructionTax, // 城建税 原AB6
$educationSurcharge, // 教育费附加 原AC6
$localEducationSurcharge, // 地方教育附加费 原AD6
$stampDuty, // 印花税 原AE6
$purchaseYears, // 购买年限 原D6
$bankType, // 银行 原B6
$isFivePercentPolicy // J3单元格是否为"是5%" 原J3_is_5_percent
)
{
// 计算分母(增值税处理)
$denominator = ($valueAddedTax === '免征') ? 1 : (1 + $vatRate);
$numerator = $totalAssessValue / $denominator;
// SUM参数1重置成本或原建购价
$sumParam1 = $resetCost > 0 ? $resetCost : $originalCost;
// SUM其他参数
$sumParams = [
$sumParam1,
$landPremium, // 应补地价
$improvementInvestment,// 改良投资
$urbanConstructionTax, // 城建税
$educationSurcharge, // 教育费附加
$localEducationSurcharge, // 地方教育附加费
$stampDuty // 印花税
];
// SUM参数8特殊条件计算
$specialParam8 = 0;
if ($purchaseYears >= 1 && $isFivePercentPolicy === '是5%' && $resetCost === '') {
$taxRate = in_array($bankType, ['工行', '中行', '中行(企业自建房)']) ? 0 : 0.05;
$specialParam8 = $originalCost * $taxRate * $purchaseYears;
}
// 总和计算
$totalSum = array_sum(array_merge($sumParams, [$specialParam8]));
// 最终计算并四舍五入
return round($numerator - $totalSum);
}
/**
* 计算增值税
*
* @param bool $owenship_type 产权人类型1: 个人, 2: 企业)
* @param string|null $transaction_date 交易日期格式YYYY-MM-DD仅企业需要
* @param float $total_assessment_price 评估总值(万元)
* @return array 包含计算结果的标准响应数组
*/
public function calculate_valueAddtion_tax(
$owenship_type,
$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;
}
// 获取增值税率
$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'];
// 计算税额
$tax_base = ($total_assessment_price - $OriginalAmount) / (1 + $vat_rate);
$tax = $tax_base * $vat_rate;
//var_dump( $desc, $transaction_date ,$vat_rate,'增值税:'.$tax );
// 设置结果
$result['res'] = round($tax, 0);
//var_dump('vat',$total_assessment_price,$owenship_type,$transaction_date,$vat_rate );
$result['debug'] = ' 增值税-税率:' . $vat_rate;
//var_dump(' 增值税税率',$vat_rate ,$total_assessment_price,$OriginalAmount);
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 function calculate_deed_tax_old(
$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; // 初始化
// 个人住宅计算逻辑
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 // 企业计算逻辑
{
$vat_rate = 0;// 增值税率
// 如果增值税等于0
if ($vat_tax <= 0) {
$tax = $total_assessment_price * 0.03;
} else {
// 获取增值税率
$vatRes = $this->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 function set_error(int $code, string $msg, string $debug = "")
{
return [
'res' => 0.00,
'taxrate' => 0.00,
'code' => $code,
'msg' => $msg,
'debug' => $debug
];
}
// 计算增值比例
public function calc_value_added_ratio(
$totalAssessValue, // U6: 评估总值(元)
$isValueAddedTaxFree, // 是否免征增值税(元)
$excluseTaxCost // 扣除项目金额总和
)
{
$rate = $isValueAddedTaxFree ? 1 : 1.05;
$v = ($totalAssessValue / $rate) - $excluseTaxCost;
//var_dump("--------------calc_value_added_ratio:",$v,$totalAssessValue,$isPayValueAddedTax,$excluseTaxCost);
return (($v > 0 ? $v : 0) / $excluseTaxCost);
}
/**
* 计算印花税
*
* @param 评估总值
* @param 权利人
* @param 房屋类型
* @param 购买日期
*/
public function calc_stamp_tax(
$total_assessment_price,//评估总值
$owenship_type,//权利人
$house_type,//房屋类型
$transaction_date//购买日期
)
{
$resAT = [
'res' => 0,
'debug' => "",
'code' => 0,
'msg' => '成功!'
];
// 个人住宅不征税
if ($owenship_type == 1 and $house_type == 1) {
$resAT['res'] = '暂不计征';
return $resAT;
}
// round(评估总值/1+增值税率)*0.05%)
$r = CalcTaxService::calc_value_added_tax_rate($owenship_type, $transaction_date);
if ($r['code'] < 0) {
$resAT['res'] = 0;
$resAT['code'] = -1;
$resAT['msg'] = $resAT['msg'];
return $resAT;
} else {
$taxRate = $r['res'];
$resAT['res'] = round($total_assessment_price / (1 + $taxRate) * 0.0005, 0);
$resAT['debug'] = ' 印花税增值税率:' . $taxRate;
return $resAT;
}
}
/**
* 计算核定土地增值税(单位:万元)
* @param float $total_assessment_price 评估总值(万元)
* @param string $property_usage 物业用途('shop': 商铺, 'hotel': 酒店, 'office': 写字楼, 'other': 其他, 'residential': 住宅)
* @return float 计算结果保留两位小数
*/
private function calcFixLandVatTax(float $total_assessment_price, string $houseUsage): array
{
// 定义不同类型物业的税率
$tax_rates = [
'1' => 0.06, // 住宅税率 6%
'2' => 0.10, // 商铺税率 10% 酒店税率 10% 写字楼税率 10%
// 其他 0.05
];
// 获取对应物业类型的税率,如果类型不存在,默认使用其他类型的税率
$tax_rate = 0.05;
if ($houseUsage == '1' or $houseUsage == '2') {
$tax_rate = $tax_rates[$houseUsage];
}
// 计算核定税额
$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 owenship_type 权利人: 1个人;2企业
* @param transaction_date 购买日期 年-月-日 (购买日期2016-4-30前 5%后9%)
* @return array 'res'
* **/
public static function calc_value_added_tax_rate($owenship_type, $transaction_date)
{
$res = [
'code' => 0, // 0为成功复数为失败。
'msg' => '成功!',
'res' => 0 // 结果值
];
// 确定增值税率
$vat_rate = 0.05; // 默认增值税率
// 企业名下并且分2016-4.30日前后0.05后0.09
if ($owenship_type == 2 && $transaction_date !== null) {
// 校验交易日期格式
if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $transaction_date)) {
$res['code'] = -2;
$res['msg'] = '交易日期格式错误应为YYYY-MM-DD';
// var_dump($desc.'交易日期格式应为YYYY',$total_assessment_price,$owenship_type,$transaction_date,$vat_rate );
return $res;
}
// 根据交易日期调整增值税率
if (strtotime($transaction_date) > strtotime('2016-04-30')) {
$vat_rate = 0.09;
}
}
$res['res'] = round($vat_rate, 2);
return $res;
}
/**
* 计算增值税
*
* @param bool $owenship_type 产权人类型1: 个人, 2: 企业)
* @param string|null $transaction_date 交易日期格式YYYY-MM-DD仅企业需要
* @param float $total_assessment_price 评估总值(万元)
* @return array 包含计算结果的标准响应数组
*/
public function calculate_valueAddtion_tax_old(
$owenship_type,
$transaction_date = null,
$total_assessment_price,
$desc = ""
): array
{
$result = [
'res' => 0.00, // 计算结果
'code' => 0, // 0为成功负数为失败
'msg' => '成功!'
];
// 参数有效性校验
if ($total_assessment_price <= 0) {
$result['code'] = -1;
$result['msg'] = '评估总值必须大于0';
return $result;
}
// 确定增值税率
$vat_rate = 0.05; // 默认增值税率
if ($owenship_type == 2 && $transaction_date !== null) {
// 校验交易日期格式
if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $transaction_date)) {
$result['code'] = -2;
$result['msg'] = '交易日期格式应为YYYY-MM-DD';
// var_dump($desc.'交易日期格式应为YYYY',$total_assessment_price,$owenship_type,$transaction_date,$vat_rate );
return $result;
}
// 根据交易日期调整增值税率
if (strtotime($transaction_date) > strtotime('2016-04-30')) {
$vat_rate = 0.09;
}
}
// 计算税额
$tax_base = $total_assessment_price / (1 + $vat_rate);
$tax = $tax_base * 0.05;
// 设置结果
$result['res'] = round($tax, 2);
//var_dump('vat',$total_assessment_price,$owenship_type,$transaction_date,$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 function calculate_deed_tax(
$owenship_type,
$property_type,
bool $is_two_years,
$area,
$total_assessment_price,
$original_price = null,
$transaction_date = null
): array
{
$result = [
'res' => 0.00,
'taxrate' => 0.00,
'code' => 0,
'msg' => '成功!'
];
// 基础参数校验
if ($owenship_type == '2' && ($original_price === null || $transaction_date === null)) {
return $this->set_error(-3, '企业/非住宅必须提供原建购价和交易日期');
}
/* if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $transaction_date ?? '')) {
return $this->set_error(-6, '交易日期格式应为YYYY-MM-DD');
}*/
if ($total_assessment_price <= 0) {
return $this->set_error(-5, '评估总值必须大于0');
}
try {
$tax = 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 $this->set_error(-4, '房屋面积必须大于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;
}
// 企业计算逻辑
} else {
// 确定增值税率
$vat_rate = ($transaction_date < '2016-04-30') ? 0.05 : 0.09;
// 计算税基
$tax_base = $is_two_years
? max(($total_assessment_price - $original_price), 0)
: $total_assessment_price;
// 计算最终税额
$tax = ($tax_base / (1.0 + $vat_rate)) * 0.03;
// 填充额外信息
$result['rate'] = $vat_rate;
}
// 最终处理
$result['res'] = round(max($tax, 0), 2);
$result['taxrate'] = round($tax_base ?? 0, 2);
} catch (Exception $e) {
return $this->set_error(-1, '计算异常: ' . $e->getMessage());
}
return $result;
}
// 错误处理辅助函数
public function set_error_old(int $code, string $msg)
{
return [
'res' => 0.00,
'taxrate' => 0.00,
'code' => $code,
'msg' => $msg
];
}
/*****************************************************/
/**
* 计算增值税和增值税率
* @param $ownership_type
* @param $house_type
* @param $transaction_date
* @param $purchase_year
* @param $total_assessment_price
* @param $original_amount
* @param $land_price_supple
* @param $improvement_invest
* @return array
*/
public static function calcAddedTax(
$ownership_type, // 产权人类型(1=个人 2=企业)
$house_type, // 房产类型(1=住宅 2=非住宅)
$transaction_date, //购买日期
$purchase_year, //购买年限
$total_assessment_price, //评估总值
$original_amount, // 原建构价
$land_price_supple, // 应补地价
$improvement_invest // 改良投资
)
{
if ($ownership_type == self::OWNERSHIP_TYPE_PERSONAL) { //个人
if ($house_type == self::HOUSE_TYPE_RESIDENCE) { //住宅
if ($purchase_year >= 2) {
$added_tax = '免征';
$added_tax_rate = 0;
} else {
$added_tax_rate = 3;
$added_tax = $total_assessment_price / (1 + ($added_tax_rate / 100)) * ($added_tax_rate / 100);
}
} else { //非住宅
$added_tax_rate = 5;
$added_tax = max(
0,
($total_assessment_price - $original_amount - $land_price_supple - $improvement_invest) / (1 + ($added_tax_rate / 100)) * ($added_tax_rate / 100)
);
}
} else { //企业
$added_tax_rate = self::getAddedTaxRate($ownership_type, $transaction_date);
$added_tax = max(
0,
($total_assessment_price - $original_amount - $land_price_supple - $improvement_invest) / (1 + ($added_tax_rate / 100)) * ($added_tax_rate / 100)
);
}
if ($added_tax === '免征' || $added_tax == 0) {
$added_tax_rate = 0;
}
return [
'added_tax' => $added_tax,
'added_tax_rate' => $added_tax_rate,
];
}
/**
* 计算城建税
* @param $added_tax string|int|float 增值税
* @return string|float
*/
public static function calcUrbanConstructionTax($added_tax)
{
if ($added_tax === '免征') {
return '免征';
}
return $added_tax * 0.07;
}
/**
* 计算教育附加费
* @param $added_tax string|int|float 增值税
* @return string|float
*/
public static function calcEduSurcharge($added_tax)
{
if ($added_tax === '免征') {
return '免征';
}
return $added_tax * 0.05;
}
/**
* 计算扣除项目金额
* @param $reset_cost string 重置成本
* @param $original_amount float 原建购价
* @param $purchase_year int 购买年限
* @param $bank_name string 银行名称
* @param $land_price_supple float 应补地价
* @param $improvement_invest float 改良投资
* @param $urban_construction_tax float 城建税
* @param $edu_surcharge float 教育附加费
* @return float 扣除项目金额
*/
public static function calcExclueProjectFee(
$reset_cost, // 重置成本
$original_amount, // 原建购价
$purchase_year, // 购买年限
$bank_name, // 银行名称
$land_price_supple, // 应补地价
$improvement_invest, // 改良投资
$urban_construction_tax, // 城建税
$edu_surcharge, // 教育附加费
$stamp_duty // 印花税
)
{
if ($reset_cost > 0) {
$tmp_fee1 = $reset_cost;
} else {
$tmp_fee1 = $original_amount;
}
$tmp_fee2 = 0;
if ($purchase_year >= 1 && empty($reset_cost) && !($bank_name == '中国工商银行' || $bank_name == '中国银行')) {
$tmp_fee2 = $original_amount * 0.05 * $purchase_year;
}
// dump($purchase_year);
// dump($tmp_fee1);
// dump($urban_construction_tax);
// dump($edu_surcharge);
// dump($stamp_duty);
// dump($tmp_fee2);
// dump($tmp_fee1 + $land_price_supple + $improvement_invest + $urban_construction_tax + $edu_surcharge + $stamp_duty + $tmp_fee2);
// die;
return $tmp_fee1 + $land_price_supple + $improvement_invest + $urban_construction_tax + $edu_surcharge + $stamp_duty + $tmp_fee2;
}
/**
* 计算土地增值税
* @param $options_land_added_tax_rate float 土地增值税率,百分比
* @param $ownership_type int 产权人类型1: 个人, 2: 企业)
* @param $house_type int 房屋类型1: 住宅, 2: 非住宅)
* @param $added_tax_rate int 增值税税率 百分比
* @param $total_assessment_price float 评估总值
* @param $exclue_project_fee float 扣除项目金额
* @param $tax_rate float 税率,百分比
* @param $rapid_calc_rate float 速算率,百分比
* @param $bank_name string 银行名称
* @param $loan_type string 贷款种类
* @return float|int|string
*/
public static function calcLandAddedTaxFee(
$options_land_added_tax_rate, // 土地增值税率
$ownership_type, // 产权人类型
$house_type, // 房屋类型
$house_usage, // 房屋用途
$original_amount, // 原建构价
$added_tax_rate, // 增值税税率
$total_assessment_price, // 评估总值
$exclue_project_fee, // 扣除项目金额
$tax_rate, // 规定税率
$rapid_calc_rate, // 速算率
$bank_name, // 银行名称
$loan_type // 贷款种类
)
{
// 个人-住宅的情况
if ($ownership_type == self::OWNERSHIP_TYPE_PERSONAL && $house_type == self::HOUSE_TYPE_RESIDENCE) {
return '免征';
}
$house_usage_dict_list = Db::name('dictionary')->where('type', 'HOUSE_USAGE')->column('code,valname');
// 2.如果选项中选择了【不征】则直接返回0
$approved_land_added_tax_rate = 0;
if ($options_land_added_tax_rate == '不征') {
return 0;
} else if ($options_land_added_tax_rate == '正常征税') {
$approved_land_added_tax_rate = self::getApprovedLandTaxRate($house_usage, $house_usage_dict_list); //核定土地增值税税率
} else if (strpos($options_land_added_tax_rate, '%') !== false) { //只要选了百分号的土增税率,都统一返回核定 2025-07-10
$approved_land_added_tax_rate = trim($options_land_added_tax_rate, '%');
$approved_land_added_price = $total_assessment_price / (1 + ($added_tax_rate / 100)) * ($approved_land_added_tax_rate / 100);
return $approved_land_added_price;
} else { //为空
//企业名下的物业,土增默认为正常扣,所得默认为不扣就是否
//个人名下的非住宅土增默认为正常扣,所得默认为正常扣
if (($ownership_type == self::OWNERSHIP_TYPE_ENTERPRISE)
||
($ownership_type == self::OWNERSHIP_TYPE_PERSONAL && $house_type == self::HOUSE_TYPE_NOT_RESIDENCE)
) {
$approved_land_added_tax_rate = self::getApprovedLandTaxRate($house_usage, $house_usage_dict_list); //核定土地增值税税率
}
}
$approved_land_added_price = $total_assessment_price / (1 + ($added_tax_rate / 100)) * ($approved_land_added_tax_rate / 100);
$verify_land_added_price = ($total_assessment_price / (1 + ($added_tax_rate / 100)) - $exclue_project_fee) * ($tax_rate / 100) - $exclue_project_fee * ($rapid_calc_rate / 100);
if ($original_amount > 0) {
$return_price = $verify_land_added_price;
} else {
$return_price = $approved_land_added_price;
}
// 核定和核实的,哪个低的取哪个
if (
($bank_name == '中国工商银行' && $loan_type == '普惠')
&&
(
$ownership_type == self::OWNERSHIP_TYPE_ENTERPRISE //企业名下物业
||
($ownership_type == self::OWNERSHIP_TYPE_PERSONAL && $house_type == self::HOUSE_TYPE_NOT_RESIDENCE) //个人名下非住宅
)
) {
$return_price = min($approved_land_added_price, max(0, $verify_land_added_price));
}
// 工行对公、邮储、中行、浙商、华润这几家银行不能做核定。2025-07-10
if (
($bank_name == '中国工商银行' && $loan_type == '对公')
||
in_array($bank_name, [
'中国邮政储蓄银行',
'中国银行',
'浙商银行',
'珠海华润银行',
])
) {
$return_price = $verify_land_added_price;
}
return $return_price;
//企业名下不管是住宅非住宅,土增都是正常扣税,所得不扣
//个人名下非住宅,土增默认正常扣,所得正常扣
//工行普惠,个人名下住宅,只扣契税(税费合计)
//工行普惠,个人名下非住宅,土增正常扣,和核定,哪个低取哪个
}
/**
* 计算印花税
* @param $ownership_type int 产权人类型 (1=个人 2=企业)
* @param $house_type int 房产类型 (1=住宅 2=非住宅)
* @param $total_assessment_price float 评估总值
* @param $added_tax_rate float 增值税率,百分比
* @return float|string
*/
public static function calcStampDuty($ownership_type, $house_type, $total_assessment_price, $added_tax_rate)
{
if ($ownership_type == self::OWNERSHIP_TYPE_PERSONAL && $house_type == self::HOUSE_TYPE_RESIDENCE) {
return '暂不计征';
}
return $total_assessment_price / (1 + ($added_tax_rate / 100)) * 0.0005;
}
/**
* 计算个人所得税
* @param $ownership_type int 产权人类型 (1=个人 2=企业)
* @param $purchase_date string 购买日期
* @param $house_type int 房产类型 (1=住宅 2=非住宅)
* @param $house_usage string 房屋用途
* @param $option_personal_income_tax_rate float|string 个人所得税税率,"带百分号的百分比"或者"是"
* @param $bank_name string 银行名称
* @param $loan_type string 贷款种类
* @param $added_tax string|int|float 增值税
* @param $added_tax_rate string|int|float 增值税率
* @param $total_assessment_price float 评估总值
* @param $original_amount float 原建购价
* @param $land_price_supple float 应补地价
* @param $improvement_invest float 改良投资
* @param $urban_construction_tax float 城建税
* @param $edu_surcharge float 教育附加费
* @param $stamp_duty float 印花税
* @param $land_added_tax_fee float 土地增值税
* @param $tran_service_fee int 交易服务费直接默认0
* @param $deed_tax float 契税
* @param $auction_fee float 拍卖费
* @param $litigation_cost float 诉讼费用
* @return mixed|string
*/
public static function calcPersonalIncomeTax(
$ownership_type, // 产权人类型(1=个人 2=企业)
$purchase_date, // 购买日期
$house_type, // 房产类型 (1=住宅 2=非住宅)
$house_usage, // 房屋用途
$option_personal_income_tax_rate, // 个人所得税税率,百分比
$bank_name, // 银行名称
$loan_type, //贷款种类
$added_tax, //增值税
$added_tax_rate, //增值税
$total_assessment_price, // 评估总值
$original_amount, // 原建构价
$land_price_supple, // 应补地价
$improvement_invest, // 改良投资
$urban_construction_tax, // 城建税
$edu_surcharge, // 教育附加费
$stamp_duty, // 印花税
$land_added_tax_fee, // 土地增值税
$tran_service_fee, // 交易服务费直接默认0
$deed_tax, // 契税
$auction_fee, // 拍卖费
$litigation_cost //诉讼费用
)
{
$house_usage_dict_list = Db::name('dictionary')->where('type', 'HOUSE_USAGE')->column('code,valname');
if ($option_personal_income_tax_rate == "") {
if ($house_type == self::HOUSE_TYPE_NOT_RESIDENCE) { //非住宅
$approved_personal_income_tax_rate = 1.5;
} else { //住宅
$approved_personal_income_tax_rate = 1;
}
$return_price = $total_assessment_price / (1 + ($added_tax_rate / 100)) * ($approved_personal_income_tax_rate / 100);
} else if (strpos($option_personal_income_tax_rate, '%') !== false) {
$approved_personal_income_tax_rate = trim($option_personal_income_tax_rate, '%');
$return_price = $total_assessment_price / (1 + ($added_tax_rate / 100)) * ($approved_personal_income_tax_rate / 100);;
} else {
if ($ownership_type == self::OWNERSHIP_TYPE_ENTERPRISE) {
return '暂不计征';
}
if ($bank_name == '中国工商银行') {
if ($loan_type == '普惠') {//工行普惠
if ($house_type == self::HOUSE_TYPE_NOT_RESIDENCE || (array_key_exists($house_usage, $house_usage_dict_list) && $house_usage_dict_list[$house_usage] == '商务公寓')) {
$approved_personal_income_tax_rate = 1.5;
} else {
$approved_personal_income_tax_rate = 1;
}
$approved_personal_income_price = $total_assessment_price / (1 + ($added_tax_rate / 100)) * ($approved_personal_income_tax_rate / 100);
// 核实
$verify_personal_income_price = max(0, ($total_assessment_price / (1 + ($added_tax_rate / 100)) - (
$original_amount +
$land_price_supple +
$improvement_invest +
$urban_construction_tax +
$edu_surcharge +
$stamp_duty +
$land_added_tax_fee +
$tran_service_fee +
$deed_tax +
$auction_fee +
$litigation_cost)) * 0.2);
$return_price = min($approved_personal_income_price, max(0, $verify_personal_income_price));
} else {
$return_price = ($total_assessment_price / (1 + ($added_tax_rate / 100)) - (
$original_amount +
$land_price_supple +
$improvement_invest +
$urban_construction_tax +
$edu_surcharge +
$stamp_duty +
$land_added_tax_fee +
$tran_service_fee +
$deed_tax +
$auction_fee +
$litigation_cost)) * 0.2;
}
} else {
$return_price = ($total_assessment_price / (1 + ($added_tax_rate / 100)) - (
$original_amount +
$land_price_supple +
$improvement_invest +
$urban_construction_tax +
$edu_surcharge +
$stamp_duty +
$land_added_tax_fee +
$tran_service_fee +
$deed_tax +
$auction_fee +
$litigation_cost)) * 0.2;
}
}
return $return_price;
}
/**
* 计算契税
* @param $bank_name string 银行名称
* @param $loan_type string 贷款种类
* @param $ownership_type int 产权人类型(1=个人 2=企业)
* @param $house_type int 房产类型 (1=住宅 2=非住宅)
* @param $size float 房屋面积
* @param $added_tax string|int|float 增值税
* @param $total_assessment_price float 评估总值
* @param $added_tax_rate float 增值税率,百分比
* @return float
*/
public static function calcDeedTax(
$bank_name,
$loan_type,
$ownership_type,
$house_type,
$size,
$added_tax,
$total_assessment_price,
$added_tax_rate
)
{
/* 以下的是计算契税,其余的则不计算
* 中国民生银行 住宅、非住宅 二手按揭
* 中国建设银行 住宅、非住宅 二手按揭
* 中国工商银行 住宅、非住宅 普惠、二手按揭
*/
if (
!(
($bank_name == '中国工商银行' && in_array($loan_type, ['普惠', '二手按揭']))
||
(($bank_name == '中国民生银行' || $bank_name == '中国建设银行') && $loan_type == '二手按揭')
)
) {
return '暂不计征';
}
if ($ownership_type == self::OWNERSHIP_TYPE_PERSONAL && $house_type == self::HOUSE_TYPE_RESIDENCE) {
if ($size > 140) {
if ($added_tax === '免征') {
return $total_assessment_price * 0.015;
} else {
return $total_assessment_price / (1 + ($added_tax_rate / 100)) * 0.015;
}
} else {
if ($added_tax === '免征') {
return $total_assessment_price * 0.01;
} else {
return $total_assessment_price / (1 + ($added_tax_rate / 100)) * 0.01;
}
}
} else {
if ($added_tax == 0) {
return $total_assessment_price * 0.03;
} else {
if (empty(1 + ($added_tax_rate / 100))) {
return 0;
}
return $total_assessment_price / (1 + ($added_tax_rate / 100)) * 0.03;
}
}
}
/**
* 计算拍卖费
* @param $bank_name string 银行名称
* @param $loan_type string 贷款种类
* @param $total_assessment_price float 评估总值
* @return float|int
*/
public
static function calcAuctionFee($bank_name, $loan_type, $total_assessment_price)
{
if ($bank_name == '中国农业银行' && in_array($loan_type, ['对公', '小企业简式', '个人住宅', '个人商业办公'])) {
if ($total_assessment_price <= 5000000) {
return $total_assessment_price * 0.02;
} elseif ($total_assessment_price <= 100000000) {
return 50000000 * 0.02 + ($total_assessment_price - 50000000) * 0.01;
} else {
return 50000000 * 0.03 + ($total_assessment_price - 100000000) * 0.005;
}
}
return 0;
}
/**
* 计算诉讼费用
* @param $bank_name string 银行名称
* @param $loan_type string 贷款种类
* @param $total_assessment_price float 评估总值
* @return float|int
*/
public
static function calcLitigationCost($bank_name, $loan_type, $total_assessment_price)
{
$tmp_fee1 = 0;
$tmp_fee2 = 0;
if ($bank_name == '中国农业银行' && in_array($loan_type, ['对公', '小企业简式', '个人住宅', '个人商业办公'])) {
if ($total_assessment_price > 1000000) {
$tmp_fee1 = $total_assessment_price * 0.005 + 10010;
} elseif ($total_assessment_price > 500000) {
$tmp_fee1 = $total_assessment_price * 0.01 + 5010;
} elseif ($total_assessment_price > 200000) {
$tmp_fee1 = $total_assessment_price * 0.015 + 2510;
} elseif ($total_assessment_price > 100000) {
$tmp_fee1 = $total_assessment_price * 0.02 + 1510;
} elseif ($total_assessment_price > 50000) {
$tmp_fee1 = $total_assessment_price * 0.03 + 510;
} elseif ($total_assessment_price > 1000) {
$tmp_fee1 = $total_assessment_price * 0.04 + 10;
} else {
$tmp_fee1 = 50;
}
if ($total_assessment_price > 500000) {
$tmp_fee2 = $total_assessment_price * 0.001 + 2000;
} elseif ($total_assessment_price > 10000) {
$tmp_fee2 = $total_assessment_price * 0.005;
} else {
$tmp_fee2 = 50;
}
}
return $tmp_fee1 + $tmp_fee2;
}
/**
* 增值税是否免征
* @param $ownership_type int 产权人类型(1=个人 2=企业)
* @param $house_type int 房产类型 (1=住宅 2=非住宅)
* @param $purchase_year int 购买年限
* @return bool
*/
public
static function isExemptAddTax($ownership_type, $house_type, $purchase_year)
{
if (
$ownership_type == self::OWNERSHIP_TYPE_PERSONAL
&&
$house_type == self::HOUSE_TYPE_RESIDENCE
&&
$purchase_year >= 2
) {
return true;
}
return false;
}
/**
* 获取购买年限
* @param $transaction_date
* @return int
*/
public
static function getPurchaseYear($transaction_date)
{
try {
$current_date = new \DateTime('@' . time(), new \DateTimeZone('Asia/Shanghai'));
$tmp_date = new \DateTime('@' . strtotime($transaction_date), new \DateTimeZone('Asia/Shanghai'));
// 计算年份差
$interval = $current_date->diff($tmp_date);
return $interval->y;
} catch (\Exception $e) {
return 0;
}
}
/**
* 获取增值税率
* @param $ownership_type
* @param $transaction_date
* @return float 百分比
*/
public
static function getAddedTaxRate($ownership_type, $transaction_date)
{
// 默认增值税率=0.05
$added_tax_rate = 5;
// 企业名下并且分2016-4.30日前后,前=0.05,后=0.09
if ($ownership_type == self::OWNERSHIP_TYPE_ENTERPRISE && strtotime($transaction_date) > strtotime('2016-04-30')) {
$added_tax_rate = 9;
}
return $added_tax_rate;
}
/**
* 获取增值额
* @param $added_tax string|int|float 增值税
* @param $total_assessment_price float 评估总值
* @param $added_tax_rate float 增值税率
* @param $exclue_project_fee float 扣除项目金额
* @return float
*/
public
static function getAddedQuota($added_tax, $total_assessment_price, $added_tax_rate, $exclue_project_fee)
{
if ($added_tax === '免征') {
$tmp_fee = $total_assessment_price;
} else {
if (1 + ($added_tax_rate / 100) == 0) {
return 0;
}
$tmp_fee = $total_assessment_price / (1 + ($added_tax_rate / 100));
}
return $tmp_fee - $exclue_project_fee;
}
/**
* 获取增值比例(百分比)
* @param $added_quota float 增值额
* @param $exclue_project_fee float 扣除项目金额
* @return float
*/
public
static function getAddedProportion($added_quota, $exclue_project_fee)
{
if ($exclue_project_fee == 0) {
return 0;
}
return $added_quota / $exclue_project_fee * 100;
}
/**
* 获取税率(百分比)
* @param $added_proportion float 增值比例,百分比
* @return int
*/
public
static function getTaxRate($added_proportion)
{
if ($added_proportion <= 0) {
return 0;
} elseif ($added_proportion <= 50) {
return 30;
} elseif ($added_proportion <= 100) {
return 40;
} elseif ($added_proportion <= 200) {
return 50;
} else {
return 60;
}
}
/**
* 获取速算率(百分比)
* @param $added_proportion float 增值比例,百分比
* @return int
*/
public
static function getRapidCalcRate($added_proportion)
{
if ($added_proportion <= 50) {
return 0;
} elseif ($added_proportion <= 100) {
return 5;
} elseif ($added_proportion <= 200) {
return 15;
} else {
return 35;
}
}
public
static function processReturn($param)
{
if (is_int($param) || is_float($param)) {
// 数字类型进行四舍五入默认精度0位小数
return max(0, round($param));
}
// 字符串类型直接返回
return $param;
}
/**
* 获取核定土地增值税率
* @return int 增值税税率百分比
*/
/**
* 获取核定土地增值税率
* @param $house_usage string 房屋用途
* @param $house_usage_dict_list array 房屋用途字典列表
* @return int
*/
public static function getApprovedLandTaxRate(string $house_usage, array $house_usage_dict_list): int
{
$tax_rate = 6; //默认是住宅的6%
// 房屋用途:住宅 百分之6
$six_percent_house_usage_type = [
'住宅'
];
// 房屋用途:商业、办公 百分之10
$ten_percent_house_usage_type = [
'商业', '办公'
];
// 房屋用途:厂房、土地、商务公寓、其他
$five_percent_house_usage_type = [
'厂房', '土地', '商务公寓', '其他'
];
foreach ($house_usage_dict_list as $code => $valname) {
if ($house_usage == $code) {
if (in_array($valname, $six_percent_house_usage_type)) {
$tax_rate = 6;
break;
}
if (in_array($valname, $ten_percent_house_usage_type)) {
$tax_rate = 10;
break;
}
if (in_array($valname, $five_percent_house_usage_type)) {
$tax_rate = 5;
break;
}
}
}
return $tax_rate;
}
}