userId = empty($this->userId) ? $this->userInfo->id : $this->userId; if (empty($this->userId)) { throw new ErrException('登录失败'); } //todo 判断注销 判断封号 //todo 更新登录时间 } /** * 返回值 * @return array * @throws \Exception */ protected function getReturn():array { $loginReturn = [ 'id' => $this->userId, 'is_bind_mobile' => $this->userInfo->mobile ? UserCode::IS_BIND_PHONE : UserCode::IS_NOT_BIND_PHONE, 'nickName' => $this->userInfo->nickName, 'is_default_avatar' => $this->userInfo->avatar_id == 0 ? UserCode::IS_DEFAULT_AVATAR : UserCode::IS_NOT_DEFAULT_AVATAR, ]; $loginReturn['token'] = $this->cryptoFactory->cryptoClass('jwt', json_encode($loginReturn))->encrypt(); return $loginReturn; } /** * 判断是不是没有加锁 * @param $type * @return void * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface * @throws \RedisException */ protected function checkLock($type): void { $this->lockKey = match ($type){ 1 => ApiRedisKey::LoginAndRegisterByMobileLock($this->mobile), 2 => ApiRedisKey::LoginAndRegisterByCodeLock($this->jsCode) }; if (0 == ($this->redis->addLock($this->lockKey))){ throw new ErrException('请勿重复点击'); } } /** * 添加用户 * @return void */ protected function addUser(): void { $model = new User(); //默认头像和默认名称 $model->nickname = '用户'.StringUtil::randStr(6); $model->avatar_id = 0; $model->reg_ip = SystemUtil::getClientIp(); if (!$model->save()) throw new ErrException('数据保存失败-注册失败'); $this->userId = $model->id; $this->userInfo = $model; } abstract protected function register(); }