diff --git a/BBWY.Server.API/Controllers/PurchaseOrderController.cs b/BBWY.Server.API/Controllers/PurchaseOrderController.cs
index ecc50e29..1c341d5d 100644
--- a/BBWY.Server.API/Controllers/PurchaseOrderController.cs
+++ b/BBWY.Server.API/Controllers/PurchaseOrderController.cs
@@ -64,7 +64,7 @@ namespace BBWY.Server.API.Controllers
}
///
- /// 1688发货回调
+ /// 1688发货回调(即将废弃)
///
///
///
@@ -73,5 +73,16 @@ namespace BBWY.Server.API.Controllers
{
purchaseOrderBusiness.DeliveryCallbackFrom1688(message);
}
+
+ ///
+ /// 1688回调
+ ///
+ ///
+ ///
+ [HttpPost]
+ public void CallbackFrom1688([FromForm] string message, [FromForm] string _aop_signature)
+ {
+ purchaseOrderBusiness.CallbackFrom1688(message);
+ }
}
}
diff --git a/BBWY.Server.Business/PlatformSDK/PlatformSDKBusiness.cs b/BBWY.Server.Business/PlatformSDK/PlatformSDKBusiness.cs
index 8239e0bb..f3bbcffb 100644
--- a/BBWY.Server.Business/PlatformSDK/PlatformSDKBusiness.cs
+++ b/BBWY.Server.Business/PlatformSDK/PlatformSDKBusiness.cs
@@ -88,5 +88,15 @@ namespace BBWY.Server.Business
throw new NotImplementedException();
}
+ ///
+ /// 获取订单金额信息
+ ///
+ ///
+ ///
+ ///
+ public virtual OrderAmountResponse GetOrderAmountInfo(GetOrderInfoRequest getOrderInfoRequest)
+ {
+ throw new NotImplementedException();
+ }
}
}
diff --git a/BBWY.Server.Business/PlatformSDK/_1688Business.cs b/BBWY.Server.Business/PlatformSDK/_1688Business.cs
index 1725f2cf..b8a26793 100644
--- a/BBWY.Server.Business/PlatformSDK/_1688Business.cs
+++ b/BBWY.Server.Business/PlatformSDK/_1688Business.cs
@@ -169,10 +169,12 @@ namespace BBWY.Server.Business
reqPolicy.AccessPrivateApi = false;
Request request = new Request();
- APIId apiId = new APIId();
- apiId.Name = "alibaba.trade.fastCreateOrder";
- apiId.NamespaceValue = "com.alibaba.trade";
- apiId.Version = 1;
+ APIId apiId = new APIId
+ {
+ Name = "alibaba.trade.fastCreateOrder",
+ NamespaceValue = "com.alibaba.trade",
+ Version = 1
+ };
request.ApiId = apiId;
var param = new
@@ -230,6 +232,51 @@ namespace BBWY.Server.Business
FailProductMessageList = failedOfferJArray == null ? null : failedOfferJArray.Select(failedOfferJToken => failedOfferJToken.ToString()).ToList()
};
}
+
+ ///
+ /// 获取订单金额
+ ///
+ ///
+ ///
+ public override OrderAmountResponse GetOrderAmountInfo(GetOrderInfoRequest getOrderInfoRequest)
+ {
+ var client = GetSyncAPIClient(getOrderInfoRequest.AppKey, getOrderInfoRequest.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
+ {
+ Name = "alibaba.trade.get.buyerView",
+ NamespaceValue = "com.alibaba.trade",
+ Version = 1
+ };
+ request.ApiId = apiId;
+
+ var param = new
+ {
+ webSite = "1688",
+ orderId = getOrderInfoRequest.OrderId,
+ includeFields = "baseInfo"
+ };
+ request.RequestEntity = param;
+ if (!string.IsNullOrEmpty(getOrderInfoRequest.AppToken))
+ request.AccessToken = getOrderInfoRequest.AppToken;
+ var result = client.NewRequest(request, reqPolicy);
+ if (result.Value("success") != true)
+ throw new BusinessException(result.Value("errorMessage")) { Code = 0 };
+
+
+ return new OrderAmountResponse()
+ {
+
+ };
+ }
}
public class _1688TradeTypeCompare : IEqualityComparer
diff --git a/BBWY.Server.Business/PurchaseOrder/PurchaseOrderBusiness.cs b/BBWY.Server.Business/PurchaseOrder/PurchaseOrderBusiness.cs
index 8ea9450b..e5cb120e 100644
--- a/BBWY.Server.Business/PurchaseOrder/PurchaseOrderBusiness.cs
+++ b/BBWY.Server.Business/PurchaseOrder/PurchaseOrderBusiness.cs
@@ -220,6 +220,32 @@ namespace BBWY.Server.Business
});
}
+ #region CallBack
+
+ #region 1688CallBack
+ public void CallbackFrom1688(string jsonStr)
+ {
+ logger.Info(jsonStr);
+ var jObject = JObject.Parse(jsonStr);
+ var type = jObject.Value("type").ToUpper();
+ switch (type)
+ {
+ case "ORDER_BUYER_VIEW_PART_PART_SENDGOODS": //部分发货
+ case "ORDER_BUYER_VIEW_ANNOUNCE_SENDGOODS": //发货
+ DeliveryCallbackFrom1688(jObject);
+ break;
+ case "ORDER_BUYER_VIEW_ORDER_PRICE_MODIFY":
+ OrderPriceModificationCallbackFrom1688(jObject); //订单改价
+ break;
+ default:
+ break;
+ }
+ }
+
+ ///
+ /// 1688发货回调(即将废弃)
+ ///
+ ///
public void DeliveryCallbackFrom1688(string jsonStr)
{
logger.Info(jsonStr);
@@ -228,15 +254,29 @@ namespace BBWY.Server.Business
Task.Factory.StartNew(() => DeliveryCallback(purchaseOrderId, Enums.Platform.阿里巴巴), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.PurchaseOrderCallbackTaskScheduler);
}
- public void DeliveryCallbackFromPDD(object param)
+ ///
+ /// 1688发货回调
+ ///
+ ///
+ private void DeliveryCallbackFrom1688(JObject jObject)
+ {
+ var purchaseOrderId = jObject["data"].Value("orderId");
+ Task.Factory.StartNew(() => DeliveryCallback(purchaseOrderId, Enums.Platform.阿里巴巴), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.PurchaseOrderCallbackTaskScheduler);
+ }
+
+ ///
+ /// 1688订单改价回调
+ ///
+ ///
+ private void OrderPriceModificationCallbackFrom1688(JObject jObject)
{
- var orderJObject = JObject.Parse(param.ToString());
- var purchaseOrderId = orderJObject.Value("orderId");
- Task.Factory.StartNew(() => DeliveryCallback(purchaseOrderId, Enums.Platform.拼多多), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.PurchaseOrderCallbackTaskScheduler);
+ var purchaseOrderId = jObject["data"].Value("orderId");
+ Task.Factory.StartNew(() => OrderPriceModificationCallback(purchaseOrderId, Enums.Platform.阿里巴巴), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.PurchaseOrderCallbackTaskScheduler);
}
+ #endregion
///
- /// 采购平台回调核心流程
+ /// 采购平台发货回调
///
///
///
@@ -245,11 +285,11 @@ namespace BBWY.Server.Business
string currentProgress = string.Empty;
try
{
- #region 查询采购单
- currentProgress = "查询采购单";
+ #region 查询代发信息
+ currentProgress = "查询代发信息";
var orderDropshipping = fsql.Select().Where(o => o.PurchaseOrderId == purchaseOrderId).ToOne();
if (orderDropshipping == null)
- throw new Exception("未查询到采购单号");
+ throw new Exception("未查询到代发信息");
#endregion
#region 查询采购账号
@@ -310,10 +350,17 @@ namespace BBWY.Server.Business
}
catch (Exception ex)
{
- logger.Error(ex, $"回调平台{callbackPlatform},采购单号{purchaseOrderId},执行进度[{currentProgress}]");
+ logger.Error(ex, $"DeliveryCallback 回调平台{callbackPlatform},采购单号{purchaseOrderId},执行进度[{currentProgress}]");
}
}
+ ///
+ /// 物流公司翻译, 将发货平台的物流公司翻译为店铺平台的物流公司
+ ///
+ ///
+ ///
+ ///
+ ///
private string ConvertLogisticsCompanyId(string sourceLogisticsCompanyName, IList targetLogisticsList, Enums.Platform tagetLogisticsPlatform)
{
var match = Regex.Match(sourceLogisticsCompanyName, "(中通|圆通|申通|顺丰|韵达|邮政快递包裹|平邮|EMS|德邦|百世|天天|优速)");
@@ -327,5 +374,65 @@ namespace BBWY.Server.Business
return deliverySelfDic[tagetLogisticsPlatform];
}
+ ///
+ /// 采购平台改价回调
+ ///
+ ///
+ ///
+ private void OrderPriceModificationCallback(string purchaseOrderId, Enums.Platform callbackPlatform)
+ {
+ string currentProgress = string.Empty;
+
+ try
+ {
+ #region 查询代发信息
+ currentProgress = "查询代发信息";
+ var orderDropshipping = fsql.Select().Where(o => o.PurchaseOrderId == purchaseOrderId).ToOne();
+ if (orderDropshipping == null)
+ throw new Exception("未查询到代发信息");
+ #endregion
+
+ #region 查询采购账号
+ currentProgress = "查询采购账号";
+ var purchaseAccount = fsql.Select().WhereIf(orderDropshipping.PurchaseAccountId != 0, pa => pa.Id == orderDropshipping.PurchaseAccountId)
+ .WhereIf(orderDropshipping.PurchaseAccountId == 0, pa => pa.AccountName == orderDropshipping.BuyerAccount)
+ .Where(pa => pa.PurchasePlatformId == callbackPlatform).ToOne();
+ if (purchaseAccount == null)
+ throw new Exception($"未查询到采购账号{orderDropshipping.BuyerAccount}");
+ #endregion
+
+ #region 查询订单Sku
+ currentProgress = "查询订单Sku";
+ var orderSku = fsql.Select().Where(osku => osku.OrderId == orderDropshipping.OrderId).ToOne();
+ if (orderSku == null)
+ throw new BusinessException("订单Sku不存在");
+ #endregion
+
+ #region 查询改价后的订单金额
+ var orderAmountResponse = platformSDKBusinessList.FirstOrDefault(p => p.Platform == callbackPlatform).GetOrderAmountInfo(new GetOrderInfoRequest()
+ {
+ AppKey = purchaseAccount.AppKey,
+ AppSecret = purchaseAccount.AppSecret,
+ AppToken = purchaseAccount.AppToken,
+ OrderId = purchaseOrderId,
+ Platform = callbackPlatform
+ });
+ #endregion
+
+ fsql.Transaction(() =>
+ {
+ fsql.Update(purchaseOrderId).Set(po => po.SingleSkuAmount, orderAmountResponse.ProductAmount / orderSku.ItemTotal.Value)
+ .Set(po => po.SingleFreight, orderAmountResponse.FreightAmount / orderSku.ItemTotal.Value)
+ .ExecuteAffrows();
+ //fsql.Update().Where(ocd=>)
+
+ });
+ }
+ catch (Exception ex)
+ {
+ logger.Error(ex, $"OrderPriceModificationCallback 回调平台{callbackPlatform},采购单号{purchaseOrderId},执行进度[{currentProgress}]");
+ }
+ }
+ #endregion
}
}
diff --git a/BBWY.Server.Model/Dto/Request/PurchaseOrder/OnlinePurchase/GetOrderInfoRequest.cs b/BBWY.Server.Model/Dto/Request/PurchaseOrder/OnlinePurchase/GetOrderInfoRequest.cs
new file mode 100644
index 00000000..e3ac82a8
--- /dev/null
+++ b/BBWY.Server.Model/Dto/Request/PurchaseOrder/OnlinePurchase/GetOrderInfoRequest.cs
@@ -0,0 +1,7 @@
+namespace BBWY.Server.Model.Dto
+{
+ public class GetOrderInfoRequest : PlatformRequest
+ {
+ public string OrderId { get; set; }
+ }
+}
diff --git a/BBWY.Server.Model/Dto/Response/PurchaseOrder/OnlinePurchase/OrderAmountResponse.cs b/BBWY.Server.Model/Dto/Response/PurchaseOrder/OnlinePurchase/OrderAmountResponse.cs
new file mode 100644
index 00000000..5447caf6
--- /dev/null
+++ b/BBWY.Server.Model/Dto/Response/PurchaseOrder/OnlinePurchase/OrderAmountResponse.cs
@@ -0,0 +1,25 @@
+namespace BBWY.Server.Model.Dto
+{
+ public class OrderAmountResponse
+ {
+ ///
+ /// 采购单号
+ ///
+ public string PurchaseOrderId { get; set; }
+
+ ///
+ /// 订单总额
+ ///
+ public decimal TotalAmount { get; set; }
+
+ ///
+ /// 货款总额
+ ///
+ public decimal ProductAmount { get; set; }
+
+ ///
+ /// 运费总额
+ ///
+ public decimal FreightAmount { get; set; }
+ }
+}