|
@@ -35,6 +35,7 @@ using XYY.Service.Standard.Finance.Charging.Base;
|
|
|
using XYY.Service.Standard.Finance.Charging.CustomerOrderFee;
|
|
|
using XYY.Service.Standard.Finance.Charging.Dto;
|
|
|
using static System.TimeZoneInfo;
|
|
|
+using static XYY.Service.Standard.ChannelApi.HangLe.Api;
|
|
|
|
|
|
namespace XYY.Service.Standard.Order.FBA
|
|
|
{
|
|
@@ -160,11 +161,45 @@ namespace XYY.Service.Standard.Order.FBA
|
|
|
var datas = await orderRepository.CheackBoxIntegrity(Ids);
|
|
|
if (datas != null && datas.Count() > 0) { throw new Exception("以下单号存在未收货完成的箱子,请完成收货后重试!\r\n " + string.Join(",", datas)); }
|
|
|
#region 增加计费逻辑,和收件信息赋值
|
|
|
+ List<string> ExpressChannelCode = new List<string>() { "SZUPS_HD5000", "HKUPS红单5000", "HKUPS红单5000包税", "SZUPS_XH5000" };
|
|
|
//偏远邮编获取
|
|
|
List<string> remotZipCode = (await _unitOfWork.QueryBySqlAsync<string>("select * from Sys_FBARemotZipCode(nolock)")).ToList();
|
|
|
var mpsOrder = (await _unitOfWork.QueryBySqlAsync<Order_MpsOrder>("select * from order_mpsorder(nolock) where orderId in @Ids", null, new { Ids = Ids })).ToList(); //orderRepository.QueryAsync(x=> (x.OrderId??0).In(Ids));
|
|
|
var boxs = await GetReceivingBoxs(Ids);
|
|
|
- foreach (var item in boxs)
|
|
|
+ //处理正常空派的数据
|
|
|
+ IEnumerable<Order_MpsOrder> fbaOrders = mpsOrder.Where(x => !ExpressChannelCode.Contains(x.ChannelCode));
|
|
|
+ if (fbaOrders != null && fbaOrders.Count() > 0)
|
|
|
+ {
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ //处理国际快递数据
|
|
|
+ IEnumerable<Order_MpsOrder> expressOrders = mpsOrder.Where(x => ExpressChannelCode.Contains(x.ChannelCode));
|
|
|
+ if (expressOrders != null && expressOrders.Count() > 0)
|
|
|
+ {
|
|
|
+ List<int> orderIds = expressOrders.Select(x => x.Id).Distinct().ToList();
|
|
|
+ IEnumerable<Order_MpsOrderBox> expressBoxes = boxs.Where(x => orderIds.Contains(x.MpsOrderId));
|
|
|
+ ExpressBillInfo(expressOrders, expressBoxes, remotZipCode);
|
|
|
+ }
|
|
|
+
|
|
|
+ string sql = @" update Order_MpsOrderBox set BillLenght = @BillLenght,BillHeight=@BillHeight,BillWidth=@BillWidth,BillWeight=@BillWeight,BillVolumeWeight=@BillVolumeWeight,GoodsNames=@GoodsNames,Remark=@Remark,Identification=@Identification where Id = @Id ";
|
|
|
+ await _unitOfWork.ExecuteAsync(sql, boxs);
|
|
|
+ string orderSql = @" update Order_MpsOrder set GoodsNames=@GoodsNames,Identification=@Identification,CustomerConfirmBillWeight=@CustomerConfirmBillWeight where Id=@Id";
|
|
|
+ await _unitOfWork.ExecuteAsync(orderSql, mpsOrder);
|
|
|
+ //更新订单收货重量 OPWeight
|
|
|
+ string oPWeightSql = @" update Order_Order set OPWeight=@CustomerConfirmBillWeight where Id=@OrderId";
|
|
|
+ await _unitOfWork.ExecuteAsync(oPWeightSql, mpsOrder);
|
|
|
+ #endregion
|
|
|
+ await orderRepository.UpdateMpsOrdersStatus(Ids, (int)MpsOrderStatus.打单);
|
|
|
+ await orderRepository.UpdateOrderReceiveTime(mpsOrder.Select(x => x.Id));
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ #region 国际快递和空派的客户确认数据计算
|
|
|
+ private void FbaBillInfo(IEnumerable<Order_MpsOrder> orders, IEnumerable<Order_MpsOrderBox> boxes, List<string> remotZipCode)
|
|
|
+ {
|
|
|
+ foreach (var item in boxes)
|
|
|
{
|
|
|
item.BillLenght = item.OpLength;
|
|
|
item.BillHeight = item.OpHeight;
|
|
@@ -215,9 +250,9 @@ namespace XYY.Service.Standard.Order.FBA
|
|
|
}
|
|
|
}
|
|
|
//整票数据处理
|
|
|
- foreach (var item in mpsOrder)
|
|
|
+ foreach (var item in orders)
|
|
|
{
|
|
|
- var orderBoxs = boxs.Where(x => x.MpsOrderId == item.Id).ToList();
|
|
|
+ var orderBoxs = boxes.Where(x => x.MpsOrderId == item.Id).ToList();
|
|
|
//记录最大重量值
|
|
|
decimal BillVolumeWeight = orderBoxs.Sum(x => x.BillVolumeWeight); decimal BillWeight = orderBoxs.Sum(x => x.BillWeight);
|
|
|
if (BillVolumeWeight > BillWeight) { item.CustomerConfirmBillWeight = Math.Ceiling(BillVolumeWeight); } else { item.CustomerConfirmBillWeight = Math.Ceiling(BillWeight); }
|
|
@@ -226,23 +261,99 @@ namespace XYY.Service.Standard.Order.FBA
|
|
|
{
|
|
|
item.Identification = true;
|
|
|
item.GoodsNames += ";偏远";
|
|
|
+ }
|
|
|
+ if (!string.IsNullOrEmpty(item.GoodsNames))
|
|
|
+ {
|
|
|
//处理多余的或重复的
|
|
|
List<string> goodsName = item.GoodsNames.Split(";", StringSplitOptions.RemoveEmptyEntries).ToList();
|
|
|
item.GoodsNames = string.Join(";", goodsName);
|
|
|
}
|
|
|
}
|
|
|
- string sql = @" update Order_MpsOrderBox set BillLenght = @BillLenght,BillHeight=@BillHeight,BillWidth=@BillWidth,BillWeight=@BillWeight,BillVolumeWeight=@BillVolumeWeight,GoodsNames=@GoodsNames,Remark=@Remark,Identification=@Identification where Id = @Id ";
|
|
|
- await _unitOfWork.ExecuteAsync(sql, boxs);
|
|
|
- string orderSql = @" update Order_MpsOrder set GoodsNames=@GoodsNames,Identification=@Identification,CustomerConfirmBillWeight=@CustomerConfirmBillWeight where Id=@Id";
|
|
|
- await _unitOfWork.ExecuteAsync(orderSql, mpsOrder);
|
|
|
- //更新订单收货重量 OPWeight
|
|
|
- string oPWeightSql = @" update Order_Order set OPWeight=@CustomerConfirmBillWeight where Id=@OrderId";
|
|
|
- await _unitOfWork.ExecuteAsync(oPWeightSql, mpsOrder);
|
|
|
- #endregion
|
|
|
- await orderRepository.UpdateMpsOrdersStatus(Ids, (int)MpsOrderStatus.打单);
|
|
|
- await orderRepository.UpdateOrderReceiveTime(mpsOrder.Select(x => x.Id));
|
|
|
- return true;
|
|
|
}
|
|
|
+ private void ExpressBillInfo(IEnumerable<Order_MpsOrder> orders, IEnumerable<Order_MpsOrderBox> boxes, List<string> remotZipCode)
|
|
|
+ {
|
|
|
+ foreach (var item in boxes)
|
|
|
+ {
|
|
|
+ var tempOrder = orders.Where(x => x.Id == item.MpsOrderId).FirstOrDefault();
|
|
|
+
|
|
|
+ item.BillLenght = item.OpLength;
|
|
|
+ item.BillHeight = item.OpHeight;
|
|
|
+ item.BillWidth = item.OpWidth;
|
|
|
+ //先0.5进位
|
|
|
+ item.BillWeight = RoundUpToNearestHalf(Math.Round(item.OpInputWeight, 2));
|
|
|
+ item.BillVolumeWeight = RoundUpToNearestHalf(Math.Round(item.VolumeWeight, 2));
|
|
|
+
|
|
|
+ var tempWeight = item.BillVolumeWeight > item.BillWeight ? item.BillVolumeWeight : item.BillWeight;
|
|
|
+ //超重,超尺寸||超大超尺寸逻辑判断
|
|
|
+ List<decimal> boxLenght = new List<decimal>() { item.BillLenght, item.BillWidth, item.BillHeight };
|
|
|
+ decimal maxLenght = boxLenght.Max(); decimal secondLenght = boxLenght.OrderByDescending(x => x).Skip(1).Take(1).FirstOrDefault();
|
|
|
+ decimal thirdLenght = boxLenght.OrderBy(x => x).Take(1).FirstOrDefault();
|
|
|
+ //单件实重>22,最长边>120,第二长边>76,围长(最长边+2*宽+2*高)>266
|
|
|
+ decimal girth = maxLenght + 2 * secondLenght + 2 * thirdLenght;
|
|
|
+ if (tempOrder.ChannelCode != "SZUPS_XH5000")
|
|
|
+ {
|
|
|
+ //超大 & 超重限制:1、长大于269cm ;2、围长大于418CM;3、计费重大于等于70kg------满足任一条件时,提示超过UPS可收寄范围。
|
|
|
+ if (maxLenght > 269 || girth > 418 || tempWeight >= 70) { throw new Exception("超过UPS可收寄范围"); }
|
|
|
+ //大型包裹:1、围长【最长边 + 宽 * 2 + 高 * 2】大于等于300,小于400CM,-----满足条件时,除标记大型包裹之外, 单件计费不足40kg按照40kg计费;
|
|
|
+ else if (girth >= 300 && girth < 400) { item.GoodsNames += ";大型包裹"; if (item.BillWeight < 40) { item.BillWeight = 40; } if (item.BillVolumeWeight < 40) { item.BillVolumeWeight = 40; } }
|
|
|
+ //超尺寸:1、任何最长一边之长度超过121厘米;2、第二最长边的长度超过75厘米的包裹。
|
|
|
+ //超重:任何单件货物重量大于等于25公斤;
|
|
|
+ //超尺寸/超重 同时产生时,需要做2个标识
|
|
|
+ else if (maxLenght >= 121 || secondLenght >= 75 || tempWeight >= 25)
|
|
|
+ {
|
|
|
+ if (maxLenght >= 121 || secondLenght >= 75) { item.GoodsNames += ";超尺寸"; }
|
|
|
+ if (tempWeight >= 25) { item.GoodsNames += ";超重"; }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ else//SZUPS_XH5000
|
|
|
+ {
|
|
|
+ //单件 & 单票重量限制: 1、计费重量大于20kg时;2、围长【最长边 + 宽 * 2 + 高 * 2】大于等于300CM时----提示超过小货渠道可收寄范围;
|
|
|
+ if (tempWeight > 20 || girth >= 300) { throw new Exception("超过小货渠道可收寄范围"); }
|
|
|
+ //超尺寸:1、任何最长一边之长度超过121厘米;2、第二最长边的长度超过75厘米的包裹;
|
|
|
+ else if (maxLenght >= 121 || secondLenght >= 75) { item.GoodsNames += ";超尺寸"; }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ //整票数据处理
|
|
|
+ foreach (var item in orders)
|
|
|
+ {
|
|
|
+ var orderBoxs = boxes.Where(x => x.MpsOrderId == item.Id).ToList();
|
|
|
+ //记录最大重量值
|
|
|
+ decimal BillVolumeWeight = orderBoxs.Sum(x => x.BillVolumeWeight); decimal BillWeight = orderBoxs.Sum(x => x.BillWeight);
|
|
|
+ //国家快递,除了SZUPS_XH5000 ,另外的3个都有最小23kg限重
|
|
|
+ if (item.ChannelCode != "SZUPS_XH5000")
|
|
|
+ {
|
|
|
+ if (BillVolumeWeight > BillWeight) { item.CustomerConfirmBillWeight = Math.Ceiling(BillVolumeWeight); } else { item.CustomerConfirmBillWeight = Math.Ceiling(BillWeight); }
|
|
|
+ if (item.CustomerConfirmBillWeight < 23)
|
|
|
+ {
|
|
|
+ item.CustomerConfirmBillWeight = 23;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ else//SZUPS_XH5000
|
|
|
+ {
|
|
|
+ if (BillVolumeWeight > BillWeight) { item.CustomerConfirmBillWeight = BillVolumeWeight; } else { item.CustomerConfirmBillWeight = BillWeight; }
|
|
|
+ }
|
|
|
+ if (orderBoxs.Any(x => x.Identification)) { item.Identification = true; }
|
|
|
+ if (remotZipCode.Contains(item.ReceiverZipCode.Substring(0, 5)))
|
|
|
+ {
|
|
|
+ item.Identification = true;
|
|
|
+ item.GoodsNames += ";偏远";
|
|
|
+ }
|
|
|
+ if (!string.IsNullOrEmpty(item.GoodsNames))
|
|
|
+ {
|
|
|
+ //处理多余的或重复的
|
|
|
+ List<string> goodsName = item.GoodsNames.Split(";", StringSplitOptions.RemoveEmptyEntries).ToList();
|
|
|
+ item.GoodsNames = string.Join(";", goodsName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public decimal RoundUpToNearestHalf(decimal value)
|
|
|
+ {
|
|
|
+ return Math.Ceiling(value * 2) / 2.0m;
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
public async Task<string> GetBoxIDCR(Order_MpsOrderBox box)
|
|
|
{
|
|
|
box.CustomerGoodsNames = string.Empty;
|
|
@@ -1046,7 +1157,7 @@ where Id in @Ids", 600, new { Ids = Ids });
|
|
|
oriCurrencyCode = "CNY",
|
|
|
feeType = 0,//默认就是 0 原始数据
|
|
|
originalCurrencyCode = "CNY",
|
|
|
- exchangeRate=1,
|
|
|
+ exchangeRate = 1,
|
|
|
};
|
|
|
chargeInput.userMoneyFeeItemDetailList.Add(dto);
|
|
|
}
|
|
@@ -1722,7 +1833,7 @@ where Id in @Ids", 600, new { Ids = Ids });
|
|
|
}
|
|
|
public async Task<Order_MpsOrder> ConvretToMpsOrder(Order_Order dto, List<Order_OrderGoods> goods)
|
|
|
{
|
|
|
- string orderNumber = "FBA" +dto.SystemNo.Replace("XYYEX","");
|
|
|
+ string orderNumber = "FBA" + dto.SystemNo.Replace("XYYEX", "");
|
|
|
decimal weight = dto.OPWeight / 1000m;//空派单位是kg
|
|
|
Order_MpsOrder order = new Order_MpsOrder();
|
|
|
order.TransferNumber = dto.SystemNo;
|
|
@@ -1801,7 +1912,7 @@ where Id in @Ids", 600, new { Ids = Ids });
|
|
|
good.MpsBoxId = boxId;
|
|
|
}
|
|
|
await _unitOfWork.BulkToDBAsync(item.Boxs.FirstOrDefault().Goods);
|
|
|
- await _unitOfWork.UpdateByPrimaryKeyAsync<Order_Order>("MpsOrderId",mpsOrderId,item.OrderId.Value);
|
|
|
+ await _unitOfWork.UpdateByPrimaryKeyAsync<Order_Order>("MpsOrderId", mpsOrderId, item.OrderId.Value);
|
|
|
}
|
|
|
return true;
|
|
|
}
|