<?php

namespace App\Http\Controllers\Admin;

use App\Model\Adminuser;
use App\Model\Project;
use App\Model\Table_eight;
use App\Model\Table_five;
use App\Model\Table_four;
use App\Model\Table_nine;
use App\Model\Table_one;
use App\Model\Table_seven;
use App\Model\Table_six;
use App\Model\Table_three;
use App\Model\Table_two;
use App\Model\Tablelist;
use App\Http\Controllers\Admin\CommonController;
use App\Model\User;
use Illuminate\Support\Facades\DB;
use Session;
use Symfony\Component\HttpFoundation\Request;

class SearchController extends CommonController
{

    public function table_search(Request $request,$table_type_id)
    {
        $user_data = User::where('role','=','0')->get();
        $input = $request->all();

        if (isset($table_type_id)) {
            switch ($table_type_id) {
                case 1:
                    $table_name = '国有土地房屋征收与补偿安置单（货币化安置）';
                    $th = [
                        '1' => '姓名',
                        '2' => '购买存量房面积',
                        '3' => '拆迁补偿总金额',
                        '4' => '购买存量房总价格',
                        '5' => '应交总差额',
                        '6' => '应退总差额'
                    ];
                    //都不搜索  显示表单姓名
                    if(empty($input['user_id']) && empty($input['project_id']))
                    {
                        $table = Table_one::query()
                            ->where('status','>','1')
                            ->groupBy('bzc_name')
                            ->selectRaw('bzc_name')
                            ->selectRaw('SUM(home_area+money_bus_area) as area')
                            ->selectRaw('SUM(total_money) as total_money')
                            ->selectRaw('SUM(money_home_price+money_bus_price) as price')
                            ->selectRaw('SUM(money_home_jchae+money_bus_jchae) as jchae ')
                            ->selectRaw('SUM(money_home_tchae+money_bus_tchae) as tchae')
                            ;
                        $table = $input['start_time'] != '' ? $table->where('created_at', '>', $input['start_time']) : $table;
                        $table = $input['end_time'] != '' ? $table->where('created_at', '<', $input['end_time']) : $table;
                        $table = $table->get();
                    }
                    //搜索录入人  显示收录人
                    if(!empty($input['user_id'])&& empty($input['project_id']))
                    {
                        $table = Table_one::query()
                            ->where('status','>','1')
                            ->where('user_id','=',$input['user_id'])
                            ->groupBy('id')
                            ->selectRaw('user_id')
                            ->selectRaw('SUM(home_area+money_bus_area) as area')
                            ->selectRaw('SUM(total_money) as total_money')
                            ->selectRaw('SUM(money_home_price+money_bus_price) as price')
                            ->selectRaw('SUM(money_home_jchae+money_bus_jchae) as jchae ')
                            ->selectRaw('SUM(money_home_tchae+money_bus_tchae) as tchae')
                            ;
                        $th[1] = '收录人';
                        $table = $input['start_time'] != '' ? $table->where('created_at', '>', $input['start_time']) : $table;
                        $table = $input['end_time'] != '' ? $table->where('created_at', '<', $input['end_time']) : $table;
                        $table = $table->get();
                        foreach($table as $value){
                            $value['bzc_name'] = User::where('id','=',$value['user_id'])->first()->surname;
                        }
                    }
                    //搜索项目  显示项目名
                    if(!empty($input['project_id']) && empty($input['user_id'])){
                        $table = Table_one::query()
                            ->where('project_id','=',$input['project_id'])
                            ->where('status','>','1')
                            ->groupBy('id')
                            ->selectRaw('project_id')
                            ->selectRaw('SUM(home_area+money_bus_area) as area')
                            ->selectRaw('SUM(total_money) as total_money')
                            ->selectRaw('SUM(money_home_price+money_bus_price) as price')
                            ->selectRaw('SUM(money_home_jchae+money_bus_jchae) as jchae ')
                            ->selectRaw('SUM(money_home_tchae+money_bus_tchae) as tchae')
                           ;
                        $th[1] = '项目';
                        $table = $input['start_time'] != '' ? $table->where('created_at', '>', $input['start_time']) : $table;
                        $table = $input['end_time'] != '' ? $table->where('created_at', '<', $input['end_time']) : $table;
                        $table = $table->get();
                        foreach($table as $value){
                            $value['bzc_name'] = Project::where('id','=',$value['project_id'])->first()->project_name;
                        }
                    }
                    //搜索收录人 项目名 显示收录人
                    if(!empty($input['project_id']) && !empty($input['user_id'])){
                        $table = Table_one::query()
                            ->where('status','>','1')
                            ->where('user_id','=',$input['user_id'])
                            ->where('project_id','=',$input['project_id'])
                            ->groupBy('id')
                            ->selectRaw('user_id')
                            ->selectRaw('SUM(home_area+money_bus_area) as area')
                            ->selectRaw('SUM(total_money) as total_money')
                            ->selectRaw('SUM(money_home_price+money_bus_price) as price')
                            ->selectRaw('SUM(money_home_jchae+money_bus_jchae) as jchae ')
                            ->selectRaw('SUM(money_home_tchae+money_bus_tchae) as tchae')
                            ;
                        $th[1] = '收录人';
                        $table = $input['start_time'] != '' ? $table->where('created_at', '>', $input['start_time']) : $table;
                        $table = $input['end_time'] != '' ? $table->where('created_at', '<', $input['end_time']) : $table;
                        $table = $table->get();
                        foreach($table as $value){
                            $value['bzc_name'] = User::where('id','=',$value['user_id'])->first()->surname;
                        }
                    }
                    return view('admin.sta.sta_one', compact('user_data','table_name', 'table', 'th', 'table_type_id'));
                    break;

                case 2:
                    $table_name = '违章建筑自行拆除费用申领表';
                    $th = [
                        '1' => '姓名',
                        '2' => '违章面积',
                        '3' => '拆除金额',
                    ];
                    if(empty($input['user_id']) && empty($input['project_id'])){
                        $table = Table_two::query()
                            ->where('status','>','1')
                            ->groupBy('bzc_name')
                            ->selectRaw('bzc_name')
                            ->selectRaw('SUM(bzc_area) as area')
                            ->selectRaw('SUM(chaichuje)as money')
                        ;
                        $table = $input['start_time'] != '' ? $table->where('created_at', '>', $input['start_time']) : $table;
                        $table = $input['end_time'] != '' ? $table->where('created_at', '<', $input['end_time']) : $table;
                        $table = $table->get();

                    }
                    if(!empty($input['user_id'])&& empty($input['project_id'])){
                        $table = Table_two::query()
                            ->where('status','>','1')
                            ->where('user_id','=',$input['user_id'])
                            ->groupBy('id')
                            ->selectRaw('user_id')
                            ->selectRaw('SUM(bzc_area) as area')
                            ->selectRaw('SUM(chaichuje)as money')
                        ;
                        $th[1] = '收录人';
                        $table = $input['start_time'] != '' ? $table->where('created_at', '>', $input['start_time']) : $table;
                        $table = $input['end_time'] != '' ? $table->where('created_at', '<', $input['end_time']) : $table;
                        $table = $table->get();
                        foreach($table as $value){
                            $value['bzc_name'] = User::where('id','=',$value['user_id'])->first()->surname;
                        }
                    }
                    if(!empty($input['project_id']) && empty($input['user_id'])){
                        $table = Table_two::query()
                            ->where('status','>','1')
                            ->where('project_id','=',$input['project_id'])
                            ->groupBy('id')
                            ->selectRaw('project_id')
                            ->selectRaw('SUM(bzc_area) as area')
                            ->selectRaw('SUM(chaichuje)as money')
                        ;
                        $table = $input['start_time'] != '' ? $table->where('created_at', '>', $input['start_time']) : $table;
                        $table = $input['end_time'] != '' ? $table->where('created_at', '<', $input['end_time']) : $table;
                        $table = $table->get();
                        foreach($table as $value){
                            $value['bzc_name'] = Project::where('id','=',$value['project_id'])->first()->project_name;
                        }

                    }
                    if(!empty($input['project_id']) && !empty($input['user_id'])){
                        $table = Table_three::query()
                            ->where('status','>','1')
                            ->where('user_id','=',$input['user_id'])
                            ->where('project_id','=',$input['project_id'])
                            ->groupBy('id')
                            ->selectRaw('user_id')
                            ->selectRaw('SUM(bzc_area) as area')
                            ->selectRaw('SUM(chaichuje)as money')
                        ;
                        $table = $input['start_time'] != '' ? $table->where('created_at', '>', $input['start_time']) : $table;
                        $table = $input['end_time'] != '' ? $table->where('created_at', '<', $input['end_time']) : $table;
                        $table = $table->get();
                        foreach($table as $value){
                            $value['bzc_name'] = User::where('id','=',$value['user_id'])->first()->surname;
                        }
                    }
                    return view('admin.sta.sta_two', compact('table_type_id','user_data','table_name', 'table', 'th'));
                    break;

                case 3:
                    $table_name = '残疾人房征补贴审批确认单';
                    $th = [
                        '1' => '姓名',
                        '2' => '残疾人补贴',
                        '3' => '临时安置补贴	',
                        '4' => '搬迁补贴',
                        '5' => '合计'
                    ];
                    if(empty($input['user_id']) && empty($input['project_id'])){
                        $table = Table_three::query()
                            ->where('status','>','1')
                            ->groupBy('bzc_name')
                            ->selectRaw('bzc_name')
                            ->selectRaw('SUM(canbu) as canbu')
                            ->selectRaw('SUM(linshibu)as linshibu')
                            ->selectRaw('SUM(banqianbu) as banqianbu')
                            ->selectRaw('SUM(total) as total')
                        ;
                        $table = $input['start_time'] != '' ? $table->where('created_at', '>', $input['start_time']) : $table;
                        $table = $input['end_time'] != '' ? $table->where('created_at', '<', $input['end_time']) : $table;
                        $table = $table->get();

                    }
                    if(!empty($input['user_id'])&& empty($input['project_id'])){
                        $table = Table_three::query()
                            ->where('status','>','1')
                            ->where('user_id','=',$input['user_id'])
                            ->groupBy('id')
                            ->selectRaw('user_id')
                            ->selectRaw('SUM(canbu) as canbu')
                            ->selectRaw('SUM(linshibu)as linshibu')
                            ->selectRaw('SUM(banqianbu) as banqianbu')
                            ->selectRaw('SUM(total) as total')
                        ;
                        $th[1] = '收录人';
                        $table = $input['start_time'] != '' ? $table->where('created_at', '>', $input['start_time']) : $table;
                        $table = $input['end_time'] != '' ? $table->where('created_at', '<', $input['end_time']) : $table;
                        $table = $table->get();
                        foreach($table as $value){
                            $value['bzc_name'] = User::where('id','=',$value['user_id'])->first()->surname;
                        }
                    }
                    if(!empty($input['project_id']) && empty($input['user_id'])){
                        $table = Table_three::query()
                            ->where('status','>','1')
                            ->where('project_id','=',$input['project_id'])
                            ->groupBy('id')
                            ->selectRaw('project_id')
                            ->selectRaw('SUM(canbu) as canbu')
                            ->selectRaw('SUM(linshibu)as linshibu')
                            ->selectRaw('SUM(banqianbu) as banqianbu')
                            ->selectRaw('SUM(total) as total')
                        ;
                        $th[1] = '项目';
                        $table = $input['start_time'] != '' ? $table->where('created_at', '>', $input['start_time']) : $table;
                        $table = $input['end_time'] != '' ? $table->where('created_at', '<', $input['end_time']) : $table;
                        $table = $table->get();
                        foreach($table as $value){
                            $value['bzc_name'] = Project::where('id','=',$value['project_id'])->first()->project_name;
                        }
                    }
                    if(!empty($input['project_id']) && !empty($input['user_id'])){
                        $table = Table_three::query()
                            ->where('status','>','1')
                            ->where('project_id','=',$input['project_id'])
                            ->where('user_id','=',$input['user_id'])
                            ->groupBy('id')
                            ->selectRaw('project_id')
                            ->selectRaw('SUM(canbu) as canbu')
                            ->selectRaw('SUM(linshibu)as linshibu')
                            ->selectRaw('SUM(banqianbu) as banqianbu')
                            ->selectRaw('SUM(total) as total')
                        ;
                        $th[1] = '收录人';
                        $table = $input['start_time'] != '' ? $table->where('created_at', '>', $input['start_time']) : $table;
                        $table = $input['end_time'] != '' ? $table->where('created_at', '<', $input['end_time']) : $table;
                        $table = $table->get();
                        foreach($table as $value){
                            $value['bzc_name'] = User::where('id','=',$value['user_id'])->first()->surname;
                        }
                    }
                    return view('admin.sta.sta_three', compact('table_type_id','user_data','user_data','table_name', 'table', 'th'));
                    break;

                case 4:
                    $table_name = '房屋征收提前搬迁奖励单';
                    $th = [
                        '1' => '姓名',
                        '2' => '全额奖励',
                        '3' => '差额奖励金',
                        '4' => '同住奖励',
                        '5' => '奖励总金额',
                    ];
                    if(empty($input['user_id']) && empty($input['project_id'])){
                        $table = Table_four::query()
                            ->where('status','>','1')
                            ->groupBy('bzc_name')
                            ->selectRaw('bzc_name')
                            ->selectRaw('SUM(quanj) as quanj')
                            ->selectRaw('SUM(chaj)as chaj')
                            ->selectRaw('SUM(tongj) as tongj')
                            ->selectRaw('SUM(zongj) as zongj')
                        ;
                        $table = $input['start_time'] != '' ? $table->where('created_at', '>', $input['start_time']) : $table;
                        $table = $input['end_time'] != '' ? $table->where('created_at', '<', $input['end_time']) : $table;
                        $table = $table->get();
                    }
                    if(!empty($input['user_id'])&& empty($input['project_id'])){
                        $table = Table_four::query()
                            ->where('status','>','1')
                            ->where('user_id','=',$input['user_id'])
                            ->groupBy('id')
                            ->selectRaw('user_id')
                            ->selectRaw('SUM(quanj) as quanj')
                            ->selectRaw('SUM(chaj)as chaj')
                            ->selectRaw('SUM(tongj) as tongj')
                            ->selectRaw('SUM(zongj) as zongj')
                        ;
                        $th[1] = '收录人';
                        $table = $input['start_time'] != '' ? $table->where('created_at', '>', $input['start_time']) : $table;
                        $table = $input['end_time'] != '' ? $table->where('created_at', '<', $input['end_time']) : $table;
                        $table = $table->get();
                        foreach($table as $value){
                            $value['bzc_name'] = User::where('id','=',$value['user_id'])->first()->surname;
                        }
                    }
                    if(!empty($input['project_id']) && empty($input['user_id'])){
                        $table = Table_four::query()
                            ->where('status','>','1')
                            ->where('project_id','=',$input['project_id'])
                            ->groupBy('id')
                            ->selectRaw('project_id')
                            ->selectRaw('SUM(quanj) as quanj')
                            ->selectRaw('SUM(chaj)as chaj')
                            ->selectRaw('SUM(tongj) as tongj')
                            ->selectRaw('SUM(zongj) as zongj')
                        ;
                        $th[1] = '项目';
                        $table = $input['start_time'] != '' ? $table->where('created_at', '>', $input['start_time']) : $table;
                        $table = $input['end_time'] != '' ? $table->where('created_at', '<', $input['end_time']) : $table;
                        $table = $table->get();
                        foreach($table as $value){
                            $value['bzc_name'] = Project::where('id','=',$value['project_id'])->first()->project_name;
                        }
                    }
                    if(!empty($input['project_id']) && !empty($input['user_id'])){
                        $table = Table_four::query()
                            ->where('status','>','1')
                            ->where('project_id','=',$input['project_id'])
                            ->where('user_id','=',$input['user_id'])
                            ->groupBy('id')
                            ->selectRaw('user_id')
                            ->selectRaw('SUM(quanj) as quanj')
                            ->selectRaw('SUM(chaj)as chaj')
                            ->selectRaw('SUM(tongj) as tongj')
                            ->selectRaw('SUM(zongj) as zongj')
                        ;
                        $th[1] = '收录人';
                        $table = $input['start_time'] != '' ? $table->where('created_at', '>', $input['start_time']) : $table;
                        $table = $input['end_time'] != '' ? $table->where('created_at', '<', $input['end_time']) : $table;
                        $table = $table->get();
                        foreach($table as $value){
                            $value['bzc_name'] = User::where('id','=',$value['user_id'])->first()->surname;
                        }
                    }
                    return view('admin.sta.sta_four', compact('table_type_id','user_data','table_name', 'table', 'th'));
                    break;

                case 5:
                    $table_name = '逾期过渡安置补助费发放单';
                    $th = [
                        '1' => '姓名',
                        '2' => '逾期月数',
                        '3' => '补助合计',
                        '4' => '逾期补偿金',
                    ];
                    if(empty($input['user_id']) && empty($input['project_id'])){
                        $table = Table_five::query()
                            ->where('status','>','1')
                            ->groupBy('bzc_name')
                            ->selectRaw('bzc_name')
                            ->selectRaw('SUM(yuqi_mothe1+yuqi_mothe2+yuqi_mothe3+yuqi_mothe4) as yuqi_mothe')
                            ->selectRaw('SUM(total1+total2+total3+total4)as total')
                            ->selectRaw('SUM(yuqij) as yuqij')
                        ;
                        $table = $input['start_time'] != '' ? $table->where('created_at', '>', $input['start_time']) : $table;
                        $table = $input['end_time'] != '' ? $table->where('created_at', '<', $input['end_time']) : $table;
                        $table = $table->get();
                    }
                    if(!empty($input['user_id'])&& empty($input['project_id'])){
                        $table = Table_five::query()
                            ->where('status','>','1')
                            ->where('user_id','=',$input['user_id'])
                            ->groupBy('id')
                            ->selectRaw('user_id')
                            ->selectRaw('SUM(yuqi_mothe1+yuqi_mothe2+yuqi_mothe3+yuqi_mothe4) as yuqi_mothe')
                            ->selectRaw('SUM(total1+total2+total3+total4)as total')
                            ->selectRaw('SUM(yuqij) as yuqij')
                        ;
                        $th = '收录人';
                        $table = $input['start_time'] != '' ? $table->where('created_at', '>', $input['start_time']) : $table;
                        $table = $input['end_time'] != '' ? $table->where('created_at', '<', $input['end_time']) : $table;
                        $table = $table->get();
                        foreach($table as $value){
                            $value['bzc_name'] = User::where('id','=',$input['user_id'])->first()->surname;
                        }
                    }
                    if(!empty($input['project_id']) && empty($input['user_id'])){
                        $table = Table_five::query()
                            ->where('status','>','1')
                            ->where('project_id','=',$input['project_id'])
                            ->groupBy('id')
                            ->selectRaw('project_id')
                            ->selectRaw('SUM(yuqi_mothe1+yuqi_mothe2+yuqi_mothe3+yuqi_mothe4) as yuqi_mothe')
                            ->selectRaw('SUM(total1+total2+total3+total4)as total')
                            ->selectRaw('SUM(yuqij) as yuqij')
                        ;
                        $th = '项目';
                        $table = $input['start_time'] != '' ? $table->where('created_at', '>', $input['start_time']) : $table;
                        $table = $input['end_time'] != '' ? $table->where('created_at', '<', $input['end_time']) : $table;
                        $table = $table->get();
                        foreach($table as $value){
                            $value['bzc_name'] = Project::where('id','=',$input['project_id'])->first()->project_name;
                        }
                    }
                    if(!empty($input['project_id']) && !empty($input['user_id'])){
                        $table = Table_five::query()
                            ->where('status','>','1')
                            ->where('user_id','=',$input['user_id'])
                            ->where('project_id','=',$input['project_id'])
                            ->groupBy('id')
                            ->selectRaw('user_id')
                            ->selectRaw('SUM(yuqi_mothe1+yuqi_mothe2+yuqi_mothe3+yuqi_mothe4) as yuqi_mothe')
                            ->selectRaw('SUM(total1+total2+total3+total4)as total')
                            ->selectRaw('SUM(yuqij) as yuqij')
                        ;
                        $th = '收录人';
                        $table = $input['start_time'] != '' ? $table->where('created_at', '>', $input['start_time']) : $table;
                        $table = $input['end_time'] != '' ? $table->where('created_at', '<', $input['end_time']) : $table;
                        $table = $table->get();
                        foreach($table as $value){
                            $value['bzc_name'] = User::where('id','=',$input['user_id'])->first()->surname;
                        }
                    }
                    return view('admin.sta.sta_five', compact('table_type_id','user_data','table_name', 'table', 'th'));
                    break;

                case 6:
                    $table_name = '房屋征收安置补贴单';
                    $th = [
                        '1' => '姓名',
                        '2' => '临时安置费',
                        '3' => '搬迁费',
                        '4' => '低保补贴',
                        '5' => '其他',
                        '6' => '补贴总金额',
                    ];
                    if(empty($input['user_id']) && empty($input['project_id'])){
                        $table = Table_six::query()
                            ->where('status','>','1')
                            ->groupBy('bzc_name')
                            ->selectRaw('bzc_name')
                            ->selectRaw('SUM(anzhi) as anzhi')
                            ->selectRaw('SUM(banqian)as banqian')
                            ->selectRaw('SUM(dibu) as dibu')
                            ->selectRaw('SUM(other) as other')
                            ->selectRaw('SUM(totalj) as totalj')
                        ;
                        $table = $input['start_time'] != '' ? $table->where('created_at', '>', $input['start_time']) : $table;
                        $table = $input['end_time'] != '' ? $table->where('created_at', '<', $input['end_time']) : $table;
                        $table = $table->get();
                    }
                    if(!empty($input['user_id'])&& empty($input['project_id'])){
                        $table = Table_six::query()
                            ->where('status','>','1')
                            ->where('user_id','=',$input['user_id'])
                            ->groupBy('id')
                            ->selectRaw('user_id')
                            ->selectRaw('SUM(anzhi) as anzhi')
                            ->selectRaw('SUM(banqian)as banqian')
                            ->selectRaw('SUM(dibu) as dibu')
                            ->selectRaw('SUM(other) as other')
                            ->selectRaw('SUM(totalj) as totalj')
                        ;
                        $th[1] = '收录人';
                        $table = $input['start_time'] != '' ? $table->where('created_at', '>', $input['start_time']) : $table;
                        $table = $input['end_time'] != '' ? $table->where('created_at', '<', $input['end_time']) : $table;
                        $table = $table->get();
                        foreach($table as $value){
                            $value['bzc_name'] = User::where('id','=',$input['user_id'])->first()->surname;
                        }
                    }
                    if(!empty($input['project_id']) && empty($input['user_id'])){
                        $table = Table_six::query()
                            ->where('status','>','1')
                            ->where('project_id','=',$input['project_id'])
                            ->groupBy('id')
                            ->selectRaw('project_id')
                            ->selectRaw('SUM(anzhi) as anzhi')
                            ->selectRaw('SUM(banqian)as banqian')
                            ->selectRaw('SUM(dibu) as dibu')
                            ->selectRaw('SUM(other) as other')
                            ->selectRaw('SUM(totalj) as totalj')
                        ;
                        $th[1] = '项目';
                        $table = $input['start_time'] != '' ? $table->where('created_at', '>', $input['start_time']) : $table;
                        $table = $input['end_time'] != '' ? $table->where('created_at', '<', $input['end_time']) : $table;
                        $table = $table->get();
                        foreach($table as $value){
                            $value['bzc_name'] = Project::where('id','=',$input['project_id'])->first()->project_name;
                        }
                    }
                    if(!empty($input['project_id']) && !empty($input['user_id'])){
                        $table = Table_six::query()
                            ->where('status','>','1')
                            ->where('project_id','=',$input['project_id'])
                            ->where('user_id','=',$input['user_id'])
                            ->groupBy('id')
                            ->selectRaw('user_id')
                            ->selectRaw('SUM(anzhi) as anzhi')
                            ->selectRaw('SUM(banqian)as banqian')
                            ->selectRaw('SUM(dibu) as dibu')
                            ->selectRaw('SUM(other) as other')
                            ->selectRaw('SUM(totalj) as totalj')
                        ;
                        $th[1] = '收录人';
                        $table = $input['start_time'] != '' ? $table->where('created_at', '>', $input['start_time']) : $table;
                        $table = $input['end_time'] != '' ? $table->where('created_at', '<', $input['end_time']) : $table;
                        $table = $table->get();
                        foreach($table as $value){
                            $value['bzc_name'] = User::where('id','=',$input['user_id'])->first()->surname;
                        }
                    }
                    return view('admin.sta.sta_six', compact('table_type_id','user_data','table_name', 'table', 'th'));
                    break;

                case 7:
                    $table_name = '核算单（货币化安置）';
                    $th = [
                        '1' => '姓名',
                        '2' => '住宅有证面积可置换住宅面积',
                        '3' => '住宅有证面积可置换商业面积',
                        '4' => '住宅有证面积房务补偿',
                        '5' => '无证面积可置换住宅面积',
                        '6' => '无证面积可置换商业面积',
                        '7' => '无证面积房务补偿',
                    ];
                    $th1 = [
                        '1' => '姓名',
                        '2' => '其中住改非可置换住宅面积',
                        '3' => '其中住改非可置换商业面积',
                        '4' => '其中住改非房务补偿',
                        '5' => '商业有证面积可置换住宅面积',
                        '6' => '商业有证面积可置换商业面积',
                        '7' => '商业有证面积房务补偿',
                    ];
                    $th2 = [
                        '1' => '姓名',
                        '2' => '其他项可置换住宅面积',
                        '3' => '其他项可置换商业面积',
                        '4' => '其他项房务补偿',
                        '5' => '可置换住宅面积小计',
                        '6' => '可置换商业面积小计',
                        '7' => '房务补偿小计',
                    ];
                    $th3 = [
                        '1' => '姓名',
                        '2' => '装修补偿额',
                        '3' => '庭院补偿额',
                        '4' => '停产停业损失补偿额',
                        '5' => '构筑物及其他补偿金',
                        '6' => '拆迁补偿总金额',
                    ];
                    if(empty($input['user_id']) && empty($input['project_id'])){
                        $table = Table_seven::query()
                            ->where('status','>','1')
                            ->groupBy('bzc_name')
                            ->selectRaw('bzc_name')
                            ->selectRaw('SUM(bzc_area) as bzc_area')->selectRaw('SUM(data2)as data2')
                            ->selectRaw('SUM(data3+data4) as data3')->selectRaw('SUM(data5) as data5')
                            ->selectRaw('SUM(data6) as data6')->selectRaw('SUM(data7+data8) as data7')
                            ->selectRaw('SUM(data9) as data9')->selectRaw('SUM(data10) as data10')
                            ->selectRaw('SUM(data11+data12) as data11')->selectRaw('SUM(data13) as data13')
                            ->selectRaw('SUM(data14) as data14')->selectRaw('SUM(data15+data16) as data15')
                            ->selectRaw('SUM(data17) as data17')->selectRaw('SUM(data18) as data18')
                            ->selectRaw('SUM(data19+data20) as data19')->selectRaw('SUM(data21) as data21')
                            ->selectRaw('SUM(data22) as data22')->selectRaw('SUM(data23+data24) as data23')
                            ->selectRaw('SUM(data25) as data25')->selectRaw('SUM(data26) as data26')
                            ->selectRaw('SUM(data27) as data27')->selectRaw('SUM(data42) as data42')
                            ->selectRaw('SUM(data43) as data43')
                        ;
                        $table = $input['start_time'] != '' ? $table->where('created_at', '>', $input['start_time']) : $table;
                        $table = $input['end_time'] != '' ? $table->where('created_at', '<', $input['end_time']) : $table;
                        $table = $table->get();
                    }
                    if(!empty($input['user_id'])&& empty($input['project_id'])){
                        $table = Table_seven::query()
                            ->where('status','>','1')
                            ->where('user_id','=',$input['user_id'])
                            ->groupBy('id')
                            ->selectRaw('user_id')
                            ->selectRaw('SUM(bzc_area) as bzc_area')->selectRaw('SUM(data2)as data2')
                            ->selectRaw('SUM(data3+data4) as data3')->selectRaw('SUM(data5) as data5')
                            ->selectRaw('SUM(data6) as data6')->selectRaw('SUM(data7+data8) as data7')
                            ->selectRaw('SUM(data9) as data9')->selectRaw('SUM(data10) as data10')
                            ->selectRaw('SUM(data11+data12) as data11')->selectRaw('SUM(data13) as data13')
                            ->selectRaw('SUM(data14) as data14')->selectRaw('SUM(data15+data16) as data15')
                            ->selectRaw('SUM(data17) as data17')->selectRaw('SUM(data18) as data18')
                            ->selectRaw('SUM(data19+data20) as data19')->selectRaw('SUM(data21) as data21')
                            ->selectRaw('SUM(data22) as data22')->selectRaw('SUM(data23+data24) as data23')
                            ->selectRaw('SUM(data25) as data25')->selectRaw('SUM(data26) as data26')
                            ->selectRaw('SUM(data27) as data27')->selectRaw('SUM(data42) as data42')
                            ->selectRaw('SUM(data43) as data43')
                        ;
                        $th[1] = '收录人';
                        $th1[1] = '收录人';
                        $th2[1] = '收录人';
                        $th3[1] = '收录人';
                        $table = $input['start_time'] != '' ? $table->where('created_at', '>', $input['start_time']) : $table;
                        $table = $input['end_time'] != '' ? $table->where('created_at', '<', $input['end_time']) : $table;
                        $table = $table->get();
                        foreach($table as $value){
                            $value['bzc_name'] = User::where('id','=',$input['user_id'])->first()->surname;
                        }
                    }
                    if(!empty($input['project_id']) && empty($input['user_id'])){
                        $table = Table_seven::query()
                            ->where('status','>','1')
                            ->where('project_id','=',$input['project_id'])
                            ->groupBy('id')
                            ->selectRaw('project_id')
                            ->selectRaw('SUM(bzc_area) as bzc_area')->selectRaw('SUM(data2)as data2')
                            ->selectRaw('SUM(data3+data4) as data3')->selectRaw('SUM(data5) as data5')
                            ->selectRaw('SUM(data6) as data6')->selectRaw('SUM(data7+data8) as data7')
                            ->selectRaw('SUM(data9) as data9')->selectRaw('SUM(data10) as data10')
                            ->selectRaw('SUM(data11+data12) as data11')->selectRaw('SUM(data13) as data13')
                            ->selectRaw('SUM(data14) as data14')->selectRaw('SUM(data15+data16) as data15')
                            ->selectRaw('SUM(data17) as data17')->selectRaw('SUM(data18) as data18')
                            ->selectRaw('SUM(data19+data20) as data19')->selectRaw('SUM(data21) as data21')
                            ->selectRaw('SUM(data22) as data22')->selectRaw('SUM(data23+data24) as data23')
                            ->selectRaw('SUM(data25) as data25')->selectRaw('SUM(data26) as data26')
                            ->selectRaw('SUM(data27) as data27')->selectRaw('SUM(data42) as data42')
                            ->selectRaw('SUM(data43) as data43')
                        ;
                        $th[1] = '项目';
                        $th1[1] = '项目';
                        $th2[1] = '项目';
                        $th3[1] = '项目';
                        $table = $input['start_time'] != '' ? $table->where('created_at', '>', $input['start_time']) : $table;
                        $table = $input['end_time'] != '' ? $table->where('created_at', '<', $input['end_time']) : $table;
                        $table = $table->get();
                        foreach($table as $value){
                            $value['bzc_name'] = Project::where('id','=',$input['project_id'])->first()->project_name;
                        }
                    }
                    if(!empty($input['project_id']) && !empty($input['user_id'])){
                        $table = Table_seven::query()
                            ->where('status','>','1')
                            ->where('project_id','=',$input['project_id'])
                            ->where('user_id','=',$input['user_id'])
                            ->groupBy('id')
                            ->selectRaw('user_id')
                            ->selectRaw('SUM(bzc_area) as bzc_area')->selectRaw('SUM(data2)as data2')
                            ->selectRaw('SUM(data3+data4) as data3')->selectRaw('SUM(data5) as data5')
                            ->selectRaw('SUM(data6) as data6')->selectRaw('SUM(data7+data8) as data7')
                            ->selectRaw('SUM(data9) as data9')->selectRaw('SUM(data10) as data10')
                            ->selectRaw('SUM(data11+data12) as data11')->selectRaw('SUM(data13) as data13')
                            ->selectRaw('SUM(data14) as data14')->selectRaw('SUM(data15+data16) as data15')
                            ->selectRaw('SUM(data17) as data17')->selectRaw('SUM(data18) as data18')
                            ->selectRaw('SUM(data19+data20) as data19')->selectRaw('SUM(data21) as data21')
                            ->selectRaw('SUM(data22) as data22')->selectRaw('SUM(data23+data24) as data23')
                            ->selectRaw('SUM(data25) as data25')->selectRaw('SUM(data26) as data26')
                            ->selectRaw('SUM(data27) as data27')->selectRaw('SUM(data42) as data42')
                            ->selectRaw('SUM(data43) as data43')
                        ;
                        $th[1]  = '收录人';
                        $th1[1] = '收录人';
                        $th2[1] = '收录人';
                        $th3[1] = '收录人';
                        $table = $input['start_time'] != '' ? $table->where('created_at', '>', $input['start_time']) : $table;
                        $table = $input['end_time'] != '' ? $table->where('created_at', '<', $input['end_time']) : $table;
                        $table = $table->get();
                        foreach($table as $value){
                            $value['bzc_name'] = User::where('id','=',$input['user_id'])->first()->suranme;
                        }
                    }
                    return view('admin.sta.sta_seven', compact('table_type_id','user_data','table_name', 'table', 'th', 'th1', 'th2', 'th3'));
                    break;

                case 8:
                    $table_name = '核算单（产权调换）';
                    $th = [
                        '1' => '姓名',
                        '2' => '住宅有证面积可置换住宅面积',
                        '3' => '住宅有证面积可置换商业面积',
                        '4' => '住宅有证面积房务补偿',
                        '5' => '无证面积可置换住宅面积',
                        '6' => '无证面积可置换商业面积',
                        '7' => '无证面积房务补偿',
                    ];
                    $th1 = [
                        '1' => '姓名',
                        '2' => '其中住改非可置换住宅面积',
                        '3' => '其中住改非可置换商业面积',
                        '4' => '其中住改非房务补偿',
                        '5' => '商业有证面积可置换住宅面积',
                        '6' => '商业有证面积可置换商业面积',
                        '7' => '商业有证面积房务补偿',
                    ];
                    $th2 = [
                        '1' => '姓名',
                        '2' => '其他项可置换住宅面积',
                        '3' => '其他项可置换商业面积',
                        '4' => '其他项房务补偿',
                        '5' => '可置换住宅面积小计',
                        '6' => '可置换商业面积小计',
                        '7' => '房务补偿小计',
                    ];
                    $th3 = [
                        '1' => '姓名',
                        '2' => '装修补偿额',
                        '3' => '庭院补偿额',
                        '4' => '停产停业损失补偿额',
                        '5' => '构筑物及其他补偿金',
                        '6' => '拆迁补偿总金额',
                    ];
                    $th4 = [
                        '1' => '姓名',
                        '2' => '住宅可调换面积',
                        '3' => '住宅实际调换面积',
                        '4' => '住宅大于可调换面积',
                        '5' => '住宅可调换面积价格核算',
                        '6' => '住宅大于可调换面积价格核算',
                        '7' => '住宅调换房屋价格',
                    ];
                    $th5 = [
                        '1' => '姓名',
                        '2' => '商业可调换面积',
                        '3' => '商业实际调换面积',
                        '4' => '商业大于可调换面积',
                        '5' => '商业可调换面积价格核算',
                        '6' => '商业大于可调换面积价格核算',
                        '7' => '商业调换房屋价格',
                        '8' => '应退差额',
                        '9' => '应缴差额',
                    ];
                    if(empty($input['user_id']) && empty($input['project_id'])){
                        $table = Table_eight::query()
                            ->where('status','>','1')
                            ->groupBy('bzc_name')
                            ->selectRaw('bzc_name')
                            ->selectRaw('SUM(bzc_area) as bzc_area')->selectRaw('SUM(data2)as data2')
                            ->selectRaw('SUM(data3+data4) as data3')->selectRaw('SUM(data5) as data5')
                            ->selectRaw('SUM(data6) as data6')->selectRaw('SUM(data7+data8) as data7')
                            ->selectRaw('SUM(data9) as data9')->selectRaw('SUM(data10) as data10')
                            ->selectRaw('SUM(data11+data12) as data11')->selectRaw('SUM(data13) as data13')
                            ->selectRaw('SUM(data14) as data14')->selectRaw('SUM(data15+data16) as data15')
                            ->selectRaw('SUM(data17) as data17')->selectRaw('SUM(data18) as data18')
                            ->selectRaw('SUM(data19+data20) as data19')->selectRaw('SUM(data21) as data21')
                            ->selectRaw('SUM(data22) as data22')->selectRaw('SUM(data23+data24) as data23')
                            ->selectRaw('SUM(data25) as data25')->selectRaw('SUM(data26) as data26')
                            ->selectRaw('SUM(data27) as data27')->selectRaw('SUM(data42) as data42')
                            ->selectRaw('SUM(data43) as data43')->selectRaw('SUM(home_area) as home_area')
                            ->selectRaw('SUM(data50) as data50')->selectRaw('SUM(data51) as data51')
                            ->selectRaw('SUM(data52) as data52')->selectRaw('SUM(data57) as data57')
                            ->selectRaw('SUM(data58) as data58')->selectRaw('SUM(data53) as data53')
                            ->selectRaw('SUM(data54) as data54')->selectRaw('SUM(data55) as data55')
                            ->selectRaw('SUM(data56) as data56')->selectRaw('SUM(data61) as data61')
                            ->selectRaw('SUM(data62) as data62')->selectRaw('SUM(data59) as data59')
                            ->selectRaw('SUM(data60) as data60')
                        ;
                        $table = $input['start_time'] != '' ? $table->where('created_at', '>', $input['start_time']) : $table;
                        $table = $input['end_time'] != '' ? $table->where('created_at', '<', $input['end_time']) : $table;
                        $table = $table->get();
                    }
                    if(!empty($input['user_id'])&& empty($input['project_id'])){
                        $table = Table_eight::query()
                            ->where('status','>','1')
                            ->where('user_id','=',$input['user_id'])
                            ->groupBy('id')
                            ->selectRaw('user_id')
                            ->selectRaw('SUM(bzc_area) as bzc_area')->selectRaw('SUM(data2)as data2')
                            ->selectRaw('SUM(data3+data4) as data3')->selectRaw('SUM(data5) as data5')
                            ->selectRaw('SUM(data6) as data6')->selectRaw('SUM(data7+data8) as data7')
                            ->selectRaw('SUM(data9) as data9')->selectRaw('SUM(data10) as data10')
                            ->selectRaw('SUM(data11+data12) as data11')->selectRaw('SUM(data13) as data13')
                            ->selectRaw('SUM(data14) as data14')->selectRaw('SUM(data15+data16) as data15')
                            ->selectRaw('SUM(data17) as data17')->selectRaw('SUM(data18) as data18')
                            ->selectRaw('SUM(data19+data20) as data19')->selectRaw('SUM(data21) as data21')
                            ->selectRaw('SUM(data22) as data22')->selectRaw('SUM(data23+data24) as data23')
                            ->selectRaw('SUM(data25) as data25')->selectRaw('SUM(data26) as data26')
                            ->selectRaw('SUM(data27) as data27')->selectRaw('SUM(data42) as data42')
                            ->selectRaw('SUM(data43) as data43')->selectRaw('SUM(home_area) as home_area')
                            ->selectRaw('SUM(data50) as data50')->selectRaw('SUM(data51) as data51')
                            ->selectRaw('SUM(data52) as data52')->selectRaw('SUM(data57) as data57')
                            ->selectRaw('SUM(data58) as data58')->selectRaw('SUM(data53) as data53')
                            ->selectRaw('SUM(data54) as data54')->selectRaw('SUM(data55) as data55')
                            ->selectRaw('SUM(data56) as data56')->selectRaw('SUM(data61) as data61')
                            ->selectRaw('SUM(data62) as data62')->selectRaw('SUM(data59) as data59')
                            ->selectRaw('SUM(data60) as data60')
                        ;
                        $th[1]  = '收录人';
                        $th1[1] = '收录人';
                        $th2[1] = '收录人';
                        $th3[1] = '收录人';
                        $th4[1] = '收录人';
                        $th5[1] = '收录人';
                        $table = $input['start_time'] != '' ? $table->where('created_at', '>', $input['start_time']) : $table;
                        $table = $input['end_time'] != '' ? $table->where('created_at', '<', $input['end_time']) : $table;
                        $table = $table->get();
                        foreach($table as $value){
                            $value['bzc_name'] = User::where('id','=',$input['user_id'])->first()->surname;
                        }
                    }
                    if(!empty($input['project_id']) && empty($input['user_id'])){
                        $table = Table_eight::query()
                            ->where('status','>','1')
                            ->where('project_id','=',$input['project_id'])
                            ->groupBy('id')
                            ->selectRaw('project_id')
                            ->selectRaw('SUM(bzc_area) as bzc_area')->selectRaw('SUM(data2)as data2')
                            ->selectRaw('SUM(data3+data4) as data3')->selectRaw('SUM(data5) as data5')
                            ->selectRaw('SUM(data6) as data6')->selectRaw('SUM(data7+data8) as data7')
                            ->selectRaw('SUM(data9) as data9')->selectRaw('SUM(data10) as data10')
                            ->selectRaw('SUM(data11+data12) as data11')->selectRaw('SUM(data13) as data13')
                            ->selectRaw('SUM(data14) as data14')->selectRaw('SUM(data15+data16) as data15')
                            ->selectRaw('SUM(data17) as data17')->selectRaw('SUM(data18) as data18')
                            ->selectRaw('SUM(data19+data20) as data19')->selectRaw('SUM(data21) as data21')
                            ->selectRaw('SUM(data22) as data22')->selectRaw('SUM(data23+data24) as data23')
                            ->selectRaw('SUM(data25) as data25')->selectRaw('SUM(data26) as data26')
                            ->selectRaw('SUM(data27) as data27')->selectRaw('SUM(data42) as data42')
                            ->selectRaw('SUM(data43) as data43')->selectRaw('SUM(home_area) as home_area')
                            ->selectRaw('SUM(data50) as data50')->selectRaw('SUM(data51) as data51')
                            ->selectRaw('SUM(data52) as data52')->selectRaw('SUM(data57) as data57')
                            ->selectRaw('SUM(data58) as data58')->selectRaw('SUM(data53) as data53')
                            ->selectRaw('SUM(data54) as data54')->selectRaw('SUM(data55) as data55')
                            ->selectRaw('SUM(data56) as data56')->selectRaw('SUM(data61) as data61')
                            ->selectRaw('SUM(data62) as data62')->selectRaw('SUM(data59) as data59')
                            ->selectRaw('SUM(data60) as data60')
                        ;
                        $th[1]  = '项目';
                        $th1[1] = '项目';
                        $th2[1] = '项目';
                        $th3[1] = '项目';
                        $th4[1] = '项目';
                        $th5[1] = '项目';
                        $table = $input['start_time'] != '' ? $table->where('created_at', '>', $input['start_time']) : $table;
                        $table = $input['end_time'] != '' ? $table->where('created_at', '<', $input['end_time']) : $table;
                        $table = $table->get();
                        foreach($table as $value){
                            $value['bzc_name'] = Project::where('id','=',$input['project_id'])->first()->project_name;
                        }
                    }
                    if(!empty($input['project_id']) && !empty($input['user_id'])){
                        $table = Table_eight::query()
                            ->where('status','>','1')
                            ->where('project_id','=',$input['project_id'])
                            ->where('user_id','=',$input['user_id'])
                            ->groupBy('id')
                            ->selectRaw('user_id')
                            ->selectRaw('SUM(bzc_area) as bzc_area')->selectRaw('SUM(data2)as data2')
                            ->selectRaw('SUM(data3+data4) as data3')->selectRaw('SUM(data5) as data5')
                            ->selectRaw('SUM(data6) as data6')->selectRaw('SUM(data7+data8) as data7')
                            ->selectRaw('SUM(data9) as data9')->selectRaw('SUM(data10) as data10')
                            ->selectRaw('SUM(data11+data12) as data11')->selectRaw('SUM(data13) as data13')
                            ->selectRaw('SUM(data14) as data14')->selectRaw('SUM(data15+data16) as data15')
                            ->selectRaw('SUM(data17) as data17')->selectRaw('SUM(data18) as data18')
                            ->selectRaw('SUM(data19+data20) as data19')->selectRaw('SUM(data21) as data21')
                            ->selectRaw('SUM(data22) as data22')->selectRaw('SUM(data23+data24) as data23')
                            ->selectRaw('SUM(data25) as data25')->selectRaw('SUM(data26) as data26')
                            ->selectRaw('SUM(data27) as data27')->selectRaw('SUM(data42) as data42')
                            ->selectRaw('SUM(data43) as data43')->selectRaw('SUM(home_area) as home_area')
                            ->selectRaw('SUM(data50) as data50')->selectRaw('SUM(data51) as data51')
                            ->selectRaw('SUM(data52) as data52')->selectRaw('SUM(data57) as data57')
                            ->selectRaw('SUM(data58) as data58')->selectRaw('SUM(data53) as data53')
                            ->selectRaw('SUM(data54) as data54')->selectRaw('SUM(data55) as data55')
                            ->selectRaw('SUM(data56) as data56')->selectRaw('SUM(data61) as data61')
                            ->selectRaw('SUM(data62) as data62')->selectRaw('SUM(data59) as data59')
                            ->selectRaw('SUM(data60) as data60')
                        ;
                        $th[1]  = '收录人';
                        $th1[1] = '收录人';
                        $th2[1] = '收录人';
                        $th3[1] = '收录人';
                        $th4[1] = '收录人';
                        $th5[1] = '收录人';
                        $table = $input['start_time'] != '' ? $table->where('created_at', '>', $input['start_time']) : $table;
                        $table = $input['end_time'] != '' ? $table->where('created_at', '<', $input['end_time']) : $table;
                        $table = $table->get();
                        foreach($table as $value){
                            $value['bzc_name'] = User::where('id','=',$input['user_id'])->first()->surname;
                        }
                    }

                    return view('admin.sta.sta_eight', compact('table_type_id','user_data','table_name', 'th', 'th1', 'th2', 'th3', 'th4', 'th5', 'table'));
                    break;

                case 9:
                    $table_name = '核算单（货币补偿）';
                    $th = [
                        '1' => '姓名',
                        '2' => '房1房屋面积',
                        '3' => '房2房屋面积',
                        '4' => '房3房屋面积',
                        '5' => '房4房屋面积',
                        '6' => '房5房屋面积',
                        '7' => '房6房屋面积',
                        '8' => '合计',
                    ];
                    $th1 = [
                        '1' => '姓名',
                        '2' => '房1装修',
                        '3' => '房2装修',
                        '4' => '房3装修',
                        '5' => '房4装修',
                        '6' => '房5装修',
                        '7' => '房6装修',
                        '8' => '小计',
                    ];
                    $th2 = [
                        '1' => '姓名',
                        '2' => '空院补偿额',
                        '3' => '停产停业损失补偿额',
                        '4' => '房屋补偿总额',
                        '5' => '构筑物及其他补偿金',
                        '6' => '拆迁补偿总金额',
                    ];
                    if(empty($input['user_id']) && empty($input['project_id'])){
                        $table = Table_nine::query()
                            ->where('status','>','1')
                            ->groupBy('bzc_name')
                            ->selectRaw('bzc_name')
                            ->selectRaw('SUM(data6) as data6')->selectRaw('SUM(data9)as data9')
                            ->selectRaw('SUM(data12) as data12')->selectRaw('SUM(data15) as data15')
                            ->selectRaw('SUM(data18) as data18')->selectRaw('SUM(data21) as data21')
                            ->selectRaw('SUM(data24) as data24')->selectRaw('SUM(data7) as data7')
                            ->selectRaw('SUM(data10) as data10')->selectRaw('SUM(data13) as data13')
                            ->selectRaw('SUM(data16) as data16')->selectRaw('SUM(data19) as data19')
                            ->selectRaw('SUM(data22) as data22')->selectRaw('SUM(data25) as data25')
                            ->selectRaw('SUM(data26) as data26')->selectRaw('SUM(data27) as data27')
                            ->selectRaw('SUM(data28) as data28')->selectRaw('SUM(data43) as data43')
                            ->selectRaw('SUM(data44) as data44')
                        ;
                        $table = $input['start_time'] != '' ? $table->where('created_at', '>', $input['start_time']) : $table;
                        $table = $input['end_time'] != '' ? $table->where('created_at', '<', $input['end_time']) : $table;
                        $table = $table->get();
                    }
                    if(!empty($input['user_id'])&& empty($input['project_id'])){
                        $table = Table_nine::query()
                            ->where('status','>','1')
                            ->where('user_id','=',$input['user_id'])
                            ->groupBy('id')
                            ->selectRaw('user_id')
                            ->selectRaw('SUM(data6) as data6')->selectRaw('SUM(data9)as data9')
                            ->selectRaw('SUM(data12) as data12')->selectRaw('SUM(data15) as data15')
                            ->selectRaw('SUM(data18) as data18')->selectRaw('SUM(data21) as data21')
                            ->selectRaw('SUM(data24) as data24')->selectRaw('SUM(data7) as data7')
                            ->selectRaw('SUM(data10) as data10')->selectRaw('SUM(data13) as data13')
                            ->selectRaw('SUM(data16) as data16')->selectRaw('SUM(data19) as data19')
                            ->selectRaw('SUM(data22) as data22')->selectRaw('SUM(data25) as data25')
                            ->selectRaw('SUM(data26) as data26')->selectRaw('SUM(data27) as data27')
                            ->selectRaw('SUM(data28) as data28')->selectRaw('SUM(data43) as data43')
                            ->selectRaw('SUM(data44) as data44')
                        ;
                        $th[1] =  '收录人';
                        $th1[1] = '收录人';
                        $th2[1] = '收录人';
                        $table = $input['start_time'] != '' ? $table->where('created_at', '>', $input['start_time']) : $table;
                        $table = $input['end_time'] != '' ? $table->where('created_at', '<', $input['end_time']) : $table;
                        $table = $table->get();
                        foreach($table as $value){
                            $value['bzc_name'] = User::where('id','=',$value['user_id'])->first()->surname;
                        }
                    }
                    if(!empty($input['project_id']) && empty($input['user_id'])){
                        $table = Table_nine::query()
                            ->where('status','>','1')
                            ->where('project_id','=',$input['project_id'])
                            ->groupBy('id')
                            ->selectRaw('project_id')
                            ->selectRaw('SUM(data6) as data6')->selectRaw('SUM(data9)as data9')
                            ->selectRaw('SUM(data12) as data12')->selectRaw('SUM(data15) as data15')
                            ->selectRaw('SUM(data18) as data18')->selectRaw('SUM(data21) as data21')
                            ->selectRaw('SUM(data24) as data24')->selectRaw('SUM(data7) as data7')
                            ->selectRaw('SUM(data10) as data10')->selectRaw('SUM(data13) as data13')
                            ->selectRaw('SUM(data16) as data16')->selectRaw('SUM(data19) as data19')
                            ->selectRaw('SUM(data22) as data22')->selectRaw('SUM(data25) as data25')
                            ->selectRaw('SUM(data26) as data26')->selectRaw('SUM(data27) as data27')
                            ->selectRaw('SUM(data28) as data28')->selectRaw('SUM(data43) as data43')
                            ->selectRaw('SUM(data44) as data44')
                        ;
                        $th[1] =  '项目';
                        $th1[1] = '项目';
                        $th2[1] = '项目';
                        $table = $input['start_time'] != '' ? $table->where('created_at', '>', $input['start_time']) : $table;
                        $table = $input['end_time'] != '' ? $table->where('created_at', '<', $input['end_time']) : $table;
                        $table = $table->get();
                        foreach($table as $value){
                            $value['bzc_name'] = Project::where('id','=',$value['project_id'])->first()->project_name;
                        }
                    }
                    if(!empty($input['project_id']) && !empty($input['user_id'])){
                        $table = Table_nine::query()
                            ->where('status','>','1')
                            ->where('project_id','=',$input['project_id'])
                            ->where('user_id','=',$input['user_id'])
                            ->groupBy('id')
                            ->selectRaw('user_id')
                            ->selectRaw('SUM(data6) as data6')->selectRaw('SUM(data9)as data9')
                            ->selectRaw('SUM(data12) as data12')->selectRaw('SUM(data15) as data15')
                            ->selectRaw('SUM(data18) as data18')->selectRaw('SUM(data21) as data21')
                            ->selectRaw('SUM(data24) as data24')->selectRaw('SUM(data7) as data7')
                            ->selectRaw('SUM(data10) as data10')->selectRaw('SUM(data13) as data13')
                            ->selectRaw('SUM(data16) as data16')->selectRaw('SUM(data19) as data19')
                            ->selectRaw('SUM(data22) as data22')->selectRaw('SUM(data25) as data25')
                            ->selectRaw('SUM(data26) as data26')->selectRaw('SUM(data27) as data27')
                            ->selectRaw('SUM(data28) as data28')->selectRaw('SUM(data43) as data43')
                            ->selectRaw('SUM(data44) as data44')
                        ;
                        $th[1] =  '收录人';
                        $th1[1] = '收录人';
                        $th2[1] = '收录人';
                        $table = $input['start_time'] != '' ? $table->where('created_at', '>', $input['start_time']) : $table;
                        $table = $input['end_time'] != '' ? $table->where('created_at', '<', $input['end_time']) : $table;
                        $table = $table->get();
                        foreach($table as $value){
                            $value['bzc_name'] = User::where('id','=',$value['user_id'])->first()->surname;
                        }
                    }
                    return view('admin.sta.sta_nine', compact('table_type_id','user_data','table_name', 'table', 'th', 'th1', 'th2'));
                    break;

                case 0:
                    $table_name = '成本审计汇总表';
                    $th = [
                        '合同编号',
                        '姓名',
                        '房栋号',
                        '身份证',
                        '联系电话',
                        '有证面积',
                        '无证面积',
                        '房屋补偿金',
                        '庭院面积',
                        '庭院补偿',
                        '装修',
                        '构筑物及其他',
                        '停产停业损失补偿（临街路补偿）',
                        '临时安置',
                        '搬迁',
                        '低保',
                        '全额奖励金',
                        '整栋奖励',
                        '违章自行拆除费',
                        '残疾及其他',
                        '补偿总额',
                        '回迁套数',
                        '回迁小区楼栋号',
                        '回迁住宅面积',
                        '回迁商铺面积',
                        '回迁楼房金额',
                        '应缴差价',
                        '应退差价',
                        '签约日期',
                        '交房日期',
                        '备注',
                    ];

                    $result = Tablelist::query();

                    $data = $request->all();

                    $result = $result->where('status', '>', '0');

                    $result = $data['name'] != '' ? $result->where('bzc_name','like', '%'.$data['name'].'%') : $result;

                    $result = $data['project_name'] != '' ? $result->where('project_name', $data['project_name']) : $result;

                    $result = $data['start_time'] != '' ? $result->where('updated_at', '>', $data['start_time']) : $result;

                    $result = $data['end_time'] != '' ? $result->where('updated_at', '<', $data['end_time']) : $result;

                    return view('admin.sta.sta_all',compact('th','table_name','user_data','table'));
                    break;
            }
        } else {
            return redirect('/');
        }

    }

}