|
|
@ -264,7 +264,7 @@ namespace BBWYB.Server.Business |
|
|
|
throw new BusinessException("缺少收货人信息"); |
|
|
|
if (request.PurchaseAccountList == null || request.PurchaseAccountList.Count() == 0) |
|
|
|
throw new BusinessException("缺少采购账号"); |
|
|
|
if (request.CargoParamGroupList == null || request.CargoParamGroupList.Count() == 0) |
|
|
|
if (request.CargoParamGroupList == null || request.CargoParamGroupList.Count() == 0 || request.CargoParamGroupList.Any(g => string.IsNullOrEmpty(g.PurchaserId))) |
|
|
|
throw new BusinessException("缺少下单商品参数"); |
|
|
|
|
|
|
|
#region 验证同一个批次中,一个订单sku不能同时拥有多个采购方案
|
|
|
@ -320,6 +320,9 @@ namespace BBWYB.Server.Business |
|
|
|
List<IUpdate<PurchaseScheme>> updatePurchaseSchemeList = new List<IUpdate<PurchaseScheme>>(); |
|
|
|
List<OrderPurchaseRelationInfo> insertOrderPurchaseRelationInfoList = new List<OrderPurchaseRelationInfo>(); |
|
|
|
List<string> updatePurchaseTimeLimitTaskOrderSkuList = new List<string>(); |
|
|
|
List<IUpdate<Purchaser>> updatePurchaserList = new List<IUpdate<Purchaser>>(); |
|
|
|
List<SkuHistoryPurchaserRelation> insertSkuHistoryPurchaserRelationList = new List<SkuHistoryPurchaserRelation>(); |
|
|
|
|
|
|
|
List<QiKuPackTaskSkuPurchaseSchemeIdRequest> notifyQikuPackSchemeParamList = null; |
|
|
|
if (dbOrder.IntoStoreType == Enums.IntoStoreType.发回齐越) |
|
|
|
notifyQikuPackSchemeParamList = new List<QiKuPackTaskSkuPurchaseSchemeIdRequest>(); |
|
|
@ -507,18 +510,56 @@ namespace BBWYB.Server.Business |
|
|
|
var cargoParamGroupsBySchemeList = allCargoParamList.GroupBy(c => c.SchemeId); |
|
|
|
foreach (var cargoParamGroupsByScheme in cargoParamGroupsBySchemeList) |
|
|
|
{ |
|
|
|
var defalutCost = 0M; |
|
|
|
var schemeId = cargoParamGroupsByScheme.Key; |
|
|
|
|
|
|
|
defalutCost = cargoParamGroupsByScheme.Sum(cargoParam => createdPurchaseOrderItemList.Where(x => x.SkuId == cargoParam.SkuId) |
|
|
|
.Select(x => x.Price * (cargoParam.PurchaseRatio ?? 1)).DefaultIfEmpty(0M).First()); |
|
|
|
var skuId = cargoParamGroupsByScheme.FirstOrDefault().BelongSkuId; |
|
|
|
|
|
|
|
var lastPurchasePriceCost = cargoParamGroupsByScheme.Sum(cargoParam => createdPurchaseOrderItemList |
|
|
|
.Where(x => x.SkuId == cargoParam.SkuId) |
|
|
|
.Select(x => x.Price * (cargoParam.PurchaseRatio ?? 1)) |
|
|
|
.DefaultIfEmpty(0M) |
|
|
|
.First()); |
|
|
|
var purchasedAmount = insertOrderCostDetails.FirstOrDefault(ocd => ocd.SkuId == skuId)?.SkuAmount ?? 0M; |
|
|
|
var update = fsql.Update<PurchaseScheme>(schemeId).Set(ps => ps.LastPurchaseTime, DateTime.Now) |
|
|
|
.Set(ps => ps.LastPurchasePriceCost, defalutCost); |
|
|
|
.Set(ps => ps.LastPurchasePriceCost, lastPurchasePriceCost) |
|
|
|
.Set(ps => ps.PurchasedCount + 1) |
|
|
|
.Set(ps => ps.PurchasedAmount + purchasedAmount); |
|
|
|
updatePurchaseSchemeList.Add(update); |
|
|
|
} |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 更新采购商采购次数和sku数
|
|
|
|
{ |
|
|
|
var purchaserIdList = new List<string>(); |
|
|
|
var purchaserSkuDictionary = new Dictionary<string, List<string>>(); |
|
|
|
request.CargoParamGroupList.ForEach(x => |
|
|
|
{ |
|
|
|
purchaserIdList.Add(x.PurchaserId); |
|
|
|
purchaserSkuDictionary.Add(x.PurchaserId, x.CargoParamList.Select(c => c.BelongSkuId).Distinct().ToList()); |
|
|
|
}); |
|
|
|
|
|
|
|
//采购商的sku采购关系表
|
|
|
|
var dbSkuAndPurchaserRelationList = fsql.Select<SkuHistoryPurchaserRelation>() |
|
|
|
.Where(spr => purchaserIdList.Contains(spr.PurchaserId)) |
|
|
|
.ToList(); |
|
|
|
|
|
|
|
foreach (var purchaserId in purchaserIdList) |
|
|
|
{ |
|
|
|
purchaserSkuDictionary.TryGetValue(purchaserId, out var fromRequestSkuList); |
|
|
|
var fromDBSkuList = dbSkuAndPurchaserRelationList.Where(x => x.PurchaserId == purchaserId) |
|
|
|
.Select(x => x.SkuId) |
|
|
|
.Distinct() |
|
|
|
.ToList(); |
|
|
|
var exceptSkuList = fromRequestSkuList.Except(fromDBSkuList); |
|
|
|
if (exceptSkuList.Count() > 0) |
|
|
|
{ |
|
|
|
//insertSkuHistoryPurchaserRelationList.AddRange();
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 订单Sku成本
|
|
|
|
var allOrderCostDetail = orderCostDetailList.Union(insertOrderCostDetails).ToList(); |
|
|
|
foreach (var orderSku in orderSkus) |
|
|
@ -610,6 +651,8 @@ namespace BBWYB.Server.Business |
|
|
|
fsql.Insert(insertOrderPurchaseSkuInfos).ExecuteAffrows(); |
|
|
|
if (insertOrderPurchaseRelationInfoList.Count() > 0) |
|
|
|
fsql.Insert(insertOrderPurchaseRelationInfoList).ExecuteAffrows(); |
|
|
|
if (insertSkuHistoryPurchaserRelationList.Count() > 0) |
|
|
|
fsql.Insert(insertSkuHistoryPurchaserRelationList).ExecuteAffrows(); |
|
|
|
updateOrderCost?.ExecuteAffrows(); |
|
|
|
insertOrderCost?.ExecuteAffrows(); |
|
|
|
if (updatePurchaseSchemeList.Count() > 0) |
|
|
@ -628,6 +671,11 @@ namespace BBWYB.Server.Business |
|
|
|
foreach (var update in updateOrderSkuCostList) |
|
|
|
update.ExecuteAffrows(); |
|
|
|
} |
|
|
|
if (updatePurchaserList.Count() > 0) |
|
|
|
{ |
|
|
|
foreach (var update in updatePurchaserList) |
|
|
|
update.ExecuteAffrows(); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
//#region 更新采购方案最新价格
|
|
|
|