| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707 | <?phpnamespace app\common\controller;use app\BaseController;use app\common\api\ChuanglanSmsApi;use app\common\api\EnterpriseApi;use app\common\model\MessageRecord;use app\common\model\TalentChecklog;use think\facade\Cache;use app\common\validate\Enterprise;use app\common\validate\Person;use think\exception\ValidateException;use think\facade\Request;use app\common\api\UploadApi;use app\enterprise\model\Talent;use app\common\api\TalentState;class Auth extends BaseController {    private function checkRegisterTime($special, $type1, $type2 = null) {        $now = time();        $key = "";        $agency_label = "";        $registerCfg = \app\common\model\SysConfig::where("key", "register")->find();        if ($registerCfg) {            $registerCfg = json_decode($registerCfg["value"], true);            switch ($special) {                case 0://企业                    if ($type1 == 1) {                        //晋江人才                        if ($type2 == 1) {                            //4341                            $key = "jjrc_4341";                            $agency_label = "晋江市现代产业体系人才(4341现代产业体系)";                        } else {                            //非4341                            $key = "jjrc_no4341";                            $agency_label = "晋江市现代产业体系人才(非4341现代产业体系)";                        }                    } else if ($type1 == 2) {                        //电路人才                        $key = "jcrc";                        $agency_label = "集成电路优秀人才";                    }                    break;                case 1://事业                    if ($type1 == "institution_common") {                        $key = "sy_nomedia";                        $agency_label = "事业单位-非媒体单位";                    } else if ($type1 == "institution_media") {                        $key = "sy_media";                        $agency_label = "事业单位-媒体单位";                    }                    break;                case 3://民非                    if ($type1 == "minfei") {                        $key = "mbfqy";                        $agency_label = "民办非企业";                    }                    break;            }            if ($registerCfg[$key]) {                list($startdate, $enddate) = explode(" - ", $registerCfg[$key]);                $starttime = strtotime($startdate . "00:00:00");                $endtime = strtotime($enddate . "23:59:59");                if ($starttime && $endtime && ($now < $starttime || $now > $endtime)) {                    $response_object = new \StdClass();                    $response_object->code = 500;                    $response_object->msg = sprintf("您注册的类型【%s】不在可注册时间内(%s)", $agency_label, $registerCfg[$key]);                    return $response_object;                }            }        }        return true;    }    public function register() {        $msg = "";        if ($this->request->isPost()) {            $source = 3; //intval($this->request['source']);            $response_object = new \StdClass();            $special = \StrUtil::getRequestDecodeParam($this->request, 'special');            $data = [                'username' => \StrUtil::getRequestDecodeParam($this->request, 'username'),                'password' => \StrUtil::getRequestDecodeParam($this->request, 'password'),                're_password' => \StrUtil::getRequestDecodeParam($this->request, 're_password'),                'name' => \StrUtil::getRequestDecodeParam($this->request, 'name'),                'idCard' => \StrUtil::getRequestDecodeParam($this->request, 'idCard'),                'agentName' => \StrUtil::getRequestDecodeParam($this->request, 'agentName'),                'agentPhone' => \StrUtil::getRequestDecodeParam($this->request, 'agentPhone'),                'verificationCode' => \StrUtil::getRequestDecodeParam($this->request, 'verificationCode'),                'legal' => \StrUtil::getRequestDecodeParam($this->request, 'legal'),                'street' => \StrUtil::getRequestDecodeParam($this->request, 'street'),                'address' => \StrUtil::getRequestDecodeParam($this->request, 'address'),                'type' => intval($this->request['type']),                'agencyType' => intval($this->request['agencyType']),                'enterpriseTag' => \StrUtil::getRequestDecodeParam($this->request, 'enterpriseTag'),                'organizationTag' => \StrUtil::getRequestDecodeParam($this->request, 'organizationTag'),                'institutionTag' => \StrUtil::getRequestDecodeParam($this->request, 'institutionTag'),                'enterpriseType' => \StrUtil::getRequestDecodeParam($this->request, 'enterpriseType'),                'agentEmail' => \StrUtil::getRequestDecodeParam($this->request, 'agentEmail'),                'ephone' => \StrUtil::getRequestDecodeParam($this->request, 'ephone'),                'industryFieldNew' => \StrUtil::getRequestDecodeParam($this->request, 'industryFieldNew'),                'industryFieldOld' => \StrUtil::getRequestDecodeParam($this->request, 'industryFieldOld'),                'bankCard' => \StrUtil::getRequestDecodeParam($this->request, 'bankCard'),                'bank' => \StrUtil::getRequestDecodeParam($this->request, 'bank'),                'bankNetwork' => \StrUtil::getRequestDecodeParam($this->request, 'bankNetwork')            ];            try {                if (stripos($data['name'], "(")) {                    $data['name'] = str_replace('(', '(', $data['name']);                }                if (stripos($data['name'], ")")) {                    $data['name'] = str_replace(')', ')', $data['name']);                }                $files = $this->request->file();                switch ($special) {                    case 'qiye':                        if ($data['type'] == 1) {                            if ($data["agencyType"] == 1) {                                validate(Enterprise::class)->batch(true)->scene('add')->check($data);                                $registerTimeLimitReturnObj = $this->checkRegisterTime(0, $data['type'], $data["agencyType"]);                                if ($registerTimeLimitReturnObj !== true)                                    return \StrUtil::back($registerTimeLimitReturnObj, "Register.epCallBack");                                if (!array_key_exists('domainImg', $files) || $files['domainImg'] == '') {                                    $response_object->code = 500;                                    $response_object->msg = '行业领域佐证材料不能为空';                                    return \StrUtil::back($response_object, "Register.epCallBack");                                }                            } else {                                validate(Enterprise::class)->batch(true)->scene('add2')->check($data);                                $registerTimeLimitReturnObj = $this->checkRegisterTime(0, $data['type'], $data["agencyType"]);                                if ($registerTimeLimitReturnObj !== true)                                    return \StrUtil::back($registerTimeLimitReturnObj, "Register.epCallBack");                            }                            $checkTypes = ["guishang", "gaoxinjishu", "zhuanjingtexin"];                            if (in_array($data["enterpriseType"], $checkTypes) && (!array_key_exists('typeImg', $files) || $files['typeImg'] == '')) {                                $response_object->code = 500;                                $response_object->msg = '规上、高新技术、专精特新企业需要上传佐证材料';                                return \StrUtil::back($response_object, "Register.epCallBack");                            }                            if (!array_key_exists('bankImg', $files) || $files['bankImg'] == '') {                                $response_object->code = 500;                                $response_object->msg = '开户许可证/基本存款账户信息不能为空';                                return \StrUtil::back($response_object, "Register.epCallBack");                            }                        } else {                            validate(Enterprise::class)->batch(true)->scene('jc_add')->check($data); //集成电路                            $registerTimeLimitReturnObj = $this->checkRegisterTime(0, $data['type']);                            if ($registerTimeLimitReturnObj !== true)                                return \StrUtil::back($registerTimeLimitReturnObj, "Register.epCallBack");                        }                        if (!array_key_exists('imgurl', $files) || $files['imgurl'] == '') {                            $response_object->code = 500;                            $response_object->msg = '营业执照不能为空';                            return \StrUtil::back($response_object, "Register.epCallBack");                        }                        if (!array_key_exists('beian', $files) || $files['beian'] == '') {                            $response_object->code = 500;                            $response_object->msg = '人才联络员备案表不能为空';                            return \StrUtil::back($response_object, "Register.epCallBack");                        }                        $data['special'] = 0;                        break;                    case 'minfei':                        $data['type'] = 1;                        $registerTimeLimitReturnObj = $this->checkRegisterTime(3, $data['organizationTag']);                        if ($registerTimeLimitReturnObj !== true)                            return \StrUtil::back($registerTimeLimitReturnObj, "Register.epCallBack");                        if (!array_key_exists('imgurl', $files) || $files['imgurl'] == '') {                            $response_object->code = 500;                            $response_object->msg = '营业执照不能为空';                            return \StrUtil::back($response_object, "Register.epCallBack");                        }                        if (!array_key_exists('bankImg', $files) || $files['bankImg'] == '') {                            $response_object->code = 500;                            $response_object->msg = '开户许可证/基本存款账户信息不能为空';                            return \StrUtil::back($response_object, "Register.epCallBack");                        }                        if (!array_key_exists('beian', $files) || $files['beian'] == '') {                            $response_object->code = 500;                            $response_object->msg = '人才联络员备案表不能为空';                            return \StrUtil::back($response_object, "Register.epCallBack");                        }                        $data['special'] = 3;                        break;                    case 'shiye':                        $data['type'] = 1;                        validate(Enterprise::class)->batch(true)->scene('sy_add')->check($data); //事业单位                        $registerTimeLimitReturnObj = $this->checkRegisterTime(1, $data['institutionTag']);                        if ($registerTimeLimitReturnObj !== true)                            return \StrUtil::back($registerTimeLimitReturnObj, "Register.epCallBack");                        if (!array_key_exists('imgurl', $files) || $files['imgurl'] == '') {                            $response_object->code = 500;                            $response_object->msg = '法人代表证或批文不能为空';                            return \StrUtil::back($response_object, "Register.epCallBack");                        }                        $data['special'] = 1;                        break;                }                //检验验证码                $codeResult = MessageRecord::where('smsType', 1)->where('phone', $data['agentPhone'])->order('createTime', 'desc')->find();                if (!$codeResult) {                    $response_object->code = 500;                    $response_object->msg = '请先发送验证码';                    return \StrUtil::back($response_object, "Register.epCallBack");                }                if ($codeResult['params'] != $data["verificationCode"]) {                    $response_object->code = 500;                    $response_object->msg = '验证码错误';                    return \StrUtil::back($response_object, "Register.epCallBack");                }                if (time() - strtotime($codeResult['createTime']) > 300) {                    $response_object->code = 500;                    $response_object->msg = '验证码过期,请重新发送';                    return \StrUtil::back($response_object, "Register.epCallBack");                }                $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, "Register.epCallBack");                    }                    $imgurl = $upload_result->filepath;                } else {                    $imgurl = '';                }                //检验附件 开户许可证                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, "Register.epCallBack");                    }                    $bankImg = $upload_result1->filepath;                } else {                    $bankImg = '';                }                //检验附件 行业领域佐证材料                if (array_key_exists('domainImg', $files)) {                    $upload_result2 = $uploadapi->uploadOne($this->request->file('domainImg'), 'system');                    if ($upload_result2->code == 500) {                        return \StrUtil::back($upload_result2, "Register.epCallBack");                    }                    $domainImg = $upload_result2->filepath;                } else {                    $domainImg = '';                }                //检验附件 行业领域佐证材料                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, "Register.epCallBack");                    }                    $typeImg = $upload_result4->filepath;                } else {                    $typeImg = '';                }                //检验附件 人才联络员备案表                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, "Register.epCallBack");                    }                    $beian = $upload_result3->filepath;                } else {                    $beian = '';                }                $data['id'] = getStringId();                $data['password'] = hash('md5', $data['password']);                $data['source'] = $source;                $data['imgurl'] = $imgurl;                $data['bankImg'] = $bankImg;                $data['domainImg'] = $domainImg;                $data["typeImg"] = $typeImg;                $data['beian'] = $beian;                $data['createTime'] = date("Y-m-d H:i:s", time());                $data['updateTime'] = date("Y-m-d H:i:s", time());                $data['active'] = 1;                $data['checkState'] = 1;                \app\common\model\Enterprise::create($data);                TalentChecklog::create([                    'id' => getStringId(),                    'mainId' => $data['id'],                    'type' => 10,                    'typeField' => null,                    'active' => 1,                    'state' => 1,                    'step' => 100,                    'stateChange' => '用户提交',                    'description' => '用户注册',                    'createTime' => date("Y-m-d H:i:s", time()),                    'createUser' => '用户'                ]);                $response_object->code = 200;                $response_object->msg = '注册成功';                return \StrUtil::back($response_object, "Register.epCallBack");            } catch (ValidateException $e) {                $error = $e->getError();                $response_object->code = 500;                $response_object->msg = array_pop($error);                return \StrUtil::back($response_object, "Register.epCallBack");            }        }        return view("", ["msg" => $msg]);    }    public function enterprise_edit() {        $temp = session('temp');        if (empty($temp)) {            return redirect("/");        }        $ep = EnterpriseApi::getOne(session('temp')['uid']);        if ($this->request->isPost()) {            $response_object = new \StdClass();            $data = $ep->toArray();            $data = [                'name' => \StrUtil::getRequestDecodeParam($this->request, 'name'), //单位名称                'idCard' => \StrUtil::getRequestDecodeParam($this->request, 'idCard'), //统一社会信用代码                'agentName' => \StrUtil::getRequestDecodeParam($this->request, 'agentName'), //人才联络员                'legal' => \StrUtil::getRequestDecodeParam($this->request, 'legal'), //法人                'street' => \StrUtil::getRequestDecodeParam($this->request, 'street'), //镇街                'address' => \StrUtil::getRequestDecodeParam($this->request, 'address'), //地址                'type' => intval($this->request['type']),                'agencyType' => intval($this->request['agencyType']),                'enterpriseTag' => \StrUtil::getRequestDecodeParam($this->request, 'enterpriseTag'), //单位标签                'organizationTag' => \StrUtil::getRequestDecodeParam($this->request, 'organizationTag'), //机构标签                'institutionTag' => \StrUtil::getRequestDecodeParam($this->request, 'institutionTag'), //事业单位标签                'enterpriseType' => \StrUtil::getRequestDecodeParam($this->request, 'enterpriseType'), //单位类型                'agentPhone' => \StrUtil::getRequestDecodeParam($this->request, 'agentPhone'), //手机                'agentEmail' => \StrUtil::getRequestDecodeParam($this->request, 'agentEmail'), //邮箱                'ephone' => \StrUtil::getRequestDecodeParam($this->request, 'ephone'), //单位电话                'industryFieldNew' => \StrUtil::getRequestDecodeParam($this->request, 'industryFieldNew'), //产业领域                'industryFieldOld' => \StrUtil::getRequestDecodeParam($this->request, 'industryFieldOld'), //行业领域                'bankCard' => \StrUtil::getRequestDecodeParam($this->request, 'bankCard'), //银行                'bank' => \StrUtil::getRequestDecodeParam($this->request, 'bank'), //开户行                'bankNetwork' => \StrUtil::getRequestDecodeParam($this->request, 'bankNetwork')//网点            ];            $ep->modify_fields = null; //注释注册驳回:如果要开启驳回,注释或者删掉这句话及上面那段 $data = [...];            if ($ep->modify_fields) {                $modify_fields = explode(",", $ep->modify_fields);                foreach ($modify_fields as $field) {                    $data[$field] = \StrUtil::getRequestDecodeParam($this->request, $field);                }            }            $modify_files = ["imgurl", "bankImg", "domainImg", "typeImg", "beian"]; //注释注册驳回:如果要开启驳回,用explode(",", $ep->modify_files)替换["imgurl", "bankImg", "domainImg", "typeImg", "beian"]这句代码;            $files = $this->request->file();            if ($files) {                $uploadapi = new UploadApi();                if (array_key_exists('imgurl', $files) && in_array('imgurl', $modify_files)) {                    $upload_result = $uploadapi->uploadOne($this->request->file('imgurl'), 'system');                    if ($upload_result->code == 500) {                        return \StrUtil::back($upload_result, "Register.epCallBack");                    }                    $data["imgurl"] = $upload_result->filepath;                }                //检验附件 开户许可证                if (array_key_exists('bankImg', $files) && in_array('bankImg', $modify_files)) {                    $upload_result1 = $uploadapi->uploadOne($this->request->file('bankImg'), 'system');                    if ($upload_result1->code == 500) {                        return \StrUtil::back($upload_result1, "Register.epCallBack");                    }                    $data["bankImg"] = $upload_result1->filepath;                }                //检验附件 行业领域佐证材料                if (array_key_exists('domainImg', $files) && in_array('domainImg', $modify_files)) {                    $upload_result2 = $uploadapi->uploadOne($this->request->file('domainImg'), 'system');                    if ($upload_result2->code == 500) {                        return \StrUtil::back($upload_result2, "Register.epCallBack");                    }                    $data["domainImg"] = $upload_result2->filepath;                }                //检验附件 行业领域佐证材料                if (array_key_exists('typeImg', $files) && in_array('typeImg', $modify_files)) {                    $upload_result4 = $uploadapi->uploadOne($this->request->file('typeImg'), 'system');                    if ($upload_result4->code == 500) {                        return \StrUtil::back($upload_result4, "Register.epCallBack");                    }                    $data["typeImg"] = $upload_result4->filepath;                }                //检验附件 人才联络员备案表                if (array_key_exists('beian', $files) && in_array('beian', $modify_files)) {                    $upload_result3 = $uploadapi->uploadOne($this->request->file('beian'), 'system');                    if ($upload_result3->code == 500) {                        return \StrUtil::back($upload_result3, "Register.epCallBack");                    }                    $data["beian"] = $upload_result3->filepath;                }            }            try {                if ($data['name'] && stripos($data['name'], "(")) {                    $data['name'] = str_replace('(', '(', $data['name']);                }                if ($data['name'] && stripos($data['name'], ")")) {                    $data['name'] = str_replace(')', ')', $data['name']);                }                $data['id'] = $ep->id;                if ($ep->special == 0) {                    if ($data["type"] == 1) {                        if ($data["agencyType"] == 1) {                            validate(\app\common\validate\Enterprise::class)->batch(true)->scene('change')->check($data);                            if (!$data["domainImg"] && !$ep->domainImg) {                                $response_object->code = 500;                                $response_object->msg = "行业领域佐证材料不能为空";                                return \StrUtil::back($response_object, "Register.epCallBack");                            }                        } else {                            validate(\app\common\validate\Enterprise::class)->batch(true)->scene('change2')->check($data);                        }                        $checkTypes = ["guishang", "gaoxinjishu", "zhuanjingtexin"];                        if (in_array($data["enterpriseType"], $checkTypes) && (!$data["typeImg"] && !$ep->typeImg)) {                            $response_object->code = 500;                            $response_object->msg = '规上、高新技术、专精特新企业需要上传佐证材料';                            return \StrUtil::back($response_object, "Register.epCallBack");                        }                        if (!$data["bankImg"] && !$ep->bankImg) {                            $response_object->code = 500;                            $response_object->msg = '开户许可证/基本存款账户信息不能为空';                            return \StrUtil::back($response_object, "Register.epCallBack");                        }                    } else {                        validate(\app\common\validate\Enterprise::class)->batch(true)->scene('jc_change')->check($data);                    }                    if (!$data["imgurl"] && !$ep->imgurl) {                        $response_object->code = 500;                        $response_object->msg = '营业执照不能为空';                        return \StrUtil::back($response_object, "Register.epCallBack");                    }                    if (!$data["beian"] && !$ep->beian) {                        $response_object->code = 500;                        $response_object->msg = '人才联络员备案表不能为空';                        return \StrUtil::back($response_object, "Register.epCallBack");                    }                } else {                    validate(\app\common\validate\Enterprise::class)->batch(true)->scene('sy_change')->check($data);                    if (!$data["imgurl"] && !$ep->imgurl) {                        $response_object->code = 500;                        $response_object->msg = '法人代表证或批文不能为空';                        return \StrUtil::back($response_object, "Register.epCallBack");                    }                }                //unset($data["agentPhone"]);                $data['checkState'] = 4;                $data["updateTime"] = date("Y-m-d H:i:s");                $ep->update($data);                TalentChecklog::create([                    'id' => getStringId(),                    'mainId' => $data['id'],                    'type' => 10,                    'typeField' => null,                    'active' => 1,                    'state' => 4,                    'step' => 100,                    'stateChange' => '用户提交',                    'description' => '用户信息修改成功',                    'createTime' => date("Y-m-d H:i:s", time()),                    'createUser' => '用户'                ]);                $response_object->code = 200;                $response_object->msg = '修改成功';                return \StrUtil::back($response_object, "Register.epCallBack");            } catch (ValidateException $e) {                $error = $e->getError();                $response_object->code = 500;                $response_object->msg = array_pop($error);                return \StrUtil::back($response_object, "Register.epCallBack");            }        }        if ($ep->imgurl) {            $pathinfo = pathinfo($ep->imgurl);            if (in_array($pathinfo["extension"], ["jpg", "jpeg", "png", "gif"])) {                $ep->imgurl_is_img = 1;            }        }        if ($ep->domainImg) {            $pathinfo = pathinfo($ep->domainImg);            if (in_array($pathinfo["extension"], ["jpg", "jpeg", "png", "gif"])) {                $ep->domainImg_is_img = 1;            }        }        if ($ep->typeImg) {            $pathinfo = pathinfo($ep->typeImg);            if (in_array($pathinfo["extension"], ["jpg", "jpeg", "png", "gif"])) {                $ep->typeImg_is_img = 1;            }        }        if ($ep->beian) {            $pathinfo = pathinfo($ep->beian);            if (in_array($pathinfo["extension"], ["jpg", "jpeg", "png", "gif"])) {                $ep->beian_is_img = 1;            }        }        if ($ep->bankImg) {            $pathinfo = pathinfo($ep->bankImg);            if (in_array($pathinfo["extension"], ["jpg", "jpeg", "png", "gif"])) {                $ep->bankImg_is_img = 1;            }        }        $msg = session('temp')['msg'];        return view("", ['msg' => $msg, 'ep' => $ep]);    }    public function findBackPassword() {        $type = intval($this->request['type']);        if (\StrUtil::isEmpOrNull($type)) {            return json(['msg' => '请选择账号类型', 'code' => 500]);        }        $username = \StrUtil::getRequestDecodeParam($this->request, 'username');        if (\StrUtil::isEmpOrNull($username)) {            return json(['msg' => '请填写账号', 'code' => 500]);        }        $password = \StrUtil::getRequestDecodeParam($this->request, 'password');        if (\StrUtil::isEmpOrNull($password)) {            return json(['msg' => '请填写新密码', 'code' => 500]);        }        $rePassword = \StrUtil::getRequestDecodeParam($this->request, 'rePassword');        if (\StrUtil::isEmpOrNull($rePassword)) {            return json(['msg' => '请填写重复新密码', 'code' => 500]);        }        if ($password != $rePassword) {            return json(['msg' => '两次密码填写不一致', 'code' => 500]);        }        if (!preg_match("/^(?=.*\d)(?=.*[A-Za-z]).{8,}$/", $password)) {            return json(['msg' => '密码必须包含字母、数字、特殊字符且长度超过8位', 'code' => 500]);        }        $phone = \StrUtil::getRequestDecodeParam($this->request, 'phone');        if (\StrUtil::isEmpOrNull($phone)) {            return json(['msg' => '请填写手机号', 'code' => 500]);        }        $verificationCode = \StrUtil::getRequestDecodeParam($this->request, 'verificationCode');        if (\StrUtil::isEmpOrNull($verificationCode)) {            return json(['msg' => '请填写验证码', 'code' => 500]);        }        //检验验证码        $codeResult = MessageRecord::where('smsType', 1)->where('phone', $phone)->order('createTime', 'desc')->find();        if (!$codeResult || (time() - strtotime($codeResult['sendingDate']) > 300)) {            return json(['msg' => '请先发送验证码', 'code' => 500]);        }        if ($codeResult['params'] != $verificationCode) {            return json(['msg' => '验证码不正确', 'code' => 500]);        }        $password = hash('md5', $password);        if ($type == 1) {            $count = \app\common\model\Enterprise::where('username', $username)->where('agentPhone', $phone)->count();            if ($count == 0) {                return json(['msg' => '未找到相关账号,请仔细核对账号及手机号信息!', 'code' => 500]);            }            if ($count > 1) {                return json(['msg' => '找到多个账户,请联系相关单位处理!', 'code' => 500]);            }            $ep = \app\common\model\Enterprise::where('username', $username)->where('agentPhone', $phone)->find();            $ep->password = $password;            $ep->save();        } else {            //个人账户找回密码TODO        }        return json(['msg' => '找回密码成功!', 'code' => 200]);    }    public function verificationCode() {        $phone = $this->request["phone"];        $type = $this->request["type"];        //校验手机号码是否为空        if (\StrUtil::isEmpOrNull($phone)) {            return json(["msg" => "请填写手机号码!"], 500);        }        if (\StrUtil::isEmpOrNull($type)) {            return json(["msg" => "请填写手机号码!"], 500);        }        //校验手机号码格式是否正确        if (\StrUtil::isMoblePhone($phone)) {            return json(["msg" => "请填写正确的手机号码!"], 500);        }        $record = Cache::get("verify_{$type}_{$phone}");        if ($record) {            $time = time();            if ($time - $record <= 60) {                return json(["msg" => "一分钟内请勿频繁发送短信!"], 500);            }        }        $code = '';        for ($i = 1; $i <= 6; $i++) {            $code .= rand(0, 9);        }        //$code = 999999;        $template = "【晋江市人才服务平台】尊敬的用户,您的短信验证码为{$code},5分钟内有效。若非本人操作请忽略。";        $smsapi = new ChuanglanSmsApi();        $result = $smsapi->sendSMS($phone, $template);        $result = json_decode($result, true);        $id = getStringId();        $record_data = [            'id' => $id,            'bizId' => $id,            'type' => 2,            'smsType' => 1,            'phone' => $phone,            'params' => $code,            'templateCode' => $template,            'state' => $result['code'] == 0 ? 2 : 3,            'sendingDate' => date("Y-m-d H:i:s", time()),            'createTime' => date("Y-m-d H:i:s", time()),            'msg' => $result['errorMsg']        ];        MessageRecord::create($record_data);        if ($result['code'] == 0) {            Cache::set("verify_{$type}_{$phone}", time());            return json(["msg" => '验证码发送成功'], 200);        } else {            return json(["msg" => '验证码发送失败'], 500);        }    }    public function person_register() {        $source = intval($this->request['source']);        $response_object = new \StdClass();        $response_object->code = 500;        $data = [            'username' => \StrUtil::getRequestDecodeParam($this->request, 'username'),            'password' => \StrUtil::getRequestDecodeParam($this->request, 'password'),            'name' => \StrUtil::getRequestDecodeParam($this->request, 'name'),            'idCard' => \StrUtil::getRequestDecodeParam($this->request, 'idCard'),            'sex' => \StrUtil::getRequestDecodeParam($this->request, 'sex'),            'phone' => \StrUtil::getRequestDecodeParam($this->request, 'phone'),        ];        $verificationCode = \StrUtil::getRequestDecodeParam($this->request, 'verificationCode');        try {            validate(Person::class)->batch(true)->scene('add')->check($data);            //检验验证码            $codeResult = MessageRecord::where('smsType', 1)->where('phone', $data['phone'])->order('createTime', 'desc')->find();            if (!$codeResult) {                throw new ValidateException("请先发送验证码");            }            if (!$verificationCode) {                throw new ValidateException("请输入手机验证码");            }            if ($codeResult["params"] != $verificationCode) {                throw new ValidateException("验证码错误");            }            if (time() - strtotime($codeResult['createTime']) > 300) {                throw new ValidateException("验证码过期,请重新发送");            }            $info = Talent::where('card_number', $data['idCard'])->alias("ti")                            ->field("ti.*,e.type as enterpriseType")                            ->leftJoin("un_enterprise e", "e.id=ti.enterprise_id")                            ->where('ti.checkState', TalentState::CERTIFICATED)->find();            if (!$info) {                throw new ValidateException("人才库中不存在该证件号码,注册失败");            }            if (!strtotime($info["certificateExpireTime"]) || strtotime($info["certificateExpireTime"]) < time()) {                throw new ValidateException("人才库中该证件号码所属人才的人才证书已过期,注册失败");            }            if ($info["phone"] != $data["phone"]) {                throw new ValidateException("手机号码必须与人才库中一致,可联系企业经办人修改人才库手机号码");            }            $data["id"] = getStringId();            $data["type"] = $info["enterpriseType"];            $data["createTime"] = date("Y-m-d H:i:s");            $data["updateTime"] = date("Y-m-d H:i:s");            $data["password"] = md5($data["password"]);            $data["active"] = 1;            \app\admin\model\Person::insert($data);            $response_object->code = 200;            $response_object->msg = "注册成功";            return json($response_object);        } catch (ValidateException $e) {            $response_object->msg = $e->getError();            return json($response_object);        } catch (\think\db\exception\DbException $e) {            $response_object->msg = $e->getMessage();            return json($response_object);        }    }}
 |