Browse Source

重货优惠调整

lzk 4 days ago
parent
commit
51e23e8e48

+ 2 - 1
2.Data/XYY.Data.Strandard/Order/FBAOrderRepository.cs

@@ -327,8 +327,9 @@ where Target=({(int)target}) and OrderId = {OrderId}";
         public async Task<bool> SaveFBA_Incidentals(List<FBA_Incidental> fBA_Incidentals, int OrderId, bool isSettlement = false)
         {
             //每次只能先删除后新增
-            string sql = $"delete FBA_Incidental where OrderId={OrderId}";
+            string sql = $"delete FBA_Incidental where OrderId={OrderId} ";
             if (isSettlement) { sql += " and Target=1 "; }//结算只删除结算的部分,收入将删除所有
+            else { sql+= $" and Id not in (select Id from FBA_Incidental(nolock) where OrderId={OrderId} and FBAOtherFeeId=28 and Target=1 )"; }
             await _unitOfWork.ExecuteAsync(sql);
             await _unitOfWork.BulkToDBAsync(fBA_Incidentals);
             return true;

+ 21 - 4
3.Service/XYY.Service.Standard.Order/FBA/FBAOrderService.cs

@@ -270,7 +270,7 @@ namespace XYY.Service.Standard.Order.FBA
                     if (BillWeight / boxes.Sum(x => x.OpLength * x.OpWidth * x.OpHeight / 1000000) >= 300)
                     {
                         item.GoodsNames += ";-2/kg";
-                        await AddFbaHeavyCargoOtherFee(item.OrderId.Value,item.CustomerConfirmBillWeight.Value*-2.0m);
+                        await AddFbaHeavyCargoOtherFee(item.OrderId.Value, item.CustomerConfirmBillWeight.Value * -2.0m);
                     }
                     else if (BillWeight / boxes.Sum(x => x.OpLength * x.OpWidth * x.OpHeight / 1000000) >= 200)
                     {
@@ -298,9 +298,10 @@ namespace XYY.Service.Standard.Order.FBA
         /// <param name="otherFee"></param>
         private async Task AddFbaHeavyCargoOtherFee(int OrderId, decimal otherFee)
         {
-            string sql = $@"delete FBA_Incidental where OrderId={OrderId} and FBAOtherFeeId=(select Id from FBA_OtherFee(nolock) where Name='重货优惠' )
+            //只处理结算
+            string sql = $@"delete FBA_Incidental where OrderId={OrderId} and FBAOtherFeeId=(select Id from FBA_OtherFee(nolock) where Name='重货优惠' ) and Target=1
 insert into FBA_Incidental(OrderId,CalculateType,Target,Fee,FBAOtherFeeId,CustomerRemark,JSRemark,SysncJS)
-select {OrderId},0,0,{otherFee},Id,CustomerRemark,JSRemark,SysncJS from FBA_OtherFee(nolock) where Name='重货优惠' ";
+select {OrderId},0,1,{otherFee},Id,CustomerRemark,JSRemark,SysncJS from FBA_OtherFee(nolock) where Name='重货优惠' ";
             await _unitOfWork.ExecuteAsync(sql);
         }
         private void ExpressBillInfo(IEnumerable<Order_MpsOrder> orders, IEnumerable<Order_MpsOrderBox> boxes, List<string> remotZipCode)
@@ -502,6 +503,11 @@ select {OrderId},0,0,{otherFee},Id,CustomerRemark,JSRemark,SysncJS from FBA_Othe
             if (incidentals != null && incidentals.Count() > 0)
             {
                 incidentals.RemoveAll(x => x.FBAOtherFeeId == null);
+                if (incidentals.Any(x => x.FBAOtherFeeId == 28))
+                {
+                    //重货优惠,特殊处理,不做同步
+                    incidentals.ForEach(x => { if (x.FBAOtherFeeId == 28) { x.SysncJS = false; } });
+                }
                 var tempData = incidentals.Where(x => (x.SysncJS ?? false)).ToList().CopyList<FBA_Incidental>();
                 foreach (var x in tempData) { x.Target = FBAIncidentalCalculateTarget.结算价; }
                 if (tempData != null && tempData.Count > 0) { incidentals.AddRange(tempData); }
@@ -893,9 +899,11 @@ where Id in @Ids", 600, new { Ids = Ids });
             }
             if (!smpSuccess) { throw new Exception(errorMsg); }
             #endregion
+            #region 逐单检测
             string exMessage = string.Empty;
             foreach (var item in confirms)
             {
+                #region 计费重异常
                 try
                 {
                     await orderRepository.GetUnitPrice(new KPUnitPriceRequest()
@@ -913,9 +921,18 @@ where Id in @Ids", 600, new { Ids = Ids });
                     if (ex.Message.Contains("计费重异常")) { exMessage += $"{item.SystemNo},计费重异常!"; }
                     //忽略其他的异常
                 }
-
+                #endregion
+                #region 附加费检测
+                if (item.GoodsNames.Contains("/kg"))
+                {
+                    var incidentals = await orderRepository.GetFBA_Incidentals(item.Id, FBAIncidentalCalculateTarget.客户);
+                    if (incidentals.Where(x=>x.SysncJS==true).Count() > 2) { exMessage += $"重货附加费同步条目不能超过两条!"; }
+                }
+                #endregion
             }
             if (!string.IsNullOrEmpty(exMessage)) { throw new Exception(exMessage); }
+            #endregion
+
             return true;
         }
         #region smp计费逻辑处理