789 lines
35 KiB
PHP
789 lines
35 KiB
PHP
<?php
|
||
|
||
namespace app\admin\controller;
|
||
|
||
use app\model\Taxation;
|
||
use app\model\TaxationItem;
|
||
use app\model\TaxationAuxiliary;
|
||
use app\model\Product;
|
||
use think\Db;
|
||
|
||
class TaxationSetUp extends Base
|
||
{
|
||
/**
|
||
* 税费设置列表
|
||
* @author cavan
|
||
*/
|
||
public function TaxationList()
|
||
{
|
||
$keyword = $this->request->post('keyword', '','trim'); //银行和分行名称搜索
|
||
$page = $this->request->post('page', '','trim'); //页码
|
||
$size = $this->request->post('limit', '','trim'); //单页数量
|
||
|
||
$where = array();
|
||
if(!empty($keyword)){
|
||
$where[]=['bank|branch','like',"%".$keyword."%"];
|
||
}
|
||
if(empty($order)){
|
||
$order=json_encode(array('create_time'=>'desc'));
|
||
}
|
||
if(empty($page)){
|
||
$page=1;
|
||
}
|
||
if(empty($size)){
|
||
$size=10;
|
||
}
|
||
|
||
$config = array(
|
||
"list_rows" => $size,
|
||
"page" => $page
|
||
);
|
||
|
||
$Taxation = new Taxation();
|
||
|
||
$resultData=$Taxation->where($where)
|
||
->order(json_decode($order,true))
|
||
->field('id,bank,branch,product_name,loan_percentage,state,type,create_time,update_time')
|
||
->paginate($size,false,$config);
|
||
|
||
if(!empty($resultData)){
|
||
foreach ($resultData as $k => $v){
|
||
$resultData[$k]['type_name'] = ($v['type']==1)?"住宅":(($v['type']==2)?"商业":"");
|
||
$resultData[$k]['state_name'] = $v['state']==1?"有效":"无效";
|
||
$resultData[$k]['time'] = !empty($v['update_time'])?date("Y-m-d H:i:s",$v['update_time']):date("Y-m-d H:i:s",$v['create_time']);
|
||
}
|
||
}
|
||
|
||
return $this->buildSuccess($resultData);
|
||
}
|
||
|
||
|
||
/**
|
||
* 税费计算
|
||
* @param mixed _InquiryList 询价列表, 算税金额,xxx
|
||
* @return $isOK(Boolean),tax1
|
||
*/
|
||
protected function calTax( $_InquiryList, $price,
|
||
$tax_items, $gfa,
|
||
$ResidentialType,$ManuTotalamo, $OriginalAmount,
|
||
$buyYears, $purpose,$tenureType)
|
||
{
|
||
//评估总值=建筑面积*评估单价
|
||
$ManuTotalamo = $gfa * $price;
|
||
|
||
$list = $_InquiryList;
|
||
|
||
//所选银行
|
||
$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 = $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']):"";
|
||
$item = [];
|
||
|
||
$str = $this->pipei($va['formula'],
|
||
$ResidentialType,
|
||
$gfa,
|
||
$price,
|
||
$ManuTotalamo,
|
||
$OriginalAmount,
|
||
$buyYears,
|
||
$purpose,
|
||
$tenureType,
|
||
$X, $N, $L, $Q, $P, $R, $V, $Z, $T, $O);
|
||
|
||
if (empty($va['condition'])) {
|
||
$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);
|
||
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);
|
||
$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);
|
||
$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);
|
||
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);
|
||
$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);
|
||
$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);
|
||
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);
|
||
$L = round(eval("return {$str};"));
|
||
$L = ($L > 0)?$L:0;
|
||
} else {
|
||
continue;
|
||
}
|
||
}
|
||
}
|
||
if ($va['code_name'] == 'Q') {
|
||
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);
|
||
$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);
|
||
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);
|
||
$Q = round(eval("return {$str};"));
|
||
$Q = ($Q > 0)?$Q:0;
|
||
} else {
|
||
continue;
|
||
}
|
||
}
|
||
}
|
||
if ($va['code_name'] == 'P') {
|
||
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);
|
||
$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);
|
||
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);
|
||
$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);
|
||
$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);
|
||
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);
|
||
$R = round(eval("return {$str};"));
|
||
$R = ($R > 0)?$R:0;
|
||
} else {
|
||
continue;
|
||
}
|
||
}
|
||
}
|
||
if ($va['code_name'] == 'V') {
|
||
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);
|
||
$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);
|
||
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);
|
||
$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);
|
||
$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);
|
||
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);
|
||
$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);
|
||
$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);
|
||
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);
|
||
$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);
|
||
$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);
|
||
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);
|
||
$O = round(eval("return {$str};"));
|
||
$O = ($O > 0)?$O:0;
|
||
} else {
|
||
continue;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
if($list['type'] == 1 && ((strpos($banksubTax,'民生') !== false && $list['eva_purpose'] != "了解市场价值") || (strpos($banksubTax,'光大') !== false) && $list['eva_purpose'] != "了解市场价值")){ //业务类型:住宅,民生和光大(除了评估目的为了解市场价值之外)个人所得税显示为0
|
||
$R_COPY = $R;
|
||
$R = 0;
|
||
}else if($list['type'] == 2 && (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];
|
||
}
|
||
|
||
|
||
public function pipei($str, $ResidentialType, $gfa, $ManuUnitprice, $ManuTotalamo, $OriginalAmount, $buyYears, $purpose,$tenureType, $X, $N, $L, $Q, $P, $R, $V, $Z, $T, $O)
|
||
{
|
||
//[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 == 'P') {
|
||
$value = "'" . $P . "'";
|
||
}
|
||
if ($value == 'R') {
|
||
$value = "'" . $R . "'";
|
||
}
|
||
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 cavan
|
||
*
|
||
*/
|
||
public function TaxationAdd(){
|
||
$list = array();
|
||
//获取计税辅助字段和税费项目
|
||
$list['taxation'] = $this->taxDetailInfo(1); //计税辅助字段
|
||
$list['taxation_item'] = $this->taxDetailInfo(2); //税费项目
|
||
|
||
return $this->buildSuccess($list);
|
||
}
|
||
|
||
/**
|
||
* 税费设置详情--修改调用接口
|
||
* @author cavan
|
||
*
|
||
*/
|
||
public function TaxationDetails(){
|
||
$id = $this->request->post('id', '', 'trim');
|
||
if(!$id){
|
||
return $this->buildFailed("缺少参数id");
|
||
}
|
||
$Taxation = new Taxation();
|
||
$TaxationItem = new TaxationItem();
|
||
//主表信息
|
||
$list = $Taxation->where("id",$id)
|
||
->field("id,bank_id,bank,branch_id,branch,product_name,product_id,loan_percentage,net_worth_one_percentage,net_worth_tow_percentage,eva_net_value,eva_net_value2,tax_items,type")
|
||
->find();
|
||
if(!empty($list)){
|
||
$list['type'] = strval($list['type']);
|
||
$list['json_data'] = $TaxationItem->where("taxation_id",$id)->field("id,taxation_id,code_name,name,condition,formula,tax_description")->select();
|
||
//获取计税辅助字段和税费项目
|
||
$list['eva_net_value'] = !empty($list['eva_net_value'])?explode(",",$list['eva_net_value']):array(); //净值1 一维数组
|
||
$list['eva_net_value2'] = !empty($list['eva_net_value2'])?explode(",",$list['eva_net_value2']):array(); //净值2 一维数组
|
||
$list['tax_items'] = !empty($list['tax_items'])?explode(",",$list['tax_items']):array(); //净值2 一维数组
|
||
|
||
//转换数据类型
|
||
$list['eva_net_value'] = json_decode('[' . join(',', $list['eva_net_value']) . ']',true);
|
||
$list['eva_net_value2'] = json_decode('[' . join(',', $list['eva_net_value2']) . ']',true);
|
||
$list['tax_items'] = json_decode('[' . join(',', $list['tax_items']) . ']',true);
|
||
|
||
$list['taxation'] = $this->taxDetailInfo(1); //计税辅助字段
|
||
$list['taxation_item'] = $this->taxDetailInfo(2); //税费项目
|
||
}
|
||
|
||
return $this->buildSuccess($list);
|
||
}
|
||
|
||
/**
|
||
* 税费设置状态修改
|
||
* @author cavan
|
||
*
|
||
* @parameter id 数据id
|
||
* @parameter state 当前状态
|
||
*/
|
||
public function TaxationModify(){
|
||
$id = $this->request->post('id', '', 'trim'); //数据id
|
||
$state = $this->request->post('state', '','trim'); //当前状态
|
||
if(!$id){
|
||
return $this->buildFailed("缺少参数id");
|
||
}
|
||
if(!$state){
|
||
return $this->buildFailed("缺少参数状态值");
|
||
}
|
||
$Taxation = new Taxation(); //
|
||
if($state != 1){ //2020年4月22日09:02:40
|
||
$rt = $Taxation->where("id",$id)->field("bank_id,branch_id,product_id,type")->find();
|
||
$old_id = $Taxation->where("id","<>",$id)->where(["bank_id"=>$rt['bank_id'],"branch_id"=>$rt['branch_id'],"product_id"=>$rt['product_id'],"type"=>$rt['type'],"state"=>1])->value("id");
|
||
if($old_id){
|
||
return $this->buildFailed("已经存在该银行同一城市分行税费信息");
|
||
}
|
||
}
|
||
|
||
$update_data = array();
|
||
if($state == 1){
|
||
$update_data['state'] = 2;
|
||
$msg = "禁用成功";
|
||
$errormsg = "禁用失败";
|
||
}else{
|
||
$update_data['state'] = 1;
|
||
$msg = "启用成功";
|
||
$errormsg = "启用失败";
|
||
}
|
||
$do = $Taxation->where("id",$id)->update($update_data);
|
||
if($do > 0){
|
||
return $this->buildSuccess("",$msg);
|
||
}else{
|
||
return $this->buildFailed($errormsg);
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* 新增计税银行税费设置
|
||
* @author cavan
|
||
*
|
||
* @parameter bank 银行
|
||
* @parameter bank_id 银行
|
||
* @parameter branch 分行
|
||
* @parameter branch_id 分行
|
||
* @parameter product_name 产品名称
|
||
* @parameter product_id 产品表id
|
||
* @parameter type 业务类型 1.住宅 2.商业
|
||
* @parameter loan_percentage 贷款成数
|
||
* @parameter net_worth_one_percentage 净值1成数
|
||
* @parameter net_worth_tow_percentage 净值2成数
|
||
* @parameter eva_net_value 税费合计1:辅助字段表id字符串
|
||
* @parameter eva_net_value2 税费合计2:辅助字段表id字符串
|
||
* @parameter tax_items 税费项目,选中辅助字段表id字符串
|
||
* @parameter json_data 计税百分比
|
||
*/
|
||
public function save()
|
||
{
|
||
$id = $this->request->post('id', '', 'trim');
|
||
$bank = $this->request->post('bank', '', 'trim');
|
||
$bank_id = $this->request->post('bank_id', '', 'trim');
|
||
$branch = $this->request->post('branch', '', 'trim');
|
||
$branch_id = $this->request->post('branch_id', '', 'trim');
|
||
$product_name = $this->request->post('product_name', '', 'trim');
|
||
$product_id = $this->request->post('product_id', '', 'trim');
|
||
$type = $this->request->post('type', '', 'trim');
|
||
$loan_percentage = $this->request->post('loan_percentage', '', 'trim');
|
||
$net_worth_one_percentage = $this->request->post('net_worth_one_percentage', '', 'trim');
|
||
$net_worth_tow_percentage = $this->request->post('net_worth_tow_percentage', '', 'trim');
|
||
$eva_net_value = $this->request->post('eva_net_value', '', 'trim');
|
||
$eva_net_value2 = $this->request->post('eva_net_value2', '', 'trim');
|
||
// $tax_items = $this->request->post('tax_items', '', 'trim');
|
||
$json_data = $this->request->post('json_data', '', 'trim');
|
||
if (!$bank_id) {
|
||
return $this->buildFailed("缺少银行信息");
|
||
}
|
||
if (!$bank) {
|
||
return $this->buildFailed("缺少银行信息");
|
||
}
|
||
if (!$branch_id) {
|
||
return $this->buildFailed("缺少分行信息");
|
||
}
|
||
if (!$branch) {
|
||
return $this->buildFailed("缺少分行信息");
|
||
}
|
||
if (!$type) {
|
||
return $this->buildFailed("业务类型为必填");
|
||
}
|
||
if (!$product_name) {
|
||
return $this->buildFailed("缺少产品信息");
|
||
}
|
||
if (!$product_id) {
|
||
return $this->buildFailed("缺少产品信息");
|
||
}
|
||
// if (empty($json_data)) {
|
||
// return $this->buildFailed("缺少税费信息");
|
||
// }
|
||
// $json_data = json_decode($json_data,true);
|
||
$Taxation = new Taxation();
|
||
$TaxationItem = new TaxationItem();
|
||
$TaxationAuxiliary = new TaxationAuxiliary();
|
||
|
||
if (!$id){
|
||
$return = $Taxation->where(['bank_id' => $bank_id, 'branch_id' => $branch_id, 'product_id' => $product_id, 'state' => 1])->value("id");
|
||
if ($return) {
|
||
return $this->buildFailed("该银行已存在有效状态的税费设置");
|
||
}
|
||
}
|
||
$tax_items = [];
|
||
if(!empty($json_data)){
|
||
foreach ($json_data as $k => $v){
|
||
if($id){
|
||
if(!array_key_exists("id",$v)){
|
||
return $this->buildFailed("缺少税费详情id");
|
||
}
|
||
}
|
||
if(!array_key_exists("code_name",$v)){
|
||
return $this->buildFailed("缺少税费代号");
|
||
}else if(!array_key_exists("name",$v)){
|
||
return $this->buildFailed("缺少税费名称");
|
||
}
|
||
$tax_items[] = $TaxationAuxiliary->where('number', $v['code_name'])->value('id');
|
||
}
|
||
}
|
||
$insert_data['bank'] = $bank;
|
||
$insert_data['bank_id'] = $bank_id;
|
||
$insert_data['branch'] = $branch;
|
||
$insert_data['branch_id'] = $branch_id;
|
||
$insert_data['product_name'] = $product_name;
|
||
$insert_data['product_id'] = $product_id;
|
||
$insert_data['type'] = $type;
|
||
$insert_data['loan_percentage'] = (!$loan_percentage && $loan_percentage === "") ? null : $loan_percentage;
|
||
$insert_data['net_worth_one_percentage'] = (!$net_worth_one_percentage && $net_worth_one_percentage === "") ? null : $net_worth_one_percentage;
|
||
$insert_data['net_worth_tow_percentage'] = (!$net_worth_tow_percentage && $net_worth_tow_percentage === "") ? null : $net_worth_tow_percentage;
|
||
$insert_data['eva_net_value'] = implode(",",$eva_net_value);
|
||
$insert_data['eva_net_value2'] = implode(",",$eva_net_value2);
|
||
$insert_data['tax_items'] = implode(",",$tax_items);
|
||
$insert_data['state'] = 1;
|
||
if($id){
|
||
Db::startTrans();
|
||
try {
|
||
$old_id = $Taxation->where("id","<>",$id)->where(["bank_id"=>$bank_id,"branch_id"=>$branch_id,"product_id"=>$product_id,"state"=>1])->value("id");
|
||
if($old_id){
|
||
return $this->buildFailed("该银行已存在有效状态的税费设置");
|
||
}
|
||
$insert_data['update_time'] = time();
|
||
$Taxation->where("id",$id)->update($insert_data);
|
||
$ids = $TaxationItem->where("taxation_id",$id)->column("id");
|
||
if(!empty($json_data)){
|
||
foreach ($json_data as $k =>$v){
|
||
$item_data = array();
|
||
$item_data['code_name'] = $v['code_name'];
|
||
$item_data['name'] = $v['name'];
|
||
$item_data['condition'] = $v['condition'];
|
||
$item_data['formula'] = $v['formula'];
|
||
$item_data['tax_description'] = $v['tax_description'];
|
||
$item_data['create_time'] = time();
|
||
if($v['id']){
|
||
if(in_array($v['id'],$ids)){
|
||
foreach($ids as $ks=>$vs) {
|
||
if($v['id'] == $vs) unset($ids[$ks]);
|
||
}
|
||
$ids = array_merge($ids);
|
||
}
|
||
$TaxationItem->where("id",$v['id'])->update($item_data);
|
||
}else{
|
||
$item_data['taxation_id'] = $id;
|
||
$TaxationItem->insert($item_data);
|
||
}
|
||
}
|
||
if(!empty($ids)){
|
||
$idstr = implode(",",$ids);
|
||
$TaxationItem->where("id","in",$idstr)->delete();
|
||
}
|
||
}
|
||
|
||
// 提交事务
|
||
Db::commit();
|
||
} catch (\Exception $e) {
|
||
// 回滚事务
|
||
Db::rollback();
|
||
return $e->getMessage();
|
||
}
|
||
}else{
|
||
Db::startTrans();
|
||
try {
|
||
$insert_data['create_time'] = time();
|
||
$id = $Taxation->insertGetId($insert_data);
|
||
if($id > 0){
|
||
if(!empty($json_data)){
|
||
foreach ($json_data as $k =>$v){
|
||
$item_data[$k]['taxation_id'] = $id;
|
||
$item_data[$k]['code_name'] = $v['code_name'];
|
||
$item_data[$k]['name'] = $v['name'];
|
||
$item_data[$k]['condition'] = $v['condition'];
|
||
$item_data[$k]['formula'] = $v['formula'];
|
||
$item_data[$k]['tax_description'] = $v['tax_description'];
|
||
$item_data[$k]['create_time'] = time();
|
||
}
|
||
$TaxationItem->insertAll($item_data);
|
||
}
|
||
}
|
||
// 提交事务
|
||
Db::commit();
|
||
} catch (\Exception $e) {
|
||
// 回滚事务
|
||
Db::rollback();
|
||
return $e->getMessage();
|
||
}
|
||
}
|
||
return $this->buildSuccess([],"保存成功");
|
||
}
|
||
|
||
|
||
/**
|
||
*
|
||
* @author cavan
|
||
* @parameter type 类型:1、计税辅助字段,2、税费项目,3、评估费辅助字段
|
||
*/
|
||
public function taxDetailInfo( $type = '' )
|
||
{
|
||
if(!$type) return [];
|
||
$TaxationAuxiliary = new TaxationAuxiliary();
|
||
$resultData = $TaxationAuxiliary->where('type',$type)
|
||
->field('id,number,name,value,key')
|
||
->order("sort","asc")
|
||
->select();
|
||
return $resultData;
|
||
}
|
||
|
||
/**
|
||
* 银行对应产品列表
|
||
*/
|
||
public function productLiat(){
|
||
$bank_id = $this->request->post('bank_id', '', 'trim');
|
||
$type = $this->request->post('type', '', 'trim');
|
||
if (!$bank_id) {
|
||
return $this->buildFailed("缺少银行参数");
|
||
}
|
||
if (!$type) {
|
||
return $this->buildFailed("缺少业务类型");
|
||
}
|
||
|
||
$Product = new Product();
|
||
|
||
$list = $Product->where(["bank_id"=>$bank_id,"type"=>$type,"state"=>1])->field("id as value,product_name as name")->select();
|
||
|
||
return $this->buildSuccess($list);
|
||
}
|
||
|
||
}
|