Exemplo n.º 1
0
        private SplitedOrder SplitOrder(string orderId, List <ProductEntity> productList, List <Product> badProductList, int totalQuantity, SplitPrinciple splitPrinciple)
        {
            Debug.Assert(splitPrinciple != SplitPrinciple.LogisticsFirst);
            var result = new SplitedOrder();
            List <List <RuleEntity> > ruleOptions = null;

            switch (splitPrinciple)
            {
            case SplitPrinciple.SpeedFirst:
                break;

            case SplitPrinciple.QuanlityFirst:
            case SplitPrinciple.PriceFirst:
            default:
                ruleOptions = splitConfig.GetRuleEntities(splitPrinciple, productList);
                break;
            }
            if (ruleOptions != null && ruleOptions.Count > 0)
            {
                var splitResults = ruleOptions.Select(rules => SplitOnce(SplitPackage.SplitV1.Common.Common.CloneProductEntityList(productList), rules, splitPrinciple)).ToList();
                Tuple <SplitedOrder, bool, List <ProductEntity> > optimal = null;
                switch (splitPrinciple)
                {
                case SplitPrinciple.QuanlityFirst:
                    optimal = splitResults.OrderBy(t => t.Item2 ? 0 : 1)
                              .ThenBy(t => t.Item1.OrderList.Count)
                              .ThenBy(t => t.Item1.CalculateLogisticsAndTaxCost())
                              .FirstOrDefault();
                    break;

                case SplitPrinciple.PriceFirst:
                case SplitPrinciple.LogisticsFirst:
                default:
                    optimal = splitResults.OrderBy(t => t.Item2 ? 0 : 1)
                              .ThenBy(t => t.Item1.CalculateLogisticsAndTaxCost())
                              .ThenBy(t => t.Item1.OrderList.Count)
                              .FirstOrDefault();
                    break;
                }
                result = optimal != null ? optimal.Item1 : result;
            }
            else
            {
                // BC方式,计算跨境综合税
                result = this.ReturnRemainPackage(productList);
            }
            if (badProductList != null && badProductList.Any())
            {
                var subOrder = new SubOrder("-2", null, null, null, null, null, badProductList)
                {
                    LogisticsUnitPrice = int.MaxValue,
                    LogisticsCost      = int.MaxValue,
                    TaxCost            = int.MaxValue,
                };
                result.AddSubOrder(subOrder);
            }
            result.OrderId = orderId;
            return(result);
        }
Exemplo n.º 2
0
        private Tuple <SplitedOrder, List <ProductEntity> > SplitOrderWithOrganization(string orderId, List <ProductEntity> productList, int totalQuantity, List <RuleEntity> ruleList)
        {
            // 指定物流时,此处传入的RuleEntity清单仅为该物流规则
            Debug.Assert(ruleList != null);
            var ruleOptions     = SplitConfig.GetRuleEntities(ruleList, productList);
            var splitResults    = ruleOptions.Select(rules => SplitOnce(SplitPackage.SplitV1.Common.Common.CloneProductEntityList(productList), rules, SplitPrinciple.LogisticsFirst)).ToList();
            var optimal         = splitResults.OrderBy(t => t.Item2 ? 0 : 1).ThenBy(t => t.Item1.CalculateLogisticsAndTaxCost()).FirstOrDefault();
            var result          = optimal != null ? optimal.Item1 : new SplitedOrder();
            var restProductList = optimal != null ? optimal.Item3 : productList;

            result.OrderId = orderId;
            return(Tuple.Create(result, restProductList));
        }