<?php

namespace app\admin\controller;

use app\admin\common\AdminController;
use think\facade\Db;

class DataCheck extends AdminController{

    public function index(){
        return view("", []);
    }

    /**
     * 数据核验列表
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function list(){
        $list = Db::table("new_data_check")->order('createTime','desc')->select();
        return ["total" => count($list), "rows" => $list];
    }

    public function import_wuxian(){
        $response_obj = new \StdClass();
        if (!$this->request->file()){
            $response_obj->code = 500;
            $response_obj->msg = '没有选择文件';
            return \StrUtil::back($response_obj, "DataCheck.callBack");
        }

        $excel = $this->request->file("file");

        $year = $this->request->post('year');

        $savename = \think\facade\Filesystem::disk("public")->putFile("uploadexcel", $excel);

        $check_data = [
            'task_name' => date("Y-m-d",time()) . "-导入五险({$year}年度)查询数据",
            'task_file' => $savename,
            'task_status' => -1,
            'createTime' => date("Y-m-d H:i:s",time()),
            'updateTime' => date("Y-m-d H:i:s",time())
        ];

        $id = Db::table("new_data_check")->insertGetId($check_data);

        queue("app\job\Import", ["id" => $id,"type" => 1, 'year' => $year]);

        $response_obj = new \StdClass();
        $response_obj->code = 200;
        $response_obj->msg = '导入成功';
        return \StrUtil::back($response_obj, "DataCheck.callBack");
    }

}