'/^[1-9]\d{5}(18|19|20|(3\d))\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/i'], ['id_card', 'checkCard'], ]; } public function checkCard($attribute, $params) { $response = (new Client(['http_errors' => false]))->post("https://eid.shumaidata.com/eid/check", [ 'headers' => ['Authorization' =>"APPCODE f98bba3251714c759f5bd29d00e1c46e"], 'query' => [ 'idcard' => $this->idcard, 'name' => $this->name ], ]); $result = json_decode($response->getBody(),true); if(!($result['code']==0 && $result['result']['res']==1)){ $this->addError($attribute, '身份证名字不匹配'); } } public function attributeLabels() { return [ 'name' => '姓名', 'avatar' => '头像', 'mobile' => '手机号', 'idcard' => '身份证号', 'hospital_id' => '医院id', 'yard_id' => '院区', 'depart_id' => '科室', 'title_id' => '职称', 'card_up' => '身份证正面', 'card_down' => '身份证反面' ]; } public function save() { if(!$this->validate()){ throw new Exception($this->getErrorMsg()); } $t = \Yii::$app->db->beginTransaction(); try { $model = ServInfo::find()->where([ 'su_id' => \Yii::$app->user->identity->id, ])->one(); if(!$model){ $model = new ServInfo(); $model->su_id = \Yii::$app->user->identity->id; } $model->attributes = $this->attributes; $model->saveOrFail(); //修改状态 $user = \Yii::$app->user->identity; $user->status = UserStatusEnum::WAIT_SH; $user->saveOrFail(); $t->commit(); }catch (Exception $exception){ $t->rollBack(); throw $exception; } return []; } }