Exemplo n.º 1
0
        public RuleResult Execute(RuleParameter parameter)
        {
            var result = base.Execute(parameter);

            if (!result.Succeeded)
            {
                return(result);
            }

            var userMap = Resolve <IUserMapService>().GetParentMapFromCache(base.OrderUser.Id);
            var map     = userMap.ParentMap.DeserializeJson <List <ParentMap> >();

            if (map == null || map.Count == 0)
            {
                return(RuleResult.Failure("未找到触发会员的Parent Map."));
            }

            // 一级分润

            var shareUser   = GetShareUser(map[0].UserId);
            var shareAmount = Config.OneFixed;

            ToResult(shareAmount, shareUser, ref result);

            // 二级分润
            if (map.Count > 1)
            {
                shareUser   = GetShareUser(map[1].UserId);
                shareAmount = Config.TwoFixed;
                ToResult(shareAmount, shareUser, ref result);
            }

            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 检查分润订单用户的类型与等级
        /// </summary>

        private RuleResult CheckOrderUser(long orderUserId)
        {
            //判断交易用户
            this.OrderUser = Alabo.Helpers.Ioc.Resolve <IUserService>().GetSingle(orderUserId);
            if (this.OrderUser == null)
            {
                return(RuleResult.Failure($"DataDependencyRule.Execute 交易用户不存在"));
            }
            //检查分润订单用户类型
            if (Config.RewardRule.UserRang.OrderUser.IsLimitOrderUserType)
            {
                if (!Config.RewardRule.UserRang.OrderUser.OrderUserTypeId.IsGuidNullOrEmpty())
                {
                    if (Config.RewardRule.UserRang.OrderUser.OrderUserTypeId == Guid.Parse("71BE65E6-3A64-414D-972E-1A3D4A365000"))
                    {
                        //如果是会员,检查会员等级
                        if (Config.RewardRule.UserRang.OrderUser.IsLimitOrderUserGrade)
                        {
                            if (Config.RewardRule.UserRang.OrderUser.OrderUserGradeId != OrderUser.GradeId)
                            {
                                return(RuleResult.Failure($"DataDependencyRule.CheckOrderUserTypeAndGrade 用户等级不匹配,用户Id{OrderUser.Id}"));
                            }
                        }
                    }
                    else
                    {
                        ////检查用户类型
                        //var userType = Alabo.Helpers.Ioc.Resolve<IUserTypeService>().GetSingle(ShareOrderUser.Id, Config.OrderUser.OrderUserTypeId);
                        //if (userType == null) {
                        //    return return RuleResult.Failure(($"user with id {ShareOrder.UserId} has not  userType:{Config.OrderUser.OrderUserTypeId}, exit module"); //该会员不存在该类型的用户类型
                        //} else {
                        //    //检查用户类型等级
                        //    if (Config.OrderUser.IsLimitOrderUserGrade) {
                        //        if (Config.OrderUser.OrderUserGradeId != userType.GradeId) {
                        //            return return RuleResult.Failure(($"userType with UserId {ShareOrder.UserId} not match UserTypeGradeid:{Config.OrderUser.OrderUserTypeId}, exit module"); //会员等级不符合grade要求,直接退出
                        //        }
                        //    }
                        //}
                    }
                }
                else
                {
                    return(RuleResult.Failure($"OrderUserTypeId is null"));
                }
            }
            return(new RuleResult(true));;
        }
Exemplo n.º 3
0
        /// <summary>
        /// 基础数据校验
        /// </summary>
        /// <param name="parameter"></param>
        /// <returns></returns>
        protected override RuleResult Execute(RuleParameter parameter)
        {
            this.RewardRule = parameter.RewardRule;
            var ruleConfig = Resolve <IRuleModuleService>().GetConfigValue(this.RewardRule.ModuleId, this.RewardRule.Value);
            var config     = (dynamic)ruleConfig;

            config.RewardRule = this.RewardRule;
            this.Config       = (TConfiguration)config;
            if (Config == null)
            {
                return(RuleResult.Failure("DataDependencyRule.Config 维度规则配置为空"));
            }
            if (Config.RewardRule.Base == null)
            {
                return(RuleResult.Failure("DataDependencyRule.Config 维度规则基本配置RewardRule.Base为空"));
            }
            if (!Config.RewardRule.Base.IsEnable)
            {
                return(RuleResult.Failure("DataDependencyRule.Config 维度规则未启用RewardRule.Base.IsEnable"));
            }
            //进行参数判断
            if (parameter == null)
            {
                throw new ArgumentNullException(nameof(parameter));
            }

            this.ShareTrade = parameter.Trade;
            if (this.ShareTrade == null)
            {
                return(RuleResult.Failure("DataDependencyRule.Execute 分润中台订单为空"));
            }
            if (this.ShareTrade.Id <= 0)
            {
                return(RuleResult.Failure("DataDependencyRule.Execute 分润中台订单Id未找到"));
            }
            //判断通用交易订单
            var shareOrder = Alabo.Helpers.Ioc.Resolve <ITradeService>().GetSingle(r => r.Id == this.ShareTrade.Id);

            if (shareOrder == null)
            {
                return(RuleResult.Failure($"DataDependencyRule.Execute 分润订单为空,订单Id{this.ShareTrade.Id}"));
            }
            if (shareOrder.Status != ShareOrderStatus.Pending)
            {
                return(RuleResult.Failure($"DataDependencyRule.Execute 分润订单状态不是待处理状态,不触发分润."));
            }
            if (shareOrder.Amount <= 0)
            {
                return(RuleResult.Failure($"DataDependencyRule.Execute 分润订单金额小于0 "));
            }
            if (Config.RewardRule.Limit.PriceLimitType == PriceLimitType.OrderPrice)
            {
                if (shareOrder.Amount > Config.RewardRule.Limit.MaxAmount && Config.RewardRule.Limit.MaxAmount > 0)
                {
                    return(RuleResult.Failure($"DataDependencyRule.Execute 分润订单金额{ shareOrder.Amount} > 最大触发金额{ Config.RewardRule.Limit.MaxAmount}, 退出模块"));
                }
                if (shareOrder.Amount < Config.RewardRule.Limit.MinimumAmount && Config.RewardRule.Limit.MinimumAmount > 0)
                {
                    return(RuleResult.Failure($"DataDependencyRule.Execute 分润订单金额{ shareOrder.Amount} <= 最小触发金额{ Config.RewardRule.Limit.MinimumAmount}, 退出模块"));
                }
            }
            this.ShareTrade = shareOrder;

            this.BaseFenRunAmount = ShareTrade.Amount;
            if (this.BaseFenRunAmount < 0)
            {
                return(RuleResult.Failure($"DataDependencyRule.Execute 分润基数不能为0 "));
            }

            this.MoneyTypes = Resolve <IAutoConfigService>().GetList <MoneyTypeConfig>(r => r.Status == Status.Normal);
            return(CheckOrderUser(this.ShareTrade.UserId));
        }