BeforeToAfter.php 33.1 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775
<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Db;

/**
 * 正算接口
 * @ApiWeigh(99)
 */
class BeforeToAfter extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    public function _initialize()
    {
        parent::_initialize();
    }

    /**
     * @ApiTitle    (税前工资-计算税后)
     * @ApiSummary  (税前工资-计算税后)
     * @ApiMethod   (POST)
     *
     * @ApiParams   (name="salary", type="inter", required=true, description="税前每月工资")
     * @ApiParams   (name="month", type="inter", required=true, description="工作月份")
     * @ApiParams   (name="annual_bonus", type="inter", required=false, description="年终奖")
     * @ApiParams   (name="add_money", type="inter", required=false, description="每月专项附加金额")
     * @ApiParams   (name="social_base", type="inter", required=false, description="社保汇缴基数")
     * @ApiParams   (name="housing_fund_base", type="inter", required=false, description="公积金汇缴基数")
     * @ApiParams   (name="housing_fund_rate", type="inter", required=false, description="公积金汇缴比例")
     *
     * @ApiReturn({
        "code": 1,
        "msg": "请求成功",
        "time": "1601360343",
        "data": {
            "param": { //填过的参数
                "salary": "9753.20", //税前每月工资
                "month": "12", //工作月份
                "annual_bonus": "", //年终奖
                "add_money": "1500", //每月专项附加金额
                "social_base": "", //社保汇缴基数
                "housing_fund_base": "", //公积金汇缴基数
                "housing_fund_rate": "" //公积金汇缴比例
            },
            "plan_a": { //方案A
                "annual_bonus_fee": 0, //年终奖应缴个税
                "new_person_fee": 556.7, //新税法下累计应缴个人所得税
                "new_person_current_fee": 46.39, //新税法下本期应缴个人所得税
                "old_person_current_fee": 354.28, //老税法下本期应缴个人所得税
                "new_current_salary": 8000, //新税法下个人当月到手工资
                "old_current_salary": 7692.11, //老税法下个人当月到手工资
                "new_salary_average": 8000, //新税法下个人平均每月到手工资
                "old_salary_average": 7692.11, //老税法下个人平均每月到手工资
                "cost_new_a": 11411.24 //方案A平均每月用人成本
            },
            "plan_b": { //方案B
                "new_person_fee": 556.7, //新税法下工资与年终奖累计应缴个人所得税
                "new_person_current_fee": 46.39, //新税法下本期应缴个人所得税
                "old_person_current_fee": 354.28, //老税法下本期应缴个人所得税
                "new_current_salary": 8000, //新税法下个人当月到手工资
                "old_current_salary": 7692.11, //老税法下个人当月到手工资
                "new_salary_average": 8000, //新税法下个人平均每月到手工资
                "old_salary_average": 7692.11, //老税法下个人平均每月到手工资
                "cost_new_b": 11411.24 //方案B平均每月用人成本
            },
            "social_user": { //个人五险一金
                "housing_fund": { //基本住房公积金
                    "rate": "7", //比率(%)
                    "money": 682.72 //缴纳金额
                },
                "endowment": { //养老保险金
                    "rate": "8",
                    "money": 780.26
                },
                "medical": { //医疗保险金
                    "rate": "2",
                    "money": 195.06
                },
                "unemployment": { //失业保险金
                    "rate": "0.5",
                    "money": 48.77
                },
                "birth": { //生育保险金
                    "rate": "0",
                    "money": 0
                },
                "industrial": { //工商保险金
                    "rate": "0",
                    "money": 0
                }
            },
            "social_user_money": 1706.81, //个人五险一金合计
            "social_company": { //单位五险一金
                "housing_fund": { //基本住房公积金
                    "rate": "7", //比率(%)
                    "money": 682.72 //缴纳金额
                },
                "endowment": { //养老保险金
                    "rate": "0",
                    "money": 0
                },
                "medical": { //医疗保险金
                    "rate": "9",
                    "money": 877.79
                },
                "unemployment": { //失业保险金
                    "rate": "0",
                    "money": 0
                },
                "birth": { //生育保险金
                    "rate": "1",
                    "money": 97.53
                },
                "industrial": { //工伤保险金
                    "rate": "0",
                    "money": 0
                }
            },
            "social_company_money": 1658.04, //单位五险一金合计
            "user_go": { //税前工资去向
                "salary": 9753.2, //工资
                "zh": [{ //中文
                        "value": 682.72, //金额
                        "name": "个人基本住房公积金" //名称
                    },
                    {
                        "value": 780.26,
                        "name": "个人养老保险金"
                    },
                    {
                        "value": 195.06,
                        "name": "个人医疗保险金"
                    },
                    {
                        "value": 48.77,
                        "name": "个人失业保险金"
                    },
                    {
                        "value": 46.39,
                        "name": "个人所得税"
                    },
                    {
                        "value": 8000,
                        "name": "个人税后月薪"
                    }
                ],
                "en": [{ //英文
                        "value": 682.72,
                        "name": "Per. basic housing funds"
                    },
                    {
                        "value": 780.26,
                        "name": "Per. pension insurance"
                    },
                    {
                        "value": 195.06,
                        "name": "Per. medical insurance"
                    },
                    {
                        "value": 48.77,
                        "name": "Per. unemployment insurance"
                    },
                    {
                        "value": 46.39,
                        "name": "Per. income tax"
                    },
                    {
                        "value": 8000,
                        "name": "After-tax monthly salary"
                    }
                ]
            },
            "company_go": { //单位成本去向
                "cost": 11411.24, //成本
                "zh": [{ //中文
                        "value": 682.72, //金额
                        "name": "企业基本住房公积金" //名称
                    },
                    {
                        "value": 0,
                        "name": "企业养老保险金"
                    },
                    {
                        "value": 877.79,
                        "name": "企业医疗保险金"
                    },
                    {
                        "value": 0,
                        "name": "企业失业保险金"
                    },
                    {
                        "value": 97.53,
                        "name": "企业生育保险金"
                    },
                    {
                        "value": 0,
                        "name": "企业工伤保险金"
                    },
                    {
                        "value": 682.72,
                        "name": "个人基本住房公积金"
                    },
                    {
                        "value": 780.26,
                        "name": "个人养老保险金"
                    },
                    {
                        "value": 195.06,
                        "name": "个人医疗保险金"
                    },
                    {
                        "value": 48.77,
                        "name": "个人失业保险金"
                    },
                    {
                        "value": 46.39,
                        "name": "个人所得税"
                    },
                    {
                        "value": 8000,
                        "name": "个人税后月薪"
                    }
                ],
                "en": [{ //英文
                        "value": 682.72,
                        "name": "Co. basic housing funds"
                    },
                    {
                        "value": 0,
                        "name": "Co. pension insurance"
                    },
                    {
                        "value": 877.79,
                        "name": "Co. medical insurance"
                    },
                    {
                        "value": 0,
                        "name": "Co. unemployment insurance"
                    },
                    {
                        "value": 97.53,
                        "name": "Co. maternity insurance"
                    },
                    {
                        "value": 0,
                        "name": "Co. work injury insurance"
                    },
                    {
                        "value": 682.72,
                        "name": "Personal basic housing funds"
                    },
                    {
                        "value": 780.26,
                        "name": "Personal pension insurance"
                    },
                    {
                        "value": 195.06,
                        "name": "Personal medical insurance"
                    },
                    {
                        "value": 48.77,
                        "name": "Personal unemployment insurance"
                    },
                    {
                        "value": 46.39,
                        "name": "Personal income tax"
                    },
                    {
                        "value": 8000,
                        "name": "After-tax monthly salary"
                    }
                ]
            }
        }
    })
     */
    public function index()
    {
        $param = $this->request->param(); //返回给前端
        $salary = $this->request->param('salary',0);
        $month = $this->request->param('month',0);
        $annual_bonus = $this->request->param('annual_bonus',0);
        $add_money = $this->request->param('add_money',0);
        $social_base = $this->request->param('social_base');
        $housing_fund_base = $this->request->param('housing_fund_base');
        $housing_fund_rate = $this->request->param('housing_fund_rate');
        empty($salary) && $this->error('请输入税前每月工资');
        empty($month) && $this->error('请输入工作月份');
        if(empty($annual_bonus)){
            $annual_bonus = 0;
        }
        if(empty($add_money)){
            $add_money = 0;
        }
        // 累计工资(不含年终奖)
        $salary_total = $salary * $month;
        // 社保基数
        $social_top = config('site.social_top'); //社保封顶金额
        $social_bottom = config('site.social_bottom'); //社保保底金额
        if(!empty($social_base)){
            $social_base > $social_top && $this->error('社保汇缴基数不能大于'.$social_top);
            $social_base < $social_bottom && $this->error('社保汇缴基数不能小于'.$social_bottom);
        }else{
            $social_base = $salary > $social_top ? $social_top : ($salary < $social_bottom ? $social_bottom : $salary);
        }
        // 公积金基数
        $housing_fund_top = config('site.housing_fund_top'); //公积金封顶金额
        $housing_fund_bottom = config('site.housing_fund_bottom'); //公积金保底金额
        if(!empty($housing_fund_base)){
            $housing_fund_base > $housing_fund_top && $this->error('公积金汇缴基数不能大于'.$housing_fund_top);
            $housing_fund_base < $housing_fund_bottom && $this->error('公积金汇缴基数不能小于'.$housing_fund_bottom);
        }else{
            $housing_fund_base = $salary > $housing_fund_top ? $housing_fund_top : ($salary < $housing_fund_bottom ? $housing_fund_bottom : $salary);
        }
        // 公积金缴存比例5%-7%
        $social_rate_user = Db::name('social_insurance_rate')->where('id',1)->find();
        $social_rate_company = Db::name('social_insurance_rate')->where('id',2)->find();
        if(!empty($housing_fund_rate)){
            $housing_fund_rate > 7 && $this->error('公积金汇缴比例不能大于7%');
            $housing_fund_rate < 5 && $this->error('公积金汇缴比例不能小于5%');
        }else{
            $housing_fund_rate = config('site.housing_fund_rate');
        }
        // 每月个人承担的三险比例(其中养老8%,医疗2%,失业0.5%,三种保险总和为10.5%,上海地区个人承担的三种保险比例一致。)
        $social_rate = ($social_rate_user['endowment']+$social_rate_user['medical']+$social_rate_user['unemployment']+$social_rate_user['birth']+$social_rate_user['industrial'])/100;
        // 每月个人承担的三险
        $social_money = $social_base * $social_rate;
        // 每月个人承担的公积金
        $housing_fund = $housing_fund_base * $housing_fund_rate / 100;
        // 累计个人承担的三险
        $social_money_total = $social_money * $month;
        // 累计个人承担的公积金
        $housing_fund_total = $housing_fund * $month;
        // 您的累计6项专项附加及其他项
        $six_fee = $add_money * $month;
        // 公司用人成本
            // 公司工伤的缴款比例(浮动比例0.16%-1.52%,其中:服务业0.258%,生产加工业0.76%,化工及油气1.52%。)
            $industrial_rate_company = $social_rate_company['industrial'];
            // 公司每月承担的养老、医疗、生育、失业比例
            $company_fourxianbili = ($social_rate_company['endowment']+$social_rate_company['medical']+$social_rate_company['unemployment']+$social_rate_company['birth'])/100;
            // 公司每月承担的养老、医疗、生育、失业金额
            $company_fourxian_money = $social_base * $company_fourxianbili;
            // 公司每月承担的工伤金额
            $company_industrial_money = $social_base * $industrial_rate_company/100;
            // 公司每月承担公积金金额
            $company_housing_fund = $housing_fund_base * $housing_fund_rate/100;
            // 新税法下方案A平均每月用人成本(包括年终奖)
            $cost_new_a = $salary + $company_fourxian_money + $company_industrial_money + $company_housing_fund + $annual_bonus/12;
            // 老税法下方案A平均每月用人成本(包括年终奖)
            $cost_old_a = $cost_new_a;
            // 新税法下方案B平均每月用人成本(包括年终奖)
            $cost_new_b = $cost_new_a;
            // 老税法下方案B平均每月用人成本(包括年终奖)
            $cost_old_b = $cost_new_a;
            // 新税法下方案A累计用人成本
            $cost_new_a_total = $cost_new_a * $month;
            // 老税法下方案A累计用人成本
            $cost_old_a_total = $cost_old_a * $month;
            // 新税法下方案B累计用人成本
            $cost_new_b_total = $cost_new_b * $month;
            // 老税法下方案B累计用人成本
            $cost_old_b_total = $cost_old_b * $month;
        // 方案A
        $plan_a = array_merge(
            $this->planA(
                $salary,
                $month,
                $annual_bonus,
                $salary_total,
                $social_money,
                $housing_fund,
                $social_money_total,
                $housing_fund_total,
                $six_fee
            ),[
                'cost_new_a' => round($cost_new_a,2)
            ]
        );
        // 方案B
        $plan_b = array_merge(
            $this->planB(
                $salary,
                $month,
                $salary_total,
                $annual_bonus,
                $social_money,
                $housing_fund,
                $social_money_total,
                $housing_fund_total,
                $six_fee
            ),[
                'cost_new_b' => round($cost_new_b,2)
            ]
        );
        // 五险一金汇缴明细-个人
        $social_user = [
            'housing_fund' => [
                'rate' => $housing_fund_rate,
                'money' => round($housing_fund,2)
            ],
            'endowment' => [
                'rate' => $social_rate_user['endowment'],
                'money' => round($social_base * $social_rate_user['endowment']/100,2)
            ],
            'medical' => [
                'rate' => $social_rate_user['medical'],
                'money' => round($social_base * $social_rate_user['medical']/100,2)
            ],
            'unemployment' => [
                'rate' => $social_rate_user['unemployment'],
                'money' => round($social_base * $social_rate_user['unemployment']/100,2)
            ],
            'birth' => [
                'rate' => $social_rate_user['birth'],
                'money' => round($social_base * $social_rate_user['birth']/100,2)
            ],
            'industrial' => [
                'rate' => $social_rate_user['industrial'],
                'money' => round($social_base * $social_rate_user['industrial']/100,2)
            ],
        ];
        // 五险一金汇缴明细-个人合计
        $social_user_money = round(array_sum(array_map(function($val){return $val['money'];}, $social_user)),2);
        // 五险一金汇缴明细-单位
        $social_company = [
            'housing_fund' => [
                'rate' => $housing_fund_rate,
                'money' => round($company_housing_fund,2)
            ],
            'endowment' => [
                'rate' => $social_rate_company['endowment'],
                'money' => round($social_base * $social_rate_company['endowment']/100,2)
            ],
            'medical' => [
                'rate' => $social_rate_company['medical'],
                'money' => round($social_base * $social_rate_company['medical']/100,2)
            ],
            'unemployment' => [
                'rate' => $social_rate_company['unemployment'],
                'money' => round($social_base * $social_rate_company['unemployment']/100,2)
            ],
            'birth' => [
                'rate' => $social_rate_company['birth'],
                'money' => round($social_base * $social_rate_company['birth']/100,2)
            ],
            'industrial' => [
                'rate' => $industrial_rate_company,
                'money' => round($company_industrial_money,2)
            ],
        ];
        // 五险一金汇缴明细-单位合计
        $social_company_money = round(array_sum(array_map(function($val){return $val['money'];}, $social_company)),2);
        // 税前工资去向
        $user_go = [
        	'salary' => round($salary,2),
        	'zh' => [
        		[
        			'value' => $social_user['housing_fund']['money'],
        			'name' => '个人基本住房公积金',
        		],
        		[
        			'value' => $social_user['endowment']['money'],
        			'name' => '个人养老保险金',
        		],
        		[
        			'value' => $social_user['medical']['money'],
        			'name' => '个人医疗保险金',
        		],
        		[
        			'value' => $social_user['unemployment']['money'],
        			'name' => '个人失业保险金',
        		],
        		[
        			'value' => $plan_a['new_person_current_fee'],
        			'name' => '个人所得税',
        		],
        		[
        			'value' => $plan_a['new_current_salary'],
        			'name' => '个人税后月薪',
        		],
        	],
            'en' => [
                [
                    'value' => $social_user['housing_fund']['money'],
                    'name'=>'Per. basic housing funds',
                ],
                [
                    'value' => $social_user['endowment']['money'],
                    'name' => 'Per. pension insurance',
                ],
                [
                    'value' => $social_user['medical']['money'],
                    'name' => 'Per. medical insurance',
                ],
                [
                    'value' => $social_user['unemployment']['money'],
                    'name' => 'Per. unemployment insurance',
                ],
                [
                    'value' => $plan_a['new_person_current_fee'],
                    'name' => 'Per. income tax',
                ],
                [
                    'value' => $plan_a['new_current_salary'],
                    'name' => 'After-tax monthly salary',
                ],
            ],
        ];
        // 单位成本去向
        $company_go = [
        	'cost' => round($cost_new_a,2),
        	'zh' => array_merge([
        		[
        			'value' => $social_company['housing_fund']['money'],
        			'name' => '企业基本住房公积金',
        		],
        		[
        			'value' => $social_company['endowment']['money'],
        			'name' => '企业养老保险金',
        		],
        		[
        			'value' => $social_company['medical']['money'],
        			'name' => '企业医疗保险金',
        		],
        		[
        			'value' => $social_company['unemployment']['money'],
        			'name' => '企业失业保险金',
        		],
        		[
        			'value' => $social_company['birth']['money'],
        			'name' => '企业生育保险金',
        		],
        		[
        			'value' => $social_company['industrial']['money'],
        			'name' => '企业工伤保险金',
        		]
        	],$user_go['zh']),
            'en' => array_merge([
                [
                    'value' => $social_company['housing_fund']['money'],
                    'name'=>'Co. basic housing funds',
                ],
                [
                    'value' => $social_company['endowment']['money'],
                    'name' => 'Co. pension insurance',
                ],
                [
                    'value' => $social_company['medical']['money'],
                    'name' => 'Co. medical insurance',
                ],
                [
                    'value' => $social_company['unemployment']['money'],
                    'name' => 'Co. unemployment insurance',
                ],
                [
                    'value' => $social_company['birth']['money'],
                    'name' => 'Co. maternity insurance',
                ],
                [
                    'value' => $social_company['industrial']['money'],
                    'name' => 'Co. work injury insurance',
                ]
            ],$user_go['en']),
        ];
        $this->success('请求成功',compact('param','plan_a','plan_b','social_user','social_user_money','social_company','social_company_money','user_go','company_go'));
    }

    /**
     * 方案A
     * @ApiInternal
     */
    public function planA($salary,$month,$annual_bonus,$salary_total,$social_money,$housing_fund,$social_money_total,$housing_fund_total,$six_fee){
        // 一、年终奖应缴个税计算
            // 按国税发〔2005〕9号文号计算年终奖应缴个税
            $tax_rate_bonus = db('tax_rate_bonus')->order('level desc')->select();
            $annual_bonus_fee = 0;
            foreach ($tax_rate_bonus as $v) {
                if($annual_bonus/12 > $v['money']){
                    $annual_bonus_fee = $annual_bonus*$v['tax_rate']/100 - $v['dec_fee'];
                    break;
                }
            }
        // 二、工资全年应缴个人所得税计算
            // 累计工资(不含年终奖)
            $salary_total = $salary_total;
            // 每月可扣除费用
            $money_dec = 5000;
            // 累计可扣除的费用(6万/年)
            $dec_fee = $money_dec * $month;
            // 累计专项扣除金额(全年三险一金)
            $san_gong_money_total = $social_money_total + $housing_fund_total;
            // 新税法下累计应纳税所得额
            $new_fee = $salary_total-$dec_fee-$san_gong_money_total-$six_fee;
            // 老税法下本期应纳税所得额
            $old_current_fee = $salary-3500-$social_money-$housing_fund;
            // 新税法下累计应缴个人所得税
            $tax_rate_new = db('tax_rate_new')->order('level desc')->select();
            $new_person_fee = 0;
            foreach ($tax_rate_new as $v) {
                if($new_fee > $v['money_have_tax']){
                    $new_person_fee = $new_fee*$v['tax_rate']/100 - $v['dec_fee'];
                    break;
                }
            }
            // 新税法下累计已预缴个人所得税
            $var1 = $salary*($month-1)-($social_money+$housing_fund)*($month-1)-$six_fee/$month*($month-1)-$money_dec*($month-1);
            $new_pre_person_fee = 0;
            foreach ($tax_rate_new as $v) {
                if($var1 > $v['money_have_tax']){
                    $new_pre_person_fee = $var1*$v['tax_rate']/100 - $v['dec_fee'];
                    break;
                }
            }
            // 新税法下本期应缴个人所得税
            $new_person_current_fee = $new_person_fee - $new_pre_person_fee;
            // 老税法下本期应缴个人所得税
            $tax_rate_old = db('tax_rate_old')->order('level desc')->select();
            $old_person_current_fee = 0;
            foreach ($tax_rate_old as $v) {
            	if($old_current_fee > $v['money_have_tax']){
                    $old_person_current_fee = $old_current_fee*$v['tax_rate']/100 - $v['dec_fee'];
                    break;
                }
            }
            // 新税法下个人当月到手工资
            $new_current_salary = ($salary - $social_money - $housing_fund - $new_person_current_fee) + ($annual_bonus - $annual_bonus_fee) / 12;
            // 老税法下个人当月到手工资
            $old_current_salary = $salary - $social_money - $housing_fund - $old_person_current_fee + ($annual_bonus - $annual_bonus_fee) / 12;
            // 新税法下个人累计到手工资及年终奖总和
            $new_saan_total = $salary_total - $san_gong_money_total - $new_person_fee + ($annual_bonus - $annual_bonus_fee)/12*$month;
            // 老税法下个人累计到手工资及年终奖总和
            $old_saan_total = $old_current_salary * $month + $annual_bonus - $annual_bonus_fee;
            // 新税法下个人平均每月到手工资
            $new_salary_average = $new_saan_total/$month;
            // 老税法下个人平均每月到手工资
            $old_salary_average = $old_current_salary;
        // 新税法下工资与年终奖合计累计应缴个人所得税
        $new_saan_total_person_fee = $annual_bonus_fee + $new_person_fee;
        // 老税法下工资与年终奖合计累计应缴个人所得税
        $old_saan_total_person_fee = $annual_bonus_fee + $old_person_current_fee * $month;
        return [
        	'annual_bonus_fee' => round($annual_bonus_fee,2),
        	'new_person_fee' => round($new_person_fee,2),
        	'new_person_current_fee' => round($new_person_current_fee,2),
        	'old_person_current_fee' => round($old_person_current_fee,2),
        	'new_current_salary' => round($new_current_salary,2),
        	'old_current_salary' => round($old_current_salary,2),
        	'new_salary_average' => round($new_salary_average,2),
        	'old_salary_average' => round($old_salary_average,2)
        ];
    }

    /**
     * 方案B
     * @ApiInternal
     */
    public function planB($salary,$month,$salary_total,$annual_bonus,$social_money,$housing_fund,$social_money_total,$housing_fund_total,$six_fee){
        // 全年年终奖累计计入工资进行交税金额
        $annual_bonus_fee = $annual_bonus/12*$month;
        // 每月可扣除费用
        $money_dec = 5000;
        // 累计可扣除的费用(6万/年)
        $dec_fee = $money_dec * $month;
        // 累计专项扣除金额(全年三险一金)
        $san_gong_money_total = $social_money_total + $housing_fund_total;
        // 累计应纳税所得额
        $submit_fee = $salary_total + $annual_bonus_fee - $dec_fee - $san_gong_money_total - $six_fee;
        // 新税法下工资与年终奖累计应缴个人所得税
        $tax_rate_new = db('tax_rate_new')->order('level desc')->select();
        $new_person_fee = 0;
        foreach ($tax_rate_new as $v) {
            if($submit_fee > $v['money_have_tax']){
                $new_person_fee = $submit_fee*$v['tax_rate']/100 - $v['dec_fee'];
                break;
            }
        }
        // 新税法下累计已预缴个人所得税
        $new_pre_person_fee = 0;
        $var1 = $salary*($month-1) + $annual_bonus/12*($month-1) - ($social_money+$housing_fund)*($month-1) - $six_fee/$month*($month-1) - $money_dec*($month-1);
        foreach ($tax_rate_new as $v) {
            if($var1 > $v['money_have_tax']){
                $new_pre_person_fee = $var1*$v['tax_rate']/100 - $v['dec_fee'];
                break;
            }
        }
        // 新税法下本期应缴个人所得税
        $new_person_current_fee = $new_person_fee - $new_pre_person_fee;
        // 老税法下本期应缴个人所得税
        $tax_rate_old = db('tax_rate_old')->order('level desc')->select();
        $old_person_current_fee = 0;
        $var2 = $salary + $annual_bonus/12 - 3500 - $social_money - $housing_fund;
        foreach ($tax_rate_old as $v) {
        	if($var2 > $v['money_have_tax']){
                $old_person_current_fee = $var2*$v['tax_rate']/100 - $v['dec_fee'];
                break;
            }
        }
        // 新税法下个人当月到手工资
        $new_current_salary = $salary + $annual_bonus/12 - $social_money - $housing_fund - $new_person_current_fee;
        // 老税法下个人当月到手工资
        $old_current_salary = $salary+$annual_bonus/12-$social_money-$housing_fund-$old_person_current_fee;
        // 新税法下个人累计到手工资及年终奖总和
        $new_saan_total = $salary_total+$annual_bonus/12*$month-$social_money_total-$housing_fund_total-$new_person_fee;
        // 老税法下个人累计到手工资及年终奖总和
        $old_saan_total = $old_current_salary*$month;
        // 新税法下个人平均每月到手工资
        $new_salary_average = $new_saan_total/$month;
        // 老税法下个人平均每月到手工资
        $old_salary_average = $old_current_salary;
        return [
        	'new_person_fee' => round($new_person_fee,2),
        	'new_person_current_fee' => round($new_person_current_fee,2),
        	'old_person_current_fee' => round($old_person_current_fee,2),
        	'new_current_salary' => round($new_current_salary,2),
        	'old_current_salary' => round($old_current_salary,2),
        	'new_salary_average' => round($new_salary_average,2),
        	'old_salary_average' => round($old_salary_average,2)
        ];
    }


    /**
     * @ApiTitle    (住房公积金汇缴比例)
     * @ApiSummary  (住房公积金汇缴比例)
     * @ApiMethod   (POST)
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1601280074",
        "data": {
            "housing_fund_rate": "7", //住房公积金汇缴比例
            "housing_fund_rate_option": { //住房公积金汇缴比例-选项
                "1": "5", //选项-取值即可
                "2": "6",
                "3": "7"
            }
        }
    })
     */
    public function getHousingFundRate(){
        $housing_fund_rate = config('site.housing_fund_rate');
        $housing_fund_rate_option = config('site.housing_fund_rate_option');
        $this->success('成功',compact('housing_fund_rate','housing_fund_rate_option'));
    }

    /**
     * @ApiTitle    (社保和公积金汇缴基数-税前)
     * @ApiSummary  (社保和公积金汇缴基数-税前)
     * @ApiMethod   (POST)
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1602306155",
        "data": {
            "social_top": "28017", //社保汇缴基数封顶金额
            "social_bottom": "4927", //社保汇缴基数保底金额
            "housing_fund_top": "28017", //公积金汇缴基数封顶金额
            "housing_fund_bottom": "2480" //公积金汇缴基数保底金额
        }
    })
     */
    public function getBase(){
        // 社保基数
        $social_top = config('site.social_top'); //社保封顶金额
        $social_bottom = config('site.social_bottom'); //社保保底金额
        // 公积金基数
        $housing_fund_top = config('site.housing_fund_top'); //公积金封顶金额
        $housing_fund_bottom = config('site.housing_fund_bottom'); //公积金保底金额
        $this->success('成功',compact('social_top','social_bottom','housing_fund_top','housing_fund_bottom'));
    }
}