Browse Source

自动发货

qianyi
shanji 3 years ago
parent
commit
8a333d775a
  1. 11
      BBWY.Server.API/Controllers/PlatformSDKController.cs
  2. 5
      BBWY.Server.Business/PlatformSDK/PlatformSDKBusiness.cs
  3. 35
      BBWY.Server.Business/PlatformSDK/_1688Business.cs
  4. 55
      BBWY.Server.Business/PurchaseOrder/PurchaseOrderBusiness.cs
  5. 11
      BBWY.Server.Model/Dto/Request/Logistics/QueryOrderWayBillNoRequest.cs
  6. 9
      BBWY.Server.Model/Dto/Response/Logistics/LogisticsResponse.cs

11
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);
}
/// <summary>
/// 获取物流单号
/// </summary>
/// <param name="queryOrderWayBillNoRequest"></param>
/// <returns></returns>
[HttpPost]
public WayBillNoResponse GetWayBillNoByOrderId(QueryOrderWayBillNoRequest queryOrderWayBillNoRequest)
{
return platformSDKBusinessList.FirstOrDefault(p => p.Platform == queryOrderWayBillNoRequest.Platform).GetWayBillNoByOrderId(queryOrderWayBillNoRequest);
}
/// <summary>
/// 出库发货
/// </summary>

5
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();

35
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<bool>("success") != true)
throw new BusinessException(result.Value<string>("errorMsg")) { Code = 0 };
var firstJToken = result["result"].FirstOrDefault();
return new WayBillNoResponse()
{
LogisticsCompanyId = firstJToken.Value<string>("logisticsCompanyId"),
LogisticsCompanyName = firstJToken.Value<string>("logisticsCompanyName"),
WayBillNo = firstJToken.Value<string>("logisticsBillNo")
};
}
public override PreviewOrderResponse PreviewOrder(PreviewOrderReuqest previewOrderReuqest)
{
var client = GetSyncAPIClient(previewOrderReuqest.AppKey, previewOrderReuqest.AppSecret);

55
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<Enums.Platform, string> deliverySelfDic;
public PurchaseOrderBusiness(IFreeSql fsql, NLog.ILogger logger, IIdGenerator idGenerator, IEnumerable<PlatformSDKBusiness> platformSDKBusinessList, TaskSchedulerManager taskSchedulerManager, OrderBusiness orderBusiness, MDSBusiness mdsBusiness) : base(fsql, logger, idGenerator)
public PurchaseOrderBusiness(IFreeSql fsql,
NLog.ILogger logger,
IIdGenerator idGenerator,
IEnumerable<PlatformSDKBusiness> 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, string>()
{
{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<LogisticsResponse> 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];
}
}
}

11
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; }
}
}

9
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; }
}
}

Loading…
Cancel
Save