穷逼VIP的日常(手动斜眼( ﹁ ﹁ ) ~→)

  |   2 评论   |   1,905 浏览

var UserModel = function () {
  function UserModel() {
    _classCallCheck(this, UserModel);
    this._userInfo;
  }

  _createClass(UserModel, [{
    key: '_fetchUserInfo',
    value: function _fetchUserInfo() {
      var update = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
      if (update) this._userInfo = electron.remote.getGlobal("userInfo") || {};
    }
  },
    {
      key: 'getUserInfo',
      value: function getUserInfo() {
        var update = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
        this._fetchUserInfo(update);
        return this._userInfo;
      }
    }, {
      key: 'checkVipExpired',
      value: function checkVipExpired() {
        var update = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
        this._fetchUserInfo(update);
        var targetExpired = this._userInfo.vipExpire;
        return !(targetExpired && isNumber(targetExpired) && targetExpired > Date.now());
      }
    }, {
      key: 'getExpiredDays',
      value: function getExpiredDays() {
        var update = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
        this._fetchUserInfo(update);
        var targetExpired = this._userInfo.vipExpire || 0;
        return Math.ceil((targetExpired - Date.now()) / (24 * 3600 * 1000));
      }
    }, {
      key: 'isReachedMaxDownloadItem',
      value: function isReachedMaxDownloadItem() {
        var update = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
        this._fetchUserInfo(update);
        return this._userInfo.downCountLeft <= 0;
      }
    }, {
      key: 'isLogin',
      value: function isLogin() {
        var update = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
        this._fetchUserInfo(update);
        return !!this._userInfo.accessToken;
      }
      /**
 * 判断是否是307版本之前的用户信息结构 */  }, {
      key: 'isBefore307VersionData',
      value: function isBefore307VersionData() {
        var update = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
        this._fetchUserInfo(update);
        return !this._userInfo.version;
      }
      /**
 * 判断是否是309版本之前的用户信息结构 */  }, {
      key: 'isBefore309VersionData',
      value: function isBefore309VersionData() {
        var update = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
        this._fetchUserInfo(update);
        return this._userInfo.verifyIsOpen === undefined && this._userInfo.userVerify === undefined;
      }
      /**
 * 是不是VIP * @param update
 * @returns {UserModel.isVip|*}
 */  }, {
      key: 'isVip',
      value: function isVip() {
        var update = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
        this._fetchUserInfo(update);
        return this.isNormalVip(false) || this.isSuperVip(false);
      }
      /**
 * 穷逼VIP(活动送的那种) * @param update
 * @returns {boolean}
 */  }, {
      key: 'isBeggarVip',
      value: function isBeggarVip() {
        var update = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
        this._fetchUserInfo(update);
        return this._userInfo.isDemoVip || false;
      }
      /**
 * 普通VIP * @param update
 * @returns {number}
 */  }, {
      key: 'isNormalVip',
      value: function isNormalVip() {
        var update = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
        this._fetchUserInfo(update);
        return this._userInfo.visits & 1 << 8;
      }
      /**
 * 超级VIP * @param update
 * @returns {number}
 */  }, {
      key: 'isSuperVip',
      value: function isSuperVip() {
        var update = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
        this._fetchUserInfo(update);
        return this._userInfo.visits & 1;
      }
    }]);
  return UserModel;
}();


知乎问题地址:https://www.zhihu.com/question/68347364

评论

  • lwl 回复»

    大厂应该有代码互查吧?这样估计团队不止一人心有不满

  • undefinedUser 回复»

    估计工资绩效和营收相关,虾米出来的早,还没尝到什么甜头,就被网易云音乐给爆了,开发满心怨言。
    现在的VIP资格应该大部分来自支付宝积分兑换的

  • lijp 回复»

    看代码的备注也是一件欢乐的事情。

发表评论