'/^[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'], [['good_at','intro'], 'string', 'max' => 500], ]; } 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' => '门店', 'depart_id' => '科室', 'identity' => '身份', 'title_id' => '职称', 'good_at' => '擅长', 'intro' => '个人简介', ]; } public function save() { if(!$this->validate()){ throw new Exception($this->getErrorMsg()); } $su_id=\Yii::$app->user->identity->getId(); $model = DoctorInfo::find()->where([ 'su_id' => $su_id, ])->one(); $t=\Yii::$app->db->beginTransaction(); try { if(!$model){//新增 $model = new DoctorInfo(); $model->su_id = $su_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; $model->saveOrFail(); $store= Json::decode($this->store_id,true); foreach ($store as $value){ $store=Store::find()->where(['id'=>$value])->one(); if ($store){ if (!StoreDoctor::find()->where([ 'su_id'=>$su_id, 'store_id'=>$value ])->one()) { $StoreDoctor=new StoreDoctor(); $StoreDoctor->store_id=$value; $StoreDoctor->su_id=$su_id; $StoreDoctor->last_login_time=time(); $StoreDoctor->saveOrFail(); } } } $t->commit(); return ['已完善基本信息']; } catch (\Exception $e){ $t->rollBack(); throw new Exception($e->getMessage()); } } }