Ejemplo n.º 1
0
        //关于缓存期限:
        //1、用户邀请码配额 使用CachingExpirationType.SingleObject
        //2、邀请码实体、列表 使用CachingExpirationType.SingleObject、ObjectCollection
        //3、邀请好友记录列表 使用CachingExpirationType.ObjectCollection

        #region 邀请码

        //done:zhengw,by mazq 方法名不好理解 或者直接与上一个方法合并叫 GetInvitationCode(long userId) 有什么问题?
        //zhengw回复:已修改

        /// <summary>
        /// 获取邀请码
        /// </summary>
        /// <param name="userId">申请人</param>
        public string GetInvitationCode(long userId)
        {
            //回复:我本身也没有判断吧。
            string code = EncryptionUtility.MD5_16(userId.ToString() + DateTime.UtcNow.Ticks.ToString());
            IInviteFriendSettingsManager inviteFriendSettingsManager = DIContainer.Resolve <IInviteFriendSettingsManager>();
            InviteFriendSettings         inviteFriendSettings        = inviteFriendSettingsManager.Get();

            if (inviteFriendSettings.AllowInvitationCodeUseOnce)
            {
                InvitationCodeStatistic invitationCodeStatistic = GetUserInvitationCodeStatistic(userId);
                //如果配额够用的
                if (ChangeUserInvitationCodeCount(userId, -1, 1, 1))
                {
                    InvitationCode invitationCode = new InvitationCode
                    {
                        Code        = code,
                        DateCreated = DateTime.UtcNow,
                        ExpiredDate = DateTime.UtcNow.AddDays(inviteFriendSettings.InvitationCodeTimeLiness),
                        IsMultiple  = !inviteFriendSettings.AllowInvitationCodeUseOnce,
                        UserId      = userId
                    };
                    invitationCodesRepository.Insert(invitationCode);
                }
                else
                {
                    code = string.Empty;
                }
                //1.用户未使用邀请码配额减1,然后调用ChangeUserInvitationCodeCount进行更新
                //2.过期时间根据InviteFriendSettings.InvitationCodeTimeLiness确定
            }
            else
            {
                string todayCode = invitationCodesRepository.GetTodayCode(userId);
                if (string.IsNullOrEmpty(todayCode))
                {
                    ILinktimelinessSettingsManager manager = DIContainer.Resolve <ILinktimelinessSettingsManager>();
                    InvitationCode invitationCode          = new InvitationCode
                    {
                        Code        = code,
                        DateCreated = DateTime.UtcNow,
                        ExpiredDate = DateTime.UtcNow.AddDays(inviteFriendSettings.InvitationCodeTimeLiness),
                        IsMultiple  = !inviteFriendSettings.AllowInvitationCodeUseOnce,
                        UserId      = userId
                    };
                    invitationCodesRepository.Insert(invitationCode);
                }
                else
                {
                    code = todayCode;
                }
                //检查今日是否有生成过的可多次使用的邀请码,若没有,则生成;否则,直接返回
                //过期时间根据LinktimelinessSettings.Lowlinktimeliness确定
                //设置IsMultiple为true
            }
            //向邀请码表中插入数据库
            return(code);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取邀请码实体
        /// </summary>
        /// <param name="invitationCode">邀请码</param>
        public InvitationCode GetInvitationCodeEntity(string invitationCode)
        {
            InvitationCode       invitation           = invitationCodesRepository.Get(invitationCode);
            InviteFriendSettings inviteFriendSettings = inviteFriendSettingsManager.Get();

            if (invitation == null || inviteFriendSettings.AllowInvitationCodeUseOnce == invitation.IsMultiple)
            {
                return(null);
            }
            return(invitation);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 获取用户邀请码统计实体
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <returns>用户邀请码统计实体</returns>
        public InvitationCodeStatistic GetUserInvitationCodeStatistic(long userId)
        {
            InvitationCodeStatistic invitationCodeStatistic = invitationCodeStatisticsRepository.Get(userId);

            if (invitationCodeStatistic == null)
            {
                InviteFriendSettings inviteFriendSettings = inviteFriendSettingsManager.Get();
                invitationCodeStatistic = new InvitationCodeStatistic
                {
                    CodeUnUsedCount = inviteFriendSettings.DefaultUserInvitationCodeCount,
                    CodeUsedCount   = 0,
                    CodeBuyedCount  = 0,
                    UserId          = userId
                };
            }
            return(invitationCodeStatistic);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="userProfileSettings">用户资料设置</param>
 /// <param name="userSettings">用户设置</param>
 /// <param name="inviteFriendSettings">邀请朋友设置</param>
 public UserSettingsEditModel(UserProfileSettings userProfileSettings, UserSettings userSettings, InviteFriendSettings inviteFriendSettings)
 {
     if (userSettings != null)
     {
         RegistrationMode = userSettings.RegistrationMode;
         AccountActivation = userSettings.AccountActivation;
         EnableNotActivatedUsersToLogin = userSettings.EnableNotActivatedUsersToLogin;
         EnableTrackAnonymous = userSettings.EnableTrackAnonymous;
         UserOnlineTimeWindow = userSettings.UserOnlineTimeWindow;
         UserPasswordFormat = userSettings.UserPasswordFormat;
         AutomaticModerated = userSettings.AutomaticModerated;
         NoModeratedUserPoint = userSettings.NoModeratedUserPoint;
         EnableNickname = userSettings.EnableNickname;
         DisplayNameType = userSettings.DisplayNameType;
         DisallowedUserNames = userSettings.DisallowedUserNames;
         MyHomePageAsSiteEntry = userSettings.MyHomePageAsSiteEntry;
     }
     if (userProfileSettings != null)
     {
         Avatar = userProfileSettings.IntegrityProportions[0];
         Birthday = userProfileSettings.IntegrityProportions[1];
         NowArea = userProfileSettings.IntegrityProportions[2];
         HomeArea = userProfileSettings.IntegrityProportions[3];
         IM = userProfileSettings.IntegrityProportions[4];
         Mobile = userProfileSettings.IntegrityProportions[5];
         EducationExperience = userProfileSettings.IntegrityProportions[6];
         WorkExperience = userProfileSettings.IntegrityProportions[7];
         Introduction = userProfileSettings.IntegrityProportions[8];
         MaxPersonTag = userProfileSettings.MaxPersonTag;
         MinIntegrity = userProfileSettings.MinIntegrity;
     }
     if (inviteFriendSettings != null)
     {
         AllowInvitationCodeUseOnce = inviteFriendSettings.AllowInvitationCodeUseOnce;
         InvitationCodeTimeLiness = inviteFriendSettings.InvitationCodeTimeLiness;
         InvitationCodeUnitPrice = inviteFriendSettings.InvitationCodeUnitPrice;
         DefaultUserInvitationCodeCount = inviteFriendSettings.DefaultUserInvitationCodeCount;
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// 用户购买邀请码
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <param name="invitationCodeCount">购买的邀请码数量</param>
        public bool BuyInvitationCodes(long userId, int invitationCodeCount)
        {
            InviteFriendSettings inviteFriendSettings = inviteFriendSettingsManager.Get();
            int requiredTradePoints = invitationCodeCount * inviteFriendSettings.InvitationCodeUnitPrice;

            IUserService userService = DIContainer.Resolve <IUserService>();
            IUser        user        = userService.GetUser(userId);

            if (user == null || user.TradePoints < requiredTradePoints)
            {
                return(false);
            }
            PointService pointService = new PointService();

            pointService.TradeToSystem(userId, requiredTradePoints, "购买邀请码", true);
            return(ChangeUserInvitationCodeCount(userId, invitationCodeCount, 0, invitationCodeCount));


            //检查用户交易积分是否足以支付购买invitationCodeCount个邀请码配额
            //用户的未使用邀请码配额、购买的邀请码配额加invitationCodeCount,然后调用ChangeUserInvitationCodeCount进行更新

            //mazq回复:增加了TradeToSystem方法
        }