步步为盈
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
6.7 KiB

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<AfterSaleOrder> 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;
//orderCost.Profit = order.OrderSellerPrice + order.FreightPrice - orderCost.RefundAmount -
// orderCost.PurchaseAmount -
// orderCost.DeliveryExpressFreight -
// orderCost.PlatformCommissionAmount -
// orderCost.AfterTotalCost +
// orderCost.RefundPurchaseAmount;
orderCost.Profit = (order.ActualProductAmount ?? 0M) -
orderCost.RefundAmount -
orderCost.PurchaseAmount -
orderCost.DeliveryExpressFreight -
orderCost.PlatformCommissionAmount -
orderCost.AfterTotalCost +
orderCost.RefundPurchaseAmount;
}
public static void CalculationOrderProfitAndCost(this OrderCost orderCost, decimal actualAmountProduct, IList<AfterSaleOrder> 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 = (actualAmountProduct - orderCost.RefundAmount) * orderCost.PlatformCommissionRatio;
//orderCost.Profit = orderSellerPrice + freightPrice - orderCost.RefundAmount -
// orderCost.PurchaseAmount -
// orderCost.DeliveryExpressFreight -
// orderCost.PlatformCommissionAmount -
// orderCost.AfterTotalCost +
// orderCost.RefundPurchaseAmount;
orderCost.Profit = actualAmountProduct -
orderCost.RefundAmount -
orderCost.PurchaseAmount -
orderCost.DeliveryExpressFreight -
orderCost.PlatformCommissionAmount -
orderCost.AfterTotalCost +
orderCost.RefundPurchaseAmount;
}
public static void CalculationSDOrderProfitAndCost(this OrderCost orderCost, Order order, IList<AfterSaleOrder> 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;
}
/// <summary>
/// 计算SKU毛利
/// </summary>
/// <param name="ocd"></param>
/// <param name="skuShouldPay"></param>
/// <param name="pingTaiChengDanYouHuiQuan"></param>
/// <param name="superRedEnvelope"></param>
/// <param name="xianPinLeiDongQuan"></param>
/// <param name="skuVenderFee"></param>
/// <param name="jingdou"></param>
/// <param name="dongquan"></param>
/// <param name="balance"></param>
/// <param name="platformCommissionRatio"></param>
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;
}
}
}