Browse Source

预估成本,覆盖成本

pjzs_starttask_update
shanji 2 years ago
parent
commit
d22e634a90
  1. 19
      BBWY.Server.API/Controllers/OrderEstimateCostSyncController.cs
  2. 24
      BBWY.Server.Business/Order/OrderBusiness.cs
  3. 6
      BBWY.Server.Business/PurchaseOrder/PurchaseOrderBusiness.cs
  4. 40
      BBWY.Server.Business/Sync/OrderEstimateCostSyncBusiness.cs
  5. 6
      BBWY.Server.Business/Sync/OrderSyncBusiness.cs
  6. 2
      BBWY.Server.Model/Db/Order/OrderCost.cs
  7. 4
      BBWY.Server.Model/Db/Order/OrderCostDetail.cs

19
BBWY.Server.API/Controllers/OrderEstimateCostSyncController.cs

@ -33,5 +33,24 @@ namespace BBWY.Server.API.Controllers
{
orderEstimateCostSyncBusiness.SyncOrderSkuRecentCost(request);
}
/// <summary>
/// 为所有店铺没有成本的订单预估成本和毛利
/// </summary>
[HttpPost]
public void EstimateCostForAllShopNoCostOrder()
{
orderEstimateCostSyncBusiness.EstimateCostForAllShopNoCostOrder();
}
/// <summary>
/// 按指定条件预估成本和毛利
/// </summary>
/// <param name="request"></param>
[HttpPost]
public void EstimateCostForNoCostOrder([FromBody] SkuRecentCostRequest request)
{
orderEstimateCostSyncBusiness.EstimateCostForNoCostOrder(request);
}
}
}

24
BBWY.Server.Business/Order/OrderBusiness.cs

@ -509,7 +509,9 @@ namespace BBWY.Server.Business
var dbAfterSaleOrderList = fsql.Select<AfterSaleOrder>().Where(aso => aso.OrderId == autoCalculationCostRequest.OrderId).ToList();
var orderCost = fsql.Select<OrderCost>(autoCalculationCostRequest.OrderId).ToOne();
var orderCostDetails = fsql.Select<OrderCostDetail>().Where(ocd => ocd.OrderId == autoCalculationCostRequest.OrderId && ocd.IsEnabled == true).ToList();
var orderCostDetails = fsql.Select<OrderCostDetail>().Where(ocd => ocd.OrderId == autoCalculationCostRequest.OrderId &&
ocd.IsEnabled == true &&
ocd.IsEstimateCost == false).ToList();
IUpdate<Order> orderUpdate = null;
IUpdate<OrderCost> updateOrderCost = null;
@ -630,7 +632,8 @@ namespace BBWY.Server.Business
Profit = 0,
PurchaseAmount = orderCostPurchaseAmount,
DeliveryExpressFreight = orderDeliveryExpressFreight,
CreateTime = DateTime.Now
CreateTime = DateTime.Now,
IsEstimateCost = false
};
orderCost.CalculationOrderProfitAndCost(dbOrder, dbAfterSaleOrderList);
insertOrderCost = fsql.Insert(orderCost);
@ -638,6 +641,7 @@ namespace BBWY.Server.Business
}
else
{
orderCost.IsEstimateCost = false;
orderCost.PurchaseAmount += orderCostPurchaseAmount;
orderCost.DeliveryExpressFreight += orderDeliveryExpressFreight;
orderCost.CalculationOrderProfitAndCost(dbOrder, dbAfterSaleOrderList);
@ -654,6 +658,12 @@ namespace BBWY.Server.Business
foreach (var update in updatePurchaseOrderList)
update.ExecuteAffrows();
}
fsql.Update<OrderCostDetail>()
.Set(ocd => ocd.IsEnabled, false)
.Where(ocd => ocd.OrderId == autoCalculationCostRequest.OrderId &&
ocd.IsEnabled == true &&
ocd.IsEstimateCost == true)
.ExecuteAffrows();
if (insertOrderCostDetailList.Count > 0)
fsql.Insert(insertOrderCostDetailList).ExecuteAffrows();
});
@ -708,7 +718,7 @@ namespace BBWY.Server.Business
orderCostDetail.CreateTime = DateTime.Now;
orderCostDetail.OrderId = manualCalculationCostRequest.OrderId;
orderCostDetail.PurchaseOrderPKId = 0;
orderCostDetail.IsEstimateCost = false;
var osku = orderSkuList.FirstOrDefault(o => o.SkuId == orderCostDetail.SkuId);
if (osku != null)
{
@ -745,7 +755,8 @@ namespace BBWY.Server.Business
PurchaseAmount = totalPurchaseCost,
DeliveryExpressFreight = totalDeliveryExpressFreight,
CreateTime = DateTime.Now,
IsManualEdited = true
IsManualEdited = true,
IsEstimateCost = false
};
//orderCost.PlatformCommissionAmount = dbOrder.OrderSellerPrice * orderCost.PlatformCommissionRatio;
//orderCost.Profit = dbOrder.OrderSellerPrice +
@ -767,6 +778,7 @@ namespace BBWY.Server.Business
// orderCost.PlatformCommissionAmount;
orderCost.CalculationOrderProfitAndCost(dbOrder, dbAfterSaleOrderList);
orderCost.IsManualEdited = true;
orderCost.IsEstimateCost = false;
updateOrderCost = fsql.Update<OrderCost>().SetSource(orderCost);
}
@ -855,6 +867,7 @@ namespace BBWY.Server.Business
}
else
{
orderCost.IsEstimateCost = false;
orderCost.SDCommissionAmount = sdCalculationCostRequest.SDCommissionAmount;
orderCost.SDOrderAmount = sdCalculationCostRequest.SDOrderAmount;
orderCost.DeliveryExpressFreight = sdCalculationCostRequest.DeliveryExpressFreight;
@ -866,6 +879,7 @@ namespace BBWY.Server.Business
fsql.Transaction(() =>
{
fsql.Update<OrderCostDetail>().Set(ocd => ocd.IsEnabled, false).Where(ocd => ocd.OrderId == sdCalculationCostRequest.OrderId).ExecuteAffrows();
orderUpdate?.ExecuteAffrows();
updateOrderCost?.ExecuteAffrows();
insertOrderCost?.ExecuteAffrows();
@ -1014,6 +1028,8 @@ namespace BBWY.Server.Business
orderCost.PurchaseAmount -
orderCost.DeliveryExpressFreight -
orderCost.PlatformCommissionAmount;
orderCost.IsEstimateCost = false;
orderCost.IsManualEdited = true;
updateOrderCost = fsql.Update<OrderCost>().SetSource(orderCost).IgnoreColumns(oc => new
{
oc.CreateTime,

6
BBWY.Server.Business/PurchaseOrder/PurchaseOrderBusiness.cs

@ -286,6 +286,7 @@ namespace BBWY.Server.Business
SkuAmount = currentOrderSkuProductAmount,
SkuId = orderSku.SkuId,
StorageAmount = 0,
IsEstimateCost = false
//UnitCost = purchaseOrder.UnitCost,
//TotalCost = currentOrderSkuProductAmount + currentOrderSkuFreightAmount//purchaseOrder.UnitCost * orderSku.ItemTotal.Value
};
@ -317,7 +318,8 @@ namespace BBWY.Server.Business
PreferentialAmount = dbOrder.PreferentialAmount,
SDCommissionAmount = 0,
SDOrderAmount = 0,
PurchaseAmount = purchaseOrderSimpleInfo.TotalAmount
PurchaseAmount = purchaseOrderSimpleInfo.TotalAmount,
IsEstimateCost = false
};
//orderCost.PlatformCommissionAmount = dbOrder.OrderSellerPrice * orderCost.PlatformCommissionRatio;
//orderCost.Profit = dbOrder.OrderSellerPrice +
@ -675,7 +677,7 @@ namespace BBWY.Server.Business
#region 查询成本明细
currentProgress = "查询成本明细";
var orderCostDetailList = fsql.Select<OrderCostDetail>().Where(ocd => ocd.OrderId == orderDropshipping.OrderId).ToList();
var orderCostDetailList = fsql.Select<OrderCostDetail>().Where(ocd => ocd.OrderId == orderDropshipping.OrderId && ocd.IsEnabled == true).ToList();
if (orderCostDetailList == null || orderCostDetailList.Count() == 0)
throw new BusinessException("订单成本明细不存在");
#endregion

40
BBWY.Server.Business/Sync/OrderEstimateCostSyncBusiness.cs

@ -199,27 +199,9 @@ namespace BBWY.Server.Business
return;
var orderIdList = orderList.Select(o => o.Id).ToList();
List<OrderCostDetail> insertOrderCostDetailList = new List<OrderCostDetail>();
List<OrderCost> insertOrderCostList = new List<OrderCost>();
/*
decimal skuShouldPay,
decimal pingTaiChengDanYouHuiQuan,
decimal superRedEnvelope,
decimal xianPinLeiDongQuan,
decimal skuVenderFee,
decimal jingdou,
decimal dongquan,
decimal balance,
*/
/*
SkuAmount +
PurchaseFreight +
FirstFreight +
InStorageAmount +
OutStorageAmount +
StorageAmount +
ConsumableAmount
*/
var orderSkuAndRecentList = fsql.Select<OrderSku, SkuRecentCost>()
.LeftJoin((osku, src) => osku.SkuId == src.SkuId)
.Where((osku, src) => orderIdList.Contains(osku.SkuId) && osku.Price > 0)
@ -256,6 +238,7 @@ namespace BBWY.Server.Business
osku.SingleSkuAmount == 0))
continue; //预估成本和毛利,必须订单下的每一笔sku都具备最近成本
List<OrderCostDetail> currentOrderInsertOcdList = new List<OrderCostDetail>();
foreach (var osku in currentOrderSkuList)
{
var ocd = new OrderCostDetail()
@ -287,7 +270,24 @@ namespace BBWY.Server.Business
osku.DongQuan ?? 0M,
osku.Balance ?? 0M,
shop.PlatformCommissionRatio ?? 0.05M);
currentOrderInsertOcdList.Add(ocd);
}
var orderCost = new OrderCost()
{
OrderId = order.Id,
CreateTime = DateTime.Now,
AfterTotalCost = 0M,
DeliveryExpressFreight = currentOrderInsertOcdList.Sum(ocd => ocd.DeliveryExpressFreight),
IsEstimateCost = true,
IsManualEdited = false,
PlatformCommissionRatio = shop.PlatformCommissionRatio ?? 0.05M,
PurchaseAmount = currentOrderInsertOcdList.Sum(ocd => ocd.TotalCost),
PreferentialAmount = order.PreferentialAmount
};
orderCost.CalculationOrderProfitAndCost(order, null);
insertOrderCostDetailList.AddRange(currentOrderInsertOcdList);
insertOrderCostList.Add(orderCost);
}
}
catch (Exception ex)

6
BBWY.Server.Business/Sync/OrderSyncBusiness.cs

@ -887,7 +887,8 @@ namespace BBWY.Server.Business
PurchaseFreight = purchaseOrder.SingleFreight * deductionQuantity,
SkuAmount = purchaseOrder.SingleSkuAmount * deductionQuantity,
StorageAmount = purchaseOrder.SingleStorageAmount * deductionQuantity,
IsEnabled = true
IsEnabled = true,
IsEstimateCost = false
};
//orderCostDetail.SkuGrossProfit = itemPrice * deductionQuantity - avgPreferential -
@ -922,7 +923,8 @@ namespace BBWY.Server.Business
Profit = 0,
PurchaseAmount = orderCostPurchaseAmount,
DeliveryExpressFreight = orderDeliveryExpressFreight,
CreateTime = DateTime.Now
CreateTime = DateTime.Now,
IsEstimateCost = false
};
if (dbOrder.OrderTotalPrice != 0)
orderCost.CalculationOrderProfitAndCost(dbOrder, null);

2
BBWY.Server.Model/Db/Order/OrderCost.cs

@ -89,7 +89,7 @@ namespace BBWY.Server.Model.Db
/// 是否为预估成本
/// </summary>
[Column(DbType = "bit")]
public bool IsEstimateCost { get; set; }
public bool IsEstimateCost { get; set; } = false;
}
}

4
BBWY.Server.Model/Db/Order/OrderCostDetail.cs

@ -106,7 +106,7 @@ namespace BBWY.Server.Model.Db
public decimal SkuGrossProfit { get; set; } = 0.00M;
/// <summary>
/// 总计
/// 总计(不含发货运费)
/// </summary>
[Column(IsIgnore = true)]
public decimal TotalCost
@ -121,7 +121,7 @@ namespace BBWY.Server.Model.Db
/// 是否为预估成本
/// </summary>
[Column(DbType = "bit")]
public bool IsEstimateCost { get; set; }
public bool IsEstimateCost { get; set; } = false;
}
}

Loading…
Cancel
Save