/// <summary> /// 审核状态发生变化时处理积分 /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> private void TopicEntityPointModule_After(TopicEntity sender, AuditEventArgs eventArgs) { string pointItemKey = string.Empty; string eventOperationType = string.Empty; string description = string.Empty; ActivityService activityService = new ActivityService(); AuditService auditService = new AuditService(); PointService pointService = new PointService(); bool? auditDirection = auditService.ResolveAuditDirection(eventArgs.OldAuditStatus, eventArgs.NewAuditStatus); if (auditDirection == true) //加积分 { pointItemKey = PointItemKeys.Instance().Topic_CreateTopic(); if (eventArgs.OldAuditStatus == null) eventOperationType = EventOperationType.Instance().Create(); else eventOperationType = EventOperationType.Instance().Approved(); } else if (auditDirection == false) //减积分 { pointItemKey = PointItemKeys.Instance().Topic_DeleteTopic(); if (eventArgs.NewAuditStatus == null) eventOperationType = EventOperationType.Instance().Delete(); else eventOperationType = EventOperationType.Instance().Disapproved(); } if (!string.IsNullOrEmpty(pointItemKey)) { description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_" + eventOperationType), "专题", sender.TopicName); } pointService.GenerateByRole(sender.UserId, pointItemKey, description, eventOperationType == EventOperationType.Instance().Create() || eventOperationType == EventOperationType.Instance().Delete() && eventArgs.OperatorInfo.OperatorUserId == sender.UserId); }
public override void ProcessRequest(HttpContext context) { long attachmentId = context.Request.QueryString.Get<long>("attachmentId", 0); if (attachmentId <= 0) { WebUtility.Return404(context); return; } string tenantTypeId = context.Request.QueryString.Get<string>("tenantTypeId", null); if (string.IsNullOrEmpty(tenantTypeId)) { WebUtility.Return404(context); return; } AttachmentService<Attachment> attachmentService = new AttachmentService<Attachment>(tenantTypeId); Attachment attachment = attachmentService.Get(attachmentId); if (attachment == null) { WebUtility.Return404(context); return; } IUser currentUser = UserContext.CurrentUser; //判断是否有附件的购买权限或下载权限,有下载权限肯定有购买权限,目前只有未登录或积分不够时才判定为没有权限 if (!DIContainer.Resolve<Authorizer>().Attachment_Buy(attachment)) { WebUtility.Return403(context); return; } //如果还没有下载权限,则说明积分可以支付附件售价,但是还未购买,则先进行积分交易 if (!DIContainer.Resolve<Authorizer>().Attachment_Download(attachment)) { //积分交易 PointService pointService = new PointService(); pointService.Trade(currentUser.UserId, attachment.UserId, attachment.Price, string.Format("购买附件{0}", attachment.FriendlyFileName), true); } //创建下载记录 AttachmentDownloadService attachmentDownloadService = new AttachmentDownloadService(); attachmentDownloadService.Create(currentUser == null ? 0 : currentUser.UserId, attachment.AttachmentId); //下载计数 CountService countService = new CountService(TenantTypeIds.Instance().Attachment()); countService.ChangeCount(CountTypes.Instance().DownloadCount(), attachment.AttachmentId, attachment.UserId, 1, false); bool enableCaching = context.Request.QueryString.GetBool("enableCaching", true); context.Response.Status = "302 Object Moved"; context.Response.StatusCode = 302; LinktimelinessSettings linktimelinessSettings = DIContainer.Resolve<ISettingsManager<LinktimelinessSettings>>().Get(); string token = Utility.EncryptTokenForAttachmentDownload(linktimelinessSettings.Highlinktimeliness, attachmentId); context.Response.Redirect(SiteUrls.Instance().AttachmentTempUrl(attachment.AttachmentId, tenantTypeId, token, enableCaching), true); context.Response.Flush(); context.Response.End(); }
/// <summary> /// 批量关注积分处理 /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> void BatchFollowPointModule_After(int sender, BatchFollowEventArgs eventArgs) { if (EventOperationType.Instance().Create() == eventArgs.EventOperationType && sender > 0) { string pointItemKey = string.Empty; pointItemKey = PointItemKeys.Instance().FollowUser(); PointService pointService = new PointService(); for(int i=0; i<sender; i++) { pointService.GenerateByRole(eventArgs.UserId, pointItemKey, "批量添加关注"); } //更新用户缓存 ICacheService cacheService = DIContainer.Resolve<ICacheService>(); RealTimeCacheHelper realTimeCacheHelper = EntityData.ForType(typeof(User)).RealTimeCacheHelper; if (cacheService.EnableDistributedCache) { realTimeCacheHelper.IncreaseEntityCacheVersion(eventArgs.UserId); } else { string cacheKey = realTimeCacheHelper.GetCacheKeyOfEntity(eventArgs.UserId); User user = cacheService.Get<User>(cacheKey); if (user != null) { user.FollowedCount = user.FollowedCount+sender; } } } }
/// <summary> /// 创建邀请记录之后的方法 /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> void CreateInviteFriendRecordEventModule_After(InviteFriendRecord sender, CommonEventArgs eventArgs) { if (eventArgs.EventOperationType == EventOperationType.Instance().Create()) { PointService pointService = new PointService(); string userName = UserIdToUserNameDictionary.GetUserName(sender.UserId); string invitedName = UserIdToUserNameDictionary.GetUserName(sender.InvitedUserId); string description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_CreateInviteFriendRecord"), userName, invitedName); pointService.GenerateByRole(sender.UserId, PointItemKeys.Instance().InviteUserRegister(), description, true); } }
/// <summary> /// 生成动态操作链接 /// </summary> private static MvcHtmlString PointMessage(this HtmlHelper htmlHelper, long userId) { PointService pointService = new PointService(); IEnumerable<PointCategory> pointCategories = pointService.GetPointCategories(); htmlHelper.ViewData["ExperiencePoints"] = pointCategories.FirstOrDefault(n => n.CategoryKey.Equals("ExperiencePoints")).CategoryName; htmlHelper.ViewData["ReputationPoints"] = pointCategories.FirstOrDefault(n => n.CategoryKey.Equals("ReputationPoints")).CategoryName; htmlHelper.ViewData["TradePoints"] = pointCategories.FirstOrDefault(n => n.CategoryKey.Equals("TradePoints")).CategoryName; PointRecord pointRecord = pointService.GetUserLastestRecord(userId); htmlHelper.ViewData["PointRecord"] = pointRecord; return htmlHelper.DisplayForModel("PointMessage"); }
/// <summary> /// 评论的积分处理 /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> void CommentCreatAndDeleteEventModel_After(Comment sender, CommonEventArgs eventArgs) { PointService pointService = new PointService(); if (eventArgs.EventOperationType == EventOperationType.Instance().Create()) { string description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_CreateComment"), sender.Author, sender.Subject); pointService.GenerateByRole(sender.UserId, PointItemKeys.Instance().CreateComment(), description, true); } if (eventArgs.EventOperationType == EventOperationType.Instance().Delete()) { string description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_DeleteComment"), sender.Author, sender.Subject); pointService.GenerateByRole(sender.UserId, PointItemKeys.Instance().DeleteComment(), description, true); } }
/// <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方法 }
/// <summary> /// 创建评分 /// </summary> /// <param name="rating">评分</param> /// <returns>true-评分成功,false-评分失败(可能今日评分已超过限额)</returns> public bool Create(BarRating rating) { BarThreadService barThreadService = new BarThreadService(); BarThread thread = barThreadService.Get(rating.ThreadId); EventBus<BarRating>.Instance().OnBefore(rating, new CommonEventArgs(EventOperationType.Instance().Create())); bool result = false; bool.TryParse(barRatingRepository.Insert(rating).ToString(), out result); if (result) { //给楼主加威望/交易积分 IUserService userService = DIContainer.Resolve<IUserService>(); userService.ChangePoints(thread.UserId, 0, rating.ReputationPoints, rating.TradePoints); PointService pointService = new PointService(); pointService.CreateRecord(thread.UserId, "帖子评分", "发布的帖子被其他用户评分", 0, rating.ReputationPoints, rating.TradePoints); EventBus<BarRating>.Instance().OnAfter(rating, new CommonEventArgs(EventOperationType.Instance().Create())); } return result; }
/// <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方法 }
public ActionResult ManagePointRecords(int? pageIndex, int pageSize = 20) { PointService pointService = new PointService(); pageResourceManager.InsertTitlePart("管理积分记录"); IEnumerable<PointCategory> pointCategories = pointService.GetPointCategories(); ViewData["traPoint"] = pointCategories.FirstOrDefault(n => n.CategoryKey.Equals("TradePoints")).CategoryName; ViewData["expPoint"] = pointCategories.FirstOrDefault(n => n.CategoryKey.Equals("ExperiencePoints")).CategoryName; ViewData["prePoint"] = pointCategories.FirstOrDefault(n => n.CategoryKey.Equals("ReputationPoints")).CategoryName; bool? isIncome = null; DateTime? startDate = null; DateTime? endDate = null; string isSystemData = Request.QueryString["isSystemData"]; IEnumerable<long> userIds = Request.QueryString.Gets<long>("userId"); long? userId = null; string pointItemName = Request.QueryString.GetString("pointItemName", null); bool isCheck = false; isIncome = Request.QueryString.Get<bool?>("incomelist"); if (isSystemData != null && !isSystemData.Equals("false")) { userId = 0; isCheck = true; } else if (userIds != null && userIds.Count() > 0) { userId = userIds.FirstOrDefault(); } ViewData["isCheck"] = isCheck; if (Request.QueryString.Get<DateTime>("startdate") != DateTime.MinValue) startDate = Request.QueryString.Get<DateTime>("startDate"); if (Request.QueryString.Get<DateTime>("enddate") != DateTime.MinValue) endDate = Request.QueryString.Get<DateTime>("endDate"); if (startDate.HasValue && endDate.HasValue && startDate.Value > endDate.Value) { DateTime? changDate = startDate; startDate = endDate; endDate = changDate; } if (endDate.HasValue) endDate = endDate.Value.AddDays(1).AddMilliseconds(-1); Dictionary<bool, string> income = new Dictionary<bool, string> { { true, "收入" }, { false, "支出" } }; ViewData["incomeList"] = new SelectList(income.Select(n => new { text = n.Value.ToString(), value = n.Key.ToString().ToLower() }), "value", "text", isIncome); ViewData["userId"] = userId; PagingDataSet<PointRecord> pointRecords = pointService.GetPointRecords(userId, isIncome, pointItemName, startDate, endDate, pageSize, pageIndex ?? 1); Dictionary<long, string> displayNameDic = new Dictionary<long, string>(); foreach (var item in pointRecords) { if (userService.GetUser(item.UserId) != null && userService.GetUser(item.UserId).DisplayName != null) displayNameDic[item.UserId] = userService.GetUser(item.UserId).DisplayName; } ViewData["displayNameDic"] = displayNameDic; return View(pointRecords); }
/// <summary> /// 审核状态发生变化时处理积分 /// </summary> /// <param name="blogThread">日志</param> /// <param name="eventArgs">事件</param> private void BlogThreadPointModule_After(BlogThread blogThread, AuditEventArgs eventArgs) { AuditService auditService = new AuditService(); string pointItemKey = string.Empty; string eventOperationType = string.Empty; bool? auditDirection = auditService.ResolveAuditDirection(eventArgs.OldAuditStatus, eventArgs.NewAuditStatus); if (auditDirection == true) //加积分 { pointItemKey = PointItemKeys.Instance().Blog_CreateThread(); if (eventArgs.OldAuditStatus == null) eventOperationType = EventOperationType.Instance().Create(); else eventOperationType = EventOperationType.Instance().Approved(); } else if (auditDirection == false) //减积分 { pointItemKey = PointItemKeys.Instance().Blog_DeleteThread(); if (eventArgs.NewAuditStatus == null) eventOperationType = EventOperationType.Instance().Delete(); else eventOperationType = EventOperationType.Instance().Disapproved(); } if (!string.IsNullOrEmpty(pointItemKey)) { PointService pointService = new PointService(); string description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_" + eventOperationType), "日志", blogThread.Subject); pointService.GenerateByRole(blogThread.UserId, pointItemKey, description, eventOperationType == EventOperationType.Instance().Create() || eventOperationType == EventOperationType.Instance().Delete() && eventArgs.OperatorInfo.OperatorUserId == blogThread.UserId); } }
/// <summary> /// 处理加精操作加积分 /// </summary> /// <param name="blogThread">日志</param> /// <param name="eventArgs">事件</param> private void BlogThreadPointModuleForManagerOperation_After(BlogThread blogThread, CommonEventArgs eventArgs) { NoticeService noticeService = new NoticeService(); string pointItemKey = string.Empty; if (eventArgs.EventOperationType == EventOperationType.Instance().SetEssential()) { pointItemKey = PointItemKeys.Instance().EssentialContent(); PointService pointService = new PointService(); string description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_" + eventArgs.EventOperationType), "日志", blogThread.ResolvedSubject); pointService.GenerateByRole(blogThread.UserId, pointItemKey, description); if (blogThread.UserId > 0) { Notice notice = Notice.New(); notice.UserId = blogThread.UserId; notice.ApplicationId = BlogConfig.Instance().ApplicationId; notice.TypeId = NoticeTypeIds.Instance().Hint(); notice.LeadingActor = blogThread.Author; notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(blogThread.UserId))); notice.RelativeObjectName = HtmlUtility.TrimHtml(blogThread.Subject, 64); notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().BlogDetail(blogThread.User.UserName, blogThread.ThreadId)); notice.TemplateName = NoticeTemplateNames.Instance().ManagerSetEssential(); noticeService.Create(notice); } } }
/// <summary> /// 审核状态发生变化时处理积分 /// </summary> /// <param name="sender">微博实体</param> /// <param name="eventArgs">时间参数</param> private void MicroblogPointModule_After(MicroblogEntity sender, AuditEventArgs eventArgs) { string pointItemKey = string.Empty, eventOperationType = string.Empty; ActivityService activityService = new ActivityService(); AuditService auditService = new AuditService(); bool? auditDirection = auditService.ResolveAuditDirection(eventArgs.OldAuditStatus, eventArgs.NewAuditStatus); if (auditDirection == true) //加积分 { pointItemKey = PointItemKeys.Instance().Microblog_CreateMicroblog(); if (eventArgs.OldAuditStatus == null) eventOperationType = EventOperationType.Instance().Create(); else eventOperationType = EventOperationType.Instance().Approved(); } else if (auditDirection == false) //减积分 { pointItemKey = PointItemKeys.Instance().Microblog_DeleteMicroblog(); if (eventArgs.NewAuditStatus == null) eventOperationType = EventOperationType.Instance().Delete(); else eventOperationType = EventOperationType.Instance().Disapproved(); } if (!string.IsNullOrEmpty(pointItemKey)) { PointService pointService = new PointService(); string description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_" + eventOperationType), "微博", Tunynet.Utilities.HtmlUtility.TrimHtml(sender.Body, 15)); pointService.GenerateByRole(sender.UserId, pointItemKey, description, eventOperationType == EventOperationType.Instance().Create() || eventOperationType == EventOperationType.Instance().Delete() && eventArgs.OperatorInfo.OperatorUserId == sender.UserId); } }
/// <summary> /// 处理加精、置顶等操作 /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> private void BarThreadPointModuleForManagerOperation_After(BarThread sender, CommonEventArgs eventArgs) { NoticeService noticeService = new NoticeService(); if (eventArgs.OperatorInfo == null) return; string pointItemKey = string.Empty; if (eventArgs.EventOperationType == EventOperationType.Instance().SetEssential()) { pointItemKey = PointItemKeys.Instance().EssentialContent(); if (sender.UserId > 0 && sender.UserId != eventArgs.OperatorInfo.OperatorUserId) { Notice notice = Notice.New(); notice.UserId = sender.UserId; notice.ApplicationId = BarConfig.Instance().ApplicationId; notice.TypeId = NoticeTypeIds.Instance().Hint(); notice.LeadingActor = sender.Author; notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(sender.UserId))); notice.RelativeObjectName = HtmlUtility.TrimHtml(sender.Subject, 64); notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().ThreadDetail(sender.ThreadId)); notice.TemplateName = NoticeTemplateNames.Instance().ManagerSetEssential(); noticeService.Create(notice); } } else if (eventArgs.EventOperationType == EventOperationType.Instance().SetSticky()) { pointItemKey = PointItemKeys.Instance().StickyContent(); if (sender.UserId > 0 && sender.UserId != eventArgs.OperatorInfo.OperatorUserId) { Notice notice = Notice.New(); notice.UserId = sender.UserId; notice.ApplicationId = BarConfig.Instance().ApplicationId; notice.TypeId = NoticeTypeIds.Instance().Hint(); notice.LeadingActor = sender.Author; notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(sender.UserId))); notice.RelativeObjectName = HtmlUtility.TrimHtml(sender.Subject, 64); notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().ThreadDetail(sender.ThreadId)); notice.TemplateName = NoticeTemplateNames.Instance().ManagerSetSticky(); noticeService.Create(notice); } } if (!string.IsNullOrEmpty(pointItemKey)) { PointService pointService = new PointService(); string description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_" + eventArgs.EventOperationType), "帖子", sender.Subject); pointService.GenerateByRole(sender.UserId, pointItemKey, description); } }
/// <summary> /// 删除被评论对象时评论的积分处理 /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> void CommentsDeleteEventModel_After(IEnumerable<Comment> sender, CommonEventArgs eventArgs) { if (eventArgs.EventOperationType == EventOperationType.Instance().Delete() && sender != null) { PointService pointService = new PointService(); foreach (var item in sender) { string description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_DeleteComment"), item.Author, item.Subject); pointService.GenerateByRole(item.UserId, PointItemKeys.Instance().DeleteComment(), description); } } }
/// <summary> /// 首次上传头像加分 /// </summary> /// <param name="sender">用户实体</param> /// <param name="eventArgs">事件参数</param> public void UserPointEventModule_After(User sender, CropAvatarEventArgs eventArgs) { string pointItemKey = string.Empty; string eventOperationType = string.Empty; if (eventArgs.IsFirst) { PointService pointService = new PointService(); pointItemKey = PointItemKeys.Instance().FirstUploadAvatar(); string description = ResourceAccessor.GetString("PointRecord_Pattern_FirstUploadAvatar"); pointService.GenerateByRole(sender.UserId, pointItemKey, description, true); } }
/// <summary> /// 用户解除管制后增加邀请人积分 /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> void FreeModeratedUser_After(User sender, CommonEventArgs eventArgs) { if (sender == null || string.IsNullOrEmpty(eventArgs.EventOperationType)) return; if (eventArgs.EventOperationType == EventOperationType.Instance().CancelModerateUser() || eventArgs.EventOperationType == EventOperationType.Instance().AutoNoModeratedUser()) { PointService pointService = new PointService(); string pointItemKey = string.Empty; pointItemKey = PointItemKeys.Instance().FreeModeratedUser(); if (sender != null) { InviteFriendRecord invitingUser = inviteFriendService.GetInvitingUserId(sender.UserId); if (invitingUser != null) { if (!invitingUser.InvitingUserHasBeingRewarded) { string userName = UserIdToUserNameDictionary.GetUserName(invitingUser.UserId); string invitedName = UserIdToUserNameDictionary.GetUserName(sender.UserId); string description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_FreeModeratedUser"), userName, invitedName); pointService.GenerateByRole(invitingUser.UserId, pointItemKey, description); inviteFriendService.RewardingUser(invitingUser.UserId); } } } } }
/// <summary> /// 积分处理程序 /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> private void BarPostPointModule_After(BarPost sender, AuditEventArgs eventArgs) { AuditService auditService = new AuditService(); bool? auditDirection = auditService.ResolveAuditDirection(eventArgs.OldAuditStatus, eventArgs.NewAuditStatus); string pointItemKey = string.Empty; string eventOperationType = string.Empty; if (auditDirection == true) //加积分 { pointItemKey = PointItemKeys.Instance().CreateComment(); if (eventArgs.OldAuditStatus == null) eventOperationType = EventOperationType.Instance().Create(); else eventOperationType = EventOperationType.Instance().Approved(); } else if (auditDirection == false) //减积分 { pointItemKey = PointItemKeys.Instance().DeleteComment(); if (eventArgs.NewAuditStatus == null) eventOperationType = EventOperationType.Instance().Delete(); else eventOperationType = EventOperationType.Instance().Disapproved(); } if (!string.IsNullOrEmpty(pointItemKey)) { PointService pointService = new PointService(); string description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_" + eventOperationType), "回帖", HtmlUtility.TrimHtml(sender.GetBody(), 32)); pointService.GenerateByRole(sender.UserId, pointItemKey, description, eventOperationType == EventOperationType.Instance().Create() || eventOperationType == EventOperationType.Instance().Delete() && eventArgs.OperatorInfo.OperatorUserId == sender.UserId); } }
/// <summary> /// 删除用户 /// </summary> /// <param name="userId">用户Id</param> /// <param name="takeOverUserName">用于接管删除用户的内容(例如:用户创建的群组)</param> /// <param name="takeOverAll">是否接管被删除用户的所有内容</param> /// <remarks>接管被删除用户的所有内容</remarks> /// <returns></returns> public UserDeleteStatus DeleteUser(long userId, string takeOverUserName, bool takeOverAll) { User user = userRepository.Get(userId); if (user == null) return UserDeleteStatus.DeletingUserNotFound; if (takeOverAll) { long takeOverUserId = userRepository.GetUserIdByUserName(takeOverUserName); User takeOverUser = userRepository.Get(takeOverUserId); if (takeOverUser == null) return UserDeleteStatus.InvalidTakeOverUsername; } if (!user.IsModerated && !user.IsForceModerated) { // 邀请用户被删除时扣除邀请人积分 PointService pointService = new PointService(); string pointItemKey = string.Empty; pointItemKey = PointItemKeys.Instance().DeleteInvitedUser(); InviteFriendRecord invitingUser = new InviteFriendService().GetInvitingUserId(user.UserId); if (invitingUser != null) { string userName = UserIdToUserNameDictionary.GetUserName(invitingUser.UserId); string invitedName = UserIdToUserNameDictionary.GetUserName(user.UserId); string description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_DeleteInvitedUser"), userName, invitedName); pointService.GenerateByRole(invitingUser.UserId, pointItemKey, description); } } EventBus<User, DeleteUserEventArgs>.Instance().OnBefore(user, new DeleteUserEventArgs(takeOverUserName, takeOverAll)); int affectCount = userRepository.Delete(user); if (affectCount > 0) { UserIdToUserNameDictionary.RemoveUserId(userId); UserIdToUserNameDictionary.RemoveUserName(user.UserName); EventBus<User, DeleteUserEventArgs>.Instance().OnAfter(user, new DeleteUserEventArgs(takeOverUserName, takeOverAll)); return UserDeleteStatus.Deleted; } return UserDeleteStatus.UnknownFailure; }
/// <summary> /// 创建用户的时候修改积分 /// </summary> /// <param name="sender">创建用户角色</param> /// <param name="eventArgs">参数</param> void RegisterEventModule_After(User sender, CreateUserEventArgs eventArgs) { PointService pointService = new PointService(); string description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_Register"), sender.UserName); pointService.GenerateByRole(sender.UserId, PointItemKeys.Instance().Register(), description, true); }
/// <summary> /// 用户积分处理 /// </summary> /// <param name="sender">关注实体</param> /// <param name="eventArgs">事件参数</param> void FollowPointModule_After(FollowEntity sender, CommonEventArgs eventArgs) { IUserService userservice = DIContainer.Resolve<IUserService>(); IUser followedUser = userservice.GetUser(sender.FollowedUserId); if (followedUser == null) { return; } string pointItemKey = string.Empty; PointService pointService = new PointService(); string description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_FollowUser"), followedUser.DisplayName); #region 设置积分项Key if (EventOperationType.Instance().Create() == eventArgs.EventOperationType) pointItemKey = PointItemKeys.Instance().FollowUser(); else if (EventOperationType.Instance().Delete() == eventArgs.EventOperationType) pointItemKey = PointItemKeys.Instance().CancelFollowUser(); #endregion pointService.GenerateByRole(sender.UserId, pointItemKey, description); }
/// <summary> /// 转换为PointItem /// </summary> /// <returns>PointItem</returns> public PointItem AsPointItem() { PointItem pointItem = new PointService().GetPointItem(ItemKey); pointItem.ItemKey = this.ItemKey; pointItem.ItemName = this.ItemName; pointItem.TradePoints = this.TradePoints; pointItem.ReputationPoints = this.ReputationPoints; pointItem.ExperiencePoints = this.ExperiencePoints; return pointItem; }
/// <summary> /// 添加BBTag实体 /// </summary> /// <param name="htmlTemplate">html模板</param> /// <param name="attachment">带替换附件</param> /// <returns>BBTag实体</returns> private BBTag AddBBTag(string htmlTemplate, Attachment attachment) { PointCategory pointCategory = new PointService().GetPointCategory(PointCategoryKeys.Instance().TradePoints()); string categoryName = pointCategory != null ? pointCategory.CategoryName : "金币"; BBAttribute bbAttribute = new BBAttribute("attachTemplate", "", n => { return string.Format(htmlTemplate, attachment.FriendlyFileName, attachment.FriendlyFileLength, attachment.Price > 0 ? ",<em>需要" + attachment.Price + categoryName + "</em>" : "", attachment.DownloadCount, attachment.AttachmentId); }, HtmlEncodingMode.UnsafeDontEncode); return new BBTag("attach:" + attachment.AttachmentId, "${attachTemplate}", "", false, BBTagClosingStyle.LeafElementWithoutContent, null, bbAttribute); }
/// <summary> /// 推荐积分处理 /// </summary> /// <param name="sender">推荐实体</param> /// <param name="eventArgs">事件参数</param> void RecommendPointModule_After(RecommendItem sender, CommonEventArgs eventArgs) { if (eventArgs.EventOperationType != EventOperationType.Instance().Create()) { return; } string pointItemKey = string.Empty; PointService pointService = new PointService(); string description = string.Empty; TenantTypeService tenantTypeService = new TenantTypeService(); var urlGetter = RecommendUrlGetterFactory.Get(sender.TenantTypeId); NoticeService noticeService = new NoticeService(); Notice notice = Notice.New(); notice.TypeId = NoticeTypeIds.Instance().Hint(); //notice.TemplateName = "FollowUser"; notice.UserId = sender.UserId; notice.LeadingActorUserId = sender.ReferrerId; notice.LeadingActor = sender.ReferrerName; notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(sender.ReferrerId)); notice.RelativeObjectId = sender.UserId; notice.RelativeObjectName = sender.ItemName; notice.RelativeObjectUrl = sender.DetailUrl; if (sender.TenantTypeId == TenantTypeIds.Instance().User()) { pointItemKey = PointItemKeys.Instance().RecommendUser(); description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_RecommendUser")); notice.TemplateName = NoticeTemplateNames.Instance().ManagerRecommendedUser(); } else { pointItemKey = PointItemKeys.Instance().RecommendContent(); TenantType tenantType = tenantTypeService.Get(sender.TenantTypeId); if (tenantType == null) return; description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_RecommendContent"), tenantType.Name, sender.ItemName); notice.TemplateName = NoticeTemplateNames.Instance().ManagerRecommended(); } noticeService.Create(notice); pointService.GenerateByRole(sender.UserId, pointItemKey, description); }