Пример #1
0
        /// <summary>
        /// 用户和系统进行积分交易(例如:用户购买邀请码,礼品兑换)
        /// </summary>
        /// <param name="payerUserId">支付积分人UserId</param>
        /// <param name="points">交易积分额</param>
        /// <param name="description">交易描述</param>
        /// <param name="isImmediate">是否即时交易</param>
        public void TradeToSystem(long payerUserId, 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));
            }

            //2、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);
            }

            //用于积分提醒
            TrackPointRecord(payerUserId, payerPointRecord);

            //变更系统积分
            PointRecord pointRecord = new PointRecord(0, ResourceAccessor.GetString("Common_PointTrade"), description, 0, 0, points);

            pointRecordRepository.Insert(pointRecord);
            ChangeSystemTradePoints(points);
        }
Пример #2
0
        /// <summary>
        /// 新建实体时使用
        /// </summary>
        public static PointCategory New()
        {
            PointCategory pointCategorie = new PointCategory()
            {
                CategoryName = string.Empty,
                Unit         = string.Empty,
                Description  = string.Empty
            };

            return(pointCategorie);
        }
Пример #3
0
        /// <summary>
        /// 新建实体时使用
        /// </summary>
        public static PointCategory New()
        {
            PointCategory pointCategorie = new PointCategory()
            {
                CategoryName = string.Empty,
                Unit = string.Empty,
                Description = string.Empty

            };
            return pointCategorie;
        }
Пример #4
0
 /// <summary>
 /// 更新积分类型
 /// </summary>
 /// <param name="pointCategory">待更新的积分类型</param>
 public void UpdatePointCategory(PointCategory pointCategory)
 {
     //注意:CategoryKey、CategoryName、Description、DisplayOrder不允许修改
     pointCategoryRepository.Update(pointCategory);
 }
Пример #5
0
 /// <summary>
 /// 更新积分类型
 /// </summary>
 /// <param name="pointCategory">待更新的积分类型</param>
 public void UpdatePointCategory(PointCategory pointCategory)
 {
     //注意:CategoryKey、CategoryName、Description、DisplayOrder不允许修改
     pointCategoryRepository.Update(pointCategory);
 }
Пример #6
0
        /// <summary>
        /// 奖惩用户
        /// </summary>
        /// <param name="userId">被奖惩用户</param>
        /// <param name="experiencePoints">经验</param>
        /// <param name="reputationPoints">威望</param>
        /// <param name="tradePoints">金币</param>
        /// <param name="description">奖惩理由</param>
        public void Reward(long userId, int experiencePoints, int reputationPoints, int tradePoints, string description)
        {
            if (experiencePoints == 0 && reputationPoints == 0 && tradePoints == 0)
            {
                return;
            }
            IUserService userService = DIContainer.Resolve <IUserService>();
            IUser        user        = userService.GetUser(userId);

            if (user == null)
            {
                throw new ExceptionFacade(string.Format("用户“{0}”不存在或已被删除", userId));
            }
            //1、增减用户积分额并生成用户积分记录;
            bool        isIncome    = experiencePoints > 0 || reputationPoints > 0 || tradePoints > 0;
            PointRecord pointRecord = new PointRecord(userId, isIncome ? ResourceAccessor.GetString("Common_AdminReward") : ResourceAccessor.GetString("Common_AdminPunish"), description, experiencePoints, reputationPoints, tradePoints);

            pointRecordRepository.Insert(pointRecord);
            userService.ChangePoints(userId, experiencePoints, reputationPoints, tradePoints);

            //2、增减系统积分额并生成系统积分记录;
            PointRecord systemPointRecord = new PointRecord(0, isIncome ? ResourceAccessor.GetString("Common_RewardUser") : ResourceAccessor.GetString("Common_PunishUser"), description, -experiencePoints, -reputationPoints, -tradePoints);

            pointRecordRepository.Insert(systemPointRecord);

            ChangeSystemTradePoints(-tradePoints);

            //3、生成操作文章
            OperationLogService logService         = Tunynet.DIContainer.Resolve <OperationLogService>();
            IOperatorInfoGetter operatorInfoGetter = DIContainer.Resolve <IOperatorInfoGetter>();

            if (operatorInfoGetter == null)
            {
                return;
            }

            OperationLogEntry logEntry = new OperationLogEntry(operatorInfoGetter.GetOperatorInfo());

            logEntry.ApplicationId       = 0;
            logEntry.Source              = string.Empty;
            logEntry.OperationType       = EventOperationType.Instance().Update();
            logEntry.OperationObjectName = user.UserName;
            logEntry.OperationObjectId   = userId;

            PointCategory experiencePointCategory = GetPointCategory(PointCategoryKeys.Instance().ExperiencePoints());

            if (experiencePointCategory == null)
            {
                return;
            }
            PointCategory reputationPointCategory = GetPointCategory(PointCategoryKeys.Instance().ReputationPoints());

            if (reputationPointCategory == null)
            {
                return;
            }
            PointCategory tradePointCategory = GetPointCategory(PointCategoryKeys.Instance().TradePoints());

            if (tradePointCategory == null)
            {
                return;
            }

            logEntry.Description = string.Format("{0}“{1}”:{2}{3}{4},{5}{6}{7},{8}{9}{10}",
                                                 isIncome ? ResourceAccessor.GetString("Common_RewardUser") : ResourceAccessor.GetString("Common_PunishUser"), user.UserName,
                                                 experiencePoints, experiencePointCategory.Unit, experiencePointCategory.CategoryName,
                                                 reputationPoints, reputationPointCategory.Unit, reputationPointCategory.CategoryName,
                                                 tradePoints, tradePointCategory.Unit, tradePointCategory.CategoryName);
            logService.Create(logEntry);
        }
Пример #7
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>
        /// <param name="needPointMessage">是否需要积分提醒</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、检查是否需要缴纳交易税,如果需要,则创建系统积分记录,变更系统积分总额
            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)
                {
                    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);
            }

            //用于积分提醒
            TrackPointRecord(payerUserId, payerPointRecord);

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

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