Browse Source

空派重货优惠处理

lzk 1 week ago
parent
commit
9aee753cec
1 changed files with 37 additions and 6 deletions
  1. 37 6
      3.Service/XYY.Service.Standard.Order/FBA/FBAOrderService.cs

+ 37 - 6
3.Service/XYY.Service.Standard.Order/FBA/FBAOrderService.cs

@@ -174,7 +174,7 @@ namespace XYY.Service.Standard.Order.FBA
             {
                 List<int> orderIds = fbaOrders.Select(x => x.Id).Distinct().ToList();
                 IEnumerable<Order_MpsOrderBox> fbaBoxes = boxs.Where(x => orderIds.Contains(x.MpsOrderId));
-                FbaBillInfo(fbaOrders, fbaBoxes, remotZipCode);
+                await FbaBillInfo(fbaOrders, fbaBoxes, remotZipCode);
             }
             //处理国际快递数据
             IEnumerable<Order_MpsOrder> expressOrders = mpsOrder.Where(x => ExpressChannelCode.Contains(x.ChannelCode));
@@ -199,7 +199,7 @@ namespace XYY.Service.Standard.Order.FBA
         }
 
         #region 国际快递和空派的客户确认数据计算
-        private void FbaBillInfo(IEnumerable<Order_MpsOrder> orders, IEnumerable<Order_MpsOrderBox> boxes, List<string> remotZipCode)
+        private async Task FbaBillInfo(IEnumerable<Order_MpsOrder> orders, IEnumerable<Order_MpsOrderBox> boxes, List<string> remotZipCode)
         {
             foreach (var item in boxes)
             {
@@ -264,14 +264,45 @@ namespace XYY.Service.Standard.Order.FBA
                     item.Identification = true;
                     item.GoodsNames += ";偏远";
                 }
+                //实重/体积立方>200, >300 分别做  1:200标识-1,1:300标识-2
+                if (new List<string>() { "USKPLine", "USKPLine-J" }.Contains(item.ChannelCode))
+                {
+                    if (BillWeight / boxes.Sum(x => x.OpLength * x.OpWidth * x.OpHeight / 1000000) >= 300)
+                    {
+                        item.GoodsNames += ";-2/kg";
+                        await AddFbaHeavyCargoOtherFee(item.Id,item.CustomerConfirmBillWeight.Value*-2.0m);
+                    }
+                    else if (BillWeight / boxes.Sum(x => x.OpLength * x.OpWidth * x.OpHeight / 1000000) >= 200)
+                    {
+                        item.GoodsNames += ";-1/kg";
+                        await AddFbaHeavyCargoOtherFee(item.Id, item.CustomerConfirmBillWeight.Value * -1.0m);
+                    }
+                }
+                //实重/体积立方>300 做 1:300标识-1
+                if (new List<string>() { "USKPLine-5K", "USKPLine-J-5K" }.Contains(item.ChannelCode) && BillWeight / boxes.Sum(x => x.OpLength * x.OpWidth * x.OpHeight / 1000000) >= 300)
+                {
+                    item.GoodsNames += ";-1/kg";
+                    await AddFbaHeavyCargoOtherFee(item.Id, item.CustomerConfirmBillWeight.Value * -1.0m);
+                }
                 if (!string.IsNullOrEmpty(item.GoodsNames))
                 {
                     //处理多余的或重复的
-                    List<string> goodsName = item.GoodsNames.Split(";", StringSplitOptions.RemoveEmptyEntries).ToList();
+                    List<string> goodsName = item.GoodsNames.Split(";", StringSplitOptions.RemoveEmptyEntries).Distinct().ToList();
                     item.GoodsNames = string.Join(";", goodsName);
                 }
             }
         }
+        /// <summary>
+        /// 重货优惠 附加费添加
+        /// </summary>
+        /// <param name="otherFee"></param>
+        private async Task AddFbaHeavyCargoOtherFee(int OrderId, decimal otherFee)
+        {
+            string sql = $@"delete FBA_Incidental where OrderId={OrderId} and FBAOtherFeeId=(select SMPOtherFeeId from FBA_OtherFee(nolock) where Name='重货优惠' )
+insert into FBA_Incidental(OrderId,CalculateType,Target,Fee,FBAOtherFeeId,CustomerRemark,JSRemark,SysncJS)
+select {OrderId},0,0,{otherFee},SMPOtherFeeId,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)
         {
             foreach (var item in boxes)
@@ -872,7 +903,7 @@ where Id in @Ids", 600, new { Ids = Ids });
                         CustomerId = item.CustomerId,
                         OrderId = item.Id,
                         PublicExpressId = item.CreateOrderChannelId,
-                        TransactionTime =item.ForecastTime.HasValue?item.ForecastTime.Value:item.ReceiveTime,
+                        TransactionTime = item.ForecastTime.HasValue ? item.ForecastTime.Value : item.ReceiveTime,
                         ZipCode = item.ReceiverZipCode,
                         gWeight = (double)item.CustomerConfirmBillWeight,
                     });
@@ -1092,7 +1123,7 @@ where Id in @Ids", 600, new { Ids = Ids });
                         TransactionType = (int)TransactionType.Consume,
                         TransactionNo = "OF" + DateTime.Now.ToString("yyyyMMddHHmmssfff"),
                         ChargeName = tempIncidentals?.Name ?? "附加费",
-                        TransactionTime =confirm.ForecastTime.HasValue?confirm.ForecastTime.Value: confirm.ReceiveTime,
+                        TransactionTime = confirm.ForecastTime.HasValue ? confirm.ForecastTime.Value : confirm.ReceiveTime,
                         IncomeOrESxpense = "支出",
                         Currency = "CNY",
                         AmountinOriginalCurrency = item.Fee,
@@ -1139,7 +1170,7 @@ where Id in @Ids", 600, new { Ids = Ids });
                         volumeWeight = (double)confirm.OPVolumeWeight,
                         countFeeWeight = (double)confirm.CustomerConfirmBillWeight,//计费重
                         salesmanName = confirm.NickName,
-                        receiveTime = confirm.ForecastTime.HasValue ? confirm.ForecastTime.Value.ToString_yyyyMMddHHmmss() :  confirm.ReceiveTime.ToString_yyyyMMddHHmmss(),
+                        receiveTime = confirm.ForecastTime.HasValue ? confirm.ForecastTime.Value.ToString_yyyyMMddHHmmss() : confirm.ReceiveTime.ToString_yyyyMMddHHmmss(),
                         iossFlag = "false",
                         remark = string.Join(";", remarks),