From 039a451651010bac3191f4640e2ff326a7a17474 Mon Sep 17 00:00:00 2001 From: shanji <18996038927@163.com> Date: Tue, 4 Apr 2023 15:17:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AE=A2=E5=8D=95=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=20=E4=BB=93=E5=BA=93Id=E6=9B=B4=E6=94=B9=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=8C=E4=BF=AE=E5=A4=8D=E4=BA=AC=E4=BA=91=E4=BB=93?= =?UTF-8?q?=E8=B4=9F=E5=88=A9=E6=B6=A6=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Extensions/OrderCostExtension.cs | 19 +++++++++++ .../Sync/OrderSyncBusiness.cs | 33 +++++++++++-------- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/BBWY.Server.Business/Extensions/OrderCostExtension.cs b/BBWY.Server.Business/Extensions/OrderCostExtension.cs index c980374f..2111990c 100644 --- a/BBWY.Server.Business/Extensions/OrderCostExtension.cs +++ b/BBWY.Server.Business/Extensions/OrderCostExtension.cs @@ -25,6 +25,25 @@ namespace BBWY.Server.Business.Extensions orderCost.RefundPurchaseAmount; } + public static void CalculationOrderProfitAndCost(this OrderCost orderCost, decimal orderSellerPrice,decimal freightPrice, IList afterSaleOrders) + { + orderCost.AfterTotalCost = afterSaleOrders == null || afterSaleOrders.Count == 0 ? 0M : afterSaleOrders.Sum(aso => aso.AfterTotalCost); + orderCost.RefundAmount = afterSaleOrders == null || afterSaleOrders.Count == 0 ? 0M : afterSaleOrders.Sum(aso => aso.RefundAmount ?? 0M); + orderCost.RefundPurchaseAmount = afterSaleOrders == null || afterSaleOrders.Count == 0M ? 0M : afterSaleOrders.Sum(aso => aso.RefundPurchaseAmount ?? 0); + + //退款之后平台扣点 + orderCost.PlatformCommissionAmount = (orderSellerPrice - orderCost.RefundAmount) * (orderCost.PlatformCommissionRatio); + + orderCost.Profit = orderSellerPrice + freightPrice - orderCost.RefundAmount - + orderCost.PurchaseAmount - + orderCost.DeliveryExpressFreight - + orderCost.PlatformCommissionAmount - + orderCost.AfterTotalCost + + orderCost.RefundPurchaseAmount; + } + + + public static void CalculationSDOrderProfitAndCost(this OrderCost orderCost, Order order, IList afterSaleOrders) { orderCost.AfterTotalCost = afterSaleOrders == null || afterSaleOrders.Count == 0 ? 0M : afterSaleOrders.Sum(aso => aso.AfterTotalCost); diff --git a/BBWY.Server.Business/Sync/OrderSyncBusiness.cs b/BBWY.Server.Business/Sync/OrderSyncBusiness.cs index 87fac13c..4655069d 100644 --- a/BBWY.Server.Business/Sync/OrderSyncBusiness.cs +++ b/BBWY.Server.Business/Sync/OrderSyncBusiness.cs @@ -246,7 +246,9 @@ namespace BBWY.Server.Business SellerPreferentialAmount = o.SellerPreferentialAmount, OrderSellerPrice = o.OrderSellerPrice, OrderTotalPrice = o.OrderTotalPrice, - StoreOrder = o.StoreOrder + StoreOrder = o.StoreOrder, + PreferentialAmount = o.PreferentialAmount, + StoreId = o.StoreId }); //数据库订单 var dbOrderConsigneeList = fsql.Select().Where(oc => interfaceOrderIdList.Contains(oc.OrderId)).ToList(); //数据库订单收货信息 var dbOrderCostList = fsql.Select().Where(oc => interfaceOrderIdList.Contains(oc.OrderId)).ToList(); //数据库订单成本信息 @@ -294,7 +296,9 @@ namespace BBWY.Server.Business var orderSellerPrice = orderJToken.Value("orderSellerPrice"); var orderTotalPrice = orderJToken.Value("orderTotalPrice"); var storeOrder = orderJToken.Value("storeOrder") ?? string.Empty; + var storeId = orderJToken.Value("storeId"); var storageType = ConvertStoreOrder(storeOrder); + var preferentialAmount = 0M; if (dbOrder == null) { dbOrder = new Order() @@ -316,7 +320,7 @@ namespace BBWY.Server.Business //VenderId = orderJToken.Value("venderId"), WaybillNo = waybillNo, StoreOrder = storeOrder, - StoreId = orderJToken.Value("storeId"), + StoreId = storeId, IsGift = orderTotalPrice == 0M || orderSellerPrice == 0M, StorageType = storageType }; @@ -405,7 +409,8 @@ namespace BBWY.Server.Business var couponType = orderCouponJToken.Value("couponType"); if (string.IsNullOrEmpty(couponType)) continue; - dbOrder.PreferentialAmount += orderCouponJToken.Value("couponPrice"); + //dbOrder.PreferentialAmount += orderCouponJToken.Value("couponPrice"); + preferentialAmount += orderCouponJToken.Value("couponPrice"); insertOrderCouponList.Add(new OrderCoupon() { Id = idGenerator.NewLong(), @@ -555,19 +560,17 @@ namespace BBWY.Server.Business { OrderId = orderId, PlatformCommissionRatio = platformCommissionRatio, - PreferentialAmount = dbOrder.PreferentialAmount, + PreferentialAmount = preferentialAmount, Profit = 0, PurchaseAmount = orderCostPurchaseAmount, DeliveryExpressFreight = orderDeliveryExpressFreight, CreateTime = DateTime.Now }; - orderCost.CalculationOrderProfitAndCost(dbOrder, null); - //orderCost.PlatformCommissionAmount = dbOrder.OrderSellerPrice * orderCost.PlatformCommissionRatio; - //orderCost.Profit = dbOrder.OrderSellerPrice + - // dbOrder.FreightPrice - - // orderCost.PurchaseAmount - - // orderCost.DeliveryExpressFreight - - // orderCost.PlatformCommissionAmount; + if (dbOrder.OrderTotalPrice != 0) + orderCost.CalculationOrderProfitAndCost(dbOrder, null); + else + orderCost.CalculationOrderProfitAndCost(orderSellerPrice, freightPrice, null); + insertOrderCostList.Add(orderCost); #endregion } @@ -592,7 +595,9 @@ namespace BBWY.Server.Business sellerPreferentialAmount != dbOrder.SellerPreferentialAmount || orderSellerPrice != dbOrder.OrderSellerPrice || orderTotalPrice != dbOrder.OrderTotalPrice || - storeOrder != dbOrder.StoreOrder) + storeOrder != dbOrder.StoreOrder || + preferentialAmount != dbOrder.PreferentialAmount || + storeId != dbOrder.StoreId) { var updateSql = fsql.Update(orderId).SetIf(orderState != null && orderState != dbOrder.OrderState, o => o.OrderState, orderState) .SetIf(buyerRemark != dbOrder.BuyerRemark, o => o.BuyerRemark, buyerRemark) @@ -607,7 +612,9 @@ namespace BBWY.Server.Business .SetIf(orderTotalPrice != dbOrder.OrderTotalPrice, o => o.OrderTotalPrice, orderTotalPrice) .SetIf(orderTotalPrice != dbOrder.OrderTotalPrice && orderTotalPrice > 0M, o => o.IsGift, false) .SetIf(storeOrder != dbOrder.StoreOrder, o => o.StoreOrder, storeOrder) - .SetIf(storeOrder != dbOrder.StoreOrder, o => o.StorageType, storageType); + .SetIf(storeOrder != dbOrder.StoreOrder, o => o.StorageType, storageType) + .SetIf(preferentialAmount != dbOrder.PreferentialAmount, o => o.PreferentialAmount, preferentialAmount) + .SetIf(storeId != dbOrder.StoreId, o => o.StoreId, storeId); updateOrderList.Add(updateSql); } #endregion