Пример #1
0
        private void RewardAndPunishmentUser_After(IUser sender, RewardAndPunishmentUserEventArgs eventArgs)
        {
            PointSettings pointSettings = pointSettingsManger.Get();
            int           totalPoints   = pointSettings.CalculateIntegratedPoint(sender.ExperiencePoints, sender.ReputationPoints);

            //更新用户等级
            //if (eventArgs.ExperiencePoints <= 0 && eventArgs.ReputationPoints <= 0)
            //    return;
            IUserService               userService     = DIContainer.Resolve <IUserService>();
            UserRankService            userRankService = new UserRankService();
            SortedList <int, UserRank> userRanks       = userRankService.GetAll();
            UserRank maxUserRank = null;

            if (userRanks != null && userRanks.Count > 0)
            {
                maxUserRank = userRanks.First().Value;
            }
            foreach (KeyValuePair <int, UserRank> userRank in userRanks)
            {
                if (totalPoints > userRank.Value.PointLower && userRank.Value.PointLower > maxUserRank.PointLower)
                {
                    maxUserRank = userRank.Value;
                }
            }
            userService.UpdateRank(sender.UserId, maxUserRank.Rank);

            //自动解除管制
            var user = userService.GetFullUser(sender.UserId);

            if (user.IsModerated && !user.IsForceModerated)
            {
                UserSettings userSettings = DIContainer.Resolve <IUserSettingsManager>().Get();
                if (totalPoints > userSettings.NoModeratedUserPoint)
                {
                    userService.NoModeratedUser(user.UserId);
                }
            }

            //发送通知
            if (sender == null)
            {
                return;
            }
            Notice notice = Notice.New();

            notice.UserId        = sender.UserId;
            notice.ApplicationId = 0;
            notice.TypeId        = NoticeTypeIds.Instance().Hint();
            if (eventArgs.ExperiencePoints < 0 || eventArgs.ReputationPoints < 0 || eventArgs.TradePoints < 0)
            {
                notice.Body = "您被系统扣除经验:" + -eventArgs.ExperiencePoints + "、威望:" + -eventArgs.ReputationPoints + "、金币:" + -eventArgs.TradePoints;
            }
            else
            {
                notice.Body = "您收到系统奖励经验:" + eventArgs.ExperiencePoints + "、威望:" + eventArgs.ReputationPoints + "、金币:" + eventArgs.TradePoints;
            }
            notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().ListNotices(sender.UserName, null, null));
            noticeService.Create(notice);
        }
Пример #2
0
        /// <summary>
        /// 根据一定规则重置所有的用户等级
        /// </summary>
        public void ResetAllUser()
        {
            IPointSettingsManager pointSettingsManager = DIContainer.Resolve <IPointSettingsManager>();
            PointSettings         pointSettings        = pointSettingsManager.Get();

            var sql_Update = PetaPoco.Sql.Builder;

            sql_Update.Append("update tn_Users set Rank = (select max(Rank) from tn_UserRanks UR where UR.PointLower <= (ExperiencePoints * @0 + ReputationPoints * @1) or ((ExperiencePoints * @0 + ReputationPoints * @1)<0 and UR.Rank = 1) )", pointSettings.ExperiencePointsCoefficient, pointSettings.ReputationPointsCoefficient);
            CreateDAO().Execute(sql_Update);
        }
Пример #3
0
        /// <summary>
        /// 更改用户积分
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="eventArgs"></param>
        void ChangePointsEventModule_After(IUser sender, ChangePointsEventArgs eventArgs)
        {
            if (eventArgs.ExperiencePoints <= 0 && eventArgs.ReputationPoints <= 0)
            {
                return;
            }

            IUserService userService = DIContainer.Resolve <IUserService>();

            //自动升级
            UserRankService            userRankService = new UserRankService();
            SortedList <int, UserRank> userRanks       = userRankService.GetAll();
            UserRank maxUserRank = null;

            if (userRanks != null && userRanks.Count > 0)
            {
                maxUserRank = userRanks.ElementAt(0).Value;
            }
            IPointSettingsManager pointSettingsManger = DIContainer.Resolve <IPointSettingsManager>();
            PointSettings         pointSettings       = pointSettingsManger.Get();
            int totalPoints = pointSettings.CalculateIntegratedPoint(sender.ExperiencePoints, sender.ReputationPoints);

            foreach (KeyValuePair <int, UserRank> userRank in userRanks)
            {
                if (totalPoints > userRank.Value.PointLower && userRank.Value.PointLower > maxUserRank.PointLower)
                {
                    maxUserRank = userRank.Value;
                }
            }
            if (maxUserRank.Rank > sender.Rank)
            {
                userService.UpdateRank(sender.UserId, maxUserRank.Rank);
            }

            //自动解除管制
            var user = userService.GetFullUser(sender.UserId);

            if (user.IsModerated && !user.IsForceModerated)
            {
                UserSettings userSettings = DIContainer.Resolve <IUserSettingsManager>().Get();
                if (totalPoints > userSettings.NoModeratedUserPoint)
                {
                    userService.NoModeratedUser(user.UserId);
                }
            }
        }
Пример #4
0
        public ActionResult MyRank(string spaceKey)
        {
            IUser         user          = userService.GetUser(spaceKey);
            PointSettings pointSettings = pointSettingsManger.Get();

            pageResourceManager.InsertTitlePart("我的等级");

            int totalPoints = pointSettings.CalculateIntegratedPoint(user.ExperiencePoints, user.ReputationPoints);

            SortedList <int, UserRank> userRanks = userRankService.GetAll();
            UserRank userRank = userRankService.Get(user.Rank);

            if (userRank != null)
            {
                ViewData["userRankName"] = userRank.RankName;
            }


            ViewData["userRanks"]   = userRanks;
            ViewData["totalPoints"] = totalPoints;
            if (user.Rank + 1 <= userRankService.GetAll().Count())
            {
                ViewData["nextRankName"] = userRankService.Get(user.Rank + 1).RankName;
                ViewData["leftUpgradeExperiencePoints"] = userRankService.Get(user.Rank + 1).PointLower - totalPoints;
            }
            else
            {
                ViewData["leftUpgradeExperiencePoints"] = 0;
            }

            #region 计算进度条百分比

            List <UserRank> ranks      = userRanks.Values.ToList();
            int             a          = (userRanks.Count() - 2) / 3;
            int             rank       = user.Rank;
            double          leftPoints = 0;

            if (rank >= 1 && rank < ranks.ElementAt(a).Rank)
            {
                leftPoints = totalPoints / (double)ranks.ElementAt(a).PointLower / 5;
            }
            else if (rank >= ranks.ElementAt(a).Rank&& rank < ranks.ElementAt(2 * a).Rank)
            {
                leftPoints = (totalPoints - ranks.ElementAt(a).PointLower) / (double)(ranks.ElementAt(2 * a).PointLower - ranks.ElementAt(a).PointLower) / 5 + 0.2;
            }

            else if (rank >= ranks.ElementAt(2 * a).Rank&& rank < ranks.ElementAt(3 * a).Rank)
            {
                leftPoints = (totalPoints - ranks.ElementAt(2 * a).PointLower) / (double)(ranks.ElementAt(3 * a).PointLower - ranks.ElementAt(2 * a).PointLower) / 5 + 0.4;
            }

            else if (rank >= ranks.ElementAt(3 * a).Rank&& rank < userRanks.ToArray()[userRanks.Count() - 1].Value.Rank)
            {
                leftPoints = (totalPoints - ranks.ElementAt(3 * a).PointLower) / (double)(userRanks.ToArray()[userRanks.Count() - 1].Value.PointLower - ranks.ElementAt(3 * a).PointLower) / 5 + 0.6;
            }
            else
            {
                leftPoints = totalPoints / double.MaxValue + 0.8;
            }
            ViewData["leftPoints"] = leftPoints;
            #endregion


            return(View(user));
        }
Пример #5
0
        /// <summary>
        /// 积分交易
        /// </summary>
        /// <param name="payerUserId">支付积分人UserId</param>
        /// <param name="payeeUserId">接收积分人UserId</param>
        /// <param name="points">交易积分额</param>
        /// <param name="description">交易描述</param>
        /// <param name="isImmediate">是否即时交易</param>
        public void Trade(long payerUserId, long payeeUserId, int points, string description, bool isImmediate)
        {
            //如果是即时交易,从支付方从交易积分扣除,否则从冻结的交易积分扣除(不足时抛出异常)

            if (points <= 0)
            {
                return;
            }
            //1、首先检查payerUserId是否可以支付积分交易额,如果余额不足抛出异常
            IUserService userService = DIContainer.Resolve <IUserService>();
            IUser        payer       = userService.GetUser(payerUserId);

            if (payer == null)
            {
                throw new ExceptionFacade(string.Format("用户“{0}”不存在或已被删除", payerUserId));
            }

            PointCategory pointCategory = GetPointCategory(PointCategoryKeys.Instance().TradePoints());

            if (pointCategory == null)
            {
                return;
            }

            if (isImmediate && payer.TradePoints < points)
            {
                throw new ExceptionFacade(string.Format("积分余额不足,仅有{0}{2}{3},不够支付{1}{2}{3}", payer.TradePoints, points, pointCategory.Unit, pointCategory.CategoryName));
            }

            if (!isImmediate && payer.FrozenTradePoints < points)
            {
                throw new ExceptionFacade(string.Format("冻结积分余额不足,仅有{0}{2}{3},不够支付{1}{2}{3}", payer.FrozenTradePoints, points, pointCategory.Unit, pointCategory.CategoryName));
            }

            IUser payee = userService.GetUser(payeeUserId);

            if (payee == null)
            {
                throw new ExceptionFacade(string.Format("用户“{0}”不存在或已被删除", payeeUserId));
            }

            //2、检查是否需要缴纳交易税,如果需要,则创建系统积分记录,变更系统积分总额
            IPointSettingsManager pointSettingsManager = DIContainer.Resolve <IPointSettingsManager>();
            PointSettings         pointSettings        = pointSettingsManager.Get();
            int realPoints = points;

            if (pointSettings.TransactionTax > 0 && pointSettings.TransactionTax < 100)
            {
                realPoints = points * (100 - pointSettings.TransactionTax) / 100;
                int taxPoints = points - realPoints;
                if (taxPoints > 0)
                {
                    //done:zhengw,by mazq  交易税 应该放入资源文件(该类描述都应该允许管理员修改)
                    //zhengw回复:已修改
                    PointRecord pointRecord = new PointRecord(0, ResourceAccessor.GetString("Common_TransactionTax"), description, 0, 0, taxPoints);
                    pointRecordRepository.Insert(pointRecord);
                    ChangeSystemTradePoints(taxPoints);
                }
            }

            //3、points去除交易税,分别变更交易双方的积分值,并生成积分记录
            PointRecord payerPointRecord = new PointRecord(payerUserId, ResourceAccessor.GetString("Common_PointTrade"), description, 0, 0, -points);

            pointRecordRepository.Insert(payerPointRecord);
            if (isImmediate)
            {
                userService.ChangePoints(payerUserId, 0, 0, -points);
            }
            else
            {
                userService.ReduceFrozenTradePoints(payerUserId, points);
            }

            PointRecord payeePointRecord = new PointRecord(payeeUserId, ResourceAccessor.GetString("Common_PointTrade"), description, 0, 0, realPoints);

            pointRecordRepository.Insert(payeePointRecord);
            userService.ChangePoints(payeeUserId, 0, 0, realPoints);
        }