Ejemplo n.º 1
0
        /// <summary>
        ///     获取当前会员等级是否满足条件
        /// </summary>
        /// <param name="gradeInfo"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        public Tuple <bool, Guid> GetKpiResult(GradeInfo gradeInfo, User user, IScope scope)
        {
            var rules = UpgradeRule.GetRules();
            var rule  = rules.FirstOrDefault(r => r.BeforeGradeId == user.GradeId);

            if (rule != null)
            {
                // 书生升级秀才
                if (rule.BaseGradeId == Guid.Empty)
                {
                    //  直推大于等于3个,团队15人
                    if (gradeInfo.RecomendCount >= rule.GradeCount && gradeInfo.TeamCount >= rule.TeamNumber)
                    {
                        return(Tuple.Create(true, rule.GradeId));
                    }
                }
                else if (gradeInfo.TeamCount >= rule.TeamNumber)
                {
                    // 满足团队数,在来执行市场人数
                    var count = GetKpiItemResult(gradeInfo, user, rule, scope);
                    if (count >= rule.GradeCount)
                    {
                        return(Tuple.Create(true, rule.GradeId));
                    }
                }
            }

            return(Tuple.Create(false, Guid.Empty));
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     最小项目的Kpi计算
        /// </summary>
        /// <param name="gradeInfo"></param>
        /// <returns></returns>
        public long GetKpiItemResult(GradeInfo gradeInfo, User user, UpgradeRule rule, IScope scope)
        {
            long result     = 0;
            var  childUsers = scope.Resolve <IUserService>().GetList(r => r.ParentId == user.Id);

            if (childUsers.Count < rule.GradeCount)
            {
                return(result);
            }

            foreach (var child in childUsers)
            {
                var map = scope.Resolve <IUserMapService>().GetSingle(r => r.UserId == child.Id);
                if (map != null)
                {
                    var parentMap = map.ParentMap.ToObject <List <ParentMap> >();
                    if (parentMap.Any())
                    {
                        var userIds = parentMap.Select(r => r.UserId).ToList();
                        var sql     =
                            $"select count(id) from User_User where GradeId='{rule.BaseGradeId}' and Id in({userIds.ToSqlString()})";
                        var sqlResult = scope.Resolve <IUserRepository>().RepositoryContext.ExecuteScalar(sql);
                        var count     = sqlResult.ConvertToLong();
                        if (count > 0)
                        {
                            result++;
                            if (result >= rule.GradeCount)
                            {
                                break;
                            }
                        }
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 获取所有的升级规则
        /// </summary>
        /// <returns></returns>
        public static List <UpgradeRule> GetRules()
        {
            var result = new List <UpgradeRule>();
            // 书生升级->秀才等级:直推3人,团队15人
            var ruleItem = new UpgradeRule {
                BeforeGradeId = Guid.Parse("72be65e6-3000-414d-972e-1a3d4a366000"),
                GradeId       = Guid.Parse("72be65e6-3000-414d-972e-1a3d4a366001"),
                BaseGradeId   = Guid.Empty,
                GradeCount    = 3,
                TeamNumber    = 15,
            };

            result.Add(ruleItem);

            // 举人等级:任意两个市场各1各秀才,团队30人
            ruleItem = new UpgradeRule {
                BeforeGradeId = Guid.Parse("72be65e6-3000-414d-972e-1a3d4a366001"),
                GradeId       = Guid.Parse("72be65e6-3000-414d-972e-1a3d4a366002"),
                BaseGradeId   = Guid.Parse("72be65e6-3000-414d-972e-1a3d4a366001"),
                GradeCount    = 2,
                TeamNumber    = 30,
            };
            result.Add(ruleItem);

            // 贡士等级:任意两个市场各1各/ 举人,团队90人
            ruleItem = new UpgradeRule {
                BeforeGradeId = Guid.Parse("72be65e6-3000-414d-972e-1a3d4a366002"),
                GradeId       = Guid.Parse("72be65e6-3000-414d-972e-1a3d4a366003"),
                BaseGradeId   = Guid.Parse("72be65e6-3000-414d-972e-1a3d4a366002"),
                GradeCount    = 2,
                TeamNumber    = 90,
            };
            result.Add(ruleItem);

            // 进士等级:任意两个市场各1各/贡士,团队270人
            ruleItem = new UpgradeRule {
                BeforeGradeId = Guid.Parse("72be65e6-3000-414d-972e-1a3d4a366003"),
                GradeId       = Guid.Parse("72be65e6-3000-414d-972e-1a3d4a366004"),
                BaseGradeId   = Guid.Parse("72be65e6-3000-414d-972e-1a3d4a366003"),
                GradeCount    = 2,
                TeamNumber    = 270,
            };
            result.Add(ruleItem);

            // 状元等级:任意两个市场各1各/进士,团队90人
            ruleItem = new UpgradeRule {
                BeforeGradeId = Guid.Parse("72be65e6-3000-414d-972e-1a3d4a366004"),
                GradeId       = Guid.Parse("72be65e6-3000-414d-972e-1a3d4a366005"),
                BaseGradeId   = Guid.Parse("72be65e6-3000-414d-972e-1a3d4a366004"),
                GradeCount    = 2,
                TeamNumber    = 820,
            };
            result.Add(ruleItem);

            // 大学士等级:任意两个市场各1各/大学士,团队2500人
            ruleItem = new UpgradeRule {
                BeforeGradeId = Guid.Parse("72be65e6-3000-414d-972e-1a3d4a366005"),
                GradeId       = Guid.Parse("72be65e6-3000-414d-972e-1a3d4a366006"),
                BaseGradeId   = Guid.Parse("72be65e6-3000-414d-972e-1a3d4a366005"),
                GradeCount    = 2, TeamNumber = 2500,
            };
            result.Add(ruleItem);

            return(result);
        }