request->param("order")) ?: "desc";
        $offset = trim($this->request->param("offset")) ?: 0;
        $limit = trim($this->request->param("limit")) ?: 10;
        $list = EnterpriseRecord::where('mainId', session("user")["uid"])->limit($offset, $limit)->order('createTime ' . $order)->select()->toArray();
        $count = count($list);
        if ($count > 0) {
            $streetList = DictApi::selectByParentCode('street');
            $typeList = DictApi::selectByParentCode('enterprise_type');
            $industryFieldNew = DictApi::selectByParentCode('industry_field');
            foreach ($list as $k => &$v) {
                $v['newIndustryFieldNewName'] = $industryFieldNew[$v['newIndustryFieldNew']];
                $v['newEnterpriseType'] = $typeList[$v['newEnterpriseType']];
                $v['newStreetName'] = $streetList[$v['newStreet']];
            }
        }
        return json(["total" => $count, "rows" => $list]);
    }
    public function findUnfinishedChangeRecord() {
        return EnterpriseRecord::where('mainId', session("user")["uid"])->where('checkState', '<>', 4)->select()->toArray();
    }
    public function toAdd() {
        $ep = Enterprise::where('id', session("user")["uid"])->find();
        $ecr = [
            "special" => $ep["special"],
            'enterprise_id' => $ep['id'],
            'newName' => $ep['name'],
            'newIdCard' => $ep['idCard'],
            'newStreet' => $ep['street'],
            'newAddress' => $ep['address'],
            'newLegal' => $ep['legal'],
            'newEphone' => $ep['ephone'],
            'newAgentName' => $ep['agentName'],
            'newAgentEmail' => $ep['agentEmail'],
            'newAgentPhone' => $ep['agentPhone'],
            'type' => $ep['type'],
            'newAgencyType' => $ep['agencyType'],
            'newEnterpriseTag' => $ep['enterpriseTag'],
            'newOrganizationTag' => $ep['organizationTag'],
            'newInstitutionTag' => $ep['institutionTag'],
            'newEnterpriseType' => $ep['enterpriseType'],
            'newIndustryFieldNew' => $ep['industryFieldNew'],
            'newIndustryFieldOld' => $ep['industryFieldOld'],
            'newBankCard' => $ep['bankCard'],
            'newBank' => $ep['bank'],
            'newBankNetwork' => $ep['bankNetwork']
        ];
        if ($ep["imgurl"]) {
            $ecr["imgurl"] = $ep["imgurl"];
            $extension = pathinfo($ep["imgurl"])["extension"];
            if (in_array($extension, ["jpeg", "jpg", "png", "gif"])) {
                $ecr["imgurl_is_img"] = 1;
            }
        }
        if ($ep["bankImg"]) {
            $ecr["bankImg"] = $ep["bankImg"];
            $extension = pathinfo($ep["bankImg"])["extension"];
            if (in_array($extension, ["jpeg", "jpg", "png", "gif"])) {
                $ecr["bankImg_is_img"] = 1;
            }
        }
        if ($ep["domainImg"]) {
            $ecr["domainImg"] = $ep["domainImg"];
            $extension = pathinfo($ep["domainImg"])["extension"];
            if (in_array($extension, ["jpeg", "jpg", "png", "gif"])) {
                $ecr["domainImg_is_img"] = 1;
            }
        }
        if ($ep["typeImg"]) {
            $ecr["typeImg"] = $ep["typeImg"];
            $extension = pathinfo($ep["typeImg"])["extension"];
            if (in_array($extension, ["jpeg", "jpg", "png", "gif"])) {
                $ecr["typeImg_is_img"] = 1;
            }
        }
        if ($ep["beian"]) {
            $ecr["beian"] = $ep["beian"];
            $extension = pathinfo($ep["beian"])["extension"];
            if (in_array($extension, ["jpeg", "jpg", "png", "gif"])) {
                $ecr["beian_is_img"] = 1;
            }
        }
        switch ($ep['checkState']) {
            case 1:
                $ecr['checkStateName'] = '保存未提交审核';
                break;
            case 2:
                $ecr['checkStateName'] = '待审核';
                break;
            case 3:
                $ecr['checkStateName'] = '审核驳回';
                break;
            case 4:
                $ecr['checkStateName'] = '审核通过';
                break;
            case 5:
                $ecr['checkStateName'] = '重新提交';
                break;
            default:
                $ecr['checkStateName'] = '';
        }
        //20220918增加根据不同的企业类型显示不同的信息变更界面
        switch ($ep->special) {
            case 0:
                return view("", ['ecr' => $ecr]);
                break;
            case 1:
                return view("", ['ecr' => $ecr]);
                break;
            case 3:
                return view("", ['ecr' => $ecr]);
                break;
            default:
                break;
        }
    }
    public function upsert() {
        $data = [
            'id' => \StrUtil::getRequestDecodeParam($this->request, 'enterprise_id'),
            'name' => \StrUtil::getRequestDecodeParam($this->request, 'newName'), //单位名称
            'idCard' => \StrUtil::getRequestDecodeParam($this->request, 'newIdCard'), //统一社会信用代码
            'agentName' => \StrUtil::getRequestDecodeParam($this->request, 'newAgentName'), //人才联络员
            'agentPhone' => \StrUtil::getRequestDecodeParam($this->request, 'newAgentPhone'), //人才联络员电话
            'legal' => \StrUtil::getRequestDecodeParam($this->request, 'newLegal'), //法人
            'street' => \StrUtil::getRequestDecodeParam($this->request, 'newStreet'), //镇街
            'address' => \StrUtil::getRequestDecodeParam($this->request, 'newAddress'), //地址
            'type' => intval($this->request['type']),
            'agencyType' => intval($this->request['newAgencyType']),
            'enterpriseTag' => \StrUtil::getRequestDecodeParam($this->request, 'newEnterpriseTag'), //单位标签
            'organizationTag' => \StrUtil::getRequestDecodeParam($this->request, 'newOrganizationTag'), //机构标签
            'institutionTag' => \StrUtil::getRequestDecodeParam($this->request, 'newInstitutionTag'), //事业单位标签
            'enterpriseType' => \StrUtil::getRequestDecodeParam($this->request, 'newEnterpriseType'), //单位类型
            'agentEmail' => \StrUtil::getRequestDecodeParam($this->request, 'newAgentEmail'), //邮箱
            'ephone' => \StrUtil::getRequestDecodeParam($this->request, 'newEphone'), //单位电话
            'industryFieldNew' => \StrUtil::getRequestDecodeParam($this->request, 'newIndustryFieldNew'), //产业领域
            'industryFieldOld' => \StrUtil::getRequestDecodeParam($this->request, 'newIndustryFieldOld'), //行业领域
            'bankCard' => \StrUtil::getRequestDecodeParam($this->request, 'newBankCard'), //银行
            'bank' => \StrUtil::getRequestDecodeParam($this->request, 'newBank'), //开户行
            'bankNetwork' => \StrUtil::getRequestDecodeParam($this->request, 'newBankNetwork')//网点
        ];
        $response_object = new \stdClass();
        try {
            if (stripos($data['name'], "(")) {
                $data['name'] = str_replace('(', '(', $data['name']);
            }
            if (stripos($data['name'], ")")) {
                $data['name'] = str_replace(')', ')', $data['name']);
            }
            $ep = Enterprise::where('id', session("user")["uid"])->find();
            switch ($ep->special) {
                case 0:
                    if ($ep->type == 2) {
                        validate(\app\common\validate\Enterprise::class)->batch(true)->scene('jc_change')->check($data);
                    } else {
                        if ($data["agencyType"] == 1) {
                            validate(\app\common\validate\Enterprise::class)->batch(true)->scene('change')->check($data);
                        } else {
                            validate(\app\common\validate\Enterprise::class)->batch(true)->scene('change2')->check($data);
                        }
                    }
                    break;
                case 1:
                    validate(\app\common\validate\Enterprise::class)->batch(true)->scene('sy_change')->check($data);
                    break;
                default:
                    break;
            }
            $record_id = \StrUtil::getRequestDecodeParam($this->request, 'id');
            if (!$record_id) {
                $record_id = getStringId();
                $record_data = [
                    'id' => $record_id,
                    'mainId' => $data['id'],
                    'type' => $data['type'],
                    'oldAgencyType' => $ep['agencyType'],
                    'oldName' => $ep['name'],
                    'oldIdCard' => $ep['idCard'],
                    'oldIndustryFieldNew' => $ep['industryFieldNew'],
                    'oldIndustryFieldOld' => $ep['industryFieldOld'],
                    'oldStreet' => $ep['street'],
                    'oldAddress' => $ep['address'],
                    'oldLegal' => $ep['legal'],
                    'oldEphone' => $ep['ephone'],
                    'oldAgentName' => $ep['agentName'],
                    'oldAgentEmail' => $ep['agentEmail'],
                    'oldAgentPhone' => $ep['agentPhone'],
                    'oldEnterpriseTag' => $ep['enterpriseTag'],
                    'oldOrganizationTag' => $ep['organizationTag'],
                    'oldInstitutionTag' => $ep['institutionTag'],
                    'oldEnterpriseType' => $ep['enterpriseType'],
                    'oldBankCard' => $ep['bankCard'],
                    'oldBank' => $ep['bank'],
                    'oldBankNetwork' => $ep['bankNetwork'],
                    "oldImgurl" => $ep["imgurl"],
                    "oldBankImg" => $ep["bankImg"],
                    "oldDomainImg" => $ep["domainImg"],
                    "oldTypeImg" => $ep["typeImg"],
                    "oldBeian" => $ep["beian"],
                    'newAgencyType' => $data['agencyType'],
                    'newName' => htmlspecialchars($data['name']),
                    'newIdCard' => htmlspecialchars($data['idCard']),
                    'newIndustryFieldNew' => $data['industryFieldNew'],
                    'newIndustryFieldOld' => $data['industryFieldOld'],
                    'newStreet' => $data['street'],
                    'newAddress' => $data['address'],
                    'newLegal' => $data['legal'],
                    'newEphone' => $data['ephone'],
                    'newAgentName' => $data['agentName'],
                    'newAgentEmail' => $data['agentEmail'],
                    'newAgentPhone' => $data['agentPhone'],
                    'newEnterpriseTag' => $data['enterpriseTag'],
                    'newOrganizationTag' => $data['organizationTag'],
                    'newInstitutionTag' => $data['institutionTag'],
                    'newEnterpriseType' => $data['enterpriseType'],
                    'newBankCard' => $data['bankCard'],
                    'newBank' => $data['bank'],
                    'newBankNetwork' => $data['bankNetwork'],
                    'checkState' => 1,
                    'createTime' => date("Y-m-d H:i:s", time()),
                    'createUser' => session("user")["uid"]
                ];
                $record_data["newImgurl"] = $ep["imgurl"];
                $record_data["newBankImg"] = $ep["bankImg"];
                $record_data["newDomainImg"] = $ep["domainImg"];
                $record_data["newTypeImg"] = $ep["typeImg"];
                $record_data["newBeian"] = $ep["beian"];
                if ($data["agencyType"] != 1) {
                    $record_data["newIndustryFieldNew"] = null;
                    $record_data["newIndustryFieldOld"] = null;
                    $record_data["newDomainImg"] = null;
                }
                $files = $this->request->file();
                if ($files) {
                    $uploadapi = new UploadApi();
                    if (array_key_exists('imgurl', $files)) {
                        $upload_result = $uploadapi->uploadOne($this->request->file('imgurl'), 'system');
                        if ($upload_result->code == 500) {
                            return \StrUtil::back($upload_result, "EpChangeEdit.callBack");
                        }
                        $record_data["newImgurl"] = $upload_result->filepath;
                    }
                    //检验附件 开户许可证
                    if (array_key_exists('bankImg', $files)) {
                        $upload_result1 = $uploadapi->uploadOne($this->request->file('bankImg'), 'system');
                        if ($upload_result1->code == 500) {
                            return \StrUtil::back($upload_result1, "EpChangeEdit.callBack");
                        }
                        $record_data["newBankImg"] = $upload_result1->filepath;
                    }
                    //检验附件 行业领域佐证材料
                    if (array_key_exists('domainImg', $files) && $data['agencyType'] == 1) {
                        $upload_result2 = $uploadapi->uploadOne($this->request->file('domainImg'), 'system');
                        if ($upload_result2->code == 500) {
                            return \StrUtil::back($upload_result2, "EpChangeEdit.callBack");
                        }
                        $record_data["newDomainImg"] = $upload_result2->filepath;
                    }
                    //检验附件 三种类型企业上传材料
                    if (array_key_exists('typeImg', $files)) {
                        $upload_result4 = $uploadapi->uploadOne($this->request->file('typeImg'), 'system');
                        if ($upload_result4->code == 500) {
                            return \StrUtil::back($upload_result4, "EpChangeEdit.callBack");
                        }
                        $record_data["newTypeImg"] = $upload_result4->filepath;
                    }
                    //检验附件 人才联络员备案表
                    if (array_key_exists('beian', $files)) {
                        $upload_result3 = $uploadapi->uploadOne($this->request->file('beian'), 'system');
                        if ($upload_result3->code == 500) {
                            return \StrUtil::back($upload_result3, "EpChangeEdit.callBack");
                        }
                        $record_data["newBeian"] = $upload_result3->filepath;
                    }
                }
                if (!$record_data["newImgurl"]) {
                    throw new ValidateException("请上传营业执照");
                }
                if ($ep->special == 0) {
                    if (!$record_data["newBankImg"]) {
                        throw new ValidateException("请上传开户许可证/基本存款账户信息");
                    }
                    if ($ep->type == 1 && $data['agencyType'] == 1 && !$record_data["newDomainImg"]) {
                        throw new ValidateException("请上传行业领域佐证材料");
                    }
                    if (in_array($record_data["newEnterpriseType"], ["guishang", "gaoxinjishu", "zhuanjingtexin"]) && !$record_data["newTypeImg"]) {
                        throw new ValidateException("规上、高新技术、专精特新企业需要上传佐证材料");
                    }
                    if (!in_array($record_data["newEnterpriseType"], ["guishang", "gaoxinjishu", "zhuanjingtexin"])) {
                        $record_data["newTypeImg"] = null;
                    }
                }
                if (!$record_data["newBeian"]) {
                    throw new ValidateException("请上传人才联络员信息备案表");
                }
                EnterpriseRecord::create($record_data);
                $log = [
                    'id' => getStringId(),
                    'mainId' => $record_data['id'],
                    'category' => 'enterprise_change',
                    'type' => 10,
                    'active' => 1,
                    'state' => 1,
                    'step' => 100,
                    'stateChange' => '保存未提交',
                    'description' => '机构信息变更记录添加成功',
                    'createTime' => date("Y-m-d H:i:s", time()),
                    'createUser' => '用户'
                ];
                $success_msg = "添加成功";
                //$res = ['msg' => '添加成功', 'code' => 200, 'obj' => $record_data];
            } else {
                $record = EnterpriseRecord::find($record_id);
                $ep = Enterprise::where('id', session("user")["uid"])->find();
                $record->oldAgencyType = $ep['agencyType'];
                $record->oldName = $ep['name'];
                $record->oldIdCard = $ep['idCard'];
                $record->oldIndustryFieldNew = $ep['industryFieldNew'];
                $record->oldIndustryFieldOld = $ep['industryFieldOld'];
                $record->oldStreet = $ep['street'];
                $record->oldAddress = $ep['address'];
                $record->oldLegal = $ep['legal'];
                $record->oldEphone = $ep['ephone'];
                $record->oldAgentName = $ep['agentName'];
                $record->oldAgentEmail = $ep['agentEmail'];
                $record->oldAgentPhone = $ep['agentPhone'];
                $record->oldEnterpriseTag = $ep['enterpriseTag'];
                $record->oldOrganizationTag = $ep['organizationTag'];
                $record->oldInstitutionTag = $ep['institutionTag'];
                $record->oldEnterpriseType = $ep['enterpriseType'];
                $record->oldBankCard = $ep['bankCard'];
                $record->oldBank = $ep['bank'];
                $record->oldBankNetwork = $ep['bankNetwork'];
                if ($record->checkState == 1) {
                    $record->newAgencyType = $data['agencyType'];
                    $record->newName = htmlspecialchars($data['name']);
                    $record->newIdCard = htmlspecialchars($data['idCard']);
                    if ($data["agencyType"] == 1) {
                        $record->newIndustryFieldNew = $data['industryFieldNew'];
                        $record->newIndustryFieldOld = $data['industryFieldOld'];
                    } else {
                        $record->newIndustryFieldNew = null;
                        $record->newIndustryFieldOld = null;
                    }
                    $record->newStreet = $data['street'];
                    $record->newAddress = $data['address'];
                    $record->newLegal = $data['legal'];
                    $record->newEphone = $data['ephone'];
                    $record->newAgentName = $data['agentName'];
                    $record->newAgentEmail = $data['agentEmail'];
                    $record->newAgentPhone = $data['agentPhone'];
                    $record->newEnterpriseTag = $data['enterpriseTag'];
                    $record->newOrganizationTag = $data['organizationTag'];
                    $record->newInstitutionTag = $data['institutionTag'];
                    $record->newEnterpriseType = $data['enterpriseType'];
                    $record->newBankCard = $data['bankCard'];
                    $record->newBank = $data['bank'];
                    $record->newBankNetwork = $data['bankNetwork'];
                } else {
                    $fields = array_filter(explode(",", $record->modify_fields));
                    for ($i = 0; $i < count($fields); $i++) {
                        $key = lcfirst(substr($fields[$i], 3));
                        $record[$fields[$i]] = $data[$key]; //仅可修改选择的字段
                    }
                }
                if (!$record["newImgurl"]) {
                    if (strtotime($record["createTime"]) < strtotime($this->compatible_time)) {
                        $where = [];
                        $where[] = ["mainId", "=", $record_id];
                        $where[] = ["api", "=", "businessLicense"];
                        $where[] = ["active", "=", 1];
                        $_uploadFile = TalentCommonFile::alias("tcf")->leftJoin("new_currency_filetype ft", "ft.id=tcf.typeId")->where($where)->order("tcf.createTime desc")->find();
                        if ($_uploadFile) {
                            $record["newImgurl"] = $_uploadFile["url"];
                        } else {
                            $record["newImgurl"] = $ep["imgurl"];
                        }
                    }
                }
                if (!$record["newBankImg"]) {
                    if (strtotime($record["createTime"]) < strtotime($this->compatible_time)) {
                        $where = [];
                        $where[] = ["mainId", "=", $record_id];
                        $where[] = ["api", "=", "businessBank"];
                        $where[] = ["active", "=", 1];
                        $_uploadFile = TalentCommonFile::alias("tcf")->leftJoin("new_currency_filetype ft", "ft.id=tcf.typeId")->where($where)->order("tcf.createTime desc")->find();
                        if ($_uploadFile) {
                            $record["newBankImg"] = $_uploadFile["url"];
                        } else {
                            $record["newBankImg"] = $ep["bankImg"];
                        }
                    }
                }
                if (!$record["newDomainImg"]) {
                    if (strtotime($record["createTime"]) < strtotime($this->compatible_time)) {
                        $where = [];
                        $where[] = ["mainId", "=", $record_id];
                        $where[] = ["api", "=", "businessDomain"];
                        $where[] = ["active", "=", 1];
                        $_uploadFile = TalentCommonFile::alias("tcf")->leftJoin("new_currency_filetype ft", "ft.id=tcf.typeId")->where($where)->order("tcf.createTime desc")->find();
                        if ($_uploadFile) {
                            $record["newDomainImg"] = $_uploadFile["url"];
                        } else {
                            $record["newDomainImg"] = $ep["domainImg"];
                        }
                    }
                }
                if (!$record["newBeian"]) {
                    if (strtotime($record["createTime"]) < strtotime($this->compatible_time)) {
                        $where = [];
                        $where[] = ["mainId", "=", $record_id];
                        $where[] = ["api", "=", "businessBeian"];
                        $where[] = ["active", "=", 1];
                        $_uploadFile = TalentCommonFile::alias("tcf")->leftJoin("new_currency_filetype ft", "ft.id=tcf.typeId")->where($where)->order("tcf.createTime desc")->find();
                        if ($_uploadFile) {
                            $record["newBeian"] = $_uploadFile["url"];
                        } else {
                            $record["newBeian"] = $ep["beian"];
                        }
                    }
                }
                $files = $this->request->file();
                if ($files) {
                    $uploadapi = new UploadApi();
                    $modify_files = array_filter(explode(",", $record->modify_files));
                    if (strtotime($record->createTime) < strtotime($this->compatible_time)) {
                        //旧typeid需要转换成新的禁用文件格式
                        $oldtypes = ["1161965644164075522" => "newImgurl", "1518753449987148467" => "newImgurl", "1518328155588131269" => "newBankImg", "1518926324960220206" => "newBankImg",
                            "1518941016720463523" => "newDomainImg", "1519109971871948101" => "newBeian", "1519185486755815382" => "newBeian"];
                        foreach ($modify_files as $key => $_typeId) {
                            if ($oldtypes[$_typeId]) {
                                $modify_files[$key] = $oldtypes[$_typeId];
                            }
                        }
                    }
                    $uploadAllowed = $record->checkState == 1 || ($record->checkState != 1 && in_array("newImgurl", $modify_files)) ? true : false;
                    if (array_key_exists('imgurl', $files) && $uploadAllowed) {
                        $upload_result = $uploadapi->uploadOne($this->request->file('imgurl'), 'system');
                        if ($upload_result->code == 500) {
                            return \StrUtil::back($upload_result, "EpChangeEdit.callBack");
                        }
                        $record["newImgurl"] = $upload_result->filepath;
                    }
                    //检验附件 开户许可证
                    $uploadAllowed = $record->checkState == 1 || ($record->checkState != 1 && in_array("newBankImg", $modify_files)) ? true : false;
                    if (array_key_exists('bankImg', $files) && $uploadAllowed) {
                        $upload_result1 = $uploadapi->uploadOne($this->request->file('bankImg'), 'system');
                        if ($upload_result1->code == 500) {
                            return \StrUtil::back($upload_result1, "EpChangeEdit.callBack");
                        }
                        $record["newBankImg"] = $upload_result1->filepath;
                    }
                    //检验附件 行业领域佐证材料
                    $uploadAllowed = $record->checkState == 1 || ($record->checkState != 1 && in_array("newDomainImg", $modify_files)) ? true : false;
                    if (array_key_exists('domainImg', $files) && $uploadAllowed) {
                        $upload_result2 = $uploadapi->uploadOne($this->request->file('domainImg'), 'system');
                        if ($upload_result2->code == 500) {
                            return \StrUtil::back($upload_result2, "EpChangeEdit.callBack");
                        }
                        $record["newDomainImg"] = $upload_result2->filepath;
                    }
                    //检验附件 规上、高新技术、专精特新企业需要上传佐证材料
                    $uploadAllowed = $record->checkState == 1 || ($record->checkState != 1 && in_array("newTypeImg", $modify_files)) ? true : false;
                    if (array_key_exists('typeImg', $files) && $uploadAllowed) {
                        $upload_result4 = $uploadapi->uploadOne($this->request->file('typeImg'), 'system');
                        if ($upload_result4->code == 500) {
                            return \StrUtil::back($upload_result4, "EpChangeEdit.callBack");
                        }
                        $record["newTypeImg"] = $upload_result4->filepath;
                    }
                    //检验附件 人才联络员备案表
                    $uploadAllowed = $record->checkState == 1 || ($record->checkState != 1 && in_array("newBeian", $modify_files)) ? true : false;
                    if (array_key_exists('beian', $files) && $uploadAllowed) {
                        $upload_result3 = $uploadapi->uploadOne($this->request->file('beian'), 'system');
                        if ($upload_result3->code == 500) {
                            return \StrUtil::back($upload_result3, "EpChangeEdit.callBack");
                        }
                        $record["newBeian"] = $upload_result3->filepath;
                    }
                }
                if (!$record["newImgurl"]) {
                    throw new ValidateException("请上传营业执照");
                }
                if ($ep->special == 0) {
                    if (!$record["newBankImg"]) {
                        throw new ValidateException("请上传开户许可证/基本存款账户信息");
                    }
                    if ($ep->type == 1 && $data["agencyType"] == 1 && !$record["newDomainImg"]) {
                        throw new ValidateException("请上传行业领域佐证材料");
                    }
                    if ($data["agencyType"] != 1) {
                        $record["newDomainImg"] = null;
                    }
                    if (in_array($record->newEnterpriseType, ["guishang", "gaoxinjishu", "zhuanjingtexin"]) && !$record["newTypeImg"]) {
                        throw new ValidateException("规上、高新技术、专精特新企业需要上传佐证材料");
                    }
                    if (!in_array($record->newEnterpriseType, ["guishang", "gaoxinjishu", "zhuanjingtexin"])) {
                        $record["newTypeImg"] = null;
                    }
                }
                if (!$record["newBeian"]) {
                    throw new ValidateException("请上传人才联络员信息备案表");
                }
                $record->updateTime = date("Y-m-d H:i:s");
                $record->updateUser = session("user")["uid"];
                $record->save();
                $log = [
                    'id' => getStringId(),
                    'category' => 'enterprise_change',
                    'mainId' => '',
                    'type' => 10,
                    'active' => 1,
                    'state' => 1,
                    'step' => 100,
                    'stateChange' => '保存未提交',
                    'description' => '机构信息变更记录修改成功',
                    'createTime' => date("Y-m-d H:i:s", time()),
                    'createUser' => '用户'
                ];
                $success_msg = "修改成功";
                //$res = ['msg' => '修改成功', 'code' => 200, 'obj' => $record];
            }
            TalentChecklog::create($log);
            $response_object->id = $record_id;
            $response_object->code = 200;
            $response_object->msg = $success_msg;
            return \StrUtil::back($response_object, "EpChangeEdit.callBack");
            //return json($res);
        } catch (ValidateException $e) {
            $response_object->code = 500;
            $response_object->msg = is_array($e->getError()) ? implode("
", $e->getError()) : $e->getError();
            return \StrUtil::back($response_object, "EpChangeEdit.callBack");
            //return json(["msg" => array_pop($error), 'code' => 500]);
        }
    }
    public function toUpdate() {
        $id = trim($this->request['id']);
        $ecr = EnterpriseRecord::findOrEmpty($id);
        $ep = Enterprise::where('id', $ecr->mainId)->find();
        $ecr["special"] = $ep["special"];
        $time = $this->compatible_time;
        if (strtotime($ecr["createTime"]) < strtotime($time)) {
            $_files = explode(",", $ecr["modify_files"]);
            $_new_files = [];
            foreach ($_files as $_file) {
                $where = [];
                $where[] = ["id", "=", $_file];
                $_filetype = CurrentcyFileType::where($where)->find();
                switch ($_filetype["api"]) {
                    case "businessLicense":
                        $_new_files[] = "newImgurl";
                        break;
                    case "businessBank";
                        $_new_files[] = "newBankImg";
                        break;
                    case "businessDomain";
                        $_new_files[] = "newDomainImg";
                        break;
                    case "businessBeian";
                        $_new_files[] = "newBeian";
                        break;
                    default:
                        $_new_files[] = $_file;
                        break;
                }
            }
            $ecr["modify_files"] = implode(",", $_new_files);
        }
        //营业执照
        if (!$ecr["newImgurl"]) {
            //兼容旧filetype
            if (strtotime($ecr["createTime"]) < strtotime($time)) {
                $where = [];
                $where[] = ["mainId", "=", $id];
                $where[] = ["api", "=", "businessLicense"];
                $where[] = ["active", "=", 1];
                $_uploadFile = TalentCommonFile::alias("tcf")->leftJoin("new_currency_filetype ft", "ft.id=tcf.typeId")->where($where)->order("tcf.createTime desc")->find();
                if ($_uploadFile) {
                    $ecr["newImgurl"] = $_uploadFile["url"];
                } else {
                    $ecr["newImgurl"] = $ep["imgurl"];
                }
            }
        }
        if ($ecr["newImgurl"]) {
            $pathinfo = pathinfo($ecr["newImgurl"]);
            if (in_array($pathinfo["extension"], ["jpeg", "jpg", "png", "gif"])) {
                $ecr["imgurl_is_img"] = 1;
            }
        }
        //备案表
        if (!$ecr["newBeian"]) {
            //兼容旧filetype
            if (strtotime($ecr["createTime"]) < strtotime($time)) {
                $where = [];
                $where[] = ["mainId", "=", $id];
                $where[] = ["api", "=", "businessBeian"];
                $where[] = ["active", "=", 1];
                $_uploadFile = TalentCommonFile::alias("tcf")->leftJoin("new_currency_filetype ft", "ft.id=tcf.typeId")->where($where)->order("tcf.createTime desc")->find();
                if ($_uploadFile) {
                    $ecr["newBeian"] = $_uploadFile["url"];
                } else {
                    $ecr["newBeian"] = $ep["beian"];
                }
            }
        }
        if ($ecr["newBeian"]) {
            $pathinfo = pathinfo($ecr["newBeian"]);
            if (in_array($pathinfo["extension"], ["jpeg", "jpg", "png", "gif"])) {
                $ecr["beian_is_img"] = 1;
            }
        }
        //行业领域
        if (!$ecr["newDomainImg"]) {
            //兼容旧filetype
            if (strtotime($ecr["createTime"]) < strtotime($time)) {
                $where = [];
                $where[] = ["mainId", "=", $id];
                $where[] = ["api", "=", "businessDomain"];
                $where[] = ["active", "=", 1];
                $_uploadFile = TalentCommonFile::alias("tcf")->leftJoin("new_currency_filetype ft", "ft.id=tcf.typeId")->where($where)->order("tcf.createTime desc")->find();
                if ($_uploadFile) {
                    $ecr["newDomainImg"] = $_uploadFile["url"];
                } else {
                    $ecr["newDomainImg"] = $ep["domainImg"];
                }
            }
        }
        if ($ecr["newDomainImg"]) {
            $pathinfo = pathinfo($ecr["newDomainImg"]);
            if (in_array($pathinfo["extension"], ["jpeg", "jpg", "png", "gif"])) {
                $ecr["domainImg_is_img"] = 1;
            }
        }
        //规上、高新技术、专精特新企业需要上传佐证材料        
        if ($ecr["newTypeImg"]) {
            $pathinfo = pathinfo($ecr["newTypeImg"]);
            if (in_array($pathinfo["extension"], ["jpeg", "jpg", "png", "gif"])) {
                $ecr["typeImg_is_img"] = 1;
            }
        }
        //开户许可证
        if (!$ecr["newBankImg"]) {
            //兼容旧filetype
            if (strtotime($ecr["createTime"]) < strtotime($time)) {
                $where = [];
                $where[] = ["mainId", "=", $id];
                $where[] = ["api", "=", "businessBank"];
                $where[] = ["active", "=", 1];
                $_uploadFile = TalentCommonFile::alias("tcf")->leftJoin("new_currency_filetype ft", "ft.id=tcf.typeId")->where($where)->order("tcf.createTime desc")->find();
                if ($_uploadFile) {
                    $ecr["newBankImg"] = $_uploadFile["url"];
                } else {
                    $ecr["newBankImg"] = $ep["bankImg"];
                }
            }
        }
        if ($ecr["newBankImg"]) {
            $pathinfo = pathinfo($ecr["newBankImg"]);
            if (in_array($pathinfo["extension"], ["jpeg", "jpg", "png", "gif"])) {
                $ecr["bankImg_is_img"] = 1;
            }
        }
        switch ($ep->special) {
            case 0:
                return view("", ['ecr' => $ecr]);
                break;
            case 1:
                return view("", ['ecr' => $ecr]);
                break;
            case 3:
                return view("", ['ecr' => $ecr]);
                break;
            default:
                break;
        }
    }
    public function submitToCheck() {
        $id = trim($this->request->post('id'));
        if (!$id) {
            return json(['msg' => '记录为空', 'code' => 500]);
        }
        $obj = EnterpriseRecord::find($id);
        if (!$obj) {
            return json(['msg' => '提交审核失败,请先填写基础信息', 'code' => 500]);
        }
        if ($obj['checkState'] != 1 && $obj['checkState'] != 3) {
            return json(['msg' => '不能重复提交审核', 'code' => 500]);
        }
        $ep = EnterpriseApi::getOne($obj->mainId);
        //20220918增加根据不同的企业类型显示不同的信息变更界面|20221014废弃使用filetype
        /* switch ($ep->special) {
          case 0:
          $org_type = 'enterpriseChange';
          break;
          case 1:
          $org_type = 'governmentChange';
          break;
          default:
          break;
          }
          $list = CurrentcyFileType::where('type', $org_type)->where('active', 1)->select();
          if (!$list || count($list) <= 0) {
          return json(['msg' => '缺少附件', 'code' => 500]);
          }
          $error_msg = "";
          foreach ($list as $k => $v) {
          if ($v['must'] == 1) {
          $count = TalentCommonFile::where('mainId', $id)->where('typeId', $v['id'])->count();
          if ($count == 0) {
          if (strlen($error_msg) == 0) {
          $error_msg = "以下为必传附件:";
          }
          $error_msg .= $v['name'] . ";";
          }
          }
          }
          if (strlen($error_msg) > 0) {
          return json(['msg' => $error_msg, 'code' => 500]);
          } */
        if ($obj['checkState'] == 3) {
            $obj['checkState'] = 5;
            $state = 5;
        } else {
            $obj['checkState'] = 2;
            $state = 2;
        }
        $obj->save();
        $log = [
            'id' => getStringId(),
            'category' => 'enterprise_change',
            'mainId' => $id,
            'type' => 10,
            'active' => 1,
            'state' => $state,
            'step' => 100,
            'stateChange' => "待提交->待审核",
            'description' => '提交审核',
            'createTime' => date("Y-m-d H:i:s", time()),
            'createUser' => '用户'
        ];
        TalentChecklog::create($log);
        return json(['msg' => '提交审核成功', 'code' => 200, 'obj' => 1]);
    }
    public function toDetail() {
        $id = trim($this->request['id']);
        if (!$id) {
            return json(['msg' => '记录为空', 'code' => 500]);
        }
        $ecr = EnterpriseRecord::find($id);
        $ep = EnterpriseApi::getOne($ecr['mainId']);
        $streetList = DictApi::selectByParentCode('street');
        $ecr["special"] = $ep["special"];
        $ecr['oldStreetName'] = $streetList[$ecr['oldStreet']];
        $ecr['newStreetName'] = $streetList[$ecr['newStreet']];
        //20220918增加根据不同的企业类型显示不同的信息变更界面
        $time = $this->compatible_time;
        //营业执照
        if (!$ecr["oldImgurl"]) {
            $ecr["oldImgurl"] = $ep["imgurl"];
        }
        if ($ecr["oldImgurl"]) {
            $pathinfo = pathinfo($ecr["oldImgurl"]);
            if (in_array($pathinfo["extension"], ["jpeg", "jpg", "png", "gif"])) {
                $ecr["oldImgurl_is_img"] = 1;
            }
        }
        if (!$ecr["newImgurl"]) {
            //兼容旧filetype
            if (strtotime($ecr["createTime"]) < strtotime($time)) {
                $where = [];
                $where[] = ["mainId", "=", $id];
                $where[] = ["api", "=", "businessLicense"];
                $where[] = ["active", "=", 1];
                $_uploadFile = TalentCommonFile::alias("tcf")->leftJoin("new_currency_filetype ft", "ft.id=tcf.typeId")->where($where)->order("tcf.createTime desc")->find();
                if ($_uploadFile) {
                    $ecr["newImgurl"] = $_uploadFile["url"];
                } else {
                    $ecr["newImgurl"] = $ep["imgurl"];
                }
            }
        }
        if ($ecr["newImgurl"]) {
            $pathinfo = pathinfo($ecr["newImgurl"]);
            if (in_array($pathinfo["extension"], ["jpeg", "jpg", "png", "gif"])) {
                $ecr["newImgurl_is_img"] = 1;
            }
        }
        //备案表
        if (!$ecr["oldBeian"]) {
            $ecr["oldBeian"] = $ep["beian"];
        }
        if ($ecr["oldBeian"]) {
            $pathinfo = pathinfo($ecr["oldBeian"]);
            if (in_array($pathinfo["extension"], ["jpeg", "jpg", "png", "gif"])) {
                $ecr["oldBeian_is_img"] = 1;
            }
        }
        if (!$ecr["newBeian"]) {
            //兼容旧filetype
            if (strtotime($ecr["createTime"]) < strtotime($time)) {
                $where = [];
                $where[] = ["mainId", "=", $id];
                $where[] = ["api", "=", "businessBeian"];
                $where[] = ["active", "=", 1];
                $_uploadFile = TalentCommonFile::alias("tcf")->leftJoin("new_currency_filetype ft", "ft.id=tcf.typeId")->where($where)->order("tcf.createTime desc")->find();
                if ($_uploadFile) {
                    $ecr["newBeian"] = $_uploadFile["url"];
                } else {
                    $ecr["newBeian"] = $ep["beian"];
                }
            }
        }
        if ($ecr["newBeian"]) {
            $pathinfo = pathinfo($ecr["newBeian"]);
            if (in_array($pathinfo["extension"], ["jpeg", "jpg", "png", "gif"])) {
                $ecr["newBeian_is_img"] = 1;
            }
        }
        //行业领域
        if (!$ecr["oldDomainImg"]) {
            $ecr["oldDomainImg"] = $ep["domainImg"];
        }
        if ($ecr["oldDomainImg"]) {
            $pathinfo = pathinfo($ecr["oldDomainImg"]);
            if (in_array($pathinfo["extension"], ["jpeg", "jpg", "png", "gif"])) {
                $ecr["oldDomainImg_is_img"] = 1;
            }
        }
        if (!$ecr["newDomainImg"]) {
            //兼容旧filetype
            if (strtotime($ecr["createTime"]) < strtotime($time)) {
                $where = [];
                $where[] = ["mainId", "=", $id];
                $where[] = ["api", "=", "businessDomain"];
                $where[] = ["active", "=", 1];
                $_uploadFile = TalentCommonFile::alias("tcf")->leftJoin("new_currency_filetype ft", "ft.id=tcf.typeId")->where($where)->order("tcf.createTime desc")->find();
                if ($_uploadFile) {
                    $ecr["newDomainImg"] = $_uploadFile["url"];
                } else {
                    $ecr["newDomainImg"] = $ep["domainImg"];
                }
            }
        }
        if ($ecr["newDomainImg"]) {
            $pathinfo = pathinfo($ecr["newDomainImg"]);
            if (in_array($pathinfo["extension"], ["jpeg", "jpg", "png", "gif"])) {
                $ecr["newDomainImg_is_img"] = 1;
            }
        }
        //规上、高新技术、专精特新企业需要上传佐证材料
        if ($ecr["oldTypeImg"]) {
            $pathinfo = pathinfo($ecr["oldTypeImg"]);
            if (in_array($pathinfo["extension"], ["jpeg", "jpg", "png", "gif"])) {
                $ecr["oldTypeImg_is_img"] = 1;
            }
        }
        if ($ecr["newTypeImg"]) {
            $pathinfo = pathinfo($ecr["newTypeImg"]);
            if (in_array($pathinfo["extension"], ["jpeg", "jpg", "png", "gif"])) {
                $ecr["newTypeImg_is_img"] = 1;
            }
        }
        //开户许可证
        if (!$ecr["oldBankImg"]) {
            $ecr["oldBankImg"] = $ep["bankImg"];
        }
        if ($ecr["oldBankImg"]) {
            $pathinfo = pathinfo($ecr["oldBankImg"]);
            if (in_array($pathinfo["extension"], ["jpeg", "jpg", "png", "gif"])) {
                $ecr["oldBankImg_is_img"] = 1;
            }
        }
        if (!$ecr["newBankImg"]) {
            //兼容旧filetype
            if (strtotime($ecr["createTime"]) < strtotime($time)) {
                $where = [];
                $where[] = ["mainId", "=", $id];
                $where[] = ["api", "=", "businessBank"];
                $where[] = ["active", "=", 1];
                $_uploadFile = TalentCommonFile::alias("tcf")->leftJoin("new_currency_filetype ft", "ft.id=tcf.typeId")->where($where)->order("tcf.createTime desc")->find();
                if ($_uploadFile) {
                    $ecr["newBankImg"] = $_uploadFile["url"];
                } else {
                    $ecr["newBankImg"] = $ep["bankImg"];
                }
            }
        }
        if ($ecr["newBankImg"]) {
            $pathinfo = pathinfo($ecr["newBankImg"]);
            if (in_array($pathinfo["extension"], ["jpeg", "jpg", "png", "gif"])) {
                $ecr["newBankImg_is_img"] = 1;
            }
        }
        switch ($ep->special) {
            case 0:
                $agencyTypeList = DictApi::selectByParentCode('agency_type');
                $tagList = DictApi::selectByParentCode('enterprise_tag');
                $typeList = DictApi::selectByParentCode('enterprise_type');
                $industryFieldNew = DictApi::selectByParentCode('industry_field');
                $industry = DictApi::findDictByCode($ecr['oldIndustryFieldOld']);
                $ecr['oldIndustryFieldOldName'] = $industry['name'];
                $industry = DictApi::findDictByCode($ecr['newIndustryFieldOld']);
                $ecr['newIndustryFieldOldName'] = $industry['name'];
                $ecr['oldEnterpriseTagName'] = $tagList[$ecr['oldEnterpriseTag']];
                $ecr['newEnterpriseTagName'] = $tagList[$ecr['newEnterpriseTag']];
                $ecr['oldEnterpriseTypeName'] = $typeList[$ecr['oldEnterpriseType']];
                $ecr['newEnterpriseTypeName'] = $typeList[$ecr['newEnterpriseType']];
                $ecr['oldIndustryFieldNewName'] = $industryFieldNew[$ecr['oldIndustryFieldNew']];
                $ecr['newIndustryFieldNewName'] = $industryFieldNew[$ecr['newIndustryFieldNew']];
                $ecr['oldAgencyTypeName'] = $agencyTypeList[$ecr['oldAgencyType']];
                $ecr['newAgencyTypeName'] = $agencyTypeList[$ecr['newAgencyType']];
                return view("", ['ecr' => $ecr]);
                break;
            case 1:
                $tagList = DictApi::selectByParentCode('institution_tag');
                $ecr['oldInstitutionTagName'] = $tagList[$ecr['oldInstitutionTag']];
                $ecr['newInstitutionTagName'] = $tagList[$ecr['newInstitutionTag']];
                return view("", ['ecr' => $ecr]);
                break;
            case 3:
                $tagList = DictApi::selectByParentCode('organization_tag');
                $ecr['oldOrganizationTagName'] = $tagList[$ecr['oldOrganizationTag']];
                $ecr['newOrganizationTagName'] = $tagList[$ecr['newOrganizationTag']];
                return view("", ['ecr' => $ecr]);
                break;
            default:
                break;
        }
    }
}