/// <summary> /// 根据给予的组合规则进行拆单操作 /// </summary> /// <param name="productList">订单商品明细</param> /// <param name="rules">按层面整合的符合规则</param> /// <param name="withTax">是否收税</param> /// <returns>可拆解的订单,未能拆解的订单</returns> private Tuple <SplitedOrder, List <ProductEntity> > Split(List <ProductEntity> productList, List <List <IProductRuleEntity> > rules, bool withTax) { var result = new SplitedOrder(); var restProductList = productList; for (int i = 0; i < rules.Count && restProductList.Count > 0; i++) { var l = rules[i]; for (int j = 0; j < l.Count && restProductList.Count > 0; j++) { var r = l[j]; while (restProductList.Count > 0) { var so = r.Split(restProductList, withTax); result.AddSubOrderRange(so.Item1); if (so.Item1.OrderList.Count == 0 || so.Item2.Count <= 0) { // 拆不出来,此规则不适用 || 全拆完了 break; } restProductList = so.Item2; } } } result.OrderList.ForEach(o => o.LogisticsCost = this.CalculateFreight(o.CalculateTotalWeight())); return(Tuple.Create(result, restProductList)); }
private Tuple <SplitedOrder, bool, List <ProductEntity> > SplitOnce(List <ProductEntity> productList, List <RuleEntity> rules, SplitPrinciple splitPrinciple) { var splitedOrder = new SplitedOrder(); var restProductList = productList; for (int i = 0; i < rules.Count && restProductList.Count > 0; i++) { var tuple = rules[i].Split(restProductList, splitPrinciple, false); splitedOrder.AddSubOrderRange(tuple.Item1); restProductList = tuple.Item2; } bool isTax = false; if (splitPrinciple != SplitPrinciple.LogisticsFirst && restProductList.Count > 0) { // 没拆完,按含税方式拆一遍 //for (int i = 0; i < rules.Count && restProductList.Count > 0; i++) //{ // var tuple = rules[i].Split(restProductList, splitPrinciple, true); // isTax |= tuple.Item1.OrderList.Count > 0; // splitedOrder.AddSubOrderRange(tuple.Item1); // restProductList = tuple.Item2; //} //if (restProductList.Count > 0) { // 还有剩余就按BC拆 isTax = true; //var subOrder = new SubOrder("-1", null, null, null, null, restProductList.SelectMany(pe => pe.OrderInfo).ToList()) //{ // LogisticsUnitPrice = decimal.MaxValue, // LogisticsCost = decimal.MaxValue, // TaxCost = decimal.MaxValue, //}; //splitedOrder.AddSubOrder(subOrder); splitedOrder.AddSubOrderRange(bcRuleEntity.Split(restProductList)); restProductList.Clear(); } } return(Tuple.Create(splitedOrder, isTax, restProductList)); }
private Tuple <SplitedOrder, bool, List <ProductEntity> > SplitOnce(List <ProductEntity> productList, List <RuleEntity> rules, SplitPrinciple splitPrinciple) { var splitedOrder = new SplitedOrder(); var restProductList = productList; for (int i = 0; i < rules.Count && restProductList.Count > 0; i++) { var tuple = rules[i].Split(restProductList, splitPrinciple, false); splitedOrder.AddSubOrderRange(tuple.Item1); restProductList = tuple.Item2; } bool isTax = false; if (splitPrinciple != SplitPrinciple.LogisticsFirst && restProductList.Count > 0) { isTax = true; splitedOrder.AddSubOrderRange(this.ReturnRemainPackage(restProductList)); restProductList.Clear(); } return(Tuple.Create(splitedOrder, isTax, restProductList)); }
private Tuple <SplitedOrder, List <ProductEntity> > SplitOnceWithOrganization(List <ProductEntity> productList, List <RuleEntity> rules, SplitPrinciple splitPrinciple) { var splitedOrder = new SplitedOrder(); var restProductList = productList; for (int i = 0; i < rules.Count && restProductList.Count > 0; i++) { var tuple = rules[i].Split(restProductList, splitPrinciple, false); splitedOrder.AddSubOrderRange(tuple.Item1); restProductList = tuple.Item2; } return(Tuple.Create(splitedOrder, restProductList)); }