wangrong
9 小时以前 0d90e20ec20f0aeee642756a7ebf9e8514174124
src/modules/user/service/info.ts
@@ -50,8 +50,17 @@
   * @returns
   */
  async person(id) {
    const info = await this.userInfoEntity.findOneBy({ id: Equal(id) });
    //delete info.password;
    const idText = id === undefined || id === null ? '' : String(id);
    // 手机号登录签发的是 unionid(手机号),不能拿去查整型主键
    let info = null;
    if (/^\d{1,10}$/.test(idText)) {
      info = await this.userInfoEntity.findOneBy({ id: Equal(Number(idText)) });
    }
    if (!info && idText) {
      info = await this.userInfoEntity.findOneBy({
        unionid: Equal(idText),
      });
    }
    return info;
  }
@@ -60,8 +69,12 @@
   * @param userId
   */
  async logoff(userId: number) {
    const info = await this.person(userId);
    if (!info) {
      throw new CoolCommException('用户不存在');
    }
    await this.userInfoEntity.update(
      { id: userId },
      { id: info.id },
      {
        status: 2,
        phone: "",
@@ -92,7 +105,7 @@
      }
    } catch (err) { }
    try {
      return await this.userInfoEntity.update({ id }, param);
      return await this.userInfoEntity.update({ id: info.id }, param);
    } catch (err) {
      throw new CoolCommException('更新失败,参数错误或者手机号已存在');
    }
@@ -116,7 +129,7 @@
      throw new CoolCommException('验证码错误');
    }
    await this.userInfoEntity.update(user.unionid, {
    await this.userInfoEntity.update(user.id, {
      password: md5(password),
    });
  }
@@ -132,7 +145,11 @@
    if (!check) {
      throw new CoolCommException('验证码错误');
    }
    await this.userInfoEntity.update({ id: userId }, { phone });
    const info = await this.person(userId);
    if (!info) {
      throw new CoolCommException('用户不存在');
    }
    await this.userInfoEntity.update({ id: info.id }, { phone });
  }
  /**