<?php
namespace app\web\controller;

use think\facade\Session;
use app\web\BaseController;

class Index extends BaseController
{
	
	public function index()
	{
		return redirect('/web.php/home/home');
	}
	
	public function t1()
    {
        halt(1);
        set_time_limit(0);
        ini_set("memory_limit","10000M");
        $dir = scandir(public_path().'public/其他');
        $res = [];
        $data= [];
        for ($i = 0,$i<=50;$i++;) {
            $data[] = $i;
        }
        foreach ($dir as $key => $file) {
            if ($file == '.' || $file == '..') {
                continue;
            }

            $list       = importExecl('其他/'.$file, $data, 0);
            $name_key = array_search('姓名',$list[2]);
            $idcard_key = array_search('身份证号码',$list[2]) !== false ? array_search('身份证号码',$list[2]) : array_search('证件号码',$list[2]);
            $wuxian_key = 0;
            $yingfa_key = 0;
            foreach ($list[2] as $k => $v) {
                if (mb_strpos($v,'个人') !== false) {
                    $wuxian_key = $k;
                }
                if (mb_strpos($v,'应发') !== false) {
                    $yingfa_key = $k;
                }
            }
            $yanglan_key = 0;
            $shiye_key = 0;
            $yiliao_key = 0;
            $gongjijin_key = 0;
            foreach ($list[3] as $k => $v) {
                if ($k >= $wuxian_key) {
                    if (mb_strpos($v,'养老') !== false) {
                        $yanglan_key = $k;
                    } elseif (mb_strpos($v,'失业') !== false) {
                        $shiye_key = $k;
                    } elseif (mb_strpos($v,'医疗') !== false) {
                        $yiliao_key = $k;
                    } elseif (mb_strpos($v,'公积金') !== false) {
                        $gongjijin_key = $k;
                    }
                }
            }

            $list = array_slice($list,4);
            foreach ($list as $v) {
                if (!is_numeric($v[0])) {
                    break;
                }
                $res[] = [
                    'title' => $file,
                    'name' => $name_key ? $v[$name_key] : "",
                    'idcard' => $idcard_key ? $v[$idcard_key] : "",
                    'yingfa' => $yingfa_key ? $v[$yingfa_key] : 0,
                    'yanglan' => $yanglan_key ? $v[$yanglan_key] : 0,
                    'shiye' => $shiye_key ? $v[$shiye_key] : 0,
                    'yiliao' => $yiliao_key ? $v[$yiliao_key] : 0,
                    'gongjijin' => $gongjijin_key ? $v[$gongjijin_key] : 0,
                ];
            }
        }

        $xlsCell = [['title','表名'],['name','姓名'],['idcard','身份证'],['yingfa','应发'],['yanglan','养老'],['shiye','失业'],['yiliao','医疗'],['gongjijin','公积金']];
        export_excel('结果',$xlsCell,$res);
    }
}
	