Browse Source

1688 改价 暂定

qianyi
shanji 3 years ago
parent
commit
8751217082
  1. 13
      BBWY.Server.API/Controllers/PurchaseOrderController.cs
  2. 10
      BBWY.Server.Business/PlatformSDK/PlatformSDKBusiness.cs
  3. 55
      BBWY.Server.Business/PlatformSDK/_1688Business.cs
  4. 125
      BBWY.Server.Business/PurchaseOrder/PurchaseOrderBusiness.cs
  5. 7
      BBWY.Server.Model/Dto/Request/PurchaseOrder/OnlinePurchase/GetOrderInfoRequest.cs
  6. 25
      BBWY.Server.Model/Dto/Response/PurchaseOrder/OnlinePurchase/OrderAmountResponse.cs

13
BBWY.Server.API/Controllers/PurchaseOrderController.cs

@ -64,7 +64,7 @@ namespace BBWY.Server.API.Controllers
} }
/// <summary> /// <summary>
/// 1688发货回调 /// 1688发货回调(即将废弃)
/// </summary> /// </summary>
/// <param name="message"></param> /// <param name="message"></param>
/// <param name="_aop_signature"></param> /// <param name="_aop_signature"></param>
@ -73,5 +73,16 @@ namespace BBWY.Server.API.Controllers
{ {
purchaseOrderBusiness.DeliveryCallbackFrom1688(message); purchaseOrderBusiness.DeliveryCallbackFrom1688(message);
} }
/// <summary>
/// 1688回调
/// </summary>
/// <param name="message"></param>
/// <param name="_aop_signature"></param>
[HttpPost]
public void CallbackFrom1688([FromForm] string message, [FromForm] string _aop_signature)
{
purchaseOrderBusiness.CallbackFrom1688(message);
}
} }
} }

10
BBWY.Server.Business/PlatformSDK/PlatformSDKBusiness.cs

@ -88,5 +88,15 @@ namespace BBWY.Server.Business
throw new NotImplementedException(); throw new NotImplementedException();
} }
/// <summary>
/// 获取订单金额信息
/// </summary>
/// <param name="getOrderInfoRequest"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public virtual OrderAmountResponse GetOrderAmountInfo(GetOrderInfoRequest getOrderInfoRequest)
{
throw new NotImplementedException();
}
} }
} }

55
BBWY.Server.Business/PlatformSDK/_1688Business.cs

@ -169,10 +169,12 @@ namespace BBWY.Server.Business
reqPolicy.AccessPrivateApi = false; reqPolicy.AccessPrivateApi = false;
Request request = new Request(); Request request = new Request();
APIId apiId = new APIId(); APIId apiId = new APIId
apiId.Name = "alibaba.trade.fastCreateOrder"; {
apiId.NamespaceValue = "com.alibaba.trade"; Name = "alibaba.trade.fastCreateOrder",
apiId.Version = 1; NamespaceValue = "com.alibaba.trade",
Version = 1
};
request.ApiId = apiId; request.ApiId = apiId;
var param = new var param = new
@ -230,6 +232,51 @@ namespace BBWY.Server.Business
FailProductMessageList = failedOfferJArray == null ? null : failedOfferJArray.Select(failedOfferJToken => failedOfferJToken.ToString()).ToList() FailProductMessageList = failedOfferJArray == null ? null : failedOfferJArray.Select(failedOfferJToken => failedOfferJToken.ToString()).ToList()
}; };
} }
/// <summary>
/// 获取订单金额
/// </summary>
/// <param name="getOrderInfoRequest"></param>
/// <returns></returns>
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<bool>("success") != true)
throw new BusinessException(result.Value<string>("errorMessage")) { Code = 0 };
return new OrderAmountResponse()
{
};
}
} }
public class _1688TradeTypeCompare : IEqualityComparer<JToken> public class _1688TradeTypeCompare : IEqualityComparer<JToken>

125
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<string>("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;
}
}
/// <summary>
/// 1688发货回调(即将废弃)
/// </summary>
/// <param name="jsonStr"></param>
public void DeliveryCallbackFrom1688(string jsonStr) public void DeliveryCallbackFrom1688(string jsonStr)
{ {
logger.Info(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); Task.Factory.StartNew(() => DeliveryCallback(purchaseOrderId, Enums.Platform.), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.PurchaseOrderCallbackTaskScheduler);
} }
public void DeliveryCallbackFromPDD(object param) /// <summary>
/// 1688发货回调
/// </summary>
/// <param name="jObject"></param>
private void DeliveryCallbackFrom1688(JObject jObject)
{
var purchaseOrderId = jObject["data"].Value<string>("orderId");
Task.Factory.StartNew(() => DeliveryCallback(purchaseOrderId, Enums.Platform.), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.PurchaseOrderCallbackTaskScheduler);
}
/// <summary>
/// 1688订单改价回调
/// </summary>
/// <param name="jObject"></param>
private void OrderPriceModificationCallbackFrom1688(JObject jObject)
{ {
var orderJObject = JObject.Parse(param.ToString()); var purchaseOrderId = jObject["data"].Value<string>("orderId");
var purchaseOrderId = orderJObject.Value<string>("orderId"); Task.Factory.StartNew(() => OrderPriceModificationCallback(purchaseOrderId, Enums.Platform.), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.PurchaseOrderCallbackTaskScheduler);
Task.Factory.StartNew(() => DeliveryCallback(purchaseOrderId, Enums.Platform.), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.PurchaseOrderCallbackTaskScheduler);
} }
#endregion
/// <summary> /// <summary>
/// 采购平台回调核心流程 /// 采购平台发货回调
/// </summary> /// </summary>
/// <param name="purchaseOrderId"></param> /// <param name="purchaseOrderId"></param>
/// <param name="callbackPlatform"></param> /// <param name="callbackPlatform"></param>
@ -245,11 +285,11 @@ namespace BBWY.Server.Business
string currentProgress = string.Empty; string currentProgress = string.Empty;
try try
{ {
#region 查询采购单 #region 查询代发信息
currentProgress = "查询采购单"; currentProgress = "查询代发信息";
var orderDropshipping = fsql.Select<OrderDropShipping>().Where(o => o.PurchaseOrderId == purchaseOrderId).ToOne(); var orderDropshipping = fsql.Select<OrderDropShipping>().Where(o => o.PurchaseOrderId == purchaseOrderId).ToOne();
if (orderDropshipping == null) if (orderDropshipping == null)
throw new Exception("未查询到采购单号"); throw new Exception("未查询到代发信息");
#endregion #endregion
#region 查询采购账号 #region 查询采购账号
@ -310,10 +350,17 @@ namespace BBWY.Server.Business
} }
catch (Exception ex) catch (Exception ex)
{ {
logger.Error(ex, $"回调平台{callbackPlatform},采购单号{purchaseOrderId},执行进度[{currentProgress}]"); logger.Error(ex, $"DeliveryCallback 回调平台{callbackPlatform},采购单号{purchaseOrderId},执行进度[{currentProgress}]");
} }
} }
/// <summary>
/// 物流公司翻译, 将发货平台的物流公司翻译为店铺平台的物流公司
/// </summary>
/// <param name="sourceLogisticsCompanyName"></param>
/// <param name="targetLogisticsList"></param>
/// <param name="tagetLogisticsPlatform"></param>
/// <returns></returns>
private string ConvertLogisticsCompanyId(string sourceLogisticsCompanyName, IList<LogisticsResponse> targetLogisticsList, Enums.Platform tagetLogisticsPlatform) private string ConvertLogisticsCompanyId(string sourceLogisticsCompanyName, IList<LogisticsResponse> targetLogisticsList, Enums.Platform tagetLogisticsPlatform)
{ {
var match = Regex.Match(sourceLogisticsCompanyName, "(中通|圆通|申通|顺丰|韵达|邮政快递包裹|平邮|EMS|德邦|百世|天天|优速)"); var match = Regex.Match(sourceLogisticsCompanyName, "(中通|圆通|申通|顺丰|韵达|邮政快递包裹|平邮|EMS|德邦|百世|天天|优速)");
@ -327,5 +374,65 @@ namespace BBWY.Server.Business
return deliverySelfDic[tagetLogisticsPlatform]; return deliverySelfDic[tagetLogisticsPlatform];
} }
/// <summary>
/// 采购平台改价回调
/// </summary>
/// <param name="purchaseOrderId"></param>
/// <param name="callbackPlatform"></param>
private void OrderPriceModificationCallback(string purchaseOrderId, Enums.Platform callbackPlatform)
{
string currentProgress = string.Empty;
try
{
#region 查询代发信息
currentProgress = "查询代发信息";
var orderDropshipping = fsql.Select<OrderDropShipping>().Where(o => o.PurchaseOrderId == purchaseOrderId).ToOne();
if (orderDropshipping == null)
throw new Exception("未查询到代发信息");
#endregion
#region 查询采购账号
currentProgress = "查询采购账号";
var purchaseAccount = fsql.Select<PurchaseAccount>().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<OrderSku>().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<PurchaseOrder>(purchaseOrderId).Set(po => po.SingleSkuAmount, orderAmountResponse.ProductAmount / orderSku.ItemTotal.Value)
.Set(po => po.SingleFreight, orderAmountResponse.FreightAmount / orderSku.ItemTotal.Value)
.ExecuteAffrows();
//fsql.Update<OrderCostDetail>().Where(ocd=>)
});
}
catch (Exception ex)
{
logger.Error(ex, $"OrderPriceModificationCallback 回调平台{callbackPlatform},采购单号{purchaseOrderId},执行进度[{currentProgress}]");
}
}
#endregion
} }
} }

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

25
BBWY.Server.Model/Dto/Response/PurchaseOrder/OnlinePurchase/OrderAmountResponse.cs

@ -0,0 +1,25 @@
namespace BBWY.Server.Model.Dto
{
public class OrderAmountResponse
{
/// <summary>
/// 采购单号
/// </summary>
public string PurchaseOrderId { get; set; }
/// <summary>
/// 订单总额
/// </summary>
public decimal TotalAmount { get; set; }
/// <summary>
/// 货款总额
/// </summary>
public decimal ProductAmount { get; set; }
/// <summary>
/// 运费总额
/// </summary>
public decimal FreightAmount { get; set; }
}
}
Loading…
Cancel
Save