Exemplo n.º 1
0
        public void TeamUserGradeAutoUpdate(long userId, IScope scope)
        {
            var parentMaps = scope.Resolve <ITeamService>().GetTeamMap(userId).ToList();
            var userIds    = parentMaps.Select(r => r.UserId);
            var users      = scope.Resolve <IUserService>().GetList(userIds);

            // 更新团队等级数量
            foreach (var item in parentMaps)
            {
                // 更新团队上级的等级数据
                // 从最新的会员开始更新,UserId大的在前面
                scope.Resolve <IGradeInfoService>().UpdateSingle(item.UserId);

                var itemGradeInfo =
                    scope.Resolve <IGradeInfoService>()
                    .GetSingle(r => r.UserId == item.UserId);     // 必须重新获取,因为如果下级会员更新成功,会自动更新
                var itemUser = users.FirstOrDefault(r => r.Id == item.UserId);
                if (itemGradeInfo == null || itemUser == null)
                {
                    continue;
                }

                var kpiResult = GetKpiResult(itemGradeInfo, itemUser, scope);
                if (kpiResult.Item1)
                {
                    var user          = scope.Resolve <IUserService>().GetSingle(r => r.Id == item.UserId);
                    var beforeGradeId = user.GradeId;
                    user.GradeId = kpiResult.Item2;
                    if (scope.Resolve <IUserService>().Update(user))
                    {
                        var upgradeRecord = new UpgradeRecord {
                            UserId        = item.UserId,
                            Type          = UpgradeType.TeamUserGradeChange,
                            QueueId       = 0,
                            BeforeGradeId = beforeGradeId,
                            AfterGradeId  = kpiResult.Item2
                        };
                        scope.Resolve <IUpgradeRecordService>().Add(upgradeRecord);

                        // 重新添加队列 // 触发上面的
                        UpgradeQueue queue = new UpgradeQueue {
                            UserId = user.Id,
                            Type   = UpgradeType.TeamUserGradeChange,
                            Status = QueueStatus.Pending
                        };
                        scope.Resolve <IUpgradeQueueService>().Add(queue);
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///     计算会员自动升级Kpi,
        ///     如果满足条件,则会员自动升级,同时更新上级团队信息、添加会员等级记录
        /// </summary>
        /// <param name="userId"></param>
        public void TeamUserGradeAutoUpdate(long userId)
        {
            var parentMaps = Resolve <ITeamService>().GetTeamMap(userId).ToList();
            var userIds    = parentMaps.Select(r => r.UserId);
            var users      = Resolve <IUserService>().GetList(userIds);

            // 更新团队等级数量
            foreach (var item in parentMaps)
            {
                // 更新团队上级的等级数据
                // 从最新的会员开始更新,UserId大的在前面
                UpdateSingle(item.UserId);

                var itemGradeInfo = GetSingle(r => r.UserId == item.UserId); // 必须重新获取,因为如果下级会员更新成功,会自动更新
                var itemUser      = users.FirstOrDefault(r => r.Id == item.UserId);
                if (itemGradeInfo == null || itemUser == null)
                {
                    continue;
                }

                var kpiResult = GetKpiResult(itemGradeInfo, itemUser);
                if (kpiResult.Item1)
                {
                    var user = Resolve <IUserService>().GetSingle(r => r.Id == item.UserId);
                    user.GradeId = kpiResult.Item2;
                    if (Resolve <IUserService>().Update(user))
                    {
                        var upgradeRecord = new UpgradeRecord
                        {
                            UserId        = item.UserId,
                            Type          = UpgradeType.TeamUserGradeChange,
                            QueueId       = 0,
                            BeforeGradeId = itemUser.GradeId,
                            AfterGradeId  = kpiResult.Item2
                        };
                        Resolve <IUpgradeRecordService>().Add(upgradeRecord);
                        Log($"{user.GetUserName()}自动升级成功");
                    }
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        ///     执行分润执行结果
        /// </summary>
        /// <param name="resultList">The result list.</param>
        public void UpdateUpgradeTaskResult(IEnumerable <UserGradeChangeResult> resultList)
        {
            var sqlList           = new List <string>();
            var dbParameterList   = new List <DbParameter[]>();
            var repositoryContext = RepositoryContext;

            IList <long> shareUsreIds = new List <long>();

            foreach (var gradeResult in resultList)
            {
                //更新等级
                var sql        = "update User_User set GradeId=@GradeId  where  Id=@Id";
                var parameters = new[]
                {
                    repositoryContext.CreateParameter("@Id", gradeResult.Result.UserId),
                    repositoryContext.CreateParameter("@GradeId", gradeResult.Result.GradeId)
                };
                sqlList.Add(sql);
                dbParameterList.Add(parameters);

                #region 添加的短信队列

                //添加的短信队列
                //if (shareResult.SmsNotification) {
                //    if (RegexHelper.CheckMobile(shareResult.ShareUser.Mobile) && !shareResult.SmsIntro.IsNullOrEmpty()) {
                //        sql = @"INSERT INTO [dbo].[Basic_MessageQueue] ([TemplateCode],[Mobile],[Content] ,[Parameters] ,[Status],[Message] ,[Summary],[IpAdress],[RequestTime],[SendTime])
                //                VALUES (@TemplateCode,@Mobile,@Content ,@Parameters ,@Status,@Message ,@Summary,@IpAdress,@RequestTime,@SendTime)";
                //        parameters = new[]
                //        {
                //            repositoryContext.CreateParameter("@TemplateCode", 0),
                //            repositoryContext.CreateParameter("@Mobile", shareResult.ShareUser.Mobile),
                //            repositoryContext.CreateParameter("@Content", shareResult.SmsIntro),
                //            repositoryContext.CreateParameter("@Parameters",string.Empty),
                //            repositoryContext.CreateParameter("@Status", Convert.ToInt16(MessageStatus.Pending)),
                //            repositoryContext.CreateParameter("@Message", string.Empty),
                //            repositoryContext.CreateParameter("@Summary", string.Empty),
                //            repositoryContext.CreateParameter("@IpAdress", "127.0.0.3"),
                //            repositoryContext.CreateParameter("@RequestTime", DateTime.Now),
                //            repositoryContext.CreateParameter("@SendTime",DateTime.Now),
                //     };
                //        sqlList.Add(sql);
                //        dbParameterList.Add(parameters);
                //    }
                //}

                #endregion 添加的短信队列

                #region 团队等级自动更新模块

                //等级触发时,添加推荐等级,间接推荐等级,团队等级自动更新
                var taskQueue = new TaskQueue {
                    UserId   = gradeResult.Result.UserId,
                    ModuleId = TaskQueueModuleId.TeamUserGradeAutoUpdate, //团队等级自动更新模块
                    Type     = TaskQueueType.Once
                };
                sql =
                    "INSERT INTO [dbo].[Task_TaskQueue] ([UserId]  ,[Type],[ModuleId] ,[Parameter],[ExecutionTimes] ,[ExecutionTime],[CreateTime] ,[HandleTime] ,[MaxExecutionTimes],[Status] ,[Message]) " +
                    "VALUES (@UserId  ,@Type,@ModuleId ,@Parameter,@ExecutionTimes ,@ExecutionTime,@CreateTime ,@HandleTime ,@MaxExecutionTimes,@Status ,@Message)";
                parameters = new[]
                {
                    repositoryContext.CreateParameter("@UserId", taskQueue.UserId),
                    repositoryContext.CreateParameter("@Type", taskQueue.Type), // 升级只需执行一次
                    repositoryContext.CreateParameter("@ModuleId", taskQueue.ModuleId),
                    repositoryContext.CreateParameter("@Parameter", taskQueue.Parameter),
                    repositoryContext.CreateParameter("@ExecutionTimes", taskQueue.ExecutionTimes),
                    repositoryContext.CreateParameter("@ExecutionTime", taskQueue.ExecutionTime),
                    repositoryContext.CreateParameter("@CreateTime", taskQueue.CreateTime),
                    repositoryContext.CreateParameter("@HandleTime", taskQueue.HandleTime),
                    repositoryContext.CreateParameter("@MaxExecutionTimes", taskQueue.MaxExecutionTimes),
                    repositoryContext.CreateParameter("@Status", taskQueue.Status),
                    repositoryContext.CreateParameter("@Message", taskQueue.Message)
                };
                sqlList.Add(sql);
                dbParameterList.Add(parameters);

                #endregion 团队等级自动更新模块

                //清除用户缓存,不然会员查看不到等级的变化
                Ioc.Resolve <IUserService>().DeleteUserCache(gradeResult.Result.UserId, gradeResult.Result.UserName);

                // 添加升级记录
                UpgradeRecord upgradeRecord = new UpgradeRecord {
                    UserId        = gradeResult.Result.UserId,
                    BeforeGradeId = gradeResult.Result.OldGradeId,
                    AfterGradeId  = gradeResult.Result.GradeId,
                    Type          = UpgradeType.UpgradePoint,
                };
                Ioc.Resolve <IUpgradeRecordService>().Add(upgradeRecord);
            }

            if (sqlList.Count > 0)
            {
                try {
                    var excuteResult = repositoryContext.ExecuteBatch(sqlList, dbParameterList);
                } catch (Exception ex) {
                    Console.WriteLine(ex.Message);
                }
            }
        }
Exemplo n.º 4
0
        public void AfterPaySuccess(List <object> entityIdList)
        {
            var orderId = entityIdList.FirstOrDefault();
            var order   = Resolve <IOrderService>().GetSingle(r => r.Id == orderId.ConvertToLong(0));

            UserRightsOrderInput userRightsOrder;

            if (order != null)
            {
                userRightsOrder = order.OrderExtension.AttachContent.ToObject <UserRightsOrderInput>();
                if (userRightsOrder != null)
                {
                    var buyUser = Resolve <IUserService>().GetSingle(userRightsOrder.BuyUser?.Id);
                    if (buyUser != null)
                    {
                        var upgradeRecord = new UpgradeRecord {
                            AfterGradeId = userRightsOrder.GradeId,
                            UserId       = buyUser.Id,
                            Type         = UpgradeType.Buy
                        };
                        if (order.OrderExtension.User != null)
                        {
                            upgradeRecord.BeforeGradeId = order.OrderExtension.User.GradeId;
                        }

                        var beforeGrade = Resolve <IGradeService>().GetGrade(buyUser.GradeId);            // 当前等级
                        var afterGrade  = Resolve <IGradeService>().GetGrade(upgradeRecord.AfterGradeId); // 升级后等级
                        if (afterGrade.Id == afterGrade.Id)
                        {
                            //throw new ValidException("非法调用");
                            Resolve <IUserRightsService>()
                            .Log(
                                $"购买者:{userRightsOrder.BuyUser?.Id},order:{order.Id}=>{afterGrade.Id + "==" + afterGrade.Id}非法调用!");
                            return;
                        }

                        if (afterGrade.Contribute <= beforeGrade.Contribute)
                        {
                            Resolve <IUserRightsService>()
                            .Log(
                                $"购买者:{userRightsOrder.BuyUser?.Id},order:{order.Id}=>{afterGrade.Contribute + "<=" + beforeGrade.Contribute}非法调用!");
                            //throw new ValidException("非法调用");
                            return;
                        }

                        // 按要求所有开通, 既要花钱又扣端口 2019.04.02
                        if (true)
                        {
                            // 检查端口, 检查用户的名额
                            var userGrades = Resolve <IAutoConfigService>().GetList <UserGradeConfig>();
                            var userRight  = GetSingle(r =>
                                                       r.UserId == userRightsOrder.UserId && r.GradeId == userRightsOrder.GradeId);

                            if (userRight != null && userRight.TotalCount - userRight.TotalUseCount > 0 &&
                                userRightsOrder.BuyUser != null)
                            {
                                var kpi = new Kpi {
                                    ModuleId = userRightsOrder.GradeId,
                                    UserId   = userRightsOrder.UserId,
                                    Type     = TimeType.NoLimit,
                                    Value    = 1
                                };
                                var lastKpiSingle = Resolve <IKpiService>()
                                                    .GetSingle(r =>
                                                               r.ModuleId == userRightsOrder.GradeId && r.Type == TimeType.NoLimit);
                                if (lastKpiSingle != null)
                                {
                                    kpi.TotalValue = lastKpiSingle.TotalValue + kpi.Value;
                                }

                                // 新增Kpi记录,使用Kpi 记录表保存记录数据
                                Resolve <IKpiService>().Add(kpi);

                                // 使用数+1
                                userRight.TotalUseCount += 1;
                                Update(userRight);
                            }
                        }

                        Resolve <IUpgradeRecordService>().Add(upgradeRecord);
                        // 删除缓存
                        Resolve <IUserService>().DeleteUserCache(buyUser.Id, buyUser.UserName);
                        // 发送短信
                        SendMessage(buyUser, userRightsOrder.GradeId);
                    }
                }
            }
        }