public function beforeSave($insert) { if ($insert) { if (empty($this->code)) { $this->code = rand(1000, 9999); } if (empty($this->type)) { if ((new EmailValidator())->validate($this->field)) { $this->type = self::TYPE_EMAIL; } elseif (Utils::phoneVerify($this->field)) { $this->type = self::TYPE_PHONE; } else { throw new ErrorException('格式错误', ErrorCode::Vcode_not_field); } $this->_sendVcode(); } if ($insert) { $this->status = self::STATUS_VERIFY_UNSUCCESS; } } return parent::beforeSave($insert); }