'/^[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'], ['idcard', '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' => '身份证号', 'store_id' => '门店id', 'title_id' => '职称', 'type' => '身份类型1中医药师 2西医药师', ]; } public function save() { if(!$this->validate()){ throw new Exception($this->getErrorMsg()); } $model = PharmacistrInfo::find()->where([ 'su_id' => \Yii::$app->user->identity->id, ])->one(); $t=\Yii::$app->db->beginTransaction(); if(!$model){ $model = new PharmacistrInfo(); $model->su_id = \Yii::$app->user->identity->id; $docinfo=DoctorInfo::find()->where(['idcard'=>$this->idcard,'is_delete'=>0])->one(); $pharmacistrInfo=PharmacistrInfo::find()->where(['idcard'=>$this->idcard])->one(); if ($pharmacistrInfo){ throw new \yii\db\Exception('您已经注册过药师了'); } if ($docinfo){ throw new \yii\db\Exception('您的身份证不能同时注册医生和药师'); } } $model->attributes = $this->attributes; if (!$model->saveOrFail()){ $t->rollBack(); } $t->commit(); return ['已完善基础信息']; } }