|
|
@ -734,171 +734,6 @@ namespace BBWY.Server.Business |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 关联外部订单
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="relationPurchaseOrderRequest"></param>
|
|
|
|
public void RelationPurchaseOrder(RelationPurchaseOrderRequest relationPurchaseOrderRequest) |
|
|
|
{ |
|
|
|
var dbOrder = fsql.Select<Order>(relationPurchaseOrderRequest.OrderDropShipping.OrderId).ToOne(); |
|
|
|
if (dbOrder == null) |
|
|
|
throw new BusinessException($"订单号{relationPurchaseOrderRequest.OrderDropShipping.OrderId}不存在"); |
|
|
|
|
|
|
|
if (relationPurchaseOrderRequest.PlatformCommissionRatio == 0M) |
|
|
|
relationPurchaseOrderRequest.PlatformCommissionRatio = 0.05M; |
|
|
|
|
|
|
|
IInsert<OrderDropShipping> insertOrderDropShipping = null; |
|
|
|
IUpdate<OrderDropShipping> updateOrderDropShipping = null; |
|
|
|
IInsert<OrderCost> insertOrderCost = null; |
|
|
|
IUpdate<OrderCost> updateOrderCost = null; |
|
|
|
IDelete<PurchaseOrder> deletePurchaseOrder = null; |
|
|
|
IDelete<OrderCostDetail> deleteOrderCostDetail = null; |
|
|
|
IUpdate<OrderSku> updateOrderSku = null; |
|
|
|
List<PurchaseOrder> insertPurchaseOrderList = new List<PurchaseOrder>(); |
|
|
|
List<OrderCostDetail> insertOrderCostDetailList = new List<OrderCostDetail>(); |
|
|
|
|
|
|
|
|
|
|
|
#region 代发信息表
|
|
|
|
var dbOrderDropShipping = fsql.Select<OrderDropShipping>().Where(ods => ods.OrderId == relationPurchaseOrderRequest.OrderDropShipping.OrderId).ToOne(); |
|
|
|
if (dbOrderDropShipping == null) |
|
|
|
{ |
|
|
|
var orderDropShipping = relationPurchaseOrderRequest.OrderDropShipping.Map<OrderDropShipping>(); |
|
|
|
orderDropShipping.CreateTime = DateTime.Now; |
|
|
|
orderDropShipping.ShopId = dbOrder.ShopId; |
|
|
|
orderDropShipping.Id = idGenerator.NewLong(); |
|
|
|
insertOrderDropShipping = fsql.Insert(orderDropShipping); |
|
|
|
updateOrderSku = fsql.Update<OrderSku>().Set(osku => osku.OrderDropShippingId, orderDropShipping.Id) |
|
|
|
.Where(osku => osku.OrderId == dbOrder.Id); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
var orderDropShippingId = dbOrderDropShipping.Id; |
|
|
|
relationPurchaseOrderRequest.OrderDropShipping.Map(dbOrderDropShipping); |
|
|
|
dbOrderDropShipping.Id = orderDropShippingId; |
|
|
|
updateOrderDropShipping = fsql.Update<OrderDropShipping>().IgnoreColumns(new string[] { "CreateTime" }).SetSource(dbOrderDropShipping); |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 采购单表
|
|
|
|
var oldPourchaseIdList = fsql.Select<OrderCostDetail>().Where(ocd => ocd.OrderId == relationPurchaseOrderRequest.OrderDropShipping.OrderId) |
|
|
|
.ToList(ocd => ocd.PurchaseOrderPKId); |
|
|
|
deletePurchaseOrder = fsql.Delete<PurchaseOrder>().Where(po => oldPourchaseIdList.Contains(po.Id)); |
|
|
|
insertPurchaseOrderList.AddRange(relationPurchaseOrderRequest.RelationPurchaseOrderSkuList.Select(x => new PurchaseOrder() |
|
|
|
{ |
|
|
|
Id = idGenerator.NewLong(), |
|
|
|
CreateTime = DateTime.Now, |
|
|
|
ProductId = x.ProductId, |
|
|
|
PurchaseMethod = Enums.PurchaseMethod.线下采购, |
|
|
|
StorageType = Enums.StorageType.代发, |
|
|
|
PurchaseOrderId = relationPurchaseOrderRequest.OrderDropShipping.PurchaseOrderId, |
|
|
|
PurchasePlatform = relationPurchaseOrderRequest.OrderDropShipping.PurchasePlatform, |
|
|
|
PurchaseQuantity = x.Quantity, |
|
|
|
RemainingQuantity = 0, |
|
|
|
ShopId = dbOrder.ShopId, |
|
|
|
SkuId = x.SkuId, |
|
|
|
SingleConsumableAmount = 0, |
|
|
|
SingleFirstFreight = 0, |
|
|
|
SingleFreight = relationPurchaseOrderRequest.OrderDropShipping.PurchaseFreight / relationPurchaseOrderRequest.RelationPurchaseOrderSkuList.Count() / x.Quantity, |
|
|
|
SingleOperationAmount = 0, |
|
|
|
SingleStorageAmount = 0, |
|
|
|
SingleSkuAmount = x.SingleSkuAmount, |
|
|
|
SingleDeliveryFreight = 0 |
|
|
|
})); |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 订单成本表
|
|
|
|
var orderCost = fsql.Select<OrderCost>(relationPurchaseOrderRequest.OrderDropShipping.OrderId).ToOne(); |
|
|
|
if (orderCost != null) |
|
|
|
{ |
|
|
|
orderCost.PlatformCommissionRatio = relationPurchaseOrderRequest.PlatformCommissionRatio; |
|
|
|
orderCost.PlatformCommissionAmount = dbOrder.OrderSellerPrice * relationPurchaseOrderRequest.PlatformCommissionRatio; |
|
|
|
orderCost.DeliveryExpressFreight = relationPurchaseOrderRequest.OrderDropShipping.DeliveryFreight; |
|
|
|
orderCost.PurchaseAmount = relationPurchaseOrderRequest.OrderDropShipping.PurchaseAmount; |
|
|
|
orderCost.Profit = dbOrder.OrderSellerPrice + |
|
|
|
dbOrder.FreightPrice - |
|
|
|
orderCost.PurchaseAmount - |
|
|
|
orderCost.DeliveryExpressFreight - |
|
|
|
orderCost.PlatformCommissionAmount; |
|
|
|
updateOrderCost = fsql.Update<OrderCost>().SetSource(orderCost).IgnoreColumns(oc => new |
|
|
|
{ |
|
|
|
oc.CreateTime, |
|
|
|
oc.SDCommissionAmount, |
|
|
|
oc.PlatformCommissionAmount, |
|
|
|
oc.PlatformCommissionRatio |
|
|
|
}); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
var preferentialAmount = fsql.Select<OrderCoupon>().Where(oc => oc.OrderId == relationPurchaseOrderRequest.OrderDropShipping.OrderId) |
|
|
|
.ToAggregate(g => g.Sum(g.Key.CouponPrice)); |
|
|
|
orderCost = new OrderCost() |
|
|
|
{ |
|
|
|
OrderId = relationPurchaseOrderRequest.OrderDropShipping.OrderId, |
|
|
|
CreateTime = DateTime.Now, |
|
|
|
DeliveryExpressFreight = relationPurchaseOrderRequest.OrderDropShipping.DeliveryFreight, |
|
|
|
PlatformCommissionRatio = relationPurchaseOrderRequest.PlatformCommissionRatio, |
|
|
|
SDCommissionAmount = 0, |
|
|
|
PurchaseAmount = relationPurchaseOrderRequest.RelationPurchaseOrderSkuList.Sum(s => s.SingleSkuAmount * s.Quantity), |
|
|
|
PlatformCommissionAmount = dbOrder.OrderSellerPrice * relationPurchaseOrderRequest.PlatformCommissionRatio, |
|
|
|
PreferentialAmount = preferentialAmount, |
|
|
|
IsManualEdited = true |
|
|
|
}; |
|
|
|
|
|
|
|
orderCost.Profit = dbOrder.OrderSellerPrice + |
|
|
|
dbOrder.FreightPrice - |
|
|
|
orderCost.PurchaseAmount - |
|
|
|
orderCost.DeliveryExpressFreight - |
|
|
|
orderCost.PlatformCommissionAmount; |
|
|
|
insertOrderCost = fsql.Insert(orderCost); |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 订单成本明细表
|
|
|
|
var oldOrderCostDetailIdList = fsql.Select<OrderCostDetail>().Where(ocd => ocd.OrderId == relationPurchaseOrderRequest.OrderDropShipping.OrderId) |
|
|
|
.ToList(ocd => ocd.Id); |
|
|
|
deleteOrderCostDetail = fsql.Delete<OrderCostDetail>().Where(ocd => oldOrderCostDetailIdList.Contains(ocd.Id)); |
|
|
|
insertOrderCostDetailList.AddRange(relationPurchaseOrderRequest.RelationPurchaseOrderSkuList.Select(x => new OrderCostDetail() |
|
|
|
{ |
|
|
|
Id = idGenerator.NewLong(), |
|
|
|
ConsumableAmount = 0, |
|
|
|
CreateTime = DateTime.Now, |
|
|
|
DeductionQuantity = x.Quantity, |
|
|
|
DeliveryExpressFreight = 0, |
|
|
|
FirstFreight = 0, |
|
|
|
OperationAmount = 0, |
|
|
|
OrderId = relationPurchaseOrderRequest.OrderDropShipping.OrderId, |
|
|
|
ProductId = x.ProductId, |
|
|
|
PurchaseFreight = relationPurchaseOrderRequest.OrderDropShipping.PurchaseFreight / relationPurchaseOrderRequest.RelationPurchaseOrderSkuList.Count(), |
|
|
|
SkuAmount = x.SingleSkuAmount * x.Quantity, |
|
|
|
SkuId = x.SkuId, |
|
|
|
StorageAmount = 0, |
|
|
|
TotalCost = x.SingleSkuAmount * x.Quantity + relationPurchaseOrderRequest.OrderDropShipping.PurchaseFreight / relationPurchaseOrderRequest.RelationPurchaseOrderSkuList.Count(), |
|
|
|
UnitCost = x.SingleSkuAmount, |
|
|
|
PurchaseOrderPKId = insertPurchaseOrderList.FirstOrDefault(po => po.SkuId == x.SkuId).Id |
|
|
|
})); |
|
|
|
#endregion
|
|
|
|
|
|
|
|
fsql.Transaction(() => |
|
|
|
{ |
|
|
|
deletePurchaseOrder?.ExecuteAffrows(); |
|
|
|
deleteOrderCostDetail?.ExecuteAffrows(); |
|
|
|
insertOrderDropShipping?.ExecuteAffrows(); |
|
|
|
updateOrderDropShipping?.ExecuteAffrows(); |
|
|
|
insertOrderCost?.ExecuteAffrows(); |
|
|
|
updateOrderCost?.ExecuteAffrows(); |
|
|
|
updateOrderSku?.ExecuteAffrows(); |
|
|
|
fsql.Insert(insertPurchaseOrderList).ExecuteAffrows(); |
|
|
|
fsql.Insert(insertOrderCostDetailList).ExecuteAffrows(); |
|
|
|
if (dbOrder.StorageType != Enums.StorageType.代发) |
|
|
|
{ |
|
|
|
fsql.Update<Order>(relationPurchaseOrderRequest.OrderDropShipping.OrderId) |
|
|
|
.Set(o => o.StorageType, Enums.StorageType.代发) |
|
|
|
.SetIf(dbOrder.OrderState == Enums.OrderState.等待采购, o => o.OrderState, Enums.OrderState.待出库) |
|
|
|
.ExecuteAffrows(); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 关联外部订单
|
|
|
|
/// </summary>
|
|
|
@ -941,7 +776,7 @@ namespace BBWY.Server.Business |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
updateOrderDropShippingList.Add(fsql.Update<OrderDropShipping>().SetSource(orderDropShipping).IgnoreColumns(new string[] { "CreateTime", "ShopId" })); |
|
|
|
updateOrderDropShippingList.Add(fsql.Update<OrderDropShipping>().SetSource(orderDropShipping).IgnoreColumns(ods => new { ods.CreateTime, ods.ShopId })); |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
@ -1052,30 +887,30 @@ namespace BBWY.Server.Business |
|
|
|
} |
|
|
|
|
|
|
|
fsql.Transaction(() => |
|
|
|
{ |
|
|
|
deletePurchaseOrder.ExecuteAffrows(); |
|
|
|
deleteOrderCostDetail.ExecuteAffrows(); |
|
|
|
foreach (var update in updateOrderSkuList) |
|
|
|
update.ExecuteAffrows(); |
|
|
|
fsql.Insert(insertPurchaseOrderList).ExecuteAffrows(); |
|
|
|
fsql.Insert(insertOrderCostDetailList).ExecuteAffrows(); |
|
|
|
insertOrderCost?.ExecuteAffrows(); |
|
|
|
updateOrderCost?.ExecuteAffrows(); |
|
|
|
if (insertOrderDropShippingList.Count() > 0) |
|
|
|
fsql.Insert(insertOrderDropShippingList).ExecuteAffrows(); |
|
|
|
if (updateOrderDropShippingList.Count() > 0) |
|
|
|
{ |
|
|
|
foreach (var update in updateOrderDropShippingList) |
|
|
|
deletePurchaseOrder.ExecuteAffrows(); |
|
|
|
deleteOrderCostDetail.ExecuteAffrows(); |
|
|
|
foreach (var update in updateOrderSkuList) |
|
|
|
update.ExecuteAffrows(); |
|
|
|
} |
|
|
|
if (dbOrder.StorageType != Enums.StorageType.代发) |
|
|
|
{ |
|
|
|
fsql.Update<Order>(dbOrder.Id) |
|
|
|
.Set(o => o.StorageType, Enums.StorageType.代发) |
|
|
|
.SetIf(dbOrder.OrderState == Enums.OrderState.等待采购, o => o.OrderState, Enums.OrderState.待出库) |
|
|
|
.ExecuteAffrows(); |
|
|
|
} |
|
|
|
}); |
|
|
|
fsql.Insert(insertPurchaseOrderList).ExecuteAffrows(); |
|
|
|
fsql.Insert(insertOrderCostDetailList).ExecuteAffrows(); |
|
|
|
insertOrderCost?.ExecuteAffrows(); |
|
|
|
updateOrderCost?.ExecuteAffrows(); |
|
|
|
if (insertOrderDropShippingList.Count() > 0) |
|
|
|
fsql.Insert(insertOrderDropShippingList).ExecuteAffrows(); |
|
|
|
if (updateOrderDropShippingList.Count() > 0) |
|
|
|
{ |
|
|
|
foreach (var update in updateOrderDropShippingList) |
|
|
|
update.ExecuteAffrows(); |
|
|
|
} |
|
|
|
if (dbOrder.StorageType != Enums.StorageType.代发) |
|
|
|
{ |
|
|
|
fsql.Update<Order>(dbOrder.Id) |
|
|
|
.Set(o => o.StorageType, Enums.StorageType.代发) |
|
|
|
.SetIf(dbOrder.OrderState == Enums.OrderState.等待采购, o => o.OrderState, Enums.OrderState.待出库) |
|
|
|
.ExecuteAffrows(); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|