Пример #1
0
        protected override RuleResult Execute(RuleParameter parameter)
        {
            var result = base.Execute(parameter);

            // 通过动态类型获取配置属性

            return(result);
        }
Пример #2
0
        /// <summary>
        /// 开始执行分润
        /// </summary>
        /// <param name="moduleType"></param>
        /// <param name="shareOrder"></param>
        public void ExecuteTask(Type moduleType, Trade shareOrder)
        {
            var ruleAttribute = moduleType.GetTypeInfo().GetAttribute <RuleAttribute>();

            if (ruleAttribute == null)
            {
                return;
            }

            //从数据库中获取所有分润模块
            var modules = Ioc.Resolve <IRewardRuleService>().GetEnableList(ruleAttribute.Id);

            if (!modules.Any())
            {
                return;
            }

            var  resultList = new List <RuleResultItem>();
            long count      = 0;

            foreach (var item in modules)
            {
                if (item.Limit.TriggerType != shareOrder.TriggerType)
                {
                    continue;
                }

                try {
                    RuleParameter ruleParameter = new RuleParameter {
                        RewardRule = item,
                        Trade      = shareOrder
                    };

                    var instance   = Activator.CreateInstance(moduleType);
                    var parameters = new[]
                    {
                        new Parameter("parameter", ruleParameter)
                    };
                    var target     = new Interpreter().SetVariable("entityService", instance);
                    var evalString = $"entityService.Execute(parameter)";
                    var result     = (RuleResult)target.Eval(evalString, parameters);

                    if (result.Succeeded)
                    {
                        count++;
                        resultList.AddRange(result.Result);
                    }
                    else
                    {
                        Ioc.Resolve <IShareService>().AddMessage(result?.Message, shareOrder, ruleAttribute, item);
                    }
                } catch (Exception ex) {
                    Ioc.Resolve <IShareService>().AddMessage(ex.Message, shareOrder, ruleAttribute, item);
                }
            }

            if (resultList.Count > 0)
            {
                var shareOrderNative = Ioc.Resolve <IShareService>().GetSingleNative(shareOrder.Id);
                if (shareOrderNative.Status == ShareOrderStatus.Pending)
                {
                    // 更新结果
                    Ioc.Resolve <IShareRepository>().UpdatePriceTaskResult(resultList);
                }

                // 更新次数
                Ioc.Resolve <IShareRepository>().UpdateExcuteCount(shareOrder.Id, count);
            }
        }
Пример #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));
        }
Пример #4
0
 /// <summary>
 /// 执行方法
 /// </summary>
 /// <param name="parameter"></param>
 /// <returns></returns>
 protected abstract RuleResult Execute(RuleParameter parameter);