|
|
@ -130,7 +130,7 @@ namespace BBWY.Server.Business |
|
|
|
CreateTime = DateTime.Now, |
|
|
|
ProductId = orderSku.ProductId, |
|
|
|
SkuId = orderSku.SkuId, |
|
|
|
PurchaseMethod = Model.Enums.PurchaseMethod.线上采购, |
|
|
|
PurchaseMethod = Enums.PurchaseMethod.线上采购, |
|
|
|
PurchaseOrderId = createOrderResponse.PurchaseOrderId, |
|
|
|
PurchasePlatform = createOnlinePurchaseOrderRequest.Platform, |
|
|
|
PurchaseQuantity = orderSku.ItemTotal.Value, |
|
|
@ -143,7 +143,7 @@ namespace BBWY.Server.Business |
|
|
|
SingleOperationAmount = 0, |
|
|
|
SingleSkuAmount = createOrderResponse.ProductAmount / orderSku.ItemTotal.Value, |
|
|
|
SingleFreight = createOrderResponse.FreightAmount / orderSku.ItemTotal.Value, |
|
|
|
StorageType = Model.Enums.StorageType.代发 |
|
|
|
StorageType = Enums.StorageType.代发 |
|
|
|
}; |
|
|
|
insertPurchaseOrder = fsql.Insert(purchaseOrder); |
|
|
|
#endregion
|
|
|
@ -220,6 +220,146 @@ namespace BBWY.Server.Business |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
public void NewFastCreateOrder(CreateOnlinePurchaseOrderRequest createOnlinePurchaseOrderRequest) |
|
|
|
{ |
|
|
|
if (createOnlinePurchaseOrderRequest.Platform != Enums.Platform.阿里巴巴) |
|
|
|
throw new NotImplementedException(); |
|
|
|
var dbOrder = fsql.Select<Order>(createOnlinePurchaseOrderRequest.OrderId).ToOne(); |
|
|
|
if (dbOrder == null) |
|
|
|
throw new BusinessException("订单不存在"); |
|
|
|
if (dbOrder.OrderState != Model.Enums.OrderState.等待采购) |
|
|
|
throw new BusinessException("只能为等待采购的订单进行采购"); |
|
|
|
|
|
|
|
var orderSkus = fsql.Select<OrderSku>().Where(osku => osku.OrderId == createOnlinePurchaseOrderRequest.OrderId).ToList(); |
|
|
|
|
|
|
|
var createOrderResponse = platformSDKBusinessList.FirstOrDefault(p => p.Platform == createOnlinePurchaseOrderRequest.Platform) |
|
|
|
.FastCreateOrder(createOnlinePurchaseOrderRequest); |
|
|
|
|
|
|
|
|
|
|
|
var purchaseOrderSimpleInfo = platformSDKBusinessList.FirstOrDefault(p => p.Platform == createOnlinePurchaseOrderRequest.Platform).GetOrderSimpleInfo(new GetOrderInfoRequest() |
|
|
|
{ |
|
|
|
AppKey = createOnlinePurchaseOrderRequest.AppKey, |
|
|
|
AppSecret = createOnlinePurchaseOrderRequest.AppSecret, |
|
|
|
AppToken = createOnlinePurchaseOrderRequest.AppToken, |
|
|
|
OrderId = createOrderResponse.PurchaseOrderId, |
|
|
|
Platform = createOnlinePurchaseOrderRequest.Platform |
|
|
|
}); |
|
|
|
|
|
|
|
List<PurchaseOrder> insertPurchaseOrders = new List<PurchaseOrder>(); |
|
|
|
List<OrderCostDetail> insertOrderCostDetails = new List<OrderCostDetail>(); |
|
|
|
List<PurchaseOrderDetail> insertPurchaseOrderDetails = new List<PurchaseOrderDetail>(); |
|
|
|
|
|
|
|
IInsert<OrderCost> insertOrderCost = null; |
|
|
|
IInsert<OrderDropShipping> insertOrderDropShipping = null; |
|
|
|
foreach (var orderSku in orderSkus) |
|
|
|
{ |
|
|
|
#region 计算当前sku的采购成本和采购运费
|
|
|
|
var currentOrderSkuProductAmount = 0M; //采购成本
|
|
|
|
var currentOrderSkuCargoParamList = createOnlinePurchaseOrderRequest.CargoParamList.Where(p => p.BelongSkuId == orderSku.SkuId); //找当前skuId的采购skuId
|
|
|
|
currentOrderSkuProductAmount = purchaseOrderSimpleInfo.ItemList.Where(p => currentOrderSkuCargoParamList.Any(p1 => p1.SkuId == p.SkuId)) |
|
|
|
?.Sum(p => p.ProductAmount) ?? 0M; |
|
|
|
|
|
|
|
var currentOrderSkuFreightAmount = purchaseOrderSimpleInfo.FreightAmount / orderSkus.Count(); //采购运费(按sku数均分)
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 采购单
|
|
|
|
var purchaseOrder = new PurchaseOrder() |
|
|
|
{ |
|
|
|
Id = idGenerator.NewLong(), |
|
|
|
CreateTime = DateTime.Now, |
|
|
|
ProductId = orderSku.ProductId, |
|
|
|
SkuId = orderSku.SkuId, |
|
|
|
PurchaseMethod = Enums.PurchaseMethod.线上采购, |
|
|
|
PurchaseOrderId = createOrderResponse.PurchaseOrderId, |
|
|
|
PurchasePlatform = createOnlinePurchaseOrderRequest.Platform, |
|
|
|
PurchaseQuantity = orderSku.ItemTotal.Value, |
|
|
|
RemainingQuantity = 0, |
|
|
|
ShopId = createOnlinePurchaseOrderRequest.ShopId, |
|
|
|
SingleConsumableAmount = 0, |
|
|
|
SingleDeliveryFreight = 0, |
|
|
|
SingleFirstFreight = 0, |
|
|
|
SingleStorageAmount = 0, |
|
|
|
SingleOperationAmount = 0, |
|
|
|
SingleSkuAmount = currentOrderSkuProductAmount / orderSku.ItemTotal.Value, |
|
|
|
SingleFreight = currentOrderSkuFreightAmount / orderSku.ItemTotal.Value, |
|
|
|
StorageType = Enums.StorageType.代发 |
|
|
|
}; |
|
|
|
insertPurchaseOrders.Add(purchaseOrder); |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 成本明细
|
|
|
|
var orderCostDetail = new OrderCostDetail() |
|
|
|
{ |
|
|
|
Id = idGenerator.NewLong(), |
|
|
|
ConsumableAmount = 0, |
|
|
|
CreateTime = DateTime.Now, |
|
|
|
DeductionQuantity = orderSku.ItemTotal.Value, |
|
|
|
DeliveryExpressFreight = 0, |
|
|
|
FirstFreight = 0, |
|
|
|
OperationAmount = 0, |
|
|
|
OrderId = createOnlinePurchaseOrderRequest.OrderId, |
|
|
|
ProductId = orderSku.ProductId, |
|
|
|
PurchaseFreight = currentOrderSkuFreightAmount, |
|
|
|
PurchaseOrderPKId = purchaseOrder.Id, |
|
|
|
SkuAmount = currentOrderSkuProductAmount, |
|
|
|
SkuId = orderSku.SkuId, |
|
|
|
StorageAmount = 0, |
|
|
|
UnitCost = purchaseOrder.UnitCost, |
|
|
|
TotalCost = currentOrderSkuProductAmount + currentOrderSkuFreightAmount//purchaseOrder.UnitCost * orderSku.ItemTotal.Value
|
|
|
|
}; |
|
|
|
insertOrderCostDetail = fsql.Insert(orderCostDetail); |
|
|
|
#endregion
|
|
|
|
} |
|
|
|
|
|
|
|
#region 订单成本
|
|
|
|
var orderCost = new OrderCost() |
|
|
|
{ |
|
|
|
OrderId = createOnlinePurchaseOrderRequest.OrderId, |
|
|
|
CreateTime = DateTime.Now, |
|
|
|
DeliveryExpressFreight = 0, |
|
|
|
IsManualEdited = false, |
|
|
|
PlatformCommissionRatio = 0.05M, |
|
|
|
PreferentialAmount = dbOrder.PreferentialAmount, |
|
|
|
SDCommissionAmount = 0, |
|
|
|
PurchaseAmount = createOrderResponse.TotalAmount |
|
|
|
}; |
|
|
|
orderCost.PlatformCommissionAmount = dbOrder.OrderSellerPrice * orderCost.PlatformCommissionRatio; |
|
|
|
orderCost.Profit = dbOrder.OrderSellerPrice + |
|
|
|
dbOrder.FreightPrice - |
|
|
|
orderCost.PurchaseAmount - |
|
|
|
orderCost.DeliveryExpressFreight - |
|
|
|
orderCost.PlatformCommissionAmount; |
|
|
|
insertOrderCost = fsql.Insert(orderCost); |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 采购信息
|
|
|
|
var orderDropShipping = new OrderDropShipping() |
|
|
|
{ |
|
|
|
OrderId = createOnlinePurchaseOrderRequest.OrderId, |
|
|
|
PurchaseAccountId = createOnlinePurchaseOrderRequest.PurchaseAccountId, |
|
|
|
BuyerAccount = createOnlinePurchaseOrderRequest.BuyerAccount, |
|
|
|
SellerAccount = createOnlinePurchaseOrderRequest.SellerAccount, |
|
|
|
CreateTime = DateTime.Now, |
|
|
|
DeliveryFreight = 0, |
|
|
|
PurchaseAmount = createOrderResponse.TotalAmount, |
|
|
|
PurchaseOrderId = createOrderResponse.PurchaseOrderId, |
|
|
|
PurchasePlatform = createOnlinePurchaseOrderRequest.Platform |
|
|
|
}; |
|
|
|
insertOrderDropShipping = fsql.Insert(orderDropShipping); |
|
|
|
#endregion
|
|
|
|
|
|
|
|
fsql.Transaction(() => |
|
|
|
{ |
|
|
|
insertPurchaseOrder.ExecuteAffrows(); |
|
|
|
insertOrderCostDetail.ExecuteAffrows(); |
|
|
|
insertOrderCost.ExecuteAffrows(); |
|
|
|
insertOrderDropShipping.ExecuteAffrows(); |
|
|
|
fsql.Update<Order>(createOnlinePurchaseOrderRequest.OrderId).SetIf(dbOrder.OrderState == Enums.OrderState.等待采购, o => o.OrderState, Model.Enums.OrderState.待出库) |
|
|
|
.Set(o => o.StorageType, Model.Enums.StorageType.代发) |
|
|
|
.ExecuteAffrows(); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
#region CallBack
|
|
|
|
|
|
|
|
#region 1688CallBack
|
|
|
@ -242,18 +382,6 @@ namespace BBWY.Server.Business |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 1688发货回调(即将废弃)
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="jsonStr"></param>
|
|
|
|
public void DeliveryCallbackFrom1688(string jsonStr) |
|
|
|
{ |
|
|
|
logger.Info(jsonStr); |
|
|
|
var orderJObject = JObject.Parse(jsonStr); |
|
|
|
var purchaseOrderId = orderJObject["data"].Value<string>("orderId"); |
|
|
|
Task.Factory.StartNew(() => DeliveryCallback(purchaseOrderId, Enums.Platform.阿里巴巴), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.PurchaseOrderCallbackTaskScheduler); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 1688发货回调
|
|
|
|
/// </summary>
|
|
|
|