//回复:此方法名。郑伟定的。等我问问郑伟。 /// <summary> /// 变更用户邀请码配额 /// </summary> /// <param name="userId">用户Id</param> /// <param name="userInvitationCodeUnUsedCount">用户未使用邀请码配额增量(若减少请使用负数)</param> /// <param name="userInvitationCodeUsedCount">用户使用的邀请码配额增量(若减少请使用负数)</param> /// <param name="userInvitationCodeBuyedCount">用户购买的邀请码配额增量(若减少请使用负数)</param> /// <returns>是否更新成功</returns> public bool ChangeUserInvitationCodeCount(long userId, int userInvitationCodeUnUsedCount, int userInvitationCodeUsedCount, int userInvitationCodeBuyedCount) { InvitationCodeStatistic invitationCodeStatistic = Get(userId); if (invitationCodeStatistic == null) { IInviteFriendSettingsManager inviteFriendSettingsManager = DIContainer.Resolve <IInviteFriendSettingsManager>(); InviteFriendSettings inviteFriendSettings = inviteFriendSettingsManager.Get(); invitationCodeStatistic = new InvitationCodeStatistic { CodeBuyedCount = 0, CodeUnUsedCount = inviteFriendSettings.DefaultUserInvitationCodeCount, CodeUsedCount = 0, UserId = userId }; Insert(invitationCodeStatistic); } invitationCodeStatistic.CodeBuyedCount += userInvitationCodeBuyedCount; invitationCodeStatistic.CodeUnUsedCount += userInvitationCodeUnUsedCount; invitationCodeStatistic.CodeUsedCount += userInvitationCodeUsedCount; //done:bianchx by libsh,怎么能防止这些统计数被减到负数 //回复:在业务逻辑类中做了拦截,请查看业务逻辑类中的ChangeUserInvitationCodeCount方法 var sql_Update = PetaPoco.Sql.Builder .Append("update tn_InvitationCodeStatistics set CodeUnUsedCount=CodeUnUsedCount+@0,CodeUsedCount=CodeUsedCount+@1,CodeBuyedCount=CodeBuyedCount+@2 where UserId=@3", userInvitationCodeUnUsedCount, userInvitationCodeUsedCount, userInvitationCodeBuyedCount, userId); //done:bianchx by libsh,应该先做数据库操作再处理缓存 //回复:修改了执行顺序 int affectedCount = CreateDAO().Execute(sql_Update); OnUpdated(invitationCodeStatistic); return(affectedCount > 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); }
/// <summary> /// 获取邀请码实体 /// </summary> /// <param name="invitationCode">邀请码</param> public InvitationCode GetInvitationCodeEntity(string invitationCode) { InvitationCode invitation = invitationCodesRepository.Get(invitationCode); IInviteFriendSettingsManager inviteFriendSettingsManager = DIContainer.Resolve <IInviteFriendSettingsManager>(); InviteFriendSettings inviteFriendSettings = inviteFriendSettingsManager.Get(); if (invitation == null || inviteFriendSettings.AllowInvitationCodeUseOnce == invitation.IsMultiple) { return(null); } return(invitation); }
public TestForUserEditModel GetUserSettings() { //根据站点配置设置用户属性 IUserSettingsManager userSettingsManager = DIContainer.Resolve <IUserSettingsManager>(); UserSettings userSettings = userSettingsManager.Get(); IInviteFriendSettingsManager inviteFriendSettingsManager = DIContainer.Resolve <IInviteFriendSettingsManager>(); InviteFriendSettings inviteFriendSettings = inviteFriendSettingsManager.Get(); return(new TestForUserEditModel { registrationMode = userSettings.RegistrationMode, EnableNotActivatedUsersToLogin = userSettings.EnableNotActivatedUsersToLogin, MyHomePageAsSiteEntry = userSettings.MyHomePageAsSiteEntry, AllowInvitationCodeUseOnce = inviteFriendSettings.AllowInvitationCodeUseOnce, UserPasswordFormat = userSettings.UserPasswordFormat }); }
/// <summary> /// 获取用户邮件模板的数据字典 /// </summary> /// <param name="emailBuilder"></param> /// <param name="user"></param> /// <returns></returns> public static dynamic GetUserEmailModel(this EmailBuilder emailBuilder, IUser user) { IInviteFriendSettingsManager manager = DIContainer.Resolve <IInviteFriendSettingsManager>(); dynamic model = emailBuilder.GetCommonEmailModel();//合并全局数据字典 model.UserName = user.UserName; model.UserDisplayName = user.DisplayName; model.PublicEmail = "PublicEmail"; model.LastLogin = SiteUrls.FullUrl(SiteUrls.Instance().Login()); model.ProfileUrl = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(user.UserName)); model.ChangePasswordUrl = SiteUrls.FullUrl(SiteUrls.Instance().ChangePassword(user.UserName)); model.UserAvatarUrl = SiteUrls.FullUrl(SiteUrls.Instance().UserAvatarUrl(user, AvatarSizeType.Medium, false)); model.ResetPassword = SiteUrls.FullUrl(SiteUrls.Instance().ResetPassword(user.UserId)); model.ExpirationTime = DateTime.Now.AddDays(manager.Get().InvitationCodeTimeLiness).ToFriendlyDate(); model.InvitationCodeTimeLiness = manager.Get().InvitationCodeTimeLiness; return(model); }
/// <summary> /// 获取用户邀请码统计实体 /// </summary> /// <param name="userId">用户Id</param> /// <returns>用户邀请码统计实体</returns> public InvitationCodeStatistic GetUserInvitationCodeStatistic(long userId) { InvitationCodeStatistic invitationCodeStatistic = invitationCodeStatisticsRepository.Get(userId); if (invitationCodeStatistic == null) { IInviteFriendSettingsManager inviteFriendSettingsManager = DIContainer.Resolve <IInviteFriendSettingsManager>(); InviteFriendSettings inviteFriendSettings = inviteFriendSettingsManager.Get(); invitationCodeStatistic = new InvitationCodeStatistic { CodeUnUsedCount = inviteFriendSettings.DefaultUserInvitationCodeCount, CodeUsedCount = 0, CodeBuyedCount = 0, UserId = userId }; } return(invitationCodeStatistic); }
/// <summary> /// 用户购买邀请码 /// </summary> /// <param name="userId">用户Id</param> /// <param name="invitationCodeCount">购买的邀请码数量</param> public bool BuyInvitationCodes(long userId, int invitationCodeCount) { IInviteFriendSettingsManager inviteFriendSettingsManager = DIContainer.Resolve <IInviteFriendSettingsManager>(); 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方法 }