|
|
@ -2,6 +2,7 @@ |
|
|
|
using BBWY.Common.Models; |
|
|
|
using BBWY.Server.Model.Db; |
|
|
|
using BBWY.Server.Model.Dto; |
|
|
|
using FreeSql; |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
@ -74,10 +75,117 @@ namespace BBWY.Server.Business |
|
|
|
{ |
|
|
|
if (createOnlinePurchaseOrderRequest.Platform != Model.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 orderSku = fsql.Select<OrderSku>().Where(osku => osku.OrderId == createOnlinePurchaseOrderRequest.OrderId).ToOne(); |
|
|
|
if (orderSku == null) |
|
|
|
throw new BusinessException("订单Sku不存在"); |
|
|
|
|
|
|
|
var createOrderResponse = platformSDKBusinessList.FirstOrDefault(p => p.Platform == createOnlinePurchaseOrderRequest.Platform) |
|
|
|
.FastCreateOrder(createOnlinePurchaseOrderRequest); |
|
|
|
|
|
|
|
IInsert<PurchaseOrder> insertPurchaseOrder = null; |
|
|
|
IInsert<OrderCostDetail> insertOrderCostDetail = null; |
|
|
|
IInsert<OrderCost> insertOrderCost = null; |
|
|
|
IInsert<OrderDropShipping> insertOrderDropShipping = null; |
|
|
|
|
|
|
|
#region 采购单
|
|
|
|
var purchaseOrder = new PurchaseOrder() |
|
|
|
{ |
|
|
|
Id = idGenerator.NewLong(), |
|
|
|
CreateTime = DateTime.Now, |
|
|
|
ProductId = orderSku.ProductId, |
|
|
|
SkuId = orderSku.SkuId, |
|
|
|
PurchaseMethod = Model.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 = createOrderResponse.ProductAmount / orderSku.ItemTotal.Value, |
|
|
|
SingleFreight = createOrderResponse.FreightAmount / orderSku.ItemTotal.Value, |
|
|
|
StorageType = Model.Enums.StorageType.代发 |
|
|
|
}; |
|
|
|
insertPurchaseOrder = fsql.Insert(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 = createOrderResponse.FreightAmount, |
|
|
|
PurchaseOrderPKId = purchaseOrder.Id, |
|
|
|
SkuAmount = createOrderResponse.ProductAmount, |
|
|
|
SkuId = orderSku.SkuId, |
|
|
|
StorageAmount = 0, |
|
|
|
UnitCost = purchaseOrder.UnitCost, |
|
|
|
TotalCost = createOrderResponse.TotalAmount //purchaseOrder.UnitCost * orderSku.ItemTotal.Value
|
|
|
|
}; |
|
|
|
insertOrderCostDetail = fsql.Insert(orderCostDetail); |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 订单成本
|
|
|
|
var orderCost = new OrderCost() |
|
|
|
{ |
|
|
|
OrderId = orderSku.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, |
|
|
|
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).Set(o => o.OrderState, Model.Enums.OrderState.待出库) |
|
|
|
.Set(o => o.StorageType, Model.Enums.StorageType.代发) |
|
|
|
.ExecuteAffrows(); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|