|
@ -14,6 +14,8 @@ using Microsoft.Extensions.DependencyInjection; |
|
|
using Newtonsoft.Json; |
|
|
using Newtonsoft.Json; |
|
|
using Newtonsoft.Json.Linq; |
|
|
using Newtonsoft.Json.Linq; |
|
|
using SDKAdapter; |
|
|
using SDKAdapter; |
|
|
|
|
|
using SDKAdapter.OperationPlatform.Client; |
|
|
|
|
|
using SDKAdapter.OperationPlatform.Models; |
|
|
using SDKAdapter.PurchasePlatform.Client; |
|
|
using SDKAdapter.PurchasePlatform.Client; |
|
|
using SDKAdapter.PurchasePlatform.Models; |
|
|
using SDKAdapter.PurchasePlatform.Models; |
|
|
using System.Text; |
|
|
using System.Text; |
|
@ -32,6 +34,7 @@ namespace BBWYB.Server.Business |
|
|
private Lazy<QiKuManager> qiKuManagerLazy; |
|
|
private Lazy<QiKuManager> qiKuManagerLazy; |
|
|
private Lazy<RestApiService> restApiServiceLazy; |
|
|
private Lazy<RestApiService> restApiServiceLazy; |
|
|
private Lazy<JDBusiness> jdBusinessLazy; |
|
|
private Lazy<JDBusiness> jdBusinessLazy; |
|
|
|
|
|
private Lazy<OP_PlatformClientFactory> opPlatformClientFactoryLazy; |
|
|
|
|
|
|
|
|
private PP_PlatformClientFactory ppPlatformClientFactory => pplatformClientFactoryLazy.Value; |
|
|
private PP_PlatformClientFactory ppPlatformClientFactory => pplatformClientFactoryLazy.Value; |
|
|
private TaskSchedulerManager taskSchedulerManager => taskSchedulerManagerLazy.Value; |
|
|
private TaskSchedulerManager taskSchedulerManager => taskSchedulerManagerLazy.Value; |
|
@ -41,6 +44,7 @@ namespace BBWYB.Server.Business |
|
|
private DingDingBusiness dingDingBusiness => dingDingBusinessLazy.Value; |
|
|
private DingDingBusiness dingDingBusiness => dingDingBusinessLazy.Value; |
|
|
private QiKuManager qiKuManager => qiKuManagerLazy.Value; |
|
|
private QiKuManager qiKuManager => qiKuManagerLazy.Value; |
|
|
private RestApiService restApiService => restApiServiceLazy.Value; |
|
|
private RestApiService restApiService => restApiServiceLazy.Value; |
|
|
|
|
|
private OP_PlatformClientFactory opPlatformClientFactory => opPlatformClientFactoryLazy.Value; |
|
|
|
|
|
|
|
|
private JDBusiness jdBusiness => jdBusinessLazy.Value; |
|
|
private JDBusiness jdBusiness => jdBusinessLazy.Value; |
|
|
|
|
|
|
|
@ -60,6 +64,8 @@ namespace BBWYB.Server.Business |
|
|
qiKuManagerLazy = new Lazy<QiKuManager>(() => serviceProvider.GetService<QiKuManager>()); |
|
|
qiKuManagerLazy = new Lazy<QiKuManager>(() => serviceProvider.GetService<QiKuManager>()); |
|
|
restApiServiceLazy = new Lazy<RestApiService>(() => serviceProvider.GetService<RestApiService>()); |
|
|
restApiServiceLazy = new Lazy<RestApiService>(() => serviceProvider.GetService<RestApiService>()); |
|
|
jdBusinessLazy = new Lazy<JDBusiness>(() => serviceProvider.GetService<JDBusiness>()); |
|
|
jdBusinessLazy = new Lazy<JDBusiness>(() => serviceProvider.GetService<JDBusiness>()); |
|
|
|
|
|
opPlatformClientFactoryLazy = new Lazy<OP_PlatformClientFactory>(() => serviceProvider.GetService<OP_PlatformClientFactory>()); |
|
|
|
|
|
|
|
|
cantPurchaseOrderStateList = new List<Enums.OrderState>() |
|
|
cantPurchaseOrderStateList = new List<Enums.OrderState>() |
|
|
{ |
|
|
{ |
|
|
Enums.OrderState.已取消, |
|
|
Enums.OrderState.已取消, |
|
@ -2369,8 +2375,7 @@ namespace BBWYB.Server.Business |
|
|
/// <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; |
|
|
bool isEditOrderPrice = true; |
|
|
|
|
|
|
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
|
var orderPurchaseInfo = fsql.Select<OrderPurchaseInfo>().Where(opi => opi.PurchaseOrderId == purchaseOrderId).ToOne(); |
|
|
var orderPurchaseInfo = fsql.Select<OrderPurchaseInfo>().Where(opi => opi.PurchaseOrderId == purchaseOrderId).ToOne(); |
|
@ -2386,6 +2391,8 @@ namespace BBWYB.Server.Business |
|
|
if (dbOrderCost == null) |
|
|
if (dbOrderCost == null) |
|
|
throw new Exception($"采购单{purchaseOrderId}-未查询到订单{orderPurchaseInfo.OrderId}的成本"); |
|
|
throw new Exception($"采购单{purchaseOrderId}-未查询到订单{orderPurchaseInfo.OrderId}的成本"); |
|
|
|
|
|
|
|
|
|
|
|
var shop = fsqlManager.MDSfsql.Select<Shops>().Where(s => s.ShopId == dbOrder.ShopId.ToString()).ToOne(); |
|
|
|
|
|
|
|
|
var dbOrderCostDetails = fsql.Select<OrderCostDetail>().Where(ocd => ocd.OrderId == dbOrder.Id && ocd.IsEnabled == true).ToList(); |
|
|
var dbOrderCostDetails = fsql.Select<OrderCostDetail>().Where(ocd => ocd.OrderId == dbOrder.Id && ocd.IsEnabled == true).ToList(); |
|
|
if (dbOrderCostDetails.Count() == 0) |
|
|
if (dbOrderCostDetails.Count() == 0) |
|
|
throw new Exception($"采购单{purchaseOrderId}-未查询到订单{orderPurchaseInfo.OrderId}的明细成本"); |
|
|
throw new Exception($"采购单{purchaseOrderId}-未查询到订单{orderPurchaseInfo.OrderId}的明细成本"); |
|
@ -2395,23 +2402,34 @@ namespace BBWYB.Server.Business |
|
|
if (dbOrderPurchaseInfoList.Count() == 0) |
|
|
if (dbOrderPurchaseInfoList.Count() == 0) |
|
|
throw new Exception($"采购单{purchaseOrderId}-未查询到订单{orderPurchaseInfo.OrderId}的采购单集合"); |
|
|
throw new Exception($"采购单{purchaseOrderId}-未查询到订单{orderPurchaseInfo.OrderId}的采购单集合"); |
|
|
|
|
|
|
|
|
|
|
|
isEditOrderPrice = dbOrderPurchaseInfoList.Count() == dbOrderPurchaseInfoList.Count(opi => opi.PurchasePlatform == Enums.Platform.阿里巴巴 && |
|
|
|
|
|
opi.PurchaseMethod == Enums.PurchaseMethod.线上采购); |
|
|
|
|
|
|
|
|
var dbPurchaseOrderIdList = dbOrderPurchaseInfoList.Select(x => x.PurchaseOrderId).ToList(); |
|
|
var dbPurchaseOrderIdList = dbOrderPurchaseInfoList.Select(x => x.PurchaseOrderId).ToList(); |
|
|
var dbOrderPurchaseRelationInfos = fsql.Select<OrderPurchaseRelationInfo>().Where(x => dbPurchaseOrderIdList.Contains(x.PurchaseOrderId)).ToList(); |
|
|
var dbOrderPurchaseRelationInfos = fsql.Select<OrderPurchaseRelationInfo>().Where(x => dbPurchaseOrderIdList.Contains(x.PurchaseOrderId)).ToList(); |
|
|
if (dbOrderPurchaseRelationInfos.Count() == 0) |
|
|
if (dbOrderPurchaseRelationInfos.Count() == 0) |
|
|
throw new Exception($"采购单{purchaseOrderId}-未查询到采购单关联明细,手动关联的采购单不支持改价"); |
|
|
throw new Exception($"采购单{purchaseOrderId}-未查询到采购单关联明细"); |
|
|
|
|
|
|
|
|
var dbOrderSkus = fsql.Select<OrderSku>().Where(osku => osku.OrderId == orderPurchaseInfo.OrderId).ToList(); |
|
|
var dbOrderSkus = fsql.Select<OrderSku>().Where(osku => osku.OrderId == orderPurchaseInfo.OrderId).ToList(); |
|
|
|
|
|
|
|
|
List<IUpdate<OrderCostDetail>> updateOrderCostDetailList = new List<IUpdate<OrderCostDetail>>(); |
|
|
List<IUpdate<OrderCostDetail>> updateOrderCostDetailList = new List<IUpdate<OrderCostDetail>>(); |
|
|
IUpdate<OrderCost> updateOrderCost = null; |
|
|
IUpdate<OrderCost> updateOrderCost = null; |
|
|
|
|
|
|
|
|
var client = ppPlatformClientFactory.GetClient(AdapterEnums.PlatformType.阿里巴巴); |
|
|
IList<IUpdate<OrderSku>> updateOrderSkuList = new List<IUpdate<OrderSku>>(); |
|
|
|
|
|
IUpdate<Order> updateOrder = null; |
|
|
|
|
|
|
|
|
|
|
|
IList<OP_EditPriceSkuRequest> op_EditPriceSkuRequests = new List<OP_EditPriceSkuRequest>(); |
|
|
|
|
|
|
|
|
|
|
|
var ppclient = ppPlatformClientFactory.GetClient(AdapterEnums.PlatformType.阿里巴巴); |
|
|
|
|
|
|
|
|
var totalPurchaseProductAmount = 0M; |
|
|
var totalPurchaseProductAmount = 0M; |
|
|
var totalPurchaseFreight = 0M; |
|
|
var totalPurchaseFreight = 0M; |
|
|
foreach (var opi in dbOrderPurchaseInfoList) |
|
|
foreach (var opi in dbOrderPurchaseInfoList) |
|
|
{ |
|
|
{ |
|
|
var purchaseOrderSimpleInfo = client.QueryOrderDetail(new PP_QueryOrderDetailRequest() |
|
|
if (opi.PurchasePlatform != Enums.Platform.阿里巴巴) |
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
|
|
var purchaseOrderSimpleInfo = ppclient.QueryOrderDetail(new PP_QueryOrderDetailRequest() |
|
|
{ |
|
|
{ |
|
|
AppKey = purchaseAccount.AppKey, |
|
|
AppKey = purchaseAccount.AppKey, |
|
|
AppSecret = purchaseAccount.AppSecret, |
|
|
AppSecret = purchaseAccount.AppSecret, |
|
@ -2429,6 +2447,7 @@ namespace BBWYB.Server.Business |
|
|
foreach (var belongSkuGroup in belongSkuGroups) |
|
|
foreach (var belongSkuGroup in belongSkuGroups) |
|
|
{ |
|
|
{ |
|
|
var belongSkuId = belongSkuGroup.Key; |
|
|
var belongSkuId = belongSkuGroup.Key; |
|
|
|
|
|
|
|
|
var currentOrderSkuCargoParamList = belongSkuGroup.ToList(); //找当前skuId的采购skuId
|
|
|
var currentOrderSkuCargoParamList = belongSkuGroup.ToList(); //找当前skuId的采购skuId
|
|
|
var currentOrderSkuProductAmount = 0M; //采购成本
|
|
|
var currentOrderSkuProductAmount = 0M; //采购成本
|
|
|
var currentSkuTotalPurchaseQuantity = currentOrderSkuCargoParamList.Sum(x => x.Quantity); //当前skuId的采购数量总和
|
|
|
var currentSkuTotalPurchaseQuantity = currentOrderSkuCargoParamList.Sum(x => x.Quantity); //当前skuId的采购数量总和
|
|
@ -2444,12 +2463,26 @@ namespace BBWYB.Server.Business |
|
|
currentOrderSkuProductAmount += currentPurchaseSkuProductAmount * (1.0M * currentOrderSkuCargo.Quantity.Value / currentPurchaseSkuTotalQuantity); |
|
|
currentOrderSkuProductAmount += currentPurchaseSkuProductAmount * (1.0M * currentOrderSkuCargo.Quantity.Value / currentPurchaseSkuTotalQuantity); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var dbOrderSkuDetail = dbOrderCostDetails.FirstOrDefault(ocd => ocd.SkuId == belongSkuId); |
|
|
#region 订单sku平价
|
|
|
var orderSku = dbOrderSkus.FirstOrDefault(osku => osku.SkuId == belongSkuId); |
|
|
var orderSku = dbOrderSkus.FirstOrDefault(osku => osku.SkuId == belongSkuId); |
|
|
//dbOrderSkuDetail.SkuAmount = currentOrderSkuProductAmount;
|
|
|
if (isEditOrderPrice) |
|
|
//dbOrderSkuDetail.PurchaseFreight = currentOrderSkuFreightAmount;
|
|
|
{ |
|
|
//dbOrderSkuDetail.TotalCost = currentOrderSkuProductAmount + currentOrderSkuFreightAmount;
|
|
|
orderSku.Price = currentOrderSkuProductAmount / orderSku.ItemTotal; |
|
|
|
|
|
orderSku.BuyerPayFreight = currentPurchaseFreight; |
|
|
|
|
|
op_EditPriceSkuRequests.Add(new OP_EditPriceSkuRequest() |
|
|
|
|
|
{ |
|
|
|
|
|
Freight = currentPurchaseFreight ?? 0M, |
|
|
|
|
|
InPackAmountPrice = orderSku.InPackAmount ?? 0M, |
|
|
|
|
|
OrderSkuId = orderSku.Id.ToString(), |
|
|
|
|
|
Price = orderSku.Price ?? 0M, |
|
|
|
|
|
SkuId = orderSku.SkuId |
|
|
|
|
|
}); |
|
|
|
|
|
updateOrderSkuList.Add(fsql.Update<OrderSku>(orderSku.Id).Set(osku => osku.Price, orderSku.Price) |
|
|
|
|
|
.Set(osku => osku.BuyerPayFreight, orderSku.BuyerPayFreight)); |
|
|
|
|
|
} |
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
var dbOrderSkuDetail = dbOrderCostDetails.FirstOrDefault(ocd => ocd.SkuId == belongSkuId && ocd.PurchaseOrderId == opi.PurchaseOrderId); |
|
|
dbOrderSkuDetail.CalculationOrderCostDetailCostAndProfit(orderSku.Price.Value * orderSku.ItemTotal.Value, |
|
|
dbOrderSkuDetail.CalculationOrderCostDetailCostAndProfit(orderSku.Price.Value * orderSku.ItemTotal.Value, |
|
|
orderSku.BuyerPayFreight ?? 0M, |
|
|
orderSku.BuyerPayFreight ?? 0M, |
|
|
orderSku.InPackAmount ?? 0M, |
|
|
orderSku.InPackAmount ?? 0M, |
|
@ -2459,31 +2492,61 @@ namespace BBWYB.Server.Business |
|
|
dbOrderSkuDetail.DeliveryExpressFreight ?? 0M); |
|
|
dbOrderSkuDetail.DeliveryExpressFreight ?? 0M); |
|
|
updateOrderCostDetailList.Add(fsql.Update<OrderCostDetail>().SetSource(dbOrderSkuDetail)); |
|
|
updateOrderCostDetailList.Add(fsql.Update<OrderCostDetail>().SetSource(dbOrderSkuDetail)); |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if (isEditOrderPrice) |
|
|
|
|
|
{ |
|
|
|
|
|
dbOrder.OrderTotalPrice = totalPurchaseProductAmount + totalPurchaseFreight; |
|
|
|
|
|
dbOrder.OrderSellerPrice = totalPurchaseProductAmount; |
|
|
|
|
|
dbOrder.FreightPrice = totalPurchaseFreight; |
|
|
|
|
|
updateOrder = fsql.Update<Order>(dbOrder.Id).Set(o => o.OrderTotalPrice, dbOrder.OrderTotalPrice) |
|
|
|
|
|
.Set(o => o.OrderSellerPrice, dbOrder.OrderSellerPrice) |
|
|
|
|
|
.Set(o => o.FreightPrice, dbOrder.FreightPrice); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
//dbOrderCost.TotalCost = dbOrderCost.PurchaseAmount = totalPurchaseAmount;
|
|
|
dbOrderCost.CalculationOrderCostCostAndProfit(dbOrder.OrderTotalPrice ?? 0M, |
|
|
//dbOrderCost.Profit = dbOrder.OrderTotalPrice -
|
|
|
totalPurchaseProductAmount, |
|
|
// dbOrderCost.PurchaseAmount -
|
|
|
totalPurchaseFreight, |
|
|
// dbOrderCost.DeliveryExpressFreight;
|
|
|
dbOrderCostDetails.Sum(ocd => ocd.OutPackAmount ?? 0M), |
|
|
|
|
|
dbOrderCostDetails.Sum(ocd => ocd.DeliveryExpressFreight ?? 0M)); |
|
|
|
|
|
updateOrderCost = fsql.Update<OrderCost>().SetSource(dbOrderCost); |
|
|
|
|
|
|
|
|
|
|
|
fsql.Transaction(() => |
|
|
|
|
|
{ |
|
|
|
|
|
foreach (var update in updateOrderCostDetailList) |
|
|
|
|
|
update.ExecuteAffrows(); |
|
|
|
|
|
updateOrderCost?.ExecuteAffrows(); |
|
|
|
|
|
foreach (var update in updateOrderSkuList) |
|
|
|
|
|
update.ExecuteAffrows(); |
|
|
|
|
|
updateOrder?.ExecuteAffrows(); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
dbOrderCost.CalculationOrderCostCostAndProfit(dbOrder.OrderTotalPrice ?? 0M, |
|
|
|
|
|
totalPurchaseProductAmount, |
|
|
|
|
|
totalPurchaseFreight, |
|
|
|
|
|
dbOrderCostDetails.Sum(ocd => ocd.OutPackAmount ?? 0M), |
|
|
|
|
|
dbOrderCostDetails.Sum(ocd => ocd.DeliveryExpressFreight ?? 0M)); |
|
|
|
|
|
updateOrderCost = fsql.Update<OrderCost>().SetSource(dbOrderCost); |
|
|
|
|
|
|
|
|
|
|
|
fsql.Transaction(() => |
|
|
if (isEditOrderPrice) |
|
|
|
|
|
{ |
|
|
|
|
|
#region 通知拳探改价
|
|
|
|
|
|
var opclient = opPlatformClientFactory.GetClient(AdapterEnums.PlatformType.拳探); |
|
|
|
|
|
opclient.EditPrice(new OP_EditPriceRequest() |
|
|
{ |
|
|
{ |
|
|
foreach (var update in updateOrderCostDetailList) |
|
|
AppKey = shop.AppKey, |
|
|
update.ExecuteAffrows(); |
|
|
AppSecret = shop.AppSecret, |
|
|
updateOrderCost?.ExecuteAffrows(); |
|
|
AppToken = shop.AppToken, |
|
|
|
|
|
OrderId = dbOrder.Id, |
|
|
|
|
|
EditItems = op_EditPriceSkuRequests |
|
|
}); |
|
|
}); |
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 通知C端改价
|
|
|
|
|
|
restApiService.SendRequest("https://bbwy.qiyue666.com", |
|
|
|
|
|
"/Api/PurchaseOrder/QuanTanEditPriceCallback", |
|
|
|
|
|
new { orderId = dbOrder.Id }, |
|
|
|
|
|
null, |
|
|
|
|
|
HttpMethod.Post); |
|
|
|
|
|
#endregion
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
catch (Exception ex) |
|
|
catch (Exception ex) |
|
|
{ |
|
|
{ |
|
|
nLogManager.Default().Error(ex, $"OrderPriceModificationCallback 回调平台{callbackPlatform},采购单号{purchaseOrderId},执行进度[{currentProgress}]"); |
|
|
nLogManager.Default().Error(ex, $"OrderPriceModificationCallback 回调平台{callbackPlatform},采购单号{purchaseOrderId}"); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|