|
@ -387,8 +387,8 @@ namespace BBWYB.Server.Business |
|
|
/// <param name="jObject"></param>
|
|
|
/// <param name="jObject"></param>
|
|
|
private void OrderPriceModificationCallbackFrom1688(JObject jObject) |
|
|
private void OrderPriceModificationCallbackFrom1688(JObject jObject) |
|
|
{ |
|
|
{ |
|
|
//var purchaseOrderId = jObject["data"].Value<string>("orderId");
|
|
|
var purchaseOrderId = jObject["data"].Value<string>("orderId"); |
|
|
//Task.Factory.StartNew(() => OrderPriceModificationCallback(purchaseOrderId, Enums.Platform.阿里巴巴), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.PurchaseOrderCallbackTaskScheduler);
|
|
|
Task.Factory.StartNew(() => OrderPriceModificationCallback(purchaseOrderId, Enums.Platform.阿里巴巴), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.PurchaseOrderCallbackTaskScheduler); |
|
|
} |
|
|
} |
|
|
#endregion
|
|
|
#endregion
|
|
|
|
|
|
|
|
@ -612,145 +612,72 @@ namespace BBWYB.Server.Business |
|
|
}, CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.PurchaseOrderCallbackTaskScheduler); |
|
|
}, CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.PurchaseOrderCallbackTaskScheduler); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
///// <summary>
|
|
|
/// <summary>
|
|
|
///// 采购平台改价回调
|
|
|
/// 采购平台改价回调
|
|
|
///// </summary>
|
|
|
/// </summary>
|
|
|
///// <param name="purchaseOrderId"></param>
|
|
|
/// <param name="purchaseOrderId"></param>
|
|
|
///// <param name="callbackPlatform"></param>
|
|
|
/// <param name="callbackPlatform"></param>
|
|
|
//private void OrderPriceModificationCallback(string purchaseOrderId, Enums.Platform callbackPlatform)
|
|
|
private void OrderPriceModificationCallback(string purchaseOrderId, Enums.Platform callbackPlatform) |
|
|
//{
|
|
|
{ |
|
|
// string currentProgress = string.Empty;
|
|
|
string currentProgress = string.Empty; |
|
|
|
|
|
|
|
|
// try
|
|
|
try |
|
|
// {
|
|
|
{ |
|
|
// #region 查询代发信息
|
|
|
var orderPurchaseInfo = fsql.Select<OrderPurchaseInfo>().Where(opi => opi.PurchaseOrderId == purchaseOrderId).ToOne(); |
|
|
// currentProgress = "查询代发信息";
|
|
|
if (orderPurchaseInfo == null) |
|
|
// var orderDropshipping = fsql.Select<OrderDropShipping>().Where(o => o.PurchaseOrderId == purchaseOrderId).ToOne();
|
|
|
throw new Exception($"未查询到采购单{orderPurchaseInfo.PurchaseAccountId}"); |
|
|
// if (orderDropshipping == null)
|
|
|
|
|
|
// throw new Exception("未查询到代发信息");
|
|
|
var purchaseAccount = fsqlManager.MDSfsql.Select<Purchaseaccount>().Where(pa => pa.Id == orderPurchaseInfo.PurchaseAccountId).ToOne(); |
|
|
// #endregion
|
|
|
if (purchaseAccount == null) |
|
|
|
|
|
throw new Exception($"未查询到采购账号{orderPurchaseInfo.PurchaseAccountId}"); |
|
|
// #region 查询订单Sku
|
|
|
|
|
|
// currentProgress = "查询订单Sku";
|
|
|
var dbOrder = fsql.Select<Order>(orderPurchaseInfo.OrderId).ToOne(o => new { o.OrderTotalPrice }); |
|
|
// var orderSkuList = fsql.Select<OrderSku>().Where(osku => osku.Price != 0 && osku.OrderId == orderDropshipping.OrderId).ToList();
|
|
|
var dbOrderCost = fsql.Select<OrderCost>(orderPurchaseInfo.OrderId).ToOne(); |
|
|
// if (orderSkuList == null || orderSkuList.Count() == 0)
|
|
|
if (dbOrderCost == null) |
|
|
// throw new BusinessException("订单Sku不存在");
|
|
|
throw new Exception($"未查询到订单成本 {orderPurchaseInfo.OrderId}"); |
|
|
// #endregion
|
|
|
|
|
|
|
|
|
var orderPurchaseInfoList = fsql.Select<OrderPurchaseInfo>().Where(opi => opi.OrderId == orderPurchaseInfo.OrderId).ToList(opi => new |
|
|
// #region 查询采购单
|
|
|
{ |
|
|
// currentProgress = "查询采购单";
|
|
|
opi.PurchaseOrderId, |
|
|
// var purchaseOrderList = fsql.Select<PurchaseOrder>().Where(po => po.PurchaseOrderId == purchaseOrderId).ToList();
|
|
|
opi.PurchaseAccountId |
|
|
// if (purchaseOrderList == null || purchaseOrderList.Count() == 0)
|
|
|
}); |
|
|
// throw new BusinessException("采购单不存在");
|
|
|
var client = ppPlatformClientFactory.GetClient(AdapterEnums.PlatformType.阿里巴巴); |
|
|
// if (orderSkuList.Count() > 1 && purchaseOrderList.Any(p => p.PurchaseMethod == Enums.PurchaseMethod.线下采购))
|
|
|
|
|
|
// throw new Exception("多sku订单关联采购单不支持改价");
|
|
|
var totalPurchaseAmount = 0M; |
|
|
// #endregion
|
|
|
foreach (var opi in orderPurchaseInfoList) |
|
|
|
|
|
{ |
|
|
// #region 查询成本
|
|
|
var purchaseOrderSimpleInfo = client.QueryOrderDetail(new PP_QueryOrderDetailRequest() |
|
|
// currentProgress = "查询成本";
|
|
|
{ |
|
|
// var orderCost = fsql.Select<OrderCost>(orderDropshipping.OrderId).ToOne();
|
|
|
AppKey = purchaseAccount.AppKey, |
|
|
// if (orderCost == null)
|
|
|
AppSecret = purchaseAccount.AppSecret, |
|
|
// throw new BusinessException("订单成本不存在");
|
|
|
AppToken = purchaseAccount.AppToken, |
|
|
// #endregion
|
|
|
OrderId = opi.PurchaseOrderId |
|
|
|
|
|
}); |
|
|
// #region 查询成本明细
|
|
|
totalPurchaseAmount += purchaseOrderSimpleInfo.TotalAmount; |
|
|
// currentProgress = "查询成本明细";
|
|
|
} |
|
|
// var orderCostDetailList = fsql.Select<OrderCostDetail>().Where(ocd => ocd.OrderId == orderDropshipping.OrderId).ToList();
|
|
|
|
|
|
// if (orderCostDetailList == null || orderCostDetailList.Count() == 0)
|
|
|
|
|
|
// throw new BusinessException("订单成本明细不存在");
|
|
|
//var oldTotalAmount = dbOrderCost.PurchaseAmount;
|
|
|
// #endregion
|
|
|
//var oldProductAmount = dbOrderCostDetailList.Sum(ocd => ocd.SkuAmount);
|
|
|
|
|
|
//var oldPurchaseFreight = dbOrderCostDetailList.Sum(ocd => ocd.PurchaseFreight);
|
|
|
// #region 查询采购账号
|
|
|
|
|
|
// currentProgress = "查询采购账号";
|
|
|
dbOrderCost.PurchaseAmount = totalPurchaseAmount; |
|
|
// var purchaseAccount = fsql.Select<PurchaseAccount>().WhereIf(orderDropshipping.PurchaseAccountId != 0, pa => pa.Id == orderDropshipping.PurchaseAccountId)
|
|
|
dbOrderCost.Profit = dbOrder.OrderTotalPrice - |
|
|
// .WhereIf(orderDropshipping.PurchaseAccountId == 0, pa => pa.AccountName == orderDropshipping.BuyerAccount)
|
|
|
dbOrderCost.PurchaseAmount - |
|
|
// .Where(pa => pa.PurchasePlatformId == callbackPlatform).ToOne();
|
|
|
dbOrderCost.DeliveryExpressFreight; // -orderCost.PlatformCommissionAmount
|
|
|
// if (purchaseAccount == null)
|
|
|
|
|
|
// throw new Exception($"未查询到采购账号{orderDropshipping.BuyerAccount}");
|
|
|
fsql.Transaction(() => |
|
|
// #endregion
|
|
|
{ |
|
|
|
|
|
fsql.Update<OrderCost>(dbOrderCost.OrderId).Set(oc => oc.PurchaseAmount, dbOrderCost.PurchaseAmount) |
|
|
// #region 查询改价后的订单金额
|
|
|
.Set(oc => oc.Profit, dbOrderCost.Profit) |
|
|
// currentProgress = "查询改价后的订单金额";
|
|
|
.ExecuteAffrows(); |
|
|
// var purchaseOrderSimpleInfo = platformSDKBusinessList.FirstOrDefault(p => p.Platform == callbackPlatform).GetOrderSimpleInfo(new GetOrderInfoRequest()
|
|
|
}); |
|
|
// {
|
|
|
|
|
|
// AppKey = purchaseAccount.AppKey,
|
|
|
} |
|
|
// AppSecret = purchaseAccount.AppSecret,
|
|
|
catch (Exception ex) |
|
|
// AppToken = purchaseAccount.AppToken,
|
|
|
{ |
|
|
// OrderId = purchaseOrderId,
|
|
|
nLogManager.Default().Error(ex, $"OrderPriceModificationCallback 回调平台{callbackPlatform},采购单号{purchaseOrderId},执行进度[{currentProgress}]"); |
|
|
// Platform = callbackPlatform
|
|
|
} |
|
|
// });
|
|
|
} |
|
|
// #endregion
|
|
|
|
|
|
|
|
|
|
|
|
// #region 查询采购单明细
|
|
|
|
|
|
// currentProgress = "查询采购单明细";
|
|
|
|
|
|
// var purchaseOrderDetails = fsql.Select<PurchaseOrderDetail>().Where(p => p.OrderId == orderDropshipping.OrderId);
|
|
|
|
|
|
// #endregion
|
|
|
|
|
|
|
|
|
|
|
|
// #region 查询订单
|
|
|
|
|
|
// currentProgress = "查询订单";
|
|
|
|
|
|
// var dbOrder = fsql.Select<Order>(orderDropshipping.OrderId).ToOne();
|
|
|
|
|
|
// if (dbOrder == null)
|
|
|
|
|
|
// throw new BusinessException("订单不存在");
|
|
|
|
|
|
// #endregion
|
|
|
|
|
|
|
|
|
|
|
|
// IList<IUpdate<PurchaseOrder>> updatePurchaseOrders = new List<IUpdate<PurchaseOrder>>();
|
|
|
|
|
|
// IList<IUpdate<OrderCostDetail>> updateOrderCostDetails = new List<IUpdate<OrderCostDetail>>();
|
|
|
|
|
|
|
|
|
|
|
|
// foreach (var orderSku in orderSkuList)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// var currentOrderSkuProductAmount = 0M; //采购成本
|
|
|
|
|
|
// if (orderSkuList.Count() != 1)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// var currentOrderSkuPurchaseOrderDetails = purchaseOrderDetails.Where(p => p.SkuId == orderSku.SkuId); //找当前skuId的采购skuId
|
|
|
|
|
|
// currentOrderSkuProductAmount = purchaseOrderSimpleInfo.ItemList.Where(p => currentOrderSkuPurchaseOrderDetails.Any(p1 => p1.PurchaseSkuId == p.SkuId))
|
|
|
|
|
|
// ?.Sum(p => p.ProductAmount) ?? 0M;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// else
|
|
|
|
|
|
// {
|
|
|
|
|
|
// currentOrderSkuProductAmount = purchaseOrderSimpleInfo.ProductAmount;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// var currentOrderSkuFreightAmount = purchaseOrderSimpleInfo.FreightAmount / orderSkuList.Count(); //采购运费(按sku数均分)
|
|
|
|
|
|
|
|
|
|
|
|
// var purchaseOrder = purchaseOrderList.FirstOrDefault(po => po.SkuId == orderSku.SkuId);
|
|
|
|
|
|
// var orderCostDetail = orderCostDetailList.FirstOrDefault(oc => oc.PurchaseOrderPKId == purchaseOrder.Id);
|
|
|
|
|
|
|
|
|
|
|
|
// purchaseOrder.SingleSkuAmount = currentOrderSkuProductAmount / orderSku.ItemTotal.Value;
|
|
|
|
|
|
// purchaseOrder.SingleFreight = currentOrderSkuFreightAmount / orderSku.ItemTotal.Value;
|
|
|
|
|
|
|
|
|
|
|
|
// orderCostDetail.SkuAmount = currentOrderSkuProductAmount;
|
|
|
|
|
|
// orderCostDetail.PurchaseFreight = currentOrderSkuFreightAmount;
|
|
|
|
|
|
// //orderCostDetail.UnitCost = purchaseOrder.UnitCost;
|
|
|
|
|
|
// //orderCostDetail.TotalCost = currentOrderSkuProductAmount + currentOrderSkuFreightAmount;
|
|
|
|
|
|
|
|
|
|
|
|
// updatePurchaseOrders.Add(fsql.Update<PurchaseOrder>().SetSource(purchaseOrder));
|
|
|
|
|
|
// updateOrderCostDetails.Add(fsql.Update<OrderCostDetail>().SetSource(orderCostDetail));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
// orderCost.PurchaseAmount = purchaseOrderSimpleInfo.TotalAmount;
|
|
|
|
|
|
// orderCost.Profit = dbOrder.OrderSellerPrice +
|
|
|
|
|
|
// dbOrder.FreightPrice -
|
|
|
|
|
|
// orderCost.PurchaseAmount -
|
|
|
|
|
|
// orderCost.DeliveryExpressFreight -
|
|
|
|
|
|
// orderCost.PlatformCommissionAmount;
|
|
|
|
|
|
|
|
|
|
|
|
// orderDropshipping.PurchaseAmount = purchaseOrderSimpleInfo.TotalAmount;
|
|
|
|
|
|
// orderDropshipping.SkuAmount = purchaseOrderSimpleInfo.ProductAmount;
|
|
|
|
|
|
// orderDropshipping.PurchaseFreight = purchaseOrderSimpleInfo.FreightAmount;
|
|
|
|
|
|
// fsql.Transaction(() =>
|
|
|
|
|
|
// {
|
|
|
|
|
|
// foreach (var update in updatePurchaseOrders)
|
|
|
|
|
|
// update.ExecuteAffrows();
|
|
|
|
|
|
// foreach (var update in updateOrderCostDetails)
|
|
|
|
|
|
// update.ExecuteAffrows();
|
|
|
|
|
|
// fsql.Update<OrderCost>().SetSource(orderCost).ExecuteAffrows();
|
|
|
|
|
|
// fsql.Update<OrderDropShipping>().SetSource(orderDropshipping).ExecuteAffrows();
|
|
|
|
|
|
// });
|
|
|
|
|
|
// }
|
|
|
|
|
|
// catch (Exception ex)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// nLogManager.Default().Error(ex, $"OrderPriceModificationCallback 回调平台{callbackPlatform},采购单号{purchaseOrderId},执行进度[{currentProgress}]");
|
|
|
|
|
|
// }
|
|
|
|
|
|
//}
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|