diff --git a/Myshipping.Application/Service/ExpressDelivery/Dto/SFSendBooking.cs b/Myshipping.Application/Service/ExpressDelivery/Dto/SFSendBooking.cs
index 325a0047..e6734b40 100644
--- a/Myshipping.Application/Service/ExpressDelivery/Dto/SFSendBooking.cs
+++ b/Myshipping.Application/Service/ExpressDelivery/Dto/SFSendBooking.cs
@@ -18,6 +18,11 @@ namespace Myshipping.Application.Service.ExpressDelivery.Dto
/// 客户订单号,重复使用订单号时返回第一次下单成功时的运单信息
///
public string orderId { get; set; }
+
+ ///
+ /// 顺丰月结卡号 月结支付时传值,现结不需传值;
+ ///
+ public string monthlyCard { get; set; }
}
public class CargoDetailsItem
{
diff --git a/Myshipping.Application/Service/ExpressDelivery/ExpressDeliveryService.cs b/Myshipping.Application/Service/ExpressDelivery/ExpressDeliveryService.cs
index 528064f6..a543f51d 100644
--- a/Myshipping.Application/Service/ExpressDelivery/ExpressDeliveryService.cs
+++ b/Myshipping.Application/Service/ExpressDelivery/ExpressDeliveryService.cs
@@ -95,6 +95,28 @@ namespace Myshipping.Application
}
return list;
}
+
+
+ ///
+ /// 获取详情
+ ///
+ ///
+ ///
+ [HttpPost("Get")]
+ public async Task Get(long Id)
+ {
+ ExpressDeliveryDto ordOut = new ExpressDeliveryDto();
+ var main = await _orderRep.FirstOrDefaultAsync(u => u.Id == Id);
+ if (main != null)
+ {
+ ordOut = main.Adapt();
+ var business = await _businessRep.AsQueryable().Where(x => x.PId == Id).ToListAsync();
+ ordOut.Business = business;
+ }
+ return ordOut;
+ }
+
+
///
/// 保存并返回数据
///
@@ -110,8 +132,8 @@ namespace Myshipping.Application
if (input.Id == 0)
{
- entity.CurrentStateCode = "DJY01";
- entity.CurrentStateDesc = "新建";
+ entity.CurrentStateCode = "DJY02";
+ entity.CurrentStateDesc = "已保存";
_logger.LogInformation($"快递订单新增操作开始,{logGuid}");
@@ -143,6 +165,11 @@ namespace Myshipping.Application
}
else
{
+ var oldOrder = _orderRep.FirstOrDefault(x => x.Id == input.Id);
+ if (oldOrder.CurrentStateCode != "DJY02")
+ {
+ throw Oops.Bah("修改失败,原因:下单过的快递单无法修改信息");
+ }
_logger.LogInformation($"快递订单修改操作开始,{logGuid}");
await _orderRep.AsUpdateable(entity).IgnoreColumns(it => new
{
@@ -229,7 +256,7 @@ namespace Myshipping.Application
{
OrderId = Id,
MailNo = order.KDNO,
- StatusCode = "DJY04",
+ StatusCode = "DJY05",
StatusDesc = "快递单已删除"
};
await _statusRep.InsertAsync(status);
@@ -257,25 +284,6 @@ namespace Myshipping.Application
}
}
- ///
- /// 获取详情
- ///
- ///
- ///
- [HttpPost("Get")]
- public async Task Get(long Id)
- {
- ExpressDeliveryDto ordOut = new ExpressDeliveryDto();
- var main = await _orderRep.FirstOrDefaultAsync(u => u.Id == Id);
- if (main != null)
- {
- ordOut = main.Adapt();
- var business = await _businessRep.AsQueryable().Where(x => x.PId == Id).ToListAsync();
- ordOut.Business = business;
- }
- return ordOut;
- }
-
///
/// 发送快递
///
@@ -285,50 +293,61 @@ namespace Myshipping.Application
public async Task SendBooking(long Id)
{
var rt = String.Empty;
- SFSendBooking sFSend = new SFSendBooking();
var order = _orderRep.FirstOrDefault(x => x.Id == Id);
if (order == null)
{
throw Oops.Bah("请选择正确数据!");
}
-
-
- sFSend.orderId = Id.ToString();
- sFSend.language = "zh_CN";
-
- List cargo = new List();
- cargo.Add(new CargoDetailsItem
+ if (order.CurrentStateCode == "DJY01")
{
- count = (int)order.KDNum,
- name = order.GOODSNAME
-
- });
-
- List contactList = new List();
-
- contactList.Add(new ContactInfoListItem
+ throw Oops.Bah("下单失败,原因:尚未保存");
+ }
+ if (order.CurrentStateCode != "DJY02")
{
-
- address = $"{order.FJProvince}{order.FJCity}{order.FJAddress}",
- contact = order.FJPeople,
- contactType = 1,
- country = "CN",
- //postCode = order.FJPostCode,
- tel = order.FJTel,
- });
-
- contactList.Add(new ContactInfoListItem
+ throw Oops.Bah("下单失败,原因:重复下单");
+ }
+ SFSendBooking sFSend = new SFSendBooking()
{
+ orderId = Id.ToString(),
+ language = "zh_CN",
+ cargoDetails = new List()
+ {
+ new CargoDetailsItem()
+ {
+ count = (int)order.KDNum,
+ name = order.GOODSNAME
+ }
+ }
+ };
+ if (order.SettleAccountsTypeCode == "2")
+ {
+ if (string.IsNullOrWhiteSpace(order.MonthlyCard))
+ {
+ throw Oops.Bah("当结费类型为月结时,月结卡号不能为空");
+ }
+ sFSend.monthlyCard = order.MonthlyCard;
+ }
- address = $"{order.SJProvince}{order.SJCity}{order.SJAddress}",
- contact = order.SJPeople,
- contactType = 2,
- country = "CN",
- //postCode = order.SJPostCode,
- tel = order.SJTel,
- });
+ List contactList = new()
+ {
+ new ContactInfoListItem
+ {
+ address = $"{order.FJProvince}{order.FJCity}{order.FJAddress}",
+ contact = order.FJPeople,
+ contactType = 1,
+ country = "CN",
+ tel = order.FJTel,
+ },
+ new ContactInfoListItem
+ {
+ address = $"{order.SJProvince}{order.SJCity}{order.SJAddress}",
+ contact = order.SJPeople,
+ contactType = 2,
+ country = "CN",
+ tel = order.SJTel,
+ }
+ };
sFSend.contactInfoList = contactList;
- sFSend.cargoDetails = cargo;
(string url, Dictionary dict) apiParam = await CreateSFApiParams("EXP_RECE_CREATE_ORDER", sFSend);
@@ -356,7 +375,7 @@ namespace Myshipping.Application
{
OrderId = Id,
MailNo = waybillNo,
- StatusCode = "DJY02",
+ StatusCode = "DJY03",
StatusDesc = statusDesc
};
await _statusRep.InsertAsync(status);
@@ -434,7 +453,6 @@ namespace Myshipping.Application
return rt;
}
-
///
/// 取消快递下单
///
@@ -443,6 +461,16 @@ namespace Myshipping.Application
[HttpPost("CancelBooking")]
public async Task CancelBooking(long Id)
{
+ var order = _orderRep.FirstOrDefault(x => x.Id == Id) ?? throw Oops.Bah("请选择正确数据!");
+ if (order.CurrentStateCode is "DJY01" or "DJY02")
+ {
+ throw Oops.Bah("消单失败,原因:尚未下单,无需消单");
+ }
+ if (order.CurrentStateCode is "DJY04")
+ {
+ throw Oops.Bah("消单失败,原因:已消单,无需再次消单");
+ }
+
var param = new
{
dealType = 2,
@@ -469,7 +497,7 @@ namespace Myshipping.Application
{
OrderId = Id,
MailNo = order.KDNO,
- StatusCode = "DJY03",
+ StatusCode = "DJY04",
StatusDesc = STATUS_CANCEL
};
await _statusRep.InsertAsync(status);
@@ -548,6 +576,66 @@ namespace Myshipping.Application
return rt;
}
+ ///
+ /// 根据提单号列表,向与之快递关联的订舱动态中,添加快递动态
+ ///
+ /// 需要添加快递动态的提单号列表
+ /// 快递动态描述
+ /// 日志标志
+ [NonAction]
+ private async Task InsertNewBookingStatusWithMblnoList(List mblnoList, string status, string logGuid = "")
+ {
+ if (mblnoList == null || mblnoList.Count == 0)
+ {
+ _logger.LogInformation($"快递订单关联订舱增加动态,{logGuid},mblNoList为空,return");
+ return;
+ }
+ _logger.LogInformation($"快递订单关联订舱增加动态,{logGuid},mblNoList:{string.Join(',', mblnoList)}");
+ List filteredList = mblnoList.Where(m => !string.IsNullOrWhiteSpace(m)).ToList(); // 如果提单号为空,则不进行处理
+ if (filteredList == null || filteredList.Count == 0)
+ {
+ return;
+ }
+
+ var bookingIdMapMblnoList = await _bookingOrderRep.AsQueryable(o => o.ParentId == 0 && filteredList.Contains(o.MBLNO))
+ .Select(o => new { o.Id, o.MBLNO })
+ .ToListAsync();
+
+ var bookingStatusLogList = new List();
+ foreach (string mblNo in filteredList)
+ {
+ var bookingOrderIdListTemp = bookingIdMapMblnoList.Where(o => o.MBLNO == mblNo);
+ if (bookingOrderIdListTemp == null)
+ {
+ _logger.LogInformation($"根据提单号{mblNo}查询订舱记录主键结果为空,{logGuid}");
+ continue;
+ }
+ else if (bookingOrderIdListTemp.Count() > 1)
+ {
+ _logger.LogInformation($"根据提单号{mblNo}查询订舱记录主键时查出多条记录,ids:{string.Join(',', bookingOrderIdListTemp.Select(b => b.Id).ToArray())},{logGuid}");
+ continue;
+ }
+
+ long? bookingOrderId = bookingOrderIdListTemp.First().Id;
+ _logger.LogInformation($"根据提单号{mblNo}查询订舱记录主键为{bookingOrderId},{logGuid}");
+
+ bookingStatusLogList.Add(new BookingStatusLog()
+ {
+ BookingId = bookingOrderId,
+ Status = status,
+ Category = "kuaidi",
+ OpTime = DateTime.Now,
+ MBLNO = mblNo
+ });
+ }
+ if (bookingStatusLogList.Count > 0)
+ {
+ await _bookingStatuslogRep.InsertAsync(bookingStatusLogList);
+ }
+ }
+
+ #region 顺丰专有方法
+
///
/// 获取顺丰API接口调用参数
///
@@ -619,65 +707,7 @@ namespace Myshipping.Application
return (url + "/std/service", dict);
}
-
- ///
- /// 根据提单号列表,向与之快递关联的订舱动态中,添加快递动态
- ///
- /// 需要添加快递动态的提单号列表
- /// 快递动态描述
- /// 日志标志
- [NonAction]
- private async Task InsertNewBookingStatusWithMblnoList(List mblnoList, string status, string logGuid = "")
- {
- if (mblnoList == null || mblnoList.Count == 0)
- {
- _logger.LogInformation($"快递订单关联订舱增加动态,{logGuid},mblNoList为空,return");
- return;
- }
- _logger.LogInformation($"快递订单关联订舱增加动态,{logGuid},mblNoList:{string.Join(',', mblnoList)}");
- List filteredList = mblnoList.Where(m => !string.IsNullOrWhiteSpace(m)).ToList(); // 如果提单号为空,则不进行处理
- if (filteredList == null || filteredList.Count == 0)
- {
- return;
- }
-
- var bookingIdMapMblnoList = await _bookingOrderRep.AsQueryable(o => o.ParentId == 0 && filteredList.Contains(o.MBLNO))
- .Select(o => new { o.Id, o.MBLNO })
- .ToListAsync();
-
- var bookingStatusLogList = new List();
- foreach (string mblNo in filteredList)
- {
- var bookingOrderIdListTemp = bookingIdMapMblnoList.Where(o => o.MBLNO == mblNo);
- if (bookingOrderIdListTemp == null)
- {
- _logger.LogInformation($"根据提单号{mblNo}查询订舱记录主键结果为空,{logGuid}");
- continue;
- }
- else if (bookingOrderIdListTemp.Count() > 1)
- {
- _logger.LogInformation($"根据提单号{mblNo}查询订舱记录主键时查出多条记录,ids:{string.Join(',', bookingOrderIdListTemp.Select(b => b.Id).ToArray())},{logGuid}");
- continue;
- }
-
- long? bookingOrderId = bookingOrderIdListTemp.First().Id;
- _logger.LogInformation($"根据提单号{mblNo}查询订舱记录主键为{bookingOrderId},{logGuid}");
-
- bookingStatusLogList.Add(new BookingStatusLog()
- {
- BookingId = bookingOrderId,
- Status = status,
- Category = "kuaidi",
- OpTime = DateTime.Now,
- MBLNO = mblNo
- });
- }
- if (bookingStatusLogList.Count > 0)
- {
- await _bookingStatuslogRep.InsertAsync(bookingStatusLogList);
- }
- }
-
+
///
/// 接收顺丰推送的快递动态
///
@@ -810,7 +840,7 @@ namespace Myshipping.Application
return new { return_code = "0000", return_msg = "成功" };
}
-
+ #endregion
#region 地址簿相关
///