Exemplo 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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 新建实体时使用
        /// </summary>

        public static InvitationCode New()
        {
            InvitationCode invitationCode = new InvitationCode()
            {
                ExpiredDate = DateTime.UtcNow,
                DateCreated = DateTime.UtcNow
            };

            return(invitationCode);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 相互关注,其中,只是根据邀请码来判断是否可以执行而已
        /// </summary>
        /// <param name="invitationCode">邀请码</param>
        /// <param name="user">被邀请的用户</param>
        /// <param name="errorMessage">返回错误的信息</param>
        /// <returns>要返回的页面</returns>
        private bool MutualFollow(InvitationCode invitationCode, IUser user, out string errorMessage)
        {
            if (invitationCode.ExpiredDate < DateTime.UtcNow)
            {
                errorMessage = "邀请链接已经过期";
                return false;
            }
            //判断是否过期
            User inviteUser = userService.GetFullUser(invitationCode.UserId);
            if (inviteUser == null)
            {
                errorMessage = "找不到邀请人,可能邀请人已经将帐号注销";
                return false;
            }
            if (followService.IsFollowed(user.UserId, invitationCode.UserId))
            {
                errorMessage = "您已经添加过了关注不需要再次添加关注";
                return false;
            }
            if (!invitationCode.IsMultiple)
                inviteFriendService.DeleteInvitationCode(invitationCode.UserId, invitationCode.Code);
            followService.Follow(user.UserId, invitationCode.UserId);
            followService.Follow(invitationCode.UserId, user.UserId);

            errorMessage = string.Format("成功接收了{0}邀请", user.UserName);
            return true;
        }
Exemplo n.º 5
0
 //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());
     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))
         {
             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;
 }
Exemplo n.º 6
0
        /// <summary>
        /// 新建实体时使用
        /// </summary>
        public static InvitationCode New()
        {
            InvitationCode invitationCode = new InvitationCode()
            {
                ExpiredDate = DateTime.UtcNow,
                DateCreated = DateTime.UtcNow

            };
            return invitationCode;
        }