From d22e634a908697469662f737a2fc9cd39628fd0a Mon Sep 17 00:00:00 2001 From: shanj <18996038927@163.com> Date: Mon, 11 Dec 2023 10:45:44 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A2=84=E4=BC=B0=E6=88=90=E6=9C=AC=EF=BC=8C?= =?UTF-8?q?=E8=A6=86=E7=9B=96=E6=88=90=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OrderEstimateCostSyncController.cs | 19 +++++++++ BBWY.Server.Business/Order/OrderBusiness.cs | 24 +++++++++-- .../PurchaseOrder/PurchaseOrderBusiness.cs | 6 ++- .../Sync/OrderEstimateCostSyncBusiness.cs | 40 +++++++++---------- .../Sync/OrderSyncBusiness.cs | 6 ++- BBWY.Server.Model/Db/Order/OrderCost.cs | 2 +- BBWY.Server.Model/Db/Order/OrderCostDetail.cs | 4 +- 7 files changed, 70 insertions(+), 31 deletions(-) diff --git a/BBWY.Server.API/Controllers/OrderEstimateCostSyncController.cs b/BBWY.Server.API/Controllers/OrderEstimateCostSyncController.cs index b5ae7c71..1ffe7b34 100644 --- a/BBWY.Server.API/Controllers/OrderEstimateCostSyncController.cs +++ b/BBWY.Server.API/Controllers/OrderEstimateCostSyncController.cs @@ -33,5 +33,24 @@ namespace BBWY.Server.API.Controllers { orderEstimateCostSyncBusiness.SyncOrderSkuRecentCost(request); } + + /// + /// 为所有店铺没有成本的订单预估成本和毛利 + /// + [HttpPost] + public void EstimateCostForAllShopNoCostOrder() + { + orderEstimateCostSyncBusiness.EstimateCostForAllShopNoCostOrder(); + } + + /// + /// 按指定条件预估成本和毛利 + /// + /// + [HttpPost] + public void EstimateCostForNoCostOrder([FromBody] SkuRecentCostRequest request) + { + orderEstimateCostSyncBusiness.EstimateCostForNoCostOrder(request); + } } } diff --git a/BBWY.Server.Business/Order/OrderBusiness.cs b/BBWY.Server.Business/Order/OrderBusiness.cs index 3a55f086..f2e81181 100644 --- a/BBWY.Server.Business/Order/OrderBusiness.cs +++ b/BBWY.Server.Business/Order/OrderBusiness.cs @@ -509,7 +509,9 @@ namespace BBWY.Server.Business var dbAfterSaleOrderList = fsql.Select().Where(aso => aso.OrderId == autoCalculationCostRequest.OrderId).ToList(); var orderCost = fsql.Select(autoCalculationCostRequest.OrderId).ToOne(); - var orderCostDetails = fsql.Select().Where(ocd => ocd.OrderId == autoCalculationCostRequest.OrderId && ocd.IsEnabled == true).ToList(); + var orderCostDetails = fsql.Select().Where(ocd => ocd.OrderId == autoCalculationCostRequest.OrderId && + ocd.IsEnabled == true && + ocd.IsEstimateCost == false).ToList(); IUpdate orderUpdate = null; IUpdate 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() + .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().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().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().SetSource(orderCost).IgnoreColumns(oc => new { oc.CreateTime, diff --git a/BBWY.Server.Business/PurchaseOrder/PurchaseOrderBusiness.cs b/BBWY.Server.Business/PurchaseOrder/PurchaseOrderBusiness.cs index 344da0f2..4f6f7592 100644 --- a/BBWY.Server.Business/PurchaseOrder/PurchaseOrderBusiness.cs +++ b/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().Where(ocd => ocd.OrderId == orderDropshipping.OrderId).ToList(); + var orderCostDetailList = fsql.Select().Where(ocd => ocd.OrderId == orderDropshipping.OrderId && ocd.IsEnabled == true).ToList(); if (orderCostDetailList == null || orderCostDetailList.Count() == 0) throw new BusinessException("订单成本明细不存在"); #endregion diff --git a/BBWY.Server.Business/Sync/OrderEstimateCostSyncBusiness.cs b/BBWY.Server.Business/Sync/OrderEstimateCostSyncBusiness.cs index 28b12c52..74371585 100644 --- a/BBWY.Server.Business/Sync/OrderEstimateCostSyncBusiness.cs +++ b/BBWY.Server.Business/Sync/OrderEstimateCostSyncBusiness.cs @@ -199,27 +199,9 @@ namespace BBWY.Server.Business return; var orderIdList = orderList.Select(o => o.Id).ToList(); + List insertOrderCostDetailList = new List(); + List insertOrderCostList = new List(); - /* - 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() .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 currentOrderInsertOcdList = new List(); 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) diff --git a/BBWY.Server.Business/Sync/OrderSyncBusiness.cs b/BBWY.Server.Business/Sync/OrderSyncBusiness.cs index 75379381..6edcd567 100644 --- a/BBWY.Server.Business/Sync/OrderSyncBusiness.cs +++ b/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); diff --git a/BBWY.Server.Model/Db/Order/OrderCost.cs b/BBWY.Server.Model/Db/Order/OrderCost.cs index 46a0df8c..addd12ae 100644 --- a/BBWY.Server.Model/Db/Order/OrderCost.cs +++ b/BBWY.Server.Model/Db/Order/OrderCost.cs @@ -89,7 +89,7 @@ namespace BBWY.Server.Model.Db /// 是否为预估成本 /// [Column(DbType = "bit")] - public bool IsEstimateCost { get; set; } + public bool IsEstimateCost { get; set; } = false; } } diff --git a/BBWY.Server.Model/Db/Order/OrderCostDetail.cs b/BBWY.Server.Model/Db/Order/OrderCostDetail.cs index 9f9fd331..84f89adb 100644 --- a/BBWY.Server.Model/Db/Order/OrderCostDetail.cs +++ b/BBWY.Server.Model/Db/Order/OrderCostDetail.cs @@ -106,7 +106,7 @@ namespace BBWY.Server.Model.Db public decimal SkuGrossProfit { get; set; } = 0.00M; /// - /// 总计 + /// 总计(不含发货运费) /// [Column(IsIgnore = true)] public decimal TotalCost @@ -121,7 +121,7 @@ namespace BBWY.Server.Model.Db /// 是否为预估成本 /// [Column(DbType = "bit")] - public bool IsEstimateCost { get; set; } + public bool IsEstimateCost { get; set; } = false; } }