From 8a333d775ad46c5d5d62ff3d05a7b6348060ab95 Mon Sep 17 00:00:00 2001
From: shanj <18996038927@163.com>
Date: Tue, 15 Mar 2022 04:11:02 +0800
Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=8F=91=E8=B4=A7?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Controllers/PlatformSDKController.cs | 11 ++++
.../PlatformSDK/PlatformSDKBusiness.cs | 5 ++
.../PlatformSDK/_1688Business.cs | 35 ++++++++++++
.../PurchaseOrder/PurchaseOrderBusiness.cs | 55 +++++++++++++++++--
.../Logistics/QueryOrderWayBillNoRequest.cs | 11 ++++
.../Response/Logistics/LogisticsResponse.cs | 9 +++
6 files changed, 121 insertions(+), 5 deletions(-)
create mode 100644 BBWY.Server.Model/Dto/Request/Logistics/QueryOrderWayBillNoRequest.cs
diff --git a/BBWY.Server.API/Controllers/PlatformSDKController.cs b/BBWY.Server.API/Controllers/PlatformSDKController.cs
index c3cd8487..a48a7706 100644
--- a/BBWY.Server.API/Controllers/PlatformSDKController.cs
+++ b/BBWY.Server.API/Controllers/PlatformSDKController.cs
@@ -110,6 +110,17 @@ namespace BBWY.Server.API.Controllers
return platformSDKBusinessList.FirstOrDefault(p => p.Platform == platformRequest.Platform).GetLogisticsList(platformRequest);
}
+ ///
+ /// 获取物流单号
+ ///
+ ///
+ ///
+ [HttpPost]
+ public WayBillNoResponse GetWayBillNoByOrderId(QueryOrderWayBillNoRequest queryOrderWayBillNoRequest)
+ {
+ return platformSDKBusinessList.FirstOrDefault(p => p.Platform == queryOrderWayBillNoRequest.Platform).GetWayBillNoByOrderId(queryOrderWayBillNoRequest);
+ }
+
///
/// 出库发货
///
diff --git a/BBWY.Server.Business/PlatformSDK/PlatformSDKBusiness.cs b/BBWY.Server.Business/PlatformSDK/PlatformSDKBusiness.cs
index c883ec10..8239e0bb 100644
--- a/BBWY.Server.Business/PlatformSDK/PlatformSDKBusiness.cs
+++ b/BBWY.Server.Business/PlatformSDK/PlatformSDKBusiness.cs
@@ -68,6 +68,11 @@ namespace BBWY.Server.Business
throw new NotImplementedException();
}
+ public virtual WayBillNoResponse GetWayBillNoByOrderId(QueryOrderWayBillNoRequest queryOrderWayBillNoRequest)
+ {
+ throw new NotImplementedException();
+ }
+
public virtual void OutStock(OutStockRequest outStockRequest)
{
throw new NotImplementedException();
diff --git a/BBWY.Server.Business/PlatformSDK/_1688Business.cs b/BBWY.Server.Business/PlatformSDK/_1688Business.cs
index 526fcf79..2e5b6cf7 100644
--- a/BBWY.Server.Business/PlatformSDK/_1688Business.cs
+++ b/BBWY.Server.Business/PlatformSDK/_1688Business.cs
@@ -39,6 +39,41 @@ namespace BBWY.Server.Business
return syncAPIClient;
}
+ public override WayBillNoResponse GetWayBillNoByOrderId(QueryOrderWayBillNoRequest queryOrderWayBillNoRequest)
+ {
+ var client = GetSyncAPIClient(queryOrderWayBillNoRequest.AppKey, queryOrderWayBillNoRequest.AppSecret);
+ RequestPolicy reqPolicy = new RequestPolicy();
+ reqPolicy.HttpMethod = "POST";
+ reqPolicy.NeedAuthorization = false;
+ reqPolicy.RequestSendTimestamp = false;
+ reqPolicy.UseHttps = false;
+ reqPolicy.UseSignture = true;
+ reqPolicy.AccessPrivateApi = false;
+
+ Request request = new Request();
+ APIId apiId = new APIId();
+ apiId.Name = "alibaba.trade.getLogisticsInfos.buyerView";
+ apiId.NamespaceValue = "com.alibaba.logistics";
+ apiId.Version = 1;
+ request.ApiId = apiId;
+
+ var param = new { orderId = queryOrderWayBillNoRequest.OrderId, webSite = "1688", fields = "logisticsCompanyId,logisticsCompanyName,logisticsBillNo" };
+ request.RequestEntity = param;
+ if (!string.IsNullOrEmpty(queryOrderWayBillNoRequest.AppToken))
+ request.AccessToken = queryOrderWayBillNoRequest.AppToken;
+ var result = client.NewRequest(request, reqPolicy);
+ if (result.Value("success") != true)
+ throw new BusinessException(result.Value("errorMsg")) { Code = 0 };
+
+ var firstJToken = result["result"].FirstOrDefault();
+ return new WayBillNoResponse()
+ {
+ LogisticsCompanyId = firstJToken.Value("logisticsCompanyId"),
+ LogisticsCompanyName = firstJToken.Value("logisticsCompanyName"),
+ WayBillNo = firstJToken.Value("logisticsBillNo")
+ };
+ }
+
public override PreviewOrderResponse PreviewOrder(PreviewOrderReuqest previewOrderReuqest)
{
var client = GetSyncAPIClient(previewOrderReuqest.AppKey, previewOrderReuqest.AppSecret);
diff --git a/BBWY.Server.Business/PurchaseOrder/PurchaseOrderBusiness.cs b/BBWY.Server.Business/PurchaseOrder/PurchaseOrderBusiness.cs
index 791f5e28..5526daae 100644
--- a/BBWY.Server.Business/PurchaseOrder/PurchaseOrderBusiness.cs
+++ b/BBWY.Server.Business/PurchaseOrder/PurchaseOrderBusiness.cs
@@ -10,6 +10,7 @@ using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using Yitter.IdGenerator;
@@ -22,14 +23,29 @@ namespace BBWY.Server.Business
private TaskSchedulerManager taskSchedulerManager;
private OrderBusiness orderBusiness;
private MDSBusiness mdsBusiness;
+ private VenderBusiness venderBusiness;
+ private IDictionary deliverySelfDic;
- public PurchaseOrderBusiness(IFreeSql fsql, NLog.ILogger logger, IIdGenerator idGenerator, IEnumerable platformSDKBusinessList, TaskSchedulerManager taskSchedulerManager, OrderBusiness orderBusiness, MDSBusiness mdsBusiness) : base(fsql, logger, idGenerator)
+ public PurchaseOrderBusiness(IFreeSql fsql,
+ NLog.ILogger logger,
+ IIdGenerator idGenerator,
+ IEnumerable platformSDKBusinessList,
+ TaskSchedulerManager taskSchedulerManager,
+ OrderBusiness orderBusiness,
+ MDSBusiness mdsBusiness,
+ VenderBusiness venderBusiness) : base(fsql, logger, idGenerator)
{
this.platformSDKBusinessList = platformSDKBusinessList;
this.taskSchedulerManager = taskSchedulerManager;
this.orderBusiness = orderBusiness;
this.mdsBusiness = mdsBusiness;
+ this.venderBusiness = venderBusiness;
+
+ deliverySelfDic = new Dictionary()
+ {
+ {Enums.Platform.京东 , "1274"} //厂家自送
+ };
}
public void AddPurchaseOrder(AddPurchaseOrderRequest addPurchaseOrderRequest)
@@ -243,7 +259,14 @@ namespace BBWY.Server.Business
#region 获取采购单的物流信息
currentProgress = "获取采购单的物流信息";
-
+ var wayBillNoResponse = platformSDKBusinessList.FirstOrDefault(p => p.Platform == callbackPlatform).GetWayBillNoByOrderId(new QueryOrderWayBillNoRequest()
+ {
+ AppKey = purchaseAccount.AppKey,
+ AppSecret = purchaseAccount.AppSecret,
+ AppToken = purchaseAccount.AppToken,
+ OrderId = purchaseOrderId,
+ Platform = callbackPlatform
+ });
#endregion
#region 查询采购账号的归属店铺
@@ -252,11 +275,19 @@ namespace BBWY.Server.Business
#endregion
#region 获取目标平台的物流公司列表
- currentProgress = "获取目标平台物流公司列表";
+ currentProgress = "获取店铺平台物流公司列表";
+ var logisticsCompanyList = venderBusiness.GetLogisticsList(new PlatformRequest()
+ {
+ AppKey = shop.AppKey,
+ AppSecret = shop.AppSecret,
+ AppToken = shop.AppToken,
+ Platform = shop.Platform
+ });
#endregion
#region 物流公司翻译
currentProgress = "将采购单的物流公司翻译为店铺平台的物流公司";
+ var logisticsCompanyId = ConvertLogisticsCompanyId(wayBillNoResponse.LogisticsCompanyName, logisticsCompanyList, shop.Platform);
#endregion
#region 店铺平台订单出库
@@ -268,8 +299,8 @@ namespace BBWY.Server.Business
AppToken = shop.AppToken,
OrderId = orderDropshipping.OrderId,
Platform = shop.Platform,
- WayBillNo = "",
- LogisticsId = ""
+ WayBillNo = wayBillNoResponse.WayBillNo,
+ LogisticsId = logisticsCompanyId //物流公司Id
});
#endregion
}
@@ -278,5 +309,19 @@ namespace BBWY.Server.Business
logger.Error(ex, $"回调平台{callbackPlatform},采购单号{purchaseOrderId},执行进度[{currentProgress}]");
}
}
+
+ private string ConvertLogisticsCompanyId(string sourceLogisticsCompanyName, IList targetLogisticsList, Enums.Platform tagetLogisticsPlatform)
+ {
+ var match = Regex.Match(sourceLogisticsCompanyName, "(中通|圆通|申通|顺丰|韵达|邮政快递包裹|平邮|EMS|德邦|百世|天天|优速)");
+ if (match.Success)
+ {
+ var sname = match.Groups[1].Value;
+ var targetLogistics = targetLogisticsList.FirstOrDefault(t => t.Name.Contains(sname));
+ if (targetLogistics != null)
+ return targetLogistics.Id;
+ }
+ return deliverySelfDic[tagetLogisticsPlatform];
+ }
+
}
}
diff --git a/BBWY.Server.Model/Dto/Request/Logistics/QueryOrderWayBillNoRequest.cs b/BBWY.Server.Model/Dto/Request/Logistics/QueryOrderWayBillNoRequest.cs
new file mode 100644
index 00000000..46c6a52c
--- /dev/null
+++ b/BBWY.Server.Model/Dto/Request/Logistics/QueryOrderWayBillNoRequest.cs
@@ -0,0 +1,11 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace BBWY.Server.Model.Dto
+{
+ public class QueryOrderWayBillNoRequest : PlatformRequest
+ {
+ public string OrderId { get; set; }
+ }
+}
diff --git a/BBWY.Server.Model/Dto/Response/Logistics/LogisticsResponse.cs b/BBWY.Server.Model/Dto/Response/Logistics/LogisticsResponse.cs
index 6beb6f66..2b4cd34f 100644
--- a/BBWY.Server.Model/Dto/Response/Logistics/LogisticsResponse.cs
+++ b/BBWY.Server.Model/Dto/Response/Logistics/LogisticsResponse.cs
@@ -6,4 +6,13 @@
public string Name { get; set; }
}
+
+ public class WayBillNoResponse
+ {
+ public string LogisticsCompanyId { get; set; }
+
+ public string LogisticsCompanyName { get; set; }
+
+ public string WayBillNo { get; set; }
+ }
}