using BBWY.Server.Model.Db; using System.Collections.Generic; using System.Linq; namespace BBWY.Server.Business.Extensions { public static class OrderCostExtension { public static void CalculationOrderProfitAndCost(this OrderCost orderCost, Order order, 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 = (order.OrderPayment - order.FreightPrice - orderCost.RefundAmount) * (orderCost.PlatformCommissionRatio); //orderCost.PlatformCommissionAmount = (order.OrderSellerPrice + (order.PingTaiChengDanYouHuiQuan ?? 0M) - orderCost.RefundAmount) * orderCost.PlatformCommissionRatio; orderCost.PlatformCommissionAmount = ((order.ActualProductAmount ?? 0M) - orderCost.RefundAmount) * orderCost.PlatformCommissionRatio; var actualAmount = order.OrderSellerPrice + order.FreightPrice + (order.PingTaiChengDanYouHuiQuan ?? 0M); //orderCost.Profit = order.OrderSellerPrice + order.FreightPrice - orderCost.RefundAmount - // orderCost.PurchaseAmount - // orderCost.DeliveryExpressFreight - // orderCost.PlatformCommissionAmount - // orderCost.AfterTotalCost + // orderCost.RefundPurchaseAmount; orderCost.Profit = actualAmount - orderCost.RefundAmount - orderCost.PurchaseAmount - orderCost.DeliveryExpressFreight - orderCost.PlatformCommissionAmount - orderCost.AfterTotalCost + orderCost.RefundPurchaseAmount; } public static void CalculationOrderProfitAndCost(this OrderCost orderCost, decimal actualAmount, 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 = (orderPayment - freightPrice - orderCost.RefundAmount) * (orderCost.PlatformCommissionRatio); orderCost.PlatformCommissionAmount = (actualAmount - orderCost.RefundAmount) * orderCost.PlatformCommissionRatio; //orderCost.Profit = orderSellerPrice + freightPrice - orderCost.RefundAmount - // orderCost.PurchaseAmount - // orderCost.DeliveryExpressFreight - // orderCost.PlatformCommissionAmount - // orderCost.AfterTotalCost + // orderCost.RefundPurchaseAmount; orderCost.Profit = actualAmount - 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); 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 = (order.OrderSellerPrice - orderCost.RefundAmount) * (orderCost.PlatformCommissionRatio); orderCost.Profit = (orderCost.SDCommissionAmount + orderCost.SDOrderAmount + orderCost.DeliveryExpressFreight + orderCost.PlatformCommissionAmount + orderCost.AfterTotalCost) * -1; } /// /// 计算SKU毛利 /// /// /// /// /// /// /// /// /// /// /// public static void CalculationSkuGrossProfit(this OrderCostDetail ocd, decimal skuShouldPay, decimal pingTaiChengDanYouHuiQuan, decimal superRedEnvelope, decimal xianPinLeiDongQuan, decimal skuVenderFee, decimal jingdou, decimal dongquan, decimal balance, decimal platformCommissionRatio) { var pingTaiBuTie = pingTaiChengDanYouHuiQuan + superRedEnvelope + xianPinLeiDongQuan + jingdou + dongquan; var koudian = (skuShouldPay + pingTaiBuTie - skuVenderFee) * ocd.DeductionQuantity * platformCommissionRatio; ocd.SkuGrossProfit = (skuShouldPay + pingTaiBuTie + balance) * ocd.DeductionQuantity - ocd.TotalCost - ocd.DeliveryExpressFreight - koudian; } } }